Skip to content

refactor(guardrails): simplify block-root-delete-target.sh range 3 of 5 - #15221

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

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14478

Summary

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

Simplified the functions that start in range 3 of 5 of plugins/guardrails/hooks/block-root-delete-target.sh (lines 3335-5001 of the 8,336-line file, rdt_sink_check through rdt_ix_slice) with no behavior change. Repeated logic now lives in small helpers inside that range: rdt_stdin_redir (the last fd-0 redirection scan, which rdt_sink_check and rdt_interp_check each had), rdt_hd_prog (the heredoc record, which replaces rdt_hd_shell and takes a language so rdt_interp_check uses it too), rdt_env_split_check (the four env -S splice-and-recheck blocks), rdt_parse_words (the join-and-parse with dropped-backslash restore that eval and watch each had), and rdt_may_split (the may-become-several-words test that robocopy and mv each had). The sink_check stdin test is merged into one line, and locals the helpers made unused are dropped. Moving code across files and the same scan in rdt_segment (range 4) are left to their own passes.

Not verified

  • The hook's test suites (block-root-delete-target*.test.sh and the guardrails hook tests) were not run: this lane's Bash runs only the named wrappers. Left to the PR's CI.
  • Review note, judged not a behavior change: rdt_parse_words and rdt_env_split_check add one bash call frame per eval, watch or env -S nesting level. MAX_SEGMENT_DEPTH=24 still caps nesting well below the about-100-level stack limit that the code comment cites. run-guards.sh hands the rest of the…
  • tidy: code passes 1-3 skipped because tidy-diff's GLOBAL HARD exclusions cover any script wired as a hook command, and this hook is wired in hooks.json through run-guards.sh. The markdown passes ran on the changelog fragment: write-for-humans found nothing to change (its text is fixed by the…
  • cant-fail-scan not applied: it scans test files and this change edits none.
  • ci-status green is left to the PR's CI.

Fix

  • plugins/guardrails/hooks/block-root-delete-target.sh: deduplicated logic in rdt_sink_check, rdt_check_segment (env -S and eval arms), rdt_watch_check, rdt_cmd_rd_bash, rdt_robocopy_check, rdt_content_check and rdt_interp_check into five in-range helpers; renamed the file-internal rdt_hd_shell to…
  • .changes/guardrails/work-resolve-issue-issue-14478-42935029486-1-f7874d12.md: patch fragment, '### Changed' with 'Internal simplification, no behavior change.'

Verification

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

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

The run reports:

  • check-changelog-fragments: all 10 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 before and after tidy)
  • fresh-context review subagent over the whole diff: no change found in outputs, exit codes, blocked commands or printed text; it checked dynamic-scope locals, RDT_IN_* clobbering, precedence, slice equivalence, q0 versus HOOK_SEG_WORD_QUOTED in watch, and return statuses
  • grep across the repo: rdt_hd_shell and the edited function names appear only in this file
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42935029486

Left out: the items under Not verified.

Related

#14478

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

Security review: PR #15221 (guardrails block-root-delete-target.sh range 3 refactor)

No security issues found.

The edited file is a guardrail hook: it blocks recursive deletes of root, home and protected trees. A refactor that changes behavior here could let a destructive command through, so this change did not qualify for the "no security surface" skip. I read every hunk of both changed files and the head code around each one, and checked each helper against the code it replaces.

  • rdt_sink_check stdin test. The old code set stdin=1 with A || B && stdin=1, which bash reads as (A || B) && …. The new code runs one test after esac: ((s || k >= n)) || [[ … ]] || return 0. In the source | . arm, s is still 0 and k is unchanged (block-root-delete-target.sh:3345, :3361), so its old test k >= n || stdin-path gives the same result. The bash arm's test is unchanged. The eval, -c and * arms return before the new test, as they did before.
  • rdt_stdin_redir (the last fd-0 redirection, stored in RDT_IN_R and RDT_IN_HD). It uses the same loop as before. rdt_sink_check copies both values right away (:3396). rdt_interp_check copies RDT_IN_R into last and reads RDT_IN_HD before calling anything else (:4898-4904). hd and last no longer start at -1 or 0, but both are only read after this assignment, and only when r/last >= 0. The loop counter c that rdt_sink_check gave up is reset by the later for ((c = 0; …)) (:3421).
  • rdt_hd_prog writes the same two heredoc records rdt_hd_shell and the interp branch used to write, with sh or $lang as the language.
  • rdt_env_split_check. It passes the same operand and the same words[@]:i+N slice in all four arms (${words[i + 1]-} equals the old sval="" default), clears HOOK_SEG_WORD_QUOTED as before, and declares no locals, so it shadows nothing in the recursive rdt_check_segment.
  • rdt_parse_words. The empty-word-to-backslash restore is kept, and so is the eval-too-long budget charge. In rdt_watch_check, HOOK_SEG_WORD_QUOTED is the same as q0 at the call, because nothing in the option loop changes it (:4163-4213). Its locals j, text and ev sit above rdt_parse in the call stack. Every other function in the file that uses text or q declares it local (lines 2249, 4093, 4982, 6193, 6620), so a nested parse cannot read these values in place of its own.
  • rdt_may_split has the same expression with k passed as $1. The mv last-operand drop is still may_split || unset.
  • rdt_cmd_rd_bash. The q ternary is equivalent, and q is now local.
  • Stack depth. Each eval, watch or env -S level adds one bash call frame. rdt_check_segment still caps nesting at MAX_SEGMENT_DEPTH=24 (block-root-delete-target.sh:964, :3540), and the cap fails closed.

