From ed84ca647322b8d20ef1a6fd395b286243f753f4 Mon Sep 17 00:00:00 2001 From: "christian.pritzl" Date: Wed, 6 Aug 2025 15:29:11 +0200 Subject: [PATCH] Refactor FuzzyCommandCompleter to utilize default subcommand handler Removed hardcoded subcommand definitions and replaced them with a call to the existing method for fetching subcommand suggestions. This enhances maintainability and reduces code duplication. --- src/cai/repl/commands/completer.py | 35 ++---------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/src/cai/repl/commands/completer.py b/src/cai/repl/commands/completer.py index 05f73fbe..f655d9c7 100644 --- a/src/cai/repl/commands/completer.py +++ b/src/cai/repl/commands/completer.py @@ -632,40 +632,9 @@ class FuzzyCommandCompleter(Completer): actual_words = [w for w in words if w] # Position 2: Completing subcommand (e.g., "/mcp ") + # Use the default subcommand handler - no need to duplicate! if len(words) == 2: - subcommands = { - "load": "Load an MCP server (SSE or stdio)", - "list": "List active MCP connections", - "add": "Add MCP tools to an agent", - "remove": "Remove an MCP server connection", - "tools": "List tools from an MCP server", - "status": "Check MCP server connection status", - "associations": "Show agent-MCP associations", - "help": "Show MCP command usage", - } - - for cmd, desc in subcommands.items(): - # Exact prefix match - if cmd.startswith(current_word): - suggestions.append(Completion( - cmd, - start_position=-len(current_word), - display=HTML( - f"{cmd:<12} " - f"{desc}"), - style="fg:ansigreen bold" - )) - # Fuzzy match - elif (current_word in cmd and - not cmd.startswith(current_word)): - suggestions.append(Completion( - cmd, - start_position=-len(current_word), - display=HTML( - f"{cmd:<12} " - f"{desc}"), - style="fg:ansigreen" - )) + return self.get_subcommand_suggestions(words[0], current_word) # Position 3: After subcommand (e.g., "/mcp load ") elif len(words) == 3 and len(actual_words) > 1: