Repository navigation
Conversation
1 of 3 tasks
📊 Automated PR Analysis
SummaryThis PR refactors the segment rewrite logic in rtk's discover module to lex each line once into a CompoundLex and express rewrites as a list of Edit operations (Insert/Replace) applied to the original byte spans, rather than re-tokenizing and reassembling strings at each step. It also improves the #2768 fall-through logic to skip already-tried (position, depth) pairs for linear performance on chains like repeated Review Checklist
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
KuSh
force-pushed
the
lex/13-span-edits
branch
2 times, most recently
from
October 5, 2026 22:36
e1f4173 to
384e98b
Compare
KuSh
force-pushed
the
lex/13-span-edits
branch
from
October 7, 2026 07:16
384e98b to
dfa62c8
Compare
KuSh
force-pushed
the
lex/13-span-edits
branch
2 times, most recently
from
October 9, 2026 16:27
c3b901a to
502b8e2
Compare
KuSh
force-pushed
the
lex/13-span-edits
branch
from
October 9, 2026 20:29
502b8e2 to
6855789
Compare
KuSh
force-pushed
the
lex/13-span-edits
branch
from
October 15, 2026 00:24
6855789 to
e789e06
Compare
KuSh
force-pushed
the
lex/13-span-edits
branch
2 times, most recently
from
October 19, 2026 16:38
454a6b0 to
ee36440
Compare
KuSh
force-pushed
the
lex/13-span-edits
branch
from
October 21, 2026 00:03
ee36440 to
4907c60
Compare
KuSh
force-pushed
the
lex/13-span-edits
branch
2 times, most recently
from
October 29, 2026 13:16
59d6cd8 to
25788d7
Compare
KuSh
force-pushed
the
lex/13-span-edits
branch
from
October 31, 2026 16:42
25788d7 to
19b5338
Compare
KuSh
force-pushed
the
lex/13-span-edits
branch
from
November 1, 2026 16:42
19b5338 to
9a1df5d
Compare
TaKO8Ki
force-pushed
the
lex/13-span-edits
branch
from
November 2, 2026 11:31
9a1df5d to
ef1d545
Compare
KuSh
force-pushed
the
lex/13-span-edits
branch
from
November 3, 2026 00:58
ef1d545 to
c2950bb
Compare
KuSh
force-pushed
the
lex/13-span-edits
branch
from
November 3, 2026 06:27
c2950bb to
793bcb4
Compare
KuSh
marked this pull request as draft
November 4, 2026 07:41
KuSh
force-pushed
the
lex/13-span-edits
branch
from
November 5, 2026 11:48
793bcb4 to
8f05cdc
Compare
KuSh
force-pushed
the
lex/13-span-edits
branch
from
November 5, 2026 12:12
8f05cdc to
59cfe26
Compare
KuSh
marked this pull request as ready for review
November 5, 2026 12:22
KuSh
force-pushed
the
lex/13-span-edits
branch
from
November 17, 2026 01:42
59cfe26 to
bd6972e
Compare
KuSh
force-pushed
the
lex/13-span-edits
branch
from
November 18, 2026 01:06
bd6972e to
d3e1063
Compare
KuSh
force-pushed
the
lex/13-span-edits
branch
2 times, most recently
from
November 21, 2026 09:57
2a7e011 to
e2d0353
Compare
KuSh
force-pushed
the
lex/13-span-edits
branch
from
November 23, 2026 00:14
e2d0353 to
5aad4cc
Compare
KuSh
force-pushed
the
lex/13-span-edits
branch
2 times, most recently
from
November 27, 2026 22:44
66fd71d to
70fa994
Compare
KuSh
force-pushed
the
lex/13-span-edits
branch
from
November 28, 2026 01:23
70fa994 to
df453b9
Compare
The rewrite lexes a command line once, into a `CompoundLex`, and reads everything else from those tokens: the heredoc refusal, whether a line already runs through rtk, each line of a multi-line block, each segment and pipeline stage, and the words and argv the decision checks (the program word, golangci's global flags, cat's options, a pipeline consumer's flags, grep's and rg's pattern files). A `Slice` is one command's run of tokens, from its first word to the end of its last, so an escaped or quoted blank that ends the last word stays in the command. The lexer exposes `resolve_words` to the crate, so a command resolves its own words, and keeps `resolve_word_text` to the `cmdline` module, where `rtk_invocation` reads a command's first words with it. A line runs through rtk when `rtk_invocation` says its words run rtk and no operator joins another command to it. A walk peels a segment's transparent layers left to right in one loop: an env run, a built-in wrapper, a process wrapper, a user prefix, in that order at each position, within the depth bound. The segment's words are found once, and each step reads them from the position the walk reached. Each `Layer` records at peel time what a later step reads: where it starts, and for a routable wrapper, the span of the command it wraps past any assignments, which is what its exclusion check matches. A prefix matched as text can end inside a token, as a user prefix `x 'a` ends inside the quote it opens; from there the walk reads a fresh lex of the rest of the command. Every other layer ends where a token starts, and a token starts where the lexer holds no quote, escape or word open, so the walk reads on through the segment's own tokens and words. When nothing is decided about the command under the layers, the #2768 fall-through retries each routable wrapper, innermost first, as a walk of its own from the wrapper's position and depth. A walk depends on nothing but that position and depth, so a pair already tried is skipped, which keeps the search over a `uv run uv run ... uv run` chain linear in its depth. A decision is one edit against the line, from `core::cmdline::edit`: `Insert { at, text }` puts `rtk ` in front of a command, and `Replace { span, text }` renames one. Every byte outside an edit is emitted as written. `apply_edits` takes the edits in position order, sizes its output from the line and the edit texts, and returns `None` for an overlapping, reversed, out-of-range or off-boundary span rather than panic. The `RTK_DISABLED` warning looks for a heredoc in the command as written. The rewrite output is byte-identical to its parent: `rtk rewrite` stdout, stderr and exit code, with and without a catch-all project filter, and the hook's verdicts. A quoted `sh|bash|zsh|fish -c` script is rewritten the same way, one wrapper deep: when the command a walk reaches is such a wrapper, its script is lexed and rewritten into edits of its own, and the wrapper's bytes around it are kept. A wrapper is the command wherever the walk reaches one, before any layer is peeled there, as the parent read it first: a user prefix that begins with its words (`sh -c "`) is not peeled off it. A wrapper is still reached at the prefix-depth limit, where no further layer is peeled. Co-Authored-By: Claude Opus 5.5 <[email protected]>
KuSh
force-pushed
the
lex/13-span-edits
branch
from
November 29, 2026 01:42
df453b9 to
15dc3c3
Compare
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.
The rewrite lexes a line once and expresses each decision as edits on the original bytes.
CompoundLexper line. The heredoc refusal, the already-rtk check, segments, pipeline stages and the words each decision checks all read its tokens.Layerrecords at peel time what later steps read.Edits (Insert,Replace) thatapply_editsincore::cmdline::editapplies; every byte outside an edit is emitted as written.uv runstays linear.Behaviour changes:
sh -c "), words after the wrapper's closing quote are no longer rewritten. Bash passes them to the script as arguments:sh -c " sh -c " exec uv run …never runsuv.headortailwith a redirect glued to a control byte (head -5 f 2>&1\x0b) is not rewritten, since that byte is part of the redirect's target.Otherwise
rtk rewritestdout, stderr and exit code, with and without a catch-all project filter, and the hook's verdicts are byte-identical to the parent.Test plan
cargo fmt --all --check && cargo clippy --all-targets -- -D warnings && cargo test --all: 6106 passing, clippy clean, at this commitwincheck.sh(cfg(windows) type-check) cleanPart of stack #4139. Based on #4341. Each commit gates green on its own, so the stack is bisectable.
🤖 Generated with Claude Code