Skip to content

refactor(repo-hygiene): simplify the clean tree-reset scripts and batch-common - #15171

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14718-42884806065-1
Nov 10, 2026
Merged

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14718

Summary

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

Simplified git-tree-reset.sh, git-tree-reset-batch.sh and lib/batch-common.sh without changing behavior (net 23 lines shorter). In git-tree-reset.sh: one branch.<name>.remote read now serves both the unresolved-upstream message and the fetch remote. ahead_count() replaces the two identical rev-list blocks. exit_planned_none() replaces three copies of the PlannedReset/PlannedClean none exit. A BLOCKED_EXIT code replaces the string-prefix re-tests, and one grep replaces the per-line loop that classified a git clean failure. In git-tree-reset-batch.sh: record() emits a per-repo block and counts its outcome, replacing eleven emit-plus-counter pairs, and add_reason() builds the Reason line in place of the discards/note string juggling. In batch-common.sh: batch_take_selection_arg reads --repos-from and --skip-from through one call. A fresh-context review found three edge-case differences (closed stdin, here-strings needing a temp file, merged printfs on a broken stdout). I reverted those edits, so behavior stays exact. I kept the inline repo-resolution loop and the key_seen scan in the batch script: the header and a test comment refer to them, and changing them is cross-file dedup, which the issue puts out of scope.

Not verified

  • The repo-hygiene shell test suites (git-tree-reset.test.sh, git-tree-reset-batch.test.sh, lib/batch-common.test.sh, git-noninteractive.test.sh) were not run directly: this lane's Bash runs only the named wrappers, and check-affected's output does not name which suites it ran. Left to the PR's CI.
  • ci-status green on the PR: left to the PR's CI.
  • Tidy pass 5 (/ai-slop:audit fix on the changelog fragment) could not run its detector or digest guard: this lane's Bash runs only the named wrappers. I read the line against the rubric myself and found no tell. The issue requires that text word for word.
  • Tidy pass 4 (docs-hygiene:write-for-humans on the fragment) skipped: its one prose line is required verbatim by the issue's acceptance criteria, so no edit could apply.
  • Tidy proposal not applied: ahead_count keeps the existing '|| echo 0' fallback (a silent fallback that turns a failed rev-list into 0). Changing it would change behavior.
  • Build/lint step: no separate shellcheck or shfmt run was available beyond check-affected's lints; the CI lanes run them.

