Skip to content

refactor(guardrails): simplify five hook scripts without behavior change - #15311

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

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14482

Summary

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

Simplified four of the five listed guardrails hooks with no behavior change. block-windows-drive-tmp.sh now fills two operand helpers in place instead of through command substitution, which removes a fork per segment. It also collapses the redundant return-0/return-1 branches, reuses norm_lower in the usertemp probe and drops version-history narration from comments. cli-flag-verify.sh builds each finding's display text once in split_candidate_key. flag-commit-pr-skill-bypass.sh runs one sed per command instead of one per line and joins messages directly. cloud-shfmt.sh calls uname once. guard-requires.sh is unchanged because its tables are read back by run-guards.test.sh and its two functions have nothing to remove.

Not verified

  • Hook test suites (block-windows-drive-tmp.test.sh, cli-flag-verify.test.sh, flag-commit-pr-skill-bypass.test.sh, cloud-shfmt.test.sh, run-guards.test.sh) were not executed: this lane runs only its named wrappers; left to the PR's CI
  • shellcheck/shfmt lint on the touched hooks not run directly here (not among the lane's wrappers); left to the PR's CI
  • tidy: the four hook scripts were dropped from tidy-diff because hook-wired scripts are on its GLOBAL HARD exclusion list; only the changelog fragment was in scope (pass 4 no edit; pass 5 skipped because the fragment's only prose is the issue-mandated line)
  • guard-requires.sh left unchanged: its declaration tables are compared verbatim by run-guards.test.sh and its two small functions had no behavior-preserving simplification worth the churn
  • ci-status green is a PR-time check left to CI

Fix

  • plugins/guardrails/hooks/block-windows-drive-tmp.sh: segment_destination_operand and segment_downloader_output_operand became printf -v *_to helpers (no $(...) fork); the 'cmd && return 0; return 1' tails collapsed to 'cmd; return' or a final test; posix_tmp_maps_to_usertemp reuses…
  • plugins/guardrails/hooks/cli-flag-verify.sh: split_candidate_key also sets KEY_DISP and KEY_HELPREF, replacing two duplicated display-format blocks in emit_tel and the findings loop
  • plugins/guardrails/hooks/flag-commit-pr-skill-bypass.sh: strip_literals runs a single sed over the kept lines instead of one sed per line; the message join uses "${MESSAGES[*]}" in place of a loop plus trailing-space trim
  • plugins/guardrails/hooks/cloud-shfmt.sh: uname -s/-m computed once into a local instead of twice per branch
  • .changes/guardrails/work-resolve-issue-issue-14482-42989272470-1-d97009e3.md: patch fragment, '### Changed' with 'Internal simplification, no behavior change.'

Verification

The runner ran each check from the base copy against 59b64bc:

  • 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 (run before and after tidy)
  • check-changed-skills: no changed skills, nothing to gate
  • check-affected: 13 passed, 6 skipped (ruff/typos/changed-skills not applicable or not installed; three validate-plugins sub-checks reserved), the rest CI-only
  • fresh-context review subagent over git-read diff HEAD: no behavior difference found, including printf -v name collisions, return-status collapse, NORM_OUT clobbering, sed batching and the MESSAGES join; the source-grepping lines in cli-flag-verify.test.sh, run-guards.test.sh and cloud-shfmt.test.sh…
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42989272470

Left out: the items under Not verified.

Related

#14482

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

Security review: no security issues found

I read every hunk of all five changed files. The pull request refactors four guardrails hook scripts and adds a changelog fragment. I checked each change for a guard that now blocks less, and found none.

plugins/guardrails/hooks/block-windows-drive-tmp.sh (a blocking guard)

  • Return-status collapses. Each cmd && return 0; return 1 became cmd; return, or became the function's last test. Each one gives the same exit status in every case:
    • has_drive_root_tmp
    • has_redirect_to_drive_root_tmp: when _DRIVE_TMP_SKIP_POSIX is 1, the ((...)) fails, so the function still returns 1.
    • the cp/mv/install, curl/wget, creator and python arms
    • [[ -n "$dest" ]] && has_drive_root_tmp "$dest" returns 1 when dest is empty, as before.
  • Return-status collapses under the shell options. The script runs set -uo pipefail with no -e (L42), so the shorter forms add no errexit side effect.
  • The new printf -v helpers. segment_destination_operand_to and segment_downloader_output_operand_to use only __dt_-prefixed locals. Their target name dest is declared local in the caller (L573), so no name collides with a helper local or leaks out as a global. The token parsing is unchanged apart from the renames.
  • norm_lower in posix_tmp_maps_to_usertemp. The new code turns backslashes into slashes before lowercasing; the old code lowercased first. The two orders give the same result.
  • NORM_OUT reuse. The probe now overwrites NORM_OUT, but nothing reads a stale value afterwards:
    • NORM is copied before the probe runs (L228-L229).
    • The file-path lane passes $NORM_OUT into has_drive_root_tmp by value (L830-L831).
    • After the probe, NORM_OUT is recomputed before it is read (L854-L855).
  • Comment edits. Deleted comments were history narration only; the "THIS GATE RUNS FIRST" ordering rule and its reason are still stated. No standing instruction was removed.

plugins/guardrails/hooks/flag-commit-pr-skill-bypass.sh (an advisory notice, not a block)

  • strip_literals now runs one sed over all kept lines instead of one per line. sed works line by line, and heredoc bodies are still dropped before that point, so the stripped text is the same.
  • The "${MESSAGES[*]}" join uses the default space separator; the script sets IFS only per read call.

plugins/guardrails/hooks/cli-flag-verify.sh: the display strings are built once in split_candidate_key. The output is the same, and nothing about trust or input handling changed.

plugins/guardrails/hooks/cloud-shfmt.sh: uname is cached in a local variable. The pinned URL and SHA install path is unchanged.

.changes/... fragment: changelog text only.

Other checks

  • No trust control, token scope, kill switch, merge hold or plugin manifest changed.
  • The PR context file holds no text addressed to this lane.
  • This is the lane's first review of this pull request; there are no prior findings.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: no findings

I read every hunk of all 5 changed files. I checked each simplification against the code it calls and the code that calls it, by reading the source. I ran no tests.

What I checked

  • plugins/guardrails/hooks/block-windows-drive-tmp.sh
    • The two *_to helpers. segment_destination_operand_to and segment_downloader_output_operand_to keep their locals behind the __dt_ prefix. Their caller, segment_writes_drive_root_tmp, declares dest as a local, so printf -v dest fills the caller's variable and nothing else. printf -v sets the variable even when the result is empty, so no stale value carries over. Nothing outside the CHANGELOG mentions the old function names, so no other file breaks.
    • The collapsed return tails. cmd; return, [[ -n "$dest" ]] && has_drive_root_tmp "$dest"; return, and ending a function on a bare [[ ]] all return the same status as before. No guardrails hook runs under set -e, so a non-zero status at the end of a function cannot end the script.
    • norm_lower in the usertemp check. It now replaces backslashes and then lowercases, where the old code lowercased first. The result is the same, because lowercasing never touches a slash or backslash. It overwrites the global NORM_OUT, but every reader copies or expands NORM_OUT straight after its own norm_lower call (lines 229, 831 and 855). The usertemp check only runs at line 849, before line 854 sets NORM_OUT again.
  • plugins/guardrails/hooks/cli-flag-verify.sh. split_candidate_key now also sets KEY_DISP and KEY_HELPREF, with the same format as the two blocks it replaces. Nothing else reads the old disp or helpref variables. The extra call at line 516, on the cache-hit path, only assigns strings and starts no subprocess.
  • plugins/guardrails/hooks/flag-commit-pr-skill-bypass.sh
    • One sed instead of one per line. The heredoc check still reads each raw line before the quotes are stripped, and sed works line by line, so a quoted span still cannot reach across lines. The output is the same once the command substitution trims it.
    • The "${MESSAGES[*]}" join. This hook never changes IFS globally, so the join still uses a space. MESSAGES only ever holds one entry here anyway.
  • plugins/guardrails/hooks/cloud-shfmt.sh. Calling uname once into platform does the same thing as before.

Closing issue #14482

  • Behavior unchanged: met as far as reading the code shows. I ran none of the test suites. The PR says it ran none either and leaves them to CI.
  • Only the listed files plus fragments edited: met.
  • Within 400 changed lines and 15 hand-edited files: met.
  • ci-status green: CI decides this. It is not verified here.
  • Fragment with bump: patch, ### Changed and "Internal simplification, no behavior change.": met.
  • guard-requires.sh left unchanged: the PR gives its reason (run-guards.test.sh compares its tables word for word). That is consistent with "Simplify these 5 files" when one file has nothing to simplify.

The PR body's verification lines (changelog-fragment and changed-skills checks, check-affected, a subagent review) are the author's claims. I did not reproduce them.

Path-scoped rules: .claude/rules/mod-authoring.md matches plugins/*/hooks/**, but it covers hooks modules and hooks.json "modules", and this PR changes neither.

Paved paths: I did not resolve a standards index or check for a paved-path row, so this review makes no paved-path claim.

Prior findings: none. This lane has not reviewed an earlier head of this PR.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 59b64bc

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-15311-59b64bce0ed55aa4dde9362f9331b9a728679241, 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 3d313be Nov 11, 2026
72 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14482-42989272470-1 branch November 11, 2026 09:30
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit 3d313be21b2fb68aaa136961376eb33cabf9fb43; 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 (5 of 7)

0 participants