Skip to content

The agent that grows with you

feat(commands): attach desktop slash metadata to the registry

Brooklyn Nicholsonb61408e95e08
diff --git a/hermes_cli/commands.py b/hermes_cli/commands.py
index cba38bd8544..68435460a77 100644
--- a/hermes_cli/commands.py
+++ b/hermes_cli/commands.py
@@ -17,7 +17,7 @@ import shutil
import subprocess
import time
from collections.abc import Callable, Mapping
-from dataclasses import dataclass, field
+from dataclasses import dataclass, field, replace
from typing import Any, Dict, Optional, Tuple
from utils import is_truthy_value
@@ -127,6 +127,11 @@ class CommandDef:
# gateway can import commands.py without prompt_toolkit and without
# pulling in executor dependencies.
execute: str | None = None
+ # Desktop composer: ``options`` | ``text`` | ``mixed``. ``None`` is inferred.
+ argument_mode: str | None = None
+ # Desktop availability. ``None`` = offered; ``hidden`` = runs but stays out
+ # of the popover; otherwise a reason (terminal / messaging / settings / …).
+ desktop: str | None = None
# Valid values for CommandDef.busy_policy (see field docs above).
@@ -396,6 +401,107 @@ COMMAND_REGISTRY: list[CommandDef] = [
]
+# Desktop composer / popover metadata. Lives next to the registry so a new
+# CommandDef can declare how desktop should treat it — the TS table is only
+# the local-action overlay (pickers, Electron actions, dedicated RPCs).
+_DESKTOP_UNAVAILABLE: dict[str, str] = {
+ "busy": "terminal",
+ "clear": "terminal",
+ "config": "terminal",
+ "copy": "terminal",
+ "cron": "terminal",
+ "density": "terminal",
+ "details": "terminal",
+ "footer": "terminal",
+ "gateway": "terminal",
+ "history": "terminal",
+ "image": "terminal",
+ "indicator": "terminal",
+ "logs": "terminal",
+ "mouse": "terminal",
+ "paste": "terminal",
+ "platforms": "terminal",
+ "plugins": "terminal",
+ "quit": "terminal",
+ "redraw": "terminal",
+ "reload": "terminal",
+ "restart": "terminal",
+ "sethome": "terminal",
+ "snapshot": "terminal",
+ "statusbar": "terminal",
+ "toolsets": "terminal",
+ "update": "terminal",
+ "verbose": "terminal",
+ "approve": "messaging",
+ "deny": "messaging",
+ "skills": "settings",
+ "pets": "settings",
+ "curator": "advanced",
+ "fast": "advanced",
+ "insights": "advanced",
+ "kanban": "advanced",
+ "reasoning": "advanced",
+ "reload-mcp": "advanced",
+ "reload-skills": "advanced",
+ "voice": "composer-voice",
+}
+
+_DESKTOP_HIDDEN: frozenset[str] = frozenset({"model"})
+
+# Only the cases ``args_hint`` / ``subcommands`` would get wrong.
+_ARGUMENT_MODE_OVERRIDES: dict[str, str] = {
+ "goal": "mixed",
+ "handoff": "options",
+ "loop": "mixed",
+ "personality": "options",
+ "resume": "mixed",
+ "skin": "options",
+ "tools": "options",
+}
+
+_TEXT_HINTS = ("<prompt>", "[text", "instructions", "[interval]", "<what", "[focus", "[review")
+
+
+def infer_argument_mode(cmd: CommandDef) -> str | None:
+ """Composer mode for a command: explicit, override, or inferred from args."""
+ if cmd.argument_mode in {"options", "text", "mixed"}:
+ return cmd.argument_mode
+ override = _ARGUMENT_MODE_OVERRIDES.get(cmd.name)
+ if override:
+ return override
+ hint = (cmd.args_hint or "").lower()
+ if cmd.subcommands and hint and any(token in hint for token in _TEXT_HINTS):
+ return "mixed"
+ if cmd.subcommands:
+ return "options"
+ if hint:
+ return "text"
+ return None
+
+
+def command_desktop_meta(cmd: CommandDef) -> dict[str, str | None]:
+ """Wire shape for ``commands.catalog`` — argument mode + desktop availability."""
+ desktop = cmd.desktop
+ if desktop is None and cmd.name in _DESKTOP_HIDDEN:
+ desktop = "hidden"
+ if desktop is None:
+ desktop = _DESKTOP_UNAVAILABLE.get(cmd.name)
+ return {"argument_mode": infer_argument_mode(cmd), "desktop": desktop}
+
+
+def _apply_desktop_fields(cmds: list[CommandDef]) -> list[CommandDef]:
+ applied: list[CommandDef] = []
+ for cmd in cmds:
+ meta = command_desktop_meta(cmd)
+ if meta["argument_mode"] != cmd.argument_mode or meta["desktop"] != cmd.desktop:
+ cmd = replace(cmd, argument_mode=meta["argument_mode"], desktop=meta["desktop"])
+ applied.append(cmd)
+ return applied
+
+
+COMMAND_REGISTRY = _apply_desktop_fields(COMMAND_REGISTRY)
+
+
# ---------------------------------------------------------------------------
# Derived lookups -- rebuilt once at import time, refreshed by rebuild_lookups()
# ---------------------------------------------------------------------------
diff --git a/hermes_cli/plugins.py b/hermes_cli/plugins.py
index 781c639b48e..9028e285307 100644
--- a/hermes_cli/plugins.py
+++ b/hermes_cli/plugins.py
@@ -2182,6 +2182,7 @@ class PluginContext:
handler: Callable,
description: str = "",
args_hint: str = "",
+ argument_mode: str | None = None,
) -> Optional[PluginRegistration]:
"""Register a slash command (e.g. ``/lcm``) available in CLI and gateway sessions.
@@ -2199,6 +2200,10 @@ class PluginContext:
parameterless in Discord and still accept trailing text when invoked
as free-form chat.
+ ``argument_mode`` tells the desktop composer how text after the command
+ name behaves (``options``, ``text``, or ``mixed``). Omit it to infer
+ ``text`` whenever ``args_hint`` is set, so ``/myplugin `` stays typeable.
+
Names conflicting with built-in commands are rejected with a warning.
"""
clean = name.lower().strip().lstrip("/").replace(" ", "-")
@@ -2223,12 +2228,17 @@ class PluginContext:
pass # If commands module isn't available, skip the check
previous = self._manager._plugin_commands.get(clean)
+ hint = (args_hint or "").strip()
+ mode = argument_mode if argument_mode in {"options", "text", "mixed"} else (
+ "text" if hint else None
+ )
entry = {
"handler": handler,
"description": description or "Plugin command",
"plugin": self.manifest.name,
"plugin_key": self.manifest.key or self.manifest.name,
- "args_hint": (args_hint or "").strip(),
+ "args_hint": hint,
+ "argument_mode": mode,
}
self._manager._plugin_commands[clean] = entry
handle = self._track_replacement(
diff --git a/tests/hermes_cli/test_commands.py b/tests/hermes_cli/test_commands.py
index dc0b6e9b59e..fa591b680d8 100644
--- a/tests/hermes_cli/test_commands.py
+++ b/tests/hermes_cli/test_commands.py
@@ -19,8 +19,10 @@ from hermes_cli.commands import (
_clamp_command_names,
_clamp_telegram_names,
_sanitize_telegram_name,
+ command_desktop_meta,
discord_skill_commands,
gateway_help_lines,
+ infer_argument_mode,
resolve_command,
slack_app_manifest,
slack_native_slashes,
@@ -72,8 +74,24 @@ class TestCommandRegistry:
assert resolve_command(alias).name == cmd.name or alias == cmd.name, \
f"Alias '{alias}' of '{cmd.name}' shadows canonical '{target.name}'"
+ def test_desktop_meta_marks_review_typeable_and_terminal_hidden(self):
+ review = resolve_command("review")
+ assert review is not None
+ assert review.argument_mode == "text"
+ assert review.desktop is None
+ assert command_desktop_meta(review) == {"argument_mode": "text", "desktop": None}
+ clear = resolve_command("clear")
+ assert clear is not None
+ assert clear.desktop == "terminal"
+ model = resolve_command("model")
+ assert model is not None
+ assert model.desktop == "hidden"
+
+ def test_argument_mode_infers_text_from_args_hint(self):
+ cmd = CommandDef("demo", "Demo", "Session", args_hint="<prompt>")
+ assert infer_argument_mode(cmd) == "text"
# ---------------------------------------------------------------------------
diff --git a/tests/hermes_cli/test_plugins.py b/tests/hermes_cli/test_plugins.py
index 998dcfed1c2..4f4f67be0cd 100644
--- a/tests/hermes_cli/test_plugins.py
+++ b/tests/hermes_cli/test_plugins.py
@@ -1946,6 +1946,17 @@ class TestPluginCommands:
assert len(mgr._plugin_commands) == 0
assert "empty name" in caplog.text
+ def test_register_command_infers_text_argument_mode_from_args_hint(self):
+ mgr = PluginManager()
+ manifest = PluginManifest(name="test-plugin", source="user")
+ ctx = PluginContext(manifest, mgr)
+
+ ctx.register_command("lcm", lambda a: a, description="LCM", args_hint="<prompt>")
+ ctx.register_command("ping", lambda a: a, description="Ping")
+
+ assert mgr._plugin_commands["lcm"]["argument_mode"] == "text"
+ assert mgr._plugin_commands["ping"]["argument_mode"] is None
+
diff --git a/tests/test_tui_gateway_server.py b/tests/test_tui_gateway_server.py
index deba3bd53e2..f8290f8442f 100644
--- a/tests/test_tui_gateway_server.py
+++ b/tests/test_tui_gateway_server.py
@@ -10718,6 +10718,49 @@ def test_commands_catalog_filters_gateway_only_commands_and_keeps_status_visible
assert "/set-home" not in canon
+def test_commands_catalog_includes_desktop_meta_without_skills():
+ resp = server.handle_request(
+ {"id": "1", "method": "commands.catalog", "params": {}}
+ )
+
+ commands = resp["result"]["commands"]
+ assert commands["/review"] == {"argument_mode": "text", "desktop": None}
+ assert commands["/clear"]["desktop"] == "terminal"
+ assert commands["/model"]["desktop"] == "hidden"
+ assert commands["/compact"]["argument_mode"] == commands["/compress"]["argument_mode"]
+
+ for skill in resp["result"]["skills"]:
+ assert skill not in commands
+
+
+def test_commands_catalog_includes_plugin_commands(monkeypatch):
+ monkeypatch.setattr(
+ "hermes_cli.plugins.get_plugin_commands",
+ lambda: {
+ "lcm": {
+ "description": "Latent consistency",
+ "args_hint": "<prompt>",
+ "argument_mode": "text",
+ }
+ },
+ )
+
+ resp = server.handle_request(
+ {"id": "1", "method": "commands.catalog", "params": {}}
+ )
+
+ assert resp["result"]["commands"]["/lcm"] == {
+ "argument_mode": "text",
+ "desktop": None,
+ }
+ pairs = dict(resp["result"]["pairs"])
+ assert "/lcm" in pairs
+ plugin_cat = next(
+ c for c in resp["result"]["categories"] if c["name"] == "Plugin commands"
+ )
+ assert "/lcm" in dict(plugin_cat["pairs"])
+
+
def test_session_status_reads_live_gateway_agent(monkeypatch):
agent = types.SimpleNamespace(
model="live-model",
diff --git a/tui_gateway/methods_tools.py b/tui_gateway/methods_tools.py
index f153bc98a02..0334738f869 100644
--- a/tui_gateway/methods_tools.py
+++ b/tui_gateway/methods_tools.py
@@ -260,15 +260,22 @@ def _(rid, params: dict) -> dict:
COMMAND_REGISTRY,
SUBCOMMANDS,
_build_description,
+ command_desktop_meta,
)
all_pairs: list[list[str]] = []
canon: dict[str, str] = {}
+ commands: dict[str, dict[str, str | None]] = {}
categories: list[dict] = []
cat_map: dict[str, list[list[str]]] = {}
cat_order: list[str] = []
for cmd in COMMAND_REGISTRY:
+ meta = command_desktop_meta(cmd)
+ commands[f"/{cmd.name}"] = meta
+ for alias in cmd.aliases:
+ commands[f"/{alias}"] = meta
+
if cmd.name in _TUI_HIDDEN or cmd.gateway_only:
continue
@@ -328,6 +335,35 @@ def _(rid, params: dict) -> dict:
if not warning:
warning = f"quick_commands discovery unavailable: {e}"
+ try:
+ from hermes_cli.plugins import get_plugin_commands
+
+ plugin_cmds = get_plugin_commands() or {}
+ if plugin_cmds:
+ bucket = "Plugin commands"
+ if bucket not in cat_map:
+ cat_map[bucket] = []
+ cat_order.append(bucket)
+ for pname, info in sorted(plugin_cmds.items()):
+ if not isinstance(info, dict):
+ continue
+ key = f"/{pname}"
+ if key.lower() in canon:
+ continue
+ canon[key.lower()] = key
+ pdesc = str(info.get("description") or "Plugin command")
+ pdesc = pdesc[:120] + ("…" if len(pdesc) > 120 else "")
+ all_pairs.append([key, pdesc])
+ cat_map[bucket].append([key, pdesc])
+ hint = str(info.get("args_hint") or "").strip()
+ mode = info.get("argument_mode")
+ if mode not in {"options", "text", "mixed"}:
+ mode = "text" if hint else None
+ commands[key] = {"argument_mode": mode, "desktop": None}
+ except Exception as e:
+ if not warning:
+ warning = f"plugin command discovery unavailable: {e}"
+
skill_count = 0
skills: dict[str, dict] = {}
try:
@@ -358,6 +394,7 @@ def _(rid, params: dict) -> dict:
"pairs": all_pairs,
"sub": sub,
"canon": canon,
+ "commands": commands,
"categories": categories,
"skills": skills,
"skill_count": skill_count,