The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(tui): keep the plugin-skill salvage to the slash surface
Teknium9931e3c349d5
diff --git a/tests/agent/test_plugin_skill_boundary.py b/tests/agent/test_plugin_skill_boundary.pydeleted file mode 100644index 4fcb3a8d44f..00000000000--- a/tests/agent/test_plugin_skill_boundary.py+++ /dev/null@@ -1,291 +0,0 @@-"""Regression tests for review findings B1/B2 on the plugin-skills-menu feature.--B1 — the plugin skill projection must be cached: repeating an interactive lookup-must not re-read plugin SKILL.md files per call (completion RPCs run it per-keystroke). Invalidation goes through ``invalidate_plugin_skill_commands()``-(``/reload-skills``, plugin enable/install) so a stale registration hint still-loses to fresh frontmatter after a lifecycle change.--B2 — the messaging gateway's stacked skill path is native/filesystem-only:-plugin skills are interactive-only (CLI/TUI/desktop), so neither-``split_stacked_skill_commands`` in native mode nor a loader fed the native map-may resolve a ``/plugin:skill`` token.-"""--import json-import queue-from pathlib import Path-from unittest.mock import patch--import pytest--from hermes_cli import plugins---def _make_plugin_skill(home: Path, plugin_name: str, skill: str, body: str, description: str = "") -> Path:- """Write a real plugin tree registering one skill and enable it in config."""- plugin = home / "plugins" / plugin_name- md = plugin / "skills" / skill / "SKILL.md"- md.parent.mkdir(parents=True, exist_ok=True)- (plugin / "plugin.yaml").write_text(f"name: {plugin_name}\nversion: 0.1.0\n")- (plugin / "__init__.py").write_text(- "from pathlib import Path\n"- f"def register(ctx):\n"- f" ctx.register_skill({skill!r}, Path(__file__).parent / 'skills' / {skill!r} / 'SKILL.md')\n"- )- desc_line = f"description: {description}\n" if description else ""- md.write_text(f"---\nname: {skill}\n{desc_line}---\n{body}\n")- config = home / "config.yaml"- config.write_text(f"plugins:\n enabled: [{plugin_name}]\n")- return md---def plugin_home(tmp_path, monkeypatch):- home = tmp_path / "home"- home.mkdir()- (home / "config.yaml").write_text("plugins:\n enabled: []\n")- monkeypatch.setenv("HERMES_HOME", str(home))- plugins._reset_plugin_managers_for_tests()- try:- yield home- finally:- plugins._reset_plugin_managers_for_tests()---class TestProjectionCache:- def test_empty_projection_is_cached_until_invalidation(self, plugin_home):- """An initialized empty registry is fresh too; don't rediscover on each lookup."""- import agent.skill_commands as sc-- sc.invalidate_plugin_skill_commands()- with patch.object(sc, "_scan_plugin_skill_commands", wraps=sc._scan_plugin_skill_commands) as scan:- assert sc.get_plugin_skill_commands() == {}- assert sc.get_plugin_skill_commands() == {}- assert scan.call_count == 1-- def test_repeat_lookup_does_not_reread_plugin_skill_files(self, plugin_home):- """B1: a cached interactive lookup must not touch plugin SKILL.md again."""- import agent.skill_commands as sc-- _make_plugin_skill(plugin_home, "cache-probe", "guide", "Body.")- first = sc.get_interactive_skill_commands()- assert "/cache-probe:guide" in first- reads = []- real_read_text = Path.read_text-- def counting_read_text(self, *args, **kwargs):- if self.name == "SKILL.md" and "cache-probe" in str(self):- reads.append(self)- return real_read_text(self, *args, **kwargs)-- with patch.object(Path, "read_text", counting_read_text):- second = sc.get_interactive_skill_commands()- assert second == first- assert reads == []-- def test_invalidate_rebuilds_projection_with_fresh_frontmatter(self, plugin_home):- """A changed description must reach the palette only after invalidation- (the cache serves the last built projection until then)."""- import agent.skill_commands as sc-- md = _make_plugin_skill(plugin_home, "fresh-probe", "guide", "Body.", "Old")- assert sc.get_interactive_skill_commands()["/fresh-probe:guide"]["description"] == "Old"- md.write_text("---\nname: guide\ndescription: New\n---\nBody.\n")- assert sc.get_interactive_skill_commands()["/fresh-probe:guide"]["description"] == "Old"- sc.invalidate_plugin_skill_commands()- assert sc.get_interactive_skill_commands()["/fresh-probe:guide"]["description"] == "New"-- def test_disabled_filter_is_applied_to_cached_projection_live(self, plugin_home):- """Config-only skill disabling takes effect without rebuilding the registry projection."""- import agent.skill_commands as sc-- _make_plugin_skill(plugin_home, "disabled-probe", "guide", "Body.")- assert "/disabled-probe:guide" in sc.get_plugin_skill_commands()- (plugin_home / "config.yaml").write_text(- "plugins:\n enabled: [disabled-probe]\nskills:\n disabled: [guide]\n"- )- assert "/disabled-probe:guide" not in sc.get_plugin_skill_commands()-- def test_profile_switch_self_heals_without_invalidation(self, plugin_home, tmp_path, monkeypatch):- """The cache is keyed on the resolved home: switching profiles must never- serve the other profile's plugin skills."""- import agent.skill_commands as sc-- _make_plugin_skill(plugin_home, "profile-a", "guide", "Body from A.")- assert "/profile-a:guide" in sc.get_interactive_skill_commands()-- other = tmp_path / "home-b"- other.mkdir()- (other / "config.yaml").write_text("plugins:\n enabled: []\n")- monkeypatch.setenv("HERMES_HOME", str(other))- plugins._reset_plugin_managers_for_tests()- try:- commands = sc.get_interactive_skill_commands()- assert "/profile-a:guide" not in commands- finally:- monkeypatch.setenv("HERMES_HOME", str(plugin_home))- plugins._reset_plugin_managers_for_tests()- assert "/profile-a:guide" in sc.get_interactive_skill_commands()-- def test_reload_skills_counts_plugin_skills_and_refreshes_registry(self, plugin_home):- """/reload-skills must rebuild the plugin projection so a plugin enabled- since the last lookup appears, and the receipt must count it."""- import agent.skill_commands as sc-- _make_plugin_skill(plugin_home, "reload-probe", "guide", "Body.")- config = plugin_home / "config.yaml"- config.write_text("plugins:\n enabled: []\n")- first = sc.get_interactive_skill_commands()- assert "/reload-probe:guide" not in first # not enabled yet-- config.write_text("plugins:\n enabled: [reload-probe]\n")- 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):- """B2: the messaging gateway's token scan must stay filesystem-only."""- import agent.skill_commands as sc-- _make_plugin_skill(plugin_home, "boundary-probe", "guide", "Body.")- assert "/boundary-probe:guide" in sc.get_interactive_skill_commands()- keys, instruction = sc.split_stacked_skill_commands("/boundary-probe:guide do it")- assert keys == []- assert instruction == "/boundary-probe:guide do it"- interactive_keys, _ = sc.split_stacked_skill_commands("/boundary-probe:guide do it", interactive=True)- assert interactive_keys == ["/boundary-probe:guide"]-- def test_stacked_loader_with_native_table_refuses_plugin_skill(self, plugin_home):- """The gateway loader is fed its native map: a leaked plugin-skill key- must load nothing (missing), never the plugin body."""- import agent.skill_commands as sc-- _make_plugin_skill(plugin_home, "boundary-probe", "guide", "Plugin body.")- assert sc.build_skill_invocation_message("/boundary-probe:guide", "go") is not None-- result = sc.build_stacked_skill_invocation_message(- ["/boundary-probe:guide"], "go", table=sc.get_skill_commands(),- )- assert result is None-- def test_stacked_loader_defaults_to_interactive_table(self, plugin_home):- """CLI/TUI callers keep the interactive default: a plugin skill loads."""- import agent.skill_commands as sc- _make_plugin_skill(plugin_home, "boundary-probe", "guide", "Plugin body.")- result = sc.build_stacked_skill_invocation_message(["/boundary-probe:guide"], "go")- assert result is not None- assert result[1] == ["boundary-probe:guide"]-- def test_cli_run_skill_slash_command_stacks_plugin_skill(self, plugin_home, capsys):- """The CLI is an interactive surface: ``/<local> /<plugin:skill> do it``- must load BOTH bodies. Guards against the regression where the stacked- token scan silently fell back to the native map in the CLI path."""- import agent.skill_commands as sc- from cli import HermesCLI-- _make_plugin_skill(plugin_home, "cli-stack-probe", "guide", "CLI-PLUGIN-BODY.")- local = plugin_home / "skills" / "local-skill" / "SKILL.md"- local.parent.mkdir(parents=True, exist_ok=True)- local.write_text("---\nname: local-skill\ndescription: Local.\n---\nLOCAL-BODY.\n")- commands = sc.get_interactive_skill_commands()- assert "/cli-stack-probe:guide" in commands- assert "/local-skill" in commands-- class _ReplStub(HermesCLI):- def __init__(self) -> None: # skip the real REPL boot- self.session_id = "test-session"- self._pending_input = queue.Queue()-- repl = _ReplStub.__new__(_ReplStub)- repl.session_id = "test-session"- repl._pending_input = queue.Queue()- repl._run_skill_slash_command(- "/local-skill", commands["/local-skill"], "/cli-stack-probe:guide do the thing",- )- out = capsys.readouterr().out- assert "⚡" in out # stacked load label printed- msg = repl._pending_input.get(timeout=1)- assert "LOCAL-BODY." in msg and "CLI-PLUGIN-BODY." in msgdiff --git a/tests/hermes_cli/test_cli_reload_skills.py b/tests/hermes_cli/test_cli_reload_skills.pyindex 262e329b204..315c6547baf 100644--- a/tests/hermes_cli/test_cli_reload_skills.py+++ b/tests/hermes_cli/test_cli_reload_skills.py@@ -23,67 +23,6 @@ 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-- home = tmp_path / "home"- plugin = home / "plugins" / "live-probe"- skill = plugin / "skills" / "guide" / "SKILL.md"- skill.parent.mkdir(parents=True)- (plugin / "plugin.yaml").write_text("name: live-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: Live guide.\n---\nBody.\n")- config = home / "config.yaml"- config.write_text("plugins:\n enabled: [live-probe]\n")- monkeypatch.setenv("HERMES_HOME", str(home))- monkeypatch.setattr(cli_mod, "_skill_commands", None)- plugins._reset_plugin_managers_for_tests()- try:- shell = _make_cli()- shell._reload_skills()- assert "/live-probe:guide" in cli_mod.get_skill_commands()- config.write_text("plugins:\n enabled: [live-probe]\nskills:\n disabled: [guide]\n")- assert "/live-probe:guide" not in cli_mod.get_skill_commands()- config.write_text("plugins:\n enabled: [live-probe]\n")- assert "/live-probe:guide" in cli_mod.get_skill_commands()- finally:- plugins._reset_plugin_managers_for_tests()-def test_reports_added_and_removed_and_queues_note(self, capsys):cli = _make_cli()with patch(diff --git a/tests/hermes_cli/test_skill_stacked_completion.py b/tests/hermes_cli/test_skill_stacked_completion.pydeleted file mode 100644index 9c8c2e244ad..00000000000--- a/tests/hermes_cli/test_skill_stacked_completion.py+++ /dev/null@@ -1,23 +0,0 @@-"""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"]--def test_stacked_completion_matches_underscored_current_prefix():- commands = {- "/other:guide": {"description": "Other"},- "/plugin:my_skill": {"description": "Underscored"},- }- completer = SlashCommandCompleter(skill_commands_provider=lambda: commands)- results = list(completer._stacked_skill_completions("/other:guide /plugin:my_"))- assert [result.display_text for result in results] == ["/plugin:my_skill"]\ No newline at end of filediff --git a/tests/tools/test_plugin_skills.py b/tests/tools/test_plugin_skills.pyindex 8a54585730a..83538831e7a 100644--- a/tests/tools/test_plugin_skills.py+++ b/tests/tools/test_plugin_skills.py@@ -12,7 +12,6 @@ import osimport sysimport pytest-import cli# ── Namespace helpers ─────────────────────────────────────────────────────@@ -84,136 +83,6 @@ class TestPluginSkillRegistry:# Removing non-existent key is a no-oppm.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- from agent import skill_commands as sc- from tools.skills_tool import skill_view-- home = tmp_path / ".hermes"- plugin = home / "plugins" / "slash-probe"- skill = plugin / "skills" / "guide" / "SKILL.md"- skill.parent.mkdir(parents=True)- (plugin / "plugin.yaml").write_text("name: slash-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: Plugin guide.\n---\n\nFollow the plugin guide.\n")- (home / "config.yaml").write_text("plugins:\n enabled: [slash-probe]\n")- monkeypatch.setenv("HERMES_HOME", str(home))- plugins._reset_plugin_managers_for_tests()- try:- assert json.loads(skill_view("slash-probe:guide"))["success"]- assert "/slash-probe:guide" not in sc.scan_skill_commands()- assert "/slash-probe:guide" in sc.get_interactive_skill_commands()- invoked = sc.build_skill_invocation_message("/slash-probe:guide", "apply it")- assert "Follow the plugin guide." in invoked- assert "apply it" in invoked- preload, loaded, missing = sc.build_preloaded_skills_prompt(["slash-probe:guide"])- assert loaded == ["slash-probe:guide"] and missing == []- assert "Follow the plugin guide." in preload- (home / "config.yaml").write_text("plugins:\n enabled: [slash-probe]\nskills:\n disabled: [guide]\n")- assert "/slash-probe:guide" not in sc.get_interactive_skill_commands()- assert sc.build_preloaded_skills_prompt(["slash-probe:guide"])[2] == ["slash-probe:guide"]- finally:- plugins._reset_plugin_managers_for_tests()-- def test_supporting_file_hint_keeps_plugin_namespace_on_local_name_collision(self, tmp_path, monkeypatch):- from hermes_cli import plugins- from agent import skill_commands as sc- from tools.skills_tool import skill_view-- home = tmp_path / ".hermes"- plugin = home / "plugins" / "hint-probe"- plugin_skill = plugin / "skills" / "guide"- plugin_skill.mkdir(parents=True)- (plugin / "plugin.yaml").write_text("name: hint-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"- )- (plugin_skill / "SKILL.md").write_text(- "---\nname: guide\ndescription: Plugin guide.\n---\n\nPlugin skill body.\n"- )- plugin_notes = plugin_skill / "references" / "notes.md"- plugin_notes.parent.mkdir()- plugin_notes.write_text("PLUGIN SUPPORT FILE\n")-- local_skill = home / "skills" / "guide"- local_notes = local_skill / "references" / "notes.md"- local_notes.parent.mkdir(parents=True)- local_notes.write_text("LOCAL SUPPORT FILE\n")- (local_skill / "SKILL.md").write_text(- "---\nname: guide\ndescription: Local guide.\n---\n\nLocal skill body.\n"- )- (home / "config.yaml").write_text("plugins:\n enabled: [hint-probe]\n")- monkeypatch.setenv("HERMES_HOME", str(home))- plugins._reset_plugin_managers_for_tests()- try:- message = sc.build_skill_invocation_message("/hint-probe:guide")- assert 'skill_view(name="hint-probe:guide"' in message-- support = json.loads(skill_view("hint-probe:guide", file_path="references/notes.md"))- assert support["content"] == "PLUGIN SUPPORT FILE\n"- local = json.loads(skill_view("guide", file_path="references/notes.md"))- assert local["content"] == "LOCAL SUPPORT FILE\n"- finally:- plugins._reset_plugin_managers_for_tests()--class TestPluginContextRegisterSkill:@pytest.fixturedef ctx(self, tmp_path, monkeypatch):diff --git a/tests/tui_gateway/test_interactive_profile_skill_scope.py b/tests/tui_gateway/test_interactive_profile_skill_scope.pydeleted file mode 100644index 1b16cf80dd9..00000000000--- a/tests/tui_gateway/test_interactive_profile_skill_scope.py+++ /dev/null@@ -1,96 +0,0 @@-"""Interactive plugin skill discovery must bind complete profile runtime scope."""--import os-from pathlib import Path--import pytest--import tui_gateway.server as server---def test_plugin_skill_rpc_paths_isolate_secrets_across_profiles(tmp_path, monkeypatch):- from agent import secret_scope- from hermes_cli import env_loader, plugins- import hermes_constants- import tui_gateway.launch_profile_policy as launch_policy-- launch_home = tmp_path / "relocated" / "hermes" / "default"- profiles_root = launch_home / "profiles"- homes = {"alpha": profiles_root / "alpha", "beta": profiles_root / "beta"}- launch_home.mkdir(parents=True)- monkeypatch.setenv("HERMES_HOME", str(launch_home))- monkeypatch.setenv("PLUGIN_SCOPE_TOKEN", "launch-only-test-secret")- monkeypatch.setattr(hermes_constants, "_default_hermes_root_memo", None)- monkeypatch.setattr(server, "_hermes_home", launch_home)- monkeypatch.setattr(server, "_served_profile_homes", set())- monkeypatch.setattr(secret_scope, "_MULTIPLEX_ACTIVE", False)- monkeypatch.setattr(launch_policy, "_snapshot", None)-- secrets = {"alpha": "alpha-test-secret", "beta": "beta-test-secret"}- for label, home in homes.items():- plugin = home / "plugins" / f"scope-{label}"- skill = plugin / "skills" / "guide" / "SKILL.md"- skill.parent.mkdir(parents=True)- (plugin / "plugin.yaml").write_text(f"name: scope-{label}\nversion: 0.1.0\n")- (plugin / "__init__.py").write_text(- "from pathlib import Path\nfrom agent.secret_scope import get_secret\n"- "def register(ctx):\n"- f" if get_secret('PLUGIN_SCOPE_TOKEN') != {secrets[label]!r}:\n"- " raise RuntimeError('plugin secret scope mismatch')\n"- " ctx.register_skill('guide', Path(__file__).parent / 'skills' / 'guide' / 'SKILL.md')\n"- )- skill.write_text(- f"---\nname: guide\ndescription: {label} guide.\n---\n\n{label} instructions.\n"- )- (home / "config.yaml").write_text(f"plugins:\n enabled: [scope-{label}]\n")- (home / ".env").write_text(f"PLUGIN_SCOPE_TOKEN={secrets[label]}\n")-- env_loader.reset_secret_source_cache()- plugins._reset_plugin_managers_for_tests()- try:- # Session-less palette supports the relocated default root and each named profile.- default_palette = server.handle_request({- "id": "palette-default", "method": "commands.catalog", "params": {"profile": "default"},- })- assert "result" in default_palette, default_palette- for label in ("alpha", "beta"):- palette = server.handle_request({- "id": f"palette-{label}", "method": "commands.catalog", "params": {"profile": label},- })- assert f"/scope-{label}:guide" in palette["result"]["skills"], palette-- # Exercise catalog, completion, slash.exec and command.dispatch A -> B -> A.- for label in ("alpha", "beta", "alpha"):- sid = f"scope-{label}-{len(server._sessions)}"- server._sessions[sid] = {- "session_key": sid, "agent": None, "profile_home": str(homes[label]),- }- command = f"/scope-{label}: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"/scope-{label}:"},- })- dispatched = server.handle_request({- "id": "dispatch", "method": "command.dispatch",- "params": {"session_id": sid, "name": command[1:], "arg": "apply"},- })- slash = server.handle_request({- "id": "slash", "method": "slash.exec",- "params": {"session_id": sid, "command": command + " apply"},- })- assert command in catalog["result"]["skills"], catalog- assert any(item["text"] == command[1:] and item["kind"] == "skill"- for item in completed["result"]["items"]), completed- assert dispatched["result"]["type"] == "skill", dispatched- assert f"{label} instructions." in dispatched["result"]["message"]- assert slash.get("error", {}).get("code") == 4018, slash- assert os.environ["PLUGIN_SCOPE_TOKEN"] == "launch-only-test-secret"- assert hermes_constants.get_hermes_home_override() is None- with pytest.raises(secret_scope.UnscopedSecretError):- secret_scope.get_secret("PLUGIN_SCOPE_TOKEN")- finally:- plugins._reset_plugin_managers_for_tests()- env_loader.reset_secret_source_cache()diff --git a/tests/tui_gateway/test_tui_gateway_server.py b/tests/tui_gateway/test_tui_gateway_server.pyindex 5861fc95686..4524f4fc6be 100644--- a/tests/tui_gateway/test_tui_gateway_server.py+++ b/tests/tui_gateway/test_tui_gateway_server.py@@ -3092,28 +3092,6 @@ 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@@ -3272,8 +3250,6 @@ 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).diff --git a/tui_gateway/methods_tools.py b/tui_gateway/methods_tools.pyindex 317a802c90e..8e75cc17f5a 100644--- a/tui_gateway/methods_tools.py+++ b/tui_gateway/methods_tools.py@@ -493,9 +493,7 @@ def _catalog_skills(cat: _Catalog, skills: dict[str, dict]) -> str:usage, origin_of = _skill_usage_lookup()sc = _tools_mod("agent.skill_commands")for k, info in sorted(sc.get_interactive_skill_commands().items()):- if k.lower() in cat.canon:- continue- cat.add(k, str(info.get("description", "Skill")), "Skills")+ cat.pairs.append([k, str(info.get("description", "Skill"))])name = str(info.get("name") or k.lstrip("/"))skills[k] = {"usage": usage(name), "origin": origin_of(name)}names = sorted(s["name"] for s in _tools_mod("tools.skills_tool")._find_all_skills())@@ -611,7 +609,7 @@ def _run_plugin_command(handler, arg: str, session=None) -> str:@contextlib.contextmanagerdef _session_home_scope(session, cwd: str | None = None, profile: str | None = None):- """Bind the session's full runtime profile scope and logical cwd for interactive resolution.+ """Bind HERMES_HOME and the logical cwd to the session for the block.Skill/bundle/quick-command resolution is home-keyed (``skills.external_dirs``, ``skill-bundles/``,``quick_commands`` all live in the profile's config/home); nothing upstream of these RPC handlers@@ -620,21 +618,22 @@ def _session_home_scope(session, cwd: str | None = None, profile: str | None = Nthread with no session context, where the terminal scope resolves a placeholder ``terminal.cwd`` to``$HOME`` and no project skill ever registers or dispatches (#114359). ``cwd`` overrides the sessionrecord (a session-less catalog request binds the workspace a new session would be seeded with).- ``profile`` scopes a session-less call (a Desktop draft names its rail-selected profile) (#124651).- Plugin discovery may execute ``register()`` and read profile secrets or terminal policy, so home- alone is insufficient; use the same full scope as a session turn and always reset cwd before it."""+ ``profile`` scopes a session-less call (a Desktop draft names its rail-selected profile) (#124651)."""+ hc = _tools_mod("hermes_constants")rc = _tools_mod("agent.runtime_cwd")profile_home = session.get("profile_home") if session else Noneif not session and profile:profile_home = str(_profile_home(profile) or "") or Nonecwd = cwd or (str(session.get("cwd") or "") if session else "")- with _session_profile_runtime_scope({"profile_home": str(profile_home) if profile_home else None}):- cwd_token = rc.set_session_cwd(cwd) if cwd else None- try:- yield- finally:- if cwd_token is not None:- rc.reset_session_cwd(cwd_token)+ token = hc.set_hermes_home_override(profile_home) if profile_home else None+ cwd_token = rc.set_session_cwd(cwd) if cwd else None+ try:+ yield+ finally:+ if cwd_token is not None:+ rc.reset_session_cwd(cwd_token)+ if token is not None:+ hc.reset_hermes_home_override(token)def _profile_skill_command(session: dict, base: str) -> bool | None:@@ -1136,21 +1135,11 @@ def _(rid, params: dict) -> dict:if base in _WORKER_BLOCKED_COMMANDS and _is_snapshot_restore(arg):return _err(rid, 4018, "snapshot restore mutates live config/state; use command.dispatch for /snapshot restore")# Pending-input built-ins route straight to command.dispatch (some clients fail the- # error-then-retry fallback).- if base in _PENDING_INPUT_COMMANDS:- return _methods["command.dispatch"](rid, {"name": base, "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.- with _session_home_scope(session):- 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}"})+ # error-then-retry fallback); bundles go the same way under their resolved key.with _session_home_scope(session): # a secondary-only bundle must route too (#110695)- bundle_key = _bundle_key_for(base)- if bundle_key is not None:- return _methods["command.dispatch"](rid, {"name": bundle_key.lstrip("/"), "arg": arg, "session_id": sid})+ 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})# 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.@@ -1163,6 +1152,11 @@ 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