The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): stacked /plugin:a /plugin:b loads every plugin skill
Teknium639f0b6ffef1
diff --git a/tests/tui_gateway/test_plugin_skill_slash.py b/tests/tui_gateway/test_plugin_skill_slash.pynew file mode 100644index 00000000000..d91b987816c--- /dev/null+++ b/tests/tui_gateway/test_plugin_skill_slash.py@@ -0,0 +1,57 @@+"""Plugin-registered skills in the TUI/Desktop slash menu (``/plugin:skill``).++``tui_gateway.server`` is imported at module level, not through a mocked import window: the+profile scope must bind the real ``hermes_constants`` home override for A->B->A to mean anything.+"""++import tui_gateway.server as server+++def test_plugin_skills_reach_tui_slash_menu_and_stack_per_profile(tmp_path, monkeypatch):+ """``ctx.register_skill`` skills are offered and dispatched as ``/plugin:skill`` in the+ TUI/Desktop slash menu, scoped to the session's profile, and a stacked+ ``/plugin:a /plugin:b`` loads both bodies. Native skill menus stay filesystem-only."""+ from agent import skill_commands+ from hermes_cli import plugins++ homes = {"alpha": tmp_path / "profile-a", "beta": tmp_path / "profile-b"}+ for label, home in homes.items():+ plugin = home / "plugins" / f"probe-{label}"+ plugin.mkdir(parents=True)+ (plugin / "plugin.yaml").write_text(f"name: probe-{label}\nversion: 0.1.0\n")+ (plugin / "__init__.py").write_text(+ "from pathlib import Path\ndef register(ctx):\n"+ " for name in ('guide', 'review'):\n"+ " ctx.register_skill(name, Path(__file__).parent / 'skills' / name / 'SKILL.md')\n")+ for name in ("guide", "review"):+ md = plugin / "skills" / name / "SKILL.md"+ md.parent.mkdir(parents=True)+ md.write_text(f"---\nname: {name}\ndescription: {label} {name}.\n---\n\n{label}-{name}-body\n")+ (home / "config.yaml").write_text(f"plugins:\n enabled: [probe-{label}]\n")++ monkeypatch.setenv("HERMES_HOME", str(homes["alpha"]))+ plugins._reset_plugin_managers_for_tests()+ try:+ for label in ("alpha", "beta", "alpha"):+ sid, other = f"skill-{label}", "beta" if label == "alpha" else "alpha"+ server._sessions[sid] = {"session_key": sid, "profile_home": str(homes[label]), "agent": None}+ guide, review = f"/probe-{label}:guide", f"/probe-{label}:review"+ catalog = server.handle_request({"id": "c", "method": "commands.catalog", "params": {"session_id": sid}})+ completed = server.handle_request({"id": "t", "method": "complete.slash",+ "params": {"session_id": sid, "text": f"/probe-{label}:"}})+ stacked = server.handle_request({"id": "d", "method": "command.dispatch", "params": {+ "session_id": sid, "name": guide[1:], "arg": f"{review} apply it"}})+ assert guide in catalog["result"]["skills"], catalog+ assert f"/probe-{other}:guide" not in catalog["result"]["skills"]+ assert {i["text"] for i in completed["result"]["items"] if i["kind"] == "skill"} >= {+ guide[1:], review[1:]}, completed+ result = stacked["result"]+ assert result["type"] == "skill", stacked+ assert f"{label}-guide-body" in result["message"] and f"{label}-review-body" in result["message"]+ assert "apply it" in result["message"]+ assert result.get("notice", "").startswith("⚡ Loading 2 stacked skills"), result+ assert guide not in skill_commands.get_skill_commands()+ finally:+ for label in homes:+ server._sessions.pop(f"skill-{label}", None)+ plugins._reset_plugin_managers_for_tests()diff --git a/tests/tui_gateway/test_protocol.py b/tests/tui_gateway/test_protocol.pyindex d8e7cb99f52..7ddaa246b09 100644--- a/tests/tui_gateway/test_protocol.py+++ b/tests/tui_gateway/test_protocol.py@@ -1445,122 +1445,6 @@ def test_command_dispatch_stacked_split_keeps_unknown_tokens_as_instruction(servassert "/not-a-skill-command but /model is a registry command" in result["message"]-def test_plugin_skill_catalog_completion_dispatch_and_profile_switch(server, tmp_path, monkeypatch):- """Real plugin registration reaches every interactive RPC but not native skill menus."""- from hermes_cli import plugins- from agent import skill_commands-- homes = [tmp_path / "profile-a", tmp_path / "profile-b"]- for home, suffix in zip(homes, ("alpha", "beta")):- plugin = home / "plugins" / f"probe-{suffix}"- md = plugin / "skills" / "guide" / "SKILL.md"- md.parent.mkdir(parents=True)- (plugin / "plugin.yaml").write_text(f"name: probe-{suffix}\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(f"---\nname: guide\ndescription: {suffix} guide.\n---\n\n{suffix} instructions.\n")- (home / "config.yaml").write_text(f"plugins:\n enabled: [probe-{suffix}]\n")-- monkeypatch.setenv("HERMES_HOME", str(homes[0]))- plugins._reset_plugin_managers_for_tests()- try:- for home, suffix in ((homes[0], "alpha"), (homes[1], "beta"), (homes[0], "alpha")):- sid = f"skill-{suffix}"- server._sessions[sid] = {"session_key": sid, "profile_home": str(home), "agent": None}- key = f"/probe-{suffix}:guide"- catalog = server.handle_request({"id": "cat", "method": "commands.catalog", "params": {"session_id": sid}})- completed = server.handle_request({"id": "complete", "method": "complete.slash", "params": {"session_id": sid, "text": f"/probe-{suffix}:"}})- dispatched = server.handle_request({"id": "dispatch", "method": "command.dispatch", "params": {"session_id": sid, "name": key[1:], "arg": "apply"}})- assert key in catalog["result"]["skills"], catalog- assert any(item["text"] == key[1:] and item["kind"] == "skill" for item in completed["result"]["items"]), completed- assert dispatched["result"]["type"] == "skill", dispatched- assert f"{suffix} instructions." in dispatched["result"]["message"]- assert "apply" in dispatched["result"]["message"]- assert key not in skill_commands.get_skill_commands()- other = "beta" if suffix == "alpha" else "alpha"- assert f"/probe-{other}:guide" not in catalog["result"]["skills"]- 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 agent.skill_bundles import resolve_bundle_command_key- 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"- " ctx.register_command('collision-guide', lambda arg: 'bundle-plugin:' + arg)\n")- md.write_text("---\nname: guide\n---\nSkill body.\n")- bundles_dir = home / "skill-bundles"- bundles_dir.mkdir()- (bundles_dir / "collision-guide.yaml").write_text(- "name: collision-guide\nskills: [collision:guide]\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()- assert resolve_bundle_command_key("collision-guide") == "/collision-guide"- for method, params in (- ("command.dispatch", {"session_id": sid, "name": "collision:guide", "arg": "hello"}),- ("slash.exec", {"session_id": sid, "command": "/collision:guide hello"}),- ):- result = server.handle_request({"id": "r", "method": method, "params": params})- assert result["result"]["output"] == "plugin:hello", (method, result)- for method, params in (- ("command.dispatch", {"session_id": sid, "name": "collision-guide", "arg": "hello"}),- ("slash.exec", {"session_id": sid, "command": "/collision-guide hello"}),- ):- result = server.handle_request({"id": "r", "method": method, "params": params})- expected = ({"output": "bundle-plugin:hello"} if method == "slash.exec" else- {"type": "plugin", "output": "bundle-plugin:hello"})- assert result["result"] == expected, (method, result)- finally:- plugins._reset_plugin_managers_for_tests()---def test_slash_exec_plugin_command_uses_own_profile_when_names_collide(server, tmp_path, monkeypatch):- """Both RPC routes choose the session's plugin, not the gateway launch home's plugin."""- from hermes_cli import plugins-- homes = (tmp_path / "profile-a", tmp_path / "profile-b")- for home, label in zip(homes, ("alpha", "beta")):- plugin = home / "plugins" / "scope-probe"- plugin.mkdir(parents=True)- (plugin / "plugin.yaml").write_text("name: scope-probe\nversion: 0.1.0\n")- (plugin / "__init__.py").write_text(- "def register(ctx):\n"- f" ctx.register_command('scope-probe', lambda arg: '{label}:' + arg)\n"- )- (home / "config.yaml").write_text("plugins:\n enabled: [scope-probe]\n")-- monkeypatch.setenv("HERMES_HOME", str(homes[0]))- plugins._reset_plugin_managers_for_tests()- try:- for label, home in (("alpha", homes[0]), ("beta", homes[1]), ("alpha", homes[0])):- sid = f"scope-{label}"- server._sessions[sid] = {"session_key": sid, "profile_home": str(home), "agent": None}- for method, params in (- ("command.dispatch", {"session_id": sid, "name": "scope-probe", "arg": "go"}),- ("slash.exec", {"session_id": sid, "command": "/scope-probe go"}),- ):- result = server.handle_request({"id": "r", "method": method, "params": params})- assert result["result"]["output"] == f"{label}:go", (method, result)- 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 thenamed ``profile``'s home, not the launch profile's — A→B→A under multiplexing (#124651). Thediff --git a/tui_gateway/methods_tools.py b/tui_gateway/methods_tools.pyindex ccb05202e82..317a802c90e 100644--- a/tui_gateway/methods_tools.py+++ b/tui_gateway/methods_tools.py@@ -724,7 +724,7 @@ def _dispatch_skill(rid, params, session, name, arg):# Stacked leading /skill tokens (up to 5, cli.py + gateway parity, #74705): the# first token matched above; consume any further leading skill tokens from `arg`,# then build one invocation that loads every skill over the remaining instruction.- extra_keys, user_instruction = sc.split_stacked_skill_commands(arg)+ extra_keys, user_instruction = sc.split_stacked_skill_commands(arg, interactive=True)if extra_keys:stacked = sc.build_stacked_skill_invocation_message([key, *extra_keys], user_instruction,