Repository navigation
fix(hook): pass -- to rtk rewrite in every delegate - #5133
Conversation
A command that reads as an option of `rtk rewrite` itself (`--help`, `-h`) was parsed by clap, which printed usage text and exited 0, the "rewrite, allowed" answer, so the delegate ran the usage text as the command. End the option list with `--` at all six call sites (pi, hermes, openclaw and the three rtk-rewrite.sh hooks) and register the new Pi extension hash. Closes rtk-ai#5127 Co-Authored-By: Claude Opus 5.5 <[email protected]>
📊 Automated PR Analysis
SummaryThis PR fixes a security issue where commands starting with option-like flags (e.g. Review Checklist
Linked issues: #5127 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
TechWizard9999
left a comment
There was a problem hiding this comment.
Thanks for this, the fix itself looks right. Root cause: rtk rewrite takes its command as a trailing arg with allow_hyphen_values, but a lone --help/-h still matches clap's built-in help flag, so it prints usage and exits 0, which every delegate reads as "rewrite and allow". A leading -- ends option parsing, and it works on both shapes Rewrite has had (cmd: String in 0.25-0.29, the trailing Vec<String> since). All six delegates are covered and the new test fails for each one if its -- is removed.
One thing needs updating before merge: the Hermes plugin's own unit test still expects the old argv. hooks/hermes/tests/test_rtk_rewrite_plugin.py:148-155 (test_rewrite_updates_payload_without_returning_a_directive) asserts run.assert_called_once_with(["rtk", "rewrite", "git status"], ...), but the plugin now calls ["rtk", "rewrite", "--", "git status"], so both subtests (exit 0 and 3) fail. CI doesn't run that suite, which is why it stayed green. Adding "--" to the expected list fixes it and gives the Hermes delegate a behavioural check too.
cc @KuSh
…d Pi extension With develop merged in, hooks/pi/rtk.ts carries both the 0.25.0 floor and the `--`, a revision no earlier hash covers: allowlist it. The Hermes plugin tests and the shell-hook version-floor test still expected `rtk rewrite <command>`; they now expect the `--` form, so they check the argv the Hermes, Claude Code and Cursor delegates actually pass. The hook traces in TECHNICAL.md and supported-agents.md, the Hermes snippet in hooks/README.md, the `<command>` example in what-rtk-covers.md and the `rtk rewrite` help text show the call the delegates make and get the `--` too. The delegate list in the new test is sorted by path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
KuSh
left a comment
There was a problem hiding this comment.
Round 1 — APPROVED
Claim: every delegate that hands a command to rtk rewrite passes -- first, so a command that reads as an option of rtk rewrite (--help, -h) is looked up as a command instead of coming back as rtk's usage text with exit 0.
Scope: accept (round 1, frozen); maintainer PRs: checked against #3763 and #4269, which touch the same files: neither changes the rtk rewrite call or the Pi hash list.
Ran: the six delegates driven the way their host drives them (the three shell hooks with a PreToolUse payload on stdin, the Pi extension and the OpenClaw plugin under Node with a stand-in host, the Hermes _pre_tool_call) × 10 commands (--help, -h, --version, -V, -v, git status, an ask rule, a deny rule, git log -- src, -- git status) × before/after, against rtk 0.25.0, 0.48.0, 1.1.0, 1.2.1 and this branch merged onto develop; rtk init --agent pi over every earlier stock extension, over an edited one, with --uninstall, and into a symlinked extensions directory; the full suite and the Hermes plugin tests on the head and on the merge with develop. Invariants: every decision (rewrite, ask, deny, pass-through), oldest release the version floor admits. Savings: n/a, no filter changed.
Pins: 7 decisions, 8 mutated, 0 survived. The fixup: 4 mutated, 0 survived.
Matrix: executed this round; pin check: executed this round
CI @d5195f9d: all green (16/16, on the merge with develop 5c61b87)
Blocks merge (0)
Follow-ups
- #4588 CI does not run the plugin test suites that live outside cargo: outside this PR's hunks; the Hermes failures here are a new instance, comment added.
Checked and correct — no need to re-verify
- Before: all six delegates replaced
--helpand-hwith the usage text, and the Claude Code, repo-local Claude Code and Cursor hooks marked it allowed. After: all six pass the command through. The other 108 of 120 rows are byte-identical. Same on 0.25.0, 0.48.0, 1.1.0 and 1.2.1. - On 0.25.0, the
--also stops OpenClaw from blocking--version,-V,-vand-- git statusas a deny (clap's usage error exits 2 there). rtk init --agent piupgrades every earlier stock extension, keeps an edited one and uninstalls only the stock one.- No other code calls
rtk rewriteas a subprocess; the in-process hosts never parse the command as rtk's own arguments. - Removing the
--from any of the six delegates turnsevery_rewrite_delegate_ends_options_before_the_commandred, and removing the hash turns both Pi hash tests red.
Next
Fixup d5195f9 pushed and code-reviewed, approving. It merges develop into the branch (no conflict) and adds one commit. With #5131 merged, hooks/pi/rtk.ts is a new revision whose hash was not listed, so test_known_pi_plugin_hashes_are_sha256 and test_all_git_pi_plugin_revisions_are_allowlisted failed on the merge. #5131's version_floor test and the Hermes plugin tests still expected the argv without --. The commit allowlists the merged extension, makes those tests expect -- (so they now check the Hermes, Claude Code and Cursor argv by running them), adds -- to the call examples in hooks/README.md, TECHNICAL.md, supported-agents.md, what-rtk-covers.md and the rtk rewrite help, and sorts the delegate list in the new test. The Hermes test update asked for in the earlier review is included.
Threads: 0 open.
…run as usage text (#255) * fix(hook): pass `--` to rtk rewrite in every delegate A command that reads as an option of rtk rewrite (--help, -h) was parsed by clap, which printed usage text and exited 0, so the delegate ran the usage text as the command. Ported from rtk-ai#5133. * test(bench): the fake rtk expects -- before the command * rewrite --: finish the double-dash port (docs, Pi stock hashes, OpenCode hook) * test(pi): upstream's stock extension before its rewrite -- fix is a known hash * test(hook): rtk hook opencode takes an option-shaped command after -- * docs: show rtk rewrite -- in the remaining examples * fix(pi): recognise upstream's stock extension from before its rewrite -- fix
Summary
Every delegate that hands a command to
rtk rewritenow ends the option list with--first, so a command that reads as an option ofrtk rewriteitself (--help,-h) reaches it as the positional command instead of being parsed by clap.Before,
rtk rewrite "--help"printed usage text and exited 0, which is the "rewrite, allowed" answer, so the delegate handed the usage text to the shell as the command (and the Claude Code / Cursor shell hooks marked it auto-allowed). With--, the same command exits non-zero with no stdout, which every delegate already treats as pass-through.The six call sites listed in the issue:
hooks/pi/rtk.ts(pi.exec)hooks/hermes/rtk-rewrite/__init__.py(subprocess.run)openclaw/index.ts(execFileSync)hooks/claude/rtk-rewrite.sh,hooks/cursor/rtk-rewrite.sh,.claude/hooks/rtk-rewrite.sh--is clap's own end-of-options marker, so the change works on every rtk version that hasrewrite(the hooks' 0.23.0 version guard is unaffected).The Pi extension's content changed, so its new hash is appended to
KNOWN_PI_PLUGIN_HASHES; earlier hashes stay, so installs of the previous stock extension are still recognised and upgraded.Closes #5127
Test plan
New integration test
tests/rewrite_delegates_test.rs:every_rewrite_delegate_ends_options_before_the_commandreads the six delegates and requires the--form in each. Before the fix it failed listing all six files; after, it passes.rewrite_after_double_dash_treats_an_option_as_the_commandpins the contract the delegates rely on:rtk rewrite -- --helpandrtk rewrite -- -hexit non-zero with empty stdout.cargo fmt --all --checkcargo clippy --all-targets -- -D warningscargo teston Windows 11: the new tests and all 341hooks::inittests pass. The full lib run has 21 failures, all incore::stream/core::shell/core::task_cmdprocess tests; the same 21 fail on a cleandevelop(8bb6096) on this machine, so none comes from this change. I could not run the suite on Linux locally; CI will.Snapshot tests / ≥20% reduction: not applicable, no filter changed.
🤖 Generated with Claude Code