Skip to content

fix(install): remove only graphify's own hook entries, keep others (#4359) - #4373

Closed
nothariharan wants to merge 1 commit into
Graphify-Labs:v8from
nothariharan:fix/hook-identity
Closed

nothariharan wants to merge 1 commit into
Graphify-Labs:v8from
nothariharan:fix/hook-identity

Conversation

@nothariharan

Copy link
Copy Markdown
Contributor

What this fixes

Closes #4359.

When graphify installed or removed its PreToolUse / BeforeTool hooks, it identified its own hooks with "graphify" in str(group) over the whole group dict. str(group) covers {"matcher": ..., "hooks": [...]}, not graphify's individual command, so:

  1. A user command added to the hooks array of one of graphify's groups was removed with the group on the next install/uninstall.
  2. An unrelated group whose command path merely contained the word graphify (e.g. python /tools/graphify-notes/check.py) was removed too.
  3. Uninstall rewrote the settings file with no backup, and _strip_graphify_hook raised AttributeError on a non-dict entry.

Confirmed real on v8 (0.9.87)

// graphify claude install --project
// add your own command to graphify's Bash|Grep group
// add a separate group: python /tools/graphify-notes/check.py
$ graphify claude uninstall --project
user linter kept?       False      (bug)
unrelated group kept?   False      (bug)
backup written?         False      (bug)
non-dict entry result:  AttributeError: 'str' object has no attribute 'get'

The fix

Hook entries are now matched at the entry level, not the group level:

  • _is_graphify_hook_command(command) — true when a command invokes graphify's own hook-guard <search|read|gemini> / hook-check subcommands, or references graphify-out/ (which identifies the pre-codex install writes bash-only PreToolUse hook that fails on Windows PowerShell #522 inline bash guard, so legacy entries are still cleaned up).
  • _is_graphify_hook_entry(entry) — the entry is a type: "command" hook whose command matches the above. Non-dict / non-command entries are never graphify's (and no longer crash uninstall).
  • _strip_graphify_hooks(groups) — removes only graphify's entries from each group, keeps every other entry, and drops a group only once it has nothing left. Non-dict groups and non-list hooks pass through untouched; a group with no graphify entry is never rewritten.

Applied to all four hook hosts, install and uninstall, so the filters stay in step:

Host Install Uninstall
Claude _install_claude_hook _strip_graphify_hook
CodeBuddy _install_codebuddy_hook _uninstall_codebuddy_hook
Codex _install_codex_hook _uninstall_codex_hook
Gemini _install_gemini_hook _uninstall_gemini_hook

The uninstall paths now write through _write_settings_with_backup, so they keep the same rolling .graphify-bak that install already did.

Tests

