Skip to content

fix(hook): preserve fish-wrap decisions and reuse permission scans - #4785

Merged
KuSh merged 3 commits into
rtk-ai:developfrom
Aschenbath:fix/hook-track-fish-wrap-decision
Nov 2, 2026
Merged

KuSh merged 3 commits into
rtk-ai:developfrom
Aschenbath:fix/hook-track-fish-wrap-decision

Conversation

@Aschenbath

@Aschenbath Aschenbath commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #4762.

  • Carry the wrap from the actual wrapping operation to the Claude response, as an AskRewrite the 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 explicit ask.
  • Reuse one Claude settings scan for the permission verdict and lazy wrap attestation. Unreadable settings or any raw deny entry still block wrapping, and other hosts remain outside the fish probe path.

Test plan

  • Real fish CLI regression suite: the two regression scenarios fail on the previous implementation (17 pass, 2 fail), then all 19 tests pass with fish 4.9.3.
  • cargo fmt --all --check and the separate proxy formatting check.
  • cargo clippy --workspace --all-targets, with no warnings.
  • Complete 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.
  • Coverage retains explicit approval for generated wrappers, deny/unreadable-settings handling, other-host behavior, and the rule that delegated approval cannot promote an ask the hook owns to an allow.
  • The unchanged CI workflow on the same commit passes all 14 jobs, including Linux, macOS, both Windows toolchains, the OSS edition, proxy checks, and the benchmark.

The upstream CI run on commit b55feb5d7e8592a139c5a70bc2a2b38a83106e5d passes too.

Maintainer fixups

  • 73a0bd7: tests for the explicit ask on a host without fish and for a denied script behind a configured transparent prefix, and the README sentence on typed wrap forms.
  • cc21c88: the wrap was first its own AskFishWrap decision, handled like AskRewrite almost everywhere. It is now an AskRewrite whose 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.

@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Fixes 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

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4762


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

@Aschenbath
Aschenbath marked this pull request as ready for review October 25, 2026 02:20
…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]>

@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 — 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 -c behind 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 status goes from ask to allow under allow rules, and to no decision without them. Unchanged with the wrap off.
  • Every wrap still carries "permissionDecision": "ask", with allow rules for rtk and git too. A deny rule, an unparsable file, or no fish on PATH still means no wrap.
  • With the wrap off, all 162 hook and hook check rows 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 claude gives 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 rewrite and pipeline swap paths all pass Unattested.
  • cc21c88 merged onto develop 16d1ccf: fmt, clippy (0 warnings), cargo test --all 5434 passed / 0 failed, fish_wrap_test 19/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: AskFishWrap was handled exactly like AskRewrite at 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): Host is the ordinary ask the host's rules may judge, Hook the 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 for Hook, a delegate relaxes only a Host ask, and a rewrite that changed nothing keeps a Hook ask, as AskFishWrap did. No behaviour changes: rtk hook <host> for 10 hosts, rtk hook check for 9 agents and rtk 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]>
@KuSh
KuSh merged commit 22812af into rtk-ai:develop Nov 2, 2026
16 checks passed
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hook claude: mark a fish wrap in the decision instead of matching the rewritten string

2 participants