The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(gateway): session.info carries the classic CLI's title, times, yolo, api_mode, tool count and credential hint
Teknium2e7fb2cde517
diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.tsindex 389eba7cb98..27b4e2ca33f 100644--- a/apps/shared/src/gateway-contract.generated.ts+++ b/apps/shared/src/gateway-contract.generated.ts@@ -4545,6 +4545,13 @@ export interface CanonicalSessionInfo {reasoning_effort_wire?: string | nullservice_tier?: string | nullfast?: boolean | null+ title?: string | null+ started_at?: number | null+ last_active_at?: number | null+ yolo?: boolean | null+ api_mode?: string | null+ tool_count?: number | null+ credential_hint?: string | null[key: string]: unknown}export interface SessionStatsParams {@@ -4855,6 +4862,13 @@ export interface CanonicalSnapshotInfo {reasoning_effort_wire?: string | nullservice_tier?: string | nullfast?: boolean | null+ title?: string | null+ started_at?: number | null+ last_active_at?: number | null+ yolo?: boolean | null+ api_mode?: string | null+ tool_count?: number | null+ credential_hint?: string | null}export interface CanonicalResumeParams {profile?: string | nulldiff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.jsonindex e50df09142a..4f9ea17ac9d 100644--- a/apps/shared/src/gateway-contract.openrpc.json+++ b/apps/shared/src/gateway-contract.openrpc.json@@ -10052,6 +10052,90 @@],"default": null,"title": "Fast"+ },+ "title": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Title"+ },+ "started_at": {+ "anyOf": [+ {+ "type": "number"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Started At"+ },+ "last_active_at": {+ "anyOf": [+ {+ "type": "number"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Last Active At"+ },+ "yolo": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Yolo"+ },+ "api_mode": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Api Mode"+ },+ "tool_count": {+ "anyOf": [+ {+ "type": "integer"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Tool Count"+ },+ "credential_hint": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Credential Hint"}},"required": [@@ -10648,6 +10732,90 @@],"default": null,"title": "Fast"+ },+ "title": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Title"+ },+ "started_at": {+ "anyOf": [+ {+ "type": "number"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Started At"+ },+ "last_active_at": {+ "anyOf": [+ {+ "type": "number"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Last Active At"+ },+ "yolo": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Yolo"+ },+ "api_mode": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Api Mode"+ },+ "tool_count": {+ "anyOf": [+ {+ "type": "integer"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Tool Count"+ },+ "credential_hint": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Credential Hint"}},"required": [diff --git a/gateway/run_turn_progress.py b/gateway/run_turn_progress.pyindex c603aa14b76..69acc7f9ad6 100644--- a/gateway/run_turn_progress.py+++ b/gateway/run_turn_progress.py@@ -922,6 +922,18 @@ class GatewayTurnProgressMixin:"Gateway auto-title failure suppressed (not user-visible): %s: %s", task, exc,)session_id = getattr(agent, "session_id", None)+ if local_viewer_turn(self):+ # Main's CLI repainted its status-bar title when the auto-title landed.+ authority, canonical_id, _generation = self._approval_owner++ def republish(title, title_source):+ from gateway.session_contract import SessionRef+ from gateway.session_local import local_session_info+ ref = SessionRef(getattr(authority, "profile_id", ""), canonical_id)+ authority.sessions[canonical_id].event_stream.publish(+ canonical_id, local_session_info(authority, ref), event_type="session.info")+ agent._on_session_title = republish+ returnrunner = self._runnersource = runner._recover_discord_auto_thread_source(ctx.source, ctx.session_key)# Both lanes spend a rate-limited platform call per title, so they use the model's titlediff --git a/gateway/session_local.py b/gateway/session_local.pyindex 3d6b7591946..74ea1e939a7 100644--- a/gateway/session_local.py+++ b/gateway/session_local.py@@ -305,4 +305,37 @@ def local_session_info(authority, ref):# resuming client can tell "same flags again" from a real override attempt.import jsoninfo['launch_request'] = json.loads(policy.request_json)+ info.update(_classic_cli_fields(authority, ref, live, agent, policy))return info+++def _classic_cli_fields(authority, ref, live, agent, policy):+ """What main's HermesCLI read off itself for /status, the status bar and the exit summary: the+ stored title and times, the session's yolo, api_mode, the loaded tool count and a masked+ credential hint (never the key). Lazy sessions report what is known without building an agent."""+ import contextlib+ stored_id = ref.session_id+ with contextlib.suppress(Exception):+ from hermes_state_local import local_receipt+ stored_id = local_receipt(authority.db, ref.session_id)['entry']['session_id'] or stored_id+ row = {}+ with contextlib.suppress(Exception):+ row = authority.db.get_session(stored_id) or {}+ yolo = bool(policy is not None and getattr(policy, 'yolo', False))+ with contextlib.suppress(Exception):+ from tools.approval import is_session_yolo_enabled+ yolo = yolo or is_session_yolo_enabled(live.route)+ api_mode = getattr(agent, 'api_mode', None) if agent is not None else None+ if api_mode is None and policy is not None:+ with contextlib.suppress(Exception):+ api_mode = (policy.effective(authority, secrets=False)[0].get('model') or {}).get('api_mode')+ hint = None+ if agent is not None and getattr(agent, 'api_key', None):+ from agent.redact import mask_secret+ hint = mask_secret(str(agent.api_key))+ tools = getattr(agent, 'tools', None) if agent is not None else None+ started = row.get('started_at')+ return {'title': row.get('title'), 'started_at': started,+ 'last_active_at': row.get('last_activity_at') or started, 'yolo': yolo,+ 'api_mode': api_mode or None, 'tool_count': len(tools) if isinstance(tools, list) else None,+ 'credential_hint': hint}diff --git a/gateway/session_local_inventory.py b/gateway/session_local_inventory.pyindex e12fa9c4da1..c9dcd148f57 100644--- a/gateway/session_local_inventory.py+++ b/gateway/session_local_inventory.py@@ -159,4 +159,7 @@ async def snapshot_info(authority, ref):policy = policy_for_source(authority.runner, authority.sessions[ref.session_id].source)agent = authority.agent(ref)inventory = await asyncio.to_thread(session_inventory, authority, policy, agent, info.get("cwd"))+ if info.get('tool_count') is None:+ # A lazy session: the tools its first turn loads (the banner's own count).+ info['tool_count'] = sum(len(names) for names in (inventory.get('tools') or {}).values())return {**inventory, **info}diff --git a/tests/gateway/test_local_session_info_fields.py b/tests/gateway/test_local_session_info_fields.pynew file mode 100644index 00000000000..855d3a150e7--- /dev/null+++ b/tests/gateway/test_local_session_info_fields.py@@ -0,0 +1,54 @@+"""``session.info`` carries what main's classic CLI read off itself for /status, the status bar and the+exit summary (wave A2): title, started/last-active times, yolo, api_mode, tool_count and a masked+credential hint (never the key); re-published when the auto-title lands."""+from __future__ import annotations++from types import SimpleNamespace++import pytest++from gateway.config import Platform+++async def test_session_info_carries_the_classic_cli_fields(tmp_path, monkeypatch):+ from gateway.session_contract import SessionRef+ from gateway.session_local import local_session_info+ from tests.gateway.test_surface_admission import _authority++ async def answer(event):+ return 'ok'+ authority = await _authority(tmp_path, monkeypatch, answer)+ agent = SimpleNamespace(model='m', provider='custom', api_mode='chat_completions',+ api_key='sk-abcdefghijklmnop1234', tools=[{'function': {'name': 'a'}}] * 3)+ authority.runner._cached_agent_for = lambda route: agent+ authority.db.set_session_title('s', 'Some Title')+ info = local_session_info(authority, SessionRef('p', 's'))+ assert info['title'] == 'Some Title'+ assert isinstance(info['started_at'], float) and isinstance(info['last_active_at'], float)+ assert info['yolo'] is False and info['api_mode'] == 'chat_completions' and info['tool_count'] == 3+ assert info['credential_hint'] == 'sk-a...1234' and 'abcdefgh' not in str(info)+ from tui_gateway.contracts.registry import CANONICAL_METHODS+ CANONICAL_METHODS['session.info'].result.model_validate(+ {**info, 'profile_name': 'default', 'desktop_protocol': 'hermes-gateway-v1', 'lazy': False})+++def test_local_viewer_title_republishes_session_info(monkeypatch):+ from gateway.run_turn_runner import TurnRunner+ published = []+ live = SimpleNamespace(event_stream=SimpleNamespace(+ publish=lambda sid, payload, event_type: published.append((event_type, payload))))+ authority = SimpleNamespace(sessions={'s': live})+ turn = object.__new__(TurnRunner)+ turn._ctx = SimpleNamespace(source=SimpleNamespace(platform=Platform.LOCAL), session_key='k')+ turn._approval_owner = (authority, 's', 1)+ turn._runner = SimpleNamespace(_recover_discord_auto_thread_source=lambda source, key: source,+ _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+ 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)+ agent._on_session_title('Auto', 'llm')+ assert published == [('session.info', {'title': 'Auto'})]diff --git a/tui_gateway/contracts/canonical.py b/tui_gateway/contracts/canonical.pyindex 0cd561a3433..c525dacb0bc 100644--- a/tui_gateway/contracts/canonical.py+++ b/tui_gateway/contracts/canonical.py@@ -168,6 +168,14 @@ class CanonicalSessionInfo(SessionInventoryFields, OpenModel):reasoning_effort_wire: str | None = Noneservice_tier: str | None = Nonefast: bool | None = None+ # What main's classic CLI read off itself (/status, status bar, exit summary).+ title: str | None = None+ started_at: float | None = None+ last_active_at: float | None = None+ yolo: bool | None = None+ api_mode: str | None = None+ tool_count: int | None = None+ credential_hint: str | None = Nonecanonical_method("session.info", params=CanonicalSessionInfoParams, result=CanonicalSessionInfo,diff --git a/tui_gateway/contracts/canonical_sessions.py b/tui_gateway/contracts/canonical_sessions.pyindex b01b3c4ae75..015203d4d03 100644--- a/tui_gateway/contracts/canonical_sessions.py+++ b/tui_gateway/contracts/canonical_sessions.py@@ -98,6 +98,13 @@ class CanonicalSnapshotInfo(SessionInventoryFields):reasoning_effort_wire: str | None = Noneservice_tier: str | None = Nonefast: bool | None = None+ title: str | None = None+ started_at: float | None = None+ last_active_at: float | None = None+ yolo: bool | None = None+ api_mode: str | None = None+ tool_count: int | None = None+ credential_hint: str | None = Noneclass CanonicalSnapshot(Result):