The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): scope slash.exec's skill-command check to the session's profile
chelsealongc0f89d2545ba
diff --git a/tests/tui_gateway/test_protocol.py b/tests/tui_gateway/test_protocol.pyindex f0437808486..7b27ae62530 100644--- a/tests/tui_gateway/test_protocol.py+++ b/tests/tui_gateway/test_protocol.py@@ -785,6 +785,59 @@ def test_slash_exec_rejects_skill_commands(server):assert "skill command" in resp["error"]["message"]+def test_slash_exec_scopes_skill_lookup_to_session_profile(server, tmp_path):+ """slash.exec must resolve get_skill_commands() against the session's own+ profile_home rather than the gateway process's ambient HERMES_HOME+ (#88023). A Desktop session that switches profiles mid-session shares+ the same gateway process, so a skill declared only under the new+ profile's skills.external_dirs must still be recognized here — else the+ command falls through to the slash-worker dead path instead of routing+ to command.dispatch.+ """+ import agent.skill_commands as sc_mod++ empty_local_dir = tmp_path / "no-local-skills"+ empty_local_dir.mkdir()++ profile_b = tmp_path / "profile_b"+ external_b = tmp_path / "external_b"+ profile_b.mkdir()+ skill_dir = external_b / "b-only"+ skill_dir.mkdir(parents=True)+ (skill_dir / "SKILL.md").write_text(+ "---\nname: b-only\ndescription: Only in profile b.\n---\n\n# b-only\n\nDo the thing.\n"+ )+ (profile_b / "config.yaml").write_text(+ f"skills:\n external_dirs:\n - {external_b}\n"+ )++ sid = "test-session-profile-b"+ server._sessions[sid] = {+ "session_key": sid,+ "agent": None,+ "profile_home": str(profile_b),+ }++ with (+ patch("tools.skills_tool.SKILLS_DIR", empty_local_dir),+ patch.object(sc_mod, "_skill_commands", {}),+ patch.object(sc_mod, "_skill_commands_platform", None),+ patch.object(sc_mod, "_skill_commands_home", None),+ ):+ resp = server.handle_request({+ "id": "r1",+ "method": "slash.exec",+ "params": {"command": "b-only", "session_id": sid},+ })++ # The gateway's own HERMES_HOME (the test-isolation tempdir, no+ # skills.external_dirs) has no "b-only" skill — the only way this+ # resolves is by scoping the lookup to the session's profile_home.+ assert "error" in resp+ assert resp["error"]["code"] == 4018+ assert "skill command" in resp["error"]["message"]++def test_command_dispatch_queue_sends_message(server):"""command.dispatch /queue returns {type: 'send', message: ...} for the TUI."""sid = "test-session"diff --git a/tui_gateway/methods_tools.py b/tui_gateway/methods_tools.pyindex e5b64c4bd3a..ed3ac3180ed 100644--- a/tui_gateway/methods_tools.py+++ b/tui_gateway/methods_tools.py@@ -1178,12 +1178,26 @@ def _(rid, params: dict) -> dict:try:from agent.skill_commands import get_skill_commands-- _cmd_key = f"/{_cmd_base}"- if _cmd_key in get_skill_commands():- return _err(- rid, 4018, f"skill command: use command.dispatch for {_cmd_key}"- )+ from hermes_constants import reset_hermes_home_override, set_hermes_home_override++ # Re-bind HERMES_HOME to the session's profile so get_skill_commands()+ # sees that profile's skills.external_dirs rather than whatever the+ # process-level env happens to carry (#88023): dispatch() runs this+ # handler on the pool with a copied context, and nothing upstream of+ # here binds the override for slash.exec.+ _profile_home = session.get("profile_home")+ _home_token = (+ set_hermes_home_override(_profile_home) if _profile_home else None+ )+ try:+ _cmd_key = f"/{_cmd_base}"+ if _cmd_key in get_skill_commands():+ return _err(+ rid, 4018, f"skill command: use command.dispatch for {_cmd_key}"+ )+ finally:+ if _home_token is not None:+ reset_hermes_home_override(_home_token)except Exception:pass