From 422db96c95358a0813e90f2aab659907c5b975a5 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Tue, 20 Oct 2026 15:14:39 +0100 Subject: [PATCH] web: open reasoning in the tool-style popup --- web/PARITY.md | 2 +- web/chat.css | 17 ++++---- web/src/app.js | 3 +- web/src/views/chat.js | 68 +++++++++++++++++++++---------- web/sw.js | 2 +- web/test/ui-smoke.mjs | 94 ++++++++++++++++++------------------------- 6 files changed, 98 insertions(+), 88 deletions(-) diff --git a/web/PARITY.md b/web/PARITY.md index 7716a50c..71503f47 100644 --- a/web/PARITY.md +++ b/web/PARITY.md @@ -170,7 +170,7 @@ to it, but the server never lists it and a reload drops it. | B16 | One live status line for tools | — | done — the current tool call now shares the `N tools called` line; the separate bottom per-tool line is gone and the lower indicator appears only while no tool is running. The live reasoning label's duration ticks every second without waiting for a frame. Chat frames for a background session no longer repaint a Runs/Pipelines screen: verified a synthetic stream while opening run 12's detail left the run screen interactive with no per-frame replacements. | | B17 | Clear list chrome and chat recency | — | done — list pages no longer repeat the destination title/subtitle from the rail/dock, and the manual Refresh controls are gone; the visible list refreshes once when the page regains focus, preserving its scroll position and leaving open menus, dialogs and text fields alone. Chat rows replace the meaningless `Idle`/`Open` status with the server's latest-update recency (`just now`, `15 min ago`, `2 days ago`), keep `Streaming`/`New`/`Closed`, and give each directory a full-width elevated band with centred text that expands/collapses exactly like Closed (square corners, not a rounded chip), abbreviating the server home prefix to `~` (`~/repos/pipelines`) in both the band and the row meta. `New chat` is now a filled primary control beside the search field. Runs and Pipelines use the same title-free list header. Verified at 390×844 and 1440×900 in a real browser, with no console errors; the web unit suite is 633 tests. | | B18 | Chat attachments in the message and paste | `chat_prompt.attachments` | done — composer files are read into base64 and sent with the prompt (1 MiB total, under the 2 MiB websocket frame), the server writes them to private temporary files and passes `file://` references to OpenCode's prompt `files`, and both the live user turn and reloaded history render a named file chip inside the message. Pasting an image/file into the textarea attaches it with the same picker path; a pasted image without a filename gets a generated name. The optimistic user bubble shows the file immediately, and OpenCode history maps the top-level user `files` envelope (never its base64 data) into the same part. | -| B19 | One live chat activity line and immediate Stop | — | done — every in-flight turn now has one square activity row carrying the spinner, `Thinking`/`Reasoning · N steps`, the tool-call chip with its current call, and the elapsed time; the separate reasoning, tool and bottom "thinking" lines are gone. The row stays in place when the turn settles (spinner off), and the elapsed ticks locally each second. The composer's Stop is refreshed on the step frame itself, so it appears for turns started by another client and stays through tool calls. A subscribe that joins a live turn replays a `step started` marker. Cancel now marks the run and its live step canceled immediately before interrupting the runner, so a context-unaware stage cannot leave a "running" row after Stop. | +| B19 | One live chat activity line and immediate Stop | — | done — every in-flight turn now has one square activity row carrying the spinner, `Thinking`/`Reasoning · N steps`, the tool-call chip with its current call, and the elapsed time; the separate reasoning, tool and bottom "thinking" lines are gone. The row stays in place when the turn settles (spinner off), and the elapsed ticks locally each second. Clicking the reasoning label opens the full reasoning in the same modal shape as the tool-call panel, never expanding inline. The composer's Stop is refreshed on the step frame itself, so it appears for turns started by another client and stays through tool calls. A subscribe that joins a live turn replays a `step started` marker. Cancel now marks the run and its live step canceled immediately before interrupting the runner, so a context-unaware stage cannot leave a "running" row after Stop. | | B20 | Cancel a running run immediately | `cancel_run` | done — `runner.cancel` persists `canceled` on the run and its live step before calling the runner's cancel function; late stage returns cannot overwrite it (`FinishRun` only updates queued/running, and a failed step persistence is reported as canceled, not a failure). This also covers orphaned running rows with no active goroutine and waiting runs. Verified by store tests and the run that had been stuck at run 13 is now interrupted/canceled rather than running. | | B21 | Change a chat's model | `chat_models`, `chat_model` | done — the open conversation shows its current model under the title. Clicking it lists the OpenCode endpoint's enabled, non-deprecated models with provider/name, scrolls the current selection into view, and switches through `POST /api/session/{id}/model`; the row and header update immediately and the next turn uses it. The list is read-only until a model is chosen, and a failed switch leaves the dialog open with the server's reason. Verified live: 48 models listed and an ephemeral session switched to `opencode-go/beam-free`. | | B22 | Agent badge on chat rows | — | done — every chat row shows the harness mark at its right edge (OpenCode terminal, Codex hex, Claude starburst, Pi), with the harness name as tooltip/aria-label. OpenCode is the default for legacy rows; Codex rows carry their backend from the adapter. The model switcher is hidden for harnesses that do not support it. | diff --git a/web/chat.css b/web/chat.css index d5b64042..389e5612 100644 --- a/web/chat.css +++ b/web/chat.css @@ -512,13 +512,6 @@ .chat-activity-elapsed { flex: none; } .chat-activity-sep { color: var(--muted); flex: none; } .chat-activity-head > .chat-tool-chip { min-width: 0; overflow: hidden; } -.chat-reasoning-body { - margin: 6px 0 2px; - white-space: pre-wrap; - overflow-wrap: anywhere; - color: var(--muted); - font-size: 12px; -} .chat-jump { position: absolute; right: 14px; bottom: 14px; border-color: var(--accent); color: var(--accent); } @@ -1020,6 +1013,16 @@ background: transparent; } .chat-tools-modal-panel .chat-tool-list { overflow: auto; } +.chat-reasoning-modal-body { + min-height: 0; + overflow: auto; + padding: 12px; + white-space: pre-wrap; + overflow-wrap: anywhere; + color: var(--muted); + font-size: 13px; + line-height: 1.6; +} /* Code in agent replies keeps the terminal's colour grammar: comments muted, strings green, numbers amber, keywords blue, literals pink. */ diff --git a/web/src/app.js b/web/src/app.js index 7d11baf8..749fabbf 100644 --- a/web/src/app.js +++ b/web/src/app.js @@ -299,9 +299,8 @@ const state = { chatActiveId: null, chatPlaced: null, chatFollowing: true, - chatReasoning: new Set(), // The tool-call panel (C6): the turns whose panel is open and the individual - // rows the operator has expanded, both keyed the same way as chatReasoning so + // rows the operator has expanded, keyed the same way as the old inline state so // a re-render keeps them. chatToolPanels: new Set(), chatToolRows: new Set(), diff --git a/web/src/views/chat.js b/web/src/views/chat.js index afec40ad..e2d9281e 100644 --- a/web/src/views/chat.js +++ b/web/src/views/chat.js @@ -590,7 +590,6 @@ async function openChatSession(id, { updateRoute = true } = {}) { state.chatMenu = null; state.chatPlaced = null; state.chatFollowing = true; - state.chatReasoning = new Set(); state.chatToolPanels = new Set(); state.chatToolRows = new Set(); // Opening reads the conversation: advance the watermark to its current recency @@ -3308,28 +3307,24 @@ function renderChatActivity(turn, streaming = false, elapsedMillis = () => 0, th ); } wrap.append(head); - if (steps.length > 0) { - const body = h("div", { class: "chat-reasoning-body", text: turn.reasoning }); - body.hidden = !state.chatReasoning.has(turn.key); - wrap.append(body); - } return wrap; } /** The reasoning half of the activity row: a quiet, expandable label. */ function renderChatReasoningToggle(turn, streaming, steps) { - const expanded = state.chatReasoning.has(turn.key); const toggle = h("button", { class: "chat-reasoning-toggle", type: "button", - "aria-expanded": String(expanded), + "aria-haspopup": "dialog", + "aria-label": "Open reasoning", + title: "Open reasoning", }); toggle.append( h("span", { class: "chat-reasoning-icon", role: "img", - "aria-label": expanded ? "Hide reasoning" : "Show reasoning", - text: expanded ? "\u25be" : "\u25b8", + "aria-label": "Open reasoning", + text: "\u25b8", }), ); toggle.append( @@ -3339,22 +3334,51 @@ function renderChatReasoningToggle(turn, streaming, steps) { text: reasoningLabel(steps.length, streaming), }), ); - toggle.addEventListener("click", () => { - const block = toggle.closest(".chat-activity"); - const body = block?.querySelector(".chat-reasoning-body"); - if (!body) return; - const next = body.hidden; - body.hidden = !next; - toggle.setAttribute("aria-expanded", String(next)); - const icon = toggle.querySelector(".chat-reasoning-icon"); - icon.textContent = next ? "\u25be" : "\u25b8"; - icon.setAttribute("aria-label", next ? "Hide reasoning" : "Show reasoning"); - if (next) state.chatReasoning.add(turn.key); - else state.chatReasoning.delete(turn.key); + toggle.addEventListener("click", (event) => { + event.stopPropagation(); + openChatReasoning(turn, steps); }); return toggle; } +/** The reasoning overlay, shaped like the tool-call popup. */ +function openChatReasoning(turn, steps) { + const close = () => modal.close("chat-reasoning"); + const overlay = h("div", { + class: "chat-tools-viewer chat-reasoning-viewer", + role: "dialog", + "aria-modal": "true", + "aria-label": "Reasoning", + }); + overlay.addEventListener("click", (event) => { + if (event.target === overlay) close(); + }); + const panel = h("div", { class: "chat-tools-modal-panel chat-reasoning-modal-panel" }); + panel.append( + h( + "div", + { class: "chat-tool-panel-head" }, + h("span", { class: "chat-tool-panel-count", text: reasoningLabel(steps.length, false) }), + h("button", { + class: "ghost chat-tool-close", + type: "button", + "aria-label": "Close reasoning", + title: "Close reasoning", + text: "\u00d7", + onclick: close, + }), + ), + h("div", { class: "chat-reasoning-modal-body", text: turn.reasoning }), + ); + overlay.append(panel); + modal.open("chat-reasoning", overlay, { + history: false, + onClose: close, + trigger: document.activeElement, + fallbackSelectors: ["#chatTranscript", "#detailTitle", "#pane-main"], + }); +} + /** * One turn's tool calls behind a single summary chip: `N tools`, the * current call while one is in flight, a `· long` mark and the panel chevron. diff --git a/web/sw.js b/web/sw.js index 5f868cd9..750ee1f3 100644 --- a/web/sw.js +++ b/web/sw.js @@ -1,7 +1,7 @@ // A shell cache for an installed Pipelines app. The API (the WebSocket proxy and // artifact files) is never cached; static files prefer the network and fall back // to the last good copy so an installed app still opens when the server is away. -const CACHE = "pipelines-shell-v6"; +const CACHE = "pipelines-shell-v7"; const SHELL = ["/", "/index.html", "/manifest.webmanifest", "/favicon.svg"]; self.addEventListener("install", (event) => { diff --git a/web/test/ui-smoke.mjs b/web/test/ui-smoke.mjs index 6c8e1dfd..c1084f83 100644 --- a/web/test/ui-smoke.mjs +++ b/web/test/ui-smoke.mjs @@ -5029,42 +5029,38 @@ try { // fenced code lives in its reasoning, which the app renders as plain text // (Markdown.kt draws reasoning with a plain Text, never the markdown subset). if (transcript.reasoning > 0) { + await page.evaluate(`document.querySelector("#chatTranscript .chat-reasoning-toggle")?.click()`); + await page.waitForSelector(".chat-reasoning-viewer", { timeout: 5000 }); const expanded = await page.evaluate(`(() => { - const block = document.querySelector("#chatTranscript .chat-reasoning"); - if (!block) return null; - block.querySelector(".chat-reasoning-toggle")?.click(); - const body = block.querySelector(".chat-reasoning-body"); + const viewer = document.querySelector(".chat-reasoning-viewer"); + const body = viewer?.querySelector(".chat-reasoning-modal-body"); if (!body) return null; - // Bring the reasoning's own fenced block into view, so the capture shows - // the code the live session actually carries. const fence = String.fromCharCode(96).repeat(3); const text = body.textContent ?? ""; const index = text.indexOf(fence); - const transcript = document.querySelector("#chatTranscript"); - if (index >= 0 && transcript && body.firstChild && body.firstChild.nodeType === 3) { + // Bring the fenced block into the popup's view, not the transcript's. + if (index >= 0 && body.firstChild && body.firstChild.nodeType === 3) { const range = document.createRange(); range.setStart(body.firstChild, index); range.setEnd(body.firstChild, index + fence.length); const rect = range.getBoundingClientRect(); - const tRect = transcript.getBoundingClientRect(); - transcript.scrollTop += Math.round(rect.top - tRect.top) - 120; + body.scrollTop += Math.round(rect.top - body.getBoundingClientRect().top) - 40; } return { - label: block.querySelector(".chat-reasoning-label")?.textContent ?? "", + label: viewer.querySelector(".chat-tool-panel-count")?.textContent ?? "", hasFence: index >= 0, + length: text.length, }; })()`); - await eventually( - () => - page.evaluate( - `(() => { const b = document.querySelector("#chatTranscript .chat-reasoning-body"); return !!b && !b.hidden; })()`, - ), - { timeout: 5000, what: "the reasoning block to expand" }, - ); if (expanded) { - console.log(` reasoning block "${expanded.label}" expanded; carries a fenced block: ${expanded.hasFence}`); + console.log(` reasoning popup "${expanded.label}" (${expanded.length} chars); carries a fenced block: ${expanded.hasFence}`); } await shot("47-chat-reasoning-code.png"); + await page.evaluate(`document.querySelector(".chat-reasoning-viewer .chat-tool-close")?.click()`); + await eventually(() => page.evaluate(`!document.querySelector(".chat-reasoning-viewer")`), { + timeout: 5000, + what: "the reasoning popup to close", + }); } // C7's code-block path. The live assistant answer carries no fenced block (its @@ -5108,55 +5104,43 @@ try { const reasoningNow = await page.evaluate(`(() => { const block = document.querySelector("#chatTranscript .chat-reasoning"); if (!block) return null; + const toggle = block.querySelector(".chat-reasoning-toggle"); const icon = block.querySelector(".chat-reasoning-icon"); - const body = block.querySelector(".chat-reasoning-body"); return { label: block.querySelector(".chat-reasoning-label")?.textContent ?? "", aria: icon?.getAttribute("aria-label") ?? "", - expanded: body ? !body.hidden : false, + hasPopup: toggle?.getAttribute("aria-haspopup") ?? "", + inlineBody: !!block.querySelector(".chat-reasoning-body"), }; })()`); - if (!reasoningNow) throw new Error("C6: no reasoning block rendered in the live transcript"); - if (reasoningNow.aria !== "Hide reasoning") { - throw new Error(`C6: the expanded reasoning chevron should read 'Hide reasoning', got ${reasoningNow.aria}`); + if (!reasoningNow) throw new Error("C6: no reasoning row rendered in the live transcript"); + if (reasoningNow.aria !== "Open reasoning" || reasoningNow.hasPopup !== "dialog") { + throw new Error(`C6: the reasoning control should open a dialog: ${JSON.stringify(reasoningNow)}`); } - if (!/^Reasoning( · \d+ steps)?( · \d+[a-z].*)?$/.test(reasoningNow.label)) { + if (reasoningNow.inlineBody) throw new Error("C6: reasoning still expands inline"); + if (!/^Reasoning( · \d+ steps)?/.test(reasoningNow.label)) { throw new Error(`C6: settled reasoning label: ${reasoningNow.label}`); } - const reasoningCollapsed = await page.evaluate(`(() => { - const block = document.querySelector("#chatTranscript .chat-reasoning"); - block.querySelector(".chat-reasoning-toggle").click(); - const el = document.querySelector("#chatTranscript"); - const br = block.getBoundingClientRect(); - el.scrollTop = Math.max(0, el.scrollTop + Math.round(br.top - el.getBoundingClientRect().top) - 60); + await page.evaluate(`document.querySelector("#chatTranscript .chat-reasoning-toggle").click()`); + await page.waitForSelector(".chat-reasoning-viewer", { timeout: 5000 }); + const reasoningPopup = await page.evaluate(`(() => { + const viewer = document.querySelector(".chat-reasoning-viewer"); return { - hidden: block.querySelector(".chat-reasoning-body").hidden, - aria: block.querySelector(".chat-reasoning-icon").getAttribute("aria-label"), - expanded: block.querySelector(".chat-reasoning-toggle").getAttribute("aria-expanded"), + title: viewer?.querySelector(".chat-tool-panel-count")?.textContent ?? "", + body: viewer?.querySelector(".chat-reasoning-modal-body")?.textContent ?? "", + close: viewer?.querySelector(".chat-tool-close")?.getAttribute("aria-label") ?? "", }; })()`); - if (!reasoningCollapsed.hidden || reasoningCollapsed.aria !== "Show reasoning" || reasoningCollapsed.expanded !== "false") { - throw new Error(`C6: collapsing the reasoning block: ${JSON.stringify(reasoningCollapsed)}`); + if (!reasoningPopup.title.startsWith("Reasoning") || reasoningPopup.body.length === 0 || reasoningPopup.close !== "Close reasoning") { + throw new Error(`C6: reasoning popup: ${JSON.stringify({ ...reasoningPopup, body: reasoningPopup.body.length })}`); } - console.log(` reasoning block "${reasoningNow.label}" collapsed (chevron "Show reasoning")`); - await shot("51-chat-reasoning-collapsed.png"); - const expandedReasoning = await page.evaluate(`(() => { - const block = document.querySelector("#chatTranscript .chat-reasoning"); - block.querySelector(".chat-reasoning-toggle").click(); - const el = document.querySelector("#chatTranscript"); - const br = block.getBoundingClientRect(); - el.scrollTop = Math.max(0, el.scrollTop + Math.round(br.top - el.getBoundingClientRect().top) - 60); - return { - hidden: block.querySelector(".chat-reasoning-body").hidden, - aria: block.querySelector(".chat-reasoning-icon").getAttribute("aria-label"), - length: block.querySelector(".chat-reasoning-body").textContent.length, - }; - })()`); - if (expandedReasoning.hidden || expandedReasoning.aria !== "Hide reasoning" || expandedReasoning.length === 0) { - throw new Error(`C6: expanding the reasoning block: ${JSON.stringify(expandedReasoning)}`); - } - console.log(` reasoning block expanded again (${expandedReasoning.length} chars, chevron "Hide reasoning")`); - await shot("52-chat-reasoning-expanded.png"); + console.log(` reasoning popup "${reasoningPopup.title}" (${reasoningPopup.body.length} chars, close "${reasoningPopup.close}")`); + await shot("51-chat-reasoning-popup.png"); + await page.evaluate(`document.querySelector(".chat-reasoning-viewer .chat-tool-close").click()`); + await eventually(() => page.evaluate(`!document.querySelector(".chat-reasoning-viewer")`), { + timeout: 5000, + what: "the reasoning popup to close", + }); // The chip: its count, its screen-reader announcement and its chevron. The // count is the number of rows the panel carries, so the two can never disagree.