Skip to content

feat(native): open a file change's tool-call diff from the transcript - #62

Merged
rynfar merged 2 commits into
nativefrom
nw/58-tool-diff
Nov 2, 2026
Merged

rynfar merged 2 commits into
nativefrom
nw/58-tool-diff

Conversation

@rynfar

@rynfar rynfar commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Refs #58. Ledger row TR-DIFF is now partial: side chats do not offer the diff yet (see Gaps), so #58 stays open for that.

Problem

On the web, a file_change work row's details have an Open diff button that opens the diff panel on that one tool call's recorded patch (selectToolCall, DiffPanel.tsx's tool-call scope). Native had no way to see what a single tool call changed: the diff panel only offered the git and turn scopes.

Approach

  • Core (crates/core/src/diff/tool_call.rs, diff/whitespace.rs, diff/scope.rs), ported from lib/toolCallDiff.ts, diffPanelStore.ts and diffRendering.ts:
    • tool_call_diff: complete patches stay as recorded; bare hunks get diff --git/---/+++ headers (renames use changes[0].oldPath); recorded add/delete contents become one all-added or all-deleted hunk unless the patch already covers every recorded file one-sidedly; the transport truncation marker is dropped and reported; content recorded without a diff is returned for the panel to show.
    • ToolCallTarget and resolve (resolveToolCallDiffTarget): the fetch is keyed by turnItemDetailRevision of the row the thread shows now, so a change opened while running is fetched again when it settles.
    • DiffSelection::ToolCall persists as the web's {"kind":"tool-call",threadId,itemId,revision}; DiffScope::ToolCall labels "Tool call".
    • hide_whitespace_changes (hideWhitespaceChanges): the whitespace toggle (default on, as on the web) applies to a tool call's patch client-side, re-diffing each hunk with whitespace removed (Myers, bounded at 1,000 edits per hunk).
  • Diff panel (crates/app/src/diff/): the tool-call scope fetches orchestration.getTurnItem on the network runtime and parses both whitespace variants there, so the toggle only swaps them. It works outside a git repository (!isGitRepo && !toolCallSelection), shows the web's banners ("This preview exceeds the size limit…", "This tool call changed N files. The recorded patch omits M of them."), the error line, "The provider recorded file content without a diff." with "Recorded content before/after" and "Empty content.", the loading skeleton, and "No net changes in this selection." / "No patch available for this selection.". Folds are kept per tool-call:<thread>:<item> scope. A newer revision of a loaded tool call keeps the old patch on screen but is always fetched, including one requested while the panel was hidden (needs_fetch). The way back is the scope menu (Changes, Uncommitted, Latest turn, Turn), where no entry is checked while a tool call is shown, as on the web.
  • Entry point: an xs outline Open diff button in the expanded file-change details (V2ItemInspector.tsx), wired through ThreadView::open_tool_call_diff → AppState::open_tool_call_diff. The work.rs change is the button and a Context<ThreadView> on entry_details. Only the open thread's transcript offers it (see Gaps). The web has no menu, palette or keybinding entry for this.
  • Snapshot tool: --click x,y (repeatable) so offscreen captures can drive a row and a button; documented in test-t3-native.

Evidence

Offscreen snapshots against the smoke server (thread "Write Approval Demo File", 1440x900 @2x, dark):

  • Before, expanded file change with no way to its diff: /private/tmp/claude-501/-Volumes-DevSSD-t3code-native/3ca997f3-68be-482e-8fff-7893917dbe2a/scratchpad/pr58/before-row.png
  • After, Open diff in the details and the panel on "Tool call" (file folded by default, diffFilesCollapsed): /private/tmp/claude-501/-Volumes-DevSSD-t3code-native/3ca997f3-68be-482e-8fff-7893917dbe2a/scratchpad/pr58/after-open.png
  • After, the file unfolded: /private/tmp/claude-501/-Volumes-DevSSD-t3code-native/3ca997f3-68be-482e-8fff-7893917dbe2a/scratchpad/pr58/after-diff.png
  • Way back, the scope menu while on a tool call: /private/tmp/claude-501/-Volumes-DevSSD-t3code-native/3ca997f3-68be-482e-8fff-7893917dbe2a/scratchpad/pr58/after-menu.png
  • Way back, "Latest turn" picked from it: /private/tmp/claude-501/-Volumes-DevSSD-t3code-native/3ca997f3-68be-482e-8fff-7893917dbe2a/scratchpad/pr58/after-back.png

Tests (crates/core/src/diff/tests.rs, ports of toolCallDiff.test.ts plus the target and whitespace logic):
tool_call_hunks_get_file_headers_including_renamed_paths, tool_call_added_and_deleted_contents_become_one_sided_hunks, tool_call_content_without_a_diff_is_kept_out_of_the_patch, tool_call_drops_transport_truncation_markers, tool_call_keeps_complete_patches_and_unsupported_output, tool_call_target_follows_the_row_the_thread_shows, hiding_whitespace_turns_whitespace_only_edits_into_context; and in crates/app/src/diff/source.rs, a_newer_revision_shows_the_old_patch_but_is_still_fetched (fails under the old same_source freshness rule).

Gates: cargo clippy --workspace --all-targets -- -D warnings (and with --features snapshot), cargo test --workspace, node scripts/gen-theme.ts --check, node --test parity/sync.test.ts, node ../../apps/native/conformance/generate.ts --check all pass.

Gaps

  • Side chats: the web opens a side chat's tool-call diff in the parent's panel, but native's diff panel follows only the open thread's items and the side chat's subscription drops while the diff tab is active, so a running change there would never refetch. The button is hidden in side chats until the panel can follow that thread.
  • The recorded-content fallback (horizontal scroll when wrapping is off) is not visually verified: neither server has a file change recorded without a diff.
  • The loading label ("Loading tool call diff...") is screen-reader-only on the web; native has no accessibility tree yet, so the skeleton is the same as other scopes.
  • reviewSectionTitle ("Tool call") only titles diff review comments, which native does not have (DF-COMMENTS).
  • With whitespace hidden, a split view shows a whitespace-only line's new text on both sides.
  • Not verified against a provider that records raw add/delete contents or an error from getTurnItem; those paths are covered by the core tests.

@rynfar

rynfar commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

Review round 1, all three findings were real; fixed in 7a471aa:

  1. Stale tool-call revision never refetched (source.rs): sync() now fetches when nothing answers the request exactly (needs_fetch), while has_loaded() keeps using same_source so the older patch stays on screen during the refresh. This also covers a git revision bumped while the panel was hidden. Test: diff::source::tests::a_newer_revision_shows_the_old_patch_but_is_still_fetched, which fails with the old rule.
  2. Side-chat targets never follow completion: following the side thread would mean keeping its subscription alive while the diff tab shows, so I took the smaller option. Side chats no longer offer Open diff (RowEnv::tool_diffs), and TR-DIFF is partial with the gap in the row and in Inline file-change diff (tool-call diff in the diff panel) #58.
  3. Recorded content clipped with wrapping off (lines.rs): each block now scrolls horizontally like the web's overflow-auto
    , with scroll restricted to its axis so a vertical wheel still scrolls the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant