Skip to content

The agent that grows with you

fix: keep interactive plugin skill routing in sync

Hermes Agent3e68934a404b
diff --git a/agent/skill_commands.py b/agent/skill_commands.py
index 42983c3c7f8..8d214d4a72b 100644
--- a/agent/skill_commands.py
+++ b/agent/skill_commands.py
@@ -6,7 +6,7 @@ import os
import re
import threading
from pathlib import Path
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Mapping, Optional
from hermes_constants import display_hermes_home
from agent.prompt_cache_boundary import register_stable_prefix
@@ -556,7 +556,8 @@ def get_plugin_skill_commands() -> Dict[str, Dict[str, Any]]:
parsed, _ = _parse_frontmatter(skill_md.read_text(encoding="utf-8-sig", errors="replace"))
except OSError:
continue
- frontmatter = metadata.get("frontmatter") or parsed
+ # Offer from the file we will actually load, not registration-time hints.
+ frontmatter = parsed
if not (skill_matches_platform(frontmatter) and skill_matches_environment(frontmatter)
and skill_matches_apps(frontmatter)):
continue
@@ -565,7 +566,7 @@ def get_plugin_skill_commands() -> Dict[str, Dict[str, Any]]:
logger.warning("Plugin skill %r collides with an existing slash command; skipping", qualified)
continue
commands[key] = {
- "name": qualified, "description": str(metadata.get("description") or parsed.get("description")
+ "name": qualified, "description": str(parsed.get("description") or metadata.get("description")
or f"Invoke the {qualified} plugin skill").strip(),
"skill_identifier": qualified, "skill_md_path": str(skill_md),
"skill_dir": str(skill_md.parent), "source": "plugin",
@@ -630,7 +631,7 @@ def resolve_skill_command_key(command: str, *, interactive: bool = False) -> Opt
return resolve_slash_key(command, get_interactive_skill_commands() if interactive else get_skill_commands())
-def resolve_slash_key(command: str, table: Dict[str, Any]) -> Optional[str]:
+def resolve_slash_key(command: str, table: Mapping[str, Any]) -> Optional[str]:
"""``command`` -> ``"/slug"`` when present in *table* (``_`` normalized to ``-``), else None."""
if not command:
return None
diff --git a/cli.py b/cli.py
index 56f9ff9cb2a..9fa8229b400 100644
--- a/cli.py
+++ b/cli.py
@@ -736,12 +736,10 @@ def _slash_args(cmd: str) -> str:
def _ensure_skill_commands() -> dict:
- global _skill_commands
- if _skill_commands is None:
- from agent.skill_commands import get_interactive_skill_commands
-
- _skill_commands = get_interactive_skill_commands()
- return _skill_commands
+ if _skill_commands is not None:
+ return _skill_commands
+ from agent.skill_commands import get_interactive_skill_commands
+ return get_interactive_skill_commands()
def get_skill_commands() -> dict:
diff --git a/hermes_cli/commands_completion.py b/hermes_cli/commands_completion.py
index 72e6e009b4f..66339235811 100644
--- a/hermes_cli/commands_completion.py
+++ b/hermes_cli/commands_completion.py
@@ -303,7 +303,8 @@ class SlashCommandCompleter(Completer):
return "/" + token.lstrip("/").replace("_", "-").lower()
def _is_skill_command(self, token: str) -> bool:
- return self._normalize_skill_token(token) in self._iter_skill_commands()
+ from agent.skill_commands import resolve_slash_key
+ return resolve_slash_key(token.lstrip("/"), self._iter_skill_commands()) is not None
def _stacked_skill_completions(self, text: str):
"""Skill-command completions for stacked invocations (``/skill-a /skill-b do XYZ``): only
@@ -315,10 +316,11 @@ class SlashCommandCompleter(Completer):
_cap = 5
completed, current_word = _split_args(text)
skill_cmds = self._iter_skill_commands()
+ from agent.skill_commands import resolve_slash_key
seen: set[str] = set()
for token in completed:
- key = self._normalize_skill_token(token)
- if key not in skill_cmds or key in seen:
+ key = resolve_slash_key(token.lstrip("/"), skill_cmds)
+ if key is None or key in seen:
return
seen.add(key)
if len(seen) >= _cap or not current_word.startswith("/"):
diff --git a/tests/hermes_cli/test_skill_stacked_completion.py b/tests/hermes_cli/test_skill_stacked_completion.py
new file mode 100644
index 00000000000..ccb5819e076
--- /dev/null
+++ b/tests/hermes_cli/test_skill_stacked_completion.py
@@ -0,0 +1,14 @@
+"""Interactive skill spelling must agree with slash dispatch."""
+
+from hermes_cli.commands_completion import SlashCommandCompleter
+
+
+def test_stacked_completion_prefers_exact_underscored_plugin_key():
+ commands = {
+ "/plugin:my_skill": {"description": "Underscored"},
+ "/other:guide": {"description": "Other"},
+ }
+ completer = SlashCommandCompleter(skill_commands_provider=lambda: commands)
+ assert completer._is_skill_command("/plugin:my_skill")
+ results = list(completer._stacked_skill_completions("/plugin:my_skill /other:"))
+ assert [result.display_text for result in results] == ["/other:guide"]
\ No newline at end of file
diff --git a/tests/tools/test_plugin_skills.py b/tests/tools/test_plugin_skills.py
index 45d1bc87b0e..09fbcab93a4 100644
--- a/tests/tools/test_plugin_skills.py
+++ b/tests/tools/test_plugin_skills.py
@@ -12,6 +12,7 @@ import os
import sys
import pytest
+import cli
# ── Namespace helpers ─────────────────────────────────────────────────────
@@ -84,6 +85,57 @@ class TestPluginSkillRegistry:
pm.remove_plugin_skill("p:x")
class TestInteractivePluginSkill:
+ def test_cli_command_map_tracks_plugin_lifecycle(self, tmp_path, monkeypatch):
+ from hermes_cli import plugins
+
+ home = tmp_path / "home"
+ plugin = home / "plugins" / "lifecycle-probe"
+ md = plugin / "skills" / "guide" / "SKILL.md"
+ md.parent.mkdir(parents=True)
+ (plugin / "plugin.yaml").write_text("name: lifecycle-probe\nversion: 0.1.0\n")
+ (plugin / "__init__.py").write_text(
+ "from pathlib import Path\ndef register(ctx):\n"
+ " ctx.register_skill('guide', Path(__file__).parent / 'skills' / 'guide' / 'SKILL.md')\n")
+ md.write_text("---\nname: guide\ndescription: Guide\n---\nBody.\n")
+ config = home / "config.yaml"
+ config.write_text("plugins:\n enabled: []\n")
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ plugins._reset_plugin_managers_for_tests()
+ try:
+ assert "/lifecycle-probe:guide" not in cli.get_skill_commands()
+ config.write_text("plugins:\n enabled: [lifecycle-probe]\n")
+ plugins.discover_plugins(force=True)
+ assert "/lifecycle-probe:guide" in cli.get_skill_commands()
+ config.write_text("plugins:\n enabled: []\n")
+ plugins.discover_plugins(force=True)
+ assert "/lifecycle-probe:guide" not in cli.get_skill_commands()
+ finally:
+ plugins._reset_plugin_managers_for_tests()
+
+ def test_plugin_offer_uses_same_frontmatter_as_load(self, tmp_path, monkeypatch):
+ from hermes_cli import plugins
+ from agent.skill_commands import get_interactive_skill_commands
+ from tools.skills_tool import skill_view
+
+ home = tmp_path / "home"
+ plugin = home / "plugins" / "metadata-probe"
+ md = plugin / "skills" / "guide" / "SKILL.md"
+ md.parent.mkdir(parents=True)
+ (plugin / "plugin.yaml").write_text("name: metadata-probe\nversion: 0.1.0\n")
+ (plugin / "__init__.py").write_text(
+ "from pathlib import Path\ndef register(ctx):\n"
+ " ctx.register_skill('guide', Path(__file__).parent / 'skills' / 'guide' / 'SKILL.md', "
+ "frontmatter={'platforms': ['linux'], 'description': 'Stale registration'})\n")
+ md.write_text("---\nname: guide\ndescription: Current description\n---\nBody.\n")
+ (home / "config.yaml").write_text("plugins:\n enabled: [metadata-probe]\n")
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ plugins._reset_plugin_managers_for_tests()
+ try:
+ assert json.loads(skill_view("metadata-probe:guide"))["success"]
+ assert get_interactive_skill_commands()["/metadata-probe:guide"]["description"] == "Current description"
+ finally:
+ plugins._reset_plugin_managers_for_tests()
+
def test_real_discovery_catalog_completion_dispatch_and_native_separation(self, tmp_path, monkeypatch):
from pathlib import Path
from hermes_cli import plugins
diff --git a/tests/tui_gateway/test_protocol.py b/tests/tui_gateway/test_protocol.py
index cd33b8eaddf..2e705d14d3c 100644
--- a/tests/tui_gateway/test_protocol.py
+++ b/tests/tui_gateway/test_protocol.py
@@ -1484,6 +1484,33 @@ def test_plugin_skill_catalog_completion_dispatch_and_profile_switch(server, tmp
finally:
plugins._reset_plugin_managers_for_tests()
+def test_slash_exec_plugin_command_precedes_colliding_skill(server, tmp_path, monkeypatch):
+ import agent.skill_commands as sc
+ from hermes_cli import plugins
+
+ home = tmp_path / "home"
+ plugin = home / "plugins" / "collision"
+ md = plugin / "skills" / "guide" / "SKILL.md"
+ md.parent.mkdir(parents=True)
+ (plugin / "plugin.yaml").write_text("name: collision\nversion: 0.1.0\n")
+ (plugin / "__init__.py").write_text(
+ "from pathlib import Path\ndef register(ctx):\n"
+ " ctx.register_skill('guide', Path(__file__).parent / 'skills' / 'guide' / 'SKILL.md')\n"
+ " ctx.register_command('collision:guide', lambda arg: 'plugin:' + arg)\n")
+ md.write_text("---\nname: guide\n---\nSkill body.\n")
+ (home / "config.yaml").write_text("plugins:\n enabled: [collision]\n")
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ plugins._reset_plugin_managers_for_tests()
+ try:
+ sid = "collision-session"
+ server._sessions[sid] = {"session_key": sid, "profile_home": home, "agent": None}
+ assert "/collision:guide" in sc.get_interactive_skill_commands()
+ result = server.handle_request({"id": "r", "method": "slash.exec", "params": {
+ "session_id": sid, "command": "/collision:guide hello"}})
+ assert result["result"]["output"] == "plugin:hello"
+ finally:
+ plugins._reset_plugin_managers_for_tests()
+
def test_sessionless_slash_palette_follows_profile_param(server, tmp_path, monkeypatch):
"""A Desktop draft has no session yet: ``commands.catalog`` / ``complete.slash`` must scan the
diff --git a/tests/tui_gateway/test_tui_gateway_server.py b/tests/tui_gateway/test_tui_gateway_server.py
index 4524f4fc6be..49c1ccc1093 100644
--- a/tests/tui_gateway/test_tui_gateway_server.py
+++ b/tests/tui_gateway/test_tui_gateway_server.py
@@ -3092,6 +3092,28 @@ def test_expand_skill_invocation_for_replay_leaves_ordinary_text_alone(monkeypat
# A core slash command is not a skill — nothing to expand.
assert server._expand_skill_invocation_for_replay("/status", "t") == "/status"
+def test_replay_preserves_qualified_plugin_skill(tmp_path, monkeypatch):
+ from hermes_cli import plugins
+
+ home = tmp_path / "home"
+ plugin = home / "plugins" / "replay-probe"
+ md = plugin / "skills" / "guide" / "SKILL.md"
+ md.parent.mkdir(parents=True)
+ (plugin / "plugin.yaml").write_text("name: replay-probe\nversion: 0.1.0\n")
+ (plugin / "__init__.py").write_text(
+ "from pathlib import Path\ndef register(ctx):\n"
+ " ctx.register_skill('guide', Path(__file__).parent / 'skills' / 'guide' / 'SKILL.md')\n")
+ md.write_text("---\nname: guide\n---\nReplay instructions.\n")
+ (home / "config.yaml").write_text("plugins:\n enabled: [replay-probe]\n")
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ plugins._reset_plugin_managers_for_tests()
+ try:
+ expanded = server._expand_skill_invocation_for_replay("/replay-probe:guide do it", "task")
+ assert "Replay instructions." in expanded
+ assert server._skill_scaffold_projection(expanded) == "/replay-probe:guide do it"
+ finally:
+ plugins._reset_plugin_managers_for_tests()
+
def _two_repo_project_skill_sessions(tmp_path, monkeypatch) -> tuple[Path, Path]:
"""Two trusted repos (``alpha-skill`` / ``beta-skill``) bound to sessions ``sid-a`` / ``sid-b``, in a
diff --git a/tui_gateway/methods_tools.py b/tui_gateway/methods_tools.py
index 2df2350374c..5e308a040dd 100644
--- a/tui_gateway/methods_tools.py
+++ b/tui_gateway/methods_tools.py
@@ -1142,6 +1142,13 @@ def _(rid, params: dict) -> dict:
target = base if base in _PENDING_INPUT_COMMANDS else _bundle_key_for(base)
if target is not None:
return _methods["command.dispatch"](rid, {"name": target.lstrip("/"), "arg": arg, "session_id": sid})
+ # Plugin commands have the same precedence as command.dispatch and the CLI;
+ # a same-named skill must not intercept them.
+ if plugin_handler := _plugin_command_handler(base) if base else None:
+ try:
+ return _ok(rid, {"output": _run_plugin_command(plugin_handler, arg, session) or "(no output)"})
+ except Exception as e:
+ return _ok(rid, {"output": f"Plugin command error: {e}"})
# Recognized skills keep the 4018 gate so clients command.dispatch. A scan
# exception must not fail open into the worker: return the dispatch payload
# (or a hard error) here, or the loading banner swallows the prompt.
@@ -1154,11 +1161,6 @@ def _(rid, params: dict) -> dict:
# run it. Anything else might be the skill the scan failed to see.
if (dispatched.get("result") or {}).get("type") or not _is_registry_command(base):
return dispatched
- if plugin_handler := _plugin_command_handler(base) if base else None:
- try:
- return _ok(rid, {"output": _run_plugin_command(plugin_handler, arg, session) or "(no output)"})
- except Exception as e:
- return _ok(rid, {"output": f"Plugin command error: {e}"})
worker = session.get("slash_worker")
if not worker:
# slash.exec runs on the RPC pool: two concurrent commands could both see slash_worker=None
diff --git a/tui_gateway/session_history.py b/tui_gateway/session_history.py
index 0c61dcd1dda..e40dcd9999a 100644
--- a/tui_gateway/session_history.py
+++ b/tui_gateway/session_history.py
@@ -249,7 +249,7 @@ def _expand_skill_invocation_for_replay(text: str, task_id: str) -> str:
return text
try:
from agent.skill_commands import build_skill_invocation_message, resolve_skill_command_key
- cmd_key = resolve_skill_command_key(head.lstrip("/"))
+ cmd_key = resolve_skill_command_key(head.lstrip("/"), interactive=True)
return text if cmd_key is None else (build_skill_invocation_message(cmd_key, arg.strip(), task_id=task_id) or text)
except Exception: # a skill that no longer resolves must not break the rewind
logger.debug("skill re-expansion failed for replay", exc_info=True)