Repository navigation
feat(switch): picker shortcuts — copy branch, open PR, refresh, remap remove to alt-x - #3233
Conversation
…ap remove) Add four keyboard shortcuts to the interactive `wt switch` picker: - alt-y: copy the selected branch name to the system clipboard - alt-o: open the selected row's PR/MR in the browser - alt-r: refresh the worktree list - alt-x: remove the selected worktree (remapped from alt-r) copy and open are native skim Action::Custom callbacks that read the selected row off `App.item_list`, so they run without a reload — no cursor reset and no dropping of `--prs` rows (which aren't in `shared_items`). A side table keyed by each row's `output()` token maps to the row's branch and URL, avoiding unreliable cross-thread downcasting. refresh re-enters the collect pipeline via a new PipelineFactory, extracted so startup and refresh build the pipeline identically. Clipboard (arboard) and browser-launch (open) are new cross-platform deps, gated behind the cli feature; arboard drops its image feature. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Reconciles the picker shortcut remap with #3211, #3214, and #3195, which landed on main after this branch forked and rewrote large parts of the same picker files. The substantive conflict was semantic: #3211 ("keep the alt-r picker row when its target isn't actually removed") was written assuming alt-r = remove, but this branch remapped remove to alt-x and made alt-r refresh. Resolution: - Kept #3211's full remove dispatch (removal_will_remove_target, keep_unremovable_row, restore_failed_removal, the stashed_warnings backstop) and bound it to alt-x; alt-r stays the refresh key. - invoke() now routes `refresh` to PipelineFactory::spawn ahead of #3211's remove path; the `restore` reload still falls through to the re-stream path. - PickerCollector gains both this branch's `factory` and #3211's `stashed_warnings`; test helpers share one factory via a new `test_factory`. - Retargeted #3211's docstrings, comments, and tests from alt-r to alt-x wherever they describe the remove action (refresh references stay alt-r), including the PTY test test_switch_picker_alt_x_keeps_unmerged_branch_row. Gate green: 4202 tests pass, clippy and fmt clean, snapshots and docs in sync. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pulls in #3225, #3221, #3222, #3226. Reconciles the picker shortcut remap with the two picker changes: - #3225 ("repaint the picker preview after the alt-r sticky reposition") rewrote drive_alt_r_then_switch to gate on the cursor pointer instead of the preview pane (fixing a preview-timing flake). Took that more robust assertion but kept this branch's alt-x key; retargeted #3225's docstrings from alt-r to alt-x where they describe the remove path (its production Event::RunPreview repaint merged cleanly and serves alt-x removal). - #3226 added alt-h:ignore / alt-l:ignore binds; these merged alongside the alt-x/alt-r/alt-y/alt-o binds with no conflict. Regenerated the alt_l hscroll snapshot: this branch deterministically renders the picker list with the `Remote⇅ CI` column layout (verified stable over 5 runs), matching the identically-set-up test_switch_picker_with_multiple_worktrees snapshot. #3226's `CI Age` capture was the outlier — main already carries both layouts for the same fixture, a pre-existing timing-sensitivity in column selection that this merge surfaces but does not introduce. Gate green: 4205 tests pass, clippy and fmt clean, docs in sync. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Drop "Alt-y and Alt-o run in the background — the picker stays open" (implicit for in-picker shortcuts) and the "Discrete actions live on Alt" lead-in (redundant with the keybindings table and the existing "plain digits go to the filter" paragraph). Keeps only the non-obvious Alt-o no-op caveat. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
worktrunk-bot
left a comment
There was a problem hiding this comment.
One edge case on the new alt-y copy, inline. Otherwise this looks solid — the alt-r→alt-x remove remap leaves the destructive primitive (SafeDelete via delete_branch_if_safe) untouched and moves remove to a less-reflexive key, so an old-habit alt-r now refreshes rather than removes, which is the safe direction.
…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>
codecov/patch is failing on this commit — per CLAUDE.md, patch coverage gates merge. Dismissing until the coverage gap is addressed or merging-with-gap is explicitly approved. See follow-up comment for the breakdown.
worktrunk-bot
left a comment
There was a problem hiding this comment.
codecov/patch is failing on this commit, so I'm dismissing my approval — per CLAUDE.md, patch coverage gates merge even though GitHub marks it non-required, and an empty-body approval over a red patch check reads as a rubber-stamp. codecov/project passes; this is purely the patch (new-lines) gate.
The gap is concentrated in picker/os.rs and picker/mod.rs, almost entirely in the interactive/OS-effect surface you already flagged in the PR description as headless-hostile:
| File | Misses | What's uncovered |
|---|---|---|
picker/os.rs |
9 | all of copy_to_clipboard / open_url |
picker/mod.rs |
43 | the alt-y / alt-o Action::Custom closures, spawn_shortcut, and the refresh → factory.spawn() arm |
picker/prs.rs |
1 | the GitLab arm of spawn_worktree_comments_fetch |
Most of this is genuinely irreducible — os::copy_to_clipboard / os::open_url and the spawn_shortcut thread wrapper can't run in CI, exactly as the description says. But the bulk of the mod.rs miss is the row → branch/URL resolution inside the two closures, which is pure logic that doesn't need a live App:
table.lock().unwrap().get(m.item.output().as_ref()).and_then(|d| d.branch.clone())Lifting that lookup out of each closure into a small free fn (e.g. resolve_shortcut_branch(&table, token) -> Option<String> and the url.resolve() equivalent) would let a unit test cover the part that actually matters — the side ShortcutTable keyed by output() token, and the detached-worktree no-op — leaving only the thin spawn_shortcut(os::…) call uncovered. That's likely enough to clear the patch threshold, and it directly tests the lookup the shortcut_table_branch_is_none_for_detached_worktree test only checks one half of today.
I can push that refactor + tests if you'd like — say the word and I'll add it to the branch. Alternatively, if you'd rather merge with the OS surface deliberately untested, that's your call to make explicitly (the codecov gate exists to force exactly that decision); I just won't leave a silent approval standing over the red check.
Uncovered lines (from the Codecov compare API)
os.rs:copy_to_clipboard+open_urlbodiesmod.rs: thealt-yclosure (.and_then(|d| d.branch.clone())→spawn_shortcut("picker-copy", …)), thealt-oclosure (url.resolve()→spawn_shortcut("picker-open", …)),spawn_shortcutitself, andmatch self.factory.spawn() { Ok(SpawnedPipeline { rx, .. }) => … }in therefreshbranchprs.rs:Some(CiPlatform::GitLab) => RefKind::Mr
…nd closures Addresses codecov/patch on #3233 (worktrunk-bot review). The `alt-y` / `alt-o` `Action::Custom` closures held their table lookup inline, so the row → branch/URL resolution — pure logic that needs no live skim `App` — was uncovered along with the genuinely-untestable OS calls. Lift the lookups into `resolve_shortcut_branch` / `resolve_shortcut_url` free functions and unit-test them across present / absent-field (detached row, no-URL row) / missing-token cases. Only the irreducible OS surface (`os::copy_to_clipboard` / `os::open_url`, the `spawn_shortcut` thread wrapper) stays uncovered — headless CI can't drive a clipboard or browser. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Implemented your suggested refactor in d20aadb — pulled the row → branch/URL lookup out of the
|
worktrunk-bot
left a comment
There was a problem hiding this comment.
The refactor did its job — resolve_shortcut_branch / resolve_shortcut_url are now fully covered (they've dropped out of the patch miss list), so the row → branch/URL lookup the alt-y / alt-o closures delegate to is unit-tested across the present / detached / missing-token cases.
codecov/patch is still red, though, so I'm dismissing my approval again — same reason as before (CLAUDE.md treats patch coverage as a merge gate despite the non-required mark, and an empty-body approval over a red check reads as a rubber-stamp). What's left (42 missed patch lines) is now confined to the surface headless CI genuinely can't drive, exactly as the PR description called out:
| File | Misses | What's uncovered |
|---|---|---|
picker/os.rs |
9 | copy_to_clipboard / open_url — clipboard + browser |
picker/mod.rs |
30 | the alt-o closure body, spawn_shortcut thread wrapper, and the refresh → factory.spawn() arm — all need a live skim App / pipeline |
picker/progressive_handler.rs |
1 | the comments_fetched.get() → return guard in maybe_spawn_comments (async slot state) |
picker/prs.rs |
1 | the GitLab arm of spawn_worktree_comments_fetch — needs a live PreviewOrchestrator + glab |
So this is now the deliberate "merge with the OS/interactive surface untested" call the codecov gate exists to force — your decision to make explicitly. I just won't leave a silent approval standing over the red check. If you'd rather I take a swing at any of the residual (e.g. threading the ci_platform branch in spawn_worktree_comments_fetch through a unit test for the GitLab arm), say the word.
Codecov compare API, pullid=3233
Overall patch: 906 / 948 hits (≈95.6%). Misses by file from api.codecov.io/.../compare/?pullid=3233: os.rs 9, mod.rs 30, progressive_handler.rs 1, prs.rs 1, items.rs 1.
codecov/patch failing on d20aadb — patch coverage gates merge per CLAUDE.md. Residual gap is the irreducible OS/interactive surface (clipboard/browser, keybind closures, GitLab orchestrator arm); merging over it is the author's explicit call.
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
Adds four keyboard shortcuts to the interactive
wt switchpicker:alt-y— copy the selected branch name to the system clipboardalt-o— open the selected row's PR/MR in the browseralt-r— refresh the worktree list (pick up worktrees created elsewhere)alt-x— remove the selected worktree/branch (remapped fromalt-r)Approach
alt-yandalt-oare native skimAction::Customcallbacks that read the selected row offApp.item_listand run the OS action on a background thread — noreload, so the cursor doesn't reset and--prsrows aren't dropped. A side table keyed by each row'soutput()token maps to the row's branch and URL, which avoids skim's unreliable cross-thread downcasting.alt-rrefresh re-enters the collect pipeline via a newPipelineFactory, extracted so startup and refresh build the pipeline identically; worktrees and branches created outside the session then appear without reopening the picker.The one breaking change is the
alt-r→alt-xremap for remove. It fails safe — an old-habitalt-rnow refreshes rather than removes.Key files
src/commands/picker/mod.rs—PipelineFactory,install_shortcut_keybindings, the refresh branch ininvoke, and the bind blocksrc/commands/picker/os.rs(new) —copy_to_clipboard/open_urlviaarboard+opensrc/commands/picker/items.rs— the row-shortcut side table and the controls linesrc/cli/mod.rs— the keybindings table and help textNew cross-platform dependencies:
arboard(clipboard, with itsimagefeature dropped) andopen(browser launch), both gated behind theclifeature.Testing
Unit tests cover the keybinding wiring, the row → branch/URL resolution, and the refresh/remove dispatch; PTY tests cover the alt-x sticky-cursor reposition and the unmerged-branch-keep path. The OS side effects themselves — the clipboard write and the browser launch — are not asserted (both are headless-hostile in CI), so they want a manual check on a desktop; they work on macOS, with the one documented limitation being X11 without a clipboard manager.