Fix

  • plugins/repo-hygiene/skills/clean/scripts/git-tree-reset.sh: ahead_count and exit_planned_none helpers, single BRANCH_REMOTE read, BLOCKED_EXIT in place of string-prefix re-tests, grep -qv in place of the clean-stderr classification loop, printf -v for PRESERVE_SUFFIX, history reference (pre-#460)…
  • plugins/repo-hygiene/skills/clean/scripts/git-tree-reset-batch.sh: record() and add_reason() helpers replace the inline emit+counter pairs and the discards string building; redundant printf '' and return dropped from repo_dirty_reason
  • plugins/repo-hygiene/skills/clean/scripts/lib/batch-common.sh: batch_take_selection_arg reads --repos-from/--skip-from through one batch_read_lines_into call
  • .changes/repo-hygiene/work-resolve-issue-issue-14718-42884806065-1-419e8c84.md: patch fragment, ### Changed, "Internal simplification, no behavior change."

Verification

The runner ran each check from the base copy against 8f05b9b:

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

The run reports:

  • check-changelog-fragments: all 9 fragments valid (run before tidy, after tidy, and after the review reverts)
  • check-changed-skills: clean skill PASS, 0 errors, 4 warnings that predate this change (description length, body size, no Gotchas)
  • check-affected: 13 passed, 6 skipped over 4 changed files (run three times, last after the final edits)
  • fresh-context review subagent: no behavior differences on normal input; three edge-case differences found and reverted (stdin read -u 0 error text, here-string temp-file dependence in the two grep calls, merged printf write-error counts)
  • git-read diff --stat HEAD: 3 scripts changed, 78 insertions, 101 deletions
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42884806065

Left out: the items under Not verified.

Related

#14718

Merge-Risk: max=MEDIUM demote=false head=8f05b9b42b0da08e5beb4e2e1ce5bd30c1cd4e2d rubric=8.3.5 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 8f05b9b42b0da08e5beb4e2e1ce5bd30c1cd4e2d: read 4 of 4 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #15171 (refactor of the repo-hygiene clean tree-reset scripts)

I found no security issues. I read every hunk of all 4 changed files, and none of them matches a trusted-path glob. The PR changes no plugin manifest and no workflow, token, trusted-actor, kill-switch or merge-hold control.

These scripts run git reset --hard and git clean -fdx, so I checked whether the refactor weakens any of the guards that protect local work from being destroyed. All of them still behave as they did on the base:

  • Unresolvable-upstream gate (exit 6). It still runs before any destructive command. The early read of branch.<name>.remote (BRANCH_REMOTE) only feeds the message and the fetch remote, and the fetch remote still falls back to origin (git-tree-reset.sh#L123-L146).
  • Default-branch and unpushed blocks (exits 3 and 4). BLOCKED_EXIT is set inside the same if/elif that sets BLOCKED, so it gives the same results as the old string-prefix checks. exit_planned_none exits before the dry-run and apply paths (#L174-L185).
  • Unpushed re-check after fetch. ahead_count() runs the same rev-list command with the same || echo 0 fallback, so behavior is unchanged (#L110-L115, #L211-L217).
  • Restore guard. clean_restore_tracked_deletions still runs on every path after git clean. It now runs after the failure check is computed rather than before, but it does not depend on that result (#L249-L258).
  • Clean-failure check. The new grep -qv -e '^$' -e 'failed to remove' flags a failure on the same input as the old line-by-line loop: any non-empty line without failed to remove, including a lone \r. If grep itself errored, the run would be reported as exit 0 instead of exit 7. That affects only the reported outcome, not what gets deleted or protected, so it is not a security issue.
  • Batch script. The dirty guard in repo_dirty_reason returns the same text: the dropped return 0 and printf '' sat at the end of the function. record() and add_reason() keep the same counts and reasons, and nothing changes how a repo is chosen, skipped or deleted.
  • batch-common.sh. --repos-from and --skip-from still read into the same arrays as before, and a missing file is still an error. The file mode change from 100644 to 100755 on a sourced library has no security effect.

The diff also removes a code comment ("Never let a literal @{u} reach reset --hard"). That is a comment, not a standing instruction, and the rev-parse --verify gate it described is unchanged in the code.

The PR context contains no embedded instructions aimed at this review.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: no findings. I read every hunk of all 4 changed files. None of them match a trusted-path glob.

I checked each refactor against the base code it replaces. All of them produce the same output and exit codes:

  • git-tree-reset.sh
    • ahead_count keeps the old rev-list pipeline and its || echo 0 / :-0 fallbacks, and still runs in a command substitution.
    • The single BRANCH_REMOTE read uses the same CURRENT_BRANCH key as the two reads it replaces, and nothing writes branch config in between.
    • BLOCKED_EXIT 3 and 4 match the old default-branch* and unpushed-commits* prefix checks.
    • exit_planned_none prints the same two lines.
    • printf -v gives the same suffix.
    • The grep -qv -e '^$' -e 'failed to remove' condition matches the old loop: it flags a failure when stderr has any non-empty line without failed to remove, or when stderr is empty and the exit code is non-zero.
    • The classification now runs before the restore guard. This changes nothing, because the classification has no side effects and the restore guard still runs unconditionally before any output.
  • git-tree-reset-batch.sh
    • record counts would-reset and done as reset, which matches the old single COUNT_RESET increment after the if/else.
    • add_reason builds the same a; b Reason strings from the none start.
    • Ordering is unchanged: the stderr grep still runs before the emit, and child output still prints after the failed emit.
    • repo_dirty_reason still returns 0 and prints nothing on a clean repo.
  • lib/batch-common.sh
    • --skip returns 0 as before.
    • --repos-from and --skip-from pass the array name as a value to batch_read_lines_into, so the nameref _dest cannot collide with the new local dest.
    • The PR does not mention the 100644→100755 mode change. It matches what scripts/check-affected.sh does automatically: it marks every changed *.sh executable (L245). It does not change behavior, so I did not count it as a finding.

Closing issue #14718 criteria:

  • Behavior unchanged: met on reading. The existing repo-hygiene shell suites cover these paths. I did not run them; the PR leaves them to CI.
  • Diff limited to the listed files plus a fragment: met.
  • Under 400 lines and 15 files: met.
  • Fragment: met. It is bump: patch with ### Changed and "Internal simplification, no behavior change." word for word.
  • ci-status green: the author says this is left to CI. Not verified.

The PR's verification claims (check-affected, check-changelog-fragments, check-changed-skills) are the author's and unverified. I ran no tools beyond reading files.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 8f05b9b

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-15171-8f05b9b42b0da08e5beb4e2e1ce5bd30c1cd4e2d, expires on 2026-12-10.

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 10, 2026
Merged via the queue into main with commit 65a0b20 Nov 10, 2026
63 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14718-42884806065-1 branch November 10, 2026 22:00
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit 65a0b209bdee9c648368c4f8cd620c1f43c7d1c4; 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 clean repo-hygiene plugin code (3 of 5)

0 participants