Skip to content

fix(hooks): gate the rewrite hooks on 0.25.0, the release that added rtk rewrite - #5131

Merged
KuSh merged 3 commits into
rtk-ai:developfrom
TechWizard9999:fix/5126-rewrite-version-floor
Nov 28, 2026
Merged

KuSh merged 3 commits into
rtk-ai:developfrom
TechWizard9999:fix/5126-rewrite-version-floor

Conversation

@TechWizard9999

Copy link
Copy Markdown
Contributor

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, "when rtk rewrite was introduced". rtk rewrite first shipped in 0.25.0: f447a3d is not an ancestor of v0.24.0, is in v0.25.0, and CHANGELOG.md lists it under 0.25.0. So rtk 0.23 and 0.24 pass the guard, are told nothing, and get no rewrites.

Change

  • Floor 23 → 25 and the messages need >= 0.23.0 → need >= 0.25.0 in the three hooks (the shell -lt checks, MIN_SUPPORTED_RTK_MINOR, header and guard comments).
  • The same wording in hooks/README.md, hooks/claude/README.md, hooks/cursor/README.md and hooks/pi/README.md.
  • hooks/pi/rtk.ts is embedded by rtk init --agent pi, so its new hash is added to KNOWN_PI_PLUGIN_HASHES (test_all_git_pi_plugin_revisions_are_allowlisted requires it).

Test

test_shipped_hooks_gate_on_the_release_that_added_rewrite (src/hooks/hook_check.rs) takes the release from the CHANGELOG.md heading above f447a3d (0.25.0) and asserts that each hook's guard uses that minor, each states too 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 rtk reporting 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 no rtk rewrite call; 0.25.0 and later go through.

…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
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes the version-floor check in the Claude, Cursor, and Pi rtk-rewrite hooks, which incorrectly gated on rtk >= 0.23.0 when rtk rewrite was actually introduced in 0.25.0. Updates the shell guards, the Pi extension's MIN_SUPPORTED_RTK_MINOR constant, associated README docs, and the Pi plugin hash allowlist, plus adds a regression test that derives the correct floor from CHANGELOG.md.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #5126


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@TechWizard9999

Copy link
Copy Markdown
Contributor Author

@KuSh please review this.

@Kernel-Hunter Kernel-Hunter left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked this out and ran it.

  • git merge-base --is-ancestor f447a3d v0.24.0 fails and the same check against v0.25.0 passes, so 0.25.0 is the right floor.
  • cargo test --lib -- hook_check init::pi passes, including the new test_shipped_hooks_gate_on_the_release_that_added_rewrite.
  • grep -rn "0\.23\.0" hooks src docs finds one leftover: docs/guide/getting-started/embedding.md line 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 added rtk 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.

@TechWizard9999

Copy link
Copy Markdown
Contributor Author

Fixed in ccb0db1, thanks!

@KuSh KuSh left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • 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. Done in 1d1f69a (see below).
  • 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 native rtk 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 prints rtk git status with 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.0 status in Pi), and nothing calls rtk rewrite. 0.25.0 and 1.x rewrite on both sides.
  • a9bd68b0… is the sha256 of hooks/pi/rtk.ts after LF normalisation and trim_end, which is what is_known_stock_pi_plugin hashes, so it is not a plain file hash. The previous stock file is still recognised: rtk init --agent pi replaces it without a prompt and --uninstall removes 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_MINOR 25 → 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 probes rtk 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-targets and cargo test --all on 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_rewrite now matches each hook's whole guard, every line at a line start, exactly once. A guard that loses its MAJOR -eq 0 check or its exit 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 before pi.on("tool_call".
  • New version_floor test in tests/hook_decision_protocol_test.rs: runs the Claude and Cursor hooks against a stub rtk at 0.24.0 and 0.9.0 (warning, no rtk rewrite call) 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]>
@KuSh
KuSh merged commit dcd04c3 into rtk-ai:develop Nov 28, 2026
16 checks passed
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hooks: version floor says rtk rewrite came in 0.23.0; it came in 0.25.0

3 participants