Skip to content

feat(switch): log + comments preview tabs for --prs picker rows - #3169

Merged
max-sixty merged 9 commits into
mainfrom
pr-preview-tabs
Jun 24, 2026
Merged

max-sixty merged 9 commits into
mainfrom
pr-preview-tabs

Conversation

@max-sixty

@max-sixty max-sixty commented Jun 23, 2026 •

Copy link
Copy Markdown
Owner

Before this, a --prs picker row (PrSkimItem) was built once when gh pr list / glab mr list returned, so only the pr tab had content — the head branch isn't checked out locally, so the log tab showed the "not checked out" placeholder, and there was no comments tab at all. This gives --prs rows two real preview tabs, both loaded in the background, and resolves the two follow-up TODOs left by #3128 (pr-preview-log, pr-preview-comments).

What's new

  • log tab — the PR/MR's commits. When the head commit is already in the local object store (a same-repo PR off a fetched remote), the tab renders the rich local git log — graph, dim/bright merge-base split, and relative timestamps, identical to a worktree row's log tab and sharing its SHA-keyed disk cache, with no network for that row. Otherwise (a fork PR, an unfetched head, or a forge that omits the SHA) it falls back to a flat git log --oneline-style list from the forge API: gh pr view <n> --json commits / glab api …/merge_requests/<n>/commits.
  • comments tab (new tab 7) — the PR/MR's comment thread: author + relative-time header and the body as markdown in the house gutter (the same gutter the PR description uses), via gh pr view <n> --json comments / glab api …/notes?sort=asc (GitLab system notes filtered out).

How it works

Both tabs share a background-fetch mechanism that mirrors the worktree rows' PreviewOrchestrator cache. PreviewOrchestrator::spawn_compute(key, closure) is a general-purpose companion to spawn_preview for rows that aren't worktree ListItems: it runs the closure off-thread on COLLECT_POOL, fills the shared PreviewCache, and shares the pending-counter accounting (so the dry-run path and the cache dump cover PR-row fetches). As each --prs row streams in, spawn_pr_previews kicks off its log + comments fetches keyed by the row's pr:{N} / mr:{N} token (git forbids : in ref names, so it never collides with a worktree row's branch-name key). PrSkimItem::preview is a pure cache read with a loading placeholder on a miss — skim re-queries on selection/tab change, and the fetch fills the slot off-thread.

Local git log when the commit is present

The forge list call now carries the head SHA (GitHub headRefOid, GitLab sha). compute_pr_log peels it with git rev-parse --verify --quiet <oid>^{commit} — which both confirms the object is local and rejects a SHA that resolves to a non-commit — and takes the local path when it resolves. To render it, compute_log_preview_inner was refactored to take a plain (head, branch) pair instead of a worktree ListItem, exposed as compute_log_for_head; the --prs log tab and the worktree/--remotes rows now share one renderer and one SHA-keyed disk cache. A --prs row whose head is local is, for log purposes, just a --remotes row that happens to carry a pr:/mr: token.

Width-aware tab bar

A 7th tab pushes the bar to ~77 columns. skim renders previews with wrapping off (its default), so on a narrow Right-layout preview the bar would truncate on the right — clipping the pr and comments tabs, which are exactly the ones with content on a --prs row. So render_preview_tabs is now width-aware: when the full bar doesn't fit, it falls back to a compact form (1 2: log 3 …) that keeps every Alt-N digit visible and labels only the active tab. Both style signals (dim = empty, bold = active) survive in either form.

Navigating the diff

  • src/commands/picker/preview_orchestrator.rs — spawn_compute.
  • src/commands/picker/prs.rs — the fetch + render of both tabs (fetch_forge_json, compute_pr_log/compute_pr_comments, render_*_commits/render_*_comments), the local-git log probe (local_log), the headRefOid/sha parse into PrEntry::head_oid, the PrsLayout dims, and PrSkimItem's cache read.
  • src/commands/picker/items.rs — the width-aware render_preview_tabs (render_tab_row_full / render_tab_row_compact), TabAvailability, and compute_log_for_head (the (head, branch) refactor of the local log renderer).
  • src/commands/picker/{preview,mod}.rs — PreviewMode::Comments, the Alt-7 binding, the Tab/Shift-Tab 7-way rotation, and the PrsLayout { list_width, preview_dims } wiring.

