Skip to content

Fix managed hook install detection - #352

Merged
mohanagy merged 2 commits into
nextfrom
issue-349-install-detection
May 27, 2026
Merged

mohanagy merged 2 commits into
nextfrom
issue-349-install-detection

Conversation

@mohanagy

@mohanagy mohanagy commented May 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • detect native-agent installs via the shared managed-hook recognizer instead of the old out-path heuristic
  • write stable name/source madar sentinels into Claude, Gemini, and Codex hook entries
  • cover real installer output, matcher precision, and compare/benchmark fixture setup with regression tests

Closes #349

Summary by CodeRabbit

  • Bug Fixes

    • More reliable native-agent install verification by standardizing how managed hooks are identified, improving reinstall/uninstall accuracy.
  • Tests

    • Expanded test coverage and fixtures now use the real installer flow; added assertions to verify managed hook presence across integrations.

Review Change Stack

Restore native-agent install detection by matching real managed hooks, add stable managed-hook sentinels for installed hooks, and align compare/benchmark fixtures with the real installer output.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented May 27, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c4732f2d-f08d-4524-a29b-ed6f103ad563

📥 Commits

Reviewing files that changed from the base of the PR and between 5e939c2 and 39e9b08.

📒 Files selected for processing (1)
  • src/infrastructure/compare.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/infrastructure/compare.ts

📝 Walkthrough

Walkthrough

Installs now write a stable managed-hook sentinel (name: 'madar', source: 'madar:...'). Detection and uninstall logic use this sentinel via isMadarProjectHook. Hook generators for Claude/Codex/Gemini are wrapped to include the sentinel, and tests/fixtures are updated to use the real installer and verify sentinel presence.

Changes

Managed hook detection and identity

