Skip to content

fix(install): emit a bare hook command for project-scoped installs (#3129) - #3149

Closed
davidbhoward wants to merge 1 commit into
Graphify-Labs:v8from
davidbhoward:fix/3129-project-install-portable-hook-command
Closed

davidbhoward wants to merge 1 commit into
Graphify-Labs:v8from
davidbhoward:fix/3129-project-install-portable-hook-command

Conversation

@davidbhoward

Copy link
Copy Markdown
Contributor

Summary

graphify install --project resolves the graphify executable to an absolute path from the
installing user's environment and writes that path into hook configuration that the installer
then instructs the user to commit. Those paths are invalid for every other contributor and for CI.

Refs #3129, which reports this for Codex, with the Claude Code occurrence noted in the thread.
That issue is filed against a plain graphify install, so this PR does not close it — it fixes
the --project case only, for the reason already discussed there: a user-profile install lands
somewhere nobody else is expected to share, whereas --project carries the explicit expectation
that others contribute to that checkout. See "Scope" below.

To be clear about what is and isn't at issue: hook-guard itself is sound. It handles the Grep
tool payload shape that defeats a naive command matcher, and its read mode does per-file staleness
detection. Path handling at install time is the only defect here.

Reproduction

Clean git init repositories, no prior graphify configuration:

mkdir gfx-claude && cd gfx-claude && git init .
graphify install --project --platform claude
cat .claude/settings.json
{
  "hooks": {
    "PreToolUse": [
      { "matcher": "Bash|Grep",
        "hooks": [ { "type": "command",
                     "command": "C:/Users/<user>/.local/bin/graphify.EXE hook-guard search" } ] },
      { "matcher": "Read|Glob",
        "hooks": [ { "type": "command",
                     "command": "C:/Users/<user>/.local/bin/graphify.EXE hook-guard read" } ] }
    ]
  }
}

The same run prints:

Project-scoped install. Add to version control:
  git add .claude/ CLAUDE.md

graphify install --project --platform codex writes the same shape into .codex/hooks.json
(... graphify.EXE hook-check), and --platform gemini into .gemini/settings.json
(... graphify.EXE hook-guard gemini).

Why this is wrong

--project exists to produce a shared, version-controlled setup. That is precisely the case in
which an absolute path cannot be correct. A committed hook pointing into one developer's home
directory fails silently for everyone else: the configuration is present and syntactically valid,
so nothing looks broken, but every matching tool call fails to run the hook.

The drive letter and .EXE casing also make the value non-portable between two Windows checkouts,
not only across operating systems. And each machine that reinstalls rewrites the entry with its own
path, churning a shared file.

Affected platforms

Three platforms write a hook command through the shared _resolve_graphify_exe(), so the defect is
in that shared layer rather than in any one platform's config writer:

Platform File Command
claude .claude/settings.json hook-guard search / hook-guard read
codex .codex/hooks.json hook-check
gemini .gemini/settings.json hook-guard gemini

Codex and Claude are both already noted on #3129; Gemini appears not to have been, and falls out of
the same shared resolver.

codebuddy shares _claude_pretooluse_hooks() but has no project-scoped hook path
(graphify install --project --platform codebuddy writes no .codebuddy/settings.json), so it is
unaffected by this change.

The change

Project-scoped installs emit the bare command:

"command": "graphify hook-guard search"

PATH resolves it, the way a committed config refers to git or node. _resolve_graphify_exe()
takes a project flag that is threaded through the three hook builders and set only at the
--project entry points in _project_install().

This follows a convention the codebase already uses rather than introducing a new mechanism: the
git-hook layer resolves the binary at runtime with GRAPHIFY_BIN=$(command -v graphify)
(graphify/hooks.py), and skill-agents.md does the same with which graphify. Baking a path at
install time is the outlier.

The user-profile install is unchanged. That location is not one other people are expected to
share, and the resolved absolute path is what makes the hook work where the venv Scripts/
directory is not on PATH — the VS Code Codex extension on Windows, per the existing docstring. A
regression test pins that behaviour.

Anticipated objection

A bare command breaks when graphify is not on a contributor's PATH.

That is not a regression. A missing binary and a wrong absolute path both fail the hook; the
difference is diagnosis. graphify: command not found names the problem, whereas a path into
another developer's home directory gives the reader nothing to work with and reads like a
deliberate configuration choice. The bare command fails more loudly and more usefully than what
ships today. This argument applies only to the committed case, which is why the user-profile path
is left alone.

Scope

Deliberately narrow. Two further defects were observed in the same files and are not included
here, to keep this reviewable:

  1. Generated config ends without a trailing newline (\ No newline at end of file), adding diff
    noise to committed JSON.
  2. Installing over an existing, differing hook command replaces it with no diff, no warning, and no
    indication that a customised value was overwritten.

Happy to open those separately.

This PR also does not address the non---project half of #3129. That report's reproduction is a
plain graphify install, and graphify codex install without the flag still writes an absolute
path into .codex/hooks.json in the working directory. Per the discussion on that issue, the
absolute path is defensible there — that install is not aimed at a location others are expected to
maintain — and the case is further entangled with #2164, which reports that these installs write
into the cwd rather than a user config directory at all. Left for a maintainer call rather than
silently bundled, which is why this is Refs and not Fixes.

Related: #3009 fixes the same class of defect for .githooks/* by moving the interpreter path into
a gitignored sidecar. That approach fits there because git hooks run in GUI clients and CI where
PATH is unreliable; these hooks are executed by the agent harness in the user's own shell, where
the documented install puts graphify on PATH.

Tests

Added to tests/test_install.py, asserting on generated content rather than mocked calls:

  • test_project_install_hook_command_is_portable (claude, codex, gemini) — no absolute path, no
    drive letter, no backslash, no .EXE casing, no leak of the installing user's path.
  • test_user_profile_install_still_resolves_absolute_path (claude, codex, gemini) — the
    non-project install still emits the resolved path, so the fix does not regress the case where
    that is correct.
  • test_project_install_is_idempotent (claude, codex, gemini) — installing twice leaves
    byte-identical config.
  • test_project_uninstall_removes_the_bare_hook_command — the uninstall filter matches on
    "graphify", so a bare command is still stripped.

Verified these fail without the fix: the three ..._is_portable cases fail on clean v8 and pass
with the change; the rest pass either way, as guards.

Full suite was run on Windows: 4935 passed, 31 failed, 104 skipped. All 31 failures are
pre-existing and unrelated (fifo/unix-socket, symlinks, shell metacharacters, ollama retries). I
verified this by running the same suite against clean v8 and diffing the failure sets — identical,
zero introduced and zero fixed. Per the README, exact CI parity needs Linux; the Ubuntu matrix will
confirm. ruff check and the blocking skillgen --check / --schema-singleton jobs pass.

…raphify-Labs#3129)

`--project` resolved the graphify executable to an absolute path from the installing
machine and wrote it into hook config the installer then tells the user to commit
("Add to version control: git add .claude/"). The result is a tracked hook naming a
directory that exists on exactly one machine:

    "command": "C:/Users/<user>/.local/bin/graphify.EXE hook-guard search"

For every other clone the config is present and syntactically valid, so nothing looks
broken, while each matching tool call silently fails to run the hook. The drive letter
and .EXE casing do not survive between two Windows checkouts either, and each machine
that reinstalls rewrites the entry with its own path, churning a shared file.

Project-scoped installs now emit the bare command and let PATH resolve it, the way the
git-hook layer already does with `command -v graphify` (hooks.py) and the way a tracked
config refers to git or node. This covers claude, codex and gemini, which share
_resolve_graphify_exe(); codebuddy has no project-scoped hook path.

The user-profile install is deliberately unchanged. That file stays on the machine that
wrote it, and the resolved absolute path is what keeps the hook working where the venv
Scripts/ dir is not on PATH, such as the VS Code Codex extension on Windows.

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

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.

Formal verification. 3 change(s) tested, no difference found (not proven).


Graphify review — findings

Makes project-scoped hook installs emit the bare graphify command instead of a machine-absolute exe path, so the committed .claude/settings.json, .gemini/settings.json, and .codex/hooks.json resolve via each clone's PATH rather than pointing at the installing machine's venv (#3129). Threads a project flag through _resolve_graphify_exe, _claude_pretooluse_hooks, _gemini_hook, _install_claude_hook, _install_gemini_hook, _install_codex_hook, claude_install, and _agents_install, with _project_install passing project=True. Global installs still resolve the absolute path so hooks work when the Scripts/bin dir is off PATH.

Worth a look

  • Project-scoped hooks execute unpinned bare graphify from PATH — graphify/install.py:1429 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 480 functions depend on the 284 functions this change touches.

Health — this change adds coupling hotspots:

  • new: dispatch_command() — 2 callers, 122 callees
  • new: codebuddy_install() — 20 callers, 5 callees
  • new: claude_install() — 19 callers, 4 callees
  • new: gemini_install() — 10 callers, 7 callees
  • new: claude_uninstall() — 17 callers, 4 callees
  • new: _project_uninstall() — 5 callers, 13 callees
  • new: dispatch_install_cli() — 2 callers, 31 callees
  • new: codebuddy_uninstall() — 14 callers, 4 callees
  • …and 13 more — each is listed as a finding

Verification — 480 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: 415 function(s) in the blast radius were not formally verified this run

Formal verification

Could not verify: Could not verify \_agents\_install.

The verifier did not have enough to check \_agents\_install, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: not verifiable: all 200 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)

Could not verify: Could not verify claude\_install.

The verifier did not have enough to check claude\_install, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: not verifiable: all 58 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)

No difference found (not proven): No behavior difference found in \_claude\_pretooluse\_hooks (not a proof).

The verifier ran both versions of \_claude\_pretooluse\_hooks on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

No difference found (not proven): No behavior difference found in \_gemini\_hook (not a proof).

The verifier ran both versions of \_gemini\_hook on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

Could not verify: Could not verify gemini\_install.

The verifier did not have enough to check gemini\_install, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `project_dir` is annotated `Path | None` — outside the synthesizable primitive/collection set

Could not verify: Could not verify \_install\_claude\_hook.

The verifier did not have enough to check \_install\_claude\_hook, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `project_dir` is annotated `Path` — outside the synthesizable primitive/collection set

Could not verify: Could not verify \_install\_codex\_hook.

The verifier did not have enough to check \_install\_codex\_hook, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `project_dir` is annotated `Path` — outside the synthesizable primitive/collection set

Could not verify: Could not verify \_install\_gemini\_hook.

The verifier did not have enough to check \_install\_gemini\_hook, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `project_dir` is annotated `Path` — outside the synthesizable primitive/collection set

Could not verify: Could not verify \_project\_install.

The verifier did not have enough to check \_project\_install, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `project_dir` is annotated `Path | None` — outside the synthesizable primitive/collection set

No difference found (not proven): No behavior difference found in \_resolve\_graphify\_exe (not a proof).

The verifier ran both versions of \_resolve\_graphify\_exe on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

· 5 grounded finding(s) anchored inline below; 16 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/install.py
shutil.copy2(settings_path, backup)
settings_path.write_text(output, encoding="utf-8")
def _install_gemini_hook(project_dir: Path) -> None:
def _install_gemini_hook(project_dir: Path, project: bool = False) -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — _install_gemini_hook()

high coupling complexity (Ca·Ce = 12).

Grounded coupling-delta finding (deterministic), not an LLM guess.

Comment thread graphify/install.py
return (found or "graphify").replace("\\", "/")
def _install_codex_hook(project_dir: Path) -> None:
"""Add graphify PreToolUse hook to .codex/hooks.json."""
def _install_codex_hook(project_dir: Path, project: bool = False) -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — _install_codex_hook()

high coupling complexity (Ca·Ce = 20).

Grounded coupling-delta finding (deterministic), not an LLM guess.

Comment thread graphify/install.py
hooks_path.write_text(json.dumps(existing, indent=2), encoding="utf-8")
print(f" .codex/hooks.json -> PreToolUse hook removed")
def _agents_install(project_dir: Path, platform: str) -> None:
def _agents_install(project_dir: Path, platform: str, project: bool = False) -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — _agents_install()

fans out to 6 callees (efferent coupling); 6 callers depend on it (afferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

Comment thread graphify/install.py
removed = _kilo_uninstall_global()
print("; ".join(removed) if removed else "nothing to remove")
def claude_install(project_dir: Path | None = None, strict: bool = False) -> None:
def claude_install(project_dir: Path | None = None, strict: bool = False, project: bool = False) -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — claude_install()

19 callers depend on it (afferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

Comment thread graphify/install.py
print("one `graphify query` runs (toggle with GRAPHIFY_HOOK_STRICT=0).")
def _install_claude_hook(project_dir: Path, strict: bool = False) -> None:
"""Add graphify PreToolUse hook to .claude/settings.json."""
def _install_claude_hook(project_dir: Path, strict: bool = False, project: bool = False) -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — _install_claude_hook()

high coupling complexity (Ca·Ce = 20).

Grounded coupling-delta finding (deterministic), not an LLM guess.

@davidbhoward

Copy link
Copy Markdown
Contributor Author

On the bare graphify from PATH — that's the intent of the change, not a side effect of it. The alternative is what this PR is fixing: an absolute path baked in at install time, which is correct only on the machine that ran the installer and wrong in every other clone. PATH resolution is also already the convention in this repo. hooks.py resolves the binary at runtime with GRAPHIFY_BIN=$(command -v graphify), and skill-agents.md does the same with which graphify. So this brings the agent hooks in line with the git hooks rather than introducing a new assumption. A committed config that refers to graphify is the same trust model as one that refers to git or node.

If you'd rather pin it, the gitignored sidecar in #3009 looks like the natural precedent, but that seemed like a bigger design call than this PR should make on its own. Happy to follow up separately if you want that.

On the five coupling findings, I think those are artifacts rather than real regressions. This change only adds optional keyword arguments (project: bool = False) and threads them through calls that already existed, so it doesn't add any edges. I parsed install.py before and after and compared caller/callee pairs — 550 both ways, nothing added or removed. The functions listed as new (claude_install with 19 callers, and so on) had that coupling already; only their bodies changed, so I think they're being re-registered as new nodes.

Tests are still waiting on workflow approval. Locally the full suite shows no regressions against v8 — the same 31 pre-existing Windows-only failures with and without the change — and all five skillgen validators pass.

@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.52 via authorship-preserving cherry-pick so you keep contributor-graph credit. Thanks @davidbhoward! Release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.52

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.

2 participants