Skip to content

refactor(guardrails): simplify hardcoded-path-check, refuse and the hook test helpers - #15206

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

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14483

Summary

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

Simplified the three listed guardrails files with no behavior change. In hardcoded-path-check.sh, the telemetry envelope that was built twice (MCP lane and Write/Edit lane) now comes from one helper, hpc_send_tel. Because the Write/Edit block path now hands emit_tel the violation report rather than prebuilt labels, the grep|sed|jq labels pipeline runs only when telemetry is wired, as the MCP lane already did. In refuse.sh, hook::refuse_asks is a single test equal to the old 'attended and not (attended and unwatched)'. In guardrails-test-helpers.sh, guard_invoke's four-way chdir/merge branch is now two branches using cd "${_gi_chdir:-.}", and make_sink writes its stub with one printf. Means chosen: dedupe inside one file only, since the issue puts cross-file moves out of scope; every function name and signature other files call is kept.

Not verified

  • Hook test suites (hardcoded-path-check.test.sh, the block-dangerous-git and block-root-delete-target suites that source refuse.sh, and every suite that sources guardrails-test-helpers.sh) were not run: this lane's Bash runs only the named wrappers. Left to the PR's CI.
  • ci-status green: a PR CI check, left to the PR's CI.
  • tidy ran passes 1-3 on the code lines (no further edits; no comment deletions, since the three new comments each state a constraint or reason) and passes 4-5 on the fragment by reading only. ai-slop's detect.sh could not run because the lane's Bash allows only the named wrappers, so the…

Fix

  • plugins/guardrails/hooks/hardcoded-path-check.sh: new hpc_send_tel builds and emits the telemetry envelope for both lanes; emit_tel takes the violation report instead of a labels array, so labels are computed only behind the telemetry gate.
  • plugins/guardrails/hooks/refuse.sh: hook::refuse_asks reduced to one equivalent [[ ]] test; hook::refuse_unwatched kept (still used by hook::refuse).
  • plugins/guardrails/hooks/guardrails-test-helpers.sh: guard_invoke's run block collapsed from four branches to two; make_sink writes the stub with a single printf (byte-identical output).
  • .changes/guardrails/work-resolve-issue-issue-14483-42918955423-1-98d56754.md: patch fragment, '### Changed' with 'Internal simplification, no behavior change.'

Verification

The runner ran each check from the base copy against 393c310:

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

The run reports:

  • check-changelog-fragments: all 26 fragments valid (run before and after tidy)
  • check-changed-skills: no changed skills, nothing to gate (run before and after tidy)
  • check-affected: 13 passed, 6 skipped, 0 failed over 4 changed files (run before and after tidy)
  • fresh-context review subagent over the full diff: no behavior change any caller or test would see. It noted two edge cases outside any test's reach: cd . now sets OLDPWD for the hook process, which no guard reads; and with sed missing from PATH on the Write/Edit block path with telemetry off, the…
  • grep: no test or script references the removed lines, labels_json at top level, or emit_tel's old '[]' argument; hook::refuse_unwatched and hook::refuse_asks have no callers outside refuse.sh
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42918955423

Left out: the items under Not verified.

Related

#14483

Merge-Risk: max=HIGH demote=true head=393c310a1243327a65b58c9f650c25220d5210fc 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 393c310a1243327a65b58c9f650c25220d5210fc: read 4 of 4 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #15206 (head 393c310)

I found no security issues. I read every hunk of all 4 changed files, and the head versions of refuse.sh and hardcoded-path-check.sh. No changed file matches a trusted-path glob, and the diff touches no plugin manifest or trust control.

What I checked

  • plugins/guardrails/hooks/refuse.sh: the ask-vs-deny guard.
    • The old check was ATTENDED==1 && ! hook::refuse_unwatched, where refuse_unwatched is ATTENDED==1 && UNWATCHED==1 (refuse.sh#L44-L46). That reduces to ATTENDED==1 && UNWATCHED!=1, which is exactly the new single test at L48-L50.
    • Unattended sessions and unwatched sessions still deny with exit 2. A missing or unknown value still denies. No new input turns a deny into an ask.
  • plugins/guardrails/hooks/hardcoded-path-check.sh: the hardcoded-path guard.
    • The block path still prints the report and runs exit 2 in both the MCP lane and the Write/Edit lane (L247-L256, L409-L423).
    • The new hpc_send_tel helper builds telemetry labels with hpc_labels_json_to, which keeps only the detected: headers and never the matched lines. If that or jq fails, it falls back to [] or the empty envelope.
    • The file field is still the redacted repo-relative path, or the MCP path, as before. Telemetry carries no new data (no leak).
    • Moving the labels step behind the telemetry gate only means it runs less often.
  • plugins/guardrails/hooks/guardrails-test-helpers.sh (test-only helper).
    • cd "${_gi_chdir:-.}" behaves the same as the old four branches.
    • The single-printf stub writes the same bytes.
    • The file mode changes from 100644 to 100755. This file is only sourced by tests and has no security impact.
  • .changes/ fragment: prose only.

Instruction-surface lens: the diff deletes or narrows no standing instruction, block list or allowlist. The guard logic is the same before and after.

PR context: nothing in it tries to steer the review.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: PR #15206, simplifying the guardrails hooks (closes #14483)

I read all 4 changed files in full. I also read the head copies of hardcoded-path-check.sh and refuse.sh and checked the helper functions they call. I ran no tests: the hook suites and ci-status are claimed by the author and not verified by me.

Code changes: no behavior change found

  • refuse.sh: the new hook::refuse_asks test (ATTENDED == 1 && UNWATCHED != 1) gives the same result as ATTENDED == 1 && !(ATTENDED == 1 && UNWATCHED == 1) for every input. hook::refuse_unwatched is kept and still used by hook::refuse.
  • hardcoded-path-check.sh:
    • hpc_send_tel writes into its own local labels_json through printf -v in hpc_labels_json_to, which bash's dynamic scoping allows.
    • It starts that value at [] when the report is empty, so emit_tel "ok" "" still sends violations:[] as before.
    • The MCP lane calls it only with a non-empty $violations, and the Write/Edit block path only with a non-empty $VIOLATIONS.
    • The labels pipeline now runs only behind emit_tel's start-stamp and telemetry check. Telemetry is the only thing that reads it, so moving it changes no output.
  • guardrails-test-helpers.sh:
    • cd "${_gi_chdir:-.}" treats an empty _gi_chdir the same way the old -n test did. cd . runs inside the command-substitution subshell, so the caller's directory is untouched.
    • The single printf in make_sink produces the same bytes as the old two-printf block.

Finding (advisory, no changed line can carry it)

  • Unexplained mode change on a sourced library. The diff changes plugins/guardrails/hooks/guardrails-test-helpers.sh from 100644 to 100755 (old mode 100644 / new mode 100755).
    • The file has no shebang, and its header (L1-L4) says it is only ever sourced, never executed.
    • Neither the PR body nor the fragment mentions the change, and the issue's first acceptance criterion asks for a no-behavior-change edit of the listed files.
    • The likely cause is a stray side effect of the lane's tooling. The file is not a registered shared copy, so sync-shared-copies.sh will not flag the bit as drift. The bit now differs from the file's sibling *-test-helpers.sh libraries.
    • If the file were ever run directly, it would run under the default shell with nothing to execute. Fix: restore the old mode with git update-index --chmod=-x plugins/guardrails/hooks/guardrails-test-helpers.sh.

Closing issue #14483 acceptance criteria

  • Behavior unchanged: met for the code, as covered above; the mode change is the only exception. The suites that cover these paths are hardcoded-path-check.test.sh and the block-dangerous-git / block-root-delete-target suites; the author claims they ran green in CI, and I have not checked.
  • Only the listed files plus fragments edited: met.
  • Within 400 lines / 15 files: met (4 files, about 30 changed lines).
  • ci-status green: not verifiable from this lane.
  • Fragment body: met. .changes/guardrails/...98d56754.md has bump: patch, ### Changed, and the required sentence.

No embedded instructions were found in the PR context. There is no plugin manifest change, so no manifest lines apply.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 393c310

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-15206-393c310a1243327a65b58c9f650c25220d5210fc, 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 1cd8ad3 Nov 10, 2026
72 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14483-42918955423-1 branch November 10, 2026 23:26
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit 1cd8ad37c07c22e5b1b0e8541b9851fb1f454334; 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 (6 of 7)

0 participants