Repository navigation
Conversation
4 tasks done
KuSh
marked this pull request as ready for review
September 19, 2026 16:21
KuSh
force-pushed
the
lex/07-subshell-boundary
branch
from
September 19, 2026 21:13
1ac6bef to
d3f03e5
Compare
KuSh
force-pushed
the
lex/07-subshell-boundary
branch
from
September 20, 2026 23:23
d3f03e5 to
18b47d4
Compare
KuSh
force-pushed
the
lex/07-subshell-boundary
branch
from
September 25, 2026 22:55
18b47d4 to
7f5df9e
Compare
KuSh
force-pushed
the
lex/07-subshell-boundary
branch
2 times, most recently
from
September 25, 2026 23:29
86ef2e0 to
33e5b49
Compare
KuSh
force-pushed
the
lex/07-subshell-boundary
branch
from
September 26, 2026 17:56
33e5b49 to
042d2b0
Compare
KuSh
force-pushed
the
lex/07-subshell-boundary
branch
5 times, most recently
from
October 2, 2026 15:07
97a5262 to
2c77878
Compare
KuSh
force-pushed
the
lex/07-subshell-boundary
branch
from
October 5, 2026 22:36
2c77878 to
47f858b
Compare
KuSh
force-pushed
the
lex/07-subshell-boundary
branch
2 times, most recently
from
October 9, 2026 11:07
157fdfd to
4868dda
Compare
TaKO8Ki
self-requested a review
October 9, 2026 14:48
KuSh
force-pushed
the
lex/07-subshell-boundary
branch
from
October 9, 2026 16:16
4868dda to
b7c011b
Compare
KuSh
force-pushed
the
lex/07-subshell-boundary
branch
3 times, most recently
from
October 20, 2026 23:52
b9f1ace to
d4c618f
Compare
2 tasks done
KuSh
force-pushed
the
lex/07-subshell-boundary
branch
4 times, most recently
from
October 31, 2026 14:53
b563c4e to
64120f0
Compare
KuSh
force-pushed
the
lex/07-subshell-boundary
branch
2 times, most recently
from
November 1, 2026 15:19
1cc2472 to
15a4577
Compare
TaKO8Ki
force-pushed
the
lex/07-subshell-boundary
branch
from
November 2, 2026 11:31
15a4577 to
bfd411a
Compare
KuSh
force-pushed
the
lex/07-subshell-boundary
branch
2 times, most recently
from
November 3, 2026 06:27
4b67dee to
43aedf6
Compare
KuSh
marked this pull request as draft
November 4, 2026 07:41
KuSh
force-pushed
the
lex/07-subshell-boundary
branch
from
November 5, 2026 11:48
43aedf6 to
2f5e30e
Compare
KuSh
marked this pull request as ready for review
November 5, 2026 12:22
KuSh
force-pushed
the
lex/07-subshell-boundary
branch
from
November 17, 2026 01:42
2f5e30e to
6fb8a34
Compare
KuSh
force-pushed
the
lex/07-subshell-boundary
branch
from
November 18, 2026 01:06
6fb8a34 to
91edd3e
Compare
KuSh
force-pushed
the
lex/07-subshell-boundary
branch
2 times, most recently
from
November 21, 2026 09:57
b268c4e to
f857e44
Compare
Three consumers read the same command line — the permission gate, the report's
classification, and the rewrite — and they disagreed about what a command was.
Each disagreement was a bug already happening rather than one waiting to.
`(git status; cargo build)` was the clearest. The gate split it, the other two
did not, so the rewrite glued the bracket to the text beside it: `(git status`
matched no rule while `cargo build)` matched, and one command of a pair was
filtered while the other silently was not. `(git status)` was rewritten not at
all. A subshell runs the commands it wraps, so `(` and `)` now end a command for
classification and for the rewrite, as they always did for the gate. Background
`&` was the same story and gets the same answer.
The two places that must not follow are now stated rather than assumed:
A `$( )` is not a subshell for this purpose. Its body runs, so the gate
descends and holds it to the deny rules; the other two stay out, because the
text around a substitution is not a command of its own — descending invents a
`git log $` nobody ran — and what it captures is a string the outer command is
built from, so filtering it would change that string rather than what reaches
anyone. `Policy::descend_into_substitution` carries that, and the emitter tracks
the same depth.
Staying out means every separator, not only the brackets. `&&`, `||`, `;` and
`|` inside a substitution separate commands whose output becomes one word of the
command being built, so none of them ends a command out here — otherwise
`echo $(git status && git log)` prints a line nobody wrote. Brackets nest, so a
`(` inside a substitution counts up as well, or its `)` closes the substitution
one bracket early and the real closing `)` reads as a boundary out here.
`<( )` and `>( )` are substitutions too. They hand the outer command a file
rather than text, but the inner command serves the outer one just the same, so
none of the three is a place to end a command or to filter output somebody else
is about to parse. Reading only `$` left `diff <(a) <(b)` classified as four
commands — two of them the fragments `diff <` and `<` — which `rtk session`
counts without the unattestable-construct check that shields the hook, so its
adoption figure was being computed from commands that never ran.
A `{ }` is not a subshell either. `{` opens a group only at a command position;
anywhere else it is brace expansion, and `ls {a,b}.txt` is one command. The gate
copes by stripping the bracket before matching, so nothing hides behind one.
Nor is `name()` one. It names a function, so the word before it runs nothing and
`rtk ls() {` does not parse: classification and the rewrite skip the word and the
empty pair, and read the body as usual. A `(` glued to a word, as in `a[(b)]`,
`x=(a b)` or `@(a|b)`, ends no command for them either, since it runs nothing of
its own.
A `case` pattern is the one place a `(` opens nothing. `case x in (ls) echo 1;;
esac` is the same statement as `case x in ls) echo 1;; esac`, so reading that
bracket as a subshell makes the pattern a command position: the rewrite turns a
one-word pattern into `(rtk ls)`, and bash refuses the line exactly as it refuses
a `;;` split into `; ;`. `CaseTracker` follows `case` through its `in`, each arm
terminator and its `esac`, and both segmenters consult it before reading a `(` as
a boundary. `case` counts as the keyword only in command position, so `echo case`
stays a word. The `)` still ends the pattern, so an arm's own commands are
rewritten whether or not the pattern was written with brackets.
`mod segmenter_consistency` becomes `segmenter_agreement`. It used to pin three
answers to one question and call the disagreement deliberate; it now asserts the
agreement where it exists and names the reason for each place it does not. A
divergence nobody can state a reason for is a bug.
`time (cargo build)` becomes `time (rtk cargo build)`. The wrapper never could
peel a `(`, but it no longer has to — the subshell is a boundary, so the command
inside is rewritten where it stands and the wrapper keeps wrapping the subshell.
A pipeline's swap runs a line in a child `sh`, which may read a subshell or a
compound command otherwise or not at all, and its checks read words rather than that
grammar. Now that the rewrite reaches into them, a line holding one takes the
ordinary rewrite rather than the swap.
The differential harness keeps both halves. The gate's is unchanged — a gate
that segments differently is a gate with different holes — and the legacy walker
it compares against is untouched. Classify can no longer be compared to that
walker, which describes a policy this commit deliberately changed, so it is
compared to the gate instead: on any input without a newline, a redirect or a
substitution the two hold the same policy and must agree exactly, which anchors
classify to the frozen walker through the gate. The corpus also gains the
substitution shapes it never had, including the nested and unterminated ones.
A span invariant sits alongside it — every segment is text that was really
there, at the span it claims, in order and without overlap. That is worth having
against arithmetic slips but it is not a segmentation contract: gaps between
segments are legal, since that is where the separators live, so a boundary read
in the wrong place passes it. Its comment says so rather than implying
otherwise.
Also corrects `.claude/rules/rust-patterns.md`, which required argument parsing
to go through `tokenize_with_options`. There is no such function; it is
`tokenize_grammar` (`src/core/arg_tokenizer.rs:296`).
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
KuSh
force-pushed
the
lex/07-subshell-boundary
branch
from
November 25, 2026 02:13
f857e44 to
77f96a8
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.
Three consumers read the same command line — the permission gate, the report's
classification, and the rewrite — and they disagreed about what a command was.
Each disagreement was a bug already happening rather than one waiting to.
(git status; cargo build)was the clearest. The gate split it, the other twodid not, so the rewrite glued the bracket to the text beside it:
(git statusmatched no rule while
cargo build)matched, and one command of a pair wasfiltered while the other silently was not.
(git status)was rewritten not atall. A subshell runs the commands it wraps, so
(and)now end a command forclassification and for the rewrite, as they always did for the gate. Background
&was the same story and gets the same answer.The two places that must not follow are now stated rather than assumed:
A
$( )is not a subshell for this purpose. Its body runs, so the gatedescends and holds it to the deny rules; the other two stay out, because the
text around a substitution is not a command of its own — descending invents a
git log $nobody ran — and what it captures is a string the outer command isbuilt from, so filtering it would change that string rather than what reaches
anyone.
Policy::descend_into_substitutioncarries that, and the emitter tracksthe same depth.
Staying out means every separator, not only the brackets.
&&,||,;and|inside a substitution separate commands whose output becomes one word of thecommand being built, so none of them ends a command out here — otherwise
echo $(git status && git log)prints a line nobody wrote. Brackets nest, so a(inside a substitution counts up as well, or its)closes the substitutionone bracket early and the real closing
)reads as a boundary out here.<( )and>( )are substitutions too. They hand the outer command a filerather than text, but the inner command serves the outer one just the same, so
none of the three is a place to end a command or to filter output somebody else
is about to parse. Reading only
$leftdiff <(a) <(b)classified as fourcommands — two of them the fragments
diff <and<— whichrtk sessioncounts without the unattestable-construct check that shields the hook, so its
adoption figure was being computed from commands that never ran.
A
{ }is not a subshell either.{opens a group only at a command position;anywhere else it is brace expansion, and
ls {a,b}.txtis one command.(hasno such ambiguity, which is why it became a boundary and
{did not. The gatecopes by stripping the bracket before matching, so nothing hides behind one.
Nor is
name()one. It names a function, so the word before it runs nothing andrtk ls() {does not parse: classification and the rewrite skip the word and theempty pair, and read the body as usual. A
(glued to a word, as ina[(b)],x=(a b)or@(a|b), ends no command for them either, since it runs nothing ofits own.
A
casepattern is the one place a(opens nothing.case x in (ls) echo 1;; esacis the same statement ascase x in ls) echo 1;; esac, so reading thatbracket as a subshell makes the pattern a command position: the rewrite turns a
one-word pattern into
(rtk ls), and bash refuses the line.CaseTrackerfollowscasethrough itsin, each arm terminator and itsesac, and both segmentersconsult it before reading a
(as a boundary.A pipeline's swap runs a line in a child
sh, which may read a subshell or acompound command otherwise or not at all, and its checks read words rather than that
grammar. Now that the rewrite reaches into them, a line holding one takes the
ordinary rewrite rather than the swap.
mod segmenter_consistencybecomessegmenter_agreement. It used to pin threeanswers to one question and call the disagreement deliberate; it now asserts the
agreement where it exists and names the reason for each place it does not. A
divergence nobody can state a reason for is a bug.
time (cargo build)becomestime (rtk cargo build). The wrapper never couldpeel a
(, but it no longer has to — the subshell is a boundary, so the commandinside is rewritten where it stands and the wrapper keeps wrapping the subshell.
The differential harness keeps both halves. The gate's is unchanged — a gate
that segments differently is a gate with different holes — and the legacy walker
it compares against is untouched. Classify can no longer be compared to that
walker, which describes a policy this commit deliberately changed, so it is
compared to the gate instead: on any input without a newline, a redirect or a
substitution the two hold the same policy and must agree exactly, which anchors
classify to the frozen walker through the gate. The corpus also gains the
substitution shapes it never had, including the nested and unterminated ones.
A span invariant sits alongside it — every segment is text that was really
there, at the span it claims, in order and without overlap. That is worth having
against arithmetic slips but it is not a segmentation contract: gaps between
segments are legal, since that is where the separators live, so a boundary read
in the wrong place passes it. Its comment says so rather than implying
otherwise.
Also corrects
.claude/rules/rust-patterns.md, which required argument parsingto go through
tokenize_with_options. There is no such function; it istokenize_grammar(src/core/arg_tokenizer.rs:296).Test plan
cargo fmt --all && cargo clippy --all-targets && cargo test --all— 5899 passing, clippy clean, at this commit rather than only at the tip of the stack(git status; cargo build)prefixes both commands and(git status)is rewritten, whilegit log $(git rev-parse HEAD~1)leaves the captured command alonePart of #4315 (#4129 → #4138). Based on #4134. Each commit gates green on its own, so the stack is bisectable.
🤖 Generated with Claude Code