Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

Merge origin/main into carry/1862-install-hook-optout

Martin Vogel2577a86ad0c1
diff --cc docs/CONFIGURATION.md
index d795fed9d,038256976..4cf82faf4
--- a/docs/CONFIGURATION.md
+++ b/docs/CONFIGURATION.md
@@@ -90,9 -89,8 +90,11 @@@ Current keys
| `auto_index_limit` | `50000` | Maximum file count allowed for automatic indexing of a new project. |
| `auto_watch` | `true` | Register the session's project with the background git watcher on connect. Set `false` to keep a session from registering its project (the watcher still runs for other projects). |
| `watcher_enabled` | `true` | Master switch for the background watcher subsystem. Set `false` to stop the watcher from starting at all — no poll thread and no project registration. Reindex manually with `index_repository` when disabled. |
+ | `index_max_files` | `off` | Optional maximum number of accepted source files in one discovery run. |
+ | `index_max_source_mb` | `off` | Optional maximum accepted source size in MiB in one discovery run. |
+| `install_hooks` | `true` | Install CBM-managed client hooks. `install --no-hooks` persists `false`; `install --hooks` restores `true`. |
+
+Bare installs and updates respect the stored hook preference. MCP registration, skills, instructions, and profiles remain installed when hooks are disabled.
> **`watcher_enabled` vs `auto_watch`.** `watcher_enabled` controls whether the
> watcher *subsystem* starts at all (the background poll thread). `auto_watch` is
diff --cc scripts/smoke-test.sh
index aa192261e,d1c64c6b7..a5b616db8
--- a/scripts/smoke-test.sh
+++ b/scripts/smoke-test.sh
@@@ -1691,22 -1739,6 +1739,25 @@@ if ! grep -q 'hook-augment' "$GATE_SCRI
fi
echo "OK 8e: shim installed, non-blocking, delegates to hook-augment"
+HOME="$FAKE_HOME" XDG_CONFIG_HOME="$FAKE_HOME/.config" APPDATA="$FAKE_HOME/AppData/Roaming" LOCALAPPDATA="$FAKE_HOME/AppData/Local" PATH="$FAKE_HOME/.local/bin:$PATH" \
+ "$BINARY" install --no-hooks --skip-binary --clients=claude -y >/dev/null
- if grep -qE 'cbm-(code-discovery-gate|session-reminder|subagent-reminder)' "$FAKE_HOME/.claude/settings.json" 2>/dev/null ||
- [ -e "$FAKE_HOME/.claude/hooks/cbm-code-discovery-gate" ] ||
++# Claude hooks are registered shell-free (#1733): 'hook-augment' is the owned
++# marker; the shim names only cover legacy shell registrations.
++if grep -qE 'hook-augment|cbm-(code-discovery-gate|session-reminder|subagent-reminder)' "$FAKE_HOME/.claude/settings.json" 2>/dev/null ||
++ [ -e "$GATE_SCRIPT" ] ||
+ ! grep -q 'codebase-memory-mcp' "$FAKE_HOME/.claude.json" 2>/dev/null; then
+ echo "FAIL 8e-i: --no-hooks did not remove owned Claude hooks while preserving MCP"
+ exit 1
+fi
+HOME="$FAKE_HOME" XDG_CONFIG_HOME="$FAKE_HOME/.config" APPDATA="$FAKE_HOME/AppData/Roaming" LOCALAPPDATA="$FAKE_HOME/AppData/Local" PATH="$FAKE_HOME/.local/bin:$PATH" \
+ "$BINARY" install --hooks --skip-binary --clients=claude -y >/dev/null
- if ! grep -q 'cbm-code-discovery-gate' "$FAKE_HOME/.claude/settings.json" 2>/dev/null; then
++if ! grep -q 'hook-augment' "$FAKE_HOME/.claude/settings.json" 2>/dev/null ||
++ [ ! -e "$GATE_SCRIPT" ]; then
+ echo "FAIL 8e-i: --hooks did not restore owned Claude hooks"
+ exit 1
+fi
+echo "OK 8e-i: Claude hook opt-out and re-enable preserve MCP"
+
# 8f-8h: Codex TOML
if ! grep -q '\[mcp_servers.codebase-memory-mcp\]' "$FAKE_HOME/.codex/config.toml"; then
echo "FAIL 8f: Codex TOML missing MCP section"
diff --cc src/cli/cli.c
index bb4a4cd32,b868fdca2..5707c6e0c
--- a/src/cli/cli.c
+++ b/src/cli/cli.c
@@@ -7536,12 -8177,91 +8178,96 @@@ typedef struct
static cbm_install_plan_t *g_install_plan = NULL;
static int g_agent_install_errors = 0;
static int g_agent_uninstall_errors = 0;
+static bool g_install_hooks = true;
+
+static void print_hooks_skipped(void) {
+ printf(" hooks: skipped (install --hooks to enable)\n");
+}
+ /* Every agent configuration uninstall could not clean, kept for the closing
+ * summary. A cleanup failure no longer stops executable and index removal
+ * (#1954: one symlinked ~/.cursor/mcp.json left a 300 MB binary plus the whole
+ * cache behind), so the user needs ONE list of what is still theirs to fix,
+ * with the observed reason next to each file. */
+ typedef struct {
+ char agent[64];
+ char operation[48];
+ char path[CLI_BUF_1K];
+ char reason[160];
+ char detail[160];
+ } cbm_agent_config_failure_t;
+
+ static cbm_agent_config_failure_t *g_agent_uninstall_failures = NULL;
+ static int g_agent_uninstall_failure_count = 0;
+ static int g_agent_uninstall_failure_cap = 0;
+
+ static void agent_uninstall_failures_reset(void) {
+ free(g_agent_uninstall_failures);
+ g_agent_uninstall_failures = NULL;
+ g_agent_uninstall_failure_count = 0;
+ g_agent_uninstall_failure_cap = 0;
+ }
+
+ static void agent_uninstall_failure_record(const char *agent, const char *operation,
+ const char *path, const char *reason,
+ const char *detail) {
+ if (g_agent_uninstall_failure_count >= g_agent_uninstall_failure_cap) {
+ int ncap = g_agent_uninstall_failure_cap ? g_agent_uninstall_failure_cap * 2 : CLI_BUF_16;
+ cbm_agent_config_failure_t *grown =
+ realloc(g_agent_uninstall_failures, (size_t)ncap * sizeof(*grown));
+ if (!grown) {
+ return;
+ }
+ g_agent_uninstall_failures = grown;
+ g_agent_uninstall_failure_cap = ncap;
+ }
+ cbm_agent_config_failure_t *entry =
+ &g_agent_uninstall_failures[g_agent_uninstall_failure_count++];
+ (void)snprintf(entry->agent, sizeof(entry->agent), "%s", agent ? agent : "unknown");
+ (void)snprintf(entry->operation, sizeof(entry->operation), "%s",
+ operation ? operation : "unknown");
+ (void)snprintf(entry->path, sizeof(entry->path), "%s", path ? path : "unknown");
+ (void)snprintf(entry->reason, sizeof(entry->reason), "%s", reason ? reason : "");
+ (void)snprintf(entry->detail, sizeof(entry->detail), "%s", detail ? detail : "");
+ }
+
+ /* The agent-configuration writers opt in to following user-owned symlinked
+ * config files under the user's configuration roots (#1954, decision C);
+ * every other caller of the config editors keeps refusing links. Cleared by
+ * the same command when its configuration work is done. */
+ static void cli_config_follow_begin(const char *home) {
+ cbm_config_edit_path_follow_clear();
+ if (home && home[0]) {
+ (void)cbm_config_edit_path_follow_add_root(home);
+ }
+ const char *xdg_config = getenv("XDG_CONFIG_HOME");
+ if (xdg_config && xdg_config[0]) {
+ (void)cbm_config_edit_path_follow_add_root(xdg_config);
+ }
+ }
+
+ /* The closing list of what uninstall could not clean. Printed AFTER the
+ * executable and the indexes are gone, so nothing in it is a reason to keep
+ * the installation around — each line is one file the user removes an entry
+ * from by hand. */
+ static void agent_uninstall_failures_report(bool dry_run) {
+ if (g_agent_uninstall_failure_count == 0) {
+ return;
+ }
+ (void)fprintf(stderr, "\nerror: uninstall %s with %d agent configuration(s) left uncleaned:\n",
+ dry_run ? "dry-run finished" : "finished", g_agent_uninstall_failure_count);
+ for (int i = 0; i < g_agent_uninstall_failure_count; i++) {
+ const cbm_agent_config_failure_t *entry = &g_agent_uninstall_failures[i];
+ (void)fprintf(stderr, " %s (%s): %s", entry->agent, entry->operation, entry->path);
+ if (entry->reason[0]) {
+ (void)fprintf(stderr, " reason=%s", entry->reason);
+ }
+ (void)fputs(entry->detail, stderr);
+ (void)fputc('\n', stderr);
+ }
+ (void)fputs("Remove the codebase-memory-mcp entries from these files by hand.\n", stderr);
+ }
+
static void plan_record(const char *agent, const char *kind, const char *path) {
if (!g_install_plan || !path || !path[0]) {
return;
@@@ -7828,22 -8471,6 +8567,23 @@@ static void install_claude_code_config(
char settings_path[CLI_BUF_1K];
snprintf(settings_path, sizeof(settings_path), "%s/settings.json", config_dir);
+ if (!g_install_hooks) {
+ if (!dry_run) {
- if (cbm_remove_claude_hooks(settings_path) != CLI_OK) {
++ if (cbm_remove_claude_hooks_with_binary(settings_path, binary_path) != CLI_OK) {
+ record_agent_config_error(false, "Claude Code", "hook_disable", settings_path);
+ }
- if (cbm_remove_session_hooks(settings_path) != CLI_OK) {
++ if (cbm_remove_session_hooks(settings_path, binary_path) != CLI_OK) {
+ record_agent_config_error(false, "Claude Code", "hook_disable", settings_path);
+ }
- if (cbm_remove_claude_subagent_hooks(settings_path) != CLI_OK) {
++ if (cbm_remove_claude_subagent_hooks_with_binary(settings_path, binary_path) !=
++ CLI_OK) {
+ record_agent_config_error(false, "Claude Code", "hook_disable", settings_path);
+ }
+ remove_claude_owned_hook_scripts(config_dir, binary_path, false);
+ }
+ print_hooks_skipped();
+ goto claude_hooks_done;
+ }
bool gate_ok = dry_run;
bool session_ok = dry_run;
bool subagent_ok = dry_run;
@@@ -8284,16 -8929,8 +9043,16 @@@ static void install_copilot_durable_con
plan_record("Copilot", "hook", hook_path);
return;
}
+ if (!g_install_hooks) {
+ if (!dry_run && cbm_file_exists(hook_path) &&
+ cbm_remove_copilot_hooks(hook_path, binary_path) != CLI_OK) {
+ record_agent_config_error(false, "Copilot", "hook_disable", hook_path);
+ }
+ print_hooks_skipped();
+ return;
+ }
bool hook_ok = true;
- if (!dry_run && (!cbm_mkdir_p(hooks_dir, CLI_OCTAL_PERM) ||
+ if (!dry_run && (!cbm_mkdir_p_ex(hooks_dir, CLI_OCTAL_PERM, CBM_MKDIR_FOLLOW_OWNED) ||
cbm_upsert_copilot_hooks(binary_path, hook_path) != CLI_OK)) {
hook_ok = false;
record_agent_config_error(false, "Copilot", "lifecycle_hook_install", hook_path);
diff --cc src/main.c
index 7851ab3ec,65e041217..e9fb33c64
--- a/src/main.c
+++ b/src/main.c
@@@ -898,10 -1096,13 +1096,13 @@@ static void print_help(void)
printf("codebase-memory-mcp %s\n\n", CBM_VERSION);
printf("Usage:\n");
printf(" codebase-memory-mcp Run MCP server on stdio\n");
- printf(" codebase-memory-mcp cli [--progress] [--json] <tool> [args]\n");
+ printf(" codebase-memory-mcp cli [--quiet] [--progress] [--verbose] [--json] <tool> "
+ "[args]\n");
printf(" Run one tool locally, then exit\n");
printf(" codebase-memory-mcp install [-y|-n] [--force] [--dry-run] "
- "[--dir=<path>] [--skip-config]\n");
+ "[--dir=<path>] [--skip-config] [--hooks|--no-hooks]\n");
+ printf(" [--clients=<tokens>] Run "
+ "'install --clients' to list tokens\n");
printf(" codebase-memory-mcp uninstall [-y|-n] [--dry-run]\n");
printf(" codebase-memory-mcp update [-y|-n]\n");
printf(" codebase-memory-mcp config <list|get|set|reset>\n");
diff --cc tests/test_cli.c
index b9790fdce,d56ff7c99..fcc8b9c76
--- a/tests/test_cli.c
+++ b/tests/test_cli.c
@@@ -1158,264 -2179,6 +2179,264 @@@ TEST(cli_activation_commands_reject_mal
PASS();
}
+TEST(cli_install_hooks_preference_persists_and_migrates_owned_state) {
+ char tmpdir[512];
+ snprintf(tmpdir, sizeof(tmpdir), "%s/cli-install-hooks-XXXXXX", cbm_tmpdir());
+ if (!cbm_mkdtemp(tmpdir))
+ FAIL("cbm_mkdtemp failed");
+
+ const char *const env_names[] = {"HOME", "CBM_CACHE_DIR", "CLAUDE_CONFIG_DIR", "PATH"};
+ char *saved_env[sizeof(env_names) / sizeof(env_names[0])];
+ for (size_t i = 0U; i < sizeof(env_names) / sizeof(env_names[0]); i++) {
+ saved_env[i] = save_test_env(env_names[i]);
+ cbm_unsetenv(env_names[i]);
+ }
+
+ char cache_dir[640];
+ char claude_dir[640];
+ char settings_path[768];
+ char mcp_path[768];
+ char db_path[768];
+ char gate_path[768];
+ char session_path[768];
+ char subagent_path[768];
+ snprintf(cache_dir, sizeof(cache_dir), "%s/cache", tmpdir);
+ snprintf(claude_dir, sizeof(claude_dir), "%s/.claude", tmpdir);
+ snprintf(settings_path, sizeof(settings_path), "%s/settings.json", claude_dir);
+ snprintf(mcp_path, sizeof(mcp_path), "%s/.claude.json", tmpdir);
+ snprintf(db_path, sizeof(db_path), "%s/_config.db", cache_dir);
+#ifdef _WIN32
+ snprintf(gate_path, sizeof(gate_path), "%s/hooks/cbm-code-discovery-gate.cmd", claude_dir);
+ snprintf(session_path, sizeof(session_path), "%s/hooks/cbm-session-reminder.cmd", claude_dir);
+ snprintf(subagent_path, sizeof(subagent_path), "%s/hooks/cbm-subagent-reminder.cmd", claude_dir);
+#else
+ snprintf(gate_path, sizeof(gate_path), "%s/hooks/cbm-code-discovery-gate", claude_dir);
+ snprintf(session_path, sizeof(session_path), "%s/hooks/cbm-session-reminder", claude_dir);
+ snprintf(subagent_path, sizeof(subagent_path), "%s/hooks/cbm-subagent-reminder", claude_dir);
+#endif
+ test_mkdirp(claude_dir);
+ write_test_file(settings_path,
+ "{\"hooks\":{\"PreToolUse\":[{\"matcher\":\"Bash\",\"hooks\":[{\"type\":"
+ "\"command\",\"command\":\"/usr/bin/foreign-hook\"}]}]}}\n");
+ cbm_setenv("HOME", tmpdir, 1);
+ cbm_setenv("CBM_CACHE_DIR", cache_dir, 1);
+ cbm_setenv("PATH", tmpdir, 1);
+
+ cli_activation_fake_t fake = {.mutation_reserve_result = 1};
+ cbm_cli_activation_ops_t ops = cli_activation_fake_ops(&fake);
+ cbm_cli_set_activation_ops_for_test(&ops);
+
+ char *conflict_a[] = {"--hooks", "--no-hooks"};
+ char *conflict_b[] = {"--no-hooks", "--hooks"};
+ int conflict_a_rc = cli_test_cmd_install(2, conflict_a);
+ int conflict_b_rc = cli_test_cmd_install(2, conflict_b);
+
+ char *default_args[] = {"--skip-binary", "--clients=claude", "--yes"};
+ int default_rc = cli_test_cmd_install(3, default_args);
+ char *default_state = read_test_file_alloc(settings_path);
- bool default_hook = default_state && strstr(default_state, "cbm-code-discovery-gate") &&
++ bool default_hook = default_state && strstr(default_state, "hook-augment") &&
+ strstr(default_state, "/usr/bin/foreign-hook");
+ bool default_scripts = cbm_file_exists(gate_path) && cbm_file_exists(session_path) &&
+ cbm_file_exists(subagent_path);
+ free(default_state);
+
+ char *no_hooks_plan_args[] = {"--plan", "--no-hooks"};
+ int no_hooks_plan_rc = cli_test_cmd_install(2, no_hooks_plan_args);
+ char *disabled_plan = cbm_build_install_plan_json(tmpdir, "/opt/codebase-memory-mcp");
+ yyjson_doc *disabled_doc =
+ disabled_plan ? yyjson_read(disabled_plan, strlen(disabled_plan), 0) : NULL;
+ yyjson_val *disabled_root = disabled_doc ? yyjson_doc_get_root(disabled_doc) : NULL;
+ yyjson_val *disabled_hooks =
+ disabled_root ? yyjson_obj_get(disabled_root, "hooks_planned") : NULL;
+ yyjson_val *disabled_configs =
+ disabled_root ? yyjson_obj_get(disabled_root, "config_files_planned") : NULL;
+ bool disabled_plan_ok = disabled_hooks && yyjson_is_arr(disabled_hooks) &&
+ yyjson_arr_size(disabled_hooks) == 0U && disabled_configs &&
+ yyjson_is_arr(disabled_configs) &&
+ yyjson_arr_size(disabled_configs) > 0U;
+ yyjson_doc_free(disabled_doc);
+ free(disabled_plan);
+
+ char *no_hooks_dry_args[] = {"--dry-run", "--no-hooks", "--skip-binary", "--clients=claude",
+ "--yes"};
+ int no_hooks_dry_rc = cli_test_cmd_install(5, no_hooks_dry_args);
+ struct stat db_status;
+ bool previews_read_only = stat(db_path, &db_status) != 0;
+
+ char *no_hooks_args[] = {"--no-hooks", "--skip-binary", "--clients=claude", "--yes"};
+ int no_hooks_rc = cli_test_cmd_install(4, no_hooks_args);
+ cbm_config_t *cfg = cbm_config_open(cache_dir);
+ bool stored_false = cfg && !cbm_config_get_bool(cfg, CBM_CONFIG_INSTALL_HOOKS, true);
+ cbm_config_close(cfg);
+ char *disabled_state = read_test_file_alloc(settings_path);
+ char *disabled_mcp = read_test_file_alloc(mcp_path);
+ bool disabled_ok = disabled_state && strstr(disabled_state, "/usr/bin/foreign-hook") &&
- !strstr(disabled_state, "cbm-code-discovery-gate") && disabled_mcp &&
++ !strstr(disabled_state, "hook-augment") && disabled_mcp &&
+ strstr(disabled_mcp, "codebase-memory-mcp");
+ bool no_hooks_scripts_gone = !cbm_file_exists(gate_path) && !cbm_file_exists(session_path) &&
+ !cbm_file_exists(subagent_path);
+ free(disabled_state);
+ free(disabled_mcp);
+
+ char *bare_args[] = {"--skip-binary", "--clients=claude", "--yes"};
+ int bare_disabled_rc = cli_test_cmd_install(3, bare_args);
+ disabled_state = read_test_file_alloc(settings_path);
+ bool bare_disabled = disabled_state && strstr(disabled_state, "/usr/bin/foreign-hook") &&
- !strstr(disabled_state, "cbm-code-discovery-gate");
++ !strstr(disabled_state, "hook-augment");
+ bool bare_scripts_gone =
+ !cbm_file_exists(gate_path) && !cbm_file_exists(session_path) &&
+ !cbm_file_exists(subagent_path);
+ free(disabled_state);
+
+ char *hooks_plan_args[] = {"--plan", "--hooks"};
+ char *hooks_dry_args[] = {"--dry-run", "--hooks", "--skip-binary", "--clients=claude", "--yes"};
+ int hooks_plan_rc = cli_test_cmd_install(2, hooks_plan_args);
+ int hooks_dry_rc = cli_test_cmd_install(5, hooks_dry_args);
+ cfg = cbm_config_open(cache_dir);
+ bool previews_retained_false = cfg && !cbm_config_get_bool(cfg, CBM_CONFIG_INSTALL_HOOKS, true);
+ cbm_config_close(cfg);
+
+ char *hooks_args[] = {"--hooks", "--skip-binary", "--clients=claude", "--yes"};
+ int hooks_rc = cli_test_cmd_install(4, hooks_args);
+ cfg = cbm_config_open(cache_dir);
+ bool stored_true = cfg && cbm_config_get_bool(cfg, CBM_CONFIG_INSTALL_HOOKS, false);
+ cbm_config_close(cfg);
+ char *enabled_state = read_test_file_alloc(settings_path);
- bool enabled_ok = enabled_state && strstr(enabled_state, "cbm-code-discovery-gate") &&
++ bool enabled_ok = enabled_state && strstr(enabled_state, "hook-augment") &&
+ strstr(enabled_state, "/usr/bin/foreign-hook");
+ bool hooks_scripts_back = cbm_file_exists(gate_path) && cbm_file_exists(session_path) &&
+ cbm_file_exists(subagent_path);
+ free(enabled_state);
+ int bare_enabled_rc = cli_test_cmd_install(3, bare_args);
+ bool bare_scripts_enabled = cbm_file_exists(gate_path) && cbm_file_exists(session_path) &&
+ cbm_file_exists(subagent_path);
+
+ const char *foreign_session_script =
+#ifdef _WIN32
+ "@echo off\r\nC:\\tmp\\user-owned-session-hook.cmd\r\n";
+#else
+ "#!/bin/sh\n/usr/bin/user-owned-session-hook\n";
+#endif
+ write_test_file(session_path, foreign_session_script);
+ int foreign_no_hooks_rc = cli_test_cmd_install(4, no_hooks_args);
+ char *preserved_session = read_test_file_alloc(session_path);
+ bool foreign_session_preserved =
+ foreign_no_hooks_rc == 0 && preserved_session &&
+ strcmp(preserved_session, foreign_session_script) == 0 && !cbm_file_exists(gate_path) &&
+ !cbm_file_exists(subagent_path);
+ free(preserved_session);
+
+ bool results_ok =
+ conflict_a_rc == 1 && conflict_b_rc == 1 && default_rc == 0 && default_hook &&
+ default_scripts && no_hooks_plan_rc == 0 && disabled_plan_ok && no_hooks_dry_rc == 0 &&
+ previews_read_only && no_hooks_rc == 0 && stored_false && disabled_ok &&
+ no_hooks_scripts_gone && bare_disabled_rc == 0 && bare_disabled && bare_scripts_gone &&
+ hooks_plan_rc == 0 && hooks_dry_rc == 0 && previews_retained_false && hooks_rc == 0 &&
+ stored_true && enabled_ok && hooks_scripts_back && bare_enabled_rc == 0 &&
+ bare_scripts_enabled && foreign_session_preserved && fake.mutation_reserve_count > 0;
+
+ cbm_cli_set_activation_ops_for_test(NULL);
+ cbm_set_auto_answer_for_test(0);
+ for (size_t i = 0U; i < sizeof(env_names) / sizeof(env_names[0]); i++) {
+ restore_test_env(env_names[i], saved_env[i]);
+ }
+ test_rmdir_r(tmpdir);
+
+ ASSERT_TRUE(results_ok);
+ PASS();
+}
+
+TEST(cli_no_hooks_plan_covers_every_hook_installer_family) {
+ char tmpdir[512];
+ snprintf(tmpdir, sizeof(tmpdir), "%s/cli-hook-families-XXXXXX", cbm_tmpdir());
+ if (!cbm_mkdtemp(tmpdir))
+ FAIL("cbm_mkdtemp failed");
+
+ const char *const env_names[] = {"HOME", "CBM_CACHE_DIR", "PATH", "XDG_CONFIG_HOME"};
+ char *saved_env[sizeof(env_names) / sizeof(env_names[0])];
+ for (size_t i = 0U; i < sizeof(env_names) / sizeof(env_names[0]); i++) {
+ saved_env[i] = save_test_env(env_names[i]);
+ cbm_unsetenv(env_names[i]);
+ }
+
+ const char *const dirs[] = {".claude", ".codex", ".gemini",
+ ".config/opencode", ".augment", ".openclaw/workspace",
+ ".hermes", ".qwen", ".copilot",
+ ".factory", ".qoder", ".kimi-code",
+ ".config/devin", ".gitlab/duo", "bin"};
+ char path[768];
+ for (size_t i = 0U; i < sizeof(dirs) / sizeof(dirs[0]); i++) {
+ snprintf(path, sizeof(path), "%s/%s", tmpdir, dirs[i]);
+ test_mkdirp(path);
+ }
+ snprintf(path, sizeof(path), "%s/.openclaw/openclaw.json", tmpdir);
+ write_test_file(path, "{}\n");
+ snprintf(path, sizeof(path), "%s/.copilot/mcp-config.json", tmpdir);
+ write_test_file(path, "{}\n");
+
+ const char *const commands[] = {"qodercli", "kimi", "duo", "devin", "gemini",
+ "copilot", "auggie", "hermes", "droid"};
+ char bin_dir[640];
+ snprintf(bin_dir, sizeof(bin_dir), "%s/bin", tmpdir);
+ for (size_t i = 0U; i < sizeof(commands) / sizeof(commands[0]); i++) {
+#ifdef _WIN32
+ snprintf(path, sizeof(path), "%s/%s.exe", bin_dir, commands[i]);
+#else
+ snprintf(path, sizeof(path), "%s/%s", bin_dir, commands[i]);
+#endif
+ write_test_file(path, "exit 0\n");
+ chmod(path, 0700);
+ }
+
+ char cache_dir[640];
+ snprintf(cache_dir, sizeof(cache_dir), "%s/cache", tmpdir);
+ cbm_setenv("HOME", tmpdir, 1);
+ cbm_setenv("CBM_CACHE_DIR", cache_dir, 1);
+ cbm_setenv("PATH", bin_dir, 1);
+ char *no_hooks_args[] = {"--plan", "--no-hooks"};
+ int no_hooks_rc = cli_test_cmd_install(2, no_hooks_args);
+ char *plan = cbm_build_install_plan_json(tmpdir, "/opt/codebase-memory-mcp");
+ yyjson_doc *doc = plan ? yyjson_read(plan, strlen(plan), 0) : NULL;
+ yyjson_val *root = doc ? yyjson_doc_get_root(doc) : NULL;
+ yyjson_val *hooks = root ? yyjson_obj_get(root, "hooks_planned") : NULL;
+ yyjson_val *configs = root ? yyjson_obj_get(root, "config_files_planned") : NULL;
+ yyjson_val *instructions = root ? yyjson_obj_get(root, "instruction_files_planned") : NULL;
+ const char *const detected[] = {"claude-code", "codex", "gemini", "opencode",
+ "augment-auggie", "openclaw", "hermes", "qwen",
+ "copilot-cli", "factory-droid", "qoder", "kimi",
+ "gitlab-duo", "devin"};
+ bool families = no_hooks_rc == 0 && hooks && yyjson_is_arr(hooks) &&
+ yyjson_arr_size(hooks) == 0U && configs && yyjson_is_arr(configs) &&
+ yyjson_arr_size(configs) > 0U && instructions && yyjson_is_arr(instructions) &&
+ yyjson_arr_size(instructions) > 0U && plan && !strstr(plan, "cbm-augment.ts");
+ for (size_t i = 0U; families && i < sizeof(detected) / sizeof(detected[0]); i++) {
+ families = test_json_string_array_contains(root, "agents_detected", detected[i]);
+ }
+ yyjson_doc_free(doc);
+ free(plan);
+
+ char *hooks_args[] = {"--plan", "--hooks"};
+ int hooks_rc = cli_test_cmd_install(2, hooks_args);
+ char *enabled_plan = cbm_build_install_plan_json(tmpdir, "/opt/codebase-memory-mcp");
+ yyjson_doc *enabled_doc =
+ enabled_plan ? yyjson_read(enabled_plan, strlen(enabled_plan), 0) : NULL;
+ yyjson_val *enabled_root = enabled_doc ? yyjson_doc_get_root(enabled_doc) : NULL;
+ yyjson_val *enabled_hooks = enabled_root ? yyjson_obj_get(enabled_root, "hooks_planned") : NULL;
+ bool enabled_plan_ok =
+ enabled_hooks && yyjson_is_arr(enabled_hooks) && yyjson_arr_size(enabled_hooks) > 0U;
+ yyjson_doc_free(enabled_doc);
+ free(enabled_plan);
+ for (size_t i = 0U; i < sizeof(env_names) / sizeof(env_names[0]); i++) {
+ restore_test_env(env_names[i], saved_env[i]);
+ }
+ test_rmdir_r(tmpdir);
+
+ ASSERT_TRUE(families);
+ ASSERT_EQ(hooks_rc, 0);
+ ASSERT_TRUE(enabled_plan_ok);
+ PASS();
+}
+
TEST(cli_install_reset_deletion_waits_for_final_activation_guard) {
char tmpdir[256];
snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-daemon-install-reset-XXXXXX");
@@@ -13941,9 -16187,8 +16459,10 @@@ SUITE(cli)
RUN_TEST(cli_install_force_quiesces_active_cohort_before_replacing_binary);
RUN_TEST(cli_install_dir_and_skip_config_stage_first_install_safely);
RUN_TEST(cli_activation_commands_reject_malformed_and_unknown_flags);
+ RUN_TEST(cli_install_hooks_preference_persists_and_migrates_owned_state);
+ RUN_TEST(cli_no_hooks_plan_covers_every_hook_installer_family);
RUN_TEST(cli_install_reset_deletion_waits_for_final_activation_guard);
+ RUN_TEST(cli_remove_indexes_deletes_orphan_sqlite_sidecars_issue2054);
RUN_TEST(cli_install_config_only_waits_for_cohort_drain);
RUN_TEST(cli_install_config_and_path_finish_before_guard_release);
RUN_TEST(cli_install_config_failure_keeps_published_binary);