Add graphify PreToolUse hook to .codebuddy/settings.json.
(project_dir: Path)
| 2686 | print("CodeBuddy will now check the knowledge graph before answering") |
| 2687 | print("codebase questions and rebuild it after code changes.") |
| 2688 | def _install_codebuddy_hook(project_dir: Path) -> None: |
| 2689 | """Add graphify PreToolUse hook to .codebuddy/settings.json.""" |
| 2690 | settings_path = project_dir / ".codebuddy" / "settings.json" |
| 2691 | settings_path.parent.mkdir(parents=True, exist_ok=True) |
| 2692 | |
| 2693 | settings = _read_settings_for_merge(settings_path) |
| 2694 | |
| 2695 | hooks = settings.setdefault("hooks", {}) |
| 2696 | if not isinstance(hooks, dict): |
| 2697 | _refuse_to_modify(settings_path) |
| 2698 | pre_tool = hooks.setdefault("PreToolUse", []) |
| 2699 | if not isinstance(pre_tool, list): |
| 2700 | _refuse_to_modify(settings_path) |
| 2701 | |
| 2702 | hooks["PreToolUse"] = _strip_graphify_hooks(pre_tool) |
| 2703 | hooks["PreToolUse"].extend(_claude_pretooluse_hooks()) |
| 2704 | _write_settings_with_backup(settings_path, settings) |
| 2705 | print(f" .codebuddy/settings.json -> PreToolUse hooks registered") |
| 2706 | def _uninstall_codebuddy_hook(project_dir: Path) -> None: |
| 2707 | """Remove graphify PreToolUse hook from .codebuddy/settings.json.""" |
| 2708 | settings_path = project_dir / ".codebuddy" / "settings.json" |
no test coverage detected