Skip to content

The agent that grows with you

fix(skills): include plugin commands in reload receipt

Hermes Agent0bef04dcc727
diff --git a/agent/skill_commands.py b/agent/skill_commands.py
index 3b46c587953..3e3c802d1a2 100644
--- a/agent/skill_commands.py
+++ b/agent/skill_commands.py
@@ -26,6 +26,9 @@ logger = logging.getLogger(__name__)
# publication and the freshness lookup so a reader always sees a consistent
# (key, map) pair. Scanning stays outside the lock (#14536, #74574).
_skill_commands_by_key: Dict[tuple, Dict[str, Dict[str, Any]]] = {}
+# Keep the last map callers could actually see, even when plugin lifecycle
+# invalidation drops the projection cache before /reload-skills can diff it.
+_last_interactive_skill_commands_by_key: Dict[tuple, Dict[str, Dict[str, Any]]] = {}
_publish_lock = threading.Lock()
# ``\w`` keeps Unicode letters (CJK, Cyrillic) so a ``name: 小说拆条`` skill registers ``/小说拆条``
# instead of slugging to "" and being dropped (#12351); Telegram's ``[a-z0-9_]`` menu limit is
@@ -631,15 +634,26 @@ def _scan_plugin_skill_commands() -> Dict[str, Dict[str, Any]]:
return commands
+def _merge_interactive_skill_commands(
+ filesystem_commands: Dict[str, Dict[str, Any]], plugin_commands: Dict[str, Dict[str, Any]],
+) -> Dict[str, Dict[str, Any]]:
+ """Merge interactive sources with filesystem commands winning collisions."""
+ commands = dict(filesystem_commands)
+ for command, info in plugin_commands.items():
+ if command in commands:
+ logger.warning("Plugin skill %r collides with %r; keeping the first", command, commands[command]["name"])
+ else:
+ commands[command] = info
+ return commands
+
+
def get_interactive_skill_commands() -> Dict[str, Dict[str, Any]]:
"""Filesystem skills plus profile-scoped plugin skills; never use for
messaging/native command menus (plugin skills are CLI/TUI/desktop only)."""
- commands = dict(get_skill_commands())
- for key, info in get_plugin_skill_commands().items():
- if key in commands:
- logger.warning("Plugin skill %r collides with %r; keeping the first", key, commands[key]["name"])
- else:
- commands[key] = info
+ identity = (_resolve_skill_commands_platform(), _resolve_skill_commands_home(), _resolve_skill_commands_project())
+ commands = _merge_interactive_skill_commands(get_skill_commands(), get_plugin_skill_commands())
+ with _publish_lock:
+ _last_interactive_skill_commands_by_key[identity] = dict(commands)
return commands
@@ -668,17 +682,31 @@ def reload_skills() -> Dict[str, Any]:
since the last scan shows up without a restart."""
key = (_resolve_skill_commands_platform(), _resolve_skill_commands_home(), _resolve_skill_commands_project())
with _publish_lock:
- before_commands = _skill_commands_by_key.get(key, {})
+ before_commands = _last_interactive_skill_commands_by_key.get(key)
+ if before_commands is None:
+ # Preserve only a previously published view. A first-ever reload has
+ # no before-state, so discoveries correctly appear as additions.
+ with _publish_lock:
+ before_commands = dict(_skill_commands_by_key.get(key, {}))
+ if _plugin_skill_commands_home == key[1]:
+ for command, info in _plugin_skill_commands.items():
+ if command not in before_commands:
+ before_commands[command] = info
+ before = command_snapshot(before_commands)
+ with _publish_lock:
# Clear the entire multi-slot cache: a skill edit could affect any
# platform/profile combination, so every cached identity must rescan.
_skill_commands_by_key.clear()
from tools.skills_tool import clear_skills_cache
clear_skills_cache() # the scan reads the shared catalog; an explicit reload must not hit its TTL
- before = command_snapshot(before_commands)
invalidate_plugin_skill_commands()
new_commands = scan_skill_commands()
- result = diff_command_snapshots(before, command_snapshot(new_commands))
- result["commands"] = len(new_commands) + len(get_plugin_skill_commands())
+ effective_commands = _merge_interactive_skill_commands(new_commands, get_plugin_skill_commands())
+ after = command_snapshot(effective_commands)
+ result = diff_command_snapshots(before, after)
+ with _publish_lock:
+ _last_interactive_skill_commands_by_key[key] = effective_commands
+ result["commands"] = len(effective_commands)
return result
diff --git a/tests/agent/test_plugin_skill_boundary.py b/tests/agent/test_plugin_skill_boundary.py
index 50abe0f4d4b..8e335fa9839 100644
--- a/tests/agent/test_plugin_skill_boundary.py
+++ b/tests/agent/test_plugin_skill_boundary.py
@@ -126,8 +126,87 @@ class TestProjectionCache:
plugins.discover_plugins(force=True)
result = sc.reload_skills()
assert "/reload-probe:guide" in sc.get_plugin_skill_commands()
+ assert result["added"] == [{"name": "reload-probe:guide", "description": "Invoke the reload-probe:guide plugin skill"}]
+ assert result["removed"] == []
+ assert result["total"] == len(sc.get_interactive_skill_commands())
assert result["commands"] == len(sc.get_skill_commands()) + 1
+ def test_reload_receipt_uses_effective_set_on_never_scanned_home(self, plugin_home):
+ """A first reload reports newly visible commands and subsequent reloads are stable."""
+ import agent.skill_commands as sc
+
+ _make_plugin_skill(plugin_home, "receipt-probe", "guide", "Plugin body.")
+ local = plugin_home / "skills" / "receipt-probe-guide" / "SKILL.md"
+ local.parent.mkdir(parents=True)
+ local.write_text("---\nname: receipt-probe:guide\ndescription: Local wins.\n---\nLocal body.\n")
+ config = plugin_home / "config.yaml"
+ config.write_text("plugins:\n enabled: [receipt-probe]\n")
+
+ first = sc.reload_skills()
+ visible = sc.get_interactive_skill_commands()
+ assert "/receipt-probe:guide" in visible
+ assert {item["name"] for item in first["added"]} == {"receipt-probeguide", "receipt-probe:guide"}
+ assert first["removed"] == []
+ assert first["total"] == len(visible)
+ assert first["commands"] == len(visible)
+
+ repeated = sc.reload_skills()
+ assert repeated["added"] == []
+ assert repeated["removed"] == []
+ assert repeated["total"] == len(visible)
+ assert repeated["commands"] == len(visible)
+
+ def test_reload_receipt_keeps_last_visible_plugin_snapshot_through_invalidation(self, plugin_home):
+ """Lifecycle invalidation must not erase the pre-reload view used for the receipt."""
+ import agent.skill_commands as sc
+
+ _make_plugin_skill(plugin_home, "visible-probe", "guide", "Body.")
+ visible = sc.get_interactive_skill_commands()
+ assert "/visible-probe:guide" in visible
+
+ config = plugin_home / "config.yaml"
+ config.write_text("plugins:\n enabled: []\n")
+ plugins.discover_plugins(force=True)
+ sc.invalidate_plugin_skill_commands()
+
+ result = sc.reload_skills()
+ assert result["removed"] == [{"name": "visible-probe:guide", "description": "Invoke the visible-probe:guide plugin skill"}]
+ assert result["added"] == []
+ assert result["total"] == len(sc.get_interactive_skill_commands())
+ assert result["commands"] == result["total"]
+
+ config.write_text("plugins:\n enabled: [visible-probe]\n")
+ plugins.discover_plugins(force=True)
+ assert "/visible-probe:guide" in sc.get_interactive_skill_commands()
+ import shutil
+ shutil.rmtree(plugin_home / "plugins" / "visible-probe")
+ plugins.discover_plugins(force=True)
+ sc.invalidate_plugin_skill_commands()
+ removed = sc.reload_skills()
+ assert removed["removed"] == [{"name": "visible-probe:guide", "description": "Invoke the visible-probe:guide plugin skill"}]
+ assert removed["total"] == removed["commands"] == len(sc.get_interactive_skill_commands())
+
+ def test_reload_receipt_is_isolated_across_profile_switches(self, plugin_home, tmp_path, monkeypatch):
+ """A's cached before-snapshot must never be reported as B's removals."""
+ import agent.skill_commands as sc
+
+ _make_plugin_skill(plugin_home, "profile-receipt-a", "guide", "A body.")
+ first = sc.get_interactive_skill_commands()
+ assert "/profile-receipt-a:guide" in first
+
+ other = tmp_path / "home-b"
+ other.mkdir()
+ (other / "config.yaml").write_text("plugins:\n enabled: []\n")
+ (other / "skills" / "local-b" / "SKILL.md").parent.mkdir(parents=True)
+ (other / "skills" / "local-b" / "SKILL.md").write_text(
+ "---\nname: local-b\ndescription: B body\n---\nBody.\n")
+ monkeypatch.setenv("HERMES_HOME", str(other))
+ plugins._reset_plugin_managers_for_tests()
+ result = sc.reload_skills()
+ assert result["removed"] == []
+ assert all(item["name"] != "profile-receipt-a:guide" for item in result["removed"])
+ assert result["total"] == result["commands"] == len(sc.get_interactive_skill_commands())
+
class TestNativeStackedBoundary:
def test_split_native_mode_never_resolves_plugin_skill_token(self, plugin_home):
diff --git a/tests/hermes_cli/test_cli_reload_skills.py b/tests/hermes_cli/test_cli_reload_skills.py
index 2377cce86e0..262e329b204 100644
--- a/tests/hermes_cli/test_cli_reload_skills.py
+++ b/tests/hermes_cli/test_cli_reload_skills.py
@@ -23,6 +23,38 @@ def _make_cli():
class TestReloadSkillsCLI:
+ def test_renders_real_plugin_removal_and_queues_next_turn_note(self, tmp_path, monkeypatch, capsys):
+ import agent.skill_commands as skill_commands
+ from hermes_cli import plugins
+
+ home = tmp_path / "home"
+ plugin = home / "plugins" / "render-probe"
+ skill = plugin / "skills" / "guide" / "SKILL.md"
+ skill.parent.mkdir(parents=True)
+ (plugin / "plugin.yaml").write_text("name: render-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")
+ skill.write_text("---\nname: guide\ndescription: Rendered guide.\n---\nBody.\n")
+ config = home / "config.yaml"
+ config.write_text("plugins:\n enabled: [render-probe]\n")
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ plugins._reset_plugin_managers_for_tests()
+ try:
+ assert "/render-probe:guide" in skill_commands.get_interactive_skill_commands()
+ config.write_text("plugins:\n enabled: []\n")
+ plugins.discover_plugins(force=True)
+ skill_commands.invalidate_plugin_skill_commands()
+
+ cli = _make_cli()
+ cli._reload_skills()
+ output = capsys.readouterr().out
+ assert "render-probe:guide" in output
+ assert "0 skill(s) available" in output
+ assert "render-probe:guide" in cli._pending_skills_reload_note
+ finally:
+ plugins._reset_plugin_managers_for_tests()
+
def test_reload_keeps_plugin_skill_lookup_live_after_plugin_lifecycle(self, tmp_path, monkeypatch):
import cli as cli_mod
from hermes_cli import plugins
diff --git a/tests/tui_gateway/test_tui_gateway_server.py b/tests/tui_gateway/test_tui_gateway_server.py
index 49c1ccc1093..5861fc95686 100644
--- a/tests/tui_gateway/test_tui_gateway_server.py
+++ b/tests/tui_gateway/test_tui_gateway_server.py
@@ -3272,6 +3272,8 @@ def test_complete_slash_and_skills_reload_are_bound_to_the_session_cwd(tmp_path,
"result"]["type"] == "skill"
reload = server._methods["skills.reload"]("r", {"session_id": "sid-a"})["result"]
assert reload["result"]["removed"] == [], reload["output"]
+ assert reload["result"]["total"] == reload["result"]["commands"]
+ assert f"{reload['result']['total']} skill(s) available" in reload["output"]
# The session-bound registry still offers the project skill after the reload
# (the multi-slot cache keeps each session-identity's view; the launch-env
# identity outside any session legitimately sees none of them).