Skip to content

feat(serve): event stream, transcript read and resume-by-id for remote UI clients #524

Closed

Description

@ajianaz

What problem does this solve?

A graphical client (desktop, phone, web) needs three things tole serve does not offer today:

  • Live events. POST /sessions/{id}/prompt blocks until the turn ends; there is no event stream, so a UI cannot show streamed text, tool cards or approval requests as they happen.
  • Reading a transcript. There is no route to read a session's entries, so a client that connects late (or reconnects) cannot render history.
  • Resuming a session by id. GET /sessions lists only live sessions and POST /sessions only accepts cwd, so a client cannot reopen an existing session.

docs/mobile-control.md currently says "no new backend exists or is planned"; that has to change for UI clients. This is also what the gateway/scheduler discussion needs (see disc:tole-naik-kelas notes), so it is not UI-only work.

Proposed solution

Additive routes under the existing token-authenticated serve face (no change to existing routes):

  • GET /sessions/{id}/events?after=<seq> — Server-Sent Events.
    • Durable frames: entries from the session JSONL, each carrying its seq. The log is append-only with strictly increasing seq, so after=<seq> (and Last-Event-ID) gives lossless replay after a reconnect.
    • Ephemeral frames: text_delta, reasoning, tool started/finished from TurnObserver. These are best-effort and not replayable (deltas are not stored; the final answer is an entry).
    • Approval frames: approval_requested / approval_resolved, mirroring the existing /approvals queue.
    • Heartbeat comment frames; the stream ends cleanly when the session is closed.
  • GET /sessions/{id}/entries?after=<seq>&limit=<n> — paginated transcript read (JSON).
  • Resume by id: POST /sessions accepts an existing session id (shape to be agreed in this issue).
  • Optional, may be split out: POST /sessions accepts model / effort at creation.
  • Wire types as serde structs in one protocol module with a JSON Schema export, so Dart and TypeScript clients can be generated instead of hand-written.

Docs in the same PR (AGENTS.md §7): docs/mobile-control.md, docs/daemon-design.md, README status line, docs/epics.md.

Open questions

  • SSE vs WebSocket. SSE is one-way, curl-able and fits the append-only log; browsers' EventSource cannot send an Authorization header, so a web client needs a fetch-based stream reader (or a short-lived stream token). Preferred: SSE.
  • Are lost deltas acceptable on reconnect? Proposal: yes, the final answer entry always arrives; clients show a "resynced" marker.
  • Backpressure and a cap on concurrent streams per token.
  • Does after=<seq> on a very large session need an index, given sessions --all replays every file today?

Alternatives considered

  • Polling GET /sessions/{id}/status (what mobile does now): no streamed text, no history.
  • ACP as the UI transport: ACP is an editor protocol over stdio; a phone cannot use it.

Acceptance criteria

  • Gate: owner approves un-parking the multi-client daemon (see epic).
  • Events route replays losslessly from a seq after a dropped connection (test).
  • Transcript read is paginated and matches what tole resume replays (test).
  • Resume-by-id works and respects the per-session jail and busy rules (test).
  • No route weakens approval gates: approvals stay owner-token decisions; Destructive stays unregistrable without an interactive approver.
  • Docs synced in the same PR.

Part of #523.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions