web: chat composer review fixes — real Stop, /close leaves the pane

Address the review of C8/C9: the composer's Stop control now routes to
`chat_interrupt` (`onStop`) instead of the inert submit path, and the smoke
clicks it and asserts the page's own "Stopping the running turn…" notice with
no `Action failed` dialog (captures/63b). Accepting `/close` finishes the
session locally — the running/queued bits clear and the conversation leaves
the pane for the list, mirroring Android's `finishSession` — and the smoke
asserts the select hint returns. A command notice draws the one terminal
glyph (`CHAT_COMMAND_GLYPH`, `>_`) for both states, tinted only; the growing
textarea accounts for its padding and border so six rows are six whole lines;
remove a shadowed duplicate `chatSessionById`. Wording unchanged; every pure
helper and the wire shapes remain unit-tested.

The smoke creates a throwaway session via `/new`, really prompts, really
interrupts and closes it; the operator's session is never prompted.
This commit is contained in:
2026-10-19 07:26:25 +01:00
parent f660078173
commit d9f5ba6f75
6 changed files with 110 additions and 31 deletions
+10 -6
View File
@@ -95,7 +95,7 @@ the pipeline list already carries — rather than a pluralised verb.
| C5 | Live transcript: user/assistant text, one reply = one turn | `chat_subscribe`, `chat_event` | todo |
| 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) and `captures/64-chat-throwaway-closed.png`. The throwaway session was created with `chat_create` and closed with `chat_close` in cleanup; the operator's session `ses_eae413f50ffeLQDExlg8cYnscN` was never prompted |
| 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) |
| C10 | Permission/approval cards (allow once/always/reject) | `chat_permission`, `chat_reply` | todo |
| C11 | Background tasks bar: running shells only, capped + scrollable, bounded output page | `chat_shells`, `chat_shell_output` | todo |
@@ -129,11 +129,15 @@ server rename). And the **draft is held per chat in memory and mirrored into
persistence, while attachments are memory-only because a `File` handle cannot be
serialised. The composer's Stop control appears the moment a prompt is accepted
(optimistically, as the app does) and is released when a `chat_event` `step`
frame reports the turn `ended`; the rest of the live-transcript fold is C5's item.
The UI smoke creates one throwaway session per run (via `/new`) for the
running-turn capture and closes it again; the server keeps a closed chat as
history, so repeated runs accumulate closed `New chat` rows (there is no delete
command).
frame reports the turn `ended`; clicking it calls `stopChatTurn` (`chat_interrupt`,
as Android's `onStop` does) rather than the submit path, and the smoke clicks it on
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).
## Settings, layout, platform
| # | Feature | Protocol | Status |
+43 -23
View File
@@ -198,12 +198,18 @@ import {
retryRequestKey,
} from "./actions.js";
import {
CHAT_ATTACH_LABEL,
CHAT_COMMAND_GLYPH,
CHAT_COMPOSER_PLACEHOLDER,
CHAT_EMPTY,
CHAT_FOLLOW_THRESHOLD_PX,
CHAT_LOADING,
CHAT_NEW_ACTION,
CHAT_NO_MATCH_ACTION,
CHAT_QUEUED_NOTICE,
CHAT_SEARCH_LABEL,
CHAT_SEND_LABEL,
CHAT_STOP_LABEL,
CHAT_TAB_TITLE,
CLOSED_CHIP_LABEL,
CLOSED_SECTION_LABEL,
@@ -263,13 +269,6 @@ import {
transcriptRows,
turnElapsedMillis,
} from "./chat.js";
import {
CHAT_ATTACH_LABEL,
CHAT_COMPOSER_PLACEHOLDER,
CHAT_QUEUED_NOTICE,
CHAT_SEND_LABEL,
CHAT_STOP_LABEL,
} from "./chat.js";
import { codeBlockLabel, parseInline, parseMarkdown } from "./markdown.js";
const STORAGE_KEY = "pipelines.web.serverUrl.v2";
@@ -3443,6 +3442,14 @@ async function acceptChatClose(session) {
try {
const { session: updated } = await repo.closeChat(session.id);
applyChatSessionUpdate(session.id, updated, true);
// Closing finishes the session for every client: the turn is stopped and the
// conversation leaves the pane, back to the list (mirrors Android's
// `finishSession` calling `chatStore.close`). A rejection above leaves the
// conversation exactly as it was.
if (state.chatActiveId === session.id) {
setThread(session.id, { running: false, queued: false });
state.chatActiveId = null;
}
} catch (error) {
state.actionError = describeError(error);
}
@@ -3481,11 +3488,6 @@ function applyChatSessionUpdate(id, updated, closed) {
let chatAttachmentSeq = 0;
let chatNoticeSeq = 0;
/** The session row for an id, or null when the server never listed it. */
function chatSessionById(id) {
return state.chatSessions.find((session) => session.id === id) ?? null;
}
/** Revoke an attachment's image object URL, if it created one. */
function releaseAttachment(attachment) {
if (attachment?.thumbUrl) {
@@ -3589,16 +3591,24 @@ function onComposerKeydown(event, sessionId, session, controls) {
}
}
/** Grow the composer's textarea between one and six rows to fit its content. */
/**
* Grow the composer's textarea between one and six rows to fit its content. The
* element is `box-sizing: border-box` with vertical padding, so the cap and the
* measured height both include the padding and the border: a six-row field is
* six full text lines, not five-and-a-bit, and the first row is not clipped.
*/
function growComposerTextarea(el) {
if (!el) return;
const line = parseFloat(getComputedStyle(el).lineHeight) || 20;
const style = getComputedStyle(el);
const line = parseFloat(style.lineHeight) || 20;
const border = el.offsetHeight - el.clientHeight;
const padding = (parseFloat(style.paddingTop) || 0) + (parseFloat(style.paddingBottom) || 0);
const maxRows = 6;
const max = line * maxRows + border;
const max = line * maxRows + padding + border;
el.style.height = "auto";
el.style.height = `${Math.min(el.scrollHeight, max)}px`;
el.style.overflowY = el.scrollHeight > max ? "auto" : "hidden";
const wanted = el.scrollHeight + border;
el.style.height = `${Math.min(wanted, max)}px`;
el.style.overflowY = wanted > max ? "auto" : "hidden";
}
/**
@@ -3615,7 +3625,10 @@ function refreshComposerControls(sessionId, session, controls) {
const command = suggestions[index];
if (command) runChatCommand(sessionId, session, `/${command.name}`);
});
fillComposerPrimary(controls.primary, thread, () => submitChatComposer(sessionId, session, controls));
fillComposerPrimary(controls.primary, thread, {
onSend: () => submitChatComposer(sessionId, session, controls),
onStop: () => stopChatTurn(sessionId),
});
}
/** Run the composer's submit (Enter): a command runs, else the draft sends. */
@@ -4571,7 +4584,9 @@ function renderChatCommandNotice(sessionId, notice) {
h("span", {
class: "chat-command-notice-glyph",
"aria-hidden": "true",
text: failed ? "⌨" : "▸",
// The app draws `Icons.Default.Terminal` for both states and only changes
// the tint, so both notices share the one terminal glyph.
text: CHAT_COMMAND_GLYPH,
}),
);
head.append(
@@ -4682,7 +4697,10 @@ function renderChatComposer(thread, session, sessionId) {
const command = suggestions[index];
if (command) runChatCommand(sessionId, session, `/${command.name}`);
});
fillComposerPrimary(primary, thread, () => submitChatComposer(sessionId, session, controls));
fillComposerPrimary(primary, thread, {
onSend: () => submitChatComposer(sessionId, session, controls),
onStop: () => stopChatTurn(sessionId),
});
if (typeof requestAnimationFrame === "function") {
requestAnimationFrame(() => growComposerTextarea(input));
@@ -4720,8 +4738,10 @@ function fillCommandPalette(palette, suggestions, selected, onPick) {
/**
* The composer's single primary control: Stop while a turn is in flight (error
* tint), else Send, disabled unless the draft is sendable (or a slash draft).
* Stop routes to [onStop] (`chat_interrupt`), never to the submit path — the
* control must interrupt the running turn, as Android's `onStop` does.
*/
function fillComposerPrimary(primary, thread, onActivate) {
function fillComposerPrimary(primary, thread, { onSend, onStop } = {}) {
if (!primary) return;
primary.replaceChildren();
if (composerAction(thread) === COMPOSER_STOP) {
@@ -4734,7 +4754,7 @@ function fillComposerPrimary(primary, thread, onActivate) {
type: "button",
"aria-label": CHAT_STOP_LABEL,
title: CHAT_STOP_LABEL,
onclick: onActivate,
onclick: onStop,
},
"■",
),
@@ -4751,7 +4771,7 @@ function fillComposerPrimary(primary, thread, onActivate) {
"aria-label": CHAT_SEND_LABEL,
title: CHAT_SEND_LABEL,
disabled: !composerSendEnabled(thread),
onclick: onActivate,
onclick: onSend,
},
"➤",
),
+7
View File
@@ -820,6 +820,13 @@ export const CHAT_ATTACH_LABEL = "Attach file";
/** The composer's queued notice, shown while a prompt waits behind a turn. */
export const CHAT_QUEUED_NOTICE = "Queued — it will send when the current turn finishes.";
/**
* The terminal glyph on a command notice. The app draws `Icons.Default.Terminal`
* for both a successful and a failed notice and only changes the tint, so the
* browser uses this one glyph for both.
*/
export const CHAT_COMMAND_GLYPH = ">_";
/** The two values of [composerAction]. */
export const COMPOSER_SEND = "send";
export const COMPOSER_STOP = "stop";
+6 -1
View File
@@ -1666,7 +1666,12 @@ code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-
background: color-mix(in srgb, var(--bad) 16%, var(--surface-2));
}
.chat-command-notice-head { display: flex; gap: 6px; align-items: center; }
.chat-command-notice-glyph { font-size: 12px; color: var(--muted); }
.chat-command-notice-glyph {
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 12px;
line-height: 1;
color: var(--muted);
}
.chat-command-notice-failed .chat-command-notice-glyph { color: var(--bad); }
.chat-command-notice-label { font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.chat-command-notice-failed .chat-command-notice-label { color: var(--bad); }
+7
View File
@@ -6,6 +6,7 @@ import assert from "node:assert/strict";
import {
CHAT_COMMANDS,
CHAT_COMMAND_GLYPH,
CHAT_FOLLOW_THRESHOLD_PX,
CHAT_QUEUED_NOTICE,
COMPOSER_SEND,
@@ -767,6 +768,12 @@ test("CHAT_QUEUED_NOTICE is the app's own queued sentence", () => {
assert.equal(CHAT_QUEUED_NOTICE, "Queued — it will send when the current turn finishes.");
});
test("a command notice carries one terminal glyph for both states", () => {
// Android draws Icons.Default.Terminal for a Command and a Command failed
// notice and only changes the tint, so the two share this glyph.
assert.equal(CHAT_COMMAND_GLYPH, ">_");
});
// ---------------------------------------------------------------------------
// Slash commands (C9)
// ---------------------------------------------------------------------------
+37 -1
View File
@@ -2942,6 +2942,27 @@ try {
await showComposer();
await shot("63-chat-composer-stop.png");
// The Stop control must really interrupt (chat_interrupt), not fall through the
// inert submit path: click it and observe the page's own interrupting notice,
// with no Action failed dialog. The throwaway turn is the only one stopped.
await page.click("#chatStop");
const stopNotice = await eventually(
async () => {
const notices = await page.evaluate(
`[...document.querySelectorAll(".chat-command-notice:not(.chat-command-notice-failed) .chat-command-notice-text")].map((node) => node.textContent)`,
);
return notices.includes("Stopping the running turn…") ? "Stopping the running turn…" : false;
},
{ timeout: 15000, what: "the interrupt notice after clicking Stop" },
);
const stopFailed = await page.evaluate(
`document.querySelector(".action-failed .action-failed-message")?.textContent ?? ""`,
);
if (stopFailed !== "") throw new Error(`clicking Stop failed: ${stopFailed}`);
console.log(` clicking Stop sent chat_interrupt: "${stopNotice}"`);
await showComposer();
await shot("63b-chat-stop-interrupt.png");
// Cleanup: `/close` the throwaway through the C3 confirm. It is the only session
// this stage mutates and it is closed again (any in-flight turn is stopped).
await page.fill("#chatInput", "/close");
@@ -2976,7 +2997,22 @@ try {
hasReopen: !!row?.querySelector(".chat-reopen"),
};
})()`);
console.log(` /close closed the throwaway session ${throwawayId} (${JSON.stringify(closedRow)})`);
// Closing finishes the session: the conversation leaves the pane (back to the
// list with the select hint) and no row stays selected, as Android's
// finishSession does.
const afterThrowawayClose = await page.evaluate(`(() => ({
selected: !!document.querySelector(".chat-row.selected"),
hint: document.querySelector(".chat-detail .empty .muted")?.textContent ?? "",
composer: !!document.querySelector("#chatComposer"),
}))()`);
if (
afterThrowawayClose.selected ||
afterThrowawayClose.composer ||
afterThrowawayClose.hint !== "Select a chat to open it."
) {
throw new Error(`/close did not leave the conversation: ${JSON.stringify(afterThrowawayClose)}`);
}
console.log(` /close closed the throwaway session ${throwawayId} (${JSON.stringify(closedRow)}) and left the pane`);
await shot("64-chat-throwaway-closed.png");
throwawaySessionId = null;