web: create a chat through the directory picker (C2)
This commit is contained in:
+17
-13
@@ -88,15 +88,15 @@ 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 `<pre>` 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 `<textarea>` (placeholder `Message the agent… or / for commands`) where Enter submits and Shift+Enter inserts a newline (the submit routing is the pure `composerSubmit`), an `Attach file` control opening a multi-file picker, a removable chip per attachment (an image thumbnail else a file glyph, the display name, then the error text or `humanBytes(size)`, and a remove control named `Remove {name}`), and one primary control: Stop (`aria-label`/title `Stop`, error tint) while a turn runs, else Send (`aria-label` `Send`, disabled unless a non-blank draft with no failed attachment — or a slash draft). The 25 MiB guard reads `"{display}" is too large (25.0 MiB limit).` and an unreadable file `"{display}" could not be read.`; the web file picker cannot produce an unreadable file, so only the limit branch is captured and both are unit-tested (`test/chat.test.mjs`). Send trims the draft, clears the draft and the attachments at once, calls `chatPrompt` with `{session_id,text,operation_id,native_message_id}` (+ `files` only when present) and reads the reply's `chat_queued` into the notice `Queued — it will send when the current turn finishes.`; a rejected prompt restores the draft and the attachments (each flagged with the server's own message) and shows the shared `Action failed` dialog. The queued flag clears on any incoming frame (the client fans unsolicited envelopes out as a `frame` event; the composer folds it). The draft is kept per chat in memory **and** mirrored into `localStorage` (`pipelines.web.chatDraft.v1`) — the web analogue of per-device persistence — while attachments stay memory-only. Captured 2026-10-19 against a **freshly created** session (never the operator's own): `captures/56-chat-composer-draft.png`, `captures/60-chat-attachment-chips.png`, `captures/61-chat-attachment-removed.png`, `captures/63-chat-composer-stop.png` (a real prompt to the throwaway session turned Send into Stop), `captures/63b-chat-stop-interrupt.png` (the Stop control was **clicked**: it sent `chat_interrupt` and the page showed `Stopping the running turn…`, with no `Action failed` — the control is wired to `chat_interrupt`, never to the inert submit path) and `captures/64-chat-throwaway-closed.png` (after `/close`, the closed row plus the conversation pane left for the list). The throwaway session was created with `chat_create`, really prompted, really interrupted and closed with `chat_close`; the operator's session `ses_eae413f50ffeLQDExlg8cYnscN` was never prompted |
|
||||
| C9 | Slash commands | client-side | done — the palette appears above the composer only while the trimmed draft starts with `/` and has no whitespace, filtered case-insensitively by name prefix, each row showing `/name` and the summary and the highlighted row marked `aria-selected`; Up/Down move the highlight and Enter runs it, a tap runs a row directly, and running a command always consumes the draft and never reaches the prompt path. The five commands and their summaries are `CHAT_COMMANDS` (`/new`, `/close`, `/rename <title>`, `/stop`, `/help`), unit-tested verbatim, with `chatCommandHelp()` the `usage — summary` lines. Effects: `/new` sends `chat_create` directly (C2's item) and opens the created session, `/close` reuses the C3 `Close chat?` confirm, `/rename` is the local rename pending C13, `/stop` interrupts (`chat_interrupt`) and `/help` shows the command list. Error wording is the Android source verbatim: the unknown command reads `“{token}” is not a command, so nothing was sent to the agent. Send it as a message, or cancel.` with the draft offered back and `Send as message` / `Cancel`; an extra argument on an argument-less command reads `{usage} does not take an argument.`; `/rename` with no title reads `Usage: /rename <title> — renames this session on this device.`; `/stop` with nothing running reads `No turn is running in this chat.`. A notice renders as a full-width line after the turns (not a bubble) with the label `Command` / `Command failed` and a terminal glyph, error-coloured when failed. Captured 2026-10-19: `captures/57-chat-command-palette.png`, `captures/58-chat-command-palette-selected.png` (ArrowDown moved the highlight), `captures/59-chat-command-unknown.png` (the failed notice and its offer, dismissed with Cancel), `captures/62-chat-new-session.png` (`/new`'s created session and its `Command` notice) |
|
||||
| C9 | Slash commands | client-side | done — the palette appears above the composer only while the trimmed draft starts with `/` and has no whitespace, filtered case-insensitively by name prefix, each row showing `/name` and the summary and the highlighted row marked `aria-selected`; Up/Down move the highlight and Enter runs it, a tap runs a row directly, and running a command always consumes the draft and never reaches the prompt path. The five commands and their summaries are `CHAT_COMMANDS` (`/new`, `/close`, `/rename <title>`, `/stop`, `/help`), unit-tested verbatim, with `chatCommandHelp()` the `usage — summary` lines. Effects: `/new` sends `chat_create` directly (one step, separate from C2's picker) and opens the created session, `/close` reuses the C3 `Close chat?` confirm, `/rename` is the local rename pending C13, `/stop` interrupts (`chat_interrupt`) and `/help` shows the command list. Error wording is the Android source verbatim: the unknown command reads `“{token}” is not a command, so nothing was sent to the agent. Send it as a message, or cancel.` with the draft offered back and `Send as message` / `Cancel`; an extra argument on an argument-less command reads `{usage} does not take an argument.`; `/rename` with no title reads `Usage: /rename <title> — renames this session on this device.`; `/stop` with nothing running reads `No turn is running in this chat.`. A notice renders as a full-width line after the turns (not a bubble) with the label `Command` / `Command failed` and a terminal glyph, error-coloured when failed. Captured 2026-10-19: `captures/57-chat-command-palette.png`, `captures/58-chat-command-palette-selected.png` (ArrowDown moved the highlight), `captures/59-chat-command-unknown.png` (the failed notice and its offer, dismissed with Cancel), `captures/62-chat-new-session.png` (`/new`'s created session and its `Command` notice) |
|
||||
| C10 | Permission/approval cards (allow once/always/reject) | `chat_permission`, `chat_reply` | done — captured 2026-10-19: `captures/65-chat-approval-pending.png` (the pending card as the transcript's last item: the amber outlined shield + `Approve bash`, `Waiting for your response`, the request's six monospace resource lines, the amber `RISK REVIEW` panel, the `Allow once` / `Always allow` / `Reject` controls, and the top bar's `Waiting for your approval` control, with `#chatRunning` stood down), `captures/66-chat-approval-answered.png` (`Allowed once` / `Waiting for the agent to continue…`, controls and top-bar control gone), `captures/67-chat-approval-resolved.png` (a server resolution: `Always allowed` with its note `Another client already allowed this.`, no controls, no risk panel) and `captures/68-chat-approval-rejected.png` (a blank-action request answered `Reject`: `Rejected` / `Waiting for the agent to continue…`, the risk panel kept with the fallback sentence, no controls). The pure model is `src/chat.js` (`approvalCard`/`applyChatPermission`/`permissionRiskText`/`decisionLabel`): while pending `Approve {action}` (blank action → `Approve tool call`), after answering the decision label (`Allowed once` / `Always allowed` / `Rejected`, an unknown decision → `Resolved`) and `Waiting for the agent to continue…`, and once the server reports `resolved`/a decision that label (else `Already resolved`) with its `message` as the status (else `Another client already answered this request.`); the amber `RISK REVIEW` box shows only while pending or after a reject. Resources drop blanks and cap at six visible lines: `approvalResourceText` caps the joined text at six lines with an ellipsis on the last kept line, and the rendered text is a padding-free `-webkit-line-clamp: 6` block inside a padded frame, so a long resource that wraps is elided at the content edge and no seventh line paints into the frame's padding — matching Android's `maxLines = 6, Ellipsis` (the smoke asserts six clipped lines, a hidden overflow and the block ending at the frame's content edge, with seven lines unclamped). `Allow once` is rendered as the browser's filled primary control, matching the app's filled `Button` versus its two `TextButton`s; the head and risk-panel shields are inline SVG stroked with `currentColor` so the warn hue actually tints them (a colour emoji cannot be tinted). A server resolution always outranks a local answer, a new request replaces the settled card and clears the answer, and the same request keeps it. `PipelinesRepository.chatReply` sends exactly `{type:'chat_reply',chat_reply:{session_id,request_id,decision,client}}` (`message` only when non-blank) and refuses blank ids or a decision outside once/always/reject; answering settles the card optimistically, and a refused send reopens the same request and reports the server's reason on the thread's error line (ignored if a different request has replaced the card), so an unaccepted decision is never shown as accepted. The card is fed by `chat_permission` frames through `client.js`'s unsolicited-frame path, folded only for sessions this client has open. **Replayed, not real**: no live pending approval was available, so the captures were driven by synthetic `chat_permission` frames replayed through the page's own socket handler against the live session; the page's real `chat_reply` path was exercised but the smoke's shim suppressed every reply for the synthetic request ids (suppressed 3, one of them answered with a server error to prove the reopen path, forwarded 0), so **no approval decision was sent to the operator's server**. Unit-tested in `test/chat.test.mjs` and the reply shape in `test/repository.test.mjs`; the DOM assertions and log lines are produced by `test/ui-smoke.mjs` |
|
||||
| C11 | Background tasks bar: running shells only, capped + scrollable, bounded output page | `chat_shells`, `chat_shell_output` | done — captured 2026-10-19 into a live session: `captures/65-chat-background-tasks.png` (the bar with five running tasks — heading `Background tasks`, count `5 running`, three visible rows and a scrolling list), `captures/66-chat-background-task-detail.png` (a selected task's detail: `Command` + the command, `Task identity` + the id in monospace, `Status: running`, then `Output` + the monospace text and `Refresh`), `captures/67-chat-background-task-empty.png` (`No output yet.`), `captures/68-chat-background-task-unavailable.png` (`Output unavailable for this task.`), `captures/69-chat-background-task-truncated.png` (`Output is bounded to 64 KiB.` plus `Refresh`), `captures/70-chat-background-task-loading.png` (the spinner while the page loads) and `captures/71-chat-background-tasks-exited.png` (the bar gone after the last exit). The bar is shown only while at least one shell is running and disappears with the last exit; only running shells are listed (an exited shell is never a task). Its visible rows are capped at 3 (`BACKGROUND_TASK_VISIBLE_ROWS`) and the list scrolls beyond that instead of growing; each row is a play glyph + `Running` + `shellCommandSummary(command)` (trimmed, whitespace-collapsed, elided past 72; blank → `background process`) + `Details` only while selected, and tapping a row toggles its detail pane. Refresh always rereads the page from cursor 0 with `limit` 65536 (`SHELL_OUTPUT_LIMIT`, the server's 64 KiB bound) and never appends, so the client's output cannot grow unbounded — the smoke's own Refresh click issues exactly such a second read and the smoke asserts its `{cursor:0,limit:65536}` bounds. `chat_shells` is fetched when the conversation opens (`chat_query` body `{session_id}`) and again on every stream reconnect, and `chat_shell_output` sends `chat_shell_output_query` (`{session_id,shell_id,cursor,limit}`); both the request shapes and the pure model (`runningBackgroundShells`, `shellCommandSummary`, `mergeShellFrame`, `shellsLoaded`, `shellOutputState`, every wording constant) are unit-tested (`test/chat.test.mjs`, `test/repository.test.mjs`). A `shell` frame folds its shell into the retained set, merges a blank command from the previous frame, and never marks the thread running — a background process outlives the turn (a step ending does not clear it; only the reconnect drops and re-learns it). Every server string is set with `textContent`; shell output is never parsed as markup. **Replayed vs real, stated plainly**: only the `shell` frames (injected synthetic `chat_event` frames) and the `chat_shell_output` pages (answered by a socket reply hook) are synthetic, because the live server had no running shell to read safely; the `chat_shells` list, the `chat_subscribe` ack and every `chat_history` reply came from the real server, and the smoke asserts the real `chat_shells` fetch on open and after a reconnect. The one drop that hit a bounded read mid-section was recovered by the smoke's own bounded retry through the page's controls |
|
||||
| C12 | Human-decision notices inside chat + dismiss | `chat_event` | done — the local command-notice surface is captured and dismissible per notice. Captured 2026-10-19: `captures/72-chat-command-notice.png` (a full-width `Command` line after the turns, never a message bubble: the shared terminal glyph `>_`, the `/help` command list and its own `Dismiss`), `captures/73-chat-command-failed-offer.png` (an unknown command: `Command failed` in the error tint, the exact Android sentence and the `Send as message` / `Cancel` pair) and `captures/74-chat-command-dismissed.png` (the `/help` notice dismissed; the failed offer line and its controls remain — exactly one notice removed). A notice is a local `ChatCommandNotice`, never a `ChatMessage`: it lives in that conversation's `state.chatThreads` entry, survives switching away and back while the page is open, and never enters the prompt path — the smoke's recorded sends show **no** `chat_prompt` for `/help` or an unknown command. `Send as message` takes the offered draft through the ordinary `postChatPrompt` path, removing the notice **before** sending, so a stale second tap sends nothing (the smoke verifies both on a throwaway session). The pure model lives in `src/chat.js` (`makeChatNotice`, `appendChatNotice`, `dismissChatNotice`, `takeChatNoticeOffer`, `chatNoticeLabel`) and is unit-tested (`test/chat.test.mjs`): append, dismiss one, take the offer, a stale/offerless offer returning null and leaving the list untouched, per-conversation scoping, and the failed label/tint flag. **Wire finding, not an invented source**: `chat_event` kinds are exactly `user`, `text`, `reasoning`, `tool`, `shell`, `step` and `usage` (`internal/protocol/chat.go` `ChatEvent*`), and `chat_permission` is the only approval frame — there is **no** in-chat run-decision notice on the wire. Run-level human decisions live on R11's run-detail decision sheet (`decide_run`) and C10's approval cards (`chat_permission` / `chat_reply`), exactly as the app does it. **Stated browser divergence**: Android's `ChatCommandNoticeItem` shows actions only when `offer != null`, so it cannot dismiss a `/help` or `/new` line; the browser adds a `Dismiss` control (accessible name `Dismiss command notice`) on offerless notices to meet "each is individually dismissible", keeping the app's `Send as message` / `Cancel` pair verbatim on offer notices. |
|
||||
@@ -104,9 +104,10 @@ the pipeline list already carries — rather than a pluralised verb.
|
||||
| C14 | Scroll behaviour: follow newest, "jump to newest", restored position | client-side | done — captured 2026-10-19: `captures/45-chat-transcript-newest.png` (the conversation opens at its newest content instantly — the only live session has no saved position, so it lands at the end rather than at the top of a turn taller than the viewport) and `captures/46-chat-transcript-top.png` (after a **real wheel gesture** on the transcript — the app's own listener, not a programmatic scroll, which by the implementation's own rule cannot change intent — `Jump to latest` is offered; the smoke asserts the control and performs the gesture, `ui-smoke` log line "after a real wheel gesture (scrollTop 0) 'Jump to latest' is offered at the top"). A thread with a saved position is restored to it (a saved top, index 0, is a real position and is never treated as "new"); while within the 32 px bottom threshold the view follows, and only the operator's own wheel/drag changes that intent (a programmatic placement or follow cannot); `Jump to latest` is offered only when not following and something is below the fold; the position is saved per session in `localStorage` (`pipelines.web.chatScroll.v1`). A re-render (opening/dismissing a dialog, a refresh, or the loading frame of a paging fetch) captures the live position first and puts the operator back exactly where they were — the smoke asserts the transcript stays put across the `Close chat?` dialog (`ui-smoke` log line "the transcript stayed put across the dialog (top 7141 -> 7141)"); the paging anchor is held until the frame that actually carries the older page, so a real prepend stays on the previously visible message. No auto-load on scroll. The pure decisions are unit-tested (`chatBottomDistancePx`, `chatFollowsAt`, `chatShowJumpToLatest`, `chatOpensAtNewest`, `chatFirstScroll`) in `test/chat.test.mjs`, and the live measurement uses `chatBottomDistancePx` itself |
|
||||
|
||||
Three decisions in Chat, recorded here as the browser client's own choices where
|
||||
the app has no exact counterpart. The list's `New chat` action is rendered but
|
||||
deliberately disabled (with a note that C2 wires it), because C2's create dialog
|
||||
is a separate item. The conversation pane outside a selection reads
|
||||
the app has no exact counterpart. The list's `New chat` action — in the toolbar
|
||||
and in the empty state — opens C2's create pane (`Start a chat`), which owns the
|
||||
detail slot while it is open and leaves the list visible beside it. The
|
||||
conversation pane outside a selection reads
|
||||
`Select a chat to open it.`: the browser always shows a two-pane split (the app's
|
||||
narrow layout covers the list instead), so this stands in for `PaneIdentity`'s
|
||||
covered-pane title rather than a second feature. And the markdown renderer only
|
||||
@@ -120,9 +121,9 @@ choices and dependencies. **Attachments are not delivered to the agent yet**: th
|
||||
server's prompt path (`internal/server/chat_stream.go`) consumes only `text`
|
||||
today, so the browser collects, validates and blocks on a failed attachment and
|
||||
then sends it best-effort as the file's own reference string, but the file is not
|
||||
yet forwarded to OpenCode. **`/new` sends `chat_create` directly** because C2's
|
||||
create dialog is a separate item; it creates a session titled `New chat` in the
|
||||
current directory and opens it. **`/rename` is a local, per-device rename** until
|
||||
yet forwarded to OpenCode. **`/new` sends `chat_create` directly** as a one-step
|
||||
create in the current directory (C2's pane is the directory chooser); it creates
|
||||
a session titled `New chat` and opens it. **`/rename` is a local, per-device rename** until
|
||||
C13 lands (the browser item mirrors C13's dependency rather than inventing a
|
||||
server rename). And the **draft is held per chat in memory and mirrored into
|
||||
`localStorage`** (`pipelines.web.chatDraft.v1`), the web analogue of per-device
|
||||
@@ -134,10 +135,13 @@ as Android's `onStop` does) rather than the submit path, and the smoke clicks it
|
||||
the throwaway turn. Accepting `/close` finishes the session locally too: the
|
||||
running/queued bits clear and the conversation leaves the pane for the list
|
||||
(mirrors Android's `finishSession`); the rest of the live-transcript fold is C5's
|
||||
item. The UI smoke creates one throwaway session per run (via `/new`), really
|
||||
prompts and really interrupts it, then closes it again; the server keeps a closed
|
||||
chat as history, so repeated runs accumulate closed `New chat` rows (there is no
|
||||
delete command).
|
||||
item. The UI smoke creates one throwaway session per run (via `/new`, marked ephemeral
|
||||
so it never enters the operator registry), really prompts and really interrupts
|
||||
it, then closes it again. C2's step separately creates one **real** session,
|
||||
captures it and closes it with `chat_close`; the server keeps a closed chat as
|
||||
history, so that row stays as closed history (there is no delete command). The
|
||||
page keeps its own ephemeral throwaway row in memory so the check can switch back
|
||||
to it, but the server never lists it and a reload drops it.
|
||||
|
||||
## Settings, layout, platform
|
||||
| # | Feature | Protocol | Status |
|
||||
|
||||
+244
-10
@@ -2,7 +2,7 @@
|
||||
// Deliberately small and DOM-only (no framework, no build step). Every value
|
||||
// that came from the server is set with textContent, never innerHTML.
|
||||
import { PipelinesClient } from "./client.js";
|
||||
import { PipelinesRepository, SHELL_OUTPUT_LIMIT } from "./repository.js";
|
||||
import { PipelinesRepository, SHELL_OUTPUT_LIMIT, newChatOperationId } from "./repository.js";
|
||||
import { PROTOCOL_VERSION, Protocol, ChatKeys } from "./protocol.js";
|
||||
import { validateServerUrl, resolveArtifactUrl } from "./serverUrl.js";
|
||||
import {
|
||||
@@ -232,6 +232,13 @@ import {
|
||||
CHAT_COMMAND_DISMISS_LABEL,
|
||||
CHAT_COMMAND_GLYPH,
|
||||
CHAT_COMPOSER_PLACEHOLDER,
|
||||
CHAT_CREATE_BACK_LABEL,
|
||||
CHAT_CREATE_CANCEL,
|
||||
CHAT_CREATE_CONFIRM,
|
||||
CHAT_CREATE_LOADING,
|
||||
CHAT_CREATE_MODEL_NOTE,
|
||||
CHAT_CREATE_PROMPT,
|
||||
CHAT_CREATE_TITLE,
|
||||
CHAT_EMPTY,
|
||||
CHAT_FOLLOW_THRESHOLD_PX,
|
||||
CHAT_LOADING,
|
||||
@@ -283,6 +290,9 @@ import {
|
||||
chatCommandEffect,
|
||||
chatCommandHelp,
|
||||
chatCommandSuggestions,
|
||||
chatCreateFailed,
|
||||
chatCreateSucceeded,
|
||||
chatStartInLabel,
|
||||
chatFirstScroll,
|
||||
chatFollowsAt,
|
||||
chatHeaderMeta,
|
||||
@@ -296,6 +306,8 @@ import {
|
||||
composerCanSend,
|
||||
composerSendEnabled,
|
||||
composerSubmit,
|
||||
defaultDirectoryChoice,
|
||||
directoryChoices,
|
||||
directoryLabel,
|
||||
dismissChatNotice as dismissChatNoticeModel,
|
||||
filterSessions,
|
||||
@@ -304,6 +316,7 @@ import {
|
||||
makeChatNotice,
|
||||
mergeHistoryPage,
|
||||
mergeShellFrame,
|
||||
newChatCreateState,
|
||||
newChatThread,
|
||||
parseChatInput,
|
||||
queuedAfterFrame,
|
||||
@@ -317,6 +330,7 @@ import {
|
||||
sessionChipLabel,
|
||||
sessionMeta,
|
||||
sessionStatusLabel,
|
||||
selectChatDirectory as selectChatDirectoryModel,
|
||||
sessionTitle,
|
||||
sessionWorkLabel,
|
||||
settledThread,
|
||||
@@ -502,6 +516,11 @@ const state = {
|
||||
// is set with textContent and the markdown renderer builds DOM nodes, never
|
||||
// innerHTML.
|
||||
chatSessions: [],
|
||||
// The verification chats this page itself created (C2's automation flag). The
|
||||
// server deliberately never lists them; the page keeps its own in-memory row so
|
||||
// the creator can keep working with the chat it just opened. The set is
|
||||
// memory-only, so a reload cannot turn one into a permanent list entry.
|
||||
chatEphemeralIds: new Set(),
|
||||
chatLoading: false,
|
||||
chatLoaded: false,
|
||||
chatError: "",
|
||||
@@ -538,6 +557,14 @@ const state = {
|
||||
// re-established for the open chat on reconnect. A refused subscription simply
|
||||
// never joins the set, so the badge reads "not live" honestly.
|
||||
chatSubscriptions: new Set(),
|
||||
// C2: the create flow. `chatCreate` is the ChatCreateState analogue (null until
|
||||
// the New chat entry point is used); the directory reply is cached so cancelling
|
||||
// and reopening does not re-ask, and a failed load keeps its own reason.
|
||||
chatDirectories: [],
|
||||
chatDirectoriesLoading: false,
|
||||
chatDirectoriesLoaded: false,
|
||||
chatDirectoriesError: "",
|
||||
chatCreate: null,
|
||||
};
|
||||
|
||||
let runPoll = null;
|
||||
@@ -1055,7 +1082,9 @@ function renderContent() {
|
||||
} else if (state.view === "runs") {
|
||||
split.append(renderRunList(), renderRunDetail());
|
||||
} else if (state.view === "chat") {
|
||||
split.append(renderChatList(), renderChatConversation());
|
||||
// While the create flow is open it owns the detail pane; the session list
|
||||
// stays visible beside it, exactly as the app's two-pane chat stack does.
|
||||
split.append(renderChatList(), state.chatCreate ? renderChatCreate() : renderChatConversation());
|
||||
} else {
|
||||
split.append(renderTemplateGallery(), renderTemplateDetail());
|
||||
}
|
||||
@@ -3983,7 +4012,15 @@ async function loadChatSessions(force = false) {
|
||||
state.chatError = "";
|
||||
renderContent();
|
||||
try {
|
||||
state.chatSessions = await repo.chatSessions();
|
||||
const listed = await repo.chatSessions();
|
||||
// Keep this page's own verification chats, which the server intentionally
|
||||
// never returns, at the head of the in-memory list (memory-only; see
|
||||
// chatEphemeralIds). Everything else is the server's list, in its order.
|
||||
const held = state.chatSessions.filter(
|
||||
(session) =>
|
||||
state.chatEphemeralIds.has(session.id) && !listed.some((entry) => entry.id === session.id),
|
||||
);
|
||||
state.chatSessions = [...held, ...listed];
|
||||
state.chatLoaded = true;
|
||||
} catch (error) {
|
||||
state.chatError = describeError(error);
|
||||
@@ -3992,6 +4029,85 @@ async function loadChatSessions(force = false) {
|
||||
renderContent();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// The create flow (C2, ChatCreatePane.kt)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Open the create pane with a fresh operation id. The id is minted once per
|
||||
* intent, so a retry after a refusal reuses it and the server can dedupe the
|
||||
* create rather than starting a second session.
|
||||
*/
|
||||
function startNewChat() {
|
||||
state.chatCreate = newChatCreateState(newChatOperationId());
|
||||
state.chatDirectoriesError = "";
|
||||
renderContent();
|
||||
loadChatDirectories();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch `chat_directories` for the open picker. A failure keeps the reason for the
|
||||
* pane's error state; blank entries are dropped here as well as in the pure model
|
||||
* so a malformed reply can never produce an empty row. An already-loaded list is
|
||||
* reused unless [force] (the error state's Retry) asks again.
|
||||
*/
|
||||
async function loadChatDirectories(force = false) {
|
||||
if (!state.chatCreate || state.chatDirectoriesLoading) return;
|
||||
if (state.chatDirectoriesLoaded && !force) return;
|
||||
state.chatDirectoriesLoading = true;
|
||||
state.chatDirectoriesError = "";
|
||||
renderContent();
|
||||
try {
|
||||
const directories = await repo.chatDirectories();
|
||||
state.chatDirectories = (directories ?? []).filter((entry) => String(entry ?? "").trim() !== "");
|
||||
state.chatDirectoriesLoaded = true;
|
||||
} catch (error) {
|
||||
state.chatDirectoriesError = describeError(error);
|
||||
}
|
||||
state.chatDirectoriesLoading = false;
|
||||
renderContent();
|
||||
}
|
||||
|
||||
/** Select one directory row (the value is what chat_create will send). */
|
||||
function selectChatDirectory(value) {
|
||||
if (!state.chatCreate) return;
|
||||
state.chatCreate = selectChatDirectoryModel(state.chatCreate, value);
|
||||
renderContent();
|
||||
}
|
||||
|
||||
/** Leave the create flow without creating anything. */
|
||||
function cancelNewChat() {
|
||||
state.chatCreate = null;
|
||||
renderContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the chat in the chosen directory. Guarded against a double submit: the
|
||||
* guard reads the held state, so a second click while the request is in flight
|
||||
* sends nothing. On success the pane closes, the created session goes to the head
|
||||
* of the list, becomes the open conversation and loads its (empty) history; on
|
||||
* failure the server's own reason stays in the pane, which does not close.
|
||||
*/
|
||||
async function createNewChat() {
|
||||
const create = state.chatCreate;
|
||||
if (!create || create.creating) return;
|
||||
state.chatCreate = { ...create, creating: true, error: "" };
|
||||
renderContent();
|
||||
try {
|
||||
// Not ephemeral: this is the operator's own create path (the UI smoke uses the
|
||||
// same path for its one real session and closes it afterwards).
|
||||
const created = await repo.chatCreate("New chat", create.directory, create.operationId);
|
||||
state.chatCreate = null;
|
||||
state.chatSessions = chatCreateSucceeded(state.chatSessions, created);
|
||||
await openChatSession(created.id);
|
||||
await loadChatSessions();
|
||||
} catch (error) {
|
||||
if (!state.chatCreate) return;
|
||||
state.chatCreate = chatCreateFailed(state.chatCreate, describeError(error));
|
||||
renderContent();
|
||||
}
|
||||
}
|
||||
|
||||
/** Open a session: select it, subscribe its stream and load its newest history page. */
|
||||
async function openChatSession(id) {
|
||||
if (state.chatActiveId === id && state.chatThreads.get(id)?.loaded) return;
|
||||
@@ -4585,9 +4701,9 @@ async function startChatSession(directory) {
|
||||
// An automated check (the UI smoke) can mark its throwaway chat ephemeral, so
|
||||
// creating one for verification never adds a stray "New chat" to the
|
||||
// operator's list. Set only by test tooling; a normal page leaves it unset.
|
||||
const created = await repo.chatCreate("New chat", directory, undefined, {
|
||||
ephemeral: globalThis.__pipelinesEphemeralChat === true,
|
||||
});
|
||||
const ephemeral = globalThis.__pipelinesEphemeralChat === true;
|
||||
const created = await repo.chatCreate("New chat", directory, undefined, { ephemeral });
|
||||
if (ephemeral) state.chatEphemeralIds = new Set(state.chatEphemeralIds).add(created.id);
|
||||
// The list is the server's; insert the created session so the row is present
|
||||
// before the conversation opens, then refresh from the server.
|
||||
state.chatSessions = [created, ...state.chatSessions.filter((s) => s.id !== created.id)];
|
||||
@@ -4776,6 +4892,14 @@ function renderChatList() {
|
||||
fillChatRows(rows);
|
||||
},
|
||||
}),
|
||||
// C2: the create path stays one tap away while the list is narrowed, the same
|
||||
// trailing action the app keeps beside its search control.
|
||||
h("button", {
|
||||
class: "ghost chat-new",
|
||||
type: "button",
|
||||
text: CHAT_NEW_ACTION,
|
||||
onclick: startNewChat,
|
||||
}),
|
||||
);
|
||||
list.append(toolbar);
|
||||
const rows = h("div", { id: "chatRows", class: "chat-rows" });
|
||||
@@ -4817,16 +4941,13 @@ function fillChatRows(rows) {
|
||||
return;
|
||||
}
|
||||
if (filtered.length === 0) {
|
||||
// The create path is the C2 item; the action is shown but deliberately not
|
||||
// wired here, exactly as the item says.
|
||||
const empty = chatEmpty(CHAT_EMPTY);
|
||||
empty.append(
|
||||
h("button", {
|
||||
class: "ghost chat-new",
|
||||
type: "button",
|
||||
text: CHAT_NEW_ACTION,
|
||||
disabled: true,
|
||||
title: "Creating a chat lands with the C2 item",
|
||||
onclick: startNewChat,
|
||||
}),
|
||||
);
|
||||
rows.append(empty);
|
||||
@@ -4935,6 +5056,119 @@ function renderChatRow(session) {
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* The create pane (C2): the app's NewChatPane. A back control leaves without
|
||||
* creating, then the directory error / loading / picker states in the app's own
|
||||
* order, the model note and the footer naming the value that will be sent. Every
|
||||
* server string is set with textContent.
|
||||
*/
|
||||
function renderChatCreate() {
|
||||
const create = state.chatCreate;
|
||||
const pane = h("div", { class: "detail chat-detail chat-create" });
|
||||
|
||||
const bar = h("div", { class: "chat-bar chat-create-bar" });
|
||||
bar.append(
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
class: "ghost chat-create-back",
|
||||
type: "button",
|
||||
"aria-label": CHAT_CREATE_BACK_LABEL,
|
||||
title: CHAT_CREATE_BACK_LABEL,
|
||||
onclick: cancelNewChat,
|
||||
},
|
||||
h("span", { class: "chat-create-back-glyph", "aria-hidden": "true", text: "←" }),
|
||||
),
|
||||
h("h2", { class: "chat-bar-title chat-create-title", text: CHAT_CREATE_TITLE }),
|
||||
);
|
||||
pane.append(bar);
|
||||
|
||||
if (state.chatDirectoriesError && !state.chatDirectoriesLoaded) {
|
||||
const empty = chatEmpty(state.chatDirectoriesError);
|
||||
empty.classList.add("chat-create-directories-error");
|
||||
empty.append(
|
||||
h("button", {
|
||||
class: "ghost chat-create-retry",
|
||||
type: "button",
|
||||
text: "Retry",
|
||||
onclick: () => loadChatDirectories(true),
|
||||
}),
|
||||
);
|
||||
pane.append(empty);
|
||||
} else if (!state.chatDirectoriesLoaded) {
|
||||
pane.append(h("div", { class: "chat-create-loading muted", text: CHAT_CREATE_LOADING }));
|
||||
} else {
|
||||
pane.append(h("div", { class: "chat-create-prompt muted", text: CHAT_CREATE_PROMPT }));
|
||||
|
||||
const choices = directoryChoices(state.chatDirectories);
|
||||
const selected =
|
||||
choices.find((choice) => choice.createDirectory === create.directory) ??
|
||||
defaultDirectoryChoice(choices);
|
||||
const list = h("div", {
|
||||
class: "chat-create-choices",
|
||||
role: "listbox",
|
||||
"aria-label": CHAT_CREATE_PROMPT,
|
||||
});
|
||||
for (const choice of choices) {
|
||||
const active = choice.createDirectory === selected?.createDirectory;
|
||||
const row = h("button", {
|
||||
class: `row chat-create-choice${active ? " selected" : ""}`,
|
||||
type: "button",
|
||||
role: "option",
|
||||
"aria-selected": active ? "true" : "false",
|
||||
"data-directory": choice.createDirectory,
|
||||
onclick: () => selectChatDirectory(choice.createDirectory),
|
||||
});
|
||||
row.append(h("span", { class: "row-title chat-create-choice-label", text: choice.label }));
|
||||
if (choice.secondary) {
|
||||
row.append(h("span", { class: "row-meta chat-create-choice-path", text: choice.secondary }));
|
||||
}
|
||||
list.append(row);
|
||||
}
|
||||
pane.append(list);
|
||||
|
||||
// A refresh that failed after a successful first load keeps the choices and
|
||||
// says why the list may be stale (the app's own bodySmall error line).
|
||||
if (state.chatDirectoriesError) {
|
||||
pane.append(h("div", { class: "chat-create-directories-error", text: state.chatDirectoriesError }));
|
||||
}
|
||||
if (create.error) {
|
||||
pane.append(h("div", { class: "chat-create-error", text: create.error }));
|
||||
}
|
||||
pane.append(h("p", { class: "chat-create-model-note muted", text: CHAT_CREATE_MODEL_NOTE }));
|
||||
|
||||
const directory = selected?.createDirectory ?? create.directory;
|
||||
const footer = h("div", { class: "chat-create-footer" });
|
||||
footer.append(h("span", { class: "chat-create-start", text: chatStartInLabel(directory) }));
|
||||
footer.append(
|
||||
h("button", {
|
||||
class: "ghost chat-create-cancel",
|
||||
type: "button",
|
||||
text: CHAT_CREATE_CANCEL,
|
||||
disabled: create.creating,
|
||||
onclick: cancelNewChat,
|
||||
}),
|
||||
);
|
||||
const confirm = h("button", {
|
||||
class: "chat-create-confirm",
|
||||
type: "button",
|
||||
"aria-label": CHAT_CREATE_CONFIRM,
|
||||
disabled: create.creating,
|
||||
onclick: createNewChat,
|
||||
});
|
||||
if (create.creating) {
|
||||
confirm.append(h("span", { class: "spinner chat-create-spinner", "aria-hidden": "true" }));
|
||||
} else {
|
||||
confirm.append(document.createTextNode(CHAT_CREATE_CONFIRM));
|
||||
}
|
||||
footer.append(confirm);
|
||||
pane.append(footer);
|
||||
}
|
||||
|
||||
appendChatDialogs(pane);
|
||||
return pane;
|
||||
}
|
||||
|
||||
/** The active conversation: identity, context, transcript and its controls. */
|
||||
function renderChatConversation() {
|
||||
const pane = h("div", { class: "detail chat-detail" });
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
// toolLongRunning (the chip and its panel)
|
||||
// ui/chat/ChatListFilter.kt sessionMatchesQuery, filterChatSessions,
|
||||
// groupChatSessionsByDirectory
|
||||
// ui/chat/ChatDirectories.kt HOME_DIRECTORY, directoryChoices,
|
||||
// defaultDirectoryChoice (the create picker)
|
||||
// ui/chat/ChatCreatePane.kt the create flow's wording, NewChatActions footer
|
||||
// and the create state transitions
|
||||
// ui/chat/ChatScroll.kt chatBottomDistancePx, chatFollowsAt,
|
||||
// chatShowJumpToLatest, chatOpensAtNewest,
|
||||
// chatFirstScroll
|
||||
@@ -114,6 +118,25 @@ export const CONVERSATION_EMPTY = "This chat has no messages yet. Ask something
|
||||
export const LOAD_OLDER_ACTION = "Load older messages";
|
||||
export const SELECT_CHAT_HINT = "Select a chat to open it.";
|
||||
|
||||
// The create flow (C2, ChatCreatePane.kt), verbatim. The home choice's row is
|
||||
// `Home (~)` while chat_create sends the `~` the server documents; the footer
|
||||
// names the value that will be sent (see chatStartInLabel).
|
||||
export const HOME_DIRECTORY = "~";
|
||||
export const HOME_LABEL = `Home (${HOME_DIRECTORY})`;
|
||||
export const CHAT_CREATE_TITLE = "Start a chat";
|
||||
export const CHAT_CREATE_BACK_LABEL = "Cancel new chat";
|
||||
export const CHAT_CREATE_LOADING = "Loading directories…";
|
||||
export const CHAT_CREATE_PROMPT = "Where should this chat live?";
|
||||
export const CHAT_CREATE_MODEL_NOTE =
|
||||
"This server has no request for choosing a chat's model, so a new chat uses the server's default.";
|
||||
export const CHAT_CREATE_CONFIRM = "New chat";
|
||||
export const CHAT_CREATE_CANCEL = "Cancel";
|
||||
|
||||
/** The create footer's line: `Start in {directory}` with the value that is sent. */
|
||||
export function chatStartInLabel(directory) {
|
||||
return `Start in ${str(directory)}`;
|
||||
}
|
||||
|
||||
/** The listing's narrowed-to-nothing message: `No chats match "{query}".` */
|
||||
export function chatNoMatchMessage(query) {
|
||||
return `No chats match "${str(query).trim()}".`;
|
||||
@@ -610,6 +633,78 @@ export function directoryLabel(directory) {
|
||||
return isBlank(directory) ? NO_DIRECTORY_LABEL : str(directory);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// The create flow's directory choices (ChatDirectories.kt)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The picker's choices from the server's reported directories. The first entry is
|
||||
* the operator's home — the one entry the server always returns first — and the
|
||||
* rest keep the server's most-recently-used order. A blank entry is dropped, and a
|
||||
* reply with nothing in it still yields the home choice, so the picker is never
|
||||
* empty. A recent's `label` is its full path; only the home row carries the path
|
||||
* as `secondary`, because its own label is `Home (~)`.
|
||||
*/
|
||||
export function directoryChoices(directories) {
|
||||
const cleaned = (directories ?? []).map((entry) => str(entry)).filter((entry) => !isBlank(entry));
|
||||
const home = cleaned.length > 0 ? cleaned[0] : HOME_DIRECTORY;
|
||||
return [
|
||||
{
|
||||
label: HOME_LABEL,
|
||||
path: home,
|
||||
home: true,
|
||||
createDirectory: HOME_DIRECTORY,
|
||||
secondary: home,
|
||||
},
|
||||
...cleaned.slice(1).map((path) => ({
|
||||
label: path,
|
||||
path,
|
||||
home: false,
|
||||
createDirectory: path,
|
||||
secondary: null,
|
||||
})),
|
||||
];
|
||||
}
|
||||
|
||||
/** The choice a freshly opened picker starts on: home, first. */
|
||||
export function defaultDirectoryChoice(choices) {
|
||||
return (choices ?? [])[0] ?? null;
|
||||
}
|
||||
|
||||
/** A fresh create state: home selected, the caller's operation id, not sending. */
|
||||
export function newChatCreateState(operationId) {
|
||||
return {
|
||||
directory: HOME_DIRECTORY,
|
||||
operationId: str(operationId),
|
||||
creating: false,
|
||||
error: "",
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose one directory for the create. Kept pure so the view can re-render from a
|
||||
* single state object; the error a previous refusal left is cleared because it
|
||||
* described the old choice, not this one.
|
||||
*/
|
||||
export function selectChatDirectory(create, choice) {
|
||||
const directory =
|
||||
typeof choice === "string" ? choice : str(choice?.createDirectory ?? "");
|
||||
if (isBlank(directory)) return { ...create };
|
||||
return { ...create, directory, error: "" };
|
||||
}
|
||||
|
||||
/** The create failed: stop sending and keep the server's own reason in the pane. */
|
||||
export function chatCreateFailed(create, message) {
|
||||
return { ...create, creating: false, error: str(message) };
|
||||
}
|
||||
|
||||
/** The create succeeded: the new session goes to the head of the list, deduped by id. */
|
||||
export function chatCreateSucceeded(sessions, session) {
|
||||
const list = sessions ?? [];
|
||||
if (!session) return list;
|
||||
return [session, ...list.filter((entry) => entry?.id !== session.id)];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Transcript (ChatFormat.kt)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -64,6 +64,10 @@ export const Protocol = Object.freeze({
|
||||
CHAT_PROMPT: "chat_prompt",
|
||||
CHAT_INTERRUPT: "chat_interrupt",
|
||||
CHAT_CREATE: "chat_create",
|
||||
// The create flow's directory choices (C2): `chat_directories` has no body and
|
||||
// replies in the `chat_directories` field, home first then recent operator
|
||||
// directories (internal/protocol/chat.go ChatDirectories).
|
||||
CHAT_DIRECTORIES: "chat_directories",
|
||||
// The approval card (C10): the server pushes `chat_permission` frames (one
|
||||
// pending request, later re-pushed with the resolution) and the phone answers
|
||||
// with `chat_reply` (internal/protocol/chat.go ChatPermission/ChatReply).
|
||||
@@ -102,6 +106,9 @@ export const ChatKeys = Object.freeze({
|
||||
// separate field name here would put it on the wrong part of the envelope.
|
||||
PROMPT: "chat_prompt",
|
||||
CREATE: "chat_create",
|
||||
// The `chat_directories` reply (C2), home first then recents; mirrors
|
||||
// internal/protocol/message.go `ChatDirectories []string`.
|
||||
DIRECTORIES: "chat_directories",
|
||||
QUEUED: "chat_queued",
|
||||
// C10: the pushed approval frame (`chat_permission`) and the answer body
|
||||
// (`chat_reply`), both distinct Message fields in internal/protocol/message.go.
|
||||
|
||||
@@ -383,6 +383,18 @@ export class PipelinesRepository {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists the directories a new chat can live in (C2), mirroring
|
||||
* `PipelinesRepository.chatDirectories`: a bare `{type:'chat_directories'}` with
|
||||
* no body, replying in `chat_directories` (home first, then recent operator
|
||||
* directories). An older server that returns no field answers with an empty
|
||||
* list; the view still offers home so the picker is never empty.
|
||||
*/
|
||||
async chatDirectories() {
|
||||
const response = await this.#client.call({ type: Protocol.CHAT_DIRECTORIES });
|
||||
return response[ChatKeys.DIRECTORIES] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates one session in an explicit directory (mirrors
|
||||
* `PipelinesRepository.chatCreate`). The directory is always sent, so a chat is
|
||||
|
||||
@@ -1435,6 +1435,70 @@ code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-
|
||||
|
||||
.chat-list { display: flex; flex-direction: column; }
|
||||
.chat-search { flex: 1 1 auto; min-width: 0; }
|
||||
.chat-toolbar .chat-new { white-space: nowrap; }
|
||||
|
||||
/* C2: the create pane — the directory picker, the model note and the footer that
|
||||
names the value chat_create will send. */
|
||||
.chat-create { gap: 12px; }
|
||||
.chat-bar.chat-create-bar { align-items: center; justify-content: flex-start; gap: 10px; }
|
||||
.chat-create-back {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
padding: 0;
|
||||
flex: none;
|
||||
}
|
||||
.chat-create-back-glyph { font-size: 16px; line-height: 1; }
|
||||
.detail .chat-create-title { margin: 0; }
|
||||
.chat-create-loading { padding: 18px 4px; }
|
||||
.chat-create-prompt { padding: 2px 2px 0; font-size: 13px; }
|
||||
.chat-create-choices {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.chat-create-choice { cursor: pointer; }
|
||||
.chat-create-choice-path {
|
||||
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
|
||||
font-size: 11px;
|
||||
}
|
||||
.chat-create-directories-error { color: var(--bad); }
|
||||
.chat-create-error { color: var(--bad); font-size: 13px; }
|
||||
.chat-create-model-note { margin: 0; font-size: 12px; line-height: 1.5; max-width: 64ch; }
|
||||
.chat-create-footer {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
margin-top: auto;
|
||||
padding: 12px;
|
||||
background: var(--surface-2);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
}
|
||||
.chat-create-start {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-size: 13px;
|
||||
}
|
||||
.chat-create-confirm {
|
||||
min-width: 88px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-color: var(--accent);
|
||||
color: var(--accent);
|
||||
font-weight: 600;
|
||||
}
|
||||
.chat-create-confirm:disabled,
|
||||
.chat-create-cancel:disabled { opacity: 0.55; }
|
||||
.chat-create-spinner { width: 14px; height: 14px; border-width: 2px; }
|
||||
|
||||
.chat-group-header {
|
||||
padding: 8px 12px 4px;
|
||||
|
||||
@@ -12,6 +12,13 @@ import {
|
||||
CHAT_COMMAND_FAILED_LABEL,
|
||||
CHAT_COMMAND_GLYPH,
|
||||
CHAT_COMMAND_LABEL,
|
||||
CHAT_CREATE_BACK_LABEL,
|
||||
CHAT_CREATE_CANCEL,
|
||||
CHAT_CREATE_CONFIRM,
|
||||
CHAT_CREATE_LOADING,
|
||||
CHAT_CREATE_MODEL_NOTE,
|
||||
CHAT_CREATE_PROMPT,
|
||||
CHAT_CREATE_TITLE,
|
||||
CHAT_FOLLOW_THRESHOLD_PX,
|
||||
CHAT_QUEUED_NOTICE,
|
||||
COMPOSER_SEND,
|
||||
@@ -60,12 +67,16 @@ import {
|
||||
attachmentDisplayName,
|
||||
attachmentError,
|
||||
attachmentFiles,
|
||||
HOME_DIRECTORY,
|
||||
HOME_LABEL,
|
||||
backgroundTasksRunningLabel,
|
||||
chatBottomDistancePx,
|
||||
chatCommandEffect,
|
||||
chatCommandForEnter,
|
||||
chatCommandHelp,
|
||||
chatCommandSuggestions,
|
||||
chatCreateFailed,
|
||||
chatCreateSucceeded,
|
||||
chatFirstScroll,
|
||||
chatFollowsAt,
|
||||
chatHeaderMeta,
|
||||
@@ -73,6 +84,7 @@ import {
|
||||
chatNoticeLabel,
|
||||
chatOpensAtNewest,
|
||||
chatShowJumpToLatest,
|
||||
chatStartInLabel,
|
||||
chatStreamState,
|
||||
closeChatConfirmation,
|
||||
composerAction,
|
||||
@@ -80,7 +92,9 @@ import {
|
||||
composerSendEnabled,
|
||||
composerSubmit,
|
||||
decisionLabel,
|
||||
defaultDirectoryChoice,
|
||||
deltaPartId,
|
||||
directoryChoices,
|
||||
directoryLabel,
|
||||
dismissChatNotice,
|
||||
filterSessions,
|
||||
@@ -92,6 +106,7 @@ import {
|
||||
mergeHistoryPage,
|
||||
mergeShellFrame,
|
||||
mergeToolPart,
|
||||
newChatCreateState,
|
||||
newChatThread,
|
||||
parseChatInput,
|
||||
partRendering,
|
||||
@@ -104,6 +119,7 @@ import {
|
||||
runningBackgroundShells,
|
||||
runningToolElapsedMillis,
|
||||
runningToolStamps,
|
||||
selectChatDirectory,
|
||||
sessionActivity,
|
||||
sessionActivityBadge,
|
||||
sessionChipLabel,
|
||||
@@ -1612,3 +1628,116 @@ test("a step that ends does not clear a background shell that outlives the turn"
|
||||
assert.equal(resumed.selectedShellId, null);
|
||||
assert.equal(resumed.shellOutput, null);
|
||||
});
|
||||
|
||||
// ---- The create flow's directory picker (C2, ChatDirectories.kt) -----------
|
||||
|
||||
test("directoryChoices makes the first non-blank directory home and keeps recents in server order", () => {
|
||||
const choices = directoryChoices(["/Users/alan", "", "/work/one", " ", "/work/two"]);
|
||||
assert.deepEqual(choices, [
|
||||
{
|
||||
label: "Home (~)",
|
||||
path: "/Users/alan",
|
||||
home: true,
|
||||
createDirectory: "~",
|
||||
secondary: "/Users/alan",
|
||||
},
|
||||
{
|
||||
label: "/work/one",
|
||||
path: "/work/one",
|
||||
home: false,
|
||||
createDirectory: "/work/one",
|
||||
secondary: null,
|
||||
},
|
||||
{
|
||||
label: "/work/two",
|
||||
path: "/work/two",
|
||||
home: false,
|
||||
createDirectory: "/work/two",
|
||||
secondary: null,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test("directoryChoices always yields home first, even for an empty or blank reply", () => {
|
||||
for (const reply of [[], ["", " "], null, undefined]) {
|
||||
const choices = directoryChoices(reply);
|
||||
assert.equal(choices.length, 1);
|
||||
assert.deepEqual(choices[0], {
|
||||
label: HOME_LABEL,
|
||||
path: HOME_DIRECTORY,
|
||||
home: true,
|
||||
createDirectory: HOME_DIRECTORY,
|
||||
secondary: HOME_DIRECTORY,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test("the home row is the only one with a secondary path; recents are labelled by full path", () => {
|
||||
const choices = directoryChoices(["/home/operator", "/repo/a", "/repo/b"]);
|
||||
assert.deepEqual(
|
||||
choices.map((choice) => [choice.label, choice.secondary]),
|
||||
[
|
||||
["Home (~)", "/home/operator"],
|
||||
["/repo/a", null],
|
||||
["/repo/b", null],
|
||||
],
|
||||
);
|
||||
assert.equal(defaultDirectoryChoice(choices)?.label, HOME_LABEL);
|
||||
assert.equal(defaultDirectoryChoice([]), null);
|
||||
});
|
||||
|
||||
test("newChatCreateState starts on home, not sending, with the caller's operation id", () => {
|
||||
assert.deepEqual(newChatCreateState("web-chat-op"), {
|
||||
directory: HOME_DIRECTORY,
|
||||
operationId: "web-chat-op",
|
||||
creating: false,
|
||||
error: "",
|
||||
});
|
||||
});
|
||||
|
||||
test("selectChatDirectory sends the chosen value and clears a previous refusal", () => {
|
||||
const state = { ...newChatCreateState("op"), error: "refused" };
|
||||
const recent = { label: "/repo/a", path: "/repo/a", home: false, createDirectory: "/repo/a", secondary: null };
|
||||
assert.deepEqual(selectChatDirectory(state, recent), {
|
||||
directory: "/repo/a",
|
||||
operationId: "op",
|
||||
creating: false,
|
||||
error: "",
|
||||
});
|
||||
assert.equal(selectChatDirectory(state, "~").directory, "~");
|
||||
assert.deepEqual(selectChatDirectory(state, ""), state);
|
||||
});
|
||||
|
||||
test("chatCreateFailed keeps the pane open with the server's message; success stops sending", () => {
|
||||
const creating = { ...newChatCreateState("op"), creating: true };
|
||||
assert.deepEqual(chatCreateFailed(creating, "the directory is not available"), {
|
||||
directory: "~",
|
||||
operationId: "op",
|
||||
creating: false,
|
||||
error: "the directory is not available",
|
||||
});
|
||||
});
|
||||
|
||||
test("chatCreateSucceeded puts the created session at the head and dedupes by id", () => {
|
||||
const a = { id: "a", title: "A" };
|
||||
const b = { id: "b", title: "B" };
|
||||
const created = { id: "b", title: "New chat" };
|
||||
assert.deepEqual(chatCreateSucceeded([a, b], created), [created, a]);
|
||||
assert.deepEqual(chatCreateSucceeded([], created), [created]);
|
||||
assert.deepEqual(chatCreateSucceeded([a], null), [a]);
|
||||
});
|
||||
|
||||
test("the create flow's wording is the app's verbatim", () => {
|
||||
assert.equal(CHAT_CREATE_TITLE, "Start a chat");
|
||||
assert.equal(CHAT_CREATE_BACK_LABEL, "Cancel new chat");
|
||||
assert.equal(CHAT_CREATE_LOADING, "Loading directories…");
|
||||
assert.equal(CHAT_CREATE_PROMPT, "Where should this chat live?");
|
||||
assert.equal(
|
||||
CHAT_CREATE_MODEL_NOTE,
|
||||
"This server has no request for choosing a chat's model, so a new chat uses the server's default.",
|
||||
);
|
||||
assert.equal(CHAT_CREATE_CONFIRM, "New chat");
|
||||
assert.equal(CHAT_CREATE_CANCEL, "Cancel");
|
||||
assert.equal(chatStartInLabel(HOME_DIRECTORY), "Start in ~");
|
||||
assert.equal(chatStartInLabel("/repo/a"), "Start in /repo/a");
|
||||
});
|
||||
|
||||
@@ -345,6 +345,41 @@ test("chatInterrupt sends the session as chat_query (not a chat_interrupt body)"
|
||||
assert.deepEqual(lastFrame(ws), { type: "chat_interrupt", chat_query: { session_id: "s1" } });
|
||||
});
|
||||
|
||||
test("chatDirectories sends exactly {type:'chat_directories'} and returns the list", async () => {
|
||||
const { repo, ws } = connected();
|
||||
const directories = ["/home/operator", "/repo/one", "/repo/two"];
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "chat_directories", chat_directories: directories });
|
||||
|
||||
assert.deepEqual(await repo.chatDirectories(), directories);
|
||||
assert.deepEqual(lastFrame(ws), { type: "chat_directories" });
|
||||
});
|
||||
|
||||
test("chatDirectories returns [] when the reply carries no directories", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "chat_directories" });
|
||||
assert.deepEqual(await repo.chatDirectories(), []);
|
||||
});
|
||||
|
||||
test("chatDirectories surfaces a server refusal as a ProtocolError", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "error", error: "unknown command: chat_directories" });
|
||||
await assert.rejects(() => repo.chatDirectories(), {
|
||||
name: "ProtocolError",
|
||||
message: "unknown command: chat_directories",
|
||||
});
|
||||
});
|
||||
|
||||
test("chatCreate sends home as ~ and carries the exact title/directory/operation_id body", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "chat_create", chat_session: { id: "ses_new" } });
|
||||
|
||||
await repo.chatCreate("New chat", "~", "op-4");
|
||||
assert.deepEqual(lastFrame(ws), {
|
||||
type: "chat_create",
|
||||
chat_create: { title: "New chat", directory: "~", operation_id: "op-4" },
|
||||
});
|
||||
});
|
||||
|
||||
test("chatCreate sends title/directory/operation_id and returns chat_session", async () => {
|
||||
const { repo, ws } = connected();
|
||||
const created = { id: "ses_new", title: "New chat" };
|
||||
|
||||
+238
-13
@@ -75,6 +75,9 @@ let failed = false;
|
||||
// The throwaway chat session this run creates for the running-turn capture. It
|
||||
// is closed again in cleanup; null once closed (or when none was created).
|
||||
let throwawaySessionId = null;
|
||||
// C2's one real session. It is closed in its own step; kept here only so a
|
||||
// failure before that step can still close it rather than leave it in the list.
|
||||
let createdSessionId = null;
|
||||
|
||||
function step(label) {
|
||||
console.log(`• ${label}`);
|
||||
@@ -443,6 +446,13 @@ try {
|
||||
frame.chat_prompt?.text ?? "",
|
||||
);
|
||||
}
|
||||
// C2: the create bodies this page actually sent, so the smoke can prove
|
||||
// the picker's chosen value reached chat_create.
|
||||
if (frame.type === "chat_create") {
|
||||
(window.__chatCreateBodies = window.__chatCreateBodies || []).push(
|
||||
frame.chat_create ?? null,
|
||||
);
|
||||
}
|
||||
if (frame.type === "chat_reply") {
|
||||
const requestId = frame.chat_reply && frame.chat_reply.request_id;
|
||||
if (window.__suppressChatReplyIds.includes(requestId)) {
|
||||
@@ -1484,11 +1494,18 @@ try {
|
||||
};
|
||||
})()`),
|
||||
{ timeout: 15000, what: "the live run's active stage" },
|
||||
);
|
||||
if (!live.badge) throw new Error(`the active stage showed no elapsed badge: ${JSON.stringify(live)}`);
|
||||
console.log(` live run ${liveRunId}: active stage ${live.activeKey} (pulsing=${live.pulsing}), badge ${live.badge}`);
|
||||
await page.rect(".run-detail .graph-viewport");
|
||||
shots.push(await page.screenshot(`${out}/31-run-live-graph.png`));
|
||||
).catch(() => null);
|
||||
// The row was running when it was picked but may have stopped while its
|
||||
// detail loaded; this capture is documented as best effort, so say so rather
|
||||
// than fail an unrelated step on live-data timing.
|
||||
if (!live) {
|
||||
console.log(` -- run ${liveRunId} stopped before its active stage rendered; skipped the live halo capture`);
|
||||
} else {
|
||||
if (!live.badge) throw new Error(`the active stage showed no elapsed badge: ${JSON.stringify(live)}`);
|
||||
console.log(` live run ${liveRunId}: active stage ${live.activeKey} (pulsing=${live.pulsing}), badge ${live.badge}`);
|
||||
await page.rect(".run-detail .graph-viewport");
|
||||
shots.push(await page.screenshot(`${out}/31-run-live-graph.png`));
|
||||
}
|
||||
}
|
||||
|
||||
// The Output empty state, on the running run that has not produced output yet.
|
||||
@@ -2383,6 +2400,10 @@ try {
|
||||
await page.clickText("nav.tabs button.tab", "Chat");
|
||||
await page.waitForSelector("#chatRows .chat-row", { timeout: 25000 });
|
||||
|
||||
// The operator's own session is the one this step reads; the list may lead with
|
||||
// another run's closed row (C2 closes its create, and history sits by recency),
|
||||
// so pick the operator row rather than assuming the first.
|
||||
const expectedSession = "ses_eae413f50ffeLQDExlg8cYnscN";
|
||||
const chatList = await page.evaluate(`(() => ({
|
||||
label: document.querySelector("#chatSearch")?.getAttribute("aria-label") ?? "",
|
||||
placeholder: document.querySelector("#chatSearch")?.getAttribute("placeholder") ?? "",
|
||||
@@ -2392,26 +2413,31 @@ try {
|
||||
chips: [...row.querySelectorAll(".chip")].map((chip) => chip.textContent),
|
||||
meta: row.querySelector(".chat-row-meta")?.textContent ?? "",
|
||||
close: !!row.querySelector(".chat-close"),
|
||||
closed: !!row.querySelector(".chat-closed-chip"),
|
||||
})),
|
||||
}))()`);
|
||||
if (chatList.label !== "Search chats") throw new Error(`chat search label: ${chatList.label}`);
|
||||
if (chatList.placeholder !== "Search chats") throw new Error(`chat search placeholder: ${chatList.placeholder}`);
|
||||
if (chatList.rows.length === 0) throw new Error("no chat sessions rendered");
|
||||
if (!chatList.rows[0].title) throw new Error("the first chat row has no title");
|
||||
if (!chatList.rows[0].chips.includes("Operator")) {
|
||||
throw new Error(`chat kind chip: ${chatList.rows[0].chips.join(", ")}`);
|
||||
const operatorRow =
|
||||
chatList.rows.find((row) => row.id === expectedSession) ??
|
||||
chatList.rows.find((row) => !row.closed && row.close);
|
||||
if (!operatorRow) throw new Error("no open chat row rendered");
|
||||
if (!operatorRow.title) throw new Error("the operator chat row has no title");
|
||||
if (!operatorRow.chips.includes("Operator")) {
|
||||
throw new Error(`chat kind chip: ${operatorRow.chips.join(", ")}`);
|
||||
}
|
||||
if (!chatList.rows[0].close) throw new Error("the open chat row offers no Close chat action");
|
||||
if (!operatorRow.close) throw new Error("the open chat row offers no Close chat action");
|
||||
console.log(
|
||||
` chat list: ${chatList.rows.length} session(s); "${chatList.rows[0].title}" ` +
|
||||
`[${chatList.rows[0].chips.join(", ")}] — ${chatList.rows[0].meta}`,
|
||||
` chat list: ${chatList.rows.length} session(s); "${operatorRow.title}" ` +
|
||||
`[${operatorRow.chips.join(", ")}] — ${operatorRow.meta}`,
|
||||
);
|
||||
await shot("44-chat-sessions.png");
|
||||
|
||||
// The row's own Close chat… action with NO conversation open: the list offers
|
||||
// it on every open row, so the confirm must still appear. Shown and dismissed
|
||||
// with Cancel; no chat_close is ever sent for the operator's live session.
|
||||
await page.click(`#chatRows .chat-row[data-session="${chatList.rows[0].id}"] .chat-close`);
|
||||
await page.click(`#chatRows .chat-row[data-session="${operatorRow.id}"] .chat-close`);
|
||||
await page.waitForSelector(".confirm-chat-close", { timeout: 15000 });
|
||||
const listClose = await page.evaluate(
|
||||
`document.querySelector(".confirm-chat-close .confirm-message")?.textContent ?? ""`,
|
||||
@@ -2440,12 +2466,179 @@ try {
|
||||
throw new Error(`Clear search left the query: ${JSON.stringify(clearedQuery)}`);
|
||||
}
|
||||
|
||||
// C2: create a chat through the directory picker. This step creates exactly one
|
||||
// REAL session (the app's own path, not the ephemeral `/new` verification path),
|
||||
// captures it, then closes it with `chat_close` so it moves to closed history
|
||||
// instead of sitting active in the operator's list. The operator's own session
|
||||
// is never selected, closed or prompted here.
|
||||
step("C2: the create pane — directory picker, one real create, then close");
|
||||
await ensureConnected();
|
||||
await page.evaluate(`(() => {
|
||||
window.__pipelinesEphemeralChat = false;
|
||||
window.__chatCreateBodies = [];
|
||||
return true;
|
||||
})()`);
|
||||
await page.click(".chat-toolbar .chat-new");
|
||||
await page.waitForSelector(".chat-create", { timeout: 15000 });
|
||||
await page.waitForSelector(".chat-create-choice", { timeout: 20000 });
|
||||
|
||||
const picker = await page.evaluate(`(() => ({
|
||||
title: document.querySelector(".chat-create-title")?.textContent ?? "",
|
||||
back: document.querySelector(".chat-create-back")?.getAttribute("aria-label") ?? "",
|
||||
backTitle: document.querySelector(".chat-create-back")?.getAttribute("title") ?? "",
|
||||
prompt: document.querySelector(".chat-create-prompt")?.textContent ?? "",
|
||||
loading: !!document.querySelector(".chat-create-loading"),
|
||||
note: document.querySelector(".chat-create-model-note")?.textContent ?? "",
|
||||
start: document.querySelector(".chat-create-start")?.textContent ?? "",
|
||||
cancel: document.querySelector(".chat-create-cancel")?.textContent ?? "",
|
||||
cancelDisabled: document.querySelector(".chat-create-cancel")?.disabled ?? null,
|
||||
confirm: document.querySelector(".chat-create-confirm")?.textContent ?? "",
|
||||
confirmDisabled: document.querySelector(".chat-create-confirm")?.disabled ?? null,
|
||||
rows: [...document.querySelectorAll(".chat-create-choice")].map((row) => ({
|
||||
label: row.querySelector(".chat-create-choice-label")?.textContent ?? "",
|
||||
path: row.querySelector(".chat-create-choice-path")?.textContent ?? "",
|
||||
directory: row.dataset.directory ?? "",
|
||||
selected: row.getAttribute("aria-selected") === "true",
|
||||
})),
|
||||
}))()`);
|
||||
if (picker.title !== "Start a chat") throw new Error(`C2 title: ${picker.title}`);
|
||||
if (picker.back !== "Cancel new chat" || picker.backTitle !== "Cancel new chat") {
|
||||
throw new Error(`C2 back label: ${JSON.stringify({ aria: picker.back, title: picker.backTitle })}`);
|
||||
}
|
||||
if (picker.prompt !== "Where should this chat live?") {
|
||||
throw new Error(`C2 prompt: ${picker.prompt}`);
|
||||
}
|
||||
if (picker.loading) throw new Error("C2 still shows Loading directories… after the choices rendered");
|
||||
if (
|
||||
picker.note !==
|
||||
"This server has no request for choosing a chat's model, so a new chat uses the server's default."
|
||||
) {
|
||||
throw new Error(`C2 model note: ${picker.note}`);
|
||||
}
|
||||
if (picker.start !== "Start in ~") throw new Error(`C2 footer: ${picker.start}`);
|
||||
if (picker.cancel !== "Cancel") throw new Error(`C2 cancel: ${picker.cancel}`);
|
||||
if (picker.cancelDisabled !== false || picker.confirmDisabled !== false) {
|
||||
throw new Error(`C2 controls disabled before sending: ${JSON.stringify(picker)}`);
|
||||
}
|
||||
if (picker.confirm.trim() !== "New chat") throw new Error(`C2 confirm: ${picker.confirm}`);
|
||||
if (picker.rows.length === 0) throw new Error("C2 rendered no directory choices");
|
||||
const homeRow = picker.rows[0];
|
||||
if (homeRow.label !== "Home (~)" || homeRow.directory !== "~" || !homeRow.selected) {
|
||||
throw new Error(`C2 home row is not first and selected: ${JSON.stringify(homeRow)}`);
|
||||
}
|
||||
if (homeRow.path === "" || homeRow.path === "~") {
|
||||
throw new Error(`C2 home row has no absolute path beneath it: ${JSON.stringify(homeRow)}`);
|
||||
}
|
||||
const recents = picker.rows.slice(1);
|
||||
// A recent's own label is its full path (only the home row carries a separate
|
||||
// secondary path), so the data-directory value and the label must agree.
|
||||
if (recents.some((row) => row.label !== row.directory || row.directory === "")) {
|
||||
throw new Error(`C2 recent rows are not labelled by full path: ${JSON.stringify(recents)}`);
|
||||
}
|
||||
console.log(
|
||||
` create pane: "${picker.title}" (back "${picker.back}"); home "${homeRow.label}" ` +
|
||||
`${homeRow.path} selected; ${recents.length} recent(s); footer "${picker.start}"`,
|
||||
);
|
||||
await shot("75-chat-create-picker.png");
|
||||
|
||||
// Choose home explicitly (it is already the default), then create exactly one
|
||||
// session. The request body is recorded by the socket shim.
|
||||
await page.click(".chat-create-choice");
|
||||
await page.evaluate(`window.__chatCreateBodies = []`);
|
||||
await page.click(".chat-create-confirm");
|
||||
const beforeCreate = await page.evaluate(
|
||||
`document.querySelector(".chat-row.selected")?.dataset.session ?? ""`,
|
||||
);
|
||||
const createdId = await eventually(
|
||||
async () => {
|
||||
const id = await page.evaluate(`document.querySelector(".chat-row.selected")?.dataset.session ?? ""`);
|
||||
return id && id !== beforeCreate ? id : false;
|
||||
},
|
||||
{ timeout: 30000, what: "the C2-created session to be selected" },
|
||||
);
|
||||
createdSessionId = createdId;
|
||||
const created = await page.evaluate(`(() => {
|
||||
const rows = [...document.querySelectorAll("#chatRows .chat-row")];
|
||||
const row = document.querySelector('.chat-row[data-session="${createdId}"]');
|
||||
return {
|
||||
first: rows[0]?.dataset.session ?? "",
|
||||
title: row?.querySelector(".chat-row-title")?.textContent ?? "",
|
||||
selected: row?.classList.contains("selected") ?? false,
|
||||
closed: !!row?.querySelector(".chat-closed-chip"),
|
||||
header: document.querySelector(".chat-bar-title")?.textContent ?? "",
|
||||
empty: document.querySelector(".chat-detail .chat-transcript-empty")?.textContent ?? "",
|
||||
composer: !!document.querySelector("#chatComposer"),
|
||||
pickerGone: !document.querySelector(".chat-create"),
|
||||
};
|
||||
})()`);
|
||||
const createBodies = await page.evaluate(`window.__chatCreateBodies || []`);
|
||||
if (createBodies.length !== 1) {
|
||||
throw new Error(`C2 sent ${createBodies.length} chat_create request(s) for one create`);
|
||||
}
|
||||
const body = createBodies[0] ?? {};
|
||||
if (
|
||||
body.title !== "New chat" ||
|
||||
body.directory !== "~" ||
|
||||
typeof body.operation_id !== "string" ||
|
||||
body.operation_id === "" ||
|
||||
Object.keys(body).sort().join(",") !== "directory,operation_id,title"
|
||||
) {
|
||||
throw new Error(`C2 chat_create body: ${JSON.stringify(body)}`);
|
||||
}
|
||||
if (!created.pickerGone || !created.selected || created.closed) {
|
||||
throw new Error(`C2 did not close the pane onto the new conversation: ${JSON.stringify(created)}`);
|
||||
}
|
||||
if (created.first !== createdId) {
|
||||
throw new Error(`C2 created row is not at the head: first=${created.first} created=${createdId}`);
|
||||
}
|
||||
if (created.title !== "New chat" || created.header !== "New chat") {
|
||||
throw new Error(`C2 created title: ${JSON.stringify(created)}`);
|
||||
}
|
||||
if (created.empty !== "This chat has no messages yet. Ask something below." || !created.composer) {
|
||||
throw new Error(`C2 did not load the empty conversation: ${JSON.stringify(created)}`);
|
||||
}
|
||||
console.log(
|
||||
` chat_create sent exactly {title:"New chat",directory:"~",operation_id:${JSON.stringify(body.operation_id)}}; ` +
|
||||
`session ${createdId} at the head, active with empty history`,
|
||||
);
|
||||
await shot("76-chat-created-list.png");
|
||||
|
||||
// Close the one real session it created (chat_close through the C3 confirm) and
|
||||
// capture the Closed chip. Nothing is deleted; the row stays as closed history.
|
||||
await page.click(`#chatRows .chat-row[data-session="${createdId}"] .chat-close`);
|
||||
await page.waitForSelector(".confirm-chat-close", { timeout: 15000 });
|
||||
await page.click(".confirm-chat-close .confirm-accept");
|
||||
await eventually(
|
||||
() =>
|
||||
page.evaluate(
|
||||
`!!document.querySelector('.chat-row[data-session="${createdId}"] .chat-closed-chip')`,
|
||||
),
|
||||
{ timeout: 20000, what: "the C2 session to show as closed" },
|
||||
);
|
||||
const createdClosed = await page.evaluate(`(() => {
|
||||
const row = document.querySelector('.chat-row[data-session="${createdId}"]');
|
||||
row?.scrollIntoView({ block: "center" });
|
||||
return {
|
||||
closed: !!row?.querySelector(".chat-closed-chip"),
|
||||
hasClose: !!row?.querySelector(".chat-close"),
|
||||
hasReopen: !!row?.querySelector(".chat-reopen"),
|
||||
};
|
||||
})()`);
|
||||
if (!createdClosed.closed || createdClosed.hasClose || !createdClosed.hasReopen) {
|
||||
throw new Error(`C2 closed row: ${JSON.stringify(createdClosed)}`);
|
||||
}
|
||||
console.log(
|
||||
` C2: created real session ${createdId} ("New chat" in ~) and closed it via chat_close; ` +
|
||||
"it now shows the Closed chip (kept as history, not deleted)",
|
||||
);
|
||||
await shot("77-chat-created-closed.png");
|
||||
createdSessionId = null;
|
||||
|
||||
// The live session set changes between runs: the first row can be a
|
||||
// freshly-created empty "New chat" (which renders the empty state, not a
|
||||
// transcript). Prefer the operator's own session; otherwise try the listed rows
|
||||
// in order until one carries a real transcript, and say plainly if none does,
|
||||
// rather than waiting on a hard-coded session that the server no longer lists.
|
||||
const expectedSession = "ses_eae413f50ffeLQDExlg8cYnscN";
|
||||
const preferred = chatList.rows.find((row) => row.id === expectedSession);
|
||||
const openRows = chatList.rows.filter((row) => row.close).map((row) => row.id);
|
||||
const candidates = [
|
||||
@@ -5004,6 +5197,38 @@ try {
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
// Best-effort cleanup of C2's real session: if the run failed between creating
|
||||
// it and its own close, close it now so it never sits active in the operator's
|
||||
// list. Nothing is deleted either way.
|
||||
if (createdSessionId && page) {
|
||||
try {
|
||||
const closed = await page.evaluate(
|
||||
`!!document.querySelector('.chat-row[data-session="${createdSessionId}"] .chat-closed-chip')`,
|
||||
);
|
||||
if (!closed) {
|
||||
await page.evaluate(
|
||||
`document.querySelector('#chatRows .chat-row[data-session="${createdSessionId}"]')?.click()`,
|
||||
);
|
||||
await page.waitForSelector("#chatInput", { timeout: 8000 }).catch(() => {});
|
||||
await page.evaluate(`(async () => {
|
||||
const input = document.querySelector("#chatInput");
|
||||
if (!input) return;
|
||||
input.value = "/close";
|
||||
input.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
input.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true, cancelable: true }));
|
||||
await new Promise((resolve) => setTimeout(resolve, 400));
|
||||
document.querySelector(".confirm-chat-close .confirm-accept")?.click();
|
||||
})()`);
|
||||
await eventually(() => page.evaluate(`!document.querySelector(".confirm-chat-close")`), {
|
||||
timeout: 8000,
|
||||
what: "the C2 cleanup close to finish",
|
||||
}).catch(() => {});
|
||||
console.log(` cleanup: closed the C2-created session ${createdSessionId}`);
|
||||
}
|
||||
} catch {
|
||||
// the page may already be gone; the failure above is the real signal
|
||||
}
|
||||
}
|
||||
// Best-effort cleanup of the throwaway session this run created: if the run
|
||||
// failed before its `/close` step, close it now so it is never left open.
|
||||
if (throwawaySessionId && page) {
|
||||
|
||||
Reference in New Issue
Block a user