Repository navigation
Conversation
📊 Automated PR Analysis
SummaryRefactors Review Checklist
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
KuSh
force-pushed
the
fix/report-from-rewrite-decisions
branch
2 times, most recently
from
November 18, 2026 01:06
2f59ab9 to
4b7e110
Compare
KuSh
force-pushed
the
fix/report-from-rewrite-decisions
branch
from
November 19, 2026 01:12
4b7e110 to
f98cb90
Compare
KuSh
force-pushed
the
fix/report-from-rewrite-decisions
branch
from
November 21, 2026 09:57
f98cb90 to
8c8e9e3
Compare
KuSh
force-pushed
the
fix/report-from-rewrite-decisions
branch
from
November 23, 2026 00:14
8c8e9e3 to
de9a813
Compare
KuSh
force-pushed
the
fix/report-from-rewrite-decisions
branch
from
November 25, 2026 02:13
de9a813 to
4c99980
Compare
KuSh
force-pushed
the
fix/report-from-rewrite-decisions
branch
from
November 27, 2026 22:44
4c99980 to
a92dca7
Compare
KuSh
force-pushed
the
fix/report-from-rewrite-decisions
branch
from
November 28, 2026 01:23
a92dca7 to
6298796
Compare
`rtk discover` learned which commands of a call the rewrite acts on by rewriting the whole line, cutting the rewritten text into commands again, and comparing each command's text with the one before. That is a second reading of the call, and it gave up on the whole line when the two cuts had a different number of commands. The rewrite records each change it makes as an edit, a span of the line it lexed, and the report's commands are cut by the same walk over the same lex. The report now asks the rewrite once, over that lex, and a command is reached when an edit falls in it. An edit is placed by where it starts among the commands' own offsets, not by its rank: a command the rewrite passes over has no edit, and nor has a stage in the middle of a pipeline. A call that could not be joined is not rewritten and reaches nothing, as the hook leaves it. `rewrite_command` and the hook are unchanged: they run the same rewrite over the same lex and tag nothing. No answer of the report changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`rtk discover` decided whether the hook covers a command by rewriting text it had rebuilt: the command alone for the estimate, and for a command behind `RTK_DISABLED=` the command with the bypass words cut out of its text. Each is a second reading of the call, run outside it, so its answer could disagree with what the hook does with the call as a whole. The report now asks the rewrite it already runs over the call's one lex. - The estimate of whether the hook covers a command is that an edit of the call's rewrite falls in it and the permission checks of the whole line leave the hook free to rewrite. A pipeline consumer the rewrite leaves raw no longer estimates as covered; no row moves from that alone, as the report already left such a consumer out. The measured `hook_decisions` path is unchanged. - The walk's `Stop::Disabled` carries the word the `RTK_DISABLED=` run starts at. A call with a command the rewrite refused there, in its first walk or in a walk of the search it fell back to, gets one more rewrite over the same lex, with every run the call's own walks stopped at read past, and that command would have been covered without the bypass when an edit then falls in it, in its own place in the call. A quoted script keeps its own runs, as the hook would meet them. A run is read as the words left when its `RTK_DISABLED` ones are taken out: none when it held no others, so the walk goes on from where it stood in front of it (`RTK_DISABLED=1 time -f %e cargo test` reads `time` as the reserved word), and an ordinary assignment layer when it did. A call with no such run is rewritten once; `rtk rewrite` and the hook are unchanged in output, and the only work they add is noting where a refused command's run starts. - `disposition` no longer takes whether the command is bypassed. A bypassed command that is not counted as a bypass is judged like the same command without the assignment, with the rewrite's answer for it without the bypass, and as not covered: it ran raw, whatever a measured `hook_decisions` row says of the call. - `rewrite_command_precompiled`, `estimate_hook_coverage` and `would_be_covered_without_bypass` lose their last caller and go. What the report answers differently: - A bypassed command the rewrite would leave raw where it sits is no longer counted as a bypass: a consumer at the end of a pipeline (`cargo test | RTK_DISABLED=1 tail -n 5 f.log`), and a producer when the rewrite takes the last stage (`RTK_DISABLED=1 cat f.log | grep ERROR`), when a consumer is not safe to leave (`RTK_DISABLED=1 git status | tee out.txt | head`) or when a consumer carries a bypass of its own. - Such a command, and a bypassed command that `exclude_commands` names, moved from the missed savings to where the plain command goes: an opportunity, or a consumer the report drops. A bypassed command the rewrite would take, which the hook's checks of the line refuse or no hook is installed for, stays a missed saving, whatever a measured row says of the call. - `RTK_DISABLED+=1 git status` is a bypass, as the rewrite's refusal reads it, and when it is no bypass its row is named `git status`: the words taken out of a bypassed command are the ones that refusal reads, not only those spelled `RTK_DISABLED=`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`rtk discover` and `rtk session` classified a command as written, and found an `RTK_DISABLED=` bypass and the command behind it with a shallow scan of their own, while the rewrite reads a command under its assignments, keyword prefixes and process wrappers. `timeout 30 cargo test` was an unsupported `timeout 30`, `time cargo test` and the body of a `then` or `do` were left out, `FOO=1 rtk git status` was no adoption, and a bypass in front of a wrapper (`RTK_DISABLED=1 timeout 5 git status`) was not found. The report read each call twice, with a reader that could disagree with the rewrite. The rewrite's decision about one command (the walk of its layers, the command it stops at, the search for a fall-through behind them, refusals and exclusions) is one function, `decide_segment`, and its outcome carries the word it settles at. The rewrite applies the edit; the report reads the command from that word. `read_call` makes the decision once for each command of the call, under the same `exclude_commands` and `transparent_prefixes`, for one the rewrite never visits as well (a stage in the middle of a pipeline, a producer behind a taken last stage). The command is therefore the one the hook acts on: under every layer the walk reads through (`timeout 30 cargo test` is `cargo test`), the one behind a user prefix (`nice -n 19 ionice git status` under that prefix is `git status`), a routable wrapper the search matched whole (`uv run python x.py`), and an `rtk` the rewrite keeps (`FOO=1 rtk git status`). Its row name, classification, output share and whether it runs rtk all come from it. Where nothing settles (no rule, the command excluded, a bypass refused) it is the command the walk the decision ended in stops at: the first walk's, or the furthest one the search read behind a user prefix, when it found a command (`nice -n 19 ionice frobnicate x` under that prefix is `frobnicate x`, as `timeout 30 frobnicate x` is). Where that is no command (an option, a redirect, grammar, or an assignment behind a wrapper: `env -i git status`, `command -v cargo`, `exec >log 2>&1`, `timeout 5 [[ -f x ]]`), it is the last layer's, as written, so the call keeps its row, unless that layer is a reserved word (`time -f %e cargo test`, `if -v cargo`): that is bash's grammar, and has no row. Assignments alone run nothing, and a walk that reaches its depth limit files the whole part. For a command the rewrite refuses at an `RTK_DISABLED=` run, in its walk or in a search for a fall-through, the decision is made again with the run read past: the bypass bucket's name is the command it would run without the bypass, and a bypass needs a rule, as before. `rtk session` counts a command as adopted where it runs rtk, or where it has a rule and the rewrite reaches it on a line the hook can attest, read the way discover reads it and under the same `exclude_commands` and `transparent_prefixes`, rather than wherever a rule matches. `strip_disabled_prefix_for_analytics`, `without_rtk_disabled`, `is_already_rtk`, the report's own text classifier, `ChainPart`'s `runs_rtk` and the rewrite's record of the runs it refused lose their last caller and go. `rtk rewrite` and the hook are unchanged. What the reports answer differently: - A command behind a wrapper or keyword is the command it runs: `timeout 30 cargo test`, `time cargo test`, `nohup`, `command`, `exec`, `noglob` and the commands after `then`, `do` or `if` are classified, named and sized as theirs, and counted as covered where the rewrite reaches them, instead of an unsupported wrapper row or no row. A command behind a user prefix is the command behind it. `uv run pytest` is `pytest`, covered, where it was an `rtk uv` row; `uv run bash -c 'pytest'` is `bash -c`, which has no rule, as `bash -c 'pytest'` alone, so it is no longer counted covered through the wrapper's rule. `uv run RTK_DISABLED=1 pytest`, which the rewrite refuses, is still an `rtk uv` opportunity, as before. - An `rtk` behind assignments or wrappers is adoption (`FOO=1 rtk git status`, `timeout 5 rtk …`, `uv run rtk pytest`, and behind `RTK_DISABLED=` too, which rtk does not read); `rtk bypass` still is not. Behind a wrapper (`timeout 5 rtk cargo test`, `command`, `nohup`, `uv run rtk …`) it weighs the average of any command in its call's output share, as behind assignments or `env`, and no longer the weight of a command with no rule, so the share of the call's other rows shifts. A command behind assignments is no longer exempt from the commands the report leaves out (`FOO=1 echo hi`). - A row behind plain assignments is named by the command and merges with the row of the unprefixed command: `FOO=1 pytest` is `pytest`, `FOO=1 git status 2>&1 | tail -3` is `git status` (it was `FOO=1 git`), `FOO=1 gh pr view 1 --json title` is `gh pr` (it was `FOO=1 gh`). - A command that is none keeps a row, as the layer that owns it: `env -i git status` and `env -u FOO git status` are an `env` row, `FOO=1 env -u BAR cargo test` a `FOO=1 env` row, where they were rows named `-i git`, `-u FOO` and `-u BAR`. A reserved word has none: `time -f %e cargo test` and `if -v cargo` are grammar, as before. - Behind a transparent prefix of the user's, a command nothing settles is the command behind the prefix: `nice -n 19 ionice frobnicate x` under that prefix is a `frobnicate x` row, as `timeout 30 frobnicate x` is, and with `git` excluded, `nice -n 19 ionice git status` and `timeout 5 RTK_DISABLED=1 git status` under the prefix `timeout 5` are the `rtk git` opportunity a plain excluded `git status` is, where they were rows named `nice` and `timeout 5`. - A bypass is found behind the wrappers the rewrite reads through (`RTK_DISABLED=1 timeout 5 git status`, `nice`, `time`, `nohup`, `command`), and one the rewrite refuses through a user prefix: it was left out of the bypass bucket. `RTK_DISABLED=1 time cargo test` reaches it, named `cargo test`. One the walk does not read through (`sudo RTK_DISABLED=1 docker ps`, with `sudo` not a transparent prefix) is no bypass: it is the `sudo` command it is written as, row `sudo RTK_DISABLED=1` where it was `sudo docker`. A bypassed command with no rule is left out of the report, which now includes `RTK_DISABLED=1 sudo docker ps`, where it was a `sudo docker` row; one the rewrite takes with no rule (`RTK_DISABLED=1 stat f`, `RTK_DISABLED=1 bash -c 'git status'`) is left out as it was. - The commands of a line the hook cannot attest (a substitution, a redirect that names a file) are opportunities, not missed savings, and so is a consumer the rewrite would take there; a copy or `/dev/null` names no file. A measured `hook_decisions` row that records a rewrite of the line still counts its commands as covered. - `rtk session` counts a command as the hook leaves it: a wrapped command with a rule the rewrite reaches, `time cargo test`, is covered; one on a line the hook cannot attest, behind an `RTK_DISABLED=` (which counted as adopted before), or excluded is not. A ruled command the rewrite declines is no longer counted, a raw pipe producer included: `tail -f log` 1/1 → 0/1, `cargo test | tee out` 1/2 → 0/2, `git log --oneline | wc -l` 2/2 → 0/2, `cat file | tail -5` 2/2 → 0/2, and the `head` of `git log | head -5`. A command behind a transparent prefix of the user's is counted as the hook rewrites it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The classification of a command picked its rule by index, kept the rule's fields and dropped the index, and the rewrite's decision then found the rule again with a scan on its `rtk_cmd` (`decide`, and `tool_form` in the check against `exclude_commands`). For `rtk uv` and `rtk php`, which are two rules each, that scan returned the first of the pair, which for the second rule's commands (`uv sync`, `php -l`) is not the one that matched; it was harmless only because a test held the pair's `rewrite_prefixes` and `pipeline_safety` equal. `Classification::Supported` now carries the index of the rule that matched, and `decide` and `tool_form` read the rule from it. The rewrite no longer looks a rule up by its `rtk_cmd`, so the test that held the siblings equal goes, and a new test pins the index: it is the rule whose pattern matched, the last of several that do, and each of two sibling rules for its own commands. No answer of `rtk rewrite`, the hook, `rtk discover` or `rtk session` changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
KuSh
force-pushed
the
fix/report-from-rewrite-decisions
branch
from
November 29, 2026 01:42
6298796 to
a065a2a
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 sessionworked out what the hook does with a command by reading it a second time: a text diff of the rewrite's output to find what it reached, a rewrite of the command alone to estimate coverage, a shallow scan forRTK_DISABLED=and the text rebuilt without it, a classifier of the command as written, and a second lookup of its rule. Each reader could disagree with the rewrite, and the report then said something the hook does not do.The report now asks the rewrite. A call is lexed once, and its commands, the edits that reach them, the bypass counterfactual, each command's name and class, and the rule it matched all come from the rewrite's own decision over that lex (
read_call,decide_segment).rtk rewriteand the hook are unchanged.Built on #5024.
Commits
refactor(discover): read the commands the rewrite reaches off its edits: a command is reached when an edit of the call's rewrite falls in it. No behaviour change.fix(discover): answer the hook's coverage from the call's own rewrite: coverage and theRTK_DISABLED=counterfactual come from the call's rewrite, with the bypass run read past.fix(discover): read each command with the walk the rewrite runs: each command is named, classified and sized as what the rewrite's decision settles on, andrtk sessioncounts it the same way.refactor(discover): keep the rule a command matched: the classification carries the rule's index, so the rewrite never looks it up again. No behaviour change.Behaviour changes
timeout 30 cargo test,time cargo testand the body of athenordoarecargo test, where they were an unsupportedtimeout 30row or no row.rtkbehind assignments or wrappers is adoption:FOO=1 rtk git status,timeout 5 rtk cargo test,uv run rtk pytest.FOO=1 pytestispytest.RTK_DISABLED=bypass is found behind the wrappers the rewrite reads through:RTK_DISABLED=1 timeout 5 git status,RTK_DISABLED=1 time cargo test.cargo test | RTK_DISABLED=1 tail -n 5 f.log.RTK_DISABLED+=1 git statusis a bypass, as the rewrite's refusal reads it.git log > out,git status; echo $(date). A logged rewrite of such a line still counts as covered.transparent_prefixesandexclude_commands, a command is read as the hook reads it:nice -n 19 ionice git statusunder that prefix isgit status.env -i git statusis anenvrow, where it was a row named-i git.rtk sessioncounts a command as covered only where the hook would rewrite it:tail -f log1/1 → 0/1,cat file | tail -52/2 → 0/2,RTK_DISABLED=1 git status1/1 → 0/1,timeout 5 cargo test0/1 → 1/1. It reads the same configuration as discover.Known limits
uv run RTK_DISABLED=1 pytest, which the rewrite refuses, is still anrtk uvopportunity.uv run bash -c 'pytest'is read asbash -c, which has no rule, likebash -c 'pytest'alone, although the rewrite edits inside the quotes.nohup,nohup RTK_DISABLED=1 git statusis a bypass named as written.rtk sessiondoes not read the hook's logged decisions;rtk discoverdoes.Test plan
cargo fmt --all,cargo clippy --all-targets,cargo test --all(6351 passed)rtk rewriteandrtk hook claudeoutput identical before and after on about 57,000 shapes under six configurationsrtk discoverandrtk sessioncompared call by call, each commit against its parent (up to 9,828 recorded and generated calls, with and without the hook, the user prefixes and the exclusions); every difference is a change listed above🤖 Generated with Claude Code