Skip to content

fix(init): migrate Cursor hooks.json before deleting the legacy hook script - #3570

Open
guyoron1 wants to merge 1 commit into
rtk-ai:developfrom
guyoron1:fix/cursor-hook-migration
Open

guyoron1 wants to merge 1 commit into
rtk-ai:developfrom
guyoron1:fix/cursor-hook-migration

Conversation

@guyoron1

@guyoron1 guyoron1 commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On current develop the bug is not only still present, it always fires: an earlier unconditional cleanup step ("Remove Cursor legacy hook") deletes the script before install_cursor_hooks runs, so the if old_hook.exists() block, which held the only call to remove_legacy_cursor_hooks_json_entries, never runs at all. Checked end to end with the real binaries in throwaway HOMEs:

hooks.json before : [ "~/.cursor/hooks/rtk-rewrite.sh" ]   (script on disk)
$ rtk init --agent cursor --global
develop : "hooks.json: RTK preToolUse entry already present"
          hooks.json after : [ "~/.cursor/hooks/rtk-rewrite.sh" ]   script on disk: NO
this PR : "hooks.json: RTK preToolUse entry added"
          hooks.json after : [ "rtk hook cursor" ]                  script on disk: NO

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --all-targets (0 warnings)
  • cargo test --all (all pass; all 30 cursor tests pass)
  • New regression test test_patch_cursor_hooks_json_migrates_legacy_entry: a hooks.json referencing the legacy script is rewritten to a single rtk hook cursor entry in one operation. test_cursor_hook_already_present_legacy_script* now asserts that a legacy entry does not count as present.

Fixes #3465

@guyoron1

Copy link
Copy Markdown
Contributor Author

Rebased on current develop; two conflicts in src/hooks/init.rs, both the same shape: develop kept remove_legacy_cursor_hooks_json_entries and ported it to the new JSON I/O helpers, whereas this PR deletes it because the migration now happens in the same atomic write, so I took the PR side.

The bug is worse on develop than when I wrote this up: an earlier cleanup step ("Remove Cursor legacy hook") deletes the script before install_cursor_hooks runs, so the migration block never fires at all. hooks.json keeps pointing at the deleted script while rtk prints "RTK preToolUse entry already present". Before/after with the real binaries is in the description.

…script

`rtk init -g --agent cursor` deletes ~/.cursor/hooks/rtk-rewrite.sh and
then treats the stale hooks.json entry referencing it as "RTK hook already
present", printing a success message while leaving Cursor with a registered
preToolUse hook whose script no longer exists (rtk-ai#3465).

- patch_cursor_hooks_json now strips legacy rtk-rewrite.sh entries and
  registers the `rtk hook cursor` command in the same atomic write; a
  legacy entry no longer satisfies the presence check.
- The legacy script is deleted only after hooks.json was successfully
  patched, so a parse failure leaves the working script in place.
- The separate remove_legacy_cursor_hooks_json_entries pass is gone. It
  only ran while the script was still on disk, and the earlier "Remove
  Cursor legacy hook" cleanup deletes that script first, so the pass never
  fired and the stale entry always survived.

Reapplied on top of develop's `refactor(hooks): split init.rs into
per-agent submodules` (5ec8b8c), which moved this logic verbatim into
src/hooks/init/cursor.rs before this PR landed. The uninstall path's
is_cursor_hook_entry (matches legacy + new command) is left untouched;
only the "already present" check is narrowed, via a new
is_active_cursor_hook_entry.
@guyoron1
guyoron1 force-pushed the fix/cursor-hook-migration branch from af45afa to 65800c4 Compare September 27, 2026 03:36
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.

rtk init --agent cursor deletes ~/.cursor/hooks/rtk-rewrite.sh, leaves hooks.json referencing it, and reports success

1 participant