The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui-gateway): expand stacked /skill tokens in command.dispatch
Brooklyn Nicholson5ba9db294f6b
diff --git a/tests/tui_gateway/test_protocol.py b/tests/tui_gateway/test_protocol.pyindex 0c88de84781..01d22b39936 100644--- a/tests/tui_gateway/test_protocol.py+++ b/tests/tui_gateway/test_protocol.py@@ -1343,6 +1343,104 @@ def test_slash_exec_scopes_skill_lookup_to_session_profile(server, tmp_path):assert resp["error"]["code"] == 4018+def test_command_dispatch_expands_stacked_skills_from_temp_home(server, tmp_path, monkeypatch):+ """#74705: Desktop/TUI command.dispatch must expand every real leading+ /skill token (CLI cli.py and the messaging gateway already do), so+ '/nature-figure /academic-plotting Plot the results' loads BOTH skills+ over the remaining instruction instead of leaving the second token in+ the prompt as plain text."""+ import agent.skill_commands as skill_commands+ import tools.skills_tool as skills_tool++ home = tmp_path / ".hermes"+ skills_dir = home / "skills"+ for name, instructions in (+ ("nature-figure", "Render figures with natural colors."),+ ("academic-plotting", "Label every axis and include units."),+ ):+ skill_dir = skills_dir / name+ skill_dir.mkdir(parents=True)+ (skill_dir / "SKILL.md").write_text(+ f"---\nname: {name}\ndescription: Test {name}.\n---\n\n{instructions}\n",+ encoding="utf-8",+ )++ monkeypatch.setenv("HERMES_HOME", str(home))+ monkeypatch.setattr(skills_tool, "SKILLS_DIR", skills_dir)+ monkeypatch.setattr(skill_commands, "_skill_commands", {})+ monkeypatch.setattr(skill_commands, "_skill_commands_platform", None)+ monkeypatch.setattr(skill_commands, "_skill_commands_home", None)+ monkeypatch.setattr(skill_commands, "_skill_commands_project", None)++ sid = "test-session"+ server._sessions[sid] = {"session_key": sid, "agent": None}+ resp = server.handle_request({+ "id": "stacked-skills",+ "method": "command.dispatch",+ "params": {+ "name": "nature-figure",+ "arg": "/academic-plotting Plot the results",+ "session_id": sid,+ },+ })++ assert "error" not in resp+ result = resp["result"]+ assert result["type"] == "skill"+ assert result["notice"] == (+ "⚡ Loading 2 stacked skills: nature-figure, academic-plotting"+ )+ assert "Render figures with natural colors." in result["message"]+ assert "Label every axis and include units." in result["message"]+ assert "Plot the results" in result["message"]+ # UIs render `display`: the projection shows the invocation the user typed.+ assert result["display"] == (+ "/nature-figure /academic-plotting Plot the results"+ )+++def test_command_dispatch_stacked_split_keeps_unknown_tokens_as_instruction(server, tmp_path, monkeypatch):+ """A non-skill or repeated token stops the stack and stays instruction text —+ the split must never eat content the user meant as the prompt."""+ import agent.skill_commands as skill_commands+ import tools.skills_tool as skills_tool++ home = tmp_path / ".hermes"+ skills_dir = home / "skills"+ skill_dir = skills_dir / "nature-figure"+ skill_dir.mkdir(parents=True)+ (skill_dir / "SKILL.md").write_text(+ "---\nname: nature-figure\ndescription: Test.\n---\n\nRender figures.\n",+ encoding="utf-8",+ )++ monkeypatch.setenv("HERMES_HOME", str(home))+ monkeypatch.setattr(skills_tool, "SKILLS_DIR", skills_dir)+ monkeypatch.setattr(skill_commands, "_skill_commands", {})+ monkeypatch.setattr(skill_commands, "_skill_commands_platform", None)+ monkeypatch.setattr(skill_commands, "_skill_commands_home", None)+ monkeypatch.setattr(skill_commands, "_skill_commands_project", None)++ sid = "test-session-unknown"+ server._sessions[sid] = {"session_key": sid, "agent": None}+ resp = server.handle_request({+ "id": "stacked-unknown",+ "method": "command.dispatch",+ "params": {+ "name": "nature-figure",+ "arg": "/not-a-skill-command but /model is a registry command",+ "session_id": sid,+ },+ })++ assert "error" not in resp+ result = resp["result"]+ assert result["type"] == "skill"+ # No stacked notice — the single-skill path ran with the post-split text intact.+ assert "notice" not in result+ assert "/not-a-skill-command but /model is a registry command" in result["message"]++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 b5b7ebd413a..91e98b70ae7 100644--- a/tui_gateway/methods_tools.py+++ b/tui_gateway/methods_tools.py@@ -720,7 +720,25 @@ def _dispatch_skill(rid, params, session, name, arg):sc = _tools_mod("agent.skill_commands")cmds, key = sc.get_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 "")+ # 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)+ if extra_keys:+ stacked = sc.build_stacked_skill_invocation_message(+ [key, *extra_keys], user_instruction,+ task_id=session.get("session_key", "") if session else "")+ if stacked:+ msg, loaded_names, missing = stacked+ notice = f"⚡ Loading {len(loaded_names)} stacked skills: {', '.join(loaded_names)}"+ if missing:+ notice += f"\nSkipped missing skills: {', '.join(missing)}"+ return _ok(rid, {+ "type": "skill", "message": msg, "name": cmds[key].get("name", name),+ "notice": notice, "display": _skill_scaffold_projection(msg)})+ msg = sc.build_skill_invocation_message(+ key, user_instruction,+ 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),