Skip to content

The agent that grows with you

fix(tui): scope slash plugin dispatch to session profile

Hermes Agent1e0dff2a2077
diff --git a/tests/tui_gateway/test_protocol.py b/tests/tui_gateway/test_protocol.py
index 2e7ce6f2418..d8e7cb99f52 100644
--- a/tests/tui_gateway/test_protocol.py
+++ b/tests/tui_gateway/test_protocol.py
@@ -1530,6 +1530,37 @@ def test_slash_exec_plugin_command_precedes_colliding_skill(server, tmp_path, mo
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 the
named ``profile``'s home, not the launch profile's — A→B→A under multiplexing (#124651). The
diff --git a/tui_gateway/methods_tools.py b/tui_gateway/methods_tools.py
index bb0331b4332..07343908e74 100644
--- a/tui_gateway/methods_tools.py
+++ b/tui_gateway/methods_tools.py
@@ -1142,11 +1142,12 @@ def _(rid, params: dict) -> dict:
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.
- 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}"})
+ 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}"})
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: