Skip to content

refactor(guardrails): simplify run-guards.sh dispatcher - #15313

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

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14484

Summary

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

Simplified plugins/guardrails/hooks/run-guards.sh with no behavior change. The substitution-count and over-length caps now read the command text from one extraction, and the over-length flag is computed first, so the quote-aware recount reuses it instead of measuring the length again. The status folding (2 wins, else highest non-zero), which record and run_rest each repeated, is now one helper, run_guards::fold_rc. The per-iteration local __rg_path in run_from moved to the function's local line. Lines the tests inject after (the guard::abort_boundary run-guards line, # --- run ---, PRIME_FILTERS) and every existing function name stay as they were.

Not verified

  • plugins/guardrails/hooks/run-guards.test.sh, abort-boundary.test.sh and the other guard suites that drive run-guards.sh were not run here (the lane runs no interpreter); left to the PR's CI
  • cant-fail-scan wrapper run with no arguments timed out after 2 minutes; it is a CI-only check (scripts/check-cant-fail-scan.sh <base>) and is left to the PR's CI
  • tidy-diff: the run-guards.sh rows were dropped because a script wired as a hook command is on tidy's GLOBAL HARD exclusion list (hard_exclusions resolves to enforce); passes 1-3 had no rows left, and passes 4-5 were skipped on the changelog fragment because its body is the verbatim text the issue…
  • ci-status green is an acceptance item checked on the PR, not in this run

Fix

  • plugins/guardrails/hooks/run-guards.sh: one shared extraction of the command text for both caps; RUN_GUARDS_OVERLONG computed before the substitution check and reused in its recount condition; new run_guards::fold_rc replaces the duplicated status fold in run_guards::record and…
  • .changes/guardrails/work-resolve-issue-issue-14484-42989285313-1-5a357b6c.md: patch fragment, ### Changed with "Internal simplification, no behavior change."

Verification

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

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

The run reports:

  • check-changelog-fragments: all 6 fragments valid
  • check-changed-skills: no changed skills, nothing to gate
  • check-affected: 13 passed, 6 skipped (no .py, typos not installed, validate-plugins arms that run checked-tree code, no changed skill), over 2 changed files
  • fresh-context review subagent compared the new file with HEAD's: no input or state found where stdout, stderr, exit code, files written, flags or function names differ; test anchors in run-guards.test.sh and abort-boundary.test.sh still match. It reported two nits, neither changed: a guard exiting…
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42989285313

Left out: the items under Not verified.

Related

#14484

Merge-Risk: max=MEDIUM demote=false head=c5b0475899f65f20b671d340a3e9aeb9ed2ac9d9 rubric=8.4.2 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-review reviewed c5b0475899f65f20b671d340a3e9aeb9ed2ac9d9: read 2 of 2 changed file(s); 0 finding(s), 0 as inline comments.

Code review: no findings. I read every hunk of both changed files (plugins/guardrails/hooks/run-guards.sh and the guardrails changelog fragment). I also read the code around each change in the file at head.

Is the behavior the same? (closing issue #14484, "Behavior is unchanged")

  • One shared command extraction (run-guards.sh#L590-L628): _rg_text comes from the same source as before. That is the primed field .tool_input.command, or the whole RUN_GUARDS_INPUT when the payload is unprimed. The old over-length check read the same two values.
    • RUN_GUARDS_OVERLONG is now set before the substitution block, but nothing in that block reads it except the recount condition. That condition had the same length test inline. run_guards::verdict (L297) does not read it, and no guard in the plugin reads it either.
    • LC_ALL=C is set only as a local inside count_subst/counted_text (L425). So both length measurements still run in the shell's own locale, as before.
    • unset _rg_text now runs after both blocks, and nothing between them reads _rg_text.
  • run_guards::fold_rc (L948-L956): it uses the same rule both copies had (a 2 always wins; otherwise the highest non-zero status). It is defined at top level before run_from and run_rest run, including in the --report fresh dispatcher. The death path (guard_died → record) gains one shallow function frame, which is negligible next to the existing calls.
  • local __rg_path hoisted in run_from: same scope. The variable is assigned on every pass through the loop before anything reads it, so nothing changes.

Other acceptance criteria

  • Only the listed file plus a changelog fragment edited: met.
  • Size: about 30 changed lines in 1 hand-edited file, well within the 400-line / 15-file limit.
  • Fragment: it has bump: patch, a ### Changed heading and the exact line "Internal simplification, no behavior change.", so it meets the fragment criterion.
  • ci-status green: left to CI.
  • Tests: the author says run-guards.test.sh and abort-boundary.test.sh were not run in the lane. That is the author's claim and I could not check it. I confirmed equivalence only by reading the code; I ran nothing.

Rules and manifests

  • The path-scoped rule .claude/rules/mod-authoring.md matches plugins/*/hooks/**. It concerns hooks modules and hooks.json "modules", and this change touches neither, so nothing applies.
  • No plugin manifest changed.
  • No paved-path or prior-findings items apply.

@github-actions

Copy link
Copy Markdown
Contributor

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

Security review: PR #15313 (refactor(guardrails): simplify run-guards.sh dispatcher)

No security issues found. I read every hunk of both changed files: plugins/guardrails/hooks/run-guards.sh and the changelog fragment. Neither file matches a TRUSTED PATHS glob. I still reviewed the dispatcher closely because it is the guard hook that decides whether tool calls are blocked.

This refactor removes no checks. I read the head file around L590-L628 and L933-L1073, and the head code gives the same block or allow decision as the base in every case:

  • Text both length checks read. The base had one check for the number of command substitutions and a separate check for over-long commands, and each read the command text on its own. The head reads it once, under the condition STDIN_RC == 0 && (MAX_SUBST || MAX_CMD). That condition covers both base checks: the substitution check runs whenever MAX_SUBST && STDIN_RC == 0 holds, so _rg_text is always set by then. It comes from the same source as before: the primed .tool_input.command field, or else the whole raw payload.
  • Over-length flag. The head now sets RUN_GUARDS_OVERLONG before the substitution check, from the same expression the base used (MAX_CMD && ${#text} > MAX_CMD). The base condition !((MAX_CMD && ${#_rg_text} > MAX_CMD)) that guarded the quote-aware recount is now !RUN_GUARDS_OVERLONG, which is equal inside that block because both require STDIN_RC == 0. The flag is now set to 0 before the substitution check's BLOCKED exit. That exit path never reads the flag; the only readers are at L973 and L1013.
  • Exit-code helper run_guards::fold_rc. It replaces two identical copies of the logic that combines exit codes: a 2 always wins, otherwise the highest non-zero code is kept. Its inputs are the same as before: $__rg_rc in record, and a BASH_REMATCH match limited to [0-9]+ in run_rest. So nothing new reaches the arithmetic evaluation. A report with no status line still sets RC=2 and the call is still denied.
  • local __rg_path in run_from. Moving it to the function's local line changes nothing: every loop iteration assigns it before use. The exit() override and record still see it through bash's dynamic scoping.

Other checks:

  • Instruction-surface lens: not applicable. The diff deletes or weakens no block list or allowlist.
  • Plugin manifests: none changed.
  • Trust controls: none touched. No token, kill switch or merge-hold change.
  • PR context: contains no embedded instructions aimed at this lane.

critical-findings: 0

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for c5b0475

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-15313-c5b0475899f65f20b671d340a3e9aeb9ed2ac9d9, 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 8f53c4b Nov 11, 2026
72 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14484-42989285313-1 branch November 11, 2026 09:32
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit 8f53c4bf12642b6d5e569b2f5c43c9548bed416b; 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 run-guards.sh guardrails plugin code

0 participants