@@ -1149,70 +1149,38 @@ impl Command {
11491149 . await
11501150 }
11511151
1152+ /// Returns a vector of all available commands for dynamic enumeration
1153+ pub fn all_commands ( ) -> Vec < ( & ' static str , & ' static dyn CommandHandler ) > {
1154+ vec ! [
1155+ ( "help" , & HELP_HANDLER as & dyn CommandHandler ) ,
1156+ ( "quit" , & QUIT_HANDLER as & dyn CommandHandler ) ,
1157+ ( "clear" , & CLEAR_HANDLER as & dyn CommandHandler ) ,
1158+ ( "context" , & CONTEXT_HANDLER as & dyn CommandHandler ) ,
1159+ ( "profile" , & PROFILE_HANDLER as & dyn CommandHandler ) ,
1160+ ( "tools" , & TOOLS_HANDLER as & dyn CommandHandler ) ,
1161+ ( "compact" , & COMPACT_HANDLER as & dyn CommandHandler ) ,
1162+ ( "usage" , & USAGE_HANDLER as & dyn CommandHandler ) ,
1163+ ( "editor" , & EDITOR_HANDLER as & dyn CommandHandler ) ,
1164+ ( "issue" , & ISSUE_HANDLER as & dyn CommandHandler ) ,
1165+ ]
1166+ }
1167+
11521168 /// Generate descriptions for all commands for LLM tool descriptions
1169+ ///
1170+ /// This method dynamically iterates through all available commands and collects
1171+ /// their descriptions for use in LLM integration. This ensures that all commands
1172+ /// are properly described and no commands are missed when new ones are added.
11531173 pub fn generate_llm_descriptions ( ) -> std:: collections:: HashMap < String , CommandDescription > {
11541174 let mut descriptions = std:: collections:: HashMap :: new ( ) ;
11551175
1156- // Add descriptions for all implemented commands
1157- descriptions. insert ( "help" . to_string ( ) , CommandDescription {
1158- short_description : HELP_HANDLER . description ( ) . to_string ( ) ,
1159- full_description : HELP_HANDLER . llm_description ( ) ,
1160- usage : HELP_HANDLER . usage ( ) . to_string ( ) ,
1161- } ) ;
1162-
1163- descriptions. insert ( "quit" . to_string ( ) , CommandDescription {
1164- short_description : QUIT_HANDLER . description ( ) . to_string ( ) ,
1165- full_description : QUIT_HANDLER . llm_description ( ) ,
1166- usage : QUIT_HANDLER . usage ( ) . to_string ( ) ,
1167- } ) ;
1168-
1169- descriptions. insert ( "clear" . to_string ( ) , CommandDescription {
1170- short_description : CLEAR_HANDLER . description ( ) . to_string ( ) ,
1171- full_description : CLEAR_HANDLER . llm_description ( ) ,
1172- usage : CLEAR_HANDLER . usage ( ) . to_string ( ) ,
1173- } ) ;
1174-
1175- descriptions. insert ( "context" . to_string ( ) , CommandDescription {
1176- short_description : CONTEXT_HANDLER . description ( ) . to_string ( ) ,
1177- full_description : CONTEXT_HANDLER . llm_description ( ) ,
1178- usage : CONTEXT_HANDLER . usage ( ) . to_string ( ) ,
1179- } ) ;
1180-
1181- descriptions. insert ( "profile" . to_string ( ) , CommandDescription {
1182- short_description : PROFILE_HANDLER . description ( ) . to_string ( ) ,
1183- full_description : PROFILE_HANDLER . llm_description ( ) ,
1184- usage : PROFILE_HANDLER . usage ( ) . to_string ( ) ,
1185- } ) ;
1186-
1187- descriptions. insert ( "tools" . to_string ( ) , CommandDescription {
1188- short_description : TOOLS_HANDLER . description ( ) . to_string ( ) ,
1189- full_description : TOOLS_HANDLER . llm_description ( ) ,
1190- usage : TOOLS_HANDLER . usage ( ) . to_string ( ) ,
1191- } ) ;
1192-
1193- descriptions. insert ( "compact" . to_string ( ) , CommandDescription {
1194- short_description : COMPACT_HANDLER . description ( ) . to_string ( ) ,
1195- full_description : COMPACT_HANDLER . llm_description ( ) ,
1196- usage : COMPACT_HANDLER . usage ( ) . to_string ( ) ,
1197- } ) ;
1198-
1199- descriptions. insert ( "usage" . to_string ( ) , CommandDescription {
1200- short_description : USAGE_HANDLER . description ( ) . to_string ( ) ,
1201- full_description : USAGE_HANDLER . llm_description ( ) ,
1202- usage : USAGE_HANDLER . usage ( ) . to_string ( ) ,
1203- } ) ;
1204-
1205- descriptions. insert ( "editor" . to_string ( ) , CommandDescription {
1206- short_description : EDITOR_HANDLER . description ( ) . to_string ( ) ,
1207- full_description : EDITOR_HANDLER . llm_description ( ) ,
1208- usage : EDITOR_HANDLER . usage ( ) . to_string ( ) ,
1209- } ) ;
1210-
1211- descriptions. insert ( "issue" . to_string ( ) , CommandDescription {
1212- short_description : ISSUE_HANDLER . description ( ) . to_string ( ) ,
1213- full_description : ISSUE_HANDLER . llm_description ( ) ,
1214- usage : ISSUE_HANDLER . usage ( ) . to_string ( ) ,
1215- } ) ;
1176+ // Dynamically iterate through all commands
1177+ for ( name, handler) in Self :: all_commands ( ) {
1178+ descriptions. insert ( name. to_string ( ) , CommandDescription {
1179+ short_description : handler. description ( ) . to_string ( ) ,
1180+ full_description : handler. llm_description ( ) ,
1181+ usage : handler. usage ( ) . to_string ( ) ,
1182+ } ) ;
1183+ }
12161184
12171185 descriptions
12181186 }
0 commit comments