Skip to content

refactor(guardrails): simplify block-dangerous-git and block-exported-msys-pathconv hooks - #15161

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

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14473

Summary

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

In block-dangerous-git.sh, the two passes over a git clean argv (a dry-run pre-scan, then a force scan with the same exclude and -e bundle skipping) are now one pass. It counts force flags and calls block_clean_force that many times once dry-run is ruled out, so the number and order of block and telemetry calls stay the same. Two restore case arms that the --s* | --w* abbreviation arm already covered are gone, and so is a comment paragraph that only told the history of an earlier wording. In block-exported-msys-pathconv.sh, a one-arm case with a no-op default and its comment is now a single \[\[ \]\] test. The shared jq_rc pattern stays as it is, because six sibling guards use it and changing it in one file would break that shared shape before the planned cross-file pass.

Not verified

  • The guardrails hook test suites (block-dangerous-git and block-exported-msys-pathconv tests) were not executed: this lane runs only named wrappers, so they are left to the PR's CI
  • shellcheck and the CI-only hook scanners (hook-slow-shapes, killswitch-hoist, cant-fail-scan against a base) were not run here: left to the PR's CI
  • tidy: the ai-slop pass's detector (detect.sh) is not among the commands this lane may run, so it was skipped. The changelog fragment's one line was read against the rubric by hand and showed no tells. Passes 1-4 ran and made no edits.

Fix

  • plugins/guardrails/hooks/block-dangerous-git.sh: merged the two clean argv scans into one that counts force flags; dropped the redundant --staged/--worktree arms in the restore scan; removed a history-only comment paragraph; added forced to check_segment's locals
  • plugins/guardrails/hooks/block-exported-msys-pathconv.sh: replaced the one-arm case in leaks_into_child_shell with an equivalent \[\[ \]\] test
  • .changes/guardrails/work-resolve-issue-issue-14473-42880217584-1-66190f6f.md: new patch fragment, ### Changed / Internal simplification, no behavior change.

Verification

The runner ran each check from the base copy against 68a6692:

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

The run reports:

Left out: the items under Not verified.

Related

#14473

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

Security review: PR #15161 (head 68a6692)

I found no security issues. This pull request refactors two guardrails hooks, and the main risk was that it could quietly weaken a block. I checked each change against the head file and found no change in what gets blocked or allowed.

plugins/guardrails/hooks/block-dangerous-git.sh: the clean arm, two scans merged into one (L1155-L1201)

  • Words skipped: the old force scan skipped words the same way the dry-run scan did: -e, -e?*, --exclude=, a bare --exclude prefix (which also skips the next word), and an -e bundle (the next word too when the bundle ends in e). The new single loop skips the same words.

  • The one difference, the --no-* arm: the new loop now runs continue there, which skips the force check. In the old force scan, a --no-* word could never count as force:

    • abbrev_match "force" fails on it, because the remainder no-… is not a prefix of force (L276-L283).
    • The second - stops ^-[A-Za-z]+$ and the e-bundle pattern from matching.
    • abbrev_match "exclude" fails too, so it never consumed a word.

    So the two scans still skip the same words, and --no-force still does not count as force.

  • Force count: forced counts the hits from both force checks. Each hit then calls block_clean_force once, only after ((dry)) && return 0. That gives the same number of calls with the same arguments as before.

    • When the hook exits 2 unattended, the first call ends the run, as before.
    • The old scan's only side effects were these calls and their repo_is_temp_scratch probes, so moving the calls after the loop changes no other behaviour.
  • Shell details: forced is added to check_segment's local list (L787), and no other code in the hooks reads it. ((++forced)) always exits 0, so set -e cannot abort on it.

The restore arm (L1339-L1348): the PR removes the --staged and --worktree arms. Both words still hit the --s* | --w* arm, which sets staged=1 (abbrev_match "staged" … 2) or worktree=1 (abbrev_match "worktree" … 1). The flag values match the old arms, so the decision to block a worktree-wide restore . is unchanged.

Removed comment paragraph (base L384-L391): it only recorded history. It took no rule out of the guard's logic.

plugins/guardrails/hooks/block-exported-msys-pathconv.sh (L306): a one-arm case with a no-op default became [[ … || … ]] && seen=1. It matches the same two patterns and sets the same state. A failed test inside an && list does not trigger errexit, and the function still ends in return 1.

Changelog fragment (.changes/guardrails/…66190f6f.md): a patch bump with prose only. It has no security surface.

Other checks:

  • Instruction-surface lens: no rule the guard enforces was deleted, narrowed or softened. The edits are equivalent rewrites plus the removal of a history-only comment. I did not consult the protected-class register, because no removed rule needed it.
  • Manifests and trusted paths: no plugin manifest changed, and no changed file matches a TRUSTED PATHS glob.
  • PR context: the PR text contains no embedded instructions aimed at this lane.
  • Spend: none.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: no findings

I read every hunk in all 3 changed files and checked whether each change keeps the old behavior. I compared the code at head with the base code shown in the diff. I did not run anything, so the CI and test results quoted in the PR body are the author's claims and I have not confirmed them.

block-dangerous-git.sh: the two clean scans are now one (lines 1155-1201)

  • The old second (force) scan skipped the same words as the first scan: -e, -e?*, --exclude[=…] and its abbreviations, and e bundles. The only difference was the --no-* arm, which the first scan alone had. That arm cannot change force detection: abbrev_match "force" "--no-…" is false because "force" never starts with no-, and ^-[A-Za-z]+$ cannot match a word that starts with --. So the merged scan counts the same force flags.
  • ((dry)) && return 0 still runs before any block_clean_force. Each force word still produces exactly one call, so the block count, the telemetry and the unattended exit 2 on the first call all stay the same.
  • ((++forced)) uses pre-increment, so it never returns a non-zero status. The for (( ; forced > 0; forced--)) form is valid bash. forced was added to check_segment's locals, so it cannot leak across recursive alias re-checks.

restore arms: the removed --staged and --worktree arms are handled the same way by the --s* | --w* arm, through abbrev_match "staged" … 2 and abbrev_match "worktree" … 1.

block-exported-msys-pathconv.sh: the [[ … || … ]] && seen=1 test behaves the same as the one-arm case. A false test inside an && list does not trigger errexit or an ERR trap, and return 1 follows the loop.

Closing issue #14473: the acceptance criteria are met.

  • Only the two listed files and one changelog fragment are edited.
  • The diff is well under 400 lines.
  • The fragment has bump: patch, ### Changed, and the exact line "Internal simplification, no behavior change."
  • Tests could catch a behavior change. block-dangerous-git.test.sh:389-403 covers the shapes the merge touches: -fen, -f -e --dry-run, --dry-run --no-dry-run -f, --no-dry-run -n -f and -f --ex --dry-run. There are 7 cases for restore --staged/--worktree, and block-exported-msys-pathconv.test.sh exercises MSYS2_ARG_CONV_EXCL=.
  • I can't confirm "ci-status is green" from here.

Other notes

  • No embedded instructions were found in the PR context.
  • No plugin manifest changed.
  • There is nothing that costs money or calls for a hold.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 68a6692

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-15161-68a6692f34c57ffbcf6ca917e46cbab87bcf1a54, 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 e64e5d8 Nov 10, 2026
72 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14473-42880217584-1 branch November 10, 2026 20:54
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit e64e5d8eb087d13a24f9338583829a61a7bc193e; 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 hooks guardrails plugin code (2 of 7)

0 participants