Skip to content

feat(codemode): show a script's diffs while it runs - #65247

Merged
jlongster merged 2 commits into
devfrom
codemode-live-diffs
Nov 20, 2026
Merged

jlongster merged 2 commits into
devfrom
codemode-live-diffs

Conversation

@jlongster

@jlongster jlongster commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Targets dev. Builds on #65002, which is merged.

What

A Code Mode script's file diffs now show while it runs, in both desktop timelines and the TUI, not only once it finishes.

  • Core: each throttled progress update (at most one per 100 ms) now carries the collector's current files next to toolCalls. They use the same per-change shape and caps (MAX_FILES, MAX_PATCH_BYTES), with no file reads. A recorded change (from an inner edit/patch/write or a Bun write/append/delete) schedules an update through the same throttle. The final result still carries the full list. Once a script moves to the background, CodeModeJob already drops its progress, so it stops sending files, and a backgrounded script shows no diffs, as before.
  • Desktop: scriptChanges reads running scripts too. Their background: true flag only means "can move to the background", so only jobID hides them. Placement reads only the count of changes, and place.ts reads the paths untracked, so the projection re-runs only when a change is added or the status settles. File fact ids (…:file:<index>:<path>) only ever get appended, so open cards keep their identity.
  • TUI: PatchedFiles renders by position (Index), so a running script's blocks stay in place as changes arrive. The verbosity rules are unchanged: they fold into the activity at low and show under the script at medium and high.

Decision to confirm: failed or interrupted scripts keep their changes

The files really changed, so a script that errors or is interrupted keeps the changes made so far:

  • an error result carries metadata.files;
  • an interrupted one keeps the last progress, which now includes files.

This way cards shown live don't vanish when the script ends. It is one switch: keepFailedScriptChanges in packages/session-ui/src/timeline/facts.ts.

Tests

  • core tool-execute.test.ts: progress carries files, counts only grow and stay capped at MAX_FILES, and a failed script keeps them in metadata.files.
  • session-ui placement-reactivity (current and next timelines, --conditions=browser): { streamed: 0, moved: 1, changed: [1, 1], scripted: 1 }. A running script whose toolCalls grow causes 0 re-runs, each new change exactly 1 (including a same-count report after it), and finishing with the same changes 1.
  • Placement snapshots in both timelines gain a running script with a change.
  • tui session-verbosity.test.ts: a running script with changes at low, medium and high.

Recordings (simulated model): desktop at Detailed in artifacts/drive-codemode-gui/live-diffs/ and TUI at medium in artifacts/drive-codemode-tui/live-diffs/.

Not covered: there is no CodeModeJob test harness, so "backgrounded stops sending" relies on the existing detach gate in codemode/job.ts and has no new test.

Draft: drafts skip CI here.

@jlongster
jlongster force-pushed the codemode-script-diffs branch from bf6bb5a to 3e9505d Compare November 20, 2026 17:48
@jlongster
jlongster force-pushed the codemode-script-diffs branch from 3e9505d to 8d8d8f4 Compare November 20, 2026 18:07
@jlongster
jlongster force-pushed the codemode-live-diffs branch 4 times, most recently from 428fec7 to 1fb8cad Compare November 20, 2026 20:16
Base automatically changed from codemode-script-diffs to dev November 20, 2026 20:33
User decisions:
- Show a script's diffs live while it runs, in the desktop and the TUI
@jlongster
jlongster marked this pull request as ready for review November 20, 2026 20:34
@jlongster
jlongster marked this pull request as draft November 20, 2026 20:34
@jlongster
jlongster marked this pull request as ready for review November 20, 2026 20:35

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't confirm the live diffs end to end, but I found nothing that should block the merge. The core, session-ui (both timelines) and TUI tests you changed pass. Each package's typecheck script fails in this environment, but tsc on the changed code shows no errors. My opencode-drive run with the simulated model never showed the execute call, so I have no before/after screenshots and haven't seen diffs appear while a script runs. The recordings under artifacts/ would cover that.

The progress path reuses the existing throttle, and files() now returns a copy, so a sent update doesn't change as later changes arrive. On the desktop, placement only re-runs when the number of changes goes up or the script finishes, which the reactivity test checks.

On the decision you asked to confirm: the base already kept a failed script's metadata.files, so the new behaviour only changes the UI side, and keeping cards that were shown live seems right.

Public API: unchanged. The script's progress updates gain an optional files key in the shape the final result already uses.

User decisions:
- Fix the live diff review findings
- Failed and interrupted scripts keep their diffs

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found nothing new that needs changing in ed819d566, and my earlier review left no open points. The new core tests (the move to the background in job.test.ts, the change sent on interrupt in tool-execute.test.ts) wait on deferreds rather than sleeps. The core, session-ui and TUI tests pass, and the changed files type-check. I still haven't watched it run end to end, so your recordings are the evidence for the live UI.

Public API: unchanged.

@jlongster
jlongster merged commit e86058a into dev Nov 20, 2026
10 checks passed
@jlongster
jlongster deleted the codemode-live-diffs branch November 20, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant