mirror of
https://github.com/instructkr/claw-code.git
synced 2026-06-27 17:00:04 +02:00
Merge pull request #3263 from hiisandog/fix/claw-small-cleanup-c6b25
Improve command lookup normalization
This commit is contained in:
+10
-2
@@ -55,7 +55,8 @@ def command_names() -> list[str]:
|
|||||||
|
|
||||||
|
|
||||||
def get_command(name: str) -> PortingModule | None:
|
def get_command(name: str) -> PortingModule | None:
|
||||||
needle = COMMAND_ALIASES.get(name.lower(), name.lower())
|
normalized = name.strip().lower()
|
||||||
|
needle = COMMAND_ALIASES.get(normalized, normalized)
|
||||||
for module in PORTED_COMMANDS:
|
for module in PORTED_COMMANDS:
|
||||||
if module.name.lower() == needle:
|
if module.name.lower() == needle:
|
||||||
return module
|
return module
|
||||||
@@ -72,8 +73,15 @@ def get_commands(cwd: str | None = None, include_plugin_commands: bool = True, i
|
|||||||
|
|
||||||
|
|
||||||
def find_commands(query: str, limit: int = 20) -> list[PortingModule]:
|
def find_commands(query: str, limit: int = 20) -> list[PortingModule]:
|
||||||
needle = query.lower()
|
needle = query.strip().lower()
|
||||||
matches = [module for module in PORTED_COMMANDS if needle in module.name.lower() or needle in module.source_hint.lower()]
|
matches = [module for module in PORTED_COMMANDS if needle in module.name.lower() or needle in module.source_hint.lower()]
|
||||||
|
matches.sort(
|
||||||
|
key=lambda module: (
|
||||||
|
module.name.lower() != needle,
|
||||||
|
not module.name.lower().startswith(needle),
|
||||||
|
needle not in module.name.lower(),
|
||||||
|
)
|
||||||
|
)
|
||||||
return matches[:limit]
|
return matches[:limit]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -183,6 +183,13 @@ class PortingWorkspaceTests(unittest.TestCase):
|
|||||||
self.assertIn("Mirrored command 'plugin'", result.stdout)
|
self.assertIn("Mirrored command 'plugin'", result.stdout)
|
||||||
self.assertNotIn('Unknown mirrored command', result.stdout)
|
self.assertNotIn('Unknown mirrored command', result.stdout)
|
||||||
|
|
||||||
|
def test_command_lookup_normalizes_user_input_whitespace(self) -> None:
|
||||||
|
from src.commands import execute_command, find_commands, get_command
|
||||||
|
|
||||||
|
self.assertEqual('plugin', get_command(' PLUGINS ').name)
|
||||||
|
self.assertEqual('review', find_commands(' review ', limit=1)[0].name)
|
||||||
|
self.assertIn("Mirrored command 'plugin'", execute_command(' marketplace ', 'browse').message)
|
||||||
|
|
||||||
def test_route_plugin_slash_commands_match_commands(self) -> None:
|
def test_route_plugin_slash_commands_match_commands(self) -> None:
|
||||||
prompts = ('/plugin list', '/plugins list', '/marketplace browse', '/reload-plugins')
|
prompts = ('/plugin list', '/plugins list', '/marketplace browse', '/reload-plugins')
|
||||||
for prompt in prompts:
|
for prompt in prompts:
|
||||||
|
|||||||
Reference in New Issue
Block a user