fix #651: hook-check exits silently instead of emitting unsupported additionalContext

Codex Desktop rejects hookSpecificOutput.additionalContext on PreToolUse.
hook-check is now a no-op — graph guidance reaches the agent via AGENTS.md/skill.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Safi
2026-05-02 17:29:40 +01:00
co-authored by Claude Sonnet 4.6
parent ba41258635
commit cf7ce3a450
2 changed files with 22 additions and 17 deletions
+3 -17
View File
@@ -1510,23 +1510,9 @@ def main() -> None:
sys.exit(1)
elif cmd == "hook-check":
# Shell-agnostic PreToolUse hook entry point for Codex (and any platform
# where embedding Python/bash inline in a JSON hook command is fragile).
# Prints the hookSpecificOutput JSON if graph.json exists, exits 0 silently
# if not. Works on Windows PowerShell, cmd.exe, macOS, and Linux.
graph = Path("graphify-out") / "graph.json"
if graph.exists():
import json as _json
print(_json.dumps({
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"additionalContext": (
"graphify: Knowledge graph exists. "
"Read graphify-out/GRAPH_REPORT.md for god nodes and "
"community structure before searching raw files."
),
}
}))
# Codex Desktop rejects hookSpecificOutput.additionalContext on PreToolUse.
# Keep this as a cross-platform no-op so installed hooks never break Bash
# tool calls. Graph guidance reaches the agent via AGENTS.md / skill instead.
sys.exit(0)
elif cmd == "check-update":
if len(sys.argv) < 3:
+19
View File
@@ -123,3 +123,22 @@ def test_hook_skips_head_on_exe():
"""Hook script must skip shebang extraction for .exe binaries (Windows)."""
from graphify.hooks import _PYTHON_DETECT
assert "*.exe) _SHEBANG=" in _PYTHON_DETECT or '*.exe)' in _PYTHON_DETECT
def test_hook_check_no_additionalContext(tmp_path):
"""graphify hook-check must not emit additionalContext — Codex Desktop rejects it."""
import sys
out = tmp_path / "graphify-out"
out.mkdir()
(out / "graph.json").write_text("{}", encoding="utf-8")
result = subprocess.run(
[sys.executable, "-m", "graphify", "hook-check"],
cwd=tmp_path,
capture_output=True,
text=True,
)
assert result.returncode == 0
assert result.stdout == ""
assert result.stderr == ""