feat(tui): diff viewer, PR Code tab and thread changes view

Merged
HK
17d ago
+1405-0

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):

Code tab file list

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

Split diff

Unified (narrow region):

Unified diff

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 -- x line 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. Reads diff, activity (commits) and filesViewed from pullRequestAtoms; viewed marks write through setFilesViewed, the same server command as web. Hosts without viewed-files support keep marks in memory.
  • features/diff/ChangesView.tsx: main view diff.changes with the thread's checkpoint diffs (all turns, or one turn), from orchestrationEnvironment.fullThreadDiff / turnDiff. Viewed marks here are local (the server keeps none).
  • features/diff/CodePanel.tsx: stand-in right panel diff.code that shows the open thread's linked PR in the Code tab (see Reasoning).
  • Shared edits: state/pullRequests.ts (new, pullRequestAtoms), one line in connection/runtime.ts (PullRequestDiffLoader.layer), theme.diff.* background tokens, one line in features/index.ts, README keys.

Keys added:

  • Global: ctrl+x toggles the thread Changes view (command diff.toggle, the web id). Palette only: "Toggle pull request code" (diff.codePanel).
  • File list: j/k, g/G, enter/l open, v/space viewed, t tree, c/C scope, escape back.
  • Diff: j/k, ctrl+d/ctrl+u, g/G, n/p hunks, w wrap, x expand context, J/K next/previous file, v viewed, escape/h/backspace back to the list.

Tests

  • patch.test.ts: change types, counts, line numbers, renamed paths, binary, a removed -- x line 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, n jumps to the next hunk, escape closes 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+x opens the Changes view and escape returns. 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 (prPanelTabs in TuiFeature, PrPanelTabProps { target }, state/pullRequests.ts with pullRequestAtoms). It is not on tui yet, so CodeTab already takes { target, width, height } and state/pullRequests.ts and the runtime layer line match their text. To move it into the PR panel once their branch lands: replace panels and the diff.codePanel command in features/diff/index.ts with prPanelTabs: [{ id: "code", title: "Code", order: 40, component: CodeTab }], and delete CodePanel.tsx. The tab returns false for n in the file list, so the panel can still use n to cycle linked PRs; in a diff n/p jump hunks.
  • DiffView hands 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 orderDiffFiles needs 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+x opens 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.
  • parsePatch reads 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.codePanel panel and command with prPanelTabs: [{ id: "code", title: "Code", order: 40, component: CodeTab }] in features/diff/index.ts and deletes CodePanel.tsx once the PR panel tab API lands on tui.

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.