The changelog fragment is plain text and has no security surface.

Trusted paths: neither changed file matches a trusted-path glob. The diff changes no trust control, merge hold, plugin manifest or standing instruction, and removes no hook block-list rule.

I did not run the hook's test suites; I have no shell in this lane. The PR notes they are left to CI.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: PR #15221 (refactor(guardrails): simplify block-root-delete-target.sh range 3 of 5)

No findings. I read every hunk of both changed files and checked each change against the code at head.

What I checked

  • rdt_sink_check stdin test. Removing the stdin flag changes nothing. The old A || B && stdin=1 reads as (A || B) && stdin=1, so A || B || return 0 is the same test. The source | . branch reaches it with s=0 and the same k. The eval, c=1 and * branches still return before it.
  • rdt_stdin_redir. Its loop matches the two copies it replaces. r and hd are copied out right after the call, and RDT_IN_HD is read in rdt_interp_check with no call in between, so nothing can overwrite the globals first. When there is no fd-0 redirection, hd is now -1 where it used to be 0, but hd is only read when r >= 0. The old loop left c changed in rdt_sink_check and j changed in rdt_interp_check. Neither value is read afterwards: the later loop sets c back to 0, and last is only read inside the block that sets it.
  • rdt_hd_prog. It writes the same rdt_hd_lang and rdt_hd_st records as rdt_hd_shell (with sh) and the interp heredoc arm (with $lang) did.
  • rdt_env_split_check. The operand and slice index match all four places it replaces. "${words[i + 1]-}" stands in for the ((i + 1 < n)) guard, and ${sval#--split-string=} matches the old two-step strip. Each branch returns, or puts HOOK_SEG_WORD_QUOTED back, right after the call, as before.
  • rdt_parse_words. In the watch path it now reads HOOK_SEG_WORD_QUOTED where the old code read q0. Nothing in the rdt_watch_check option loop changes that array between the snapshot and the call, so the two are equal there. The new locals j, text and ev don't hide any variable a callback reads: the only other text= assignment, at line 6222, is in a function that declares its own local text.
  • rdt_cmd_rd_bash. The new local q keeps the same value logic. The functions it calls declare their own q.
  • rdt_may_split. The test matches the old robocopy and mv conditions word for word, and it returns the status the callers branch on.
  • Extra call frames. The added frames move the FUNCNAME depth that run_guards::run_rest compares with RUN_GUARDS_MAX_DEPTH (run-guards.sh#L1046). The verdict doesn't change: past that depth the rest of the chain runs in a new process, and it still reports back. The PR description already notes this.

Closing issue #14478 acceptance criteria

  • Behavior unchanged: consistent with the reading above. I did not run the hook's test suites (block-root-delete-target*.test.sh); the author says they weren't run either and leaves them to CI. Those suites cover the eval, env -S, watch, heredoc and interpreter paths these helpers touch.
  • Only the listed file plus a fragment edited: met.
  • Within 400 changed lines: met, the diff is small.
  • ci-status green: not verified here; left to CI.
  • Fragment: met. bump: patch, ### Changed, and the line "Internal simplification, no behavior change."
  • Only range 3 functions changed: met. Every edit falls between rdt_sink_check and rdt_interp_check, and the new helpers sit inside that range.

The PR's own verification (check-changed-skills, check-affected, its subagent review) is the author's claim; I did not check it.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Unattended merge: native auto-merge leaves this pull request unarmed at head c5ac5192e0f17a513a45fcf6ae5a1185e74cc175. 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 c5ac5192e0f17a513a45fcf6ae5a1185e74cc175, the head its arming checks judged.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for c5ac519

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-15221-c5ac5192e0f17a513a45fcf6ae5a1185e74cc175, 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 9fed859 Nov 11, 2026
72 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14478-42935029486-1 branch November 11, 2026 03:11
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit 9fed85910d00bae0b13a2f280b5504162ea4dd87; 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 block-root-delete-target.sh guardrails plugin code (part 3 of 5)

0 participants