You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(guardrails): read hook commands from shfmt's parse tree instead of the hand-written segmenter #12471
The guardrails hooks decide which commands a Bash tool call runs by reading the text with a hand-written bash reader, hook::bash_parse_segments_uncached in lib/hook-utils.sh, synced into 20 plugin copies. #12384 took five review rounds of bypass fixes: each round closed one batch of forms that hide a command from the guard ($(…)#, backticks, case/esac, here-doc levels, arithmetic versus subshell), and the next review found more. Its generated bash-oracle table showed 423 hidden commands on main, 0 after round 4, then three more classes in round 5. A reader that approximates bash's grammar by hand keeps growing edge cases.
Owner decision (2026-11-02, standing direction §1 re-pasted on PR Lane's recommendation): land #12384 after round 5, take later findings as follow-ups, and rebuild the reader on a real parser.
Approach
Walk the parse tree from shfmt --to-json (mvdan/sh). It is already a bash-format prerequisite; v3.14.1 is installed here. On the round-4 bypass echo $(case x in a|esac) :;; esac)#; git reset --hard, it ends the first statement at offset 36 and returns git reset --hard as a second statement. The guard runs its callback on every simple command in the tree, including inside substitutions, process substitutions, here-doc bodies that are evaluated, and both extglob readings.
Fail closed: when shfmt is missing, errors, or times out, refuse the call (the same refusal the guard gives an unparseable command).
Done when
The guard's command reader uses shfmt --to-json, and the hand-written segmenter is removed or reduced to a thin adapter, with the 20 synced copies regenerated.
fix(guardrails): read a # after a word-continuing ( or substitution as literal #12384's generated oracle table (every opener × case position × word × placement, checked against bash +O extglob and bash -O extglob) passes unchanged as the acceptance test, along with block-dangerous-git.test.sh, run-guards.test.sh and block-root-delete-target.test.sh.
Measured: the added time per hook call (p50 and p95 over the test corpus), before and after, recorded in the PR.
Measured and documented: forms where shfmt's parse differs from bash's (extglob by default, case patterns, [[ =~ ]]), each either handled or refused.
Proposed work class: work-class: structural
Basis: automated intake triage; the lanes App applied this class.
Size: Medium
Complexity: High
Uncertainty: Knowable
Flags: none
Blocked by: none
I read this as a refactor. The guardrails hook command reader would walk the parse tree from shfmt --to-json instead of the hand-written segmenter. It would fail closed when shfmt is missing, errors or times out. The 20 synced copies would be regenerated. The approach and done-when items are specific, so I found no open intent question.
Dependency to note: the #12384 PR carries the oracle table that serves as the acceptance test, and it needs to merge first. #12384 is a pull request, so I didn't list it as a blocker.
Not admitted to the issue lane: no trusted-human acceptance criteria: a listed human must put the confirmed - [ ] criteria in the body or post them as their own comment, or, on an issue a listed human filed, intake's newest refinement comment must hold them unedited. Admission takes the issue once each of those is met, when intake triages it again (.github/actions/resolve-config/admission-rules.json).
Activity
github-actions commentedon Nov 2, 2026
Proposed work class: work-class: structural
Basis: automated intake triage; the lanes App applied this class.
Size: Medium
Complexity: High
Uncertainty: Knowable
Flags: none
Blocked by: none
I read this as a refactor. The guardrails hook command reader would walk the parse tree from
shfmt --to-jsoninstead of the hand-written segmenter. It would fail closed whenshfmtis missing, errors or times out. The 20 synced copies would be regenerated. The approach and done-when items are specific, so I found no open intent question.Dependency to note: the #12384 PR carries the oracle table that serves as the acceptance test, and it needs to merge first. #12384 is a pull request, so I didn't list it as a blocker.
Related open issues: #12398, #12360, #8799 and #11818. They are related, not duplicates. #12398 and #12360 may be moot once this lands.
Automated triage, applied by the lanes App.
melodic-automation-lanes commentedon Nov 2, 2026
Not admitted to the issue lane: no trusted-human acceptance criteria: a listed human must put the confirmed
- [ ]criteria in the body or post them as their own comment, or, on an issue a listed human filed, intake's newest refinement comment must hold them unedited. Admission takes the issue once each of those is met, when intake triages it again (.github/actions/resolve-config/admission-rules.json).melodic-automation-lanes commentedon Nov 2, 2026
The latest triage verdict holds nothing: the issue is at
status: ready.36 remaining items
refactor(guardrails): make shfmt the only command reader (save point,…
fix(guardrails): time the shfmt parse with read -t and pin its proces…
test(guardrails): bring the segment-shape rows to the shfmt reader
fix(guardrails): close the shfmt reader's CI failures and review find…
fix(guardrails): refuse an unparsable extglob pattern holding a subst…
fix(guardrails): refuse a substitution inside an extglob pattern outr…
fix(guardrails): cap the parses one command may take
fix(source-control): keep the worktree claim gate fail-open on a pars…
fix(guardrails): list here-doc bodies in the order the callbacks see …
fix(guardrails): read every here-doc body as a shell's script
fix(guardrails): refuse a here-doc only a second reading of the comma…
fix(guardrails): refuse every extglob form instead of reading it
chore(guardrails): re-run pr-verify after recording the latency comma…