The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): /tools and /initiate-setup list the gateway session's tools
Tekniumf1f0ad123ee4
diff --git a/gateway/session_ancillary.py b/gateway/session_ancillary.pyindex 7d9978fed01..54b1dc9c762 100644--- a/gateway/session_ancillary.py+++ b/gateway/session_ancillary.py@@ -28,7 +28,7 @@ def handlers(connection):'approval.received': partial(approvals, connection, ack=True),'process.stop': partial(stop_processes, connection),'process.kill': partial(kill_process, connection), 'reload.mcp': partial(reload_mcp, connection),- 'file.attach': partial(attach_file, connection),+ 'file.attach': partial(attach_file, connection), 'tools.show': partial(show_tools, connection),**{name: partial(subagent_control, connection, steer=name == 'subagent.steer')for name in ('subagent.steer', 'subagent.interrupt')}}@@ -59,6 +59,49 @@ async def subagent_control(connection, ref, params, *, steer):return {'status': 'queued' if queued else 'rejected', 'subagent_id': sub, 'text': params['text']}+async def show_tools(connection, ref, params):+ """``/tools``: the session's catalog as main's CLI listed it (``get_tool_definitions`` with the+ session's toolsets, pre tool_search assembly), resolved in the owner, where the MCP and plugin+ tools live. Rows carry the first description sentence, grouped by toolset."""+ 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:read')+ from gateway.session_authorities import owner_scope+ from gateway.session_policy import policy_for_source+ policy = policy_for_source(authority.runner, authority.sessions[ref.session_id].source)+ agent = authority.agent(ref)++ def build():+ import model_tools+ from agent.skill_utils import parse_config_string_list+ from toolsets import session_disabled_toolsets+ with owner_scope(authority):+ if agent is not None:+ enabled, disabled = getattr(agent, 'enabled_toolsets', None), getattr(agent, 'disabled_toolsets', None)+ else:+ config = policy.config(authority, secrets=False) if policy is not None else {}+ enabled = list(policy.current_toolsets(config)) if policy is not None else None+ disabled = session_disabled_toolsets(parse_config_string_list(+ (config.get('agent') or {}).get('disabled_toolsets')) or None,+ policy.platform if policy is not None else 'cli')+ tools = model_tools.get_tool_definitions(enabled_toolsets=enabled, disabled_toolsets=disabled,+ quiet_mode=True, skip_tool_search_assembly=True)+ sections = {}+ for tool in sorted(tools or [], key=lambda item: item['function']['name']):+ name = tool['function']['name']+ desc = str(tool['function'].get('description', '') or '').split('\n')[0]+ if '. ' in desc:+ desc = desc[:desc.index('. ') + 1]+ sections.setdefault(model_tools.get_toolset_for_tool(name) or 'unknown', []).append(+ {'name': name, 'description': desc})+ return {'sections': [{'name': n, 'tools': rows} for n, rows in sorted(sections.items())],+ 'total': len(tools or [])}+ return await asyncio.to_thread(build)++async def attach_file(connection, ref, params):"""Desktop's non-image attachment: stage the file for this session (its frozen launch cwd andthe owner profile's ``attachments/``) and hand back the ``@file:`` ref its next submit carries.diff --git a/hermes_cli/cli_chat_turn_mixin.py b/hermes_cli/cli_chat_turn_mixin.pyindex a94395d6b7e..a13c3dee897 100644--- a/hermes_cli/cli_chat_turn_mixin.py+++ b/hermes_cli/cli_chat_turn_mixin.py@@ -225,8 +225,11 @@ class CLIChatTurnMixin:from hermes_cli.setup_profile import primary_profilefrom hermes_constants import get_hermes_homeprint("\n" + t("cli.commands.initiate_setup.starting"))- tools = get_tool_definitions(enabled_toolsets=self.enabled_toolsets, disabled_toolsets=self.disabled_toolsets,- quiet_mode=True, skip_tool_search_assembly=True)+ from hermes_cli.gateway_tools import session_tools+ remote = session_tools() # tool names from the gateway session that will run the turn+ tools = remote[0] if remote is not None else get_tool_definitions(+ enabled_toolsets=self.enabled_toolsets, disabled_toolsets=self.disabled_toolsets,+ quiet_mode=True, skip_tool_search_assembly=True)names = [tool["function"]["name"] for tool in tools]primary = primary_profile(get_hermes_home())self._queue_prompt_turn(build_initiate_setup_prompt("cli", names, primary), "/initiate-setup")diff --git a/hermes_cli/cli_info_mixin.py b/hermes_cli/cli_info_mixin.pyindex fe59157450d..e1f531f33d0 100644--- a/hermes_cli/cli_info_mixin.py+++ b/hermes_cli/cli_info_mixin.py@@ -402,13 +402,18 @@ class CLIInfoMixin:def show_tools(self):"""Display available tools with kawaii ASCII art."""- from cli import get_tool_definitions- from model_tools import get_toolset_for_tool- # Pre-assembly list: /tools is a discovery surface, so it must show the full catalog- # including tools deferred behind the tool_search bridge (users verify MCP installs here).- tools = get_tool_definitions(enabled_toolsets=self.enabled_toolsets,- disabled_toolsets=self.disabled_toolsets, quiet_mode=True,- skip_tool_search_assembly=True)+ from hermes_cli.gateway_tools import session_tools+ remote = session_tools() # the gateway session's catalog (its MCP + plugin tools included)+ if remote is not None:+ tools, get_toolset_for_tool = remote+ else:+ from cli import get_tool_definitions+ from model_tools import get_toolset_for_tool+ # Pre-assembly list: /tools is a discovery surface, so it must show the full catalog+ # including tools deferred behind the tool_search bridge (users verify MCP installs here).+ tools = get_tool_definitions(enabled_toolsets=self.enabled_toolsets,+ disabled_toolsets=self.disabled_toolsets, quiet_mode=True,+ skip_tool_search_assembly=True)if not tools:print(t("cli.tools.none_available"))returndiff --git a/hermes_cli/gateway_tools.py b/hermes_cli/gateway_tools.pyindex cf62b2f8590..4fe783bc331 100644--- a/hermes_cli/gateway_tools.py+++ b/hermes_cli/gateway_tools.py@@ -155,3 +155,20 @@ def process_registry():return viewfrom tools.process_registry import process_registry as localreturn local+++def session_tools():+ """``/tools`` / ``/initiate-setup``: the gateway session's tool catalog (``tools.show``) as+ ``(tools, toolset_of)``: ``get_tool_definitions``-shaped rows (first description sentence) and+ a name -> toolset lookup. None when the CLI is not gateway-backed."""+ view = process_view()+ if view is None:+ return None+ result = view.connection.call("tools.show", session_id=view.session_id) or {}+ tools, toolset_of = [], {}+ for section in result.get("sections") or []:+ for row in section.get("tools") or []:+ toolset_of[row["name"]] = section.get("name")+ tools.append({"type": "function", "function": {"name": row["name"],+ "description": row.get("description") or ""}})+ return tools, toolset_of.getdiff --git a/tests/gateway/fixtures/desktop_process_verbs_peer.py b/tests/gateway/fixtures/desktop_process_verbs_peer.pyindex 398a0effece..e45d1127843 100644--- a/tests/gateway/fixtures/desktop_process_verbs_peer.py+++ b/tests/gateway/fixtures/desktop_process_verbs_peer.py@@ -35,6 +35,14 @@ async def probe():processes.append(process_registry.spawn_local(command, cwd=str(home), task_id=task, owner_task_id=task,session_key=key))own, other, foreign = processes+ # The classic CLI's dock reads its rows' timing / verdict fields from process.list.+ listed = (await rpc(ws, 'process.list', session_id=sid))['result']['processes']+ receipt['list_fields'] = sorted({k for row in listed for k in ('started_epoch', 'exited_at', 'completion_reason')+ if k in row})+ receipt['list_ids'] = sorted(row['session_id'] for row in listed) == sorted([own.id, other.id])+ # 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'))# 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.pyindex a8cca0ae0aa..8679dc7cfdd 100644--- a/tests/gateway/test_desktop_process_verbs.py+++ b/tests/gateway/test_desktop_process_verbs.py@@ -25,7 +25,14 @@ def test_desktop_process_kill_stop_and_mcp_reload_reach_only_this_session(tmp_paassert receipt['kill'] == 'killed', receipt# Not ``not_found``, which Desktop's session-gone latch reads as a dead chat (dokterdok N64).assert receipt['foreign_kill'] == 'process_not_found', receipt- assert receipt['stop'] == {'killed': 1}, receipt+ assert receipt['stop'] == {'killed': 1, 'delegations': 0}, receipt+ assert receipt['list_fields'] == ['completion_reason', 'exited_at', 'started_epoch'], receipt+ assert receipt['list_ids'] is True, receipt+ # tools.show is served for an owner session (the classic CLI's /tools), not -32601.+ assert set(receipt['tools_show']) == {'sections', 'total'}, receipt+ 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, receiptassert receipt['exited'] == [True, True, False], receiptassert 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.pyindex 73cbc5a35d3..d021f1e8a7b 100644--- a/tests/hermes_cli/test_gateway_tools.py+++ b/tests/hermes_cli/test_gateway_tools.py@@ -40,6 +40,10 @@ class FakeClient:if row["status"] == "running":row.update(status="exited", exited_at=time.time(), completion_reason="killed", exit_code=-15)return {"killed": 1, "delegations": 0}+ if method == "tools.show":+ return {"sections": [{"name": "mcp-demo", "tools": [{"name": "mcp_demo_ping", "description": "Ping."}]},+ {"name": "terminal", "tools": [{"name": "terminal", "description": "Run."}]}],+ "total": 2}if method == "process.kill":return {"status": "killed", "session_id": params["process_id"]}return {}@@ -96,3 +100,15 @@ def test_dock_stop_kills_one_process_through_the_gateway(gateway):dock.process_rows()assert dock.kill("proc_1")["status"] == "killed"assert ("process.kill", {"session_id": SID, "process_id": "proc_1"}) in client.calls+++def test_tools_lists_the_gateway_session_catalog_with_main_rendering(gateway, capsys):+ """/tools prints the gateway session's tools (its MCP servers live there), in main's layout."""+ from hermes_cli.cli_info_mixin import CLIInfoMixin+ _agent, client = gateway+ CLIInfoMixin.show_tools(type("C", (), {"enabled_toolsets": None, "disabled_toolsets": None})())+ out = capsys.readouterr().out+ assert " [mcp-demo]\n * mcp_demo_ping - Ping.\n" in out+ assert " [terminal]\n * terminal - Run.\n" in out+ assert "Total: 2 tools" in out+ assert ("tools.show", {"session_id": SID}) in client.calls