feat: wt audit + wt prune --merged#9
Merged
Merged
Conversation
Port the standalone wt-audit script into the CLI as a first-class command. `wt audit` classifies every registered worktree by how its branch relates to the base ref (origin/main) — delete-merged, delete-consolidated, keep-open-pr, keep-wip, review-uncommitted, review-merged-diverged, review-closed-pr — and prints a copyable `wt remove` for the trees that are unambiguously safe. Deletion safety is grounded in git, not PR state: a tip is deletable when it is reachable from the base ref (merge or squash) or folded into another retained local branch, and is never suggested when the worktree has real uncommitted work. - src/core/audit.ts: framework-free classification + git/gh signal gathering, reading the registry in-process (no self-exec of `wt list --json`); base ref and ignored-dirty paths are parameters, not hardcoded tokenbooks specifics. - src/commands/audit.ts + cli.ts: `wt audit [--json] [--no-fetch] [--base <ref>] [--ignore-dirty <paths...>]`. - Tests: pure verdict matrix, PR-state ranking, porcelain parsing, report rendering, and real-git/real-worktree integration for merge/squash detection. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Build on `wt audit` so the deletion-safe verdicts can be acted on in one step. - core/audit: add `findDeletableWorktrees`, the discovery half shared with prune (resolve base → fetch → PR map → audit → keep only delete-merged/-consolidated). - prune: `--merged` removes live worktrees the audit confirms safe (db drop + docker + `git worktree remove` + registry), in a separate loop so existing prune behavior is untouched. Honors --dry-run/--keep-db; gone paths stay the mechanical missing-path prune's job; never touches worktrees with dirty work. - docs: README + skills/wt/SKILL.md document `wt audit` and `wt prune --merged`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a first-class
wt auditcommand and awt prune --mergedcompanion that acts on its verdicts — folding the standalone tokenbookswt-auditscript into the CLI.wt auditClassifies every registered worktree by how its branch relates to the base ref (
origin/main→main) and prints a copyablewt removefor the trees that are unambiguously safe. Deletion safety is grounded in git, not GitHub PR state: a tip is deletable when it's reachable from the base ref (merge or squash) or folded into another retained local branch — and never when the worktree has uncommitted work.Verdicts:
delete-merged,delete-consolidated,keep-open-pr,keep-wip,review-uncommitted,review-merged-diverged,review-closed-pr.ghPR state is advisory context when available.wt audit [--json] [--no-fetch] [--base <ref>] [--ignore-dirty <paths...>]wt prune --mergedRemoves the live worktrees the audit confirms safe (db drop + docker +
git worktree remove+ registry), in a separate loop so existing prune behavior is unchanged. Honors--dry-run/--keep-db; gone paths remain the mechanical missing-path prune's job; never deletes uncommitted work.Tests (TDD throughout)
findDeletableWorktrees.wt auditandwt prune --merged.Docs
README +
skills/wt/SKILL.mddocument both commands.