Repository navigation
Conversation
KuSh
marked this pull request as draft
November 5, 2026 23:42
📊 Automated PR Analysis
SummaryFixes rtk discover and rtk session to count every line of a multi-line call instead of only the first line, by sharing a new block_lines helper with the rewrite logic so lines are split the same way the hook rewrites them. Adds a joined_or_as_written lexer helper, updates total_commands/session adoption counting, and documents known limits (CRLF blocks, quoted newlines, comment-only blocks, quadratic cost on very long blocks). Review Checklist
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
KuSh
force-pushed
the
fix/report-reads-every-line
branch
2 times, most recently
from
November 8, 2026 17:13
5fda834 to
dd2e469
Compare
KuSh
force-pushed
the
fix/report-reads-every-line
branch
from
November 13, 2026 17:09
dd2e469 to
ecf9213
Compare
KuSh
changed the base branch from
lex/14-grammar-tables
to
feat/4315-1-cmdline-walker
November 13, 2026 17:09
6 tasks done
KuSh
force-pushed
the
fix/report-reads-every-line
branch
from
November 17, 2026 01:42
ecf9213 to
4958129
Compare
KuSh
force-pushed
the
fix/report-reads-every-line
branch
3 times, most recently
from
November 21, 2026 09:57
d686902 to
2ccb71f
Compare
KuSh
force-pushed
the
fix/report-reads-every-line
branch
2 times, most recently
from
November 25, 2026 02:13
510f28a to
4443ba3
Compare
KuSh
force-pushed
the
fix/report-reads-every-line
branch
2 times, most recently
from
November 28, 2026 01:23
48f85b4 to
ff8f0fb
Compare
`rtk discover` and `rtk session` read a multi-line call as one command, so only its
first line was classified: `git status\ngit log` counted one command, and
`cd x\ngit status` none it could offer a saving on, although the rewrite acts on each
line. A session's adoption now also counts the lines rtk does not handle.
The report's commands are now the rewrite's own: one walk over the rewrite's lex,
`cut_line`, decides every boundary, and both the rewrite and
`split_command_chain_parts` take their segments from it. A block is read line by line
as the rewrite reads it: a line is a command, a trailing operator joins the next
line, a blank or comment-only line is no command. The `\r` of a CRLF is the last byte
of its line, in its last word or its comment, as bash and the rewrite read it. A block
the rewrite refuses to read line by line, such as one with a subshell or a loop spread
over lines, stays one command, as the rewrite leaves it whole; its lines are not counted
one by one, a known limit until the rewrite reads such blocks. A pipe or an operator
inside `$( )`, `<( )` or `>( )` belongs to the command that substitution runs, in a
pipeline's stages too. A heredoc with an fd number in front
(`cat 0<<EOF`) is a heredoc too. Each command of a call is read once, for its share of
the output and for its row.
A group's own words are no command: neither `do` or `then` alone, nor a closing `}`,
`done`, `fi` or `esac` with the redirects after it, which belong to the commands inside
the group. Nor is a comment alone, so a call of comments counts no command. A stage
after a pipe reads it whatever stands in front of the pipe, so `tail` in
`{ git status; } 2>&1 | tail -1` is a consumer. A group a later stage opens, a subshell,
a `{ }` group or a `while`, `for`, `if` or `case`, is cut into its commands, which all
read the pipe, and the pipeline goes on past it, so `tail` in
`git log | (head -5; tail -5)` and in `git log | while read l; do tail -1; done` is a
consumer too, and a `case` pattern there belongs to no command, as anywhere. The `)` of a
subshell a pipeline stands in ends that pipeline. The rewrite leaves any line with a pipe
and a bracket as written, and the commands of a compound a pipe joins as they are, so
neither change reaches its answer.
A call has one measured output, which went to its last command and was lost when that
was an `echo`. Which command wrote what of it cannot be told apart, so the call's
commands now share it by category average, marked estimated, and a call of one command
takes it whole. A command with no rule is most often a builtin or a small tool, so it
weighs less than any category: in `git status && echo ok` and `cargo test; echo done`,
the command with a rule keeps most of the measurement. A command that runs rtk weighs
the average of any command, since the classifier leaves it aside although it runs a
tool. A function body's commands take a share like any other, although defining the
function runs none of them; that is a known limit of this estimate.
The hook's checks of a call's whole line are worked out once per call instead of once
per command, so a call of many commands costs its length rather than its square.
`rewrite_command`, from which the report reads which commands the rewrite reached,
changes in two ways. A backquote is a substitution, as `$( )` is: nothing in one is a
boundary, so `ls `a | b`` is one command, and a block with a newline inside one is no
longer read line by line. A heredoc with an fd number in front (`cat 0<<EOF`,
`cat 0<<<x`) is one text that is not rewritten, as one without it already was. The
hook's answer does not change, as it leaves any substitution or heredoc alone before it
asks for a rewrite.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
KuSh
force-pushed
the
fix/report-reads-every-line
branch
from
November 29, 2026 01:42
ff8f0fb to
601eb52
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.
Summary
rtk discoverandrtk sessionread a multi-line call as one command and classified only its first line.git status\ngit logcounted one command, andcd x\ngit statusoffered no saving at all, although the rewrite acts on each line.The report's commands are now the rewrite's own. One walk over the rewrite's lex,
cut_line, decides every boundary, and both the rewrite andsplit_command_chain_partstake their segments from it. A block is read line by line as the rewrite reads it: a line is a command, a trailing operator joins the next line, and a blank or comment-only line is no command. Each command of a call is read once, for its share of the output and for its row.Built on #4402. It uses that PR's walker.
Behaviour changes
total_commandsand session adoption now count every line, including lines rtk doesn't handle, so a multi-line setup script lowers a session's adoption.do,done,fi,}) and the redirects after a closing word or a subshell's)are no command. A comment alone is no command, so a call of comments counts none.tailingit log | (head -5; tail -5)and ingit log | while read l; do tail -1; doneis a consumer. Acasepattern belongs to no command.git status && echo okandcargo test; echo donethe command with a rule keeps most of the measurement. On develop the last command takes it all, and the number is lost when that command is anecho.rewrite_commandreads a backquote as a substitution, as it reads$( ): nothing inside one is a boundary. A heredoc with an fd number in front (cat 0<<EOF) is one text that is not rewritten. The hook's answer doesn't change, because it already leaves any substitution or heredoc alone.Known limits
Test plan
cargo fmt --all,cargo clippy --all-targets,cargo test --allrtk rewriteoutput identical before and after on 2,492 recorded calls, a 325-shape sweep and 63 hand shapesrtk discovercompared call by call on 2,954 recorded calls; each of the 80 differences is a change or a limit listed above, or already happens on the base🤖 Generated with Claude Code