Notes & trade-offs

  • Each --prs open eagerly queues up to 2 × MAX_PRS (~100) per-PR preview tasks. This is deliberate and matches how the picker already fetches per-row CI status: spawning once (not from preview()) keeps the UI thread's preview() a pure cache read with no in-flight bookkeeping, COLLECT_POOL bounds concurrency, and the picker's lifetime is user-bounded so a slow call never blocks the command. The local-log probe is a single off-thread git rev-parse per row; same-repo PRs that hit it skip the forge call entirely.
  • The local renderer needs a merge-base with the default branch for its dim/bright split. A --prs head that's local but shares no history with the default branch (an orphan-root PR fetched locally) renders the worktree-row "has no commits" message rather than the commit list — a cosmetic degradation in a case that can't arise from a normal PR, so it's left unguarded rather than paying a per-row merge-base probe to detect it.
  • The comments tab is --prs-row only; on a worktree row it dims and points at wt switch --prs, consistent with the dim upstream/summary tabs.

Testing

The render-from-JSON paths (commits, comments, system-note filtering, relative time, the compact-bar width threshold) are unit-tested. log_tab_uses_local_git_log_when_head_present covers the local path against a real repo (present head → graph render; absent SHA → None so the API takes over), and the full background fetch → cache pipeline is covered end-to-end via the WORKTRUNK_PICKER_DRY_RUN path with mocked gh/glab for both forges: test_switch_prs_dry_run_github_log_tab_local asserts a present headRefOid renders the log with the forge pr view rigged to fail, and the GitHub/GitLab deferred-tab tests cover the Some(non-local) and None fallbacks to the forge API.

This was written by Claude Code on behalf of max

max-sixty and others added 3 commits June 22, 2026 18:02
A `--prs` picker row is built once when `gh pr list` / `glab mr list`
returns, so before this change only the `pr` tab had content — the head
branch isn't fetched locally, so its `log` tab showed the "not checked
out" placeholder.

This adds a per-row background fetch so the `log` tab loads the PR's
commits, mirroring the worktree rows' `PreviewOrchestrator` cache:

- `PreviewOrchestrator::spawn_compute(key, closure)` is a general-purpose
  companion to `spawn_preview` for rows that aren't worktree `ListItem`s.
  It shares the same `PreviewCache`, `COLLECT_POOL` routing, and
  pending-counter accounting (so the dry-run `wait_for_idle` and the
  cache dump cover PR-row fetches). A `None`/empty result isn't cached,
  so a transient forge failure retries on the next visit.
- As each `--prs` row streams in, `spawn_pr_previews` kicks off the log
  fetch keyed by the row's `pr:{N}` / `mr:{N}` token (git forbids `:` in
  ref names, so it never collides with a worktree row's branch-name key).
- `compute_pr_log` fetches commits from the forge API — `gh pr view <n>
  --json commits` (GitHub) or `glab api …/merge_requests/<n>/commits`
  (GitLab) — and renders a `git log --oneline`-style list, newest-first.
- `PrSkimItem::preview` reads the shared cache for the `log` tab, with a
  loading placeholder on a miss (skim re-queries on selection/tab change).

Remote-branch rows (`--remotes`) already have a working `log` tab from a
local `git log`; this only fills the gap for `--prs` rows.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Adds a 7th preview tab — `comments` — to the interactive picker, showing
the selected PR/MR's discussion thread. Like the `log` tab, it loads in
the background through the shared preview cache:

- `compute_pr_comments` fetches the thread from the forge API —
  `gh pr view <n> --json comments` (GitHub) or
  `glab api …/merge_requests/<n>/notes?sort=asc` (GitLab, system notes
  filtered out) — and renders each comment with an author + relative-time
  header and its body as markdown in the house gutter, the same gutter the
  PR description uses.
- The tab is `--prs`-row only; on a worktree row it dims and points at
  `wt switch --prs`, the same pattern as the dim upstream/summary tabs.

Because skim renders previews with wrapping off (its default), a 7th tab
would push the `pr` / `comments` tabs — exactly the ones with content on a
`--prs` row — off the right edge of a narrow Right-layout preview. So the
tab bar is now width-aware: when the seven full-form tabs don't fit, it
falls back to a compact form (`1 2: log 3 …`) that keeps every `Alt-N`
accelerator visible and labels only the active tab. The two style signals
(dim = empty, bold = active) survive in both forms.

