Skip to content

refactor(discover): one segmenter behind the permission and classify walkers - #4131

Merged
KuSh merged 1 commit into
developfrom
lex/03-one-segmenter
Oct 28, 2026
Merged

KuSh merged 1 commit into
developfrom
lex/03-one-segmenter

Conversation

@KuSh

@KuSh KuSh commented Sep 19, 2026 •

Copy link
Copy Markdown
Collaborator

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.

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 stack
  • the differential harness replays 13,020 generated compound commands through both policies and the frozen walkers they replaced, and requires identical segmentation

Part of stack #4139 (#4129 → #4138). Based on #4130. Each commit gates green on its own, so the stack is bisectable.

🤖 Generated with Claude Code

@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

♻️ Type refactor
🟡 Risk medium

Summary

Refactors 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 Policy/segment() function. split_for_permissions and split_on_operators now become thin wrappers around this shared implementation, preserving their documented behavioral differences via policy flags.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Analyzed automatically by wshm · This is an automated analysis, not a human review.

@KuSh
KuSh marked this pull request as ready for review September 19, 2026 16:22
@KuSh
KuSh force-pushed the lex/03-one-segmenter branch from 5101168 to dbc59a3 Compare September 19, 2026 21:13
@KuSh
KuSh force-pushed the lex/03-one-segmenter branch from dbc59a3 to b3f0f02 Compare September 20, 2026 23:23
@KuSh
KuSh force-pushed the lex/03-one-segmenter branch from b3f0f02 to 8923aff Compare September 25, 2026 22:55
@KuSh
KuSh force-pushed the lex/03-one-segmenter branch 2 times, most recently from 947f9fd to 7cee497 Compare September 25, 2026 23:29
@KuSh
KuSh force-pushed the lex/03-one-segmenter branch 6 times, most recently from 6dad969 to fd982b7 Compare October 2, 2026 15:07
@KuSh
KuSh force-pushed the lex/03-one-segmenter branch 2 times, most recently from 964d7f4 to ee8738d Compare October 7, 2026 07:16
@KuSh
KuSh force-pushed the lex/03-one-segmenter branch 2 times, most recently from 78bb9d0 to ec82c51 Compare October 9, 2026 16:16
@KuSh
KuSh force-pushed the lex/03-one-segmenter branch from ec82c51 to fa8cc2d Compare October 9, 2026 16:27
Base automatically changed from lex/02-case-terminators to develop October 9, 2026 20:29
@KuSh
KuSh force-pushed the lex/03-one-segmenter branch 3 times, most recently from a2a41fa to 544df21 Compare October 15, 2026 12:03
@KuSh
KuSh force-pushed the lex/03-one-segmenter branch 2 times, most recently from 6809bda to ea3f43f Compare October 20, 2026 23:52

@pszymkowiak pszymkowiak left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@KuSh
KuSh force-pushed the lex/03-one-segmenter branch from ea3f43f to 1d51994 Compare October 26, 2026 11:29
…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]>
@KuSh
KuSh force-pushed the lex/03-one-segmenter branch from 1d51994 to 4576032 Compare October 28, 2026 23:40
@KuSh
KuSh merged commit 7e92da0 into develop Oct 28, 2026
20 checks passed
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Oct 28, 2026
@KuSh
KuSh deleted the lex/03-one-segmenter branch October 28, 2026 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants