Repository navigation
fix(native-chat): fold thoughts and tool calls between replies into one row - #26048
Conversation
…ne row A model that thinks before every tool call drew a 'Thought for Ns' row between each call, and each thought also stopped the calls from merging, so a turn read as dozens of alternating rows. The transcript now draws an unbroken stretch of tool calls and thoughts within a turn as one tool run; thoughts read in order inside it when opened and are not counted in its label.
A live turn that had edited a file kept splitting its newest call or thought off the run (the row carrying the turn's diff rollup could not join), so a lone "Thought for Ns" row came back at the bottom. - Run boundaries are now one pure pass in src/shared (nativeChatWorkRunSpans), applied over the built transcript slots. Section heads end runs by sitting between rows, and rows inside an expanded subagent section are grouped the same way. - The row carrying the turn's diff rollup joins as the run's last member; the run takes the rollup from it and the bar from its head. - A collapsed run reserves one tool row plus a lead's words, not every thought's text. - Lone rows and runs draw through the same MessageRow, with one flat keyed line list, so a row becoming a run no longer remounts (a revealed diff card no longer re-fires its scroll). - A run opens by default while the reader holds one of its thoughts open; the run's own choice still wins. - A drawn thought with no visible text joins a run instead of splitting it.
… thoughts out of runs - A structured journal row's call and result now share one id (the provider's call id, else the row's own id), so a diff or output can no longer pair with an earlier unanswered call in the same work run or folded message. A quiet command followed by edits now shows each diff card under its own call, and the rollup's reveal lands on it. - A thought still being thought, while its turn or subagent works, keeps its own row after the run and joins once it ends. - Removed the rule that opened a run because a thought inside it was open; a thought keeps its own open state inside its run.
Only a subagent section keeps a still-running thought out of its run. At the top level the live line owns the open thought; when it lets go (a Stop in flight, a prompt waiting on the reader) the thought now joins the run at once instead of flashing as its own row until the turn ends.
…st after it Settled work runs must not rebuild their lines and thoughts on every stream frame of the live run. Renames the slot-level run test so it no longer shares a name with the shared span test.
Review summary (final head 393aaaf)The problem. In the desktop native chat, a model that thinks before each tool call (Claude Opus at high effort, for example) drew a separate "Thought for Ns" row between nearly every call, and each thought also stopped the calls around it from merging. One real turn with 13 thoughts, 12 tool calls and 3 replies drew about 25 rows of work. What changes for you. Everything the agent does between two replies is now one row whose label counts the tool calls ("Edited 1 file and ran 2 commands"). Open it to read the calls and the thoughts in order. While the turn works it stays one live row naming the current call. Subagent sections group the same way. A lone thought right before a reply still shows as its own row. What the review loop fixed (three review rounds plus a readiness pass, each finding proven with a test against the real code):
Deferred (low impact, recorded):
What was verified.
What was not verified.
|
ELI5
When an agent thinks before each tool call, the desktop chat drew every thought as its own "Thought for 5s" row between the calls. One answer could take 25 rows to read, for example 13 thoughts and 12 commands. Now everything the agent does between two replies is one row ("Edited 1 file and ran 2 commands"). Open it to see the calls and the thoughts in order.
What Changed
Before
After
Mechanism
src/shared/native-chat-work-run.tsholds the rules as pure functions with no renderer imports: which rows are run work (nativeChatWorkRunMember), where runs start and end (nativeChatWorkRunSpans), and how a run's calls and thoughts interleave.native-chat-transcript-work-runs.ts). Over the slots it has already built, that pass merges each span into one slot that carries every member message (workRun). Anything else that takes a slot (a subagent section heading, a roster, a row that only carries the turn's bar) ends a run just by sitting between its rows, so no special cases are needed. The run takes the turn's status bar from its first member and the turn's changed-files summary from its last. Its estimated height counts one collapsed header (plus a leading reply's text), not the hidden thoughts.NativeChatMessageRowdraws both a lone row and a run, so when a row grows into a run it is not remounted and its open state, text selection and a diff you jumped to stay put. It uses the existingNativeChatToolRun, with the thoughts in one keyed list among its lines. Each message keeps its own id, so reveals, disclosure state, diff jumps (re-keyed to the run's numbering) and the task-list history still resolve.structured-agent-session-projectionnow gives the call and the result built from one journal row a shared id (the provider's call id, else the row's own item id). That is what keeps each diff under its own edit.Why
This is the common pattern for agent transcripts: thinking lives inside the group of work around it, the group's label speaks for the tool calls, only finished thoughts fold into the group, and a lone thought before a reply stays a row.
I grouped at the presentation layer, not by merging messages earlier, because each thought keeps its identity there: its open/finished state, duration, disclosure key, and the live "Thinking" line all key off the thinking message. Merging thoughts into another message's blocks would need a new block type and would lose all of that. Running the grouping as one pass over the finished slot list, rather than inside the slot loop, removed three special-case rules from an earlier draft, one of which split live edit turns.
Differences from the common pattern:
nativeChatWorkRunSpansover its list; that follow-up PR is not opened yet.Linked Issue
N/A (maintainer change, from a live session where one turn drew 13 thought rows between 12 tool calls).
Visual Proof
First round (head 8b0e53f): the same conversation opened in both builds, a real Claude (Opus, high effort) turn that ran five commands and thought between each one. Captured on a macOS rig.
Before (main): with the turn expanded, ten alternating rows, each command and then its "Thought for Ns".
After: the same turn is one "Ran 5 commands" row.
After, run opened: the thoughts read in order between the commands.
Second round (head f42da78, macOS rig): a real Claude Opus turn that edits a file, runs commands, and launches a subagent that runs three commands, thinking between steps.
While it works: one live row for the turn's work so far ("Editing 1 file, running 1 command, and running 1 agent"), and the subagent's commands growing as one live run inside its section. No lone thought rows.
Finished turn, expanded: one run before the mid-turn reply and one after it.
Run opened: thoughts in order among the edit, the command and the subagent call.
Subagent section opened: its three commands are one run.
Testing
src/shared/native-chat-work-run.test.ts: membership and span rules.native-chat-transcript-work-runs.test.ts: which rows join, runs headed by a reply, lone thoughts, turn and receipt boundaries, a live turn that edits files (one run, carrying the changed-files summary), a stopped turn ending on work, Stop in flight, height estimates, reveal lookup, diff-key re-numbering.native-chat-subagent-section-work-runs.test.ts: grouping inside sections, never across agents, depths or section headings; a thought the subagent is still thinking stays its own row.NativeChatTranscriptRow.work-run.test.tsx,NativeChatMessageRow.work-run.test.tsx,NativeChatMessageList.work-runs.test.tsx: no remount when a row becomes a run (a revealed diff does not scroll again), thoughts in order, a thought opened while live is still open inside the run, Stop in flight and a waiting prompt draw no lone thought row.NativeChatMessageList.work-run-memo.test.tsx: streaming into the live run rebuilds only that run (fails if the row's memo check is broken).native-chat-work-run-pairing.test.ts: through the real projection, each diff stays under its own call, with and without thoughts between.Locally: web and node typechecks pass; oxlint, oxfmt and the changed-code quality gate are clean; 419 test files across
src/renderer/src/components/native-chat/,src/shared/native-chat-*andsrc/shared/structured-agent-session-*pass (4,418 tests).I manually tested these changes locally (macOS rig, real Claude Opus turns; screenshots above. Not tried live: a Codex or ACP turn with diffs, which is unit-tested through the real projection; a thought opened while live, unit-tested.)
Automated tests added/updated, or explained why not below
Notes
Presentation-only, plus one client-side projection change. Each client builds chat messages from the journal items it already receives, so no wire format, stored schema or host behavior changes, and mixed-version desktop, mobile, SSH and remote setups keep working. The worker transcript output and the stored worker archive gain a value in their existing optional
callIdfield. Cross-platform: no platform-specific code. Performance: the grouping pass adds about 1–2 ms per streamed frame on a 10,000-message transcript and cuts the number of slots the windowed list handles; settled runs do not re-render while the live one streams.