`Alt-7` jumps to the tab; Tab / Shift-Tab cycle through all seven with
wraparound.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Polish pass over the log/comments preview-tab change:

- Factor `fetch_forge_json` (root-resolve + run + success-check) so
  `compute_pr_log` / `compute_pr_comments` reduce to picking args and a
  renderer, and `markdown_in_gutter` shared by the description and comment
  bodies.
- Pass `--paginate` to the GitLab `commits` / `notes` calls so a long
  thread or commit list isn't capped at GitLab's default page size,
  matching `gh`'s complete `--json` result.
- Add GitLab dry-run coverage (`test_switch_prs_dry_run_gitlab_deferred_tabs`)
  asserting the `mr:7` Log + Comments cache entries — the GitLab forge half
  the unit tests (canned JSON straight into the renderers) can't reach.
- Add a tab-bar width-threshold boundary test and an empty-body comment
  test.
- Document the eager 2×N per-row fetch as a deliberate tradeoff, note the
  controls line is intentionally left to clip, narrow "discussion thread"
  to "comment thread" (GitHub's `comments` is conversation-level), and
  tidy the compact tab renderer + a DashMap value-clone for consistency.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
max-sixty and others added 2 commits June 22, 2026 23:58
…head is present

A --prs row's `log` tab fetched its commits from the forge API
(`gh pr view --json commits` / `glab api …/commits`), producing a flat
oneline list with no graph or merge-base dimming. When the head commit is
already in the local object store — a same-repo PR off a fetched remote — the
tab now renders the rich local `git log` instead: graph, dim/bright merge-base
split, and relative timestamps, identical to a worktree row's `log` tab and
sharing its SHA-keyed disk cache. No network for that row.

The forge list call carries the head SHA (GitHub `headRefOid`, GitLab `sha`);
`compute_pr_log` peels it with `git rev-parse --verify` and takes the local
path when it resolves, falling back to the API otherwise (fork PRs, unfetched
heads, or a forge that omits the SHA).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The GitHub log-tab dry-run test now sends a `headRefOid` that isn't in the test
repo's object store, so `compute_pr_log`'s local-`git log` probe misses and the
row falls back to the forge API. That exercises the `head_oid = Some(non-local)`
branch end to end; the present-head fast path keeps its own
`_local` test and the absent/None branch stays covered by the comments and
GitLab dry-run tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
max-sixty and others added 4 commits June 23, 2026 09:45
Post-review follow-ups on the --prs log/comments preview tabs:

- Remove verify_captures, a 467KB Mach-O binary committed by accident
  alongside the forge-fallback test; it is referenced nowhere.
- Correct the docstrings/comments that claimed a failed deferred fetch
  "retries" on the next visit. The fetch is spawned once per row and
  preview() only reads the cache, so a forge failure leaves the slot
  empty and the tab keeps its loading placeholder until the picker
  reopens -- there is no in-session retry. Same for the empty-list
  rationale, which caches a terminal info line rather than "retrying".
- Delete the stale TODO(pr-preview-comments); this PR implements it.
- Extend test_switch_prs_dry_run_github_log_tab_local to assert a failed
  comments fetch leaves the cache slot empty (the present local-log entry
  proves the row streamed, so the absent comments entry is a real miss).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Resolves overlap with #3167 (PR/MR title+description in the worktree pr
pane), which moved the description renderer into a new `pr_pane` module and
refactored `preview()` into a testable `render_preview`:

- Comments share `pr_pane::markdown_in_gutter` (extracted from
  `pr_pane::description`) instead of a local helper, so the house-gutter
  idiom lives in one place.
- Ported the width-aware tab bar and the `comments` tab arm into main's
  `render_preview`.
- Dropped the now-implemented pr-preview-log / pr-preview-comments TODOs.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
A failed log/comments forge fetch leaves the tab on "Loading…" for the
session with no retry. Record the planned fix — cache a terminal
"couldn't load" pane on failure (which would also cover the orphan-root
local-head case) — as TODO(pr-preview-fetch-error).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit b3e1fc0 into main Jun 24, 2026
34 checks passed
@max-sixty
max-sixty deleted the pr-preview-tabs branch June 24, 2026 02:10
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
worktrunk 0.62.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## Release Notes

### Improved

