Repository navigation
fix(hook): preserve fish-wrap decisions and reuse permission scans - #4785
Conversation
📊 Automated PR Analysis
SummaryFixes a bug where RTK's fish-script wrapping could lose or misclassify permission decisions by introducing an explicit AskFishWrap decision variant separate from AskRewrite, ensuring user-written wrapper commands retain their normal permission decision after rewrite normalization. It also consolidates the Claude hook's permission verdict and lazy wrap attestation into a single shared settings scan, avoiding duplicate reads/warnings while preserving deny/unreadable-settings and other-host behavi… Review Checklist
Linked issues: #4762 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
…verdict The Claude hook now reads its own settings scan for the verdict, and the explicit ask for a wrap comes from the AskFishWrap arm. Two tests pin what no test checked on a host without fish: - process_claude_payload_from_decision gives an AskFishWrap an explicit "ask" and logs it as an ask, while an AskRewrite of the same text leaves the decision to the host; - rtk hook claude and rtk hook check --agent claude leave a denied command alone behind a configured transparent prefix (mywrap bash -c 'git push'), and still rewrite an allowed one through it. The README sentence on typed wrap forms now says what holds: only a wrap the decision built carries the ask, and a typed form the rules only rewrote around keeps its decision. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Round 1 — APPROVED
Claim: rtk hook claude marks a fish wrap it built as an ask the hook makes itself (explicit ask) instead of matching the rewritten string, and one Claude settings scan serves both the verdict and the wrap attestation.
Scope: accept (#4762 in full). #4458 builds the same single scan through HostRules::claude_hook() and will take this PR's ClaudeHookPermissions into it when it rebases.
Ran: rtk hook claude and rtk hook check --agent claude on the merge-base 32b2ec4, this head, develop ed0216f and the head merged onto it, under fish 4.9.1: wrap off/on × 5 settings layouts (none, allow Bash(rtk:*)+Bash(git:*), ask, deny, unparsable) × 18 commands (wrappable scripts, typed wrap forms with and without leading continuations, the refusal gates #4762 lists, a denied script), plus fish off PATH, rtk rewrite, the hook_decisions row of a wrap, and a deny behind a configured transparent prefix. Invariants: every decision, under the hook. Savings: not applicable (no filter change).
Pins: 14 decisions, 15 mutations, 3 survived the suite. Two are killed by the tests in 73a0bd7: the wrap's logged outcome (Ask → Allow), and the Claude hook verdict dropping transparent_prefixes, which turns mywrap bash -c 'git push' under a Bash(git push:*) deny into allow + mywrap bash -c 'rtk git push'. The third, handing decide_for_agent_at's callers that cannot wrap an attestation, changes no output: the attestation still says no, and only an extra fish PATH probe runs.
Matrix: executed this round; pin check: executed this round
CI @cc21c8881: all green (15 pass)
Filed as follow-ups
- #4923 fish wrap: a typed
rtk run --shell fish -cbehind a leading line continuation is wrapped again. It was already like this before the PR (32b2ec4, v1.1.0);try_wrap's first-word check is outside this PR's hunks.
Checked and correct — no need to re-verify
- The #4762 row:
\⏎rtk run --shell fish -c 'echo ok' && git statusgoes fromasktoallowunder allow rules, and to no decision without them. Unchanged with the wrap off. - Every wrap still carries
"permissionDecision": "ask", with allow rules forrtkandgittoo. A deny rule, an unparsable file, or no fish onPATHstill means no wrap. - With the wrap off, all 162 hook and
hook checkrows match the merge-base byte for byte, warning counts included. - With an unparsable settings file, each fish-shaped command (wrapped or refused) now warns once, like
git status. On the merge-base it warned twice. rtk hook check --agent claudegives the hook's answer on every row.- No other host can be handed an ask the hook owns: the copilot, cursor, gemini, codex, droid, opencode,
rtk rewriteand pipeline swap paths all passUnattested. - cc21c88 merged onto develop 16d1ccf: fmt, clippy (0 warnings),
cargo test --all5434 passed / 0 failed,fish_wrap_test19/19.
Next
Two maintainer fixups, both pushed:
- 73a0bd7, code-reviewed: two tests (
test_process_claude_payload_decision_fish_wrap_asks_explicitly, which runs without fish;claude_hook_defers_a_denied_script_behind_a_configured_transparent_prefix) and the README sentence on typed wrap forms, now limited to what holds. - cc21c88, code-reviewed:
AskFishWrapwas handled exactly likeAskRewriteat nearly every site that consumes a decision, and nothing about it is specific to fish. It becomes an owner on the ask,AskRewrite(String, AskOwner):Hostis the ordinary ask the host's rules may judge,Hookthe ask the hook makes itself (built today only by the fish wrap, reusable by a later wrap for another shell). The Claude hook sends"ask"only forHook, a delegate relaxes only aHostask, and a rewrite that changed nothing keeps aHookask, asAskFishWrapdid. No behaviour changes:rtk hook <host>for 10 hosts,rtk hook checkfor 9 agents andrtk rewrite, over 2 configs × 5 settings layouts × 18 commands under fish 4.9.1, give byte-identical output and exit codes on 73a0bd7 and cc21c88 (3600/3600 rows). Each of the 7 decisions that read the owner is pinned by a test.
Approving.
Threads: 0 open, 0 resolved this round.
A fish wrap was its own HookDecision variant, yet every host's hook but Claude's handled it exactly like AskRewrite. What sets it apart is who asks, not what is decided: the wrap hands the host one `rtk run` command whose parts the host's rules cannot see, so the hook asks itself rather than leave it to those rules. AskRewrite now carries an AskOwner. Host is the ordinary ask, which the host's rules may judge. Hook is the ask the hook makes itself: the Claude hook sends it as `"permissionDecision": "ask"`, a delegate never relaxes it into an allow, and a rewrite that changed nothing keeps it. The wrap is the only rewrite that builds a Hook ask. The tests that expect an ordinary ask now say Host, so a wrap where none is expected fails them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Fixes #4762.
AskRewritethe hook asks about itself (AskOwner::Hook) rather than one left to the host's rules (AskOwner::Host). A user-written wrapper keeps its normal permission decision after leading line continuations are normalized; every wrapper RTK creates still carries an explicitask.Test plan
cargo fmt --all --checkand the separate proxy formatting check.cargo clippy --workspace --all-targets, with no warnings.cargo test --all: 5,211 tests pass, zero fail, and eight existing tests remain ignored. This includes the existing 600-case Git blob differential test.The upstream CI run on commit
b55feb5d7e8592a139c5a70bc2a2b38a83106e5dpasses too.Maintainer fixups
AskFishWrapdecision, handled likeAskRewritealmost everywhere. It is now anAskRewritewhose owner says who asks, so a later wrap for another shell reuses it. No behaviour changes.Implementation, tests, and this description were prepared with Codex.