Repository navigation
refactor(discover): one segmenter behind the permission and classify walkers - #4131
Conversation
📊 Automated PR Analysis
SummaryRefactors the compound-command segmenter in discover/lexer.rs to unify the three previously-separate segmentation behaviors (permission gate, analytics classification, and rewrite) behind a single configurable Review Checklist
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
5101168 to
dbc59a3
Compare
dbc59a3 to
b3f0f02
Compare
b3f0f02 to
8923aff
Compare
947f9fd to
7cee497
Compare
6dad969 to
fd982b7
Compare
964d7f4 to
ee8738d
Compare
78bb9d0 to
ec82c51
Compare
ec82c51 to
fa8cc2d
Compare
a2a41fa to
544df21
Compare
6809bda to
ea3f43f
Compare
pszymkowiak
left a comment
There was a problem hiding this comment.
Verified on ea3f43f6: fmt and clippy clean, cargo test --all 5032 green, CI green, clean dry-run merge onto develop. End-to-end differential develop vs this head, with allow/deny/ask rules active: rtk rewrite on 14,039 generated compound commands (wrappers, groups, redirects, quoting) and rtk hook claude on 22 shell-wrapper cases — 0 differences. The read of segment() against the two walkers it replaces matches: every branch is one of theirs, selected by a Policy field.
ea3f43f to
1d51994
Compare
…walkers `split_for_permissions` and `split_on_operators` each walked the token stream themselves. The differences between them were real and deliberate — the gate must break on everything a command could hide behind, classification must not pretend to — but they were emergent, spelled out only in a comparison table in a doc comment and re-derived in two places. Both now call one `segment(cmd, Policy)`. The differences become a `Policy`: which newline mode, whether `&`/`(`/`)` end a segment, whether redirects are kept or excised, whether to stop at the first pipe. What was a table of accidents is now a pair of constants. `Segment` carries the byte range each command occupies as well as its text, which the rewrite needs to splice around a command rather than rebuild the line from tokens. Behaviour is unchanged, and that is the point, so it is asserted rather than claimed: both walkers are kept under `#[cfg(test)]` and a generated corpus of over five thousand compound commands — every command shape crossed with every separator, wrapper and redirect form — must segment identically through the old walker and the new policy. Mutating the new segmenter (dropping `)` as a boundary, ignoring `stop_at_pipe`) fails that test on a named input. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1d51994 to
4576032
Compare
split_for_permissionsandsplit_on_operatorseach walked the token streamthemselves. The differences between them were real and deliberate — the gate
must break on everything a command could hide behind, classification must not
pretend to — but they were emergent, spelled out only in a comparison table
in a doc comment and re-derived in two places.
Both now call one
segment(cmd, Policy). The differences become aPolicy:which newline mode, whether
&/(/)end a segment, whether redirects arekept or excised, whether to stop at the first pipe. What was a table of
accidents is now a pair of constants.
Segmentcarries the byte range each command occupies as well as its text,which the rewrite needs to splice around a command rather than rebuild the
line from tokens.
Behaviour is unchanged, and that is the point, so it is asserted rather than
claimed: both walkers are kept under
#[cfg(test)]and a generated corpus ofover five thousand compound commands — every command shape crossed with every
separator, wrapper and redirect form — must segment identically through the
old walker and the new policy. Mutating the new segmenter (dropping
)as aboundary, ignoring
stop_at_pipe) fails that test on a named input.Test plan
cargo fmt --all && cargo clippy --all-targets && cargo test --all— 3854 passing, clippy clean, at this commit rather than only at the tip of the stackPart of stack #4139 (#4129 → #4138). Based on #4130. Each commit gates green on its own, so the stack is bisectable.
🤖 Generated with Claude Code