Skip to content

refactor(prune): stream removals, skip unapproved hooks instead of prompting - #2908

Merged
max-sixty merged 2 commits into
mainfrom
prune
May 26, 2026
Merged

max-sixty merged 2 commits into
mainfrom
prune

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

Three changes to `wt step prune`, all pointing the same way — let the scan run end-to-end and react to each result as it arrives.

  • Removability uses the same gate as `wt remove`. Dirty / locked / primary worktrees flunk `prepare_worktree_removal` and drop out silently, before the age check. A young + dirty + integrated worktree (HEAD == default branch, working tree modified) no longer surfaces as `Skipped (younger than 1d)` — the dirty tree would have blocked removal anyway. The `(younger than X)` message now fires only when the worktree would actually have been pruned.
  • Scanning streams instead of batching. One parallel pass per check item bundles integration + removability + age in a single rayon worker. Results flow through a channel; the main thread calls `try_remove` immediately for positives instead of waiting for the full scan to finish. Removals overlap with continued scanning (brief check-lock pause per removal for the Windows `.git/config` race).
  • Hook approval moves out of the way. Prune never prompts inline — that would deadlock against the streaming structure. With `--yes`, every project command is auto-approved. Without `--yes`, already-approved commands run; a candidate whose hooks include any unapproved project command is SKIPPED with `(approval required)` plus a hint pointing at `wt config approvals add` (or `wt -C remove`). Unapproved hooks never run silently.

New `HookPlan::unapproved_project_commands` exposes the templates that gate the approval decision.

Test plan

  • `cargo run -- hook pre-merge --yes` (3867 tests, lints, all green)
  • `test_prune_pre_remove_needs_approval` updated to assert skip-with-hint (not abort)
  • `test_prune_unmerged_pre_remove_is_not_approved` still passes — unmerged worktrees are silently filtered before the approval check, no spurious prompts
  • `test_prune_non_current_removal_does_not_approve_post_switch` still passes — only Current candidates check post-switch
  • `test_prune_runs_pre_remove_hook` (`--yes`) still passes — auto-approval path runs hooks in full
  • Removed `test_approval_prompt_prune_decline` (PTY-based, asserted the old prompt-and-decline path that no longer exists)

🤖 Generated with Claude Code

…ompting

Three changes to `wt step prune`, all pointing the same way — let the scan run
end-to-end and react to each result as it arrives.

Removability uses the same gate as `wt remove`. Dirty / locked / primary
worktrees flunk `prepare_worktree_removal` and drop out of the candidate set
silently, before age. A young, dirty, integrated worktree (HEAD == default
branch, working tree modified) used to print `Skipped (younger than 1d)` —
misleading, since the dirty tree would have blocked removal anyway. Now it's
filtered as not-a-candidate. The `(younger than X)` message fires only when
the worktree would actually have been pruned.

Scanning streams instead of batching. One parallel pass per check item now
bundles integration + removability + age in a single rayon worker. Results
flow through a channel; the main thread processes each as it arrives,
calling `try_remove` immediately for positives instead of waiting for the
full scan to finish. Removals overlap with continued scanning, with a
brief check-lock pause per removal for the Windows `.git/config` race.

Hook approval moves out of the way. Prune never prompts inline — that would
deadlock against the streaming structure. With `--yes`, every project command
is auto-approved as before. Without `--yes`, already-approved commands run;
a candidate whose hooks include any unapproved project command is SKIPPED
with `(approval required)` plus a hint pointing at `wt config approvals add`
(or `wt -C <wt> remove`). Unapproved hooks never run silently. New
`HookPlan::unapproved_project_commands` exposes the templates that gate this
decision; `pessimistic_plan.approve_readonly(...)` produces the frozen plan
`try_remove` consumes.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@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.

Windows build break — approve_readonly is #[cfg(unix)]

src/commands/step/prune.rs:833 now calls pessimistic_plan.approve_readonly(&approvals, project_id) unconditionally, but HookPlan::approve_readonly in src/commands/hook_plan.rs is annotated #[cfg(unix)] (and its module docstring at the top of the file describes it as "the picker, which can't prompt mid-render; #[cfg(unix)]"). The picker — the previous sole caller — is itself #[cfg(unix)] via src/commands/mod.rs, so the gate was never exercised on Windows before. test (windows) is already failing on this PR with:

