Skip to content

fix(hook): handle AskRewrite in Cursor hook when no rules configured#2609

Merged
KuSh merged 4 commits into
rtk-ai:developfrom
guyoron1:fix/cursor-hook-ask-rewrite
Jun 29, 2026
Merged

fix(hook): handle AskRewrite in Cursor hook when no rules configured#2609
KuSh merged 4 commits into
rtk-ai:developfrom
guyoron1:fix/cursor-hook-ask-rewrite

Conversation

@guyoron1

@guyoron1 guyoron1 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix RTK being completely non-functional on fresh Cursor installs where no explicit permission rules exist in ~/.cursor/cli-config.json
  • When no rules are configured (the default), every command gets AskRewrite verdict — but the hook only handled AllowRewrite, silently dropping all rewrites
  • Now treat AskRewrite as allow when no rules are configured (Cursor has no ask-the-user UX); preserve conservative defer behavior when explicit rules exist
  • Also fix the legacy shell script (rtk-rewrite.sh) which treated exit code 3 (ask) as failure via || short-circuit
  • Align cursor_has_explicit_rules() to include ask rules, matching the inline check in run_cursor_inner_with_rules()

Fixes #2372

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test
  • Updated unit test: test_cursor_default_verdict_rewrites verifies that with no rules, git status rewrites to rtk git status with permission: allow
  • Manual testing: fresh Cursor install with no cli-config.json rules — commands should rewrite to rtk prefixed versions
  • Manual testing: Cursor with explicit deny/allow rules — conservative behavior preserved

@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.

Hi @guyoron1, thanks for your PR, minor changes requested before it can be merged.

Comment thread hooks/cursor/rtk-rewrite.sh Outdated
Comment thread hooks/cursor/rtk-rewrite.sh
Comment thread src/hooks/hook_cmd.rs Outdated
Comment thread src/hooks/hook_cmd.rs Outdated
@KuSh KuSh self-assigned this Jun 28, 2026
guyoron1 and others added 3 commits June 29, 2026 07:14
When no explicit permission rules exist in ~/.cursor/cli-config.json
(the default for fresh installs), every command gets Default verdict
which maps to AskRewrite. The Cursor hook only handled AllowRewrite,
silently dropping all rewrites and making RTK non-functional.

Now treat AskRewrite as allow when no rules are configured — Cursor
has no ask-the-user UX, so deferring is indistinguishable from
dropping. When explicit rules exist, preserve the conservative
behavior of deferring mixed/unmatched commands.

Also fix the legacy shell script (rtk-rewrite.sh) which treated
exit code 3 (ask) as failure via || short-circuit.

Fixes rtk-ai#2372
Align cursor_has_explicit_rules() with the inline has_rules check in
run_cursor_inner_with_rules() — both now consider deny, ask, and allow
rules when determining whether the user has configured explicit
permission policies.
Address PR rtk-ai#2609 review feedback:
- RC=3 in shell script now emits "permission": "ask" (future-proof)
- Add cursor_ask() and use it for all AskRewrite decisions
- Remove has_rules guard (unnecessary with ask semantics)
- Remove dead cursor_has_explicit_rules() function
@guyoron1 guyoron1 force-pushed the fix/cursor-hook-ask-rewrite branch from e69ee78 to c30b302 Compare June 29, 2026 04:14
@guyoron1

Copy link
Copy Markdown
Contributor Author

thank you for the review : )
addressed all issues and tested them

@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.

A minor change is needed here; otherwise, LGTM, thanks!

Comment thread src/hooks/hook_cmd.rs Outdated
@guyoron1

guyoron1 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

All review feedback has been addressed:

  • cursor_ask() with "permission": "ask" (commit c30b302)
  • Audit log uses "ask" action (commit 03bb3a3)
  • Tests updated to verify ask permission and rewrite behavior

Note: This PR (#2609) was opened before issue #2719 and PR #2720 were created, and is a superset of #2720. #2720 only fixes the shell script (hooks/cursor/rtk-rewrite.sh), while this PR fixes both the shell script and the Rust run_cursor() code path — which is the default when using rtk hook cursor. If this PR is merged, #2720 would be redundant.

@KuSh KuSh merged commit 36dd8f2 into rtk-ai:develop Jun 29, 2026
11 checks passed
KuSh pushed a commit that referenced this pull request Jun 29, 2026
Address PR #2609 review feedback:
- RC=3 in shell script now emits "permission": "ask" (future-proof)
- Add cursor_ask() and use it for all AskRewrite decisions
- Remove has_rules guard (unnecessary with ask semantics)
- Remove dead cursor_has_explicit_rules() function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cursor hook silently drops all rewrites — rtk rewrite exit code 3 treated as failure

2 participants