Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions graphify/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,13 @@ def _install_gemini_hook(project_dir: Path) -> None:
except json.JSONDecodeError:
settings = {}
before_tool = settings.setdefault("hooks", {}).setdefault("BeforeTool", [])
if any("graphify" in str(h) for h in before_tool):
print(" .gemini/settings.json -> hook already registered (no change)")
return
before_tool.append(_GEMINI_HOOK)

# Remove any existing graphify hooks (handles upgrades from old versions)
filtered = [h for h in before_tool if "graphify" not in str(h)]
settings["hooks"]["BeforeTool"] = filtered

# Install fresh hook
settings["hooks"]["BeforeTool"].append(_GEMINI_HOOK)
settings_path.write_text(json.dumps(settings, indent=2), encoding="utf-8")
print(" .gemini/settings.json -> BeforeTool hook registered")

Expand Down Expand Up @@ -417,11 +420,13 @@ def _install_codex_hook(project_dir: Path) -> None:
existing = {}

pre_tool = existing.setdefault("hooks", {}).setdefault("PreToolUse", [])
if any("graphify" in str(h) for h in pre_tool):
print(f" .codex/hooks.json -> hook already registered (no change)")
return

pre_tool.extend(_CODEX_HOOK["hooks"]["PreToolUse"])
# Remove any existing graphify hooks (handles upgrades from old versions)
filtered = [h for h in pre_tool if "graphify" not in str(h)]
existing["hooks"]["PreToolUse"] = filtered

# Install fresh hook with correct format
existing["hooks"]["PreToolUse"].extend(_CODEX_HOOK["hooks"]["PreToolUse"])
hooks_path.write_text(json.dumps(existing, indent=2), encoding="utf-8")
print(f" .codex/hooks.json -> PreToolUse hook registered")

Expand Down Expand Up @@ -540,12 +545,12 @@ def _install_claude_hook(project_dir: Path) -> None:
hooks = settings.setdefault("hooks", {})
pre_tool = hooks.setdefault("PreToolUse", [])

# Check if already installed
if any(h.get("matcher") == "Glob|Grep" and "graphify" in str(h) for h in pre_tool):
print(f" .claude/settings.json -> hook already registered (no change)")
return
# Remove any existing graphify hooks (handles upgrades from old versions)
filtered = [h for h in pre_tool if not (h.get("matcher") == "Glob|Grep" and "graphify" in str(h))]
settings["hooks"]["PreToolUse"] = filtered

pre_tool.append(_SETTINGS_HOOK)
# Install fresh hook
settings["hooks"]["PreToolUse"].append(_SETTINGS_HOOK)
settings_path.write_text(json.dumps(settings, indent=2), encoding="utf-8")
print(f" .claude/settings.json -> PreToolUse hook registered")

Expand Down