Repository navigation
feat(switch): rework the alt-x picker removal — morph in place, decline current worktree, identity cursor - #3262
Conversation
…ranch Removing a worktree from the picker (alt-r) silently kept the branch when it was unmerged — SafeDelete retains unmerged work, but the removal runs while skim owns the terminal, so nothing said the branch survived. The branch-only keep path already explains itself; the worktree-removal path did not. The background removal thread now observes the branch after the silent removal (still present, and unmerged against its target — the same "observe reality" check as removal_target_still_present, defaulting to HEAD to match the removal's own fallback) and stashes the canonical "retained; unmerged" info + hint the branch-only keep path shows, via a shared stash_retained_unmerged_branch helper so the two paths can't drift in wording. Also replaces three hardcoded 5s child-exit waits in the picker PTY tests with a documented CHILD_EXIT_TIMEOUT (30s): under heavy CI load a slow but successful switch was killed before it exited, and a killed process reports exit 1 on Windows — a spurious failure of test_switch_picker_alt_r_keeps_cursor_sticky. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
# Conflicts: # src/commands/picker/mod.rs
alt-x on a worktree whose branch is unmerged removes the worktree but keeps the branch (SafeDelete declines unmerged work). The picker used to stash a "retained; unmerged" message and drain it to stderr after exit, so the user only learned the branch survived once they left the picker. Now the background removal pins the surviving branch in a shared orphaned_branches set and fires a refresh reload. The re-collect re-includes the now-worktree-less branch, so its row transforms in place from a `+` worktree row to a `/` branch-only row while the picker is still open. An integrated branch that do_removal already deleted fails the exists_locally check, so its row stays gone. Supporting changes: - collect gains pinned_branches: branch-only rows that surface even with show_branches off, filtered against the live branch and worktree inventories so a stale pin can't produce a phantom row. `wt list` always passes an empty set. - PipelineFactory::spawn takes a `fresh` flag. The refresh re-collect builds a fresh Repository (RepoCache never invalidates) so the removed worktree's branch reads as worktree-less rather than stale; the initial spawn reuses the prewarmed repo. - Removes branch_retained_as_unmerged and the now-unused compute_integration_reason import; retained_unmerged_branch_messages now serves only the branch-only keep path. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Resolved two files: - tests/integration_tests/switch_picker.rs: kept main's `abort_and_exit_code` helper refactor and applied this branch's `CHILD_EXIT_TIMEOUT` (30s) inside it, so main's structure and the Windows kill→exit-1 flake fix both survive. - src/commands/picker/mod.rs: adopted main's `rebuild_repo`/`spawn_repo` fresh-`Repository` mechanism (eebbea9) — which independently fixes the same refresh-staleness bug and additionally threads the per-spawn repo into `PickerHandler` — and layered this branch's `orphaned_branches` / `pinned_branches` row-transform on top, dropping the now-redundant local fresh-repo block. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…cting
Removing a worktree whose branch is unmerged keeps the branch, but it
rebuilt the whole picker list: the new `/ branch` row teleported to the
branch section and the cursor snapped to the top — jerky on every alt-x.
The row now morphs in place through the same rendered-mutex channel the
progressive cell updates use: flip the gutter `+` to `/`, swap the row's
shared `rendered`/`local_content` slots to the branch line, set a shared
`morphed` flag so `output()` returns the branch token, and re-key the
alt-y/alt-o shortcut entry. No reload, no re-sort, no re-collect — the row
stays at its index and the cursor never moves. The git removal runs in the
background; only if the worktree unexpectedly survives does the row revert,
with a "kept … could not remove it" warning.
`worktree_removal_keeps_branch` predicts the kept branch synchronously,
mirroring `delete_branch_if_safe`'s integration check so the prediction
can't drift from the actual delete. The old refresh-based machinery
(`orphaned_branches`, `pinned_branches`, the `Reload("refresh")`
re-collect) is deleted — one path, not two.
`removal_target_still_present` now probes the worktree's `.git` entry
rather than `path.exists()`: removing the current worktree leaves an empty
placeholder dir behind (so the shell's $PWD stays valid until the wrapper
cd's away), which `path.exists()` mistook for a surviving worktree and used
to spuriously revert the morph. Probing `.git` tells a real worktree from
the placeholder, and is immune to a silently-failed `prune_worktrees` and
to a stray `.DS_Store` landing in the placeholder during cleanup.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
# Conflicts: # src/commands/picker/mod.rs
… why unremovable rows stay alt-x on the current worktree (the @ row) now keeps the row and explains, rather than removing the worktree the shell is standing in. That removal had to cd elsewhere first, swap an empty placeholder under the cursor mid-render, and let a post-switch hook stream into the picker frame. Declining the case deletes the whole changed_directory cd-home machinery: no placeholder, no Repository rebuild, no hook intrusion, and removal_target_still_present is back to a plain worktree_path.exists(). Rows that error in prepare_removal (the main worktree, a dirty or locked worktree) now surface the same diagnostic wt remove prints, drained to stderr on picker exit, instead of swallowing the keypress as a silent dead alt-x. Tests: current-worktree keep, unremovable-diagnostic surfacing, and two multi-row cursor-landing PTY tests (drop and keep paths). The existing sticky test removed an edge row where scroll_by's clamp masked a one-row overshoot; the new tests remove a mid-list row with two rows below, where an overshoot is not clamped, pinning exactly where the selector lands after alt-x. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
#3259 unified WorktreeSkimItem + PrSkimItem into one PickerRow (worktree-backed data behind `local: Option<LocalCheckout>`, selection via a precomputed `output_token`). Re-homed this branch's alt-x morph feature onto that structure: the `morphed` flag moves into LocalCheckout, and PickerRow::output() returns the bare branch name for a morphed worktree row, otherwise output_token. Test rows adopt main's worktree_test_row helper. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The reposition after an alt-x removal scrolled to the removed row's shared_items index. Under an active fuzzy query skim's item_list is filtered and reordered, so that index pointed at the wrong row — the cursor jumped +N rows down (N = filtered-out rows above the cursor), worst on a second removal as the offset compounds. Reposition by row identity instead: reposition_cursor_action takes a target token and walks item_list to it (last row when absent — a removed last row, or a neighbor the reload also dropped). alt-x moves from the string bind to a native [capture, reload]: the capture callback peeks the row displayed just below the selected one before the reload resets the cursor, and the drop path lands on it; the keep/morph/restore paths land on their own row's token. Drops sticky_reposition_target. Adds test_switch_picker_alt_x_lands_on_neighbor_under_filter (decoys filtered out above a removed keeper — fails on the index-based reposition, passes on identity). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
Reviewed the rework end-to-end. It's a clean separation: the dispatch reacts to an already-computed RemoveResult (keep-current / morph / drop / keep-unmerged), and the actual deletion path (do_removal → delete_branch_if_safe, BranchDeletionMode) is untouched — so this changes how the picker reflects a removal, not what gets deleted. worktree_removal_keeps_branch mirrors delete_branch_if_safe's integration check exactly, and the optimistic morph reverts only when the worktree survives, which is the safe direction. The current-worktree change is a net safety improvement: declining alt-x on the @ row is better than the old cd-home-then-remove of the worktree you're standing in. Docs, help snapshot, and the unit + PTY tests (morph, drop, current-worktree keep, unremovable diagnostic, and the filter-aware cursor landing) all line up with the behavior.
I have no actionable findings. Not approving because this edits the deletion surface (do_removal/delete_branch_if_safe in src/commands/picker/mod.rs), which per repo policy is held for your call — already satisfied here since you authored it. Flagging it explicitly rather than rubber-stamping; the merge decision is yours.
Reviewed by worktrunk-bot. The data-loss-surface hold is the only reason this is a comment and not an approval.
#3259 renamed WorktreeSkimItem to PickerRow (and the morphed flag moved to LocalCheckout); four doc comments still linked the old type, failing `cargo doc -Dwarnings` on the branch's first CI run. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Release v0.62.0 — minor bump (`cargo semver-checks` reports a breaking library-API change — `ListConfig.columns` added a public field, which requires at least a minor pre-1.0 — plus many new features). ### Highlights - **`wt switch --prs`** — browse open PRs/MRs in the interactive picker, with a live CI/review column and `pr` / `comments` / `log` preview tabs ([#3128](#3128)). [Docs](https://worktrunk.dev/switch/) - **Interactive picker now runs on Windows** ([#3217](#3217)). - **`main…±` diff column shows by default** in `wt list`; `--full` now adds only the off-machine columns (CI status, LLM summaries) ([#3236](#3236)). - **`[list] columns`** selects and orders the columns `wt list` renders ([#3141](#3141)). - **`wt config state logs profile`** performance profiler ([#3184](#3184)). - Picker keyboard shortcuts (copy / open / refresh) and the `Alt-x` removal rework, fish completion-recursion fixes, `CLAUDE_CONFIG_DIR` support, and more. **Breaking:** in the picker, remove moved from `Alt-r` to `Alt-x` (`Alt-r` now refreshes). Two "Still waiting" entries ([#3178](#3178), [#3183](#3183)) were moved here from 0.61.0 — they landed after the v0.61.0 tag, so they ship in 0.62.0. The changelog also documents the `Alt-x` removal rework ([#3262](#3262)); the tag will be placed on the `main` tip that includes both this release commit and #3262. Full notes in the `CHANGELOG.md` diff. Data-loss surface review of the cumulative diff in progress; the keyword pass came back clean (the new `Alt-x` removal uses safe variants — `SafeDelete`, no force, approval-gated). > _This was written by Claude Code on behalf of max_
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
Overhauls the
wt switchpicker'salt-x(remove) so a removal updates the selected row in place instead of re-collecting the whole list, declines removals that can't safely happen with an explanation, and lands the cursor on the right row afterward — including under an active filter.What changes for the user
alt-xon a row now behaves by what the removal does:/ branchrow (worktree gone, branch kept); the worktree removal runs in the background. No flicker, cursor stays put.@), main, dirty, locked → kept, with the same diagnosticwt removeprints (drained to stderr on picker exit) instead of a silent dead keypress or a disruptive cd-home.Before,
alt-xre-collected the entire list (a visible flicker, cursor reset to top), and removing the current worktree forced acdelsewhere mid-render.The cursor fix (last commit)
The post-removal reposition scrolled to the removed row's index in the full
shared_itemslist. Under a fuzzy query, skim'sitem_listis filtered and reordered, so that index pointed at the wrong row — the cursor jumped +N rows down (N = filtered-out rows above it), compounding on a second removal. Reposition is now by row identity: it walksitem_listto the target row'soutput()token. The drop's landing row (the display-neighbor) is captured before the reload via a nativealt-xbinding ([capture, reload]); keep/morph/restore land on their own row's token.Reviewing
The bulk is
src/commands/picker/mod.rs. Key pieces:invokedispatch (removal_targets_current_worktree→worktree_removal_keeps_branch→removal_will_remove_target) decides keep / morph / drop.morph_and_remove_in_backgrounddoes the in-place row morph (optimistic, reverted if the worktree unexpectedly survives).reposition_cursor_action/install_remove_keybindingare the identity-based cursor landing.Testing
Picker unit tests plus PTY integration tests through real skim, including the new
test_switch_picker_alt_x_lands_on_neighbor_under_filter(removes a row with filtered-out decoys above it — confirmed to fail on the old index-based reposition and pass on identity). Multi-row cursor tests cover both drop and keep paths.