Skip to content

fix(cursor-hooks): preserve similarly named user hooks - #1052

Merged
DietrichGebert merged 4 commits into
DietrichGebert:mainfrom
LurigeLars:upstream/fix-cursor-hook-ownership
Oct 13, 2026
Merged

DietrichGebert merged 4 commits into
DietrichGebert:mainfrom
LurigeLars:upstream/fix-cursor-hook-ownership

Conversation

@LurigeLars

Copy link
Copy Markdown
Contributor

Problem

Cursor hook cleanup currently treats any matching ponytail-*.js fragment as Ponytail-owned, so an unrelated user hook such as ./hooks/my-ponytail-logger.js can be removed during install/uninstall.

Fixes #1051

Related: #898

Change

  • scope ownership detection to an actual hooks/ponytail-*.js path
  • support both / and \ path separators
  • keep matching bounded
  • add a regression test proving a similarly named user hook survives install and uninstall

Validation

  • npm test
  • node scripts/check-rule-copies.js
  • node scripts/check-versions.js

All three pass against upstream main at 552acd5.

The branch is based directly on upstream main and changes only:

  • scripts/cursor-hooks.js
  • tests/cursor-hooks.test.js

@szsunyuan

Copy link
Copy Markdown
Contributor

I ran this locally. tests/cursor-hooks.test.js passes 11/11, and the new assertion fails on main, so the test catches the bug.

A small suggestion, feel free to ignore it: the existing regex can do this in one line, and isPonytailHook can stay as it is on main.

const PONYTAIL_HOOK = /[\\/]hooks[\\/]ponytail-[\w-]+\.js(?=["'\s]|$)/;

Your test passes with it too. It also handles a case the lastIndexOf version misses. If a later argument also contains /hooks/ponytail-, only that last occurrence is checked, so a real ponytail entry isn't recognized. For example, node "/opt/p/hooks/ponytail-activate.js" --log /tmp/hooks/ponytail-x/ returns false. It's unlikely in practice, since the installer never adds arguments.

Looks good to me either way.

@LurigeLars

Copy link
Copy Markdown
Contributor Author

Thanks for the review — I incorporated your regex suggestion and restored isPonytailHook to the simpler predicate.

I also added a regression test for the edge case you pointed out:

node "/opt/p/hooks/ponytail-activate.js" --log /tmp/hooks/ponytail-x/

Thanks for catching that.

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 installer can remove similarly named user hooks

3 participants