Skip to content

refactor(guardrails): simplify ps-command.sh part 1 of 2 - #15405

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

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14490

Summary

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

Simplified four functions that start in lines 1-1550 of plugins/guardrails/lib/powershell/ps-command.sh, with no behavior change. ps::has_bare_cr now deletes every CRLF pair and tests for a CR that is left, instead of walking each character. ps::blank_herestrings uses one elif where it nested an if inside an else, and drops two single-use locals. ps::_walk_quoted_spans_to merges its two identical 'ambiguous escape, delete nothing' branches into one. ps::computed_call_has_positional_write_signal computes the bracket depth once, drops a { check that could never fire, and merges its two returns into one condition. Means chosen on evidence: each edit stays inside one function, keeps its return codes and globals, and leaves the file's documented fail-closed invariants as they were. Nothing moved between functions or files.

Not verified

  • The guardrails shell test suites (e.g. plugins/guardrails/hooks/block-dangerous-git.test.sh) were not run directly: this lane's Bash runs only the named wrappers. Left to the PR's CI.
  • tidy pass 5 (ai-slop:audit fix) skipped: its detect.sh and digest-guard.sh scripts are not runnable under this lane's Bash allowlist. A manual read of the two fragment lines found no AI-writing tells.
  • ci-status green on the PR is a CI check, left to the PR's CI.
  • No commit made: the lane instructions say to leave every change uncommitted for the runner's patch, and no commit tool was provided.
  • Untracked root dotfiles (.bashrc, .bash_profile, .gitconfig, .idea, .mcp.json, .profile, .ripgreprc, .vscode, .zprofile, .zshrc) appear in git status; this run did not create them (they look like sandbox mount placeholders) and they are not part of this change.

Fix

  • plugins/guardrails/lib/powershell/ps-command.sh: simplified ps::has_bare_cr, ps::blank_herestrings, ps::_walk_quoted_spans_to and ps::computed_call_has_positional_write_signal (all start in range 1 of 2, lines 1-1550 of the 3100-line file); comments updated to match
  • .changes/guardrails/work-resolve-issue-issue-14490-43068735118-1-9070462a.md: patch fragment, '### Changed' with 'Internal simplification, no behavior change.'

Verification

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

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

The run reports:

  • check-changelog-fragments: all 15 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 over 2 changed files (run three times; the last run was after the final comment-only edit)
  • fresh-context review subagent, given the diff only, checked each of the four edits for equivalence (CR/CRLF edge cases, elif restructure and removed locals, merged ambiguity branches, arithmetic precedence, errexit/nounset/IFS hazards): no discrepancy found
  • tidy-diff (code-tidying:tidy-diff) over 12 hunk rows: no further edits; passes 1-4 found nothing to change
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/43068735118

Left out: the items under Not verified.

Related

#14490

Merge-Risk: max=HIGH demote=true head=dd42ea98b6de79abbfab7d062aaf17d5345941ef rubric=8.4.2 rater=claude-opus-5-5 checker=claude-opus-5-5

Lane-Activity: work-resolve-issue/resolve-issue
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Unattended merge: native auto-merge leaves this pull request unarmed at head dd42ea98b6de79abbfab7d062aaf17d5345941ef. No person needs to act: a lane clears this reason, and the next scheduled run judges it again.

pr-merge's gate refuses its verifier verdict (verify:missing)

@github-actions

Copy link
Copy Markdown
Contributor

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

Security review: PR #15405, refactor(guardrails): simplify ps-command.sh part 1 of 2

I found no security issues. This was a full review, not blocking-only: the prior-findings file says this lane has reviewed 0 earlier heads.

critical-findings: 0

What I checked. plugins/guardrails/lib/powershell/ps-command.sh is part of the guardrails control that classifies PowerShell commands for the dangerous-command hooks. A refactor here that changed behaviour could let a blocked command through. So I compared every hunk against the base logic, and read the head file around the changed functions:

  • ps::has_bare_cr (head L206-212). ${1//$'\r\n'/} deletes CRLF pairs left to right, and the pairs can't overlap. Every CR that was followed by LF is removed. Every CR that wasn't stays, so \r\r\n still leaves one bare CR. An empty input or one with no CR still returns 1. This gives the same result as the old character walk, so the bare-cr untrusted mark at L414 fires on exactly the same inputs.
  • ps::blank_herestrings (head L425-447, L477):
    • The nested else { if … } became an elif with the same condition, and both paths still continue.
    • The closer test now compares ${line:0:2} against ${hs_quote}@ directly. That is the same comparison as the old first2/closer locals, which were only used there.
    • pending="${prefix}…" is unchanged in effect, because prefix="${line%??}" is assigned at L465 on the same path just before.
    • PS_HERESTRING_EXPANDABLE_SUBEXPR is still set only on a dropped body line of an expandable here-string.
  • ps::_walk_quoted_spans_to (head L591-602). The new condition is (backtick inside a double-quoted span) OR (current char is the quote AND the next char is the quote). That is exactly the two old "delete nothing" exits, merged. A single closing quote still sets __wq_found=1.
  • ps::computed_call_has_positional_write_signal (head L1352-1370):
    • The removed "$tok" != \{* test could never fire, because any token starting with { already hit continue through [\(\{]*.
    • Depth is computed the same way on both old paths.
    • In the merged return count >= 2 && count_lit >= 1 || piped == 1 && count >= 1, arithmetic && binds tighter than ||, so it equals the two old separate return 0 checks.
    • Under errexit, a false (( … )) && return 0 or [[ … ]] && break sits in a non-final list position, so it doesn't abort.

So every "fail closed" path (untrusted marks, delete-nothing on an ambiguous escape, the positional-write signal) still fires on the same inputs.

Other changes:

  • The file mode changed from 100644 to 100755 on a sourced library. This has no security effect.
  • .changes/guardrails/…md is a changelog fragment only.

Other review checks:

  • No trusted-path glob matches either changed file, and the diff touches no trust control (trusted-trigger, token scope, kill switch, broker, merge hold).
  • No plugin manifest or userConfig change.
  • No standing instruction was removed or softened. Only code comments were reworded, and they describe the same rules.
  • The PR context file has no embedded instructions aimed at this lane. It notes that the closing issue's body was omitted because the author is not allow-listed.

Spend: none beyond this review run.

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: PR #15405 (refactor(guardrails): simplify ps-command.sh, part 1 of 2)

No findings. I read every hunk of both changed files. Each of the four edits behaves the same as the code it replaces. I checked this by reading the code against the head file. I did not run any tests: this lane has no shell.

How each edit holds up

  • ps::has_bare_cr (L209-L212): removing every \r\n pair leaves exactly the CRs that no LF follows. I checked the edge cases: \r\r\n is still true, \r\n alone is still false, and a trailing \r is still true. The ${1//$'\r'…/} form is already used elsewhere in the plugin (for example hooks/hook-utils.sh), so it adds no new portability risk.
  • ps::blank_herestrings (L425-L447, L477):
    • The else { if … } → elif change keeps the same control flow, and every branch still hits continue.
    • The removed locals rest and closer were used only inside the closer branch, and nothing later in the function refers to them.
    • first2 is still declared and still used at L449.
    • pending="${prefix}…" is the same value as before: prefix is set to ${line%??} at L465, in the same branch, and line does not change in between.
  • ps::_walk_quoted_spans_to (L591-L603): the merged condition checks a doubled quote before the single-quote "found" branch, the same order as before. The backtick case and the c == q case cannot both be true, so merging them changes nothing.
  • ps::computed_call_has_positional_write_signal (L1352-L1370):
    • depth is computed the same way on both paths.
    • The dropped != \{* test could never fire, because tokens starting with { already continue earlier.
    • In the merged ((a && b || c && d)), && binds tighter than ||, so it means the same as the old two ifs.
    • Under errexit, a false ((…)) in a non-final && position does not exit.

Mode change 100644 → 100755. This is expected from the pipeline, not a mistake: scripts/check-affected.sh L240-L245 notes that apply-patch makes every changed .sh file executable.

Closing issue #14490, acceptance criteria

  • Behavior unchanged: met, by my reading of the code. Existing suites test this path; for example, bare-cr / has_bare_cr appears 24 times in plugins/guardrails/hooks/block-dangerous-git.test.sh.
  • Only listed files plus a fragment are edited: met.
  • Within 400 changed lines and 15 files: met.
  • Fragment is bump: patch with ### Changed and the line "Internal simplification, no behavior change.": met.
  • Only functions starting in lines 1-1550 are changed: met. All four start before line 1300.
  • ci-status green: left to CI. The author also says the guardrails test suites were not run in the lane; that claim is unverified.

Embedded text: none found in the PR context.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for dd42ea9

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-15405-dd42ea98b6de79abbfab7d062aaf17d5345941ef, 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 9fec078 Nov 11, 2026
70 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14490-43068735118-1 branch November 11, 2026 19:16
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit 9fec078a62645c2532899bdf07e2b58046a06ce4; 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 ps-command.sh guardrails plugin code (part 1 of 2)

0 participants