Layer / File(s) Summary
Sentinel mechanism definition and detection helpers
src/infrastructure/install.ts
Adds MANAGED_HOOK_NAME/MANAGED_HOOK_SOURCE, hasMadarHookSentinel, withManagedHookIdentity, and updates isMadarProjectHook to return true when the sentinel is present.
Apply sentinel to hook generators
src/infrastructure/install.ts
Wraps generated hook entries for Codex (CODEX_HOOK PreToolUse), Claude (settingsHook), and Gemini (geminiHook) with withManagedHookIdentity so installs embed the sentinel.
Update uninstall logic to use sentinel
src/infrastructure/install.ts
Changes Gemini uninstall filtering to use `isMadarProjectHook(..., 'read_file
Replace grep heuristic with sentinel-based detection
src/infrastructure/compare.ts, src/infrastructure/install.ts
Removes OUT_PATH_SEGMENT_PATTERN and containsOutPathReference; updates findHookEntry to call isMadarProjectHook(hook, matcher) with hook-type-specific matcher constraints.
Consolidate test fixtures to shared claudeInstall helper
tests/unit/benchmark-suite.test.ts, tests/unit/compare.test.ts, tests/unit/compare-native-agent.test.ts
Replaces inline creation of .mcp.json, CLAUDE.md, and .claude/settings.json with claudeInstall(projectRoot); adds installState: 'managed' fixture mode.
Sentinel presence and installer verification tests
tests/unit/install.test.ts, tests/unit/compare-native-agent.test.ts
Adds JSON helpers to extract full hook-entry objects and tests that installers write name: 'madar' entries; adds compare tests asserting correct verification behavior for real and non-Madar managed hooks.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • mohanagy/madar#343: Adds the install-detection gate and reporting fields that depend on accurate hook detection.
  • mohanagy/madar#289: Overlaps on Claude hook construction and matcher logic; related to managed-hook identity changes.
  • mohanagy/madar#334: Also modifies Claude hook detection/verification logic and tests; closely related.

Poem

🐰 I hid a name where base64 slept,
A tiny tag that calm installs kept.
"madar" on the hook, honest and bright,
Now compare sees truth where grep lost sight.
Hops of joy — tests pass in the light.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The PR description covers the three core changes (sentinel detection, hook wrapping, regression tests) but lacks explicit test verification commands required by the template. Add explicit testing commands (npm run test:run, typecheck, build) and confirm all checklist items in the description for clarity.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix managed hook install detection' accurately summarizes the main change: fixing the install detection mechanism by switching from path heuristics to managed-hook sentinel matching.
Linked Issues check ✅ Passed The PR implementation addresses all core objectives from issue #349: managed-hook sentinels added to installers, detector logic updated to prefer sentinels, regression tests added for obfuscated hooks and empty states.
Out of Scope Changes check ✅ Passed All changes are tightly scoped to managed-hook detection: updating compare/install logic, wrapping hook generators with sentinels, and adding related test fixtures. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-349-install-detection

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Comment @coderabbitai help to get the list of available commands and usage tips.

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

🧹 Nitpick comments (1)
tests/unit/install.test.ts (1)

698-712: ⚡ Quick win

Assert the source sentinel too, not just name.

Line 708–710 only verifies name. To lock the full managed-hook identity contract and prevent silent regressions, also assert source (e.g., madar:<version>).

💡 Suggested test hardening
   const claudeSettings = readFileSync(join(projectDir, '.claude', 'settings.json'), 'utf8')
   const geminiSettings = readFileSync(join(projectDir, '.gemini', 'settings.json'), 'utf8')
   const codexHooks = readFileSync(join(projectDir, '.codex', 'hooks.json'), 'utf8')

-  expect(extractHookEntry(claudeSettings, 'UserPromptSubmit').name).toBe('madar')
-  expect(extractHookEntry(geminiSettings, 'BeforeTool').name).toBe('madar')
-  expect(extractCodexPreToolUseEntry(codexHooks).name).toBe('madar')
+  const claudeEntry = extractHookEntry(claudeSettings, 'UserPromptSubmit')
+  const geminiEntry = extractHookEntry(geminiSettings, 'BeforeTool')
+  const codexEntry = extractCodexPreToolUseEntry(codexHooks)
+
+  expect(claudeEntry.name).toBe('madar')
+  expect(geminiEntry.name).toBe('madar')
+  expect(codexEntry.name).toBe('madar')
+
+  expect(String(claudeEntry.source ?? '')).toMatch(/^madar:/)
+  expect(String(geminiEntry.source ?? '')).toMatch(/^madar:/)
+  expect(String(codexEntry.source ?? '')).toMatch(/^madar:/)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/install.test.ts` around lines 698 - 712, The test currently only
asserts the managed-hook name sentinel; update the assertions to also check the
source sentinel for each hook entry returned by extractHookEntry (for Claude and
Gemini) and extractCodexPreToolUseEntry (for Codex) — e.g., assert that .source
matches the expected managed source pattern (such as starting with "madar:" or
equals the exact "madar:<version>" you maintain); modify the three expectations
after reading claudeSettings, geminiSettings, and codexHooks to include these
.source checks alongside the existing .name checks to lock the full managed-hook
identity contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/unit/install.test.ts`:
- Around line 698-712: The test currently only asserts the managed-hook name
sentinel; update the assertions to also check the source sentinel for each hook
entry returned by extractHookEntry (for Claude and Gemini) and
extractCodexPreToolUseEntry (for Codex) — e.g., assert that .source matches the
expected managed source pattern (such as starting with "madar:" or equals the
exact "madar:<version>" you maintain); modify the three expectations after
reading claudeSettings, geminiSettings, and codexHooks to include these .source
checks alongside the existing .name checks to lock the full managed-hook
identity contract.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 495b56c0-acbc-4029-b1a6-26228d5ebc48

📥 Commits

Reviewing files that changed from the base of the PR and between 62a00e2 and 5e939c2.

📒 Files selected for processing (6)
  • src/infrastructure/compare.ts
  • src/infrastructure/install.ts
  • tests/unit/benchmark-suite.test.ts
  • tests/unit/compare-native-agent.test.ts
  • tests/unit/compare.test.ts
  • tests/unit/install.test.ts

Resolve the compare.ts import overlap between the managed-hook install detector fix and the shared explain-pack payload update from next.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

1 participant