diff --git a/.fork/customizations.yaml b/.fork/customizations.yaml index 6ab31ebf2d1df..20253cb853176 100644 --- a/.fork/customizations.yaml +++ b/.fork/customizations.yaml @@ -6586,6 +6586,16 @@ 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 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 @@ -6629,33 +6639,41 @@ - 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. 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 + 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 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 6659ed75f5f65..43a24ad28c3b2 100644 --- a/apps/web/src/components/chat/MessagesTimeline.logic.ts +++ b/apps/web/src/components/chat/MessagesTimeline.logic.ts @@ -1520,25 +1520,20 @@ 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" - | "isWorking" - | "latestRun" - | "runningRunId" - | "revealedMessageId" - | "forkShowLatestHeldReply" + "timelineEntries" | "isWorking" | "latestRun" | "runningRunId" | "revealedMessageId" >, -): 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 +1547,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 */ @@ -1589,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 +1640,11 @@ 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(forkLiveReplies.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 +1707,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; @@ -1716,7 +1715,14 @@ 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 + 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.forkShowLatestHeldReply === true ? null : (forkLiveReplies.at(-1) ?? 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) { @@ -1878,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 @@ -2374,6 +2387,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/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 c78fc3ae506dc..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, @@ -23,6 +26,40 @@ import { } from "./forkWorkingRowLast"; const BEAT_MS = 4000; +const DWELL_MS = 1500; + +/** + * 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 a cycle apart. + */ +function shimmerLineRef(element: HTMLSpanElement | null) { + 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); +} + +/** 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((current) => forkStatusLineDwellEnd(current, arrival)), + DWELL_MS, + ); + return () => window.clearTimeout(id); + }, [dwelling, arrival]); + return next.label; +} /** The rotation's state; forkWorkingRowLast holds the rules, this hook only the clock. */ function useStatusLineState(voices: ForkStatusLineVoices) { @@ -62,7 +99,10 @@ 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", + ); const text = ( <> {label} @@ -73,7 +113,7 @@ export function ForkLiveStatusLine({ <> diff --git a/apps/web/src/custom/forkWorkingRowLast.test.ts b/apps/web/src/custom/forkWorkingRowLast.test.ts index 7b2f80be57a05..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, @@ -319,11 +322,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", () => { @@ -343,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); @@ -366,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, @@ -377,6 +406,7 @@ describe("a running turn holds its replies (fork-quiet-live-turn)", () => { supportsConversationRollback: false, forkHoldLiveReplies: true, forkShowLatestHeldReply: waitingOnUser, + ...(expandedWorkGroupIds ? { expandedWorkGroupIds } : {}), }), ); const turn = [ @@ -386,8 +416,31 @@ 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("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", () => { diff --git a/apps/web/src/custom/forkWorkingRowLast.ts b/apps/web/src/custom/forkWorkingRowLast.ts index 9d642502f6903..61cdd1753cad4 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. */ @@ -238,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; +} diff --git a/apps/web/src/theme.custom.css b/apps/web/src/theme.custom.css index 2f7739905a1b4..0fc5bae197e56 100644 --- a/apps/web/src/theme.custom.css +++ b/apps/web/src/theme.custom.css @@ -3910,13 +3910,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 */