Skip to content

feat(switch): unify picker preview tabs and dim empty diff tabs - #3223

Merged
max-sixty merged 8 commits into
mainfrom
unify-picker-pr-tabs
Jun 25, 2026
Merged

max-sixty merged 8 commits into
mainfrom
unify-picker-pr-tabs

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

What this does

This makes the interactive wt switch picker's preview tab bar reflect each row's real data, instead of row-type policy or always-on assumptions. Two related changes:

  1. --prs only decides which rows are listed — not which tabs a row shows or how a tab behaves. The comments tab is the clearest case: previously a worktree row's comments tab just pointed the user at --prs ("Comments show on wt switch --prs rows"), while a --prs row's showed the real thread. Now a worktree row whose branch has an open PR fetches and renders the same thread.
  2. The diff tabs dim when their diff is empty — working_tree, branch_diff, and upstream no longer show a bright (selectable) number over a "nothing here" pane.

Part 1 — --prs only controls listing

The preview tabs split along two genuine data axes, and --prs touches neither:

  • Local-checkout tabs (working-tree, branch-diff, upstream, summary) — present on a worktree row, empty on a listed-PR row because it has no local copy. This is the only legitimate content difference, now expressed as LocalTabs rather than a --prs flag.
  • PR-backed tabs (pr and comments) — available together, gated by whether the row's branch has an open PR.

TabAvailability::pull_request() (the special-case that forced the reduced treatment and hard-coded comments differently between row types) is gone. from_axes(LocalTabs, has_pr) is the single constructor; comments availability now equals pr availability on every row, so the comments tab behaves identically regardless of how the row got listed. The substance: a worktree row whose branch has an open PR fetches and renders the real comment thread — the same background gh pr view <n> --json comments / glab api …/notes fetch a --prs row makes, read back from the shared preview cache.

Part 2 — diff tabs dim once their diff is known empty

The same TabAvailability system marked working_tree / branch_diff / upstream as available on every worktree row, regardless of content — a clean working tree, a branch with no commits ahead, or one up to date with its upstream all rendered a bright number over an empty pane.

These three tabs now follow the row's live diff content, reusing the loading-then-dim shape the pr tab already uses: available while the signal is still loading (so nothing dims prematurely during the async window — strictly the old always-bright behavior), dim once the diff is known empty. Each predicate mirrors exactly what its pane renders, so a dimmed number never contradicts a non-empty pane:

  • working-tree tracks git diff HEAD — staged/modified/renamed/deleted, not untracked (which git diff HEAD doesn't show); a branch-only row has no working tree, so it's empty immediately.
  • branch-diff follows the commits-ahead count vs the local default branch (item.counts) — deliberately the same base the pane diffs against (default_branch_sha()), not has_file_changes, which measures against the integration target and could dim the tab over a non-empty pane when the local default is stale vs its upstream. An orphan (no merge base) is kept available.
  • upstream combines the synchronous has_upstream floor (no tracking ref dims immediately, with no loading window) with the live ahead/behind — a present-but-even upstream dims too.

The async signals are carried by a new per-row LocalContent slot, mirrored from the row's ListItem in on_update exactly like the existing pr_status slot — the frozen item snapshot the WorktreeSkimItem holds can't carry them (its counts / upstream / working_tree_status are None at skeleton and never update).

Where to look

  • src/commands/picker/items.rs — TabAvailability reshaped around LocalTabs + from_axes; LocalContent (the live diff-content signals) + the worktree(...) mapping that dims a diff tab once its signal is known empty; render_comments_pane renders the fetched thread when the branch has a PR.
  • src/commands/picker/prs.rs — spawn_comments_fetch is the shared comments-fetch path for both row types; spawn_worktree_comments_fetch picks the forge CLI from the repo's platform (not the PR reference's #/! sigil — # is shared by GitHub, Gitea, and Azure).
  • src/commands/picker/progressive_handler.rs — the per-row live slots (pr_status, comments, and the new local_content) primed at skeleton and mirrored from each ListItem as the list pipeline lands.

Testing

Unit tests cover the comments-tab states, the once-per-PR / re-fetch-on-number-change comments guard, the LocalContent::from_item predicates (including untracked-only → empty and the has_upstream floor), and the loading-vs-known availability mapping; a snapshot pins the rendered bar with every diff tab dimmed. The on_update slot mirroring is covered through the existing handler test. The end-to-end PTY tests drive a real wt switch and confirm the worktree comments tab renders the actual thread with no --prs pointer. CLAUDE.md's Network Access inventory records the worktree-row comments fetch.

This branch also refreshes one pre-existing stale PTY snapshot surfaced by merging main: switch_picker_alt_l_ignored_list recorded …main↕ CI Age, inconsistent with its sibling switch_picker_multiple_worktrees_list (…main↕ Remote⇅ CI) even though the alt-l test asserts it captures "the same frame." The render had since settled on the sibling-consistent frame but the snapshot was never regenerated — it fails on current main HEAD too (verified by building origin/main and running the test). Regenerated to match.

This was written by Claude Code on behalf of max

Make `--prs` decide only whether the interactive picker lists open PR/MR
rows. The preview tab set and per-tab behavior are now the same whether or
not `--prs` was passed, and the same between a worktree row and a
listed-PR row — content differs only where the data legitimately does (a
row with no local checkout).

The `comments` tab is the crux: a worktree row whose branch has an open PR
now fetches and renders the real comment thread (the same background
`gh pr view --json comments` / `glab api …/notes` fetch a `--prs` row
makes), instead of pointing the user at `--prs`. `TabAvailability` is
reshaped around two genuine axes — the local-checkout tabs (`LocalTabs`)
and the PR-backed tabs gated by `has_pr` — so `comments` availability
equals `pr` availability on every row; the `pull_request()` special-case
is gone.

The comments fetch picks its forge CLI from the repo's platform (not the
ambiguous `#`/`!` sigil) and caches a terminal "not available" pane on
forges without comments listing. It runs once per PR, keyed by branch
name, and re-fetches if the live CI fetch corrects the PR number so the
comments and pr tabs stay on the same PR.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
max-sixty and others added 2 commits June 24, 2026 20:39
# Conflicts:
#	src/commands/picker/progressive_handler.rs
The interactive picker's preview tab bar marked the working-tree,
branch-diff, and upstream tabs as available (bright number) on every
worktree row regardless of whether the tab had anything to show — a clean
working tree, a branch with no commits ahead, or one up to date with its
upstream all rendered a bright number over a "nothing here" pane.

These three tabs now follow the row's live diff content, the same
loading-then-dim shape the `pr` tab already uses: available while the
signal is still loading (so nothing dims prematurely), dim once the diff
is known empty. Each predicate mirrors exactly what its pane renders, so a
dimmed number never contradicts a non-empty pane — working-tree tracks
`git diff HEAD` (staged/modified/renamed/deleted, not untracked),
branch-diff follows `has_file_changes`, and upstream combines the
synchronous `has_upstream` floor (no tracking ref dims immediately) with
the live ahead/behind. A new per-row `LocalContent` slot, mirrored from
the `ListItem` in `on_update` like `pr_status`, carries the async signals
the frozen item snapshot can't.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@max-sixty max-sixty changed the title feat(switch): unify PR-preview tabs across worktree and --prs rows feat(switch): unify picker preview tabs and dim empty diff tabs Jun 25, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dimming feature is clean and well-tested — working_tree (excludes untracked, matching git diff HEAD) and upstream (the has_upstream floor plus the safe loading-then-dim shape) line up with their panes. One inline note on branch_diff, where the predicate and the pane can pick different diff bases in the diverged/behind-upstream case.

Comment thread src/commands/picker/items.rs Resolved
The branch_diff dimming used `has_file_changes`, which measures against
the integration target — the upstream when the local default branch is
behind or diverged from it. The branch_diff pane diffs against the local
default (`default_branch_sha()`), so when local main was stale vs its
upstream a branch already integrated upstream could dim the tab while its
pane still showed a `local_main...branch` diff — dimming over a non-empty
pane, the one case the module invariant rules out.

Gate the dimming on the commits-ahead count instead (`item.counts`, which
the AheadBehind task measures against the same local default the pane
uses), keeping an orphan available (its three-dot diff has no merge base).
The invariant now holds in every case.

Addresses the auto-reviewer's note on PR #3223.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Heads up: code-coverage is red on f4f71e5, but it's an unrelated PTY snapshot flake — a rerun should clear it.

The single failure is integration_tests::switch_picker::test_switch_picker_alt_l_does_not_hscroll (snapshot switch_picker_alt_l_ignored_list, 2051 passed / 1 failed). It captures the list panel, which this PR doesn't touch — code-coverage passed on the previous commit (317c17a), the incremental diff since is confined to branch_diff dimming + a unit test (no change to list-row rendering, keybindings, or that snapshot), and the sibling test_switch_picker_with_multiple_worktrees that asserts the same list frame passed in this same run.

max-sixty and others added 3 commits June 24, 2026 21:52
`switch_picker_alt_l_ignored_list` (added by #3226) recorded `…main↕ CI Age`,
inconsistent with its sibling `switch_picker_multiple_worktrees_list`
(`…main↕ Remote⇅ CI`) — even though the alt-l test binds alt-l/alt-h to ignore
and asserts it captures "the same frame `test_switch_picker_with_multiple_worktrees`
snapshots." The render has since settled on the sibling-consistent frame (the
Remote⇅ column), but #3226's snapshot was never regenerated, so it fails on
current main HEAD too (verified by building origin/main and running the test —
same `Remote⇅ CI` diff). This is a pre-existing stale snapshot surfaced by
merging main, not a regression from this branch.

Regenerate it to match the current frame, which is byte-identical to the
multiple-worktrees frame as the test intends.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
worktrunk-bot
worktrunk-bot previously approved these changes Jun 25, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test (windows) failed on a real bug in this PR's new test, not a flake — dismissing my earlier approval until it's fixed.

test_switch_picker_worktree_row_comments_tab_shows_thread builds PATH with a hardcoded : separator. On Windows the separator is ;, so mock-bin:<rest> collapses into one invalid entry, the mock gh is never found, the comments fetch falls through to the real CLI / no CLI, and the pane shows ▲ Couldn't load comments. The test then times out waiting for Looks solid (Linux and macOS pass — : is correct there).

The sibling helper added with the Windows-enablement work (setup_mock_forge around line 1116) already solved exactly this with split_paths / join_paths, and its comment spells out the hazard: "a hardcoded : corrupts the PATH on Windows." This test predates that fix and was missed. The inline suggestion mirrors the helper — happy to push it if you'd rather I just commit it.

@worktrunk-bot
worktrunk-bot dismissed their stale review June 25, 2026 05:32

CI failed — test (windows) is a real failure in this PR's new test (hardcoded : PATH separator breaks the mock gh on Windows), not a flake. Re-approve once fixed.

`test_switch_picker_worktree_row_comments_tab_shows_thread` prepended the
mock-`gh` directory to PATH with a hardcoded `:`. On Windows the separator is
`;`, so the join corrupts PATH, the mock `gh.exe` is never found, and the
worktree row's comments fetch fails — the tab renders "Couldn't load comments"
instead of the thread, timing out the 30s wait for the comment body. Passed on
Linux/macOS (where `:` is correct) but failed `test (windows)` once #3221
enabled the picker tests there.

Switch to `std::env::split_paths`/`join_paths` (the OS separator), matching the
`--prs` mock helper in this file.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@worktrunk-bot

Copy link
Copy Markdown
Collaborator

The red affected tests (windows, advisory) check is an unrelated Windows infra flake, not a regression in this PR — approval stands.

The three failures are all in integration_tests::statusline, which this PR doesn't touch (the diff is the switch-picker dimming feature plus the comments-tab PATH fix). They're subprocess-launch failures under Windows runner pressure, not logic failures: test_statusline_rate_limit_5h_24h_locale reports cargo metadata failed in D:\a\worktrunk\worktrunk: command failed with exit code: 0xc0000142 (STATUS_DLL_INIT_FAILED), and the other two panic at fixture/output boundaries that depend on a child process succeeding (Repository::at(&root).unwrap() in TestRepo setup, and .expect("should be valid JSON") on empty statusline output). All three landed in the same instant.

Required test (linux) and test (macos) are green, and affected tests (linux, advisory) passed; test (windows) was still running at the time of this note. A rerun of the advisory job should clear it.

@max-sixty
max-sixty merged commit 11d525d into main Jun 25, 2026
36 of 37 checks passed
@max-sixty
max-sixty deleted the unify-picker-pr-tabs branch June 25, 2026 06:02
max-sixty added a commit that referenced this pull request Jun 25, 2026
…rees

Merge: pulls in #3231, #3223, #3229, #3227, #3157. #3223 (unify preview tabs
+ dim empty diff tabs) added `comments_fetched` / `local_content_slots` to
`PickerHandler`; threaded both through `PipelineFactory::spawn`'s handler
construction and combined the `items` import with this branch's shortcut
types. Regenerated the `empty_all_local_diffs` preview snapshot (#3223's new
snapshot captured the pre-shortcut controls line).

Fix (review feedback from worktrunk-bot on #3233): `alt-y` on a detached
worktree row copied the literal `"(detached)"` — the `branch_name()` fallback
the side table stored. `RowShortcutData.branch` is now `Option<String>`,
carried from the row's raw `ListItem.branch` (and `Some(head_branch)` for
`--prs` rows); the `alt-y` callback `.and_then`s it, so a detached row no-ops
just as `alt-o` no-ops on a row with no PR. Covered by
`shortcut_table_branch_is_none_for_detached_worktree`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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