Repository navigation
Conversation
Replace the unanchored substring matcher (first-match-wins, no ambiguity check) with a tiered resolver: exact, anchored (last path segment / sequant issue-number shapes), then quoted-glob. A bare number anchors to the issue-number position so 838 no longer matches feature/1838-other-work, and any tier with 2+ matches exits non-zero listing every candidate instead of tearing down the first. Adds multi-match regression fixtures per documented input form. Closes #844 Entire-Checkpoint: 4af007c1f6ae
4 tasks
Entire-Checkpoint: 418c173730ca
admarble
deleted the
feature/844-cleanup-worktree-unanchored-substring-matcher-can-
branch
July 29, 2026 16:33
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.
Summary
cleanup-worktree.shresolved its<branch>argument with an unanchored substring match, first-match-wins, no ambiguity check — so838matchedfeature/1838-other-workand (since #838 made local+remote deletion work off the resolved ref) tore down the wrong branch on both.This replaces the single
case "$_wt_branch" in *"$BRANCH_NAME"* | $BRANCH_NAME)arm with a tiered resolver, and makes any 2+-way match fatal:feature/838-fix/feature/838-fix-more).parseIssueNumberFromBranchalready recognizes (feature/<N>-*,feature/<N>,issue-<N>,<N>-*). So838anchors to the issue-number position and never matches1838.*/?/[; keeps the documented, quotedfeature/<issue>-*form working, now behind the ambiguity gate.Any tier yielding 2+ candidates prints every candidate (branch + path) to stderr and exits non-zero instead of silently deleting the first. Candidate collection excludes the main worktree (so
'feature/*'/'*'can't resolve to and remove it) andexec-agent-*sub-worktree branches. bash 3.2-safe (no arrays/mapfile; process substitution keeps the match counters in the current shell).Only
templates/scripts/cleanup-worktree.shis edited —scripts/cleanup-worktree.shandscripts/dev/cleanup-worktree.share symlinks to it. The documented skill/doc call sites all use thefeature/<issue>-*glob form, which still resolves to one branch behind the gate, so no SKILL.md sync is required.AC Verification
838≠feature/1838-other-work)AC-1: a bare number anchorsAC-2/AC-4 (bare number)'feature/*') hits the same checkAC-3/AC-4 (glob)andAC-3: a glob matching exactly one#844describe block: bare number, glob, full-name (exact-wins)Mutation verification (gate-test discipline)
Both new gate claims were mutation-verified:
AC-1: a bare number anchorsfailed (900mis-matchedfeature/1900-other→ ambiguous, no resolution). Restored → green.-gt 1fatal branch with first-match-wins → exactlyAC-2/AC-4 (bare number)andAC-3/AC-4 (glob)failed, whileAC-3: a glob matching exactly one branch still resolvesstayed green (correct scoping). Restored → green.Test plan
npm run build— passesnpm run lint— passesbash -n templates/scripts/cleanup-worktree.sh— passesnpx vitest run __tests__/cleanup-worktree-branch-resolution.integration.test.ts— 24 passed (18 existing fix(cleanup-worktree): merge check queries the raw argument, not the resolved branch — every documented invocation reports "PR not merged" #838/fix(cleanup-worktree): aborts mid-way when invoked from inside the worktree being deleted #575/fix(cleanup-worktree): deletes remote branch before PR is merged — closes the open PR unmerged #750 + 6 new)838-spaced(fix(cleanup-worktree): aborts mid-way when invoked from inside the worktree being deleted #575) and unmerged-PR (fix(cleanup-worktree): deletes remote branch before PR is merged — closes the open PR unmerged #750) guards still greenCloses #844