From cf7ce3a450740397c44ad1508d90f0b2ff7ff08a Mon Sep 17 00:00:00 2001 From: Safi Date: Sat, 2 May 2026 17:29:40 +0100 Subject: [PATCH] fix #651: hook-check exits silently instead of emitting unsupported additionalContext MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- graphify/__main__.py | 20 +++----------------- tests/test_hooks.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/graphify/__main__.py b/graphify/__main__.py index 256e0574..0bae9190 100644 --- a/graphify/__main__.py +++ b/graphify/__main__.py @@ -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: diff --git a/tests/test_hooks.py b/tests/test_hooks.py index 14a7ad86..9d1260c3 100644 --- a/tests/test_hooks.py +++ b/tests/test_hooks.py @@ -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 == ""