Skip to content

fix(hooks): own Gemini hooks by exact command, not substring - #4235

Open
amandeavor wants to merge 2 commits into
rtk-ai:developfrom
amandeavor:fix/gemini-hook-exact-ownership
Open

amandeavor wants to merge 2 commits into
rtk-ai:developfrom
amandeavor:fix/gemini-hook-exact-ownership

Conversation

@amandeavor

Copy link
Copy Markdown
Contributor

Summary

Closes #4227.

patch_gemini_settings and uninstall_gemini decided ownership with command.contains(\"rtk\") on the first hook in each BeforeTool group. That caused two failures:

  1. Uninstall deleted user hooks that shared a group with RTK's hook (the whole group was dropped).
  2. Install skipped / uninstall deleted a user hook whose path merely contained the substring rtk (e.g. /opt/smartkit/check.sh).

Changes

  • Reuse the shared grouped hook helpers from refactor(hooks): consolidate hook config I/O #4151
  • Own a hook only when the command is the installed path, contains rtk-hook-gemini.sh, or is rtk hook gemini
  • On uninstall, remove only matching hook entries and keep sibling user hooks in the same group

Tests

  • test_gemini_hook_ownership_is_exact_and_preserves_siblings — mixed group keeps /opt/audit/log-shell.sh
  • test_gemini_hook_presence_ignores_unrelated_rtk_substring_paths — /opt/smartkit/check.sh is not treated as RTK's
  • cargo test --bin rtk -- test_gemini_hook_ — green locally

`patch_gemini_settings` / `uninstall_gemini` treated any BeforeTool
entry whose first hook command merely contained \"rtk\" as RTK's. That
skipped install when a user path contained the substring, and on
uninstall deleted whole groups — including sibling user hooks.

Reuse the shared grouped hook helpers with an exact ownership check
(installed path, `rtk-hook-gemini.sh`, or `rtk hook gemini`), and remove
only matching hook entries so user siblings stay put.

Closes rtk-ai#4227
Copilot AI lite review requested due to automatic review settings September 25, 2026 07:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Fixes RTK's Gemini hook ownership detection, which previously used a substring match on "rtk" and could delete or ignore unrelated user hooks sharing the same BeforeTool group. The PR reuses shared grouped-hook helpers to own hooks only by exact installed path, the rtk-hook-gemini.sh filename, or the literal 'rtk hook gemini' command, and updates uninstall to remove only matching entries while preserving sibling hooks.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4227


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

Satisfy clippy::collapsible_if (denied via -D warnings) by combining
the settings parse and remove_gemini_hook_from_json check.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk init --gemini treats any BeforeTool group whose first hook contains "rtk" as RTK's: uninstall deletes user hooks, install skips

2 participants