feat(hook): parse bash with rable instead of scanning it - #875
Closed
wenzowski wants to merge 2 commits into
Closed
Conversation
`hook::segments` decided every mediated deny from a character walk: one `chars.next()` loop that hand-rolled quoting, escapes, heredoc bodies, here-strings and a positional test for whether an `&` belonged to a redirection. It could not fail, so a command it mis-split produced a confident wrong shape that no gate could tell from a correct one. CLOUD-857 measured that once already -- `git push --force` denied while `cd /tmp && git push --force` was allowed, with a green suite over it -- and CLOUD-269 was an earlier patch to the same loop, which is the pattern this replaces rather than continues. It is a real parse now: `rable`, a GNU Bash 5.3-compatible recursive descent parser. MIT, already on `deny.toml`'s allow list, and `default-features = false` leaves `thiserror` as the only runtime dependency -- nothing reaches the network, builds a runtime, or moves `ambient_authority.rs`'s `AMBIENT_CRATES`. Two properties follow that a scanner cannot have. It can say it does not know. `segments` returns `Look<Vec<Segment>>`, so an unparseable command abstains: row selectors select nothing, deciders allow, and `input.call.segments` projects `null`, which Rego reads as undefined. The call still proceeds -- `3` never blocks -- but under-denial has stopped being byte-identical to a clean read, which is the direction CLOUD-1381 calls bypass. And it descends. `$(...)`, `<(...)`, a subshell and a compound body all carry parsed commands, and the walk reached none of them (CLOUD-1257). A protected write inside a substitution is judged now. CLOUD-1287's over-deny goes with the walk. `line_bounded_words` and `joined_lines` existed only because a segment was a text span, so one segment resolved the first line's program for every operand on every line -- measured as `stat` refused while naming `cd`. Each command owns its own operands now, so there is nothing left to re-split. Three things the swap does NOT buy, stated rather than absorbed. The parser delimits words and does not remove quotes; `unquote` is still hand-written. It is a leaf operation over a token whose extent is already settled, which is a different risk class from deciding the extent. A newline is still whitespace and not a separator. `rable` returns one node per line and those are rejoined, because promoting it would move every landed `verdict-not-discarded` verdict -- a decision about that rule's reach, not about this parser. And the dependency is checked rather than trusted. Three of its arms are correct as a grammar and wrong as a drop-in here, each found by the existing corpus rather than by reading: redirect tokens leave `words`, which would have stopped `rm > guarded.md` being judged on its target; `2>&1` spans `>&1` with the descriptor in a typed field beside it; and `rm "unclosed path` returns Ok with the operand silently GONE. The first two are reconstructed, and the third is caught by `covered`, which asks the parse about itself using its own spans and abstains when it dropped input. One landed case moved and is renamed rather than re-pointed: `an_unterminated_quote_keeps_its_tail_as_one_word` asserted the walk's guess and is now `..._abstains_rather_than_inventing_a_word`. Weaker on that one input, stronger everywhere the guess was wrong -- and a guess that is right is indistinguishable from a guess that is wrong. 201 hook cases green, 195 of them unedited. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AkFLSqd83j2ZtJAmAXxDfZ
|
Warning Review limit reachedNext included review available in 19 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Team Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (4)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The parent commit's message claimed `rable`'s one-node-per-line output was
rejoined so that a newline stayed whitespace for segment identity. It was
not. The rejoining was designed and described and never written, and the
claim was asserted rather than checked --
`mediated_verbs::a_newline_did_not_become_a_separator` is a landed case
named for that exact invariant and it went red.
The design error under the slip is the part worth recording, because it
is a live tension in the tree rather than a typo. Two landed rows pull
opposite ways on the same character:
* CLOUD-1287 needs a newline to be a boundary for PROGRAM identity.
Measured over the shipped binary: `stat -c %s batten.toml` allowed
bare, and the identical `stat` on line two after a `cd /tmp` refused,
naming `cd`, because one segment resolved the first line's program
for every operand on every line.
* `a_newline_did_not_become_a_separator` needs it NOT to be a boundary
for SEGMENT identity. `mise run verify` with `| tail -1` on the next
line has to stay one segment, or the pager stops discarding the
status and a landed `verdict-not-discarded` deny is lost.
`line_bounded_words` was the seam holding those apart, and the parent
commit deleted it as redundant to the parse. It was not redundant; it was
the only thing keeping the two answers separate.
So the segment spans the newline again, and `Segment::lines` carries the
per-command split that `protected_mutation` reads. It is derived from the
parse now rather than by re-splitting `raw`, which is the part the parser
genuinely improves -- and it is private, because no module asks for it
and a schema key with no predicate behind it is surface with no consumer.
The case this file added for CLOUD-1287 asserted the wrong half too, and
now asserts both together: the tempting simplification -- one segment per
parsed line -- satisfies the first row and breaks the second, which is
precisely what happened here.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AkFLSqd83j2ZtJAmAXxDfZ
|
❌ The last analysis has failed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closed: opened in error. Both commits are cherry-picked onto the
hk-presetbundle branch and land through #873 instead — one branch, many rows, one PR, perAGENTS.md. Splitting CLOUD-1381 onto its own PR was my mistake, not a scope decision.The work itself is unchanged and is in #873 as
feat(hook): parse bash with rable instead of scanning itandfix(hook): a newline splits the program, not the segment.