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.
This commit is contained in:
christian.pritzl 2025-08-06 15:29:11 +02:00
parent 3b0fd6114b
commit ed84ca6473
1 changed files with 2 additions and 33 deletions

View File

@ -632,40 +632,9 @@ class FuzzyCommandCompleter(Completer):
actual_words = [w for w in words if w]
# Position 2: Completing subcommand (e.g., "/mcp <tab>")
# 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"<ansigreen><b>{cmd:<12}</b></ansigreen> "
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"<ansigreen>{cmd:<12}</ansigreen> "
f"{desc}"),
style="fg:ansigreen"
))
return self.get_subcommand_suggestions(words[0], current_word)
# Position 3: After subcommand (e.g., "/mcp load <tab>")
elif len(words) == 3 and len(actual_words) > 1: