Skip to content

refactor(source-control): simplify worktree-claim.sh - #15271

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14830-42962486454-1
Nov 11, 2026
Merged

melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14830-42962486454-1

Conversation

@melodic-automation-lanes

@melodic-automation-lanes melodic-automation-lanes Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #14830

Summary

Opened by the work-resolve-issue lane. The run's own summary:

Simplified plugins/source-control/scripts/worktree-claim.sh without changing behavior. Each usage error now goes through one die_usage helper, and the per-verb checks moved into the verb-validation case. The claim/release/handover verbs share a linked_index helper for the 'not a registered worktree' and 'refusing to <verb> the main worktree' refusals, and a worktree_git helper handles git lock/unlock failures. resolve_repo_dir is down to three lines, and the final dispatch exits once. Choice and basis: canonicalize_path's command substitutions were kept on purpose, because worktree-gates-spawn-budget.test.sh pins an exact fork count for a claim &lt;path&gt; run. Removing a subshell would change that count, so every edit is fork-neutral.

Not verified

  • worktree-claim.test.sh and the strace spawn-budget test (hooks/worktree-gates-spawn-budget.test.sh) were not run directly: this lane runs only the named wrappers, and check-affected does not list which suites its 13 passes covered. Left to the PR's CI.
  • ci-status green: a PR CI check, left to the PR's CI.
  • tidy: pass 1 (simplify), pass 2 (comments; the new helper comments state side effects and were kept) and pass 3 (residue; none found) ran with no further edits. Pass 4 (write-for-humans) and pass 5 (ai-slop fix) were skipped for the changelog fragment: its one line is mandated verbatim by the…

Fix

  • plugins/source-control/scripts/worktree-claim.sh: added die_usage, linked_index and worktree_git helpers. Folded the usage checks into the verb case plus one-line guards, in the same precedence order and with byte-identical messages. Collapsed resolve_repo_dir, ensure_claim_session, do_report's…
  • .changes/source-control/work-resolve-issue-issue-14830-42962486454-1-588f5d6b.md: patch fragment, '### Changed' / 'Internal simplification, no behavior change.'

Verification

The runner ran each check from the base copy against a28b08a:

  • scripts/check-changelog-fragments.sh --check: passed
  • scripts/check-changed-skills.sh --merge-base: passed

