Skip to content

The agent that grows with you

fix(cli): /reload-skills and /skills install rescan skills in the gateway session

Tekniumf4b71ed2eb9d
diff --git a/gateway/session_ancillary.py b/gateway/session_ancillary.py
index 54b1dc9c762..168516502c0 100644
--- a/gateway/session_ancillary.py
+++ b/gateway/session_ancillary.py
@@ -29,6 +29,7 @@ def handlers(connection):
'process.stop': partial(stop_processes, connection),
'process.kill': partial(kill_process, connection), 'reload.mcp': partial(reload_mcp, connection),
'file.attach': partial(attach_file, connection), 'tools.show': partial(show_tools, connection),
+ 'skills.reload': partial(reload_skills, connection),
**{name: partial(subagent_control, connection, steer=name == 'subagent.steer')
for name in ('subagent.steer', 'subagent.interrupt')}}
@@ -102,6 +103,35 @@ async def show_tools(connection, ref, params):
return await asyncio.to_thread(build)
+async def reload_skills(connection, ref, params):
+ """``/reload-skills`` (and the CLI's ``/skills install``): rescan the skill dirs in the owner,
+ whose skill-command map serves this session's skill and bundle invocations. The CLI renders
+ main's lines from ``result`` and queues main's next-turn note itself."""
+ if set(params) - {'session_id', 'profile'} or not isinstance(ref.session_id, str) or not ref.session_id:
+ raise RuntimeStoreError('invalid_params')
+ authority = connection.authority
+ if ref.session_id not in authority.sessions:
+ raise RuntimeStoreError('not_found')
+ authorize(connection, ref, params, 'session:control')
+ from gateway.session_authorities import owner_scope
+ from gateway.session_policy import policy_for_source, policy_scope
+ policy = policy_for_source(authority.runner, authority.sessions[ref.session_id].source)
+
+ def rescan():
+ from agent.skill_commands import reload_skills as rescan_skills
+ with owner_scope(authority), policy_scope(policy, authority=authority):
+ return rescan_skills()
+ result = await asyncio.to_thread(rescan)
+ added, removed = result.get('added') or [], result.get('removed') or []
+ lines = ['Reloading skills...'] + ([] if added or removed else ['No new skills detected.'])
+ for label, items in (('Added skills:', added), ('Removed skills:', removed)):
+ if items:
+ lines.append(label)
+ lines.extend(f" - {item.get('name', '')}" for item in items)
+ lines.append(f"{int(result.get('total') or 0)} skill(s) available")
+ return {'output': '\n'.join(lines), 'result': result}
+
+
async def attach_file(connection, ref, params):
"""Desktop's non-image attachment: stage the file for this session (its frozen launch cwd and
the owner profile's ``attachments/``) and hand back the ``@file:`` ref its next submit carries.
diff --git a/hermes_cli/cli_commands_mixin.py b/hermes_cli/cli_commands_mixin.py
index 3b92563a340..c82d65931d9 100644
--- a/hermes_cli/cli_commands_mixin.py
+++ b/hermes_cli/cli_commands_mixin.py
@@ -1576,7 +1576,7 @@ class CLICommandsMixin(CLICommandsSessionToolsMixin):
)
if out is not None:
return print(out)
- from hermes_cli.skills_hub import handle_skills_slash
+ from hermes_cli.gateway_tools import handle_skills_slash # + the gateway's rescan
handle_skills_slash(cmd, ChatConsole())
def _handle_memory_command(self, cmd: str):
diff --git a/hermes_cli/cli_info_mixin.py b/hermes_cli/cli_info_mixin.py
index e1f531f33d0..5f27c49b524 100644
--- a/hermes_cli/cli_info_mixin.py
+++ b/hermes_cli/cli_info_mixin.py
@@ -1032,6 +1032,8 @@ class CLIInfoMixin:
if not self._command_running:
print(t("cli.reload_skills.reloading"))
result = reload_skills()
+ from hermes_cli.gateway_tools import reload_gateway_skills
+ result = reload_gateway_skills() or result # the gateway that runs the turn rescans too
added = result.get("added", []) # [{"name", "description"}, ...]
removed = result.get("removed", [])
total = result.get("total", 0)
diff --git a/hermes_cli/gateway_tools.py b/hermes_cli/gateway_tools.py
index 247318d482c..fd8f0e79989 100644
--- a/hermes_cli/gateway_tools.py
+++ b/hermes_cli/gateway_tools.py
@@ -183,3 +183,24 @@ def session_tools():
tools.append({"type": "function", "function": {"name": row["name"],
"description": row.get("description") or ""}})
return tools, toolset_of.get
+
+
+def reload_gateway_skills():
+ """Rescan skills in the gateway session too (its skill-command map serves this session's
+ ``/<skill>`` and bundle invocations); the CLI's own rescan still drives main's output."""
+ view = process_view()
+ if view is None:
+ return None
+ try:
+ return (view.connection.call("skills.reload", session_id=view.session_id) or {}).get("result")
+ except GatewayClientError as exc:
+ logger.debug("skills.reload failed: %s", exc)
+ return None
+
+
+def handle_skills_slash(cmd, console):
+ """Main's ``/skills`` (hub search / install / uninstall write the local skills tree), then the
+ gateway's rescan so an install reaches the skill map the session's turns use."""
+ from hermes_cli.skills_hub import handle_skills_slash as local
+ local(cmd, console)
+ reload_gateway_skills()
diff --git a/tests/gateway/fixtures/desktop_process_verbs_peer.py b/tests/gateway/fixtures/desktop_process_verbs_peer.py
index e45d1127843..290eee52cb4 100644
--- a/tests/gateway/fixtures/desktop_process_verbs_peer.py
+++ b/tests/gateway/fixtures/desktop_process_verbs_peer.py
@@ -43,6 +43,13 @@ async def probe():
# The classic CLI's /tools: the session's catalog from the owner (toolsets=[] -> none).
shown = await rpc(ws, 'tools.show', session_id=sid)
receipt['tools_show'] = shown.get('result', shown.get('error'))
+ # The classic CLI's /reload-skills: the owner rescans (a skill added on disk shows as added).
+ skill = home / 'skills' / 'test' / 'zeta-skill'
+ skill.mkdir(parents=True)
+ (skill / 'SKILL.md').write_text('---\nname: zeta-skill\ndescription: Zeta.\n---\nZETA\n')
+ reloaded = await rpc(ws, 'skills.reload', session_id=sid)
+ receipt['skills_reload'] = [a.get('name') for a in reloaded.get('result', {}).get('result', {}).get('added', [])] \
+ if 'result' in reloaded else reloaded.get('error')
# composer-status.ts: per-process Stop.
kill = await rpc(ws, 'process.kill', process_id=own.id, session_id=sid)
await asyncio.to_thread(own._completion_event.wait, 10)
diff --git a/tests/gateway/test_desktop_process_verbs.py b/tests/gateway/test_desktop_process_verbs.py
index 8679dc7cfdd..c346aa56562 100644
--- a/tests/gateway/test_desktop_process_verbs.py
+++ b/tests/gateway/test_desktop_process_verbs.py
@@ -33,6 +33,7 @@ def test_desktop_process_kill_stop_and_mcp_reload_reach_only_this_session(tmp_pa
assert receipt['tools_show']['total'] == sum(len(s['tools']) for s in receipt['tools_show']['sections']), receipt
# Scoped to THIS session's toolsets (created with toolsets=[]), not the launch profile's catalog.
assert receipt['tools_show']['total'] == 0, receipt
+ assert receipt['skills_reload'] == ['zeta-skill'], receipt
assert receipt['exited'] == [True, True, False], receipt
assert receipt['reload_mcp'] == 'reloaded', receipt
# file.attach: the sidecar answered ``session not found`` for every authority session.
diff --git a/tests/hermes_cli/test_gateway_tools.py b/tests/hermes_cli/test_gateway_tools.py
index d021f1e8a7b..cb8a0220a3c 100644
--- a/tests/hermes_cli/test_gateway_tools.py
+++ b/tests/hermes_cli/test_gateway_tools.py
@@ -44,6 +44,9 @@ class FakeClient:
return {"sections": [{"name": "mcp-demo", "tools": [{"name": "mcp_demo_ping", "description": "Ping."}]},
{"name": "terminal", "tools": [{"name": "terminal", "description": "Run."}]}],
"total": 2}
+ if method == "skills.reload":
+ return {"output": "", "result": {"added": [{"name": "zeta-skill", "description": "Zeta."}],
+ "removed": [], "total": 3}}
if method == "process.kill":
return {"status": "killed", "session_id": params["process_id"]}
return {}
@@ -112,3 +115,17 @@ def test_tools_lists_the_gateway_session_catalog_with_main_rendering(gateway, ca
assert " [terminal]\n * terminal - Run.\n" in out
assert "Total: 2 tools" in out
assert ("tools.show", {"session_id": SID}) in client.calls
+
+
+def test_reload_skills_rescans_in_the_gateway_session_and_prints_main_lines(gateway, capsys, monkeypatch):
+ """/reload-skills rescans where the turn runs; main's lines print from the gateway's diff."""
+ from agent import skill_commands
+ from hermes_cli.cli_info_mixin import CLIInfoMixin
+ _agent, client = gateway
+ monkeypatch.setattr(skill_commands, "reload_skills", lambda: {"added": [], "removed": [], "total": 2})
+ cli = type("C", (), {"_command_running": False})()
+ CLIInfoMixin._reload_skills(cli)
+ out = capsys.readouterr().out
+ assert "zeta-skill" in out and "3 skill(s) available" in out
+ assert ("skills.reload", {"session_id": SID}) in client.calls
+ assert "zeta-skill" in cli._pending_skills_reload_note