Skip to content

The agent that grows with you

fix(gateway): a classic CLI snapshot counts the skills main's CLI banner counted

Tekniumc31291a765e4
diff --git a/gateway/session_local_inventory.py b/gateway/session_local_inventory.py
index c9dcd148f57..a35a5da7cb9 100644
--- a/gateway/session_local_inventory.py
+++ b/gateway/session_local_inventory.py
@@ -95,6 +95,28 @@ def _cli_startup_notices(enabled):
return notices
+def _cli_skills():
+ """``hermes_cli.banner.get_available_skills`` as main's classic CLI computed it: ``cmd_chat`` pins
+ ``HERMES_KANBAN_BOARD`` before HermesCLI starts, so ``environments: [kanban]`` skills are offered.
+ The owner never sets that env; the kanban relevance is scoped to this scan (a ContextVar) and the
+ catalog cache entry it would poison is restored, so other surfaces keep their own view."""
+ from tools import skills_tool
+ from tools.kanban_toolset_context import scoped_kanban_toolset_selection
+ key = ("filtered", False)
+ saved = skills_tool._SKILLS_CACHE.pop(key, None)
+ try:
+ with scoped_kanban_toolset_selection(["kanban"]):
+ found = skills_tool._find_all_skills()
+ finally:
+ skills_tool._SKILLS_CACHE.pop(key, None)
+ if saved is not None:
+ skills_tool._SKILLS_CACHE[key] = saved
+ grouped: dict[str, list[str]] = {}
+ for skill in found:
+ grouped.setdefault(skill.get("category") or "general", []).append(skill["name"])
+ return grouped
+
+
def session_inventory(authority, policy, agent, cwd):
"""Main's banner/status fields for one session. Each section degrades to main's empty value on
its own, so one failing builder never blanks the others (main wrapped each in ``suppress``)."""
@@ -132,8 +154,11 @@ def session_inventory(authority, policy, agent, cwd):
if policy is not None and policy.source == "cli":
info.update(_cli_startup_notices(enabled))
with contextlib.suppress(Exception):
- from hermes_cli.banner import get_available_skills
- info["skills"] = get_available_skills()
+ if policy is not None and policy.source == "cli":
+ info["skills"] = _cli_skills()
+ else:
+ from hermes_cli.banner import get_available_skills
+ info["skills"] = get_available_skills()
with contextlib.suppress(Exception):
from tools.mcp_tool_discovery import get_mcp_status
info["mcp_servers"] = get_mcp_status()
diff --git a/tests/gateway/test_canonical_session_inventory.py b/tests/gateway/test_canonical_session_inventory.py
index c71bbf02d1c..9f93ba0922f 100644
--- a/tests/gateway/test_canonical_session_inventory.py
+++ b/tests/gateway/test_canonical_session_inventory.py
@@ -116,3 +116,47 @@ async def test_cli_surface_snapshot_carries_main_cli_toolsets_and_startup_warnin
assert cli['browser_backend_notice'] == 'browser-harness is missing'
tui = (await call('session.create', request_id='tui', source='tui', cwd=str(repo)))['info']
assert 'tool_availability_warnings' not in tui and 'browser_backend_notice' not in tui
+
+
+async def test_cli_surface_counts_kanban_skills_like_main_cli_without_leaking(tmp_path, monkeypatch, repo):
+ """Main's ``cmd_chat`` pins ``HERMES_KANBAN_BOARD`` before HermesCLI starts, so its banner lists
+ ``environments: [kanban]`` skills. A CLI-surface snapshot counts them; other surfaces and the
+ process-wide catalog do not."""
+ from gateway import run
+ from gateway.config import GatewayConfig
+ from gateway.session import SessionStore
+ from gateway.session_authority import initialize_session_authority
+ from gateway.session_controls import AuthorityConnection
+ from hermes_cli import banner
+ from tools.skills_tool import _find_all_skills
+
+ home = tmp_path / 'home'
+ for name, extra in (('arxiv', ''), ('sdlc-review', 'environments:\n - kanban\n')):
+ skill = home / 'skills' / 'devops' / name
+ skill.mkdir(parents=True)
+ (skill / 'SKILL.md').write_text(f'---\nname: {name}\ndescription: d.\n{extra}---\nBody.\n')
+ (home / 'config.yaml').write_text(
+ 'model: {default: gpt-5.4, provider: custom, base_url: "http://127.0.0.1:9/v1"}\n')
+ monkeypatch.setenv('HERMES_HOME', str(home))
+ monkeypatch.delenv('HERMES_KANBAN_BOARD', raising=False)
+ monkeypatch.delenv('HERMES_KANBAN_TASK', raising=False)
+ monkeypatch.setattr(run, '_hermes_home', home)
+ monkeypatch.setattr(banner, '_available_skills_cache', None)
+ store = SessionStore(tmp_path / 'sessions', GatewayConfig())
+ runner = SimpleNamespace(session_store=store, _session_db=store._db, adapters={}, _draining=False,
+ _cached_agent_for=lambda route: None)
+ runner._adapter_for_source = lambda source: runner.adapters.get(source.platform)
+ authority = await initialize_session_authority(runner, profile_id=str(home), instance_id='first')
+ connection = AuthorityConnection(authority, object(), {'user_id': 'human'})
+
+ async def call(method, **params):
+ reply = await connection.dispatch({'id': 1, 'method': method, 'params': params})
+ assert 'result' in reply, reply
+ return reply['result']
+
+ cli = (await call('session.create', request_id='cli', source='cli', cwd=str(repo)))['info']
+ assert sorted(cli['skills']['devops']) == ['arxiv', 'sdlc-review'], cli['skills']
+ tui = (await call('session.create', request_id='tui', source='tui', cwd=str(repo)))['info']
+ assert tui['skills']['devops'] == ['arxiv'], tui['skills']
+ assert [s['name'] for s in _find_all_skills()] == ['arxiv']
diff --git a/tests/gateway/test_local_session_info_fields.py b/tests/gateway/test_local_session_info_fields.py
index 855d3a150e7..a47fa985083 100644
--- a/tests/gateway/test_local_session_info_fields.py
+++ b/tests/gateway/test_local_session_info_fields.py
@@ -46,7 +46,7 @@ def test_local_viewer_title_republishes_session_info(monkeypatch):
_is_telegram_topic_lane=lambda s: False,
_is_discord_auto_thread_lane=lambda s: False,
_is_relay_discord_channel_lane=lambda s: False)
- import gateway.session_local as session_local
+ from gateway import session_local
monkeypatch.setattr(session_local, 'local_session_info', lambda authority, ref: {'title': 'Auto'})
agent = SimpleNamespace(session_id='s')
turn._attach_session_title_callback(agent, turn._ctx)