error[E0599]: no method named `approve_readonly` found for struct `HookPlan` in the current scope
 833 |         pessimistic_plan.approve_readonly(&approvals, project_id)
     | ------------------- method `approve_readonly` not found for this struct

approve_readonly's body has no unix-specific calls (just HookSource/Approvals lookups), so the cleanest fix is to drop #[cfg(unix)] from both the function (hook_plan.rs line ~240) and its approve_readonly_drops_unapproved_project_keeps_user test (line ~467), and to remove the trailing ; #[cfg(unix)]`` from the module-doc sentence on line 41. Happy to push that fix if you'd like — let me know.

Minor: check_lock is dead weight on the dry-run path

In the new dry-run branch (prune.rs:692), check_lock = RwLock::new(()) is constructed and read-guarded by every worker, but no writer ever takes it — try_remove is only called on the live path. The lock has no serialization role to play there. Not a correctness bug; you could drop the RwLock and the per-worker read-guard from the dry-run scope and keep the live path's lock unchanged. Worth mentioning since the comment that travelled with the lock now overstates its job in this branch.

Confirmed safe (read for the record)

  • The streaming live path's overlap is correctly serialized: rayon workers hold check_lock.read() around check_one (which calls integration_reason and prepare_worktree_removal), and try_remove takes check_lock.write() for its entire body. prepare_worktree_removal is called again inside try_remove, so a stale "removable=true" verdict — e.g. if A's removal raced ahead of B's scan — fails closed at the second gate and returns Ok(false) rather than corrupting state.
  • The global needs_approval check (pre_remove_unapproved.is_empty(), etc.) is sound because all candidates resolve hooks from the same invoking-worktree config, so the unapproved-template set is identical across candidates. approve_readonly then drops project entries with any unapproved command, exactly matching the per-candidate skip decision.
  • When --yes, Approvals::default() is fine because unapproved_for_hook is short-circuited to empty and HookPlan::approve(_, true) skips its own approvals load — so a malformed approvals.toml won't abort a --yes run, matching the existing picker/CLAUDE.md contract.

Caught by the auto-reviewer on Windows: the previous sole caller (the
picker) is unix-only, so the gate was incidental. `wt step prune` now
calls it unconditionally to derive its frozen plan without prompting,
and the body has no unix-specific code.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit a2e95db into main May 26, 2026
33 checks passed
@max-sixty
max-sixty deleted the prune branch May 26, 2026 07:09
@max-sixty max-sixty mentioned this pull request May 26, 2026
max-sixty added a commit that referenced this pull request May 26, 2026
v0.54.0.

`cargo semver-checks` reports 3 breaking library API changes
(`shell_exec::set_output_log_available` removed,
`SUBPROCESS_TERMINAL_TARGET` removed, `Deprecations::{pre_start,
post_start}` removed) — none of them intentional API, but they force
minor pre-1.0.

