From 4c6dab7db08dae6c51581c60f8d77e1090316ae1 Mon Sep 17 00:00:00 2001 From: x Date: Wed, 25 Nov 2026 22:58:47 -0500 Subject: [PATCH 1/2] feat(web): a running turn grows one summary row above the status line A running turn used to read as the status line alone, so after ten minutes nothing showed it had been busy. The newest held reply now stays in the entries without a row of its own; it splits the turn, so the steps before it close into one summary row whose counts climb with each update, and the steps since it fold into the status line, which still carries the only reply text. The status line also stops stuttering: each new label stays up at least 1.5s (a streaming thought grows through on its first deadline, and a new thread shows its own label at once), a tool that ends between beats hands the line back to the latest reply instead of the thinking word, and the shimmer is phased to the clock so swapping the line's element never starts a second sweep right after one. Co-Authored-By: Claude Opus 5.5 --- .fork/customizations.yaml | 55 +++++++++++-------- .../components/chat/MessagesTimeline.logic.ts | 36 ++++++++---- apps/web/src/custom/ForkLiveStatusLine.tsx | 50 ++++++++++++++++- .../web/src/custom/forkWorkingRowLast.test.ts | 13 +++-- apps/web/src/custom/forkWorkingRowLast.ts | 10 +++- apps/web/src/theme.custom.css | 3 + 6 files changed, 125 insertions(+), 42 deletions(-) diff --git a/.fork/customizations.yaml b/.fork/customizations.yaml index 03e0ea209ff07..ab11c5263bb29 100644 --- a/.fork/customizations.yaml +++ b/.fork/customizations.yaml @@ -6586,6 +6586,13 @@ fork-quiet-live-turn), the running tool, and the thinking word. A new tool or thought takes the line at once; otherwise it turns every 4s, skipping voices with nothing to say, and the word changes each lap. A + tool that ends between beats hands the line back to the thought, not on + to the word, and each new label stays up at least 1.5s (a thought still + streaming passes through), so a burst of reply, tool and settle never + flickers three texts through the line in a few frames. The line swaps + a div for a button when a group appears, which remounts its shimmer, so + each mount is phased to the clock (--fork-shimmer-phase) and a change + never starts a second sweep right after one. A provider startup or "Waiting on N subagents" holds the line alone and stops the clock. The thinking word comes from @t3tools/shared/forkThinkingWords: the seed is what last landed (the row @@ -6629,33 +6636,37 @@ - id: fork-quiet-live-turn intent: > - A running turn reads as one status line in every tool-call mode, the way - Zen reads. Outside Zen upstream streams each reply as it lands, so a - turn grew a column of command, reply, command rows that the turn fold - swallowed into "Worked for …" the moment it ended. The fork holds a - running turn's replies (Zen's rule: everything after the response - boundary, except a revealed message, a steer's answer and a final-answer - reply) until the turn ends, so its steps join one stretch that folds into - the status line (fork-working-row-last), and the line reads Zen's - preview of them. MessagesTimeline opts in with forkHoldLiveReplies, - except while Find is open, which searches reply text, and the guest share - page opts out (forkStreamLiveReplies), so a guest still watches replies - stream as upstream shows them. While the turn waits on the user (an - approval or a question), the latest held reply shows, since it usually - explains the request (forkShowLatestHeldReply); unlike Zen. The hold runs - after settleSupersededReasoning, so a thought followed only by a held - reply still reads settled. Upstream's logic - tests derive without the flag and keep upstream's shapes. The guard runs - one fixture through Zen and through the hold and requires the same - replies, so a sync that adds a Zen exemption fails it. The no3y iOS app - is unchanged. + A running turn reads calmly in every tool-call mode: one summary row + that grows as the turn goes, then the status line. Outside Zen upstream + streams each reply as it lands, so a turn grew a column of command, + reply, command rows that the turn fold swallowed into "Worked for …" the + moment it ended. The fork holds a running turn's replies (Zen's rule: + everything after the response boundary, except a revealed message, a + steer's answer and a final-answer reply) until the turn ends, except the + newest, which stays in the entries but draws no row + (deriveMessagesTimelineRows skips it). It still splits the turn, so the + steps before it close into one summary row whose counts climb with each + update, and the steps since it fold into the status line + (fork-working-row-last), which reads Zen's preview of it. Only the status + line ever carries the agent's words. MessagesTimeline opts in with + forkHoldLiveReplies, except while Find is open, which searches reply + text, and the guest share page opts out (forkStreamLiveReplies), so a + guest still watches replies stream as upstream shows them. While the turn + waits on the user (an approval or a question), the newest reply shows, + since it usually explains the request (forkShowLatestHeldReply); unlike + Zen. The hold runs after settleSupersededReasoning, so a thought followed + only by a held reply still reads settled. Upstream's logic tests derive + without the flag and keep upstream's shapes. The guard runs one fixture + through Zen and through the hold and requires the same replies, so a sync + that adds a Zen exemption fails it. The no3y iOS app is unchanged. tier: 3 files: - apps/web/src/__fork_guards__/forkQuietLiveTurn.test.ts shadows: [] watch: - # Fenced: the forkHoldLiveReplies input, forkHeldLiveReplyIds and the - # filter in timelineRowEntries after the visibility filters. + # Fenced: the forkHoldLiveReplies input, forkLiveReplyIds, the filter in + # timelineRowEntries after the visibility filters, and the skipped row + # for the newest reply in deriveMessagesTimelineRows. - apps/web/src/components/chat/MessagesTimeline.logic.ts # Fenced: passes forkHoldLiveReplies, the forkStreamLiveReplies prop, and # reads liveAnswerPreview in every mode (upstream gates it to Zen). diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.ts b/apps/web/src/components/chat/MessagesTimeline.logic.ts index 6659ed75f5f65..47755456a2fe6 100644 --- a/apps/web/src/components/chat/MessagesTimeline.logic.ts +++ b/apps/web/src/components/chat/MessagesTimeline.logic.ts @@ -1520,9 +1520,9 @@ export function liveAnswerPreview(entries: ReadonlyArray): string } /* fork:begin fork-quiet-live-turn — see .fork/customizations.yaml#fork-quiet-live-turn - The replies Zen holds back while answering, narrowed to the run still going; + The replies Zen holds back while answering, narrowed to the run still going, in order; a guard (forkQuietLiveTurn) pins it to Zen's rule. */ -function forkHeldLiveReplyIds( +function forkLiveReplyIds( input: Pick< MessagesTimelineRowsInput, | "timelineEntries" @@ -1532,13 +1532,13 @@ function forkHeldLiveReplyIds( | "revealedMessageId" | "forkShowLatestHeldReply" >, -): ReadonlySet { - const held = new Set(); +): ReadonlyArray { + const replies: string[] = []; const answeringRunId = input.isWorking && input.latestRun?.turnEnded !== true ? deriveUnsettledRunId(input.latestRun ?? null, input.runningRunId ?? null) : null; - if (answeringRunId === null) return held; + if (answeringRunId === null) return replies; const entries = input.timelineEntries; const steerAnswerIds = deriveInFlightSteerAnswerIds(entries); const retainedReplyIds = retainedAssistantReplyEntryIds(entries); @@ -1552,12 +1552,10 @@ function forkHeldLiveReplyIds( !steerAnswerIds.has(entry.message.id) && !retainedReplyIds.has(entry.id) ) { - held.add(entry.id); + replies.push(entry.id); } } - // While the turn waits on the user, the reply that led to the request explains it. - if (input.forkShowLatestHeldReply === true) held.delete([...held].at(-1) ?? ""); - return held; + return replies; } /* fork:end fork-quiet-live-turn */ @@ -1643,9 +1641,13 @@ function timelineRowEntries( Zen's rule in every mode: a running turn's replies wait for it to end; the status line reads them. Held after settling, so a thought followed only by a held reply still reads settled. */ const settled = settleSupersededReasoning(shown); - const held = input.forkHoldLiveReplies === true ? forkHeldLiveReplyIds(input) : null; + // The newest stays in the entries: deriveMessagesTimelineRows draws no row for it, but it + // splits the turn, so the steps before it close into one summary row that grows each update. + const held = new Set( + input.forkHoldLiveReplies === true ? forkLiveReplyIds(input).slice(0, -1) : [], + ); return withoutSubagentDelegationRows( - held !== null && held.size > 0 ? settled.filter((entry) => !held.has(entry.id)) : settled, + held.size > 0 ? settled.filter((entry) => !held.has(entry.id)) : settled, ); /* fork:end fork-quiet-live-turn */ } @@ -1708,7 +1710,7 @@ export function deriveMessagesTimelineRows( hideQuietBotWakes?: boolean; /* fork:end fork-bots */ /* fork:begin fork-quiet-live-turn — see .fork/customizations.yaml#fork-quiet-live-turn */ - /** Outside Zen, a running turn's replies stay out of the rows until it ends, as Zen's do. */ + /** Outside Zen, a running turn's replies stay out of the rows until it ends, as Zen's do; the newest still splits its steps. */ forkHoldLiveReplies?: boolean; /** While the turn waits on the user, the latest held reply shows. */ forkShowLatestHeldReply?: boolean; @@ -1717,6 +1719,13 @@ export function deriveMessagesTimelineRows( resolve: MessageResolver = m, ): MessagesTimelineRow[] { const timelineEntries = timelineRowEntries(input); + /* fork:begin fork-quiet-live-turn — see .fork/customizations.yaml#fork-quiet-live-turn + While the turn waits on the user, the newest reply shows, since it explains the request. */ + const forkUnshownReplyId = + input.forkHoldLiveReplies === true && input.forkShowLatestHeldReply !== true + ? (forkLiveReplyIds(input).at(-1) ?? null) + : null; + /* fork:end fork-quiet-live-turn */ const embeddedResultRunIds = new Set(); for (const entry of timelineEntries) { if ((entry.kind === "html-render" || entry.kind === "mcp-app") && entry.runId !== null) { @@ -2374,6 +2383,9 @@ export function deriveMessagesTimelineRows( continue; } + /* fork:begin fork-quiet-live-turn — see .fork/customizations.yaml#fork-quiet-live-turn */ + if (timelineEntry.id === forkUnshownReplyId) continue; + /* fork:end fork-quiet-live-turn */ const compactionRunId = timelineEntry.message.runId; const compactionRun = compactionRunId !== null && isCompactionCommandMessage(timelineEntry.message); diff --git a/apps/web/src/custom/ForkLiveStatusLine.tsx b/apps/web/src/custom/ForkLiveStatusLine.tsx index c78fc3ae506dc..65b4adf26fdf4 100644 --- a/apps/web/src/custom/ForkLiveStatusLine.tsx +++ b/apps/web/src/custom/ForkLiveStatusLine.tsx @@ -23,6 +23,48 @@ import { } from "./forkWorkingRowLast"; const BEAT_MS = 4000; +const DWELL_MS = 1500; +/** The shimmer's cycle; theme.custom.css keeps upstream's 2.2s. */ +const SHIMMER_CYCLE_MS = 2200; + +/** + * The line swaps a div for a button when a group appears, which remounts the shimmer and + * would start a sweep at once. Phasing each mount to the clock keeps the sweeps 2.2s apart. + */ +function shimmerLineRef(element: HTMLSpanElement | null) { + element?.style.setProperty( + "--fork-shimmer-phase", + `${-(performance.now() % SHIMMER_CYCLE_MS)}ms`, + ); + return observeVisibleAnimation(element); +} + +/** + * Each new label stays up for DWELL_MS, so a burst of arrivals never flickers through the line. + * A streaming thought only grows, so it passes through on its first deadline. The list reuses + * this line across threads, so a new thread shows its own label at once. + */ +function useDwelledLabel(label: string, thought: boolean, thread: string): string { + const [shown, setShown] = useState({ label, thought, thread, dwelling: true, arrival: 0 }); + if (label !== shown.label || thread !== shown.thread) { + if (thread === shown.thread && thought && shown.thought && label.startsWith(shown.label)) { + setShown({ ...shown, label }); + } else if (!shown.dwelling || thread !== shown.thread) { + setShown({ label, thought, thread, dwelling: true, arrival: shown.arrival + 1 }); + } + } + const { dwelling, arrival } = shown; + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- a wall-clock dwell, started by each new label + useEffect(() => { + if (!dwelling) return; + const id = window.setTimeout( + () => setShown((s) => (s.arrival === arrival ? { ...s, dwelling: false } : s)), + DWELL_MS, + ); + return () => window.clearTimeout(id); + }, [dwelling, arrival]); + return shown.label; +} /** The rotation's state; forkWorkingRowLast holds the rules, this hook only the clock. */ function useStatusLineState(voices: ForkStatusLineVoices) { @@ -62,7 +104,11 @@ export function ForkLiveStatusLine({ const groupId = live?.groupId; const voices = forkStatusLineVoices(live, use(TimelineRowActivityCtx), ctx.workspaceRoot, m); const rotation = useStatusLineState(voices); - const label = forkStatusLineText(voices, rotation, row.forkWordSeed); + const label = useDwelledLabel( + forkStatusLineText(voices, rotation, row.forkWordSeed), + voices.pinned === null && rotation.voice === "thought", + ctx.routeThreadKey, + ); const text = ( <> {label} @@ -73,7 +119,7 @@ export function ForkLiveStatusLine({ <> diff --git a/apps/web/src/custom/forkWorkingRowLast.test.ts b/apps/web/src/custom/forkWorkingRowLast.test.ts index 7b2f80be57a05..24cf2610bccd1 100644 --- a/apps/web/src/custom/forkWorkingRowLast.test.ts +++ b/apps/web/src/custom/forkWorkingRowLast.test.ts @@ -319,11 +319,14 @@ describe("the status line rotation", () => { expect(forkStatusLineReconcile(beat, voices(null, "old")).voice).toBe("word"); }); - it("gives a voice that takes over between beats a full beat", () => { + it("hands a tool that settles between beats back to the thought, with a full beat", () => { const line = forkStatusLineStart(voices("vp", "old")); const settled = forkStatusLineReconcile(line, voices(null, "old")); - expect(settled.voice).toBe("word"); + expect(settled.voice).toBe("thought"); expect(settled.arrival).toBe(line.arrival + 1); + expect( + forkStatusLineReconcile(forkStatusLineStart(voices("vp", null)), voices(null, null)).voice, + ).toBe("word"); }); it("treats a thought that is still streaming as the same arrival", () => { @@ -386,8 +389,10 @@ describe("a running turn holds its replies (fork-quiet-live-turn)", () => { command("second", 5, "inProgress"), ]; - it("folds steps and replies alike into the one status line", () => { - expect(kinds(rowsFor(turn, true))).toEqual(["working"]); + it("closes the steps before the newest reply into one row and folds the rest into the line", () => { + expect(kinds(rowsFor(turn, true))).toEqual(["work-toggle", "working"]); + expect(kinds(rowsFor(turn.slice(0, 3), true))).toEqual(["work-toggle", "working"]); + expect(kinds(rowsFor(turn.slice(0, 2), true))).toEqual(["working"]); }); it("settles a thought whose only follower is a held reply", () => { diff --git a/apps/web/src/custom/forkWorkingRowLast.ts b/apps/web/src/custom/forkWorkingRowLast.ts index 9d642502f6903..001c57256dd7c 100644 --- a/apps/web/src/custom/forkWorkingRowLast.ts +++ b/apps/web/src/custom/forkWorkingRowLast.ts @@ -200,7 +200,8 @@ export function forkStatusLineStart(voices: ForkStatusLineVoices): ForkStatusLin /** * Brings the line up to date in render. A new tool or thought takes it at once; the voice - * showing going quiet hands over. Either starts a fresh beat. Returns `line` if unchanged. + * showing going quiet hands back to the thought, else moves on. Either starts a fresh beat. + * Returns `line` if unchanged. */ export function forkStatusLineReconcile( line: ForkStatusLineState, @@ -219,7 +220,12 @@ export function forkStatusLineReconcile( : null; if (arrived !== null) return { ...seen, voice: arrived, arrival: line.arrival + 1 }; if (speaks(seen, seen.voice)) return seen; - return { ...forkStatusLineAdvance(seen), arrival: line.arrival + 1 }; + // A tool that ends between beats returns the line to the update it was part of. + const next = + seen.voice !== "thought" && speaks(seen, "thought") + ? { ...seen, voice: "thought" as const } + : forkStatusLineAdvance(seen); + return { ...next, arrival: line.arrival + 1 }; } /** Whether the line needs a beat: nothing pins it and it has more than the word to say. */ diff --git a/apps/web/src/theme.custom.css b/apps/web/src/theme.custom.css index 52fbcad1f6d00..add619b707caf 100644 --- a/apps/web/src/theme.custom.css +++ b/apps/web/src/theme.custom.css @@ -3890,13 +3890,16 @@ } } @media (prefers-reduced-motion: no-preference) and (forced-colors: none) { + /* ForkLiveStatusLine phases each mount to the clock, so a remount never restarts a sweep. */ :root[data-fork="noahhendrickson-t3code"] [data-fork-status-line] .live-activity-focus { animation-name: fork-status-line-flash; animation-timing-function: steps(23); + animation-delay: var(--fork-shimmer-phase, 0ms); } :root[data-fork="noahhendrickson-t3code"] [data-fork-status-line] .live-activity-focus-counter { animation-name: fork-status-line-flash-counter; animation-timing-function: steps(23); + animation-delay: var(--fork-shimmer-phase, 0ms); } } /* fork:end fork-working-row-last */ From 0e66203c7535c79ee9cb98ae6bdc8a8d120ca9b2 Mon Sep 17 00:00:00 2001 From: x Date: Wed, 25 Nov 2026 23:18:09 -0500 Subject: [PATCH 2/2] fix(web): an opened status line stays open across updates Each newest reply moved the live group's first step, so its group id changed at every update and a status line the user had opened closed. The live group is now named for the run while replies are held, as the whole turn was before. From review: the held replies are worked out once per derive; the dwell rules move into pure functions beside the rotation's, with a test; the status line is keyed by thread at its render site instead of threading the key into the dwell; the shimmer phase reads the animation's own duration. Co-Authored-By: Claude Opus 5.5 --- .fork/customizations.yaml | 23 ++++++--- .../components/chat/MessagesTimeline.logic.ts | 36 +++++++------ .../components/chat/TimelineWorkGroupRows.tsx | 3 ++ apps/web/src/custom/ForkLiveStatusLine.tsx | 46 ++++++++--------- .../web/src/custom/forkWorkingRowLast.test.ts | 50 ++++++++++++++++++- apps/web/src/custom/forkWorkingRowLast.ts | 36 +++++++++++++ 6 files changed, 143 insertions(+), 51 deletions(-) diff --git a/.fork/customizations.yaml b/.fork/customizations.yaml index 5cc96e8cc9049..20253cb853176 100644 --- a/.fork/customizations.yaml +++ b/.fork/customizations.yaml @@ -6588,11 +6588,14 @@ skipping voices with nothing to say, and the word changes each lap. A tool that ends between beats hands the line back to the thought, not on to the word, and each new label stays up at least 1.5s (a thought still - streaming passes through), so a burst of reply, tool and settle never - flickers three texts through the line in a few frames. The line swaps - a div for a button when a group appears, which remounts its shimmer, so - each mount is phased to the clock (--fork-shimmer-phase) and a change - never starts a second sweep right after one. A + streaming grows through on its first deadline), so a burst of reply, + tool and settle never flickers three texts through the line in a few + frames; the dwell rules are pure functions beside the rotation's. The + list reuses the line across threads, so WorkingTimelineRow keys it by + thread. The line swaps a div for a button when a group appears, which + remounts its shimmer, so each mount is phased to the clock by the + animation's own duration (--fork-shimmer-phase) and a change never + starts a second sweep right after one. A provider startup or "Waiting on N subagents" holds the line alone and stops the clock. The thinking word comes from @t3tools/shared/forkThinkingWords: the seed is what last landed (the row @@ -6648,7 +6651,10 @@ steps before it close into one summary row whose counts climb with each update, and the steps since it fold into the status line (fork-working-row-last), which reads Zen's preview of it. Only the status - line ever carries the agent's words. MessagesTimeline opts in with + line ever carries the agent's words. Each split moves the live group's + first step, so the live group is named for the run, and a status line + the user opened stays open across updates, as it did when the whole turn + was one stretch. The held replies are worked out once per derive. MessagesTimeline opts in with forkHoldLiveReplies, except while Find is open, which searches reply text, and the guest share page opts out (forkStreamLiveReplies), so a guest still watches replies stream as upstream shows them. While the turn @@ -6665,8 +6671,9 @@ shadows: [] watch: # Fenced: the forkHoldLiveReplies input, forkLiveReplyIds, the filter in - # timelineRowEntries after the visibility filters, and the skipped row - # for the newest reply in deriveMessagesTimelineRows. + # timelineRowEntries after the visibility filters (and its + # forkLiveReplies parameter), the skipped row for the newest reply in + # deriveMessagesTimelineRows, and the live group's run-named id. - apps/web/src/components/chat/MessagesTimeline.logic.ts # Fenced: passes forkHoldLiveReplies, the forkStreamLiveReplies prop, and # reads liveAnswerPreview in every mode (upstream gates it to Zen). diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.ts b/apps/web/src/components/chat/MessagesTimeline.logic.ts index 47755456a2fe6..43a24ad28c3b2 100644 --- a/apps/web/src/components/chat/MessagesTimeline.logic.ts +++ b/apps/web/src/components/chat/MessagesTimeline.logic.ts @@ -1525,12 +1525,7 @@ export function liveAnswerPreview(entries: ReadonlyArray): string function forkLiveReplyIds( input: Pick< MessagesTimelineRowsInput, - | "timelineEntries" - | "isWorking" - | "latestRun" - | "runningRunId" - | "revealedMessageId" - | "forkShowLatestHeldReply" + "timelineEntries" | "isWorking" | "latestRun" | "runningRunId" | "revealedMessageId" >, ): ReadonlyArray { const replies: string[] = []; @@ -1587,9 +1582,13 @@ function timelineRowEntries( /* fork:end fork-bots */ /* fork:begin fork-quiet-live-turn — see .fork/customizations.yaml#fork-quiet-live-turn */ | "forkHoldLiveReplies" - | "forkShowLatestHeldReply" /* fork:end fork-quiet-live-turn */ >, + /* fork:begin fork-quiet-live-turn — see .fork/customizations.yaml#fork-quiet-live-turn */ + forkLiveReplies: ReadonlyArray = input.forkHoldLiveReplies === true + ? forkLiveReplyIds(input) + : [], + /* fork:end fork-quiet-live-turn */ ) { const visibility = input.toolCallVisibility ?? "showAll"; const entries = input.timelineEntries; @@ -1643,9 +1642,7 @@ function timelineRowEntries( const settled = settleSupersededReasoning(shown); // The newest stays in the entries: deriveMessagesTimelineRows draws no row for it, but it // splits the turn, so the steps before it close into one summary row that grows each update. - const held = new Set( - input.forkHoldLiveReplies === true ? forkLiveReplyIds(input).slice(0, -1) : [], - ); + const held = new Set(forkLiveReplies.slice(0, -1)); return withoutSubagentDelegationRows( held.size > 0 ? settled.filter((entry) => !held.has(entry.id)) : settled, ); @@ -1718,13 +1715,13 @@ export function deriveMessagesTimelineRows( }, resolve: MessageResolver = m, ): MessagesTimelineRow[] { - const timelineEntries = timelineRowEntries(input); /* fork:begin fork-quiet-live-turn — see .fork/customizations.yaml#fork-quiet-live-turn - While the turn waits on the user, the newest reply shows, since it explains the request. */ + Upstream: timelineRowEntries(input). While the turn waits on the user, the newest reply + shows, since it explains the request. */ + const forkLiveReplies = input.forkHoldLiveReplies === true ? forkLiveReplyIds(input) : []; + const timelineEntries = timelineRowEntries(input, forkLiveReplies); const forkUnshownReplyId = - input.forkHoldLiveReplies === true && input.forkShowLatestHeldReply !== true - ? (forkLiveReplyIds(input).at(-1) ?? null) - : null; + input.forkShowLatestHeldReply === true ? null : (forkLiveReplies.at(-1) ?? null); /* fork:end fork-quiet-live-turn */ const embeddedResultRunIds = new Set(); for (const entry of timelineEntries) { @@ -1887,7 +1884,14 @@ export function deriveMessagesTimelineRows( const activeWorkRow = activeWorkAnchor && latestVisibleToolEntry && !latestToolFailed ? (() => { - const groupId = workGroupId(activeWorkAnchor.id); + /* fork:begin fork-quiet-live-turn — see .fork/customizations.yaml#fork-quiet-live-turn + Upstream: workGroupId(activeWorkAnchor.id). Each newest reply moves the live + group's first step, so the run names it and an opened status line stays open. */ + const groupId = + input.forkHoldLiveReplies === true && unsettledRunId !== null + ? workGroupId(`fork-live:${unsettledRunId}`) + : workGroupId(activeWorkAnchor.id); + /* fork:end fork-quiet-live-turn */ return { kind: "work-live" as const, id: latestToolKeepsActivityLive diff --git a/apps/web/src/components/chat/TimelineWorkGroupRows.tsx b/apps/web/src/components/chat/TimelineWorkGroupRows.tsx index 6c55af41303a8..bde3cc349ac65 100644 --- a/apps/web/src/components/chat/TimelineWorkGroupRows.tsx +++ b/apps/web/src/components/chat/TimelineWorkGroupRows.tsx @@ -380,9 +380,12 @@ export function WorkingTimelineRow({ row }: { row: Extract : null} trailing={ diff --git a/apps/web/src/custom/ForkLiveStatusLine.tsx b/apps/web/src/custom/ForkLiveStatusLine.tsx index 65b4adf26fdf4..be01ad68d004a 100644 --- a/apps/web/src/custom/ForkLiveStatusLine.tsx +++ b/apps/web/src/custom/ForkLiveStatusLine.tsx @@ -13,6 +13,9 @@ import { ForkLiveTaskList } from "./ForkLiveTaskList"; import { ForkLiveTasksCtx } from "./forkLiveTasks"; import { forkStatusLineAdvance, + forkStatusLineDwellEnd, + forkStatusLineDwellReconcile, + forkStatusLineDwellStart, forkStatusLineReconcile, forkStatusLineRotates, forkStatusLineStart, @@ -24,46 +27,38 @@ import { const BEAT_MS = 4000; const DWELL_MS = 1500; -/** The shimmer's cycle; theme.custom.css keeps upstream's 2.2s. */ -const SHIMMER_CYCLE_MS = 2200; /** * The line swaps a div for a button when a group appears, which remounts the shimmer and - * would start a sweep at once. Phasing each mount to the clock keeps the sweeps 2.2s apart. + * would start a sweep at once. Phasing each mount to the clock keeps the sweeps a cycle apart. */ function shimmerLineRef(element: HTMLSpanElement | null) { - element?.style.setProperty( - "--fork-shimmer-phase", - `${-(performance.now() % SHIMMER_CYCLE_MS)}ms`, - ); + const shimmer = element?.querySelector(".live-activity-focus"); + const cycleMs = shimmer + ? Number.parseFloat(getComputedStyle(shimmer).animationDuration) * 1000 + : 0; + if (element && cycleMs > 0) { + element.style.setProperty("--fork-shimmer-phase", `${-(performance.now() % cycleMs)}ms`); + } return observeVisibleAnimation(element); } -/** - * Each new label stays up for DWELL_MS, so a burst of arrivals never flickers through the line. - * A streaming thought only grows, so it passes through on its first deadline. The list reuses - * this line across threads, so a new thread shows its own label at once. - */ -function useDwelledLabel(label: string, thought: boolean, thread: string): string { - const [shown, setShown] = useState({ label, thought, thread, dwelling: true, arrival: 0 }); - if (label !== shown.label || thread !== shown.thread) { - if (thread === shown.thread && thought && shown.thought && label.startsWith(shown.label)) { - setShown({ ...shown, label }); - } else if (!shown.dwelling || thread !== shown.thread) { - setShown({ label, thought, thread, dwelling: true, arrival: shown.arrival + 1 }); - } - } - const { dwelling, arrival } = shown; - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- a wall-clock dwell, started by each new label +/** Holds each new label for DWELL_MS; forkWorkingRowLast holds the rules, this hook only the clock. */ +function useDwelledLabel(label: string, thought: boolean): string { + const [shown, setShown] = useState(() => forkStatusLineDwellStart(label, thought)); + const next = forkStatusLineDwellReconcile(shown, label, thought); + if (next !== shown) setShown(next); + const { dwelling, arrival } = next; + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- a wall-clock dwell, started by each label that takes the line useEffect(() => { if (!dwelling) return; const id = window.setTimeout( - () => setShown((s) => (s.arrival === arrival ? { ...s, dwelling: false } : s)), + () => setShown((current) => forkStatusLineDwellEnd(current, arrival)), DWELL_MS, ); return () => window.clearTimeout(id); }, [dwelling, arrival]); - return shown.label; + return next.label; } /** The rotation's state; forkWorkingRowLast holds the rules, this hook only the clock. */ @@ -107,7 +102,6 @@ export function ForkLiveStatusLine({ const label = useDwelledLabel( forkStatusLineText(voices, rotation, row.forkWordSeed), voices.pinned === null && rotation.voice === "thought", - ctx.routeThreadKey, ); const text = ( <> diff --git a/apps/web/src/custom/forkWorkingRowLast.test.ts b/apps/web/src/custom/forkWorkingRowLast.test.ts index 24cf2610bccd1..4097ec014b020 100644 --- a/apps/web/src/custom/forkWorkingRowLast.test.ts +++ b/apps/web/src/custom/forkWorkingRowLast.test.ts @@ -7,6 +7,9 @@ import { import { forkLiveStatusRows, forkStatusLineAdvance, + forkStatusLineDwellEnd, + forkStatusLineDwellReconcile, + forkStatusLineDwellStart, forkStatusLineReconcile, forkStatusLineRotates, forkStatusLineStart, @@ -346,6 +349,24 @@ describe("the status line rotation", () => { expect(forkStatusLineReconcile(line, voices("a", "old"))).toBe(line); }); + it("holds each label for its dwell, letting only a growing thought through", () => { + const thought = forkStatusLineDwellStart("checking", true); + const waiting = forkStatusLineDwellReconcile(thought, "run vp", false); + expect(waiting).toBe(thought); + const grown = forkStatusLineDwellReconcile(thought, "checking the tests", true); + expect([grown.label, grown.arrival]).toEqual(["checking the tests", thought.arrival]); + const tool = forkStatusLineDwellStart("run vp", false); + expect(forkStatusLineDwellReconcile(tool, "run vp then more", true)).toBe(tool); + const ended = forkStatusLineDwellEnd(grown, grown.arrival); + const taken = forkStatusLineDwellReconcile(ended, "run vp", false); + expect([taken.label, taken.dwelling, taken.arrival]).toEqual([ + "run vp", + true, + grown.arrival + 1, + ]); + expect(forkStatusLineDwellEnd(taken, grown.arrival)).toBe(taken); + }); + it("says the pinned label, else the voice showing, with a fresh word each lap", () => { const all = voices("vp", "checking"); const line = forkStatusLineStart(all); @@ -369,7 +390,12 @@ describe("a running turn holds its replies (fork-quiet-live-turn)", () => { completedAt: isWorking ? null : at(9), ...(isWorking ? {} : { turnEnded: true }), }); - const rowsFor = (entries: Entries, isWorking: boolean, waitingOnUser = false) => + const rowsFor = ( + entries: Entries, + isWorking: boolean, + waitingOnUser = false, + expandedWorkGroupIds?: ReadonlySet, + ) => forkLiveStatusRows( deriveMessagesTimelineRows({ timelineEntries: entries, @@ -380,6 +406,7 @@ describe("a running turn holds its replies (fork-quiet-live-turn)", () => { supportsConversationRollback: false, forkHoldLiveReplies: true, forkShowLatestHeldReply: waitingOnUser, + ...(expandedWorkGroupIds ? { expandedWorkGroupIds } : {}), }), ); const turn = [ @@ -395,6 +422,27 @@ describe("a running turn holds its replies (fork-quiet-live-turn)", () => { expect(kinds(rowsFor(turn.slice(0, 2), true))).toEqual(["working"]); }); + it("keeps an opened status line open when the next reply lands", () => { + const reply = (n: number, second: number) => { + const entry = commentary(second); + return { + ...entry, + id: `reply-${n}-entry`, + message: { ...entry.message, id: `reply-${n}` as never }, + }; + }; + const first = [command("a", 2, "completed"), reply(1, 3), command("b", 4, "inProgress")]; + const opened = statusLine(rowsFor(first, true))?.groupId; + expect(opened).toBeDefined(); + const next = [ + ...first.slice(0, 2), + command("b", 4, "completed"), + reply(2, 5), + command("c", 6, "inProgress"), + ]; + expect(statusLine(rowsFor(next, true, false, new Set([opened!])))?.expanded).toBe(true); + }); + it("settles a thought whose only follower is a held reply", () => { const live = (rows: MessagesTimelineRow[]) => { const line = statusLine(rows); diff --git a/apps/web/src/custom/forkWorkingRowLast.ts b/apps/web/src/custom/forkWorkingRowLast.ts index 001c57256dd7c..61cdd1753cad4 100644 --- a/apps/web/src/custom/forkWorkingRowLast.ts +++ b/apps/web/src/custom/forkWorkingRowLast.ts @@ -244,3 +244,39 @@ export function forkStatusLineText( if (line.voice === "thought" && voices.thought !== null) return voices.thought; return forkThinkingWord(line.lap === 0 ? wordSeed : `${wordSeed}:${line.lap}`); } + +/** The label on the line, held for a dwell so a burst of arrivals never flickers through. */ +export interface ForkStatusLineDwell { + readonly label: string; + /** The label is the thought voice, which may grow through its dwell while it streams. */ + readonly thought: boolean; + readonly dwelling: boolean; + /** Bumped by each label that takes the line; its dwell ends only its own hold. */ + readonly arrival: number; +} + +export function forkStatusLineDwellStart(label: string, thought: boolean): ForkStatusLineDwell { + return { label, thought, dwelling: true, arrival: 0 }; +} + +/** + * A new label waits out the dwell of the one showing, then takes the line with a dwell of its + * own. A thought that only grows passes through on its first deadline. Returns `shown` if unchanged. + */ +export function forkStatusLineDwellReconcile( + shown: ForkStatusLineDwell, + label: string, + thought: boolean, +): ForkStatusLineDwell { + if (label === shown.label) return shown; + if (thought && shown.thought && label.startsWith(shown.label)) return { ...shown, label }; + if (shown.dwelling) return shown; + return { label, thought, dwelling: true, arrival: shown.arrival + 1 }; +} + +export function forkStatusLineDwellEnd( + shown: ForkStatusLineDwell, + arrival: number, +): ForkStatusLineDwell { + return shown.arrival === arrival && shown.dwelling ? { ...shown, dwelling: false } : shown; +}