- **Browse open PRs/MRs in the `wt switch` picker, with live CI**: The picker now streams a live CI/review-status column per row — priming from the local cache, then fetching live (it previously showed only cached numbers with no network). A new `--prs` flag adds the repository's open PRs (GitHub) / MRs (GitLab) as rows alongside your worktrees, each with `pr` / `comments` / `log` preview tabs loaded from the forge in the background; selecting one fetches its branch and switches. Rows whose branch is already shown aren't duplicated, so `--prs` differs from plain `wt switch` only by the extra rows. [Docs](https://worktrunk.dev/switch/) ([#3128](max-sixty/worktrunk#3128), [#3169](max-sixty/worktrunk#3169), [#3189](max-sixty/worktrunk#3189), [#3252](max-sixty/worktrunk#3252))

- **`main…±` diff column shows by default in `wt list`**: The `main…±` column (lines changed since the merge-base with the default branch) now renders in the default `wt list` and picker, served from a persistent cache rather than a history walk. `--full` now adds only the columns that reach off-machine — CI status and LLM branch summaries — and `wt list --format=json` populates `main.diff` for every item, not just under `--full`. ([#3236](max-sixty/worktrunk#3236))

- **`[list] columns` selects and orders the columns `wt list` shows**: A new `[list] columns` user-config key (also settable via `--config-set`) takes an ordered array of column names — built-in (`branch`, `status`, `ci`, `path`, …) and `[list.custom-columns]` headers alike — and renders exactly those, in that order. Where v0.61.0's custom columns *add* columns, this *selects and reorders* the whole set; omit the key for the default layout. (`WORKTRUNK__LIST__COLUMNS` isn't supported yet and warns if set.) ([#3141](max-sixty/worktrunk#3141))

- **Picker PR preview shows full PR/MR detail**: The `pr` tab now renders the PR/MR title, markdown description, author, draft state, comment count, bold branch name, and underlined URL for any row whose branch has an open PR — not just `--prs` rows — and the `comments` tab fetches the real thread. The title and description ride the CI fetch the picker already makes; the comment thread is fetched lazily in the background, once per row. ([#3167](max-sixty/worktrunk#3167), [#3197](max-sixty/worktrunk#3197), [#3223](max-sixty/worktrunk#3223), [#3195](max-sixty/worktrunk#3195), [#3231](max-sixty/worktrunk#3231))

- **Interactive picker runs on Windows**: The `wt switch` picker was Unix-only because its preview-tab keys shelled out through a per-process state file `cmd.exe` lacks; tab state moved to an in-memory atomic with native skim callbacks, lifting the platform gate. ([#3217](max-sixty/worktrunk#3217))

- **Picker keyboard shortcuts**: `Alt-y` copies the selected branch name, `Alt-o` opens the row's PR/MR in the browser, and `Alt-r` refreshes the list (picking up worktrees created or removed elsewhere). (Breaking: in the picker, remove moved from `Alt-r` to `Alt-x`) ([#3233](max-sixty/worktrunk#3233))

- **Picker uses the full terminal**: List height scales with the terminal (a roughly even split with the preview, minimum 3 rows) instead of a fixed 12-row cap, the table lays out at full width so toggling the preview off with `Alt-p` reveals the freed columns with no reflow, and a scrollbar appears when the list overflows. ([#3205](max-sixty/worktrunk#3205), [#3214](max-sixty/worktrunk#3214), [#3198](max-sixty/worktrunk#3198))

- **Picker filters on more of each row**: Typing a gutter sigil filters by row kind (`+` for linked worktrees, `@` for the current one), the fuzzy matcher ranks on the distinguishing path segment rather than the shared parent prefix, and rows with a PR/MR also match on its number, title, and author. ([#3143](max-sixty/worktrunk#3143), [#3208](max-sixty/worktrunk#3208), [#3252](max-sixty/worktrunk#3252))

- **Picker visual polish**: The legend recolored to dim-cyan and reordered so navigation leads, and preview loading placeholders moved to the dim-hint style (`↳` transient, `○` settled, `▲` failed). ([#3237](max-sixty/worktrunk#3237), [#3253](max-sixty/worktrunk#3253))

- **"Still waiting" status for slow commit-message generation**: A configured `commit.generation` command captures stdout, so a slow or hung LLM previously showed nothing while `wt step commit`/`squash` waited. After a 2s delay worktrunk now shows a dim, in-place `○ Waiting for the commit message (Ns)` status, escalating at 10s to reveal the exact shell-escaped invocation in a gutter beneath it; the block clears on completion, mirroring `wt list`'s stall footer. ([#3178](max-sixty/worktrunk#3178))

- **"Still waiting" status extended to more slow commands**: The same waiting status now covers three more foreground commands that were silent while a captured subprocess ran — the `wt config show --full` commit-generation self-test, the `wt switch pr:`/`mr:` host lookup, and the `wt config show --full` version check. The version check no longer caps its fetch at an aggressive 5s, instead showing the status while a slow-but-working request completes (with a generous ceiling so a non-interactive run can't hang). ([#3183](max-sixty/worktrunk#3183))

- **`wt config state logs profile` performance profiler**: A new subcommand turns a `-vv` `[wt-trace]` capture (a path argument, `-` for stdin, or the default `trace.log`) into a performance profile: subprocess time by command shape, the slowest calls, parallelism and peak concurrency, redundant cache-miss re-runs, and — for `wt list`/picker captures — derived latencies and a collect timeline. `--format=json` emits the same data, and every `-vv` bug-report bundle now inlines a rendered profile. ([#3184](max-sixty/worktrunk#3184), [#3186](max-sixty/worktrunk#3186))

- **`WORKTRUNK_VERBOSE` env var**: `WORKTRUNK_VERBOSE=0|1|2` mirrors `-v`/`-vv`, combined with any flag via `max` (the env sets a floor the flag can raise). Unlike the flags it's honored on the shell-completion path, which returns before flag parsing — so a slow tab-completion can be profiled for the first time. ([#3166](max-sixty/worktrunk#3166))

- **Aliases inherit the wrapped command's completion**: An alias that forwards `{{ args }}` to a single `wt` command (`co = "wt switch {{ args }}"`) now completes that command's arguments and flags — `wt co <Tab>` completes branches like `wt switch <Tab>` — instead of a generic stub. Bare dispatchers and multi-`{{ args }}` aliases keep the stub. ([#3172](max-sixty/worktrunk#3172), thanks @yzx9)

- **`wt step copy-ignored --require-include`**: A new `--require-include` flag makes the copy a no-op unless a `.worktreeinclude` file exists in the source worktree (matching Claude Code desktop, where that file is required), reporting why it skipped as a hint in text mode and a `reason` field in `--format=json`. ([#3196](max-sixty/worktrunk#3196), thanks @yzx9)

- **`wt step tether` honors `-C`**: The global `-C <path>` flag now sets the tethered command's working directory (`wt step tether -C frontend -- npm run dev`); teardown still watches the worktree root, so the command is reaped when the worktree is removed. ([#3207](max-sixty/worktrunk#3207))

- **Statusline rate-limit pace color grades by severity**: The pace segment's color now deepens (dim → dim-yellow → yellow) with the projected throttling severity, so an early-window burst stays muted while a costly projected lockout stands out. The displayed pace number is unchanged. ([#3229](max-sixty/worktrunk#3229))

### Fixed

- **Picker `Alt-x` removal updates the row in place**: Removing a worktree no longer re-collects the whole list (a flicker that reset the cursor to the top): an unmerged worktree's row morphs into a branch-only row while the worktree is removed in the background, and a merged worktree's row drops with the cursor landing on the row that slid up. A removal that can't safely happen — the current or main worktree, or a dirty or locked one — is declined with the same diagnostic `wt remove` prints, rather than a dead keypress or a disruptive `cd` home. The post-removal cursor lands by row identity, so it stays correct even under an active filter. ([#3262](max-sixty/worktrunk#3262), [#3199](max-sixty/worktrunk#3199), [#3211](max-sixty/worktrunk#3211), [#3225](max-sixty/worktrunk#3225))

- **Picker preview refreshes when its background fetch lands**: A diff/log/PR-view fetch that completed after its triggering keystroke used to sit unshown until the next keypress; the pane now updates on its own when the fetch lands. ([#3247](max-sixty/worktrunk#3247))

- **Picker rows stay aligned while filtering**: Typing a filter no longer slides the matched row left and drops its leading sigil, and `Alt-l`/`Alt-h` no longer scroll the list off its gutter. ([#3213](max-sixty/worktrunk#3213), [#3226](max-sixty/worktrunk#3226))

- **fish completions no longer recurse to the call-stack limit**: With worktrunk's fish lazy-load wrapper installed, co

See merge request: Harmonybrew/homebrew-core!12862
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.

2 participants