Headline user-visible changes:
- New rate-limit pace segment in the Claude Code statusline (#2899,
#2911).
- `wt step prune` streams removals and skips unapproved hooks instead of
prompting mid-scan; default `--min-age` raised 1h → 1d (#2908, #2910,
#2886).
- `-vv` no longer floods stderr — debug routes to `trace.log`, Info
stays on stderr; raw subprocess sink renamed `output.log` →
`subprocess.log`; `RUST_LOG` honored at every verbosity level (#2892,
#2901, #2913).
- Data-safety fixes across merge / remove / prune lifecycle (#2870).
- Legacy shell-wrapper deprecation warning (#2880).

Full CHANGELOG entry in this PR.
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
worktrunk 0.54.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

- **Rate-limit pace segment in the Claude Code statusline**: `wt list statusline --format=claude-code` now surfaces a yellow `1.3×pace(10am–3pm)` segment when Claude Code's reported five-hour or seven-day rate-limit window is on track to be hit before its reset. The segment uses a Bayesian forecast on `P(final ≥ 100%)` so early-window bursts (e.g., 5% used at 3% elapsed) don't trigger spurious warnings — only the worse-projected of the two windows is shown, and the segment is hidden entirely when both are safe. The clock format inside the parentheses honors `LC_ALL` / `LC_TIME` / `LANG`: `en_US`/`en_PH`/`en_CA` get 12-hour (`10am–3pm`), everything else (including unset and `C`/`POSIX`) gets 24-hour (`10:00–15:00`). ([#2899](max-sixty/worktrunk#2899), [#2911](max-sixty/worktrunk#2911))

- **`wt step prune` streams removals and never prompts mid-scan**: Prune now bundles integration, removability, and age checks into a single parallel pass and starts removing candidates as soon as they qualify, instead of batching the scan and acting at the end. Dirty / locked / primary worktrees drop out before the age check, so a young + dirty + integrated worktree no longer surfaces as `Skipped (younger than 1d)` — the `(younger than X)` message now fires only when the worktree would actually have been pruned. With `--yes`, every project command is auto-approved as before; without `--yes`, a candidate whose hooks include an unapproved project command is SKIPPED with `(approval required)` rather than aborting the scan with an inline prompt the streaming structure couldn't accommodate. The end-of-run hint enumerates the unapproved hook templates from the invoking worktree's config and emits one copy-pasteable `wt -C <path> remove` line per skipped candidate, annotating candidates whose own `.config/wt.toml` differs from the invoking worktree's. ([#2908](max-sixty/worktrunk#2908), [#2910](max-sixty/worktrunk#2910))

- **`wt step prune` default `--min-age` raised from 1h to 1d**: A worktree just created from the default branch looks "merged" because its branch still points at the same commit; a one-day floor keeps an unattended prune from sweeping it up before its owner starts work. Explicit `--min-age=0s` or any other value is unchanged. ([#2886](max-sixty/worktrunk#2886))

- **Legacy shell-wrapper deprecation warning**: Users who upgrade `wt` without restarting their shell still run the previous release's wrapper, which sets only `WORKTRUNK_DIRECTIVE_FILE` instead of the new split `WORKTRUNK_DIRECTIVE_CD_FILE` / `WORKTRUNK_DIRECTIVE_EXEC_FILE` pair. That fallback used to be silent; `wt` now emits a one-shot per-process warning hinting at `wt config shell install`. bash, zsh, fish, and PowerShell pick up the new wrapper on the next shell restart; nushell is the one shell where users must rerun `wt config shell install nu` because its wrapper is a static file. ([#2880](max-sixty/worktrunk#2880))

- **`-vv` no longer floods stderr; raw subprocess sink renamed to `subprocess.log`**: A `-vv` invocation used to spray ~15K lines of stderr per command, forcing a redirect to a file even though `trace.log` already mirrored most of it. The debug-level `log::*` pipeline now writes to `.git/wt/logs/trace.log` at `-vv`; Info-level records (hook output, template expansions, the `Tracing to …` pointer) stay on stderr at every verbosity level. The companion raw-subprocess-bytes file is renamed from `output.log` to `subprocess.log` — the prior name read as "stuff `wt` printed" but actually held uncapped multi-MB subprocess bodies (`git log -p`, patch-id pipelines). `RUST_LOG` is now honored at every verbosity level: `wt -v` and `wt -vv` previously hardcoded Info / Debug and silently dropped any `RUST_LOG` directive (`RUST_LOG=trace wt -vv` was capped at Debug, `RUST_LOG=worktrunk=trace wt -v` was ignored); all three levels now flow through one builder shape with `RUST_LOG` layered on top of the flag baseline. ([#2892](max-sixty/worktrunk#2892), [#2901](max-sixty/worktrunk#2901), [#2913](max-sixty/worktrunk#2913))

### Fixed

- **Data-safety across the worktree merge / remove / prune lifecycle**: Five TOCTOU and scoping fixes. `wt merge` and `wt remove` revalidate cleanliness and branch integration *after* `pre-remove` hooks run, so a hook (or concurrent process) that dirties the worktree or advances the branch can no longer trash the directory or trigger `git branch -D` against the stale pre-hook decision. The background-removal path does the same revalidation and fails closed for submodule worktrees on the fallback path instead of forcing. `wt step prune` runs its rename-failure fallback `git branch -d` synchronously under the write guard for non-current worktrees (no more race against live integration readers on `.git/config`), scopes hook approval to the worktrees it will actually remove (an unrelated unapproved hook can no longer abort a non-interactive prune), and prunes the stale metadata of detached worktrees whose directory was deleted outside Worktrunk. ([#2870](max-sixty/worktrunk#2870))

### Documentation

- **`-v` / `-vv` help and FAQ**: The `-v` help text is split out from its 150-character parenthetical, and `docs/content/faq.md` gains a "What does `-v` / `-vv` do?" section with a three-level table. ([#2913](max-sixty/worktrunk#2913))

- **Hook docs and `pre-start` docstring**: The `pre_create` field docstring in `HooksConfig` (user-visible via generated JSON schema) read "Commands to execute before worktree creation"; `pre-start` actually runs *after* worktree creation, blocking. Restored the correct wording. The `docs/content/extending.md` overview is reworked to read more cleanly: parallel three-paragraph intro for hooks / aliases / custom subcommands, fewer em-dashes, and the Reference section's table no longer duplicates content covered in prose. ([#2879](max-sixty/worktrunk#2879), [#2912](max-sixty/worktrunk#2912))

### Internal

- **Migrated logging from `env_logger` to `tracing-subscriber`**: A layered subscriber routes records structurally by target and verbosity. Existing `log::*` callers are bridged into `tracing` via `tracing_log::LogTracer`. `[wt-trace]` records emit as typed structured fields with a single formatter rendering the wire shape, so the grammar lives in one place instead of being duplicated across every emit site.

- **`UncommittedChanges` error renders dirty files in the canonical gutter**, matching `ConflictingChanges` and the project's `format_with_gutter()` convention. ([#2887](max-sixty/worktrunk#2887))

## Install worktrunk 0.54.0

### Install prebuilt binaries via shell script

```sh
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-installer.sh | sh && wt config shell install
```

### Install prebuilt binaries via powershell script

```sh
powershell -ExecutionPolicy Bypass -c "irm https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-installer.ps1 | iex"; git-wt config shell install
```

### Install prebuilt binaries via Homebrew

```sh
brew install worktrunk && wt config shell install
```

## Download worktrunk 0.54.0

|  File  | Platform | Checksum |
|--------|----------|----------|
| [worktrunk-aarch64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-aarch64-apple-darwin.tar.xz) | Apple Silicon macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-aarch64-apple-darwin.tar.xz.sha256) |
| [worktrunk-x86_64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-x86_64-apple-darwin.tar.xz) | Intel macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-x86_64-apple-darwin.tar.xz.sha256) |
| [worktrunk-x86_64-pc-windows-msvc.zip](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-x86_64-pc-windows-msvc.zip) | x64 Windows | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-x86_64-pc-windows-msvc.zip.sha256) |
| [worktrunk-aarch64-unknown-linux-musl.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-aarch64-unknown-linux-musl.tar.xz) | ARM64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-aarch64-unknown-linux-musl.tar.xz.sha256) |
| [worktrunk-x86_64-unknown-linux-musl.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-x86_64-unknown-linux-musl.tar.xz) | x64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-x86_64-unknown-linux-musl.tar.xz.sha256) |



### Install via Cargo

```sh
cargo install worktrunk && wt config shell install
```

### Install via Winget (Windows)

```sh
winget install max-sixty.worktrunk && git-wt config shell install
```

### Install via AUR (Arch Linux)

```sh
paru worktrunk-bin && wt config shell install
```
</pre>
  <p>View the full release notes at <a href="https://github.com/max-sixty/worktrunk/releases/tag/v0.54.0">https://github.com/max-sixty/worktrunk/releases/tag/v0.54.0</a>.</p>
</details>
<hr>

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