Skip to content

feat(native): right panel with tabs and the diff panel - #18

Merged
rynfar merged 8 commits into
nativefrom
nw/w6-diff
Nov 2, 2026
Merged

rynfar merged 8 commits into
nativefrom
nw/w6-diff

Conversation

@rynfar

@rynfar rynfar commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Problem

The native client had no right panel and no way to see what an agent changed. Issue #11 asks for the diff panel; it needs the tabbed right panel (PN-RIGHT) to live in.

Approach

Ported from the web, logic first:

  • crates/core/src/diff.rs (+ diff/): a unified-diff parser standing in for @pierre/diffs parsePatchFiles. It handles git headers, new/deleted/renamed/copied files, binary files, C-quoted paths, paths with spaces, plain ---/+++ patches with timestamps, \ No newline at end of file, empty hunks, missing counts, and tabs at Pierre's tab size 2. Content keeps its \r, and combined diffs (diff --cc) fall back to raw text. The rest of the module: per-file stacked/split rows with N unmodified lines separators and Pierre's "No newline at end of file" row, the changed-files tree, deriveThreadCheckpointSummaries, useCheckpointDiff (turn 1 → getFullThreadDiff, later → getTurnDiff), review.getDiffPreview source picking with non-repository detection, deriveWorkspaceMutationId, and the diffPanelStore.ts selection.
  • crates/core/src/right_panel.rs: the rightPanelStore.ts tab model (upsert, toggle, close with neighbor fallback, close others/to the right/all, move, maximize), closedViewStore.ts history with planNextReopen, and width clamping. Persisted state decodes leniently: bad entries drop on their own, and the active tab and visibility are repaired as the store's migration does. Surfaces are { id, kind }, so files/preview/terminal/side chats plug in as new SurfaceKinds.
  • crates/client: uses the single ClientHandle::request that feat(native): drive agents from the composer: new threads, pickers, approvals #20 landed (mine merged into it), and ClientHandle::environment() names the server. store::{load,save}_ui_state writes through one writer thread that coalesces to the newest value per file, then renames a uniquely named temporary into place. Loads tolerate corrupt files.
  • crates/app/src/right_panel/: the inline panel. It defaults to 540px (min 360, max 70% of the window or row − 360) and has an 8px resize handle (border on hover, primary/60 while dragging). Width persists per thread and is saved once the drag settles. The 52px tab bar has 24px tabs (max 144, radius 6, 12px text) with a hover X and middle-click close, a Close / Close others / Close to the right / Close all context menu, a + add menu, and the "Open a surface" launcher. Maximize and right-panel toggles sit at the window's top right. Shortcuts go through W3's keymap: diff.toggle, rightPanel.toggle, rightPanel.toggleMaximized, rightPanel.close and view.reopenClosed map to the panel's actions in keymap::action_for, so their keys and when clauses live with the other defaults, and the keymap's rightPanelOpen flag reflects the panel. The width cap and the maximized tab bar's inset follow the collapsible sidebar. Buttons, layout segments, tabs and launcher rows are tab stops with the §4.2 focus ring (2px ring inside a 1px background gap); Enter and Space activate them.
  • crates/app/src/diff/: scopes are Changes, Uncommitted, Latest turn and Turn ▸ N. Requests are fetched and parsed on the network runtime, with an LRU cache keyed by environment. Git scopes refetch when the workspace mutation id changes (finished file tools and commands, new checkpoints), on refresh, and when the panel is shown with a diff older than 10s. Failed requests rerun once the connection settles. A cwd that is not a repository shows the web's explanation and stops refetching. The code view is a virtualized list: one row per line, rows kept per file so a fold splices only that file. It has sticky 32px headers, 24px separators, 13px mono on 20px lines and a 4px change bar, and paints on background (the viewer overrides --code-background). It supports stacked/split, wrap (sideways scroll when off), hide-whitespace via ignoreWhitespace, per-file and fold-all folds (files start folded, per diffFilesCollapsed: true), copy path, and a file tree that reveals on click. Loading, empty, error, raw and truncated states use the web's copy. The diff view is .cached(), so transcript streaming doesn't repaint it.
  • Entry points: AppState::open_turn_diff(run_id, file_path) (the diff menu's turn items go through it; the transcript's per-turn changed-files summary isn't ported yet, see gaps), cmd-d (diff.toggle), the launcher and + menu, and the header toggle. Opening the diff without an explicit request resets it to Changes, as ChatView.tsx does.
  • Theme and icons: gen-theme.ts evaluates color-mix(in lab, …); diff_row_{addition,deletion}{,_gutter} and diff_hunk_separator derive from the web CSS over --background. My icons are registered in the shared icons.rs (one asset source, alongside feat(native): web-parity sidebar, thread actions, keybindings and command palette #19's sized/from_name) and vendored through scripts/vendor-icons.ts; the source also serves gpui-component's own icons so the existing IconName widgets render.

Review fixes (Sol 6.1)

Finding Fix
P1 concurrent saves Single writer thread, coalesce to latest, unique temp + atomic rename; lenient load per key
P1 folds rebuild everything View keeps rows per file; a fold splices one file's range (core::diff::file_rows)
P2 failures stick after reconnect Errors clear and the request reruns when the connection settles
P2 non-git loads forever sources: [] → "Turn diffs are unavailable because this project is not a git repository."; no refetch; turn diffs disabled there
P2 stale git scopes mid-turn workspace_mutation_id (port of deriveWorkspaceMutationId) bumps the request revision
P2 CR lost / EOF ignored \r kept in content (hidden when painted, like the web); "No newline at end of file" rows
P2 wrong diff surface Tokens and painting use background; regenerated, --check passes
P2 controls not focusable Tab stops, keyboard activation, §4.2 focus ring
Risks Environment in cache keys; active tab repaired on load; diff --cc → raw text

Ledger

  • PN-RIGHT → partial, crates/app/src/right_panel, crates/core/src/right_panel.rs
  • DF-PANEL → partial, crates/app/src/diff, crates/core/src/diff.rs
  • TR-DIFF stays todo (see gaps)

Verification

thread mcp:60fa4373-…: 3 checkpoints, 2 turns with diffs
turn 2 (orchestration.getTurnDiff): no net changes
full thread to turn 2: no net changes
git scopes in /Volumes/DevSSD/t3code-native/apps/server
changes: 120000 bytes, 8 files, 8 hunks, +4433 -0
uncommitted: 773 bytes, 1 files, 1 hunks, +5 -0

That server's turns changed no files, so the turn and full-thread diffs answer empty. Real patches come through Changes: a truncated 120 KB branch diff with a 4,000-line Cargo.lock.

  • App smoke runs against the live server, with the diff open from persisted state:
    • A deliberately corrupt panels.json (unknown tab active, bad width, bad selection, unknown layout) loaded leniently and was rewritten atomically with no temp files left.
    • With a temporary local patch (not committed) that unfolded everything, folded and unfolded a file and scrolled to row 2000: rows went 4418 → 4417 → 4418, with the list count in step and no panics.
    • Stacked, split and no-wrap layouts were covered in the earlier rounds.
  • No screenshots: this machine refuses window capture (no screen-recording permission), so pixels and the focus ring are unverified. Someone with a display should open a thread, press cmd-alt-b / cmd-d, tab through the toolbar, and compare against design-system.md §4.2, §5 and §7.8.

Gaps (follow-ups)

  • TR-DIFF / tool-call diffs: need orchestration.getTurnItem, the toolCallDiff.ts synthesis and a transcript entry point.
  • Transcript per-turn changed-files summary: timeline/rows.rs lists "per-turn diff summaries" as not ported. Its ChangedFilesTree should call open_turn_diff(run_id, Some(path)).
  • Git scopes: no Commits submenu, no base-ref combobox (refs show as text), and truncated previews show only the files present (the web lazy-loads the rest).
  • Diff view: no syntax highlighting, no "hide test files", no turn timestamps in the Turn submenu. Empty split sides are plain rather than hatched, and expanded files lack Pierre's 8px trailing gap.
  • Right panel: no sheet mode under 980px, no tab drag-reorder (the model has move_surface), no tab-strip scroll buttons, no launcher letter shortcuts, no proactive diff open when a turn finishes. File tree width is a fixed 40%.

Part of #11 (left open: see gaps).

Built by Claude Opus 5.5 (worker W6) in Claude Code.

Parses unified diffs (git headers, renames, binary, quoted paths, no newline
at EOF) into files, hunks and lines; lays them out as stacked or split rows
with hunk separators; builds the changed-files tree; derives checkpointed
turns and the requests behind each diff scope. Ports the right panel tab
model and closed-tab history from rightPanelStore.ts and closedViewStore.ts.
ClientHandle::request runs one unary RPC on the live session (diffs today,
other surfaces next). store gains small JSON files for UI state the web keeps
in localStorage. The diff_probe example fetches a thread's turn, full-thread
and git diffs headlessly and prints what they parse to.
gen-theme evaluates color-mix in CIE Lab, so the diff row and gutter fills
Pierre paints over the code surface come out of the web theme like every other
token. Icons are vendored from lucide-react 0.564.0 with the web's 1.75 stroke
and served next to gpui-component's own set.
An inline right panel beside the thread: 540px default, 8px resize handle,
width per thread, tab bar with close, middle-click and context menu, an add
menu and the Open a surface launcher, maximize, and cmd-alt-b / cmd-w /
cmd-shift-t. The diff surface shows Changes, Uncommitted, the latest or any
turn (getTurnDiff, getFullThreadDiff, review.getDiffPreview), fetched and
parsed off the UI thread and painted as a virtualized list with sticky file
headers, stacked or split layout, wrap, whitespace, folds and a file tree.
cmd-d toggles it; a turn's files-changed row opens it on that turn.
…eview

- Content lines keep their carriage return, so a line-ending change still
  reads as one; headers ignore it. Combined diffs (diff --cc) fall back to
  raw text instead of an empty file.
- No newline at end of file gets Pierre's marker row, stacked and split.
- Rows build per file (file_rows), so a fold rebuilds only that file.
- Persisted panel state decodes leniently: bad entries drop on their own and
  the active tab is repaired like rightPanelStore.ts's migration.
- UI state files have one writer thread that coalesces to the newest value
  and renames a uniquely named temporary into place.
- workspace_mutation_id ports deriveWorkspaceMutationId; preview_is_repository
  reads review.getDiffPreview's empty-sources answer; ClientHandle names its
  environment.
- Folding a file splices only that file's rows (View keeps rows per file).
- Failed diff requests rerun once the connection settles; cache keys carry
  the environment.
- A cwd with no repository shows the web's explanation and stops refetching.
- Git scopes refetch when the workspace mutation id changes mid-turn.
- The diff paints on background, as StyledDiffCodeView.tsx overrides
  --code-background; row tokens regenerate from that surface.
- Buttons, layout segments, tabs and launcher rows are tab stops with the
  design-system focus ring; Enter and Space activate them.
- Panel state saves go through the single writer; icons live in icons.rs
  beside the transcript's, served with gpui-component's own set.
… vendor-icons

diff.toggle, rightPanel.toggle, rightPanel.toggleMaximized, rightPanel.close
and view.reopenClosed map to the right panel's actions in keymap::action_for,
so their keys and when clauses live with the other defaults; the right panel
only registers the handlers. The keymap's rightPanelOpen flag now reflects
the panel. The panel's width cap and its maximized tab bar inset follow the
collapsible sidebar. Diff icons regenerate through vendor-icons.ts.
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