The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat: expose scoped local session metadata and document compatibility
Teknium52c354ff183a
diff --git a/docs/gateway-local-sessions.md b/docs/gateway-local-sessions.mdnew file mode 100644index 00000000000..fd7a64a4eb3--- /dev/null+++ b/docs/gateway-local-sessions.md@@ -0,0 +1,59 @@+# Gateway-owned fresh local sessions++The composed gateway listener can create a fresh local **CLI-policy** session without+starting `tui_gateway`'s separate agent runtime. The existing `GatewayRunner` / `TurnRunner`+own execution, approval waiters, tool calls, session storage, and canonical event delivery.++A server-authenticated identity with `session:create` can call:++```json+{"jsonrpc":"2.0","id":1,"method":"session.create","params":{"request_id":"stable-client-create-id","source":"cli"}}+```++The result preserves `session_id`, `stored_session_id`, `messages`, `message_count`, and+`info`, and includes the authority's normal resume snapshot fields. Both session IDs are+the same persisted ID. Creation is lazy with respect to the agent, but reserves the real+SessionDB/SessionStore identity before returning. Repeating the request ID for the same+principal and profile reuses its persisted routing entry. Omit the ID for a new session;+clients that need lost-ACK retry protection must retain it.++Attach another authenticated viewer with `session.resume({session_id})`, and submit+through `prompt.submit({session_id, submission_id, text})`. The accepted receipt is durable+admission, not inference completion. Closing every viewer leaves the execution and its+pending approval alive. A new viewer can resume the same identity and answer through+`approval.respond({session_id, execution_generation, prompt_id, choice})`.++## Deliberately limited compatibility++- Only `source: "cli"` (also the default) is currently accepted. It maps to the existing+ `Platform.LOCAL` → CLI tool/display policy. GUI/TUI policy is **not** inferred from+ process environment or the identity of an attaching viewer. Explicit GUI/TUI/native/+ automation source selections are rejected until their own policy is wired and tested.+- Creation currently accepts only `request_id` and `source`. Model/provider/reasoning,+ cwd/worktree, toolsets/skills, seeded history, profile switching, YOLO, and other launch+ options return `invalid_params`; none silently modify daemon-wide configuration.+- Fresh creation currently requires the identity stamped by the existing gated WS ticket+ path. The legacy ungated `?token=` path in this base does not stamp identity and cannot+ create. The authentication/bootstrap integration must supply the proper server principal;+ callers cannot provide one in RPC parameters. Resume-only capabilities must not be+ promoted to `session:create` by that integration.+- `session.list({limit})` returns authorized **live** authority sessions (`scope: "live"`),+ not the full historical session picker. `session.info({session_id})` is a lightweight,+ authorized view of source, current model, lazy-agent status, and profile ID.+- `ping({})` returns `{pong: true}`. `runtime.describe({})` exposes only authority identity,+ epoch, and the narrow implemented creation contract. It does not claim full runtime+ protocol readiness, reveal credentials/paths, start an agent, or renew a turn lease.+- Reconnect while the owner remains alive is covered. Cold gateway restart attachment,+ reset/compression identity migration, crash recovery of local queued work, and atomic+ general creation-policy receipts remain separate integration work. Stable routing is+ not a claim of the plan's complete transactional mutation/create API.++## Verification++`tests/gateway/test_local_session.py` launches a disposable process with temporary HOME+and HERMES_HOME, the production composed HTTP/WS listener, real single-use authenticated+tickets, a loopback OpenAI-compatible model, the real TurnRunner/AIAgent, and the real+terminal tool. It proves persisted identity and same-agent reattachment; closes both+viewers while approval is pending; reconnects and consents before deleting only an owned+temporary directory; checks canonical history; and rejects forged authentication/source/+profile and unsupported launch fields. No native messaging allow-all credential is used.diff --git a/gateway/session_controls.py b/gateway/session_controls.pyindex 389ea1d25a3..cd03ce6ced4 100644--- a/gateway/session_controls.py+++ b/gateway/session_controls.py@@ -25,6 +25,7 @@ class AuthorityConnection:params = request.get('params') or {}ref = SessionRef(self.actor.profile_id, params.get('session_id', ''))handlers = {'session.create': self.create, 'ping': self.ping, 'runtime.describe': self.describe,+ 'session.list': self.list_sessions, 'session.info': self.info,'session.resume': self.resume, 'prompt.submit': self.submit,'prompt.receipt': self.receipt, 'prompt.cancel': self.cancel,'session.interrupt': self.interrupt, 'session.events.since': self.events_since,@@ -62,6 +63,36 @@ class AuthorityConnection:'capabilities': ['durable-admission-v1', 'event-replay-v1', 'local-cli-create-v1'],'session_create': {'sources': ['cli'], 'parameters': ['request_id', 'source']}}+ async def info(self, ref, params):+ from gateway.session_local import local_session_info+ if set(params) != {'session_id'}:+ raise RuntimeStoreError('invalid_params')+ await self.authority.resolve(self.actor, ref)+ return local_session_info(self.authority, ref)++ async def list_sessions(self, ref, params):+ if 'session:read' not in self.actor.capabilities:+ raise RuntimeStoreError('permission_denied')+ limit = params.get('limit', 200)+ if set(params) - {'limit'} or type(limit) is not int or not 1 <= limit <= 200:+ raise RuntimeStoreError('invalid_params')+ sessions = []+ for sid in tuple(self.authority.sessions):+ candidate = SessionRef(self.actor.profile_id, sid)+ try:+ handle = await self.authority.resolve(self.actor, candidate)+ except RuntimeStoreError as exc:+ if exc.reason not in {'permission_denied', 'profile_mismatch', 'not_found'}:+ raise+ continue+ row = self.authority.db.get_session(sid)+ sessions.append({'session_id': sid, 'id': sid, 'title': row.get('title') or '',+ 'source': row.get('source'), 'started_at': row.get('started_at'),+ 'message_count': row.get('message_count', 0),+ 'running': handle.execution_state == 'running'})+ sessions.sort(key=lambda row: row['started_at'] or 0, reverse=True)+ return {'sessions': sessions[:limit], 'scope': 'live'}+async def resume(self, ref, params):snapshot = await self.authority.attach(self.actor, ref)self.subscriptions[ref.session_id] = snapshot.subscription_iddiff --git a/tests/gateway/fixtures/local_session_peer.py b/tests/gateway/fixtures/local_session_peer.pyindex c540a5f72e4..a671297d7e6 100644--- a/tests/gateway/fixtures/local_session_peer.py+++ b/tests/gateway/fixtures/local_session_peer.py@@ -54,6 +54,11 @@ async def probe(peer, target):assert 'result' in created, createdsid = created['result']['session_id']assert sid == created['result']['stored_session_id']+ listed = await rpc(a, 'session.list', limit=10)+ assert any(row['session_id'] == sid for row in listed['result']['sessions']), listed+ info = await rpc(a, 'session.info', session_id=sid)+ assert info['result']['source'] == 'cli', info+ assert info['result']['lazy'] is True, infoassert authority.db.get_session(sid) is not Nonerepeated = await rpc(a, 'session.create', request_id='fresh', source='cli')assert repeated['result']['session_id'] == sid, repeated