feat(tui): diff viewer, PR Code tab and thread changes view
Summary
Adds a reusable terminal diff component, a PR Code tab built on it, and a thread Changes view that shows checkpoint (turn) diffs. Ports the fork's Code tab redesign (#17) and warm colors (#3) to the TUI.
Preview
File list (viewed marks, change type, folder dimmed, change bar, viewed progress):

Side by side with wrap on (changed words get a stronger background):

Unified (narrow region):

Captured headless from the component with a real patch from this repo (the playground data has no PRs or checkpoints).
Changes
features/diff/patch.ts: unified diff parser (added, modified, deleted, renamed, binary, line numbers). It counts hunk lines, so a removed-- xline is never read as a file header.features/diff/rows.ts,paint.ts,DiffView.tsx: diff rows (unified, or side by side at 110+ columns), line numbers, +/- gutter, intra-line changed range (common prefix and suffix), warm syntax colors through the thread view's highlighter (cached per line), wrap toggle, long unchanged runs folded with an expand key. Only the visible rows render.features/diff/CodeBrowser.tsx,fileList.ts: file list with change marker, file name emphasized and folder dimmed, folder tree toggle, proportional +/- bar, viewed toggle and "N/M viewed" line, scope cycling (commits or turns).features/diff/CodeTab.tsx: PR Code tab. Readsdiff,activity(commits) andfilesViewedfrompullRequestAtoms; viewed marks write throughsetFilesViewed, the same server command as web. Hosts without viewed-files support keep marks in memory.features/diff/ChangesView.tsx: main viewdiff.changeswith the thread's checkpoint diffs (all turns, or one turn), fromorchestrationEnvironment.fullThreadDiff/turnDiff. Viewed marks here are local (the server keeps none).features/diff/CodePanel.tsx: stand-in right paneldiff.codethat shows the open thread's linked PR in the Code tab (see Reasoning).- Shared edits:
state/pullRequests.ts(new,pullRequestAtoms), one line inconnection/runtime.ts(PullRequestDiffLoader.layer),theme.diff.*background tokens, one line infeatures/index.ts, README keys.
Keys added:
- Global:
ctrl+xtoggles the thread Changes view (commanddiff.toggle, the web id). Palette only: "Toggle pull request code" (diff.codePanel). - File list:
j/k,g/G,enter/lopen,v/spaceviewed,ttree,c/Cscope,escapeback. - Diff:
j/k,ctrl+d/ctrl+u,g/G,n/phunks,wwrap,xexpand context,J/Knext/previous file,vviewed,escape/h/backspaceback to the list.
Tests
patch.test.ts: change types, counts, line numbers, renamed paths, binary, a removed-- xline inside a hunk.rows.test.ts: unified order and side-by-side pairing, changed-word range, fold and expand, wrap slices, word background paint, tree grouping, change bar.CodeBrowser.test.tsx: viewed toggle and progress, open a file,njumps to the next hunk,escapecloses the diff before it leaves the view.vp run check:changed: format, lint, knip, typecheck (41 packages), tests (21 files) all pass.- Manual: ran against a playground server (port 5310);
ctrl+xopens the Changes view andescapereturns. No PR or checkpoint data there, so the screenshots use a component capture.
Scope affected
TUI only (apps/tui). No server, contracts, client-runtime, web or mobile change.
Reasoning
- The PR panel thread proposed a tab API (
prPanelTabsinTuiFeature,PrPanelTabProps { target },state/pullRequests.tswithpullRequestAtoms). It is not ontuiyet, soCodeTabalready takes{ target, width, height }andstate/pullRequests.tsand the runtime layer line match their text. To move it into the PR panel once their branch lands: replacepanelsand thediff.codePanelcommand infeatures/diff/index.tswithprPanelTabs: [{ id: "code", title: "Code", order: 40, component: CodeTab }], and deleteCodePanel.tsx. The tab returnsfalsefornin the file list, so the panel can still usento cycle linked PRs; in a diffn/pjump hunks. DiffViewhands its key handler to its owner instead of registering its own region handler: it mounts after the panel, so a handler of its own would run after the panel's.- Known limits: syntax colors per line (block comments across lines are missed); host viewed presses stay in a local overlay until the tab unmounts instead of web's read-confirmed settle; only the first page of a very large PR diff loads (the scope line says "more files on the host"); no import-based file order (web's
orderDiffFilesneeds Pierre metadata); folded context expands per file, and gaps between hunks are not fetchable.
Summary by cubic
Adds a terminal diff viewer, a PR Code tab, and a thread Changes view to the TUI, so users can review pull request and checkpoint diffs without leaving the terminal.
ctrl+xopens the open thread's checkpoint diffs; the command palette's "Toggle pull request code" opens the linked PR's changed files in the right panel.- The diff view renders unified, or side by side at 110+ columns, with syntax colors, changed-word backgrounds, wrap, and folded context that expands on
x. - Viewed marks on a PR save to the host via the same server command as web; marks on thread changes stay in memory.
parsePatchreads a multi-file unified diff, counting hunk lines so a removed--line inside a hunk is never read as a file header
Migration:
- Replaces the
diff.codePanelpanel and command withprPanelTabs: [{ id: "code", title: "Code", order: 40, component: CodeTab }]infeatures/diff/index.tsand deletesCodePanel.tsxonce the PR panel tab API lands ontui.
Known limits: syntax highlighting is per line (cross-line block comments are missed), folded context expands per file, and only the first page of a large PR diff loads.