The run reports:

  • check-changelog-fragments: all 23 fragments valid (run before and after the review fix)
  • check-changed-skills: no changed skills, nothing to gate
  • check-affected: 13 passed, 6 skipped (typos not installed; validate-plugins sub-checks that run code from the checked tree; ruff and changed-skills not applicable) over the 2 changed files (run before and after the review fix)
  • fresh-context review subagent over the whole diff: confirmed usage-message text and precedence, exit codes, ${!#} use, || return propagation, the dispatch exit status and fork count all match the original. It found one difference: lock_one returned its final printf's status where the original…
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42962486454

Left out: the items under Not verified.

Related

#14830

Merge-Risk: max=MEDIUM demote=false head=a28b08a09e700005026e6d28eb98fa53b1492903 rubric=8.4.1 rater=claude-opus-5-5 checker=claude-opus-5-5

Lane-Activity: work-resolve-issue/resolve-issue
@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed a28b08a09e700005026e6d28eb98fa53b1492903: read 2 of 2 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #15271, refactor(source-control): simplify worktree-claim.sh

No security issues found. I read every hunk of both changed files: plugins/source-control/scripts/worktree-claim.sh and the changelog fragment. Neither file matches a trusted path.

What I checked

  • Release ownership is unchanged. release still requires a path and a session id before anything runs (the new case arms). The foreign-lock refusal (EX_FOREIGN) in do_release is untouched.
  • Handover checks are unchanged. The new check [[ "$session_id_given" == 1 && -n "$to_session" ]] || die_usage is equivalent to the old ((session_id_given == 0)) || [[ -z "$to_session" ]] guard. session_id_given is only ever 0 or 1 (script lines 300 and 318). --to is still checked against valid_session_id before it reaches worktree_lock_reason. Handover still refuses a lock that carries no reason, and still restores the old lock when relocking fails.
  • Main-worktree refusals still hold. The new linked_index helper keeps the "not a registered worktree" and "refusing to the main worktree" refusals for claim, release and handover. || return passes their exit codes through, and the final exit $? sends them out.
  • Guard ordering is safe. The script runs set -uo pipefail with no -e (line 98), so the one-line cond && die_usage guards cannot exit early by accident. Each guard still exits with EX_USAGE when its condition holds.
  • worktree_git passes arguments safely. It forwards them quoted ("$@"), and ${!#} only picks the path for the error message. I found no new injection surface.
  • resolve_repo_dir still checks the directory with git rev-parse --git-dir before returning it. When no hint is given, . is checked the same way as before.

The script coordinates local worktrees between sessions. It holds no credentials, and this change gives it no new reach to untrusted input, tokens, CI lanes or billing.

Other notes

  • No trust control, merge hold, plugin manifest or instruction surface is touched.
  • The pull request context contains no embedded instructions aimed at this lane.
  • This is the first review of this pull request (blocking only: no).

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed a28b08a09e700005026e6d28eb98fa53b1492903: read 2 of 2 changed file(s); 0 finding(s), 0 as inline comments.

Code review: no findings

I read the whole change in both changed files, plugins/source-control/scripts/worktree-claim.sh and the changelog fragment. I checked the head file against the base hunks for behavior equivalence. I ran nothing; every check below comes from reading the code.

Usage validation

  • The per-verb checks now sit in the verb-validation case and run in the same order as before:
    • claim: path / --all-unclaimed
    • check-enter: path
    • release: path, then session
    • handover: path, then --session-id and --to, then --to validity
  • The shared guards that follow (--to, the three --batch guards, stale path, --idle-minutes, --root, report path) keep their original order. Every message passes through die_usage with identical text and exit 2.
  • session_id_given is only ever 0 or 1, so [[ "$session_id_given" == 1 && -n "$to_session" ]] is the same test as the old ((session_id_given == 0)) || [[ -z ... ]] negation. batch is also only 0 or 1, so "$batch" == 0 matches the old ((batch == 0)).
  • The script runs set -uo pipefail without -e. That makes the cond && die_usage one-liners safe: a false condition just leaves $? at 1 and execution carries on.

Helpers

  • linked_index:
    • When the tree is linked, it returns 0, because an if whose condition is false and has no else exits 0.
    • Otherwise it returns EX_ENV or EX_USAGE with the same refusal text, "hand over" included.
    • do_claim_one used to exit and now does || return. The final exit $? forwards the code, so the result is the same exit code.
  • worktree_git: ${!#} is the last argument, the worktree path, so both the lock and the unlock failure messages match the old text. In do_handover, the restore path after a failed re-lock is unchanged.
  • lock_one ... || rc=$? captures lock_one's own status, which fixes the trap the old comment warned about.
  • do_report and ensure_claim_session keep their return codes: ((unclaimed == 0)) exits 0, and EX_OK=0.
  • resolve_repo_dir: git -C . is the same as running git with no -C. Empty and unset hints both fall back to ., and the subshell count is unchanged, so the spawn-budget test's fork count should hold.

Dispatch

  • Each case / if branch's status is the dispatched function's status, so the single trailing exit $? gives the same codes.

Closing issue #14830

  • Behavior unchanged: met by inspection. worktree-claim.test.sh asserts the exit codes of most of the usage paths and refusals touched here (main-worktree release and handover, --to misuse, all three --batch guards, --root), so a regression there would fail. The PR author says the suite and the strace spawn-budget test were not run; that is unverified and left to CI.
  • Only the listed file plus a fragment changed, and the diff is well under 400 lines: met.
  • Fragment: met. It has bump: patch, ### Changed, and the required line.
  • ci-status green: I can't see it from this lane; left to CI.

Path-scoped rules: no rule in .claude/rules/ has a paths: glob that matches the changed files.

Embedded text: none found in the PR context.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The unattended merge path armed native auto-merge at head a28b08a09e700005026e6d28eb98fa53b1492903, the head its arming checks judged.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for a28b08a

The verifier passed this head. The capture artifact holds the capture summary, which says whether the capture ran, and any screenshot or video that passed the mask check; this comment uploads no file.

Capture artifact: pr-capture-15271-a28b08a09e700005026e6d28eb98fa53b1492903, expires on 2026-12-11.

One comment per pull request, updated in place for each new head.

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Nov 11, 2026
Merged via the queue into main with commit 975250f Nov 11, 2026
63 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14830-42962486454-1 branch November 11, 2026 06:03
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit 975250f00e10e24f4e86d6ee1b3c8269c0c50989; later checks count it verified from this comment.

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.

Simplify the worktree-claim.sh source-control plugin code

0 participants