Skip to content

The agent that grows with you

fix(gateway): scope the browse-cap exemption to registry commands only

chelsealongef2013231d3a
diff --git a/tests/tui_gateway/test_slash_fuzzy.py b/tests/tui_gateway/test_slash_fuzzy.py
index bdd5e8f684b..e222bfa9b7a 100644
--- a/tests/tui_gateway/test_slash_fuzzy.py
+++ b/tests/tui_gateway/test_slash_fuzzy.py
@@ -98,17 +98,63 @@ def test_rank_slash_completions_does_not_truncate_commands_when_browsing():
# /queue sat past position 30 and never reached the client) while the
# user-growable skill block keeps its cap.
commands = [_item(f"/cmd{i}") for i in range(40)]
+ registry_names = frozenset(f"cmd{i}" for i in range(40))
ranked = _rank_slash_completions(
commands,
lambda _name: 0,
lambda _name: "user",
browsing=True,
+ registry_command_names=registry_names,
)
assert len(ranked) == 40
assert ranked[-1]["text"] == "/cmd39"
+def test_rank_slash_completions_still_caps_plugin_commands_when_browsing():
+ # Plugin-registered commands (kind: "command", same as registry
+ # commands) are an unbounded, user-installed source, unlike
+ # COMMAND_REGISTRY — a bare `/` must still bound them, or a large
+ # plugin install floods the browse list the way skills used to.
+ registry = [_item(f"/reg{i}") for i in range(40)]
+ plugins = [_item(f"/plugin{i}") for i in range(40)]
+ registry_names = frozenset(f"reg{i}" for i in range(40))
+
+ ranked = _rank_slash_completions(
+ registry + plugins,
+ lambda _name: 0,
+ lambda _name: "user",
+ browsing=True,
+ registry_command_names=registry_names,
+ )
+
+ texts = [item["text"] for item in ranked]
+ assert texts[:40] == [f"/reg{i}" for i in range(40)]
+ plugin_texts = texts[40:]
+ assert len(plugin_texts) == 30
+ assert plugin_texts == [f"/plugin{i}" for i in range(30)]
+
+
+def test_rank_slash_completions_defaults_to_the_real_command_registry():
+ # No registry_command_names override: this must wire up to the actual
+ # hermes_cli.commands.GATEWAY_KNOWN_COMMANDS, not just a test double.
+ # /help is a real registry command; /plugin* stands in for names a
+ # plugin registered (kind "command", but not in the registry) and
+ # must still be capped.
+ items = [_item("/help")] + [_item(f"/plugin{i}") for i in range(40)]
+
+ ranked = _rank_slash_completions(
+ items,
+ lambda _name: 0,
+ lambda _name: "user",
+ browsing=True,
+ )
+
+ texts = [item["text"] for item in ranked]
+ assert texts[0] == "/help"
+ assert len([t for t in texts if t.startswith("/plugin")]) == 30
+
+
def test_rank_slash_completions_still_caps_commands_when_searching():
commands = [_item(f"/cmd{i}") for i in range(40)]
diff --git a/tui_gateway/server.py b/tui_gateway/server.py
index 1969bb9aee9..6a743aed397 100644
--- a/tui_gateway/server.py
+++ b/tui_gateway/server.py
@@ -3422,10 +3422,13 @@ def _skill_usage_lookup():
_SLASH_COMPLETION_LIMIT = 30
-def _rank_slash_completions(items: list[dict], usage, origin_of, *, browsing: bool, score_of=None) -> list[dict]:
+def _rank_slash_completions(items: list[dict], usage, origin_of, *, browsing: bool, score_of=None,
+ registry_command_names: frozenset[str] | None = None) -> list[dict]:
"""Registry commands keep their order; only skills reorder: fuzzy ``score_of`` first, then most-used, then
A-Z. The limit is spent PER KIND (a flat cut on a large install offered no skill at all). ``browsing``
- (bare ``/``) drops never-used bundled skills as noise; a typed query is SEARCHING — nothing pruned, only reordered."""
+ (bare ``/``) drops never-used bundled skills as noise; a typed query is SEARCHING — nothing pruned, only reordered.
+ While browsing, only names in ``registry_command_names`` (default ``GATEWAY_KNOWN_COMMANDS``) skip the cap:
+ plugin-registered commands are also ``kind != "skill"`` but unbounded, so they stay capped like skills."""
def name_of(item: dict) -> str:
return str(item.get("text", "")).strip().lstrip("/").lower()
commands = [item for item in items if item.get("kind") != "skill"]
@@ -3434,9 +3437,15 @@ def _rank_slash_completions(items: list[dict], usage, origin_of, *, browsing: bo
skills = [item for item in skills if origin_of(name_of(item)) != "bundled" or usage(name_of(item)) > 0]
skills.sort(key=lambda item: (
*(() if score_of is None else (score_of(item),)), -usage(name_of(item)), name_of(item)))
- # Commands come from the bounded, curated registry (~150 entries), not from user-installed skills, which is
- # what the cap exists to bound. Truncating the command block hid /goal, /loop and /queue from a bare `/`.
- ranked_commands = commands if browsing else commands[:_SLASH_COMPLETION_LIMIT]
+ if browsing:
+ if registry_command_names is None:
+ from hermes_cli.commands import GATEWAY_KNOWN_COMMANDS
+ registry_command_names = GATEWAY_KNOWN_COMMANDS
+ fixed = [c for c in commands if name_of(c) in registry_command_names]
+ other = [c for c in commands if name_of(c) not in registry_command_names]
+ ranked_commands = fixed + other[:_SLASH_COMPLETION_LIMIT]
+ else:
+ ranked_commands = commands[:_SLASH_COMPLETION_LIMIT]
return ranked_commands + skills[:_SLASH_COMPLETION_LIMIT]