feat(desktop,host-service): add native streaming PR diff viewer built on @pierre/diffs 1.3

Closed
SA
2mo ago
+1533-37

Summary

First step of the diff-viewer rewrite: a diffshub-style native Files changed tab on the PR detail page (tasks/pr/$prNumber), built from scratch on @pierre/diffs 1.3.1 with Pierre's diffshub app pipeline ported nearly verbatim. This is the foundation the workspace DiffPane will be ported onto next; no existing diff code paths were modified.

How it works

  • Streaming end to end — host-service gains GET /pull-requests/diff, which pipes gh pr diff stdout straight into the HTTP response. The renderer splits the stream on diff --git boundaries (port of diffshub's incremental parser), parses each file on an 8ms work budget, publishes a viewport-sized first batch, then appends via viewer.addItems() — files paint while the patch is still downloading.
  • Virtualized rendering — one CodeView for the whole changeset; only rows near the viewport are mounted, highlighting runs in the existing app-wide shiki worker pool.
  • On-demand context expansion — new pullRequests.getDiffFiles procedure resolves the PR's merge-base/head refs (cross-repo aware, 5-min cache) and fetches full file contents via gh api, wired into 1.3's loadDiffFiles partial-diff hydration.
  • Sidebar — @pierre/trees file tree with git-status coloring, sticky folders, click-to-scroll (auto-expands collapsed files), plus diff stats and Collapse all / Expand all and Unified/Split toggles.

Also upgrades @pierre/diffs 1.2.12 → 1.3.1 (the Edit release); the existing workspace DiffPane compiles unchanged. The bunfig release-age exclusion is removable after 2026-08-04.

Verification (CDP, real dev stack, real PRs)

  • 5-file PR: stats match GitHub exactly; context expansion hydrates and realigns hunks.
  • 95-file / +2873-line PR: first files paint ~770ms after clicking the tab, stream completes ~1s, 3 <pre> surfaces mounted at any time.
  • Tree click, collapse-all, and split/unified verified with before/after screenshots.

Follow-ups

  • Port the workspace DiffPane onto this foundation (kills the fetch-all-contents + rediff-on-every-render plumbing), then delete the legacy v1 LightDiffViewer path.
  • Candidate diffshub ports: line-anchored review comments, status-filtered tree, line-selection deep links, wrap/line-number toggles.

https://claude.ai/code/session_01BpQqCmbQmBViy7rf6Gtuig


Summary by cubic

Adds a native, streaming “Files changed” tab to the PR detail page using @pierre/diffs 1.3.1 for fast, virtualized diff viewing. First files render while the patch is still downloading for a snappier experience.

  • New Features

    • Streaming pipeline: host-service GET /pull-requests/diff pipes gh pr diff stdout directly to the client.
    • Incremental parsing: split on diff --git, publish a viewport-sized first batch, then append as data streams.
    • Virtualized CodeView with worker-pool syntax highlighting.
    • On-demand context: pullRequests.getDiffFiles resolves merge-base/head refs and fetches contents via gh api (5‑min cache).
    • Sidebar: @pierre/trees file tree with git-status colors, click-to-scroll, Collapse/Expand all, Unified/Split toggles, and stats.
    • Performance: ~770ms to first paint on a 95‑file PR; stream completes ~1s.
  • Dependencies

    • Upgrade @pierre/diffs from 1.2.12 to 1.3.1.
    • Add bunfig minimumReleaseAge exclusion for @pierre/diffs (removable after 2026‑08‑04).

Summary by CodeRabbit

  • New Features

    • Added a Files changed tab to pull request pages.
    • Added a diff viewer with split or unified layouts, file navigation, search, statistics, and collapse/expand controls.
    • Added support for streamed diff loading and expanding file context.
    • Added loading, empty, retryable error, and rename handling states.
  • Bug Fixes

    • Improved handling of large, streamed, empty, and incomplete diffs.
    • Added validation and safeguards for diff file retrieval.