Skip to content

feat(hook): parse bash with rable instead of scanning it - #875

Closed
wenzowski wants to merge 2 commits into
mainfrom
claude/cloud-1381-rable-parser
Closed

feat(hook): parse bash with rable instead of scanning it#875
wenzowski wants to merge 2 commits into
mainfrom
claude/cloud-1381-rable-parser

Conversation

@wenzowski

@wenzowski wenzowski commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Closed: opened in error. Both commits are cherry-picked onto the hk-preset bundle branch and land through #873 instead — one branch, many rows, one PR, per AGENTS.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 it and fix(hook): a newline splits the program, not the segment.

`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
@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 19 minutes.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 00abf7e3-362f-4119-9185-cb78b271c606

📥 Commits

Reviewing files that changed from the base of the PR and between 1599577 and 9658066.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • .claude/rules/policy-modules.md
  • Cargo.toml
  • crates/batten/Cargo.toml
  • crates/batten/src/hook.rs

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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
@sonarqubecloud

sonarqubecloud Bot commented Sep 5, 2026

Copy link
Copy Markdown

❌ The last analysis has failed.

See analysis details on SonarQube Cloud

@wenzowski wenzowski closed this Sep 5, 2026
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.

1 participant