New tests/test_install_hook_identity.py:

  • Per host, uninstall keeps a user command sharing graphify's group and an unrelated group whose path contains graphify, while removing graphify's own commands, and writes a backup.
  • Per host, a non-dict entry in the hook array does not crash uninstall and is preserved.
  • The pre-codex install writes bash-only PreToolUse hook that fails on Windows PowerShell #522 bash guard is replaced on install, and re-install stays idempotent.
  • Unit tests for _is_graphify_hook_command (recognises graphify's variants + legacy, rejects graphify-notes-style paths) and _strip_graphify_hooks (keeps user entries, drops only emptied groups, passes malformed shapes through).

Verification:

  • New tests pass: 19 passed; pre-fix the same suite fails 16 cases.
  • Existing suites unaffected: 160 passed, 3 skipped (settings-merge + install + new).
  • End-to-end via the CLI repro above: user command and unrelated group survive, graphify guards removed, backup written.
  • ruff check clean.

…raphify-Labs#4359)

Hook install/uninstall identified graphify's hooks with
`"graphify" in str(group)` over the whole group dict. That removed a user's
own command sharing graphify's `hooks` array (with the whole group), and any
unrelated group whose command path merely contained the word "graphify" (e.g.
a script under `graphify-notes/`). Uninstall rewrote the settings file with no
backup, and `_strip_graphify_hook` raised AttributeError on a non-dict entry.

Match the individual `hooks[]` entries instead. A graphify entry is a command
hook whose command invokes graphify's own `hook-guard`/`hook-check` subcommands
(current installs) or references `graphify-out/` (the pre-Graphify-Labs#522 inline bash
guard). Only those entries are removed; a group is dropped only when nothing is
left in it, and non-dict/non-list shapes are passed through. Applies to the
Claude, CodeBuddy, Codex and Gemini install and uninstall filters, keeping them
in step. Uninstall now goes through `_write_settings_with_backup`, so it keeps
a rolling `.graphify-bak` like install already did.

Adds tests covering a user command sharing graphify's group, an unrelated group
whose path contains "graphify", a non-dict entry, and the legacy-bash replacement
plus idempotency for each host.
@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 12, 2026
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @nothariharan. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

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

Graphify reviewed this change.

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; no formal proof of the changed code.


Graphify review — findings

Replaces the whole-group "graphify" in str(group) match in the Claude, CodeBuddy, Codex and Gemini hook install/uninstall paths with _strip_graphify_hooks, which removes only individual command entries graphify wrote. Those are entries naming hook-guard/hook-check, or the legacy graphify-out/ bash guard. User commands sharing a group and unrelated groups whose path merely contains "graphify" now survive, a group is dropped only once it's emptied, and non-dict or malformed entries pass through untouched. Uninstall now skips non-list sections, does nothing when nothing changed, and writes through _write_settings_with_backup instead of overwriting the file without a backup.

No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 590 functions depend on the 178 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: _install_claude_hook() — 6 callers, 5 callees
  • worse: _install_codex_hook() — 5 callers, 5 callees
  • worse: _install_codebuddy_hook() — 3 callers, 5 callees
  • worse: _install_gemini_hook() — 3 callers, 5 callees

Verification — 590 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 401 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

40 of 391 test file(s) selected (10%) via static blast radius.

  • tests/test_affected_cli.py — impact
  • tests/test_agents_platform.py — impact
  • tests/test_atomic_version_stamp.py — impact
  • tests/test_claude_md.py — impact
  • tests/test_codebuddy.py — impact
  • tests/test_dedup_shrink_refuses_force_write.py — impact
  • tests/test_detect.py — impact
  • tests/test_devin.py — impact
  • tests/test_explain_cli.py — impact
  • tests/test_explain_same_file_tie.py — impact
  • tests/test_extract_cli.py — impact
  • tests/test_gemini_hook.py — impact
  • tests/test_global_add_tag_inference.py — impact
  • tests/test_god_nodes_cli.py — impact
  • tests/test_hollow_chunks_arm_shrink_guard.py — impact
  • tests/test_home_sandbox.py — impact
  • tests/test_hook_strict.py — impact
  • tests/test_incomplete_build_guard.py — impact
  • tests/test_install.py — impact
  • tests/test_install_hook_identity.py — impact, changed-test
  • tests/test_install_references.py — impact
  • tests/test_install_strings.py — impact
  • tests/test_install_version_warning.py — impact
  • tests/test_lookup_exit_codes.py — impact
  • tests/test_merge_chunks_validation.py — impact
  • tests/test_multigraph_diagnostics.py — impact
  • tests/test_no_dedup_flag.py — impact
  • tests/test_opencode_plugin_refresh.py — impact
  • tests/test_path_cli.py — impact
  • tests/test_query_cli.py — impact
  • tests/test_query_induced_edges.py — impact
  • tests/test_read_hook.py — impact
  • tests/test_replace_or_append_section.py — impact
  • tests/test_search_hook.py — impact
  • tests/test_skill_auto_refresh.py — impact
  • tests/test_skill_version_warning.py — impact
  • tests/test_truncation_full_answer.py — impact
  • tests/test_uninstall_purge_safety.py — impact
  • tests/test_uninstall_scope.py — impact
  • tests/test_unverified_semantic_shrink.py — impact

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

· 4 more finding(s) on lines outside this diff (see the check run).

@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.88, just released to PyPI as graphifyy 0.9.88. Landed via an authorship-preserving cherry-pick (your commit keeps your name and counts on your contributor graph), which is why GitHub marks this closed rather than merged. Thanks @nothariharan!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hook install/uninstall identifies graphify's hooks by the substring "graphify" and drops whole hook groups, including other commands in them

2 participants