diff --git a/docs/cli.md b/docs/cli.md index b1e9c2ac..3b2c2563 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -349,6 +349,12 @@ sessions pipeline runs create. The protocol types are: value all resolve to the home directory). A relative or missing directory is rejected before any OpenCode call. The created session is recorded with the stored tag `operator` and returned as the response's `chat_session`. + An optional `ephemeral: true` creates the session for automated verification: + it is created, bootstrapped and usable exactly like any other chat and can still + be closed and reopened, but its registry row is hidden, so `chat_sessions` never + lists it and a check that drives the real UI cannot leave a stray "New chat" in + the operator's list. The flag only removes a chat from the shared list, so it + cannot reveal or alter another session. - `chat_directories` returns the operator's home first, then the directories of previous operator sessions most-recently-used first, deduplicated and bounded (currently 8). It is a dedicated request so the create dialog can load the diff --git a/internal/pipeline/operator_sessions.go b/internal/pipeline/operator_sessions.go index 4d1f8a9a..fedb4736 100644 --- a/internal/pipeline/operator_sessions.go +++ b/internal/pipeline/operator_sessions.go @@ -58,7 +58,7 @@ func (s *Store) initOperatorSessions() error { _, err := s.db.Exec(`CREATE TABLE IF NOT EXISTS operator_sessions ( session_id TEXT PRIMARY KEY, directory TEXT NOT NULL, title TEXT NOT NULL DEFAULT '', tag TEXT NOT NULL DEFAULT '', created_at INTEGER NOT NULL, last_used_at INTEGER NOT NULL, -closed_at INTEGER NOT NULL DEFAULT 0); +closed_at INTEGER NOT NULL DEFAULT 0, ephemeral INTEGER NOT NULL DEFAULT 0); CREATE INDEX IF NOT EXISTS operator_sessions_recent ON operator_sessions(last_used_at DESC);`) if err != nil { return err @@ -131,7 +131,13 @@ func (s *Store) AdvanceChatCreate(ctx context.Context, requestID, from, to strin // row valid and open (0), so an upgrade is idempotent across repeated Open calls // and no session is silently reported as closed. func (s *Store) migrateOperatorSessions() error { - return s.addColumnIfMissing("operator_sessions", "closed_at", "INTEGER NOT NULL DEFAULT 0") + if err := s.addColumnIfMissing("operator_sessions", "closed_at", "INTEGER NOT NULL DEFAULT 0"); err != nil { + return err + } + // ephemeral marks a chat created for automated verification. It is hidden from + // OperatorSessions but still a real row, so the session stays usable and + // closable. Existing rows default to 0 (a normal, listed chat). + return s.addColumnIfMissing("operator_sessions", "ephemeral", "INTEGER NOT NULL DEFAULT 0") } // RecordOperatorSession upserts one operator chat session in a single statement: @@ -139,13 +145,32 @@ func (s *Store) migrateOperatorSessions() error { // repeated id updates directory/title/tag and moves last_used_at to now while // preserving the original created_at. CreatedAt is therefore stable across // re-records. Recording also clears any closed state: re-creating or adopting a -// session is use, so it is open again. +// session is use, so it is open again. The row is a normal listed operator chat +// (ephemeral = 0). func (s *Store) RecordOperatorSession(ctx context.Context, sessionID, directory, title, tag string) error { + return s.recordSession(ctx, sessionID, directory, title, tag, false) +} + +// RecordVerificationSession upserts one chat created for automated verification +// (chat_create with ephemeral set). It is a real registry row — so the session +// can still be closed, reopened and looked up by id — but OperatorSessions, and +// therefore chat_sessions, never lists it. It exists so a check that drives the +// real UI cannot leave a permanent "New chat" in the operator's list, and a +// re-record always keeps it hidden. +func (s *Store) RecordVerificationSession(ctx context.Context, sessionID, directory, title, tag string) error { + return s.recordSession(ctx, sessionID, directory, title, tag, true) +} + +func (s *Store) recordSession(ctx context.Context, sessionID, directory, title, tag string, ephemeral bool) error { now := time.Now().UnixMilli() - _, err := s.db.ExecContext(ctx, `INSERT INTO operator_sessions(session_id,directory,title,tag,created_at,last_used_at,closed_at) -VALUES(?,?,?,?,?,?,0) -ON CONFLICT(session_id) DO UPDATE SET directory=excluded.directory,title=excluded.title,tag=excluded.tag,last_used_at=excluded.last_used_at,closed_at=0`, - sessionID, directory, title, tag, now, now) + hidden := 0 + if ephemeral { + hidden = 1 + } + _, err := s.db.ExecContext(ctx, `INSERT INTO operator_sessions(session_id,directory,title,tag,created_at,last_used_at,closed_at,ephemeral) +VALUES(?,?,?,?,?,?,0,?) +ON CONFLICT(session_id) DO UPDATE SET directory=excluded.directory,title=excluded.title,tag=excluded.tag,last_used_at=excluded.last_used_at,closed_at=0,ephemeral=excluded.ephemeral`, + sessionID, directory, title, tag, now, now, hidden) return err } @@ -196,13 +221,15 @@ FROM operator_sessions WHERE session_id=? AND tag <> ''`, sessionID) // OperatorSessions reports the operator's chat sessions, most-recently-used // first (ties broken by session id for a deterministic order), capped at // operatorSessionListLimit. Rows with no tag are omitted: a session with no -// recorded tag is not an operator session and must never be listed. Closed -// sessions are included: the app groups or filters them as history, so the +// recorded tag is not an operator session and must never be listed. Ephemeral +// rows are omitted too: a chat created for automated verification is usable and +// closable but never listed here, so it cannot clutter the operator's list. +// Closed sessions are included: the app groups or filters them as history, so the // operator can still see and reopen what they finished. It is one bounded // statement; recency is never mutated here. func (s *Store) OperatorSessions(ctx context.Context) ([]OperatorSession, error) { rows, err := s.db.QueryContext(ctx, `SELECT session_id,directory,title,tag,created_at,last_used_at,closed_at -FROM operator_sessions WHERE tag <> '' ORDER BY last_used_at DESC, session_id LIMIT ?`, operatorSessionListLimit) +FROM operator_sessions WHERE tag <> '' AND ephemeral = 0 ORDER BY last_used_at DESC, session_id LIMIT ?`, operatorSessionListLimit) if err != nil { return nil, err } diff --git a/internal/pipeline/operator_sessions_test.go b/internal/pipeline/operator_sessions_test.go index e326350f..06140a79 100644 --- a/internal/pipeline/operator_sessions_test.go +++ b/internal/pipeline/operator_sessions_test.go @@ -232,3 +232,91 @@ func TestOperatorSessionsSurviveRestart(t *testing.T) { t.Fatalf("restarted row missing fields: %+v", after[0]) } } + +// TestRecordVerificationSessionIsRealButNeverListed proves the automated- +// verification contract: the row exists and is closable (so a check that drives +// the real page can still close its throwaway chat), but OperatorSessions — and +// therefore chat_sessions — never lists it. +func TestRecordVerificationSessionIsRealButNeverListed(t *testing.T) { + ctx := context.Background() + store, err := Open(filepath.Join(t.TempDir(), "verification-session.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + if err := store.RecordOperatorSession(ctx, "ses_mine", "/work/mine", "Mine", "operator"); err != nil { + t.Fatal(err) + } + if err := store.RecordVerificationSession(ctx, "ses_check", "/work/check", "New chat", "operator"); err != nil { + t.Fatal(err) + } + listed, err := store.OperatorSessions(ctx) + if err != nil { + t.Fatal(err) + } + if len(listed) != 1 || listed[0].ID != "ses_mine" { + t.Fatalf("verification session was listed: %+v", listed) + } + session, found, err := store.OperatorSession(ctx, "ses_check") + if err != nil || !found { + t.Fatalf("verification session is not looked up: found=%v err=%v", found, err) + } + if session.ID != "ses_check" || session.Directory != "/work/check" { + t.Fatalf("verification session row = %+v", session) + } + if err := store.CloseOperatorSession(ctx, "ses_check"); err != nil { + t.Fatalf("close verification session: %v", err) + } + // Re-recording keeps it hidden, and a normal record of the same id lists it + // again (the flag is replaced, not sticky). + if err := store.RecordVerificationSession(ctx, "ses_check", "/work/check", "New chat", "operator"); err != nil { + t.Fatal(err) + } + if listed, err = store.OperatorSessions(ctx); err != nil || len(listed) != 1 { + t.Fatalf("re-recorded verification session listed: %+v err=%v", listed, err) + } + if err := store.RecordOperatorSession(ctx, "ses_check", "/work/check", "Kept", "operator"); err != nil { + t.Fatal(err) + } + if listed, err = store.OperatorSessions(ctx); err != nil || len(listed) != 2 { + t.Fatalf("a normal re-record did not list the session: %+v err=%v", listed, err) + } +} + +// TestOperatorSessionsMigrationAddsEphemeral proves an existing database created +// before the ephemeral column opens cleanly and keeps every existing chat listed. +func TestOperatorSessionsMigrationAddsEphemeral(t *testing.T) { + ctx := context.Background() + path := filepath.Join(t.TempDir(), "migrate-ephemeral.db") + store, err := Open(path) + if err != nil { + t.Fatal(err) + } + if err := store.RecordOperatorSession(ctx, "ses_old", "/work/old", "Old", "operator"); err != nil { + t.Fatal(err) + } + if _, err := store.db.ExecContext(ctx, "ALTER TABLE operator_sessions DROP COLUMN ephemeral"); err != nil { + t.Fatalf("drop ephemeral: %v", err) + } + if err := store.Close(); err != nil { + t.Fatal(err) + } + store, err = Open(path) + if err != nil { + t.Fatalf("Open after drop: %v", err) + } + defer store.Close() + listed, err := store.OperatorSessions(ctx) + if err != nil { + t.Fatal(err) + } + if len(listed) != 1 || listed[0].ID != "ses_old" { + t.Fatalf("migrated session list = %+v", listed) + } + if err := store.RecordVerificationSession(ctx, "ses_new_check", "/work/new", "New chat", "operator"); err != nil { + t.Fatal(err) + } + if listed, err = store.OperatorSessions(ctx); err != nil || len(listed) != 1 { + t.Fatalf("verification session listed after migration: %+v err=%v", listed, err) + } +} diff --git a/internal/protocol/chat.go b/internal/protocol/chat.go index c9f9f4ed..cd6b87da 100644 --- a/internal/protocol/chat.go +++ b/internal/protocol/chat.go @@ -187,6 +187,14 @@ type ChatCreateRequest struct { Title string `json:"title,omitempty"` Directory string `json:"directory,omitempty"` OperationID string `json:"operation_id,omitempty"` + // Ephemeral creates a chat for automated verification: the session is created, + // bootstrapped and usable exactly like a normal one, but no operator-registry + // row is written, so it can never appear in chat_sessions. It exists because a + // verification client drives the real UI and would otherwise leave a permanent + // "New chat" in the operator's list for every run. The flag is client-supplied + // and only ever *removes* a chat from the shared list, so a buggy or hostile + // client can hide its own chat but cannot reveal or alter another one. + Ephemeral bool `json:"ephemeral,omitempty"` } // ChatAdoptRequest is the chat_adopt request body: the id of a session that diff --git a/internal/server/chat.go b/internal/server/chat.go index c0da3f30..8ae8bd3f 100644 --- a/internal/server/chat.go +++ b/internal/server/chat.go @@ -68,6 +68,9 @@ type operatorRegistry interface { SetChatCreateSession(ctx context.Context, requestID, sessionID string) error AdvanceChatCreate(ctx context.Context, requestID, from, to string) error RecordOperatorSession(ctx context.Context, sessionID, directory, title, tag string) error + // RecordVerificationSession records a chat created for automated verification: + // a real, closable row that OperatorSessions never lists. + RecordVerificationSession(ctx context.Context, sessionID, directory, title, tag string) error TouchOperatorSession(ctx context.Context, sessionID string) error OperatorSessions(ctx context.Context) ([]pipeline.OperatorSession, error) OperatorDirectories(ctx context.Context, limit int) ([]string, error) diff --git a/internal/server/chat_sessions.go b/internal/server/chat_sessions.go index a2213e94..5b22851f 100644 --- a/internal/server/chat_sessions.go +++ b/internal/server/chat_sessions.go @@ -90,7 +90,9 @@ func handleChatSessions(ctx context.Context, request protocol.Message, broker ch // resolved directory, the title and the operator tag. A blank or omitted // directory defaults to the operator's home, never the server's working // directory. A registry write failure answers an error naming the created id, so -// an orphaned session is visible rather than silently reported as success. +// an orphaned session is visible rather than silently reported as success. A +// request with Ephemeral set creates the session without any registry row, for +// automated verification that must never add a chat to the operator's list. func handleChatCreate(ctx context.Context, request protocol.Message, broker chatBroker, registry operatorRegistry, write func(protocol.Message) error) { if broker == nil { _ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "chat is not configured on this server"}) @@ -103,10 +105,12 @@ func handleChatCreate(ctx context.Context, request protocol.Message, broker chat title := "" directory := "" operationID := "" + ephemeral := false if request.ChatCreate != nil { title = strings.TrimSpace(request.ChatCreate.Title) directory = strings.TrimSpace(request.ChatCreate.Directory) operationID = strings.TrimSpace(request.ChatCreate.OperationID) + ephemeral = request.ChatCreate.Ephemeral } // Legacy clients did not carry a durable create identity. Give each received // request its own server-generated scope so their connection-local envelope @@ -182,7 +186,14 @@ func handleChatCreate(ctx context.Context, request protocol.Message, broker chat chatCreateConflictError(request, err, write) return } - if err := registry.RecordOperatorSession(ctx, session.ID, resolved, title, protocol.ChatSessionTagOperator); err != nil { + // An ephemeral (verification) create records a real but hidden row: the chat + // stays usable and closable, and chat_sessions never lists it. Everything + // else about the session — its id, skill activation and use — is identical. + record := registry.RecordOperatorSession + if ephemeral { + record = registry.RecordVerificationSession + } + if err := record(ctx, session.ID, resolved, title, protocol.ChatSessionTagOperator); err != nil { _ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "session " + session.ID + " was created but could not be recorded: " + err.Error()}) return } @@ -198,8 +209,12 @@ func handleChatCreate(ctx context.Context, request protocol.Message, broker chat session.Tag = protocol.ChatSessionTagOperator response := protocol.Message{Type: protocol.ChatCreate, ID: request.ID, ChatSession: &session} // The same registry row is echoed on the list field so a client can splice it - // into chat_sessions without a re-list. - response.ChatSessions = []protocol.ChatSession{session} + // into chat_sessions without a re-list. An ephemeral create has no listed row + // to splice, so that field stays empty and the client that asked for it opens + // the session from the echoed ChatSession instead. + if !ephemeral { + response.ChatSessions = []protocol.ChatSession{session} + } _ = write(response) } diff --git a/internal/server/chat_test.go b/internal/server/chat_test.go index 312bc221..c4c567c7 100644 --- a/internal/server/chat_test.go +++ b/internal/server/chat_test.go @@ -1451,6 +1451,60 @@ func TestChatCreateRecordsOperatorSession(t *testing.T) { } } +func TestChatCreateEphemeralSessionIsNeverListed(t *testing.T) { + store := newOperatorStore(t) + broker := scriptedChat() + broker.created = protocol.ChatSession{ID: "ses_verify", Title: "New chat"} + dir := t.TempDir() + ctx, _, conn := dialChatOptions(t, Options{Chat: broker, OperatorRegistry: store}) + if err := wsjson.Write(ctx, conn, protocol.Message{Type: protocol.ChatCreate, ID: "c1", ChatCreate: &protocol.ChatCreateRequest{Title: "New chat", Directory: dir, Ephemeral: true}}); err != nil { + t.Fatal(err) + } + var response protocol.Message + if err := wsjson.Read(ctx, conn, &response); err != nil { + t.Fatal(err) + } + // The session is real and usable: it is created, bootstrapped and echoed. + if response.Type != protocol.ChatCreate || response.ChatSession == nil || response.ChatSession.ID != "ses_verify" { + t.Fatalf("ephemeral chat_create response = %+v", response) + } + if calls, _, _ := broker.createQuery(); calls != 1 { + t.Fatalf("broker.Create calls = %d, want 1", calls) + } + broker.mu.Lock() + activateCalls := broker.activateCalls + broker.mu.Unlock() + if activateCalls != 1 { + t.Fatalf("manager bootstrap calls = %d, want 1", activateCalls) + } + // No LISTED row was written, so no list row is echoed and chat_sessions cannot + // list the verification chat... + if len(response.ChatSessions) != 0 { + t.Fatalf("ephemeral chat echoed a registry row: %+v", response.ChatSessions) + } + recorded, err := store.OperatorSessions(ctx) + if err != nil { + t.Fatal(err) + } + if len(recorded) != 0 { + t.Fatalf("ephemeral chat recorded %d listed operator session(s): %+v", len(recorded), recorded) + } + // ...but the row is real, so the session stays closable like any other chat. + if _, found, err := store.OperatorSession(ctx, "ses_verify"); err != nil || !found { + t.Fatalf("ephemeral chat is not closable: found=%v err=%v", found, err) + } + if err := store.CloseOperatorSession(ctx, "ses_verify"); err != nil { + t.Fatalf("close ephemeral chat: %v", err) + } + listed, err := store.OperatorSessions(ctx) + if err != nil { + t.Fatal(err) + } + if len(listed) != 0 { + t.Fatalf("closing an ephemeral chat listed it: %+v", listed) + } +} + func TestChatCreateReportsManagerBootstrapFailure(t *testing.T) { broker := &fakeChat{created: protocol.ChatSession{ID: "ses_new"}, activateErr: errors.New("skill not found")} store := newOperatorStore(t) diff --git a/web/PARITY.md b/web/PARITY.md index 09e05168..63d5911b 100644 --- a/web/PARITY.md +++ b/web/PARITY.md @@ -88,25 +88,26 @@ the pipeline list already carries — rather than a pluralised verb. ## Chat | # | Feature | Protocol | Status | | --- | --- | --- | --- | -| C1 | Session list (operator sessions, closed grouped as history) | `chat_sessions` | done — captured 2026-10-19: `captures/44-chat-sessions.png` (the live server's one operator session: "New chat", the `Operator` kind chip, the meta line `Idle · /Users/alan/repos/pipelines` and a `Close chat…` row action) and `captures/50-chat-no-match.png` (the narrowed-to-nothing state `No chats match "zzz-no-such-chat".` with its `Clear search` action). A row is the title (`sessionTitle`: the server title, else the id's first 18 characters, else `Untitled chat`), the kind chip derived from the server tag (`operator` → `Operator`, any other tag verbatim, a blank tag no chip), a `Closed` chip only when closed, the activity badge word (`Streaming` / `New` / `Open`, `Open` only while its conversation is open), and meta = work label · directory · model with blanks omitted (`Running` / `Running {tool}` / `Running {N} tools` while a turn is in flight, else `Busy · read-only`, else `Idle`). Active sessions are grouped by directory only when there is more than one group (header = the directory or `No directory`); closed sessions sit below under a `Closed` header, each reopenable. The search field is labelled `Search chats` and narrows by title or directory, case-insensitively, never re-sorting; the empties are `Loading chats…`, `No chat sessions on this server yet.` with a `New chat` action placeholder (wired by C2) and `No chats match "{query}".` with `Clear search`. The `Loading chats…` and `No chat sessions on this server yet.`/`New chat` states are implemented but not captured: the live server always lists its one operator session, so neither state is reachable against it | -| C2 | Create a chat (directory picker) | `chat_directories`, `chat_create` | todo | +| C1 | Session list (operator sessions, closed grouped as history) | `chat_sessions` | done — captured 2026-10-19: `captures/44-chat-sessions.png` (the live server's one operator session: "New chat", the `Operator` kind chip, the meta line `Idle · /Users/alan/repos/pipelines` and a `Close chat…` row action) and `captures/50-chat-no-match.png` (the narrowed-to-nothing state `No chats match "zzz-no-such-chat".` with its `Clear search` action). A row is the title (`sessionTitle`: the server title, else the id's first 18 characters, else `Untitled chat`), the kind chip derived from the server tag (`operator` → `Operator`, any other tag verbatim, a blank tag no chip), a `Closed` chip only when closed, the activity badge word (`Streaming` / `New` / `Open`, `Open` only while its conversation is open), and meta = work label · directory · model with blanks omitted (`Running` / `Running {tool}` / `Running {N} tools` while a turn is in flight, else `Busy · read-only`, else `Idle`). Active sessions are grouped by directory only when there is more than one group (header = the directory or `No directory`); closed sessions sit below under a `Closed` header, each reopenable. The search field is labelled `Search chats` and narrows by title or directory, case-insensitively, never re-sorting; the empties are `Loading chats…`, `No chat sessions on this server yet.` with a `New chat` action (C2) and `No chats match "{query}".` with `Clear search`. The `Loading chats…` and `No chat sessions on this server yet.`/`New chat` states are implemented but not captured: the live server always lists its one operator session, so neither state is reachable against it | +| C2 | Create a chat (directory picker) | `chat_directories`, `chat_create` | done — captured 2026-10-19: `captures/75-chat-create-picker.png` (the list's `New chat` action opens `Start a chat`; back `Cancel new chat`, prompt `Where should this chat live?`, home `Home (~)` first and selected with `/Users/alan` beneath it, two recents labelled by their full paths, the model note, and the footer `Start in ~` / `Cancel` / `New chat`), `captures/76-chat-created-list.png` (the one real session `ses_eabc47a91ffe31C6zNX4ieXN6e`, titled `New chat`, created with exactly `{title:"New chat",directory:"~",operation_id:"…"}`, at the head of the list and active with its empty history) and `captures/77-chat-created-closed.png` (the same session closed through the `Close chat…` → `chat_close` confirm, now carrying the `Closed` chip as history). Blank directory entries are dropped, an empty reply still yields home, `~` is sent for home and the absolute path for a recent, and the create is guarded against double submission; a refusal stays in the open pane with the server's own text. The operator's own `ses_eae413f50ffeLQDExlg8cYnscN` was not selected, closed, reopened or prompted by this item. The smoke created exactly one real session and closed it; nothing was deleted | | C3 | Open / close / reopen a session | `chat_close`, `chat_reopen` | done — captured 2026-10-19: `captures/49-chat-close-confirm.png`. Selecting a row opens the conversation (see C4); an open row offers `Close chat…` and a closed row offers `Reopen`. The confirm is the Android copy verbatim: title `Close chat?`, the body naming the session title (`Closes "{title}" and marks it closed on every device. A turn that is running is stopped first. Nothing is deleted — the chat and its history are kept, and you can reopen it from the list.`), confirm `Close chat`, dismiss `Cancel`; only the confirm sends `chat_close` (and `Reopen` sends `chat_reopen`), then the list is refreshed from the server. The `Close chat…` action is offered on every open row, so its confirm is rendered from the pane's overlays **whether or not a conversation is open** — the smoke exercises the row-level path with no session selected (`ui-smoke` asserts the confirm appears and dismisses it), not only the path after opening the row. **Shown, not executed**: the live server has exactly one session — `ses_eae413f50ffeLQDExlg8cYnscN`, the operator's own — so the dialog was shown, captured and dismissed with `Cancel`; **no `chat_close` was sent** and that session was not closed or reopened by this stage | | C4 | History with paging / "load older" | `chat_messages` | done — captured 2026-10-19: `captures/45-chat-transcript-newest.png` (the opened `ses_eae413f50ffeLQDExlg8cYnscN` transcript with the `Load older messages` control beside the conversation's identity while the server reports `has_more`) and `captures/48-chat-load-older-empty.png` (after pressing it: the live session's own opaque cursor returned an empty older page, so `has_more` went false and the control disappeared — the honest result of the server's cursor, distinct from 45). The request is exactly `{type:"chat_messages",chat_query:{session_id,limit:200,cursor}}`; the newest page is read with an empty cursor and an older page with the server's own opaque `next_cursor` passed back verbatim (never interpreted), and the reply is `chat_history.{messages,next_cursor,has_more}` with an older server's bare `chat_messages` falling back to `hasMore:false`. `mergeHistoryPage` prepends an older page, dedupes by id (order-preserving, the page's copy winning) and replaces `nextCursor`/`hasMore`; the prepend itself is unit-tested (`test/chat.test.mjs`) because the live server returned no older rows. Nothing auto-loads on scroll and there is no end-of-history row | | C5 | Live transcript: user/assistant text, one reply = one turn | `chat_subscribe`, `chat_event` | done — captured 2026-10-19: `captures/56-chat-live-turn.png` (the answer text growing inside the existing single agent bubble while the reasoning step count grows), `captures/57-chat-running.png` (the running indicator: spinner + `Running a tool…` + `· 1s` + the `shell npm run build` line), `captures/58-chat-long-call.png` (a 61 s-old call tinted ` · long`), `captures/59-chat-settled.png` (the tools completed and the step ended: no indicator, the same one agent bubble). Opening a conversation attaches its shared live stream with exactly `{type:'chat_subscribe',chat_subscribe:{session_id}}` (the `chat_subscribe` field, **not** `chat_query`; internal/protocol/message.go, chat_stream.go) and folds every pushed `chat_event` into the open thread; the session is never read-only and any number of clients may watch it. `client.js` surfaces an envelope with no matching pending id as a DOM-free `frame` event (a matched reply is still resolved by id and not broadcast) and `src/app.js` folds only `chat_event` frames for a session this client has open. There is **no** `chat_unsubscribe` on the wire: the server detaches a subscription when the connection closes (chat_hub.detachClient / websocket.go), so on a socket drop the page clears its subscription set and settles every running thread, and on reconnect re-subscribes the open chat and replaces its conversation with the newest history page wholesale (`historyResync`, no stale held turn) — captured by the smoke's own reconnect. The pure fold lives in `src/chat.js` (`applyChatEvent` and helpers) and is unit-tested: a `user` frame needs a non-blank message id and text, is ignored when the id already exists and keeps the sender's `client` label (the server never echoes this client's own prompt); `text`/`reasoning` deltas append to the part their kind started (`deltaPartId`, so the two kinds can never share a part) and a live turn that spans several assistant message ids stays one `transcriptRows` agent bubble; `tool` frames merge field by field (a non-empty incoming field wins, `state.status/input/content/metadata/error` each retained when omitted, `executed` sticky, `time` retained), so a later frame never blanks what an earlier one taught; `step` runs the turn unless the status is `ended`; a `shell` frame is C11's and never marks the turn running; `usage` is not folded; any frame clears `queued`. The live badge uses the same words as the run badge — `live` while subscribed on a connected socket, `reconnecting` while the socket is coming back, `not live` when idle/refused (`chatStreamState`, unit-tested; the smoke logs all three). The running indicator (under the transcript, after the last agent turn) is a spinner plus the phase headline (`Thinking…` / `Running a tool…` / `Waiting…`) and ` · {elapsed}`, then one line per running tool with its own elapsed; a call at or past 60 s is tinted and marked ` · long`. **Replayed vs real, stated plainly**: the live server had no turn to prompt (its only session is the operator's, and this stage does not write to it), so `ui-smoke.mjs` subscribes through the real server and every history reply is real, then replays exact `chat_event` frames through the socket's own `onmessage` (a WebSocket recorder shim installed before the page's scripts via `Page.addScriptToEvaluateOnNewDocument`); the smoke log names the replayed frames and asserts the subscribe ack and history came from the real server | | C6 | Reasoning block + tool calls with name/input for the whole lifecycle | `chat_event` | done — the assistant turn draws, in order, its one collapsible reasoning block and its one tool-call chip (then the answer). Reasoning labels match the app: `Thinking…` / `Reasoning` for a single step and `Thinking · {N} steps` / `Reasoning · {N} steps` for several, with ` · {duration}` appended when the parts' timing gives a settled span (earliest start → latest completed), through chevrons named `Show reasoning` / `Hide reasoning`. The chip reads `1 tool called` / `{N} tools called`, announces `… expand for details`, wears the shared spinner while a call is in flight and an error tint once one failed, and opens a fixed overlay panel under the chip (flipped above / clamped into the viewport when there is no room) with the same count, a `Close tool calls` control and an internally scrolling, independently-expandable row per call: the name (else `tool`), the first of `description`/`command`/`filePath`/`file_path`/`path`/`pattern`/`query`/`url` collapsed and elided to 72 characters, the `+N -M` edit stat when present, the `formatToolDuration` value (`340ms`/`1.2s`/`2m 3s`), and `Expand {name}`/`Collapse {name}`; a failed row is marked `Failed tool call`. An expanded row shows INPUT (pretty-printed JSON, or the raw partial string), the LCS edit diff (at most 200 rendered lines with the remaining `… {N} more changed line(s) not shown`), then ERROR (the server's `error.message`, else the output) or OUTPUT (`(no output)` when settled and empty, nothing while in flight). Lifecycle words `streaming`/`running` are in flight and `completed`/`error` settled; a settled call never spins or wears the ` · long` mark. Because the panel is a fixed overlay, opening or closing it never re-flows the transcript nor moves its scroll (C14). Captured 2026-10-19 against `ses_eae413f50ffeLQDExlg8cYnscN` (one folded turn, 80 reasoning steps, 122 tool calls): `captures/51-chat-reasoning-collapsed.png`, `captures/52-chat-reasoning-expanded.png`, `captures/53-chat-tool-chip.png`, `captures/54-chat-tool-panel.png` (an opened `read` row showing INPUT + OUTPUT) and `captures/55-chat-edit-diff-sample.png`. The live history carries no failed or edit-family call, so that capture renders a labelled page-rendered sample — a `shell` row marked `Failed tool call` with INPUT + ERROR and an `edit` row with a `+2 -1` diff — through the page's own row builder; the transcript stayed put across open/close (top 43065 → 43065). **Live arrival over `chat_event` is C5**: the renderer is built from the same part shapes (`ChatPart{type,name,state{status,input,content,error},time}`) and takes a `streaming` flag plus a live elapsed source so C5 can drive in-flight calls; the chip's in-flight spinner, the ` · long` 60s mark, the panel flip-above and an edit-family call are not reachable against the live server, so they are unit-tested (`test/chat.test.mjs`) rather than claimed as captured | | C7 | Markdown rendering + code blocks | — | done — captured 2026-10-19: `captures/45-chat-transcript-newest.png` (opened at the newest content: bold, bullet lists, a `|` table with its `---` delimiter row and inline code spans from the live assistant answer), `captures/47b-chat-markdown-code.png` (a rendered fenced code block — label `js`, the pre body `const answer = 42;` — drawn in the live browser by the page's own `renderMarkdown`, the same function that renders the answer) and `captures/47-chat-reasoning-code.png`. The subset is exactly `Markdown.kt`: paragraphs, `#`–`######` headings, fenced code (```/~~~, the language label else `code`), block quotes, bullet/ordered lists, `|` tables with a `---` delimiter row, thematic rules, inline code, bold, italic (underscore only at word boundaries, so `snake_case` stays plain), `[label](url)` links and bare http(s) autolinks; HTML entities are decoded first in one pass, and HTML, reference links, strikethrough and nested lists render as plain text and are never dropped. **Code-block caveat, stated plainly**: the live assistant answer carries **no** fenced block — its four fences live in the reasoning transcript, which the app draws as plain text, not as markdown (`captures/47-chat-reasoning-code.png` shows one such fence as muted plain text; that is C6 material, not the markdown path). So the rendered `
` code block is captured from a labelled sample through the page's real renderer (`47b`), and the same path plus its `code`-else-language label is unit-tested in `test/markdown.test.mjs`. Only `http(s)` link targets become clickable — the transcript is untrusted model output, so a `javascript:`/`data:` target renders as its label, never as a live link | | C8 | Composer: send, stop, attachments, draft | `chat_prompt`, `chat_interrupt` | done — the composer at the foot of an open conversation: a growing 1–6-row `