Diff viewer: searchable, uncapped branch base picker with smart defaults
What
Makes the diff viewer's branch targeting smart for the worktree-per-task workflow: instead of asking an agent to run `cmux diff --base `, a human picks the base branch in-app from a searchable, uncapped command-palette popover, with a smart default pre-selected.
Before: the base picker was a native `` capped at 4 candidates that often did not contain the branch you wanted. The only real entrypoint was the CLI. How The viewer pre-renders one static page per (source × repo × base), which is why base options were capped at 4. This adds on-demand regeneration so the picker is no longer bounded by pre-rendered pages: Smart default base with reason + confidence shown on the toolbar button: `branch..cmuxBase` → PR base (`gh pr view`) → `merge-base --fork-point` → `origin/HEAD`. The button shows e.g. `Base: origin/main (fork point) +1 -2`, and the full value is in the hover tooltip. Low-confidence fallbacks are visually muted with a `~` prefix. Two new `diff-viewer-server` routes (mirrored in the in-app `cmux-diff-viewer://` scheme handler via a per-group session descriptor): `/__cmux_diff_viewer_refs` returns all refs grouped suggested/worktrees/branches/remotes/recent (uncapped), and `/__cmux_diff_viewer_branch` regenerates the branch diff for an arbitrary base and 302-redirects to it. React `BranchBasePicker`: fuzzy filter across all groups, keyboard nav, raw-ref escape hatch, render cap for huge ref sets (this repo returns 2304 remotes), inline regenerate spinner. The base button is the primary toolbar control; the ref is the guaranteed-last token to truncate (deterministic flex group, not pixel thresholds). Verification Backend exercised end-to-end on a real repo: refs endpoint returns grouped uncapped data (107 worktrees / 241 branches / 2304 remotes), regenerate returns 302 to a fresh page, bad base returns 404, smart default resolves to `origin/main` "fork point". 148 webviews unit tests pass (incl. a render-cap DOM test). Typecheck/lint/build green. UX reviewed and approved over three rounds (searchable IA, ref-priority, render cap). Security reviewed: no command/path-injection (the `rev-parse --verify` chokepoint blocks argument injection, verified empirically); React treats refs as data. Known follow-ups before merge (tracked) Scope the regenerate/refs route repo allow-list to the specific group's session (currently a never-pruned same-uid union) and add the unguessable-token gate the file-serving route already has. Both are 127.0.0.1 + same-uid only. Add `--` / leading-`-` rejection on `merge-base`/`rev-list` (defense-in-depth), a server concurrency/output cap, prune session files on TTL, and HTML-escape the scheme-handler meta-refresh URL. Live popover-open screenshot (cmux's React-app webview rejects synthetic input, so the open state is currently verified by unit tests + live endpoints only). 🤖 Generated with Claude Code
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.
Summary by cubic Replaces the 4-item base select with a searchable, uncapped base picker in the diff viewer. Diff computation now always matches the smart base shown in the toolbar, with fast opens, restore-safe endpoints, and hardened routing. New Features Command‑palette base picker across suggested/worktrees/branches/remotes/recent with fuzzy search, keyboard nav, raw‑ref, and render caps; Suggested is disjoint. Smart default base with reason + confidence; toolbar shows <head> → <base> and ahead/behind. New routes: /__cmux_diff_viewer_refs (grouped refs JSON, stale‑while‑revalidate) and /__cmux_diff_viewer_branch (regenerate + redirect), mirrored under cmux-diff-viewer://. BranchBasePicker React component with labels and tests; restore‑safe, root‑relative endpoints; source/repo selects size to their selected value; jump‑to‑file hides when the Files sidebar is visible. Bug Fixes Correctness: branch diffs (including deferred Branch) render against the resolved smart base; explicit --base still honored. Fork‑point: don’t use a branch’s own @{upstream}; handle slash names; preserve merge‑base semantics. Reliability and restore: root‑relative picker URLs, manifest reload on miss, lifecycle‑safe custom‑scheme tasks; cached refs; bounded refs scans. Security and stability: session‑scoped repo auth; token‑gated refs/regenerate; dedicated queue + timeout; escaped meta‑refresh; collision‑resistant filenames; flocked manifest writes; pure‑Swift hex encoder. Keeps source/repo switchers after regenerate by rebuilding options on both HTTP and scheme paths. Includes the current base in refsURL so manual bases reappear under Suggested on reopen; repo‑switched pages compute each repo’s smart base and keep the picker. Summary by CodeRabbit Release Notes New Features Added a smarter diff base picker with grouped results, fuzzy search, keyboard navigation, and confidence/reason plus ahead/behind context. Enabled persisted base selection with on-demand branch diff regeneration and updated viewer contract. Improvements CLI process execution now supports an optional working directory. Improved handling of picker/regeneration URLs so query encoding is preserved end-to-end. Updated UI styling and labels for the new picker experience. Documentation Added a design spec for the branch-picker UX. Tests Added picker UI tests covering rendering, filtering, capped lists, and “use raw” selection.