Repository navigation
fix(hooks): gate the rewrite hooks on 0.25.0, the release that added rtk rewrite - #5131
Conversation
…rtk rewrite The Claude and Cursor shell hooks and the Pi extension required rtk >= 0.23.0, but rtk rewrite first shipped in 0.25.0 (f447a3d is not in v0.24.0). An rtk 0.23 or 0.24 passed the guard and got no rewrites with no warning. Raise the floor and its messages to 0.25.0, fix the READMEs, and allowlist the new Pi extension hash. Fixes rtk-ai#5126
📊 Automated PR Analysis
SummaryFixes the version-floor check in the Claude, Cursor, and Pi rtk-rewrite hooks, which incorrectly gated on rtk >= 0.23.0 when Review Checklist
Linked issues: #5126 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
|
@KuSh please review this. |
Kernel-Hunter
left a comment
There was a problem hiding this comment.
Checked this out and ran it.
git merge-base --is-ancestor f447a3d v0.24.0fails and the same check against v0.25.0 passes, so 0.25.0 is the right floor.cargo test --lib -- hook_check init::pipasses, including the newtest_shipped_hooks_gate_on_the_release_that_added_rewrite.grep -rn "0\.23\.0" hooks src docsfinds one leftover:docs/guide/getting-started/embedding.mdline 82 still says the Pi extension and the legacy shell hooks check for 0.23.0. It sits in the paragraph that describes 0.25.0 as the release that addedrtk rewrite, so it now contradicts the code. Probably worth changing that to 0.25.0 in this PR.
The new hash in KNOWN_PI_PLUGIN_HASHES is not a plain sha256 of hooks/pi/rtk.ts (that file hashes to something else), but test_rtk_pi_plugin_marker_tracks_code_not_comments and the rest of the pi tests pass, so I take it the hash is computed over the code without comments.
|
Fixed in ccb0db1, thanks! |
There was a problem hiding this comment.
Round 1 of 3 — APPROVED, follow-ups filed
Claim: the Claude and Cursor shell hooks and the Pi extension refuse rtk older than 0.25.0, the release that added rtk rewrite, instead of 0.23.0.
Scope: accept (round 1, frozen); maintainer PRs: checked against #3875, #4269, #4402: each merges with this one on develop (#3875 has a one-line conflict in hooks/pi/README.md; keep both bullets with 0.25.0), and the full suite passes on all three merges, including test_shipped_hooks_gate_on_the_release_that_added_rewrite
Ran: release binaries 0.22.2 / 0.23.0 / 0.24.0 / 0.25.0, plus a 0.24.9 shim and 1.x, through the Claude hook, the Cursor hook and the Pi extension (node 26, mock host), merge-base vs head, with a fresh cache dir per run; rtk init --agent pi × 8 (fresh, upgrade over the previous stock file, a second init, modified file, --uninstall of a modified file, of the current stock file and of the previous stock file, older binary over the new file); invariants: every decision (each guard on both sides of the floor, 0.24.9 boundary, major 1); savings n/a (no filter)
Pins: 4 decisions (three floors and the allowlist hash), 7 mutated, 0 survived the suite
Matrix: executed this round; pin check: executed this round
CI @ccb0db19: all green (16/16)
Blocks merge (0)
Optional — will not hold merge
Done in 1d1f69a (see below).src/hooks/hook_check.rs:153: the doc comment ends with the fix history (#5126: they said 0.23.0; it is 0.25.0). Stating only the rule is enough; the history is in the commit message.hooks/claude/rtk-rewrite.sh:30: the version-ok cache file records neither the version nor the floor. A machine where an earlier check passed skips the new guard and gets no warning, which is the same outcome as on develop. Not this PR's job.
Filed as follow-ups
- #5323 The legacy Cursor shell hook writes nothing to stdout on its jq-missing, rtk-missing and too-old exits, although its README says Cursor requires JSON on every path. This PR sends 0.23.x and 0.24.x into the third exit: they used to get
{}, and now get empty stdout. Filed rather than held here because Cursor's docs do not say what an empty answer with exit 0 does, and current rtk installs the nativertk hook cursor, so this file reaches users only when someone copies it by hand.
Checked and correct — no need to re-verify
- Floor: on
rtk rewrite "git status", 0.22.2, 0.23.0 and 0.24.0 exit 2 with nothing on stdout, and 0.25.0 printsrtk git statuswith exit 0. - Before: 0.23.0, 0.24.0 and 0.24.9 pass all three guards and get no rewrite. After: they get the warning (and the
RTK disabled: … need >= 0.25.0status in Pi), and nothing callsrtk rewrite. 0.25.0 and 1.x rewrite on both sides. a9bd68b0…is the sha256 ofhooks/pi/rtk.tsafter LF normalisation andtrim_end, which is whatis_known_stock_pi_pluginhashes, so it is not a plain file hash. The previous stock file is still recognised:rtk init --agent pireplaces it without a prompt and--uninstallremoves it. A modified file is still protected on init and on uninstall.- Mutations, each killed:
-lt 25→-lt 23(claude, cursor), claude-lt 25→-le 24,MIN_SUPPORTED_RTK_MINOR25 → 24, the new hash dropped, the cursor message → 0.24.0, the Pi status message → 0.23.0. - No other delegate reads
rtk --version(OpenCode probesrtk hook opencode --help; Hermes, Copilot, Gemini and Codex do not check), so nothing outside this diff needs the new floor. cargo fmt --check,cargo clippy --all-targetsandcargo test --allon the head merged onto develop: 5919 passed, 0 failed.
Test fixup pushed after this review: 1d1f69a
Tests only; no hook or Rust source changed. CI 16/16 on the new head.
- The doc comment states the rule without the history.
test_shipped_hooks_gate_on_the_release_that_added_rewritenow matches each hook's whole guard, every line at a line start, exactly once. A guard that loses itsMAJOR -eq 0check or itsexit 0/return, or that sits behind a#or//, fails it. Every X.Y.Z a hook names must be 0.25.0. In the Pi extension the floor constant is declared once and the guard comes beforepi.on("tool_call".- New
version_floortest intests/hook_decision_protocol_test.rs: runs the Claude and Cursor hooks against a stubrtkat 0.24.0 and 0.9.0 (warning, nortk rewritecall) and at 0.25.0 and 1.2.0 (rewrite returned). 0.9.0 is the case a string compare would let through. - 19 mutations of the three guards, each killed.
Your questions
- None open.
Next
Nothing — approving.
Rounds: 1/3. Threads: 0 open, 0 resolved this round.
…ks against it The floor test matched substrings: a guard that lost its major check or its early exit still passed it. It now matches each hook's whole guard block from line starts and requires every version a hook names to be the release. The Claude and Cursor hooks are also run against a stub rtk at 0.9.0, 0.24.0, 0.25.0 and 1.2.0 to check which versions reach rtk rewrite. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes #5126
Problem
The Claude and Cursor shell hooks (
hooks/{claude,cursor}/rtk-rewrite.sh) and the Pi extension (hooks/pi/rtk.ts) require rtk >= 0.23.0, "whenrtk rewritewas introduced".rtk rewritefirst shipped in 0.25.0: f447a3d is not an ancestor of v0.24.0, is in v0.25.0, andCHANGELOG.mdlists it under 0.25.0. So rtk 0.23 and 0.24 pass the guard, are told nothing, and get no rewrites.Change
need >= 0.23.0→need >= 0.25.0in the three hooks (the shell-ltchecks,MIN_SUPPORTED_RTK_MINOR, header and guard comments).hooks/README.md,hooks/claude/README.md,hooks/cursor/README.mdandhooks/pi/README.md.hooks/pi/rtk.tsis embedded byrtk init --agent pi, so its new hash is added toKNOWN_PI_PLUGIN_HASHES(test_all_git_pi_plugin_revisions_are_allowlistedrequires it).Test
test_shipped_hooks_gate_on_the_release_that_added_rewrite(src/hooks/hook_check.rs) takes the release from theCHANGELOG.mdheading above f447a3d (0.25.0) and asserts that each hook's guard uses that minor, each statestoo old (need >= 0.25.0)the expected number of times (1, 1, 2), and none still names 0.23.0. Each of these mutations fails it: claude-lt 25→23, the claude and cursor messages,MIN_SUPPORTED_RTK_MINOR = 24, and one of the two Pi messages.Also checked by hand (not pinned by a test): the shell hooks and the Pi extension run against a stub
rtkreporting 0.23.0 / 0.24.0 / 0.25.0 / 0.26.1 / 1.2.0. Before: every version passes the guard. After: 0.23.0 and 0.24.0 get the warning and nortk rewritecall; 0.25.0 and later go through.