mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-16 03:16:29 +00:00
feat(codex): share sessions across terminal and web
Use one native app-server for terminal, Web and phone clients while retaining the existing CLI and Runner lifecycle. Synchronize native queues, permissions, question history and steering state; preserve explicit permission precedence and per-turn usage models. Resume inactive clear commands through Runner and reject independent child cold resumes. Add shared-runtime regression tests, generated protocol fixtures and lifecycle documentation.
This commit is contained in:
@@ -47,6 +47,7 @@ Source: `hub/src/web/routes/sessions.ts`; request schemas in `shared/src/apiType
|
||||
| `PATCH /api/sessions/:id/summary` | `{text}` (1–255 chars) | `{ok: true}` |
|
||||
| `PUT /api/sessions/:id/pin` | `{mode: 'none'\|'project'\|'global'}` | `{ok: true}` |
|
||||
| `POST /api/sessions/:id/switch` | `{}` | `{ok: true}` — hands terminal-controlled session over to remote control |
|
||||
| `POST /api/sessions/:id/clear` | `{}` | `{sessionId}` — shared sessions only; resume inactive sessions through the Runner first, then create a new root; navigate only the initiating view |
|
||||
| `POST /api/sessions/:id/title-suggestion` | — | `{title}`; errors pass through 422/429/502/503 |
|
||||
| `GET /api/sessions/:id/slash-commands` | — | `SlashCommandsResponse` `{success, commands?, error?}` |
|
||||
| `GET /api/sessions/:id/skills` | — | `SkillsResponse`-shaped `{success, ...}` |
|
||||
@@ -76,6 +77,11 @@ The hub stamps `sentFrom: 'webapp'` on REST-sent messages server-side; the reque
|
||||
|
||||
Source: `hub/src/web/routes/permissions.ts`. Pending requests are **not messages**: they live in `session.agentState.requests` (keyed by request id) and move to `agentState.completedRequests` when resolved — schemas `AgentStateRequestSchema` / `AgentStateCompletedRequestSchema` in `shared/src/schemas.ts`.
|
||||
|
||||
Shared Codex completed requests may have `status: 'resolved'`: native completion
|
||||
is known, but the winner/answer is not. Render a neutral status, not Approved or
|
||||
an inferred selection. A successful approve HTTP response only submitted a
|
||||
candidate. `canceled` can instead mean withdrawal after a transport disconnect.
|
||||
|
||||
| Method & path | Request | Response |
|
||||
|---|---|---|
|
||||
| `POST /api/sessions/:id/permissions/:requestId/approve` | `{mode?, allowTools?: string[], decision?, answers?}` | `{ok: true}` |
|
||||
@@ -99,6 +105,17 @@ Source: `hub/src/web/routes/sessions.ts`; flavor gates in `shared/src/modes.ts`
|
||||
| `POST /api/sessions/:id/collaboration-mode` | `{mode: 'default' \| 'plan'}` | codex (remote-only) |
|
||||
| `POST /api/sessions/:id/copilot-agent-mode` | `{mode}` | copilot (remote-only) |
|
||||
|
||||
`metadata.capabilities.concurrentClients === true`: ignore the legacy
|
||||
`agentState.controlledByUser` input/settings gate. Shared keepalives have no
|
||||
ownership mode. `/switch` returns HTTP 409 with
|
||||
`code: 'control_mode_not_applicable'`; do not offer takeover. The remote-only
|
||||
Codex configuration restrictions above do not apply to these sessions.
|
||||
|
||||
Shared `/clear` has no global `supersededBySessionId` change; clients other than
|
||||
the caller stay on the original thread. Fork may return an already-bound shared
|
||||
child; the hub must not spawn a second engine. Use advertised history
|
||||
capabilities: shared Codex currently supports fork, not in-place rewind.
|
||||
|
||||
All respond `{ok: true}`; apply-failures return 409 with a message. Model/effort **catalogs** (RPC-wrapped; all return `{success, ...} \| {success: false, error}`):
|
||||
|
||||
| Method & path | Notes |
|
||||
|
||||
@@ -147,7 +147,7 @@ Schema: `SyncEventSchema` in `shared/src/schemas.ts` (discriminated on `type`).
|
||||
| `machine-agy-models-updated` | `machineId` | The machine's `agy models` listing changed on a background re-check. Refetch `GET /api/machines/:id/agy-models` for that machine (answered from the machine's cache; it starts no `agy` run and produces no further event). Emitted when the re-check changes what that route would answer — a different listing, or a sign-in warning that appeared or cleared — never for the machine's first listing. |
|
||||
| `toast` | `data: {title, body, sessionId, url}` | Show as in-app toast/banner. Only delivered to visible connections (see [Visibility](#visibility)). |
|
||||
| `messages-consumed` | `sessionId`, `localIds: string[]`, `invokedAt: number` | The agent consumed queued user messages: stamp `invokedAt`, flip status to `sent`, remove from the queued bar. |
|
||||
| `messages-indeterminate` | `sessionId`, `localIds: string[]` | A steer was dispatched but its outcome is unknown. Keep the row uninvoked, show an explicit Retry/Cancel resolution, and do not auto-replay it. |
|
||||
| `messages-indeterminate` | `sessionId`, `localIds: string[]` | A native dispatch/queue mutation has an unknown outcome. Keep the row uninvoked, show an explicit Retry/Cancel resolution, and do not auto-replay it. Shared-engine Retry/Cancel can remain unavailable until reconciliation proves the outcome. |
|
||||
| `messages-requeued` | `sessionId`, `localIds: string[]` | An explicit Retry restored delivery to the normal queue. Clear the indeterminate marker. |
|
||||
| `message-cancelled` | `sessionId`, `messageId`, `localId?` | A queued message was cancelled: remove the row (match by `messageId` **or** `localId`). |
|
||||
| `heartbeat` | `data?: {timestamp}` | Feed the staleness watchdog. No other action. **Carries no `id`.** |
|
||||
|
||||
Reference in New Issue
Block a user