Public: anyone can read this; the crew can change it.
Talk says what a long turn is doing and how long since its last step, across every stream #17808
Merged 15h 6m ago, live in production
talk-working-line → main 0 commits
11 files
changed +191
−40
docs/design/areas/talk.md +3 −3
| @@ -104,7 +104,7 @@ The window is the thread's one scroller; the list and a side pane are sticky col | ||
| 104 | 104 | - `.talk-m` — one row: the plain name, whose account and who pays (prices when the listing has them), the id; `data-at` is the row the keys are on, `aria-selected` the model in use. |
| 105 | 105 | - `.talk-fold` — one run of steps (the calls and thoughts between words) folded into one closed disclosure, one tab stop: one step by its words, more by their count. |
| 106 | 106 | - `.talk-fold-list` — the steps inside it, on a hairline at the start edge. |
| 107 | - `.talk-live` — the block being written; its running line shimmers (plain under reduced motion). | |
| 107 | - `.talk-live` — the block being written; its last line is the working line: what the turn does now, the time since its last step once that is quiet, how long it has run. Plain muted text in the version strip's digits (tabular, so a count never shifts the words): the counting is the sign of life, nothing shimmers. | |
| 108 | 108 | - `.talk-code`, `.talk-code-head` — a code block in a reply under a quiet head naming its language, with Copy there, never over the code. |
| 109 | 109 | |
| 110 | 110 | Prior art: Claude and ChatGPT (one centred column, the person's words in a quiet bubble, the reply as plain text, a rounded composer with one round send that becomes stop); Vercel's AI Elements (stick to bottom with a jump control, a step disclosure per reply, shimmer on the running step). |
| @@ -129,7 +129,7 @@ Prior art: Claude and ChatGPT (one centred column, the person's words in a quiet | ||
| 129 | 129 | - `.talk-reload`: Reload the preview, an icon button drawn `js-only`. |
| 130 | 130 | - `.talk-try`: the agent's one line of what to try in the frame (`pane`), above the stage: plain small muted text (`--muted-fg`), no box; text only, never a link. |
| 131 | 131 | - `.talk-stage`: the frame's surface, on the card colour with a hairline; `data-busy` dims the frame while it loads again. |
| 132 | - `.talk-stage-note`: the one line over the stage: "Updating the preview…", "Starting the preview…", "Making the first version…"; it shimmers (plain under reduced motion). | |
| 132 | - `.talk-stage-note`: the one line over the stage: "Updating the preview…", "Starting the preview…", "Making the first version…"; plain muted text. | |
| 133 | 133 | - `.talk-stage-wait`: the stage with no frame yet, beside a build: the note alone, as tall as the frame will be. |
| 134 | 134 | |
| 135 | 135 | #15734, second pass (the owner's pixel standard): |
| @@ -152,7 +152,7 @@ Prior art: Claude and ChatGPT (one centred column, the person's words in a quiet | ||
| 152 | 152 | - `.talk-links`: what a reply opened or changed, folded behind its count ("3 files") on the reply's one last line, each file by its path in its repository. |
| 153 | 153 | - `.talk-stage-files`: before a first version, the pane says what will appear and when, and shows the files the app starts from. |
| 154 | 154 | - `.talk-crew-now`, `.talk-crew-steps`: the crew's run in the pane's wait stage: why it waits or that it works, its newest steps in plain words as lines of text, and the run's page. |
| 155 | - `.talk-crew-working`, `.talk-crew-thought`: the crew member's working line (with the shine Talk's own agent uses while it answers) and its own words among its steps, in the pane's crew block. | |
| 155 | - `.talk-crew-working`, `.talk-crew-thought`: the crew member's working line and its own words among its steps, in the pane's crew block. | |
| 156 | 156 | |
| 157 | 157 | ## #16575: the pinned plan |
| 158 | 158 |
docs/features/talk-autopilot.md +1 −1
| @@ -8,6 +8,6 @@ You never have to say "continue". | ||
| 8 | 8 | |
| 9 | 9 | - **The plan**: when work takes several steps, Talk's agent keeps a plan (`keep_plan` with no repository). It is pinned at the top of the thread, says how many steps are done, and ticks each one as it finishes. The terminal's Talk shows it under the head line with the next step. When a long thread renews into a fresh session (at 85% of its context), the plan goes with it. |
| 10 | 10 | - **Carrying on**: when a turn runs out of its own time or budget, or its context is full, while the plan has open steps, the forge starts the next turn itself from the plan. It does this at most six times and for at most three dollars, then stops and says so in one line: "I stopped after 6 turns on my own; the plan's open steps are pinned above." Your next message resets both counts. Stop ends the turn and the chain. |
| 11 | - **Never looks hung**: when a running turn has shown nothing new for ten seconds, its working line says what it waits on (the step still running, its thinking, your yes on a held step, or the model) and counts the seconds. | |
| 11 | - **Never looks hung**: when a running turn has shown nothing new for ten seconds, its working line says what it waits on (the step still running, its thinking, your yes on a held step, or the model) and counts the time since its last step and the turn's own ("Live" in `docs/features/talk.md`). | |
| 12 | 12 | |
| 13 | 13 | Code: `carryOn` and `withHistory` in `src/crew/conversation.ts`, `src/core/conversation_plan.ts`, the pinned plan in `src/web/talk_lines.ts` and in the terminal's `src/tui/screens/talk_chats.ts`, `waitingOn` in `src/web/pages/talk.ts`. Tests: `test/talk-autopilot.test.ts`. |
docs/features/talk.md +4 −2
| @@ -32,7 +32,9 @@ What became of it is a line of its own in the thread, never folded, saying what | ||
| 32 | 32 | |
| 33 | 33 | The reply is drawn as it is written. The runner reports each piece of the block it is writing (`onDelta` in `src/crew/agent_runner.ts`; the Claude adapter asks for partial output with `--include-partial-messages` only for a Talk turn, so a crew run is unchanged). `src/crew/conversation_live.ts` holds the block in process memory, per conversation: the text so far (at most 20,000 characters, as a stored turn), whether the agent is thinking, and the tool call it is waiting on. It is cleared when the block is stored and when the turn ends, however it ends. |
| 34 | 34 | |
| 35 | - **Frames:** the stream sends `live` `{html, thinking, tool}` at once when something changes, at most one every 125 ms, always the latest. `html` is the text so far drawn by the same Markdown renderer as a stored reply (an unfinished fence is closed for drawing); `tool` is the step in plain words while it runs ("Reading src/a.ts…", `runningStep` in `src/core/talk_steps.ts`, or "Working: <tool words>…" for a tool with no words of its own), never its arguments as JSON; `thinking` is true or false, and the thoughts themselves arrive only in the stored, folded turn. A stream that connects mid-block gets the whole block in its first `live` frame. When the block is stored its `turn` frame is followed, in the same look, by an empty `live` frame, which removes the element: the server alone takes it away, so a turn from another door lands above the block and leaves it in place. A fresh attempt after a lost session starts from an empty block. | |
| 35 | - **Frames:** the stream sends `live` `{html, thinking, tool, waiting}` at once when something changes, at most one every 125 ms, always the latest. `html` is the text so far drawn by the same Markdown renderer as a stored reply (an unfinished fence is closed for drawing); `tool` is the step in plain words while it runs ("Reading src/a.ts…", `runningStep` in `src/core/talk_steps.ts`, or "Working: <tool words>…" for a tool with no words of its own), never its arguments as JSON; `thinking` is true or false, and the thoughts themselves arrive only in the stored, folded turn. A stream that connects mid-block gets the whole block in its first `live` frame. When the block is stored its `turn` frame is followed, in the same look, by an empty `live` frame, which removes the element: the server alone takes it away, so a turn from another door lands above the block and leaves it in place. A fresh attempt after a lost session starts from an empty block. | |
| 36 | - **The working line** (`waiting`, `workingLine` in `src/web/pages/talk.ts`): while a turn runs and is not writing words, one line says what it does now and how long the turn has run ("Reading src/a.ts… · turn 1m 05s"). After ten seconds with no new step it says what it waits on and since when ("Thinking · 1m 40s since the last step · turn 4m 05s"); "Thinking" only when the runner reports a thought, else "Working: waiting for the model". More of one thought is not a step. The last step's time is the forge's, not the stream's (the newest piece, or the newest stored turn), so a silence of minutes is counted whole over the streams that come and go, and a restart of the forge counts from the last stored step. The seconds count in the browser: no frame is sent for them, and no screen reader hears them. | |
| 37 | - **Finished steps** fold to one line as they end: one by its own words, a run that only read or only edited files as "Read 3 files" (each file once, thoughts aside), any other as "5 steps". | |
| 36 | 38 | - **The page:** one element, `<li id="live">`, last in the log before any queued message, `aria-hidden` so a screen reader hears the stored reply once. It never scrolls the page itself; the page's one follow rule does (see "Following" below). A lost stream removes it; the stream that comes back draws it again. |
| 37 | 39 | - **Who sees it:** only the conversation's owner: the stream finds the conversation by its owner, and another person naming it gets 404. |
| 38 | 40 | - **Secrets:** what leaves the block is redacted as the stored turn is (`redactHeld`: held values and credential shapes, which the stored turn now masks too), and the end of the text that could be the start of a held value is held back until the rest arrives, so a value cut across two pieces never shows in part; a word at the end that is, or could still become, a short held value waits for the letter that settles it, so nothing shows masked and then clear; the run of token characters being written (a credential shape is masked only once it is long enough) waits for the character after it, so the text grows a word at a time. |
| @@ -266,7 +268,7 @@ In the terminal, the Talk screen's pane prints the same lines ("Here:", "Lately: | ||
| 266 | 268 | |
| 267 | 269 | ## Display (#15734) |
| 268 | 270 | |
| 269 | Four preferences of the person's own, at the end of the conversation menu (⋯ → Display), one plain form that works without the script (`POST /talk/display`, signed in, same origin): spacing (comfortable or compact: the spacing scale only, never the type size), motion (as the system says, or reduced: Talk's arrivals, the head's slide and the shimmer stop whatever the system says), what Enter does (sends, or adds a line with Ctrl or Cmd+Enter sending) and whether a reply's steps start folded or open. They are the person's `user_setting` rows (`talk.density`, `talk.motion`, `talk.enter`, `talk.steps`, read by `talkDisplay` in `src/core/settings.ts`), applied by the server so the first paint is right; a value that is not one of a preference's own choices is never kept. No theme builder, no colours. The terminal honours the same steps choice: a conversation opened in `forge talk` shows a run of steps as one line ("3 steps") or each step, and `v` there flips the choice for both places, while `D` opens Talk display to set all four (docs/features/talk-display.md); spacing, motion and Enter are the page's own (the terminal has its own rows, no animation, and its `s` prompt always sends on Enter). | |
| 271 | Four preferences of the person's own, at the end of the conversation menu (⋯ → Display), one plain form that works without the script (`POST /talk/display`, signed in, same origin): spacing (comfortable or compact: the spacing scale only, never the type size), motion (as the system says, or reduced: Talk's arrivals, and the head's slide stop whatever the system says), what Enter does (sends, or adds a line with Ctrl or Cmd+Enter sending) and whether a reply's steps start folded or open. They are the person's `user_setting` rows (`talk.density`, `talk.motion`, `talk.enter`, `talk.steps`, read by `talkDisplay` in `src/core/settings.ts`), applied by the server so the first paint is right; a value that is not one of a preference's own choices is never kept. No theme builder, no colours. The terminal honours the same steps choice: a conversation opened in `forge talk` shows a run of steps as one line ("3 steps") or each step, and `v` there flips the choice for both places, while `D` opens Talk display to set all four (docs/features/talk-display.md); spacing, motion and Enter are the page's own (the terminal has its own rows, no animation, and its `s` prompt always sends on Enter). | |
| 270 | 272 | |
| 271 | 273 | **Motion.** One vocabulary: a thing arriving (a sent message, a step, a receipt, the follow control, a version chip) fades and rises 4 px over `--dur-3` (200 ms) with `--ease`, once; the live block's new paragraphs only fade, and the stored reply that takes its place does not move. Opacity and transform only, so nothing on screen shifts; none under `prefers-reduced-motion` or the person's reduced. Proof: `test/talk-display.test.ts`, `test/talk-page.test.ts`. |
| 272 | 274 |
src/crew/conversation_live.ts +13 −1
| @@ -49,6 +49,8 @@ const HELD_CHARS = MAX_TURN_CHARS + 1_000; | ||
| 49 | 49 | /** One forge's blocks being written and stream listeners, by conversation id. */ |
| 50 | 50 | interface Live { |
| 51 | 51 | readonly blocks: Map<string, Held>; |
| 52 | /** When a running answer last did something to see (`liveMoved`), by conversation id. */ | |
| 53 | readonly moved: Map<string, number>; | |
| 52 | 54 | readonly listeners: Map<string, Set<(change: LiveChange) => void>>; |
| 53 | 55 | } |
| 54 | 56 | |
| @@ -57,7 +59,7 @@ const forges = new WeakMap<Database, Live>(); | ||
| 57 | 59 | const liveOf = (db: Database): Live => { |
| 58 | 60 | let live = forges.get(db); |
| 59 | 61 | if (live === undefined) { |
| 60 | live = { blocks: new Map(), listeners: new Map() }; | |
| 62 | live = { blocks: new Map(), moved: new Map(), listeners: new Map() }; | |
| 61 | 63 | forges.set(db, live); |
| 62 | 64 | } |
| 63 | 65 | return live; |
| @@ -112,9 +114,18 @@ export function notify( | ||
| 112 | 114 | // the streams here, and the stream's slow look stays as the net. |
| 113 | 115 | onTurnAppended((db, conversationId) => notify(db, conversationId, "turn")); |
| 114 | 116 | |
| 117 | /** | |
| 118 | * When a running answer last did something to see: a call began or ended, words came or a thought | |
| 119 | * began. More of the same thought is not a step, and neither is an empty piece, which only | |
| 120 | * marks that a block begins. Undefined before the first; a stored turn says its own time. | |
| 121 | * Kept here and not by a stream, which is replaced every forty seconds: a silence is counted whole. | |
| 122 | */ | |
| 123 | export const liveMoved = (db: Database, conversationId: string): number | undefined => liveOf(db).moved.get(conversationId); | |
| 124 | ||
| 115 | 125 | /** A piece of the block being written (`AgentRun.onDelta`). */ |
| 116 | 126 | export function liveDelta(db: Database, conversationId: string, delta: Delta): void { |
| 117 | 127 | const held = heldOf(db, conversationId); |
| 128 | if (delta.kind === "thinking" ? !held.thinking : delta.kind === "tool" || delta.text !== "") liveOf(db).moved.set(conversationId, Date.now()); | |
| 118 | 129 | if (delta.kind === "tool") { |
| 119 | 130 | if (delta.state === "started") |
| 120 | 131 | held.tools.push({ name: delta.name, id: delta.id, call: "" }); |
| @@ -165,6 +176,7 @@ export function liveReset(db: Database, conversationId: string): void { | ||
| 165 | 176 | /** The answer ended, however it ended: nothing is being written. */ |
| 166 | 177 | export function liveEnd(db: Database, conversationId: string): void { |
| 167 | 178 | liveOf(db).blocks.delete(conversationId); |
| 179 | liveOf(db).moved.delete(conversationId); | |
| 168 | 180 | notify(db, conversationId, "turn"); |
| 169 | 181 | } |
| 170 | 182 |
src/web/pages/talk.ts +51 −20
| @@ -53,7 +53,7 @@ import { ASKING } from "../../crew/conversation_confirm.ts"; | ||
| 53 | 53 | import { INVERSES, readReceipt, type Receipt, UNDO_DRAFT } from "../../crew/receipt.ts"; |
| 54 | 54 | import { pastTime } from "../../core/fence.ts"; |
| 55 | 55 | import { turnRunning, type RedoHow } from "../../crew/conversation.ts"; |
| 56 | import { liveBlock, subscribe } from "../../crew/conversation_live.ts"; | |
| 56 | import { liveBlock, liveMoved, subscribe } from "../../crew/conversation_live.ts"; | |
| 57 | 57 | import { background } from "../../perf/jobs.ts"; |
| 58 | 58 | import type { Ctx } from "../../http/context.ts"; |
| 59 | 59 | import { json } from "../../http/respond.ts"; |
| @@ -259,8 +259,18 @@ const stepCard = (id: string, step: Step, at: string, set = ""): Html => | ||
| 259 | 259 | export const doneWord = (done: number, steps: number): string => |
| 260 | 260 | `${done === 1 ? "1 thing done" : `${done} things done`}${steps === 0 ? "" : `, ${steps === 1 ? "1 step" : `${steps} steps`}`}`; |
| 261 | 261 | |
| 262 | const stepsWord = (run: readonly Html[]): string => | |
| 263 | run.length === 1 ? (/<summary>([^<]*)</.exec(run[0]!.text)?.[1]?.trim() ?? "1 step") : `${run.length} steps`; | |
| 262 | /** | |
| 263 | * A run of steps in a few words: one by its own, "Read 3 files" when that is all it did (thoughts | |
| 264 | * between aside, each file once), else their count. `groupJs` in `talk_client.ts` is the same rule. | |
| 265 | */ | |
| 266 | const stepsWord = (run: readonly Html[]): string => { | |
| 267 | const labels = run.map((h) => /<summary>([^<]*)</.exec(h.text)?.[1]?.trim() ?? ""); | |
| 268 | if (run.length === 1) return labels[0] === "" ? "1 step" : labels[0]!; | |
| 269 | const did = labels.filter((l) => l !== "Thinking"); | |
| 270 | const files = new Set(did.map((l) => l.replace(/ \(\+\d+\)$/, ""))); | |
| 271 | const verb = ["Read", "Edited"].find((v) => did.length > 1 && files.size === did.length && did.every((l) => l.startsWith(`${v} `))); | |
| 272 | return verb === undefined ? `${run.length} steps` : `${verb} ${did.length} files`; | |
| 273 | }; | |
| 264 | 274 | |
| 265 | 275 | /** A thing done whose receipt offers Undo (`receiptCard`). */ |
| 266 | 276 | const undoableDone = (t: Html): boolean => /^<li [^>]*\bdata-done\b/.test(t.text.trimStart()) && t.text.includes(`action="${HERE}/undo/`); |
| @@ -1019,6 +1029,13 @@ export async function talkUndo(ctx: Ctx): Promise<Response> { | ||
| 1019 | 1029 | /** How long a running turn may show nothing new before its working line says what it waits on. */ |
| 1020 | 1030 | export const QUIET_SAY_MS = 10_000; |
| 1021 | 1031 | |
| 1032 | /** How long a running turn may have nothing to show before its line is drawn: between two steps, no blink. */ | |
| 1033 | const GAP_SAY_MS = 1_000; | |
| 1034 | ||
| 1035 | /** When the conversation's running turn began, or undefined with none. */ | |
| 1036 | const turnBegan = (db: Database, conversationId: string): string | undefined => | |
| 1037 | db.query<{ at: string }, [string]>("SELECT started_at AS at FROM conversation_run WHERE state = 'running' AND conversation_id = ?1 ORDER BY started_at DESC LIMIT 1").get(conversationId)?.at; | |
| 1038 | ||
| 1022 | 1039 | /** |
| 1023 | 1040 | * What a quiet running turn waits on, in words: the step running, its yes, the model thinking, or |
| 1024 | 1041 | * plainly working. The page counts the seconds beside it. |
| @@ -1027,7 +1044,16 @@ export function waitingOn(shown: { readonly tool: string; readonly thinking: boo | ||
| 1027 | 1044 | if (held) return "Waiting for your yes above the message box; the rest goes on"; |
| 1028 | 1045 | if (shown.tool !== "") return `Still on: ${shown.tool}`; |
| 1029 | 1046 | if (shown.thinking) return "Thinking"; |
| 1030 | return "Working: the model has not answered yet"; | |
| 1047 | return "Working: waiting for the model"; | |
| 1048 | } | |
| 1049 | ||
| 1050 | /** | |
| 1051 | * The one line of a running turn: what it does now, the time since its last step once that is quiet, | |
| 1052 | * and how long the turn has run. The times count in the browser (`live_time_client.ts`), and the line | |
| 1053 | * is inside the hidden live element, so a second passing sends nothing and is never read out. | |
| 1054 | */ | |
| 1055 | export function workingLine(what: string, o: { readonly since?: string | undefined; readonly began?: string | undefined }): Html { | |
| 1056 | return html`${what}${o.since === undefined ? null : html` · ${time(o.since, { count: "elapsed" })} since the last step`}${o.began === undefined ? null : html` · turn ${time(o.began, { count: "elapsed" })}`}`; | |
| 1031 | 1057 | } |
| 1032 | 1058 | |
| 1033 | 1059 | // GET /talk/stream?after=<turn id> — turns as they are written, ended with the turn. |
| @@ -1055,10 +1081,10 @@ export function talkStream(ctx: Ctx): Response { | ||
| 1055 | 1081 | // goes, so what is sent is always the latest. |
| 1056 | 1082 | const idle = JSON.stringify({ html: "", thinking: false, tool: "", waiting: "" }); |
| 1057 | 1083 | let liveSent = idle; |
| 1058 | // When what the turn shows last changed: past `QUIET_SAY_MS` with nothing new, the working line | |
| 1059 | // says what it waits on and counts the time, so a running turn never looks hung. | |
| 1060 | let shownKey = ""; | |
| 1061 | let changedAt = Date.now(); | |
| 1084 | // The newest stored turn is a step too: it holds over a restart of the forge, and for a runner | |
| 1085 | // that reports no pieces. | |
| 1086 | let storedAt = before.ok ? Date.parse(before.value.at(-1)?.createdAt ?? "") || 0 : 0; | |
| 1087 | const streamAt = Date.now(); | |
| 1062 | 1088 | let liveAt = Number.NEGATIVE_INFINITY; |
| 1063 | 1089 | let liveTimer: ReturnType<typeof setTimeout> | undefined; |
| 1064 | 1090 | let ended = false; |
| @@ -1076,18 +1102,22 @@ export function talkStream(ctx: Ctx): Response { | ||
| 1076 | 1102 | thinking: block?.thinking === true, |
| 1077 | 1103 | tool: block?.tool === undefined ? "" : runningStep(block.tool), |
| 1078 | 1104 | }; |
| 1079 | const shownNowKey = JSON.stringify(shownNow); | |
| 1080 | if (shownNowKey !== shownKey) { | |
| 1081 | shownKey = shownNowKey; | |
| 1082 | changedAt = Date.now(); | |
| 1083 | } | |
| 1084 | const quiet = clock.running(app, user.id, conversation.id) && Date.now() - changedAt >= QUIET_SAY_MS; | |
| 1085 | // The seconds count in the browser (the one clock, `live_time_client.ts`), from when it went | |
| 1086 | // quiet, so this frame is sent once, not each second. | |
| 1087 | const frame = { | |
| 1088 | ...shownNow, | |
| 1089 | waiting: quiet ? html`${waitingOn(shownNow, waitingConfirms(ctx, user).length > 0)} · ${time(new Date(changedAt).toISOString(), { count: "elapsed" })}`.text : "", | |
| 1090 | }; | |
| 1105 | // Words being written are their own line; anything else a running turn does has the working | |
| 1106 | // line, and past `QUIET_SAY_MS` with nothing new it says what is waited on and since when. | |
| 1107 | const running = clock.running(app, user.id, conversation.id); | |
| 1108 | const began = running ? turnBegan(app.db, conversation.id) : undefined; | |
| 1109 | const last = Math.max(liveMoved(app.db, conversation.id) ?? 0, storedAt, began === undefined ? 0 : Date.parse(began)) || streamAt; | |
| 1110 | const still = Date.now() - last; | |
| 1111 | const quiet = running && still >= QUIET_SAY_MS; | |
| 1112 | const doing = shownNow.tool !== "" ? shownNow.tool : shownNow.thinking ? "Thinking" : undefined; | |
| 1113 | const line = quiet | |
| 1114 | ? workingLine(waitingOn(shownNow, waitingConfirms(ctx, user).length > 0), { since: new Date(last).toISOString(), began }) | |
| 1115 | : running && doing !== undefined | |
| 1116 | ? workingLine(doing, { began }) | |
| 1117 | : running && block === undefined && still >= GAP_SAY_MS | |
| 1118 | ? workingLine(waitingOn(shownNow, false), { began }) | |
| 1119 | : undefined; | |
| 1120 | const frame = { ...shownNow, waiting: line === undefined ? "" : line.text }; | |
| 1091 | 1121 | const key = JSON.stringify(frame); |
| 1092 | 1122 | if (key === liveSent) return; |
| 1093 | 1123 | const wait = liveAt + LIVE_MS - clock.now(); |
| @@ -1125,6 +1155,7 @@ export function talkStream(ctx: Ctx): Response { | ||
| 1125 | 1155 | const drop = replaced?.["superseded"] === true ? String(replaced["confirm"] ?? "") : undefined; |
| 1126 | 1156 | emit("turn", { id: turn.id, role: turn.role, ...(drop === undefined ? {} : { drop }), html: inlineIcons(turnHtml(turn, waiting, undefined, undefined, works.get(turn.id), sent.get(turn.id), expired, undone, refs, voice, look, receiptLines(app.db, app.config.dataDir, user, [turn])).text), ...(held === undefined ? {} : { held: inlineIcons(held.text) }) }, turn.id); |
| 1127 | 1157 | cursor = turn.id; |
| 1158 | storedAt = Math.max(storedAt, Date.parse(turn.createdAt) || 0); | |
| 1128 | 1159 | } |
| 1129 | 1160 | // The page is told at once what the block holds after these turns, empty once it is |
| 1130 | 1161 | // stored: the server alone takes the live element away, so a turn from another door |
src/web/pages/talk_client.ts +12 −6
| @@ -208,10 +208,7 @@ body:has(.talk-page) .topbar { background: var(--bg); backdrop-filter: none; -we | ||
| 208 | 208 | .talk-fold > details > summary { position: relative; cursor: pointer; min-height: 2rem; display: inline-flex; align-items: center; gap: 6px; color: var(--muted-fg); } |
| 209 | 209 | @media (hover: hover) and (pointer: fine) { .talk-fold > details > summary:hover { color: var(--fg); } } |
| 210 | 210 | .talk-fold-list { list-style: none; margin: 0; margin-inline-start: 8px; padding: 0; padding-inline-start: 12px; border-inline-start: 2px solid var(--border); display: grid; gap: 2px; } |
| 211 | .talk-steps { margin: 4px 0 0; } | |
| 212 | .talk-live .talk-steps:last-child, .talk-status:not(:empty), .talk-stage[data-busy] .talk-stage-note, .talk-crew-working { background: linear-gradient(90deg, var(--muted-fg) 40%, var(--fg) 50%, var(--muted-fg) 60%) 0 0 / 300% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: talk-shine 2s linear infinite; } | |
| 213 | @keyframes talk-shine { from { background-position: 100% 0; } to { background-position: 0 0; } } | |
| 214 | @media (prefers-reduced-motion: reduce) { .talk-live .talk-steps:last-child, .talk-status:not(:empty), .talk-stage[data-busy] .talk-stage-note, .talk-crew-working { animation: none; color: var(--muted-fg); background: none; } } | |
| 211 | .talk-steps { margin: 4px 0 0; font-variant-numeric: tabular-nums; } | |
| 215 | 212 | .talk-confirms { display: grid; align-content: start; gap: 4px; padding-bottom: 8px; overflow: hidden; } |
| 216 | 213 | .talk-confirms[data-out] { padding-bottom: 0; } |
| 217 | 214 | .talk-confirms[hidden], .talk-confirms-count:empty { display: none; } |
| @@ -259,7 +256,7 @@ html:has(.talk-page) { scroll-padding-bottom: 8rem; } | ||
| 259 | 256 | .talk-dictate[aria-pressed="true"] { background: var(--accent); color: var(--bg); } |
| 260 | 257 | .talk-foot { margin: 6px 16px 0; } |
| 261 | 258 | .talk-status { margin: 4px 16px 0; min-height: 1.25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } |
| 262 | [data-answering] .talk-status { background: none; animation: none; color: transparent; } | |
| 259 | [data-answering] .talk-status { color: transparent; } | |
| 263 | 260 | .talk-error { margin: 6px 4px 0; color: var(--danger); } |
| 264 | 261 | .talk-error[hidden] { display: none; } |
| 265 | 262 | .talk-jump { position: absolute; bottom: calc(100% + 12px); left: 50%; transform: translateX(-50%); min-height: 2.75rem; border-radius: 999px; box-shadow: var(--shadow-2); gap: 6px; } |
| @@ -422,6 +419,14 @@ export const liveJs = ` | ||
| 422 | 419 | }; |
| 423 | 420 | `; |
| 424 | 421 | |
| 422 | /** A run of steps in a few words, from their labels: the rule `stepsWord` in `talk.ts` draws by. */ | |
| 423 | export const groupJs = `(ls) => { | |
| 424 | if (ls.length === 1) return ls[0]; | |
| 425 | const did = ls.filter((l) => l !== "Thinking"), files = new Set(did.map((l) => l.split(" (+")[0])); | |
| 426 | const verb = ["Read", "Edited"].find((v) => did.length > 1 && files.size === did.length && did.every((l) => l.startsWith(v + " "))); | |
| 427 | return verb ? verb + " " + did.length + " files" : ls.length + " steps"; | |
| 428 | }`; | |
| 429 | ||
| 425 | 430 | /** |
| 426 | 431 | * Runs after DOMContentLoaded (`pageScriptAsset`). Reads the page's own `data-talk-*`; sends with |
| 427 | 432 | * fetch, follows with EventSource. |
| @@ -594,6 +599,7 @@ if (root) { | ||
| 594 | 599 | }); |
| 595 | 600 | // A turn from the stream lands before any queued message (the live block is put back after it); |
| 596 | 601 | // a step joins the run of steps it follows, folded under one "3 steps". |
| 602 | const stepsSay = ${groupJs}; | |
| 597 | 603 | const place = (markup) => { |
| 598 | 604 | const t = document.createElement("template"); |
| 599 | 605 | t.innerHTML = markup.trim(); |
| @@ -628,7 +634,7 @@ if (root) { | ||
| 628 | 634 | if (done && !fold.hasAttribute("data-dones")) { fold.setAttribute("data-dones", ""); const ic = fold.querySelector(".talk-receipt-line > .ico"); if (ic) sum.prepend(ic.cloneNode(true)); } |
| 629 | 635 | sum.querySelector("[data-n]").textContent = done |
| 630 | 636 | ? (done === 1 ? "1 thing done" : done + " things done") + (steps ? ", " + (steps === 1 ? "1 step" : steps + " steps") : "") |
| 631 | : steps === 1 ? items[0].querySelector("summary").firstChild.textContent.trim() : steps + " steps"; | |
| 637 | : stepsSay(items.map((x) => x.querySelector("summary").firstChild.textContent.trim())); | |
| 632 | 638 | }; |
| 633 | 639 | // Earlier: the older page is fetched and put above what is read, oldest first, and the place being |
| 634 | 640 | // read stays where it is; without the script the link opens that page by itself. |
src/web/pages/talk_preview.ts +1 −1
| @@ -62,7 +62,7 @@ export interface PaneAsk { | ||
| 62 | 62 | readonly version?: number; |
| 63 | 63 | readonly wait?: string; |
| 64 | 64 | readonly idle?: string; |
| 65 | /** Something is under way (a preview starting, a first version being made): its words shimmer. */ | |
| 65 | /** Something is under way (a preview starting, a first version being made). */ | |
| 66 | 66 | readonly busy?: boolean; |
| 67 | 67 | /** Where the agent pointed the pane (`pane`), followed while it names this repository. */ |
| 68 | 68 | readonly steer?: PaneSteer; |
test/talk-autopilot.test.ts +6 −2
| @@ -18,7 +18,7 @@ import { createUser, type User } from "../src/core/users.ts"; | ||
| 18 | 18 | import { mintViaToken } from "../src/core/via_token.ts"; |
| 19 | 19 | import { AUTO_TURNS_MAX, carriedEnough, configureConversation, say, stopTurn, withHistory } from "../src/crew/conversation.ts"; |
| 20 | 20 | import { serve, type Servers } from "../src/http/server.ts"; |
| 21 | import { QUIET_SAY_MS, waitingOn } from "../src/web/pages/talk.ts"; | |
| 21 | import { QUIET_SAY_MS, waitingOn, workingLine } from "../src/web/pages/talk.ts"; | |
| 22 | 22 | import { CONVERSATION_BRIEF } from "../src/crew/conversation_brief.ts"; |
| 23 | 23 | import { ASKS_FIRST, NEEDS_CONFIRM } from "../src/http/mcp/shared.ts"; |
| 24 | 24 | import { quietLogs } from "./helpers/globals.ts"; |
| @@ -212,7 +212,11 @@ describe("a running turn never looks hung", () => { | ||
| 212 | 212 | expect(waitingOn({ tool: "Reading pull #12", thinking: false }, false)).toBe("Still on: Reading pull #12"); |
| 213 | 213 | expect(waitingOn({ tool: "", thinking: true }, false)).toBe("Thinking"); |
| 214 | 214 | expect(waitingOn({ tool: "", thinking: false }, true)).toBe("Waiting for your yes above the message box; the rest goes on"); |
| 215 | expect(waitingOn({ tool: "", thinking: false }, false)).toBe("Working: the model has not answered yet"); | |
| 215 | expect(waitingOn({ tool: "", thinking: false }, false)).toBe("Working: waiting for the model"); | |
| 216 | const line = workingLine("Thinking", { since: "2026-12-01T00:01:00.000Z", began: "2026-12-01T00:00:00.000Z" }).text; | |
| 217 | expect(line.replace(/<time[^>]*>[^<]*<\/time\s*>/g, "T")).toBe("Thinking · T since the last step · turn T"); | |
| 218 | expect(line.match(/data-count="elapsed"/g)?.length).toBe(2); | |
| 219 | expect(workingLine("Reading a.ts…", {}).text).toBe("Reading a.ts…"); | |
| 216 | 220 | }); |
| 217 | 221 | }); |
| 218 | 222 |
test/talk-live.test.ts +75 −2
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | * held for redaction, a stop mid-block, and the terminal's `talk --follow`. |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 10 | import { afterAll, beforeAll, describe, expect, setSystemTime, test } from "bun:test"; | |
| 11 | 11 | import { Database } from "bun:sqlite"; |
| 12 | 12 | import { chmodSync, readFileSync, writeFileSync } from "node:fs"; |
| 13 | 13 | import { mkdtemp, rm } from "node:fs/promises"; |
| @@ -25,7 +25,7 @@ import { | ||
| 25 | 25 | stopTurn, |
| 26 | 26 | type ConversationOptions, |
| 27 | 27 | } from "../src/crew/conversation.ts"; |
| 28 | import { liveBlock, liveDelta, liveEnd, liveSaid } from "../src/crew/conversation_live.ts"; | |
| 28 | import { liveBlock, liveDelta, liveEnd, liveMoved, liveSaid } from "../src/crew/conversation_live.ts"; | |
| 29 | 29 | import { appendTurn, setClaudeSession } from "../src/core/conversations.ts"; |
| 30 | 30 | import { sandboxPolicy } from "../src/crew/sandbox.ts"; |
| 31 | 31 | import { serve, type Servers } from "../src/http/server.ts"; |
| @@ -704,6 +704,79 @@ describe("a running step", () => { | ||
| 704 | 704 | }); |
| 705 | 705 | |
| 706 | 706 | describe("the block held", () => { |
| 707 | test("more of one thought is not a step, nor is an empty piece; a call and words are", () => { | |
| 708 | const made = createConversation(app.db, alice.id); | |
| 709 | if (!made.ok) throw new Error(made.error); | |
| 710 | const id = made.value.id, t0 = Date.parse("2026-12-01T00:00:00Z"); | |
| 711 | const at = (s: number, does: () => void): number | undefined => { | |
| 712 | setSystemTime(new Date(t0 + s * 1000)); | |
| 713 | does(); | |
| 714 | const moved = liveMoved(app.db, id); | |
| 715 | return moved === undefined ? undefined : (moved - t0) / 1000; | |
| 716 | }; | |
| 717 | try { | |
| 718 | expect(at(0, () => {})).toBeUndefined(); | |
| 719 | expect(at(5, () => liveDelta(app.db, id, { kind: "thinking", text: "a" }))).toBe(5); | |
| 720 | expect(at(100, () => liveDelta(app.db, id, { kind: "thinking", text: "b" }))).toBe(5); | |
| 721 | expect(at(110, () => liveDelta(app.db, id, { kind: "tool", name: "x", state: "started" }))).toBe(110); | |
| 722 | expect(at(120, () => liveDelta(app.db, id, { kind: "text", text: "so" }))).toBe(120); | |
| 723 | expect(at(130, () => liveDelta(app.db, id, { kind: "text", text: "" }))).toBe(120); | |
| 724 | expect(at(140, () => liveEnd(app.db, id))).toBeUndefined(); | |
| 725 | } finally { | |
| 726 | setSystemTime(); | |
| 727 | } | |
| 728 | }); | |
| 729 | ||
| 730 | test("a silence is counted whole: a stream opened 100 seconds into a thought says since when, not since it connected", async () => { | |
| 731 | const made = createConversation(app.db, alice.id); | |
| 732 | if (!made.ok) throw new Error(made.error); | |
| 733 | const id = made.value.id, was = clock.running, since = new Date(Date.now() - 100_000); | |
| 734 | clock.running = () => true; | |
| 735 | try { | |
| 736 | setSystemTime(since); | |
| 737 | liveDelta(app.db, id, { kind: "thinking", text: "hm" }); | |
| 738 | setSystemTime(); | |
| 739 | const s = await stream(`/talk/stream?c=${id}&after=`, alice); | |
| 740 | const said = String((await s.until((f) => live(f) && f.data["waiting"] !== "")).data["waiting"]); | |
| 741 | s.close(); | |
| 742 | expect(said).toStartWith("Thinking · <time"); | |
| 743 | expect(said).toContain(`datetime="${since.toISOString()}"`); | |
| 744 | expect(said).toContain("since the last step"); | |
| 745 | } finally { | |
| 746 | setSystemTime(); | |
| 747 | clock.running = was; | |
| 748 | liveEnd(app.db, id); | |
| 749 | } | |
| 750 | }); | |
| 751 | ||
| 752 | test("four minutes after a step, with no piece since, a new stream counts from the stored step and sends one frame", async () => { | |
| 753 | const made = createConversation(app.db, alice.id); | |
| 754 | if (!made.ok) throw new Error(made.error); | |
| 755 | const id = made.value.id, was = clock.running, since = new Date(Date.now() - 240_000); | |
| 756 | clock.running = () => true; | |
| 757 | try { | |
| 758 | setSystemTime(since); | |
| 759 | const step = appendTurn(app.db, alice.id, id, { role: "tool", text: 'read_file {"path":"a.ts"}' }); | |
| 760 | setSystemTime(); | |
| 761 | if (!step.ok) throw new Error(step.error); | |
| 762 | const s = await stream(`/talk/stream?c=${id}&after=${step.value.id}`, alice); | |
| 763 | const said = String((await s.until((f) => live(f) && f.data["waiting"] !== "")).data["waiting"]); | |
| 764 | // A change wakes the stream's look; the line is as it was, so nothing more is sent. | |
| 765 | liveDelta(app.db, id, { kind: "text", text: "" }); | |
| 766 | appendTurn(app.db, alice.id, id, { role: "tool", text: 'read_file {"path":"b.ts"}' }); | |
| 767 | await s.until((f) => f.event === "turn"); | |
| 768 | s.close(); | |
| 769 | expect(said).toStartWith("Working: waiting for the model · <time"); | |
| 770 | expect(said).toContain(`datetime="${since.toISOString()}"`); | |
| 771 | const before = s.frames.slice(0, s.frames.findIndex((f) => f.event === "turn")); | |
| 772 | expect(before.filter(live)).toHaveLength(1); | |
| 773 | } finally { | |
| 774 | setSystemTime(); | |
| 775 | clock.running = was; | |
| 776 | liveEnd(app.db, id); | |
| 777 | } | |
| 778 | }); | |
| 779 | ||
| 707 | 780 | test("of two calls of one tool, the one that ends is the one named by its id", () => { |
| 708 | 781 | const id = "c-two-calls"; |
| 709 | 782 | liveDelta(app.db, id, { kind: "tool", name: "mcp__forge__issue", state: "started", id: "a" }); |
test/talk-page.test.ts +24 −1
| @@ -300,6 +300,28 @@ describe("the page", () => { | ||
| 300 | 300 | expect(out).not.toMatch(/<details open/); |
| 301 | 301 | }); |
| 302 | 302 | |
| 303 | test("a run that only read files, or only edited them, says so; the page and its stream say the same", async () => { | |
| 304 | const { foldSteps, turnHtml } = await import("../src/web/pages/talk.ts"); | |
| 305 | const { groupJs } = await import("../src/web/pages/talk_client.ts"); | |
| 306 | const group = new Function(`return ${groupJs}`)() as (labels: string[]) => string; | |
| 307 | const read = (path: string) => `read_file {"repo":"a/b","path":"${path}"}`; | |
| 308 | const edit = (path: string) => `write_file {"repo":"a/b","path":"${path}","content":"x"}`; | |
| 309 | const thought = JSON.stringify({ thinking: "hm" }); | |
| 310 | const runs: [string[], string[], string][] = [ | |
| 311 | [[read("a.ts"), thought, read("b.ts"), read("c.ts")], ["Read a.ts", "Thinking", "Read b.ts", "Read c.ts"], "Read 3 files"], | |
| 312 | [[edit("a.ts"), edit("b.ts")], ["Edited a.ts (+1)", "Edited b.ts (+1)"], "Edited 2 files"], | |
| 313 | // The same file twice is not two files, and a mix is a count. | |
| 314 | [[read("a.ts"), read("a.ts")], ["Read a.ts", "Read a.ts"], "2 steps"], | |
| 315 | [[read("a.ts"), edit("a.ts")], ["Read a.ts", "Edited a.ts (+1)"], "2 steps"], | |
| 316 | [[read("a.ts")], ["Read a.ts"], "Read a.ts"], | |
| 317 | ]; | |
| 318 | for (const [texts, labels, says] of runs) { | |
| 319 | const out = foldSteps(false, texts.map((text, i) => turnHtml({ id: String(i + 1), role: "tool", text, createdAt: "2026-01-01T00:00:00Z" } as any, new Set()))).map((h) => h.text).join(""); | |
| 320 | expect(out).toContain(`<span data-n>${says}</span>`); | |
| 321 | expect(group(labels)).toBe(says); | |
| 322 | } | |
| 323 | }); | |
| 324 | ||
| 303 | 325 | test("a reply ends in one line: what it opened folds behind its count, each file by its path in its repository", async () => { |
| 304 | 326 | const { turnHtml } = await import("../src/web/pages/talk.ts"); |
| 305 | 327 | const work = { steps: "read 3 files", links: ["a.ts", "src/b.ts", "README.md"].map((p) => ({ href: `/erin/site/blob/main/${p}`, label: `erin/site/${p}` })) }; |
| @@ -348,7 +370,8 @@ describe("the page", () => { | ||
| 348 | 370 | for (const a of anim) expect(a).not.toMatch(/(height|width|margin|padding|top|bottom)\s*:/); |
| 349 | 371 | expect(talkCss).toContain("@media (prefers-reduced-motion: no-preference) {"); |
| 350 | 372 | expect(talkCss).toContain(".talk[data-motion=reduced] :is(*, ::before, ::after) { animation: none !important; transition: none !important; }"); |
| 351 | // Every arrival takes the motion tokens; only the running line's shimmer loops, and it is ambient. | |
| 373 | // Every arrival takes the motion tokens, and nothing on the page shimmers. | |
| 374 | expect(talkCss).not.toContain("talk-shine"); | |
| 352 | 375 | for (const [, v] of talkCss.matchAll(/animation: ([^;}]+)/g)) expect(v!.includes("var(--dur") || v!.includes("infinite") || v!.startsWith("none")).toBe(true); |
| 353 | 376 | }); |
| 354 | 377 |
test/talk-steps.test.ts +1 −1
| @@ -168,7 +168,7 @@ describe("a repository the person can read", () => { | ||
| 168 | 168 | expect(waiting).toContain("The files it starts from"); |
| 169 | 169 | expect(waiting).toContain('class="explorer talk-code-tree"'); |
| 170 | 170 | expect(waiting).not.toContain("data-busy"); |
| 171 | // While a first version is being made, its words shimmer: only what is under way does. | |
| 171 | // While a first version is being made, the stage says it is busy: only what is under way does. | |
| 172 | 172 | const making = (await talkPane(ctx, user, "erin/site", works, "preview", apps(undefined, {}), { build, idle: "Making the first version.", busy: true })).html.text; |
| 173 | 173 | expect(making).toContain("data-stage data-busy"); |
| 174 | 174 | const before = await talkPane(ctx, user, "erin/site", works, "code", apps(undefined, {}), { build }); |
new above
offline