Skip to content

refactor(guardrails): simplify the second half of ps-command.sh - #15458

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

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14491

Summary

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

Simplified the functions that start in the second half of plugins/guardrails/lib/powershell/ps-command.sh (from ps::git_command_is_readonly onward), with no change in behavior. ps::_skip_statement_tail_to merges three identical statement-end returns and its paired depth-case arms. ps::_blank_cmd_statements records where to start blanking and calls the tail scan, the space append and the continue once, instead of repeating them in three arms; the unused rest, matched and word locals are gone. The two quote-skip branches in it and in ps::_blank_special_construct_regions are merged. Smaller cuts: temporaries removed in ps::_blank_unbalanced_herestring_tail, a case in place of a five-way || chain in ps::print_sink_token_line, and one-line returns in has_unprovable_env_write, might_write_via_python3, classify_git_command and write_bypass. Every function name, return code, assigned variable and printed message is unchanged, and the iex/Invoke-Expression skip offsets (3 and 18) are kept as they were. A pre-existing issue, left alone because this change must not alter behavior: in _blank_cmd_statements, Invoke-Expression is 17 characters but the tail scan starts 18 past it. For Invoke-Expression;git reset --hard, the scan therefore starts after the ; and probably blanks the next statement as well, which could hide that git command from the allow-token re-check. It deserves its own issue.

Not verified

  • The guardrails shell test suites (block-dangerous-git.test.sh, block-no-verify.test.sh, block-noncanonical-commit.test.sh, run-guards.test.sh) were not run: this lane can run no test runner or interpreter. Left to the PR's CI.
  • ci-status green on the PR is a CI check, left to the PR's CI.
  • Tidy made no edits. The ps-command.sh rows were dropped under tidy's hard exclusion for hook-wired scripts, since the file is named in a hook command's arguments in plugins/guardrails/hooks/hooks.json. Passes 1-3 (code) did not run. Pass 4 (write-for-humans) made no change to the fragment, whose…
  • Pre-existing issue, not fixed because this change must not alter behavior: ps::_blank_cmd_statements starts the tail scan 18 characters past Invoke-Expression, which is 17 characters long, so for Invoke-Expression;git reset --hard the scan probably blanks the following statement too. Needs its…

Fix

  • plugins/guardrails/lib/powershell/ps-command.sh: simplified ps::has_unprovable_env_write, ps::might_write_via_python3, ps::classify_git_command, ps::_skip_statement_tail_to, ps::_blank_cmd_statements, ps::_blank_special_construct_regions, ps::_blank_unbalanced_herestring_tail,…
  • .changes/guardrails/work-resolve-issue-issue-14491-43116102783-1-91e1e7c2.md: new patch fragment with ### Changed and 'Internal simplification, no behavior change.'

Verification

The runner ran each check from the base copy against 33dba8b:

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

The run reports:

  • check-changelog-fragments: all 42 fragments valid
  • check-changed-skills: no changed skills, nothing to gate
  • check-affected: 13 passed, 6 skipped (none failed) over the 2 changed files, run before and after the review fix
  • fresh-context review subagent, hunk by hunk: no behavior difference, except that swapping lowercasing and backtick removal in ps::write_bypass could differ on invalid multibyte input; that hunk was reverted to the original order
  • range check: every edited function starts at or after line 1691, in range 2 of 2 (lines 1537-3073 of the 3073-line file before the change)
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/43116102783

Left out: the items under Not verified.

Related

#14491

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

Security review: PR #15458 (refactor(guardrails): simplify the second half of ps-command.sh)

No security issues found.

This file holds the guardrails PowerShell command classifier that the dangerous-git hook uses. The PR touches no trusted path, but a guard that silently changed behaviour could let a dangerous git command through, so I checked every hunk for equivalence rather than skipping the review.

  • ps::has_unprovable_env_write (L1895): the old ((write_head && dyn_cd)) && return 0; return 1 becomes ((write_head && dyn_cd)) as the function's last statement. Both return 0 or 1 under the same condition. Under set -e there is no new early exit either: errexit is suppressed when the function is called as a condition, and a non-condition call already failed with the old return 1.
  • ps::might_write_via_python3 (L2054), ps::classify_git_command (L2220), ps::write_bypass (L3023): each if …; then return N; fi becomes … && return N. Nothing reads $? after these lines (the only $? in the file is a regex literal at L1052). None of the lines ends its function, and an && list doesn't trigger errexit, so the control flow is the same.
  • ps::_skip_statement_tail_to (L2392-L2400): the three statement-end returns are merged into one condition with the same terminators (;, newline, |, &&). The depth arms are merged too. Equivalent.
  • ps::_blank_cmd_statements (L2475-L2523): the tail scan now writes straight into the caller's i through printf -v. The callee's locals all use the __st_ prefix, so there is no name collision, and it writes $1 on every return path (L2394, L2405), so the loop can't stall. The start offsets are unchanged: i+3 for iex, i+18 for Invoke-Expression, i for call/dot-source and launchers. Each match still appends one space and continues.
  • Merged quote-skip branches, _blank_unbalanced_herestring_tail temporaries, print_sink_token_line case (L2731): equivalent. Both paths still print the same messages and return the same status.

The only other change is a new changelog fragment (no security surface).

The PR description points out an existing quirk: the tail scan for Invoke-Expression starts at +18, but the word is 17 characters. The PR keeps that offset as it was. Because it predates this PR, it is excluded here and not counted as a finding; the PR body already proposes a separate issue for it.

The diff deletes no standing instruction and changes no plugin manifest, and nothing in it spends credits or can bill.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: refactor(guardrails): simplify the second half of ps-command.sh

I read every hunk of both changed files, plus the code around each edited function at the head commit. I checked each hunk for whether behavior stays the same:

  • ps::has_unprovable_env_write (L1895): the bare ((write_head && dyn_cd)) returns the same 0/1 status as before. The guardrails hooks deliberately don't run under errexit (hooks/abort-boundary.sh), and the one internal caller (L1939) calls it inside an && list, so the bare failing arithmetic can't abort anything.
  • ps::might_write_via_python3, the PS_REDUCTION_UNTRUSTED return, and the '>'* producer check: the && return N forms match the if/case forms they replace. None of them is the last command in its function, so a false test still falls through as it did before.
  • ps::_skip_statement_tail_to: the merged ;, newline, | and && stop condition and the merged depth arms match the old branches one for one. A bare & still doesn't end the statement.
  • ps::_blank_cmd_statements: blank_from replaces matched/word/end/rest, and the start offsets are the same (i+3 / i+18 for iex / Invoke-Expression, i for call/dot-source and launchers). Writing the result straight into i through printf -v is safe: the callee's locals all start with __st_, and the file already uses this pattern at L2564. end is still set in the quote branch before it is read. lc is computed as before.
  • ps::_blank_special_construct_regions quote merge, ps::_blank_unbalanced_herestring_tail temporaries, ps::print_sink_token_line case: all equivalent. No other code in those functions reads first2 or closer; the local closer in ps::print_sink_trigger_line is a separate local.

Closing issue #14491, acceptance criteria:

  • Behavior unchanged: met, by reading every hunk. Existing tests pin these predicates, for example pin_predicate ps::has_unprovable_env_write in hooks/block-dangerous-git.test.sh L1647-1680. The PR says the suites weren't run in the lane; that is author-stated and unverified. CI decides.
  • Only listed files and fragments edited: met.
  • Within 400 lines / 15 files: met.
  • ci-status green: left to CI, unverified here.
  • Fragment bump: patch with ### Changed / "Internal simplification, no behavior change.": met.
  • Only functions starting in range 2 changed: met. The earliest edited function starts at L1821.

Pre-existing (advisory): plugins/guardrails/lib/powershell/ps-command.sh#L2498: for Invoke-Expression, the tail scan starts at i + 18, but the word is 17 characters long. That skips the boundary character the regex just matched. For Invoke-Expression;git reset --hard, the scan steps past the ; and blanks the next statement as well. This changed line carries the offset over from the base unchanged (old word=18), so the defect predates this change. The PR body already flags it and asks for its own issue. The fix (i + 17) changes behavior, so it doesn't belong in this behavior-preserving PR. It deserves a follow-up issue, and the security lane may want to judge whether it lets a git command get past the allow-token re-check.

I found no embedded instructions in the PR context or the prior-findings file. This lane hadn't reviewed this PR before, so this is a full review rather than a blocking-only one.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Unattended merge: native auto-merge leaves this pull request unarmed at head 33dba8bbc73ba951bb02a9b1b04f9eceb6a7bbd5. 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)

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 33dba8b

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-15458-33dba8bbc73ba951bb02a9b1b04f9eceb6a7bbd5, 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 b3af16e Nov 11, 2026
70 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14491-43116102783-1 branch November 11, 2026 23:30
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit b3af16e93a400e431ec7d926bb020a62e8536ba3; 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 2 of 2)

0 participants