fix: add prefix matching to slash command dispatcher

Slash commands previously required exact full names. Typing /con
returned 'Unknown command' even though /config was the only match.

Add unambiguous prefix matching in process_command():
- Unique prefix (e.g. /con -> /config): dispatch immediately
- Ambiguous prefix (e.g. /re -> /reset, /retry, /reasoning...):
  show 'Did you mean' suggestions
- No match: existing 'Unknown command' error

Prefix matching uses the COMMANDS dict from hermes_cli/commands.py
(same source as SlashCommandCompleter) so it stays in sync with
any new commands added there.

Closes #928
This commit is contained in:
teyrebaz33
2026-03-11 21:11:04 +03:00
committed by teknium1
parent 6d2cfc24e9
commit a50550fdb4
2 changed files with 75 additions and 2 deletions

17
cli.py
View File

@@ -3094,8 +3094,21 @@ class HermesCLI:
else:
self.console.print(f"[bold red]Failed to load skill for {base_cmd}[/]")
else:
self.console.print(f"[bold red]Unknown command: {cmd_lower}[/]")
self.console.print("[dim #B8860B]Type /help for available commands[/]")
# Prefix matching: if input uniquely identifies one command, execute it
from hermes_cli.commands import COMMANDS
typed_base = cmd_lower.split()[0]
matches = [c for c in COMMANDS if c.startswith(typed_base)]
if len(matches) == 1:
# Re-dispatch with the full command name, preserving any arguments
remainder = cmd_original.strip()[len(typed_base):]
full_cmd = matches[0] + remainder
return self.process_command(full_cmd)
elif len(matches) > 1:
self.console.print(f"[bold yellow]Ambiguous command: {cmd_lower}[/]")
self.console.print(f"[dim]Did you mean: {', '.join(sorted(matches))}?[/]")
else:
self.console.print(f"[bold red]Unknown command: {cmd_lower}[/]")
self.console.print("[dim #B8860B]Type /help for available commands[/]")
return True