Skip to content

The agent that grows with you

fix(gateway): scope skill dispatch to session profile

KoNit-K4c306e9e8c12
diff --git a/tests/tui_gateway/test_protocol.py b/tests/tui_gateway/test_protocol.py
index b7e47cb3af0..fa804e2092c 100644
--- a/tests/tui_gateway/test_protocol.py
+++ b/tests/tui_gateway/test_protocol.py
@@ -1179,6 +1179,49 @@ def test_slash_exec_scopes_skill_lookup_to_session_profile(server, tmp_path):
assert "skill command" in resp["error"]["message"]
+def test_command_dispatch_scopes_skill_lookup_to_session_profile(server, tmp_path):
+ """command.dispatch must load a skill that exists only in the session profile."""
+ 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-dispatch"
+ 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": "command.dispatch",
+ "params": {"name": "b-only", "arg": "with an argument", "session_id": sid},
+ })
+
+ assert "error" not in resp
+ assert resp["result"]["type"] == "skill"
+ assert resp["result"]["name"] == "b-only"
+
+
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.py
index 9a9df6b4a35..87440b5c119 100644
--- a/tui_gateway/methods_tools.py
+++ b/tui_gateway/methods_tools.py
@@ -571,13 +571,20 @@ def _dispatch_bundle(rid, params, session, name, arg):
def _dispatch_skill(rid, params, session, name, arg):
with contextlib.suppress(Exception):
sc = _tools_mod("agent.skill_commands")
- cmds, key = sc.scan_skill_commands(), f"/{name}"
- if key in cmds:
- msg = sc.build_skill_invocation_message(key, arg, task_id=session.get("session_key", "") if session else "")
- if msg: # UIs render `display`, never `message`.
- return _ok(rid, {
- "type": "skill", "message": msg, "name": cmds[key].get("name", name),
- "display": _skill_scaffold_projection(msg)})
+ hc = _tools_mod("hermes_constants")
+ profile_home = session.get("profile_home") if session else None
+ token = hc.set_hermes_home_override(profile_home) if profile_home else None
+ try:
+ cmds, key = sc.scan_skill_commands(), f"/{name}"
+ if key in cmds:
+ msg = sc.build_skill_invocation_message(key, arg, task_id=session.get("session_key", "") if session else "")
+ if msg: # UIs render `display`, never `message`.
+ return _ok(rid, {
+ "type": "skill", "message": msg, "name": cmds[key].get("name", name),
+ "display": _skill_scaffold_projection(msg)})
+ finally:
+ if token is not None:
+ hc.reset_hermes_home_override(token)
return None