Skip to content

Commit 4e0cba7

Browse files
authored
Merge pull request #3263 from hiisandog/fix/claw-small-cleanup-c6b25
Improve command lookup normalization
2 parents d229a9b + 5babda1 commit 4e0cba7

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/commands.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def command_names() -> list[str]:
5555

5656

5757
def get_command(name: str) -> PortingModule | None:
58-
needle = COMMAND_ALIASES.get(name.lower(), name.lower())
58+
normalized = name.strip().lower()
59+
needle = COMMAND_ALIASES.get(normalized, normalized)
5960
for module in PORTED_COMMANDS:
6061
if module.name.lower() == needle:
6162
return module
@@ -72,8 +73,15 @@ def get_commands(cwd: str | None = None, include_plugin_commands: bool = True, i
7273

7374

7475
def find_commands(query: str, limit: int = 20) -> list[PortingModule]:
75-
needle = query.lower()
76+
needle = query.strip().lower()
7677
matches = [module for module in PORTED_COMMANDS if needle in module.name.lower() or needle in module.source_hint.lower()]
78+
matches.sort(
79+
key=lambda module: (
80+
module.name.lower() != needle,
81+
not module.name.lower().startswith(needle),
82+
needle not in module.name.lower(),
83+
)
84+
)
7785
return matches[:limit]
7886

7987

tests/test_porting_workspace.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ def test_plugin_command_aliases_execute_as_local_commands(self) -> None:
183183
self.assertIn("Mirrored command 'plugin'", result.stdout)
184184
self.assertNotIn('Unknown mirrored command', result.stdout)
185185

186+
def test_command_lookup_normalizes_user_input_whitespace(self) -> None:
187+
from src.commands import execute_command, find_commands, get_command
188+
189+
self.assertEqual('plugin', get_command(' PLUGINS ').name)
190+
self.assertEqual('review', find_commands(' review ', limit=1)[0].name)
191+
self.assertIn("Mirrored command 'plugin'", execute_command(' marketplace ', 'browse').message)
192+
186193
def test_route_plugin_slash_commands_match_commands(self) -> None:
187194
prompts = ('/plugin list', '/plugins list', '/marketplace browse', '/reload-plugins')
188195
for prompt in prompts:

0 commit comments

Comments
 (0)