Repository navigation
feat(switch): unify picker preview tabs and dim empty diff tabs - #3223
Conversation
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>
# 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>
worktrunk-bot
left a comment
There was a problem hiding this comment.
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.
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>
|
Heads up: The single failure is |
`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
left a comment
There was a problem hiding this comment.
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.
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>
|
The red The three failures are all in Required |
…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>
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
What this does
This makes the interactive
wt switchpicker's preview tab bar reflect each row's real data, instead of row-type policy or always-on assumptions. Two related changes:--prsonly decides which rows are listed — not which tabs a row shows or how a tab behaves. Thecommentstab is the clearest case: previously a worktree row's comments tab just pointed the user at--prs("Comments show onwt switch --prsrows"), while a--prsrow's showed the real thread. Now a worktree row whose branch has an open PR fetches and renders the same thread.working_tree,branch_diff, andupstreamno longer show a bright (selectable) number over a "nothing here" pane.Part 1 —
--prsonly controls listingThe preview tabs split along two genuine data axes, and
--prstouches neither:LocalTabsrather than a--prsflag.prandcomments) — 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-codedcommentsdifferently between row types) is gone.from_axes(LocalTabs, has_pr)is the single constructor;commentsavailability now equalspravailability 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 backgroundgh pr view <n> --json comments/glab api …/notesfetch a--prsrow makes, read back from the shared preview cache.Part 2 — diff tabs dim once their diff is known empty
The same
TabAvailabilitysystem markedworking_tree/branch_diff/upstreamas 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
prtab 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:git diff HEAD— staged/modified/renamed/deleted, not untracked (whichgit diff HEADdoesn't show); a branch-only row has no working tree, so it's empty immediately.item.counts) — deliberately the same base the pane diffs against (default_branch_sha()), nothas_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.has_upstreamfloor (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
LocalContentslot, mirrored from the row'sListIteminon_updateexactly like the existingpr_statusslot — the frozen item snapshot theWorktreeSkimItemholds can't carry them (itscounts/upstream/working_tree_statusareNoneat skeleton and never update).Where to look
src/commands/picker/items.rs—TabAvailabilityreshaped aroundLocalTabs+from_axes;LocalContent(the live diff-content signals) + theworktree(...)mapping that dims a diff tab once its signal is known empty;render_comments_panerenders the fetched thread when the branch has a PR.src/commands/picker/prs.rs—spawn_comments_fetchis the shared comments-fetch path for both row types;spawn_worktree_comments_fetchpicks 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 newlocal_content) primed at skeleton and mirrored from eachListItemas 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_itempredicates (including untracked-only → empty and thehas_upstreamfloor), and the loading-vs-known availability mapping; a snapshot pins the rendered bar with every diff tab dimmed. Theon_updateslot mirroring is covered through the existing handler test. The end-to-end PTY tests drive a realwt switchand confirm the worktree comments tab renders the actual thread with no--prspointer.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_listrecorded…main↕ CI Age, inconsistent with its siblingswitch_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 currentmainHEAD too (verified by buildingorigin/mainand running the test). Regenerated to match.