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.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
fix(cli): remove the owned Augment scripts under the install-hook opt-out
Martin Vogele1be4c4eaf6e
diff --git a/src/cli/cli.c b/src/cli/cli.cindex cf69fe13b..44c0861df 100644--- a/src/cli/cli.c+++ b/src/cli/cli.c@@ -9140,6 +9140,35 @@ static int remove_claude_owned_hook_scripts(const char *config_dir, const char *return rc;}+/* Augment's SessionStart and PostToolUse view scripts are exact-owned: each is+ * rebuilt from the binary path the install embedded and deleted only on a+ * byte-for-byte match, so a script the user edited stays. Uninstall and the+ * install-hook opt-out share this rule. */+static void remove_augment_owned_hook_scripts(const char *binary_path, const char *session_path,+ const char *coverage_path, bool uninstall) {+ const struct {+ const char *path;+ int (*build)(const char *, char *, size_t);+ const char *build_op;+ const char *remove_op;+ } scripts[] = {+ {session_path, cbm_build_augment_session_script, "session_script_build",+ uninstall ? "session_script_uninstall" : "session_script_disable"},+ {coverage_path, cbm_build_augment_coverage_script, "coverage_script_build",+ uninstall ? "coverage_script_uninstall" : "coverage_script_disable"},+ };+ for (size_t i = 0; i < sizeof(scripts) / sizeof(scripts[0]); i++) {+ char script[CLI_BUF_8K];+ if (scripts[i].build(binary_path, script, sizeof(script)) != CLI_OK) {+ record_agent_config_error(uninstall, "Augment/Auggie", scripts[i].build_op,+ scripts[i].path);+ } else if (cbm_text_remove_owned_document(scripts[i].path, script) < 0) {+ record_agent_config_error(uninstall, "Augment/Auggie", scripts[i].remove_op,+ scripts[i].path);+ }+ }+}+static void install_claude_code_config(const char *home, const char *binary_path, bool force,bool dry_run) {char config_dir[CLI_BUF_1K];@@ -11326,6 +11355,7 @@ static void install_additional_agent_configs(const cbm_detected_agents_t *agentsint session_result = cbm_remove_augment_session_hook(cp, session_hp);int coverage_result = cbm_remove_augment_coverage_hook(cp, coverage_hp);hook_ok = session_result == CLI_OK && coverage_result == CLI_OK;+ remove_augment_owned_hook_scripts(binary_path, session_hp, coverage_hp, false);} else if (!cbm_install_augment_session_script(binary_path, session_hp)) {hook_ok = false;record_agent_config_error(false, "Augment/Auggie", "session_script_install",@@ -13701,30 +13731,7 @@ static void uninstall_additional_agents(const cbm_detected_agents_t *agents, conif (cbm_remove_augment_coverage_hook(cp, coverage_hp) != CLI_OK) {record_agent_config_error(true, "Augment/Auggie", "coverage_hook_uninstall", cp);}- char session_script[CLI_BUF_8K];- if (cbm_build_augment_session_script(binary_path, session_script,- sizeof(session_script)) != CLI_OK) {- record_agent_config_error(true, "Augment/Auggie", "session_script_build",- session_hp);- } else {- int script_rc = cbm_text_remove_owned_document(session_hp, session_script);- if (script_rc < 0) {- record_agent_config_error(true, "Augment/Auggie", "session_script_uninstall",- session_hp);- }- }- char coverage_script[CLI_BUF_8K];- if (cbm_build_augment_coverage_script(binary_path, coverage_script,- sizeof(coverage_script)) != CLI_OK) {- record_agent_config_error(true, "Augment/Auggie", "coverage_script_build",- coverage_hp);- } else {- int script_rc = cbm_text_remove_owned_document(coverage_hp, coverage_script);- if (script_rc < 0) {- record_agent_config_error(true, "Augment/Auggie", "coverage_script_uninstall",- coverage_hp);- }- }+ remove_augment_owned_hook_scripts(binary_path, session_hp, coverage_hp, true);}printf(" removed SessionStart + PostToolUse hooks + dedicated subagent\n");}diff --git a/tests/test_cli.c b/tests/test_cli.cindex 569c9353d..82b65975e 100644--- a/tests/test_cli.c+++ b/tests/test_cli.c@@ -2891,6 +2891,131 @@ TEST(cli_no_hooks_removes_codex_pretool_hook) {PASS();}+/* The Augment SessionStart and PostToolUse view scripts follow the persisted+ * opt-out the way uninstall treats them: --no-hooks deletes both exact-owned+ * scripts and keeps the MCP entry, a bare install keeps them off, --hooks+ * restores them, and a script the user edited is kept. */+TEST(cli_no_hooks_removes_augment_owned_scripts) {+ char tmpdir[512];+ snprintf(tmpdir, sizeof(tmpdir), "%s/cli-augment-no-hooks-XXXXXX", cbm_tmpdir());+ if (!cbm_mkdtemp(tmpdir))+ FAIL("cbm_mkdtemp failed");++ const char *const env_names[] = {"HOME", "CBM_CACHE_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 augment_dir[640];+ char settings_path[768];+ char session_path[768];+ char coverage_path[768];+ snprintf(cache_dir, sizeof(cache_dir), "%s/cache", tmpdir);+ snprintf(augment_dir, sizeof(augment_dir), "%s/.augment", tmpdir);+ snprintf(settings_path, sizeof(settings_path), "%s/settings.json", augment_dir);+#ifdef _WIN32+ snprintf(session_path, sizeof(session_path), "%s/hooks/codebase-memory-session.ps1",+ augment_dir);+ snprintf(coverage_path, sizeof(coverage_path), "%s/hooks/codebase-memory-coverage.ps1",+ augment_dir);+#else+ snprintf(session_path, sizeof(session_path), "%s/hooks/codebase-memory-session.sh",+ augment_dir);+ snprintf(coverage_path, sizeof(coverage_path), "%s/hooks/codebase-memory-coverage.sh",+ augment_dir);+#endif+ test_mkdirp(augment_dir);+ /* An installed binary at the default target is the path the scripts embed;+ * without it --skip-binary would configure the test runner itself. */+ char binary_dir[640];+ char binary_path[768];+ snprintf(binary_dir, sizeof(binary_dir), "%s/.local/bin", tmpdir);+ test_mkdirp(binary_dir);+#ifdef _WIN32+ snprintf(binary_path, sizeof(binary_path), "%s/codebase-memory-mcp.exe", binary_dir);+#else+ snprintf(binary_path, sizeof(binary_path), "%s/codebase-memory-mcp", binary_dir);+#endif+ write_test_file(binary_path, "installed binary\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 *default_args[] = {"--skip-binary", "--clients=augment", "--yes"};+ int default_rc = cli_test_cmd_install(3, default_args);+ bool default_scripts =+ default_rc == 0 && cbm_file_exists(session_path) && cbm_file_exists(coverage_path);++ char *no_hooks_args[] = {"--no-hooks", "--skip-binary", "--clients=augment", "--yes"};+ int no_hooks_rc = cli_test_cmd_install(4, no_hooks_args);+ bool scripts_removed =+ no_hooks_rc == 0 && !cbm_file_exists(session_path) && !cbm_file_exists(coverage_path);+ char *settings = read_test_file_alloc(settings_path);+ bool mcp_kept = settings && strstr(settings, "mcpServers") &&+ strstr(settings, "codebase-memory-mcp") &&+ !strstr(settings, "codebase-memory-session") &&+ !strstr(settings, "codebase-memory-coverage");+ free(settings);++ int bare_rc = cli_test_cmd_install(3, default_args);+ bool bare_disabled =+ bare_rc == 0 && !cbm_file_exists(session_path) && !cbm_file_exists(coverage_path);++ char *hooks_args[] = {"--hooks", "--skip-binary", "--clients=augment", "--yes"};+ int hooks_rc = cli_test_cmd_install(4, hooks_args);+ settings = read_test_file_alloc(settings_path);+ bool restored = hooks_rc == 0 && cbm_file_exists(session_path) &&+ cbm_file_exists(coverage_path) && settings &&+ strstr(settings, "codebase-memory-session") &&+ strstr(settings, "codebase-memory-coverage");+ free(settings);++ /* A script the user edited is no longer the owned document: the opt-out+ * keeps it, as uninstall does, and still deletes the untouched one. */+ char *owned_session = read_test_file_alloc(session_path);+ char user_session[4096];+ snprintf(user_session, sizeof(user_session), "%s# local edit\n",+ owned_session ? owned_session : "");+ free(owned_session);+ write_test_file(session_path, user_session);+ int user_rc = cli_test_cmd_install(4, no_hooks_args);+ char *kept_session = read_test_file_alloc(session_path);+ bool user_script_kept = user_rc == 0 && kept_session &&+ strcmp(kept_session, user_session) == 0 &&+ !cbm_file_exists(coverage_path);+ free(kept_session);++ /* End on --hooks, as the Codex case does: the opt-out is process state,+ * and later tests install without the command line. */+ (void)remove(session_path);+ int final_rc = cli_test_cmd_install(4, hooks_args);+ bool final_restored =+ final_rc == 0 && cbm_file_exists(session_path) && cbm_file_exists(coverage_path);++ 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(default_scripts);+ ASSERT_TRUE(mcp_kept);+ ASSERT_TRUE(restored);+ ASSERT_TRUE(scripts_removed);+ ASSERT_TRUE(bare_disabled);+ ASSERT_TRUE(user_script_kept);+ ASSERT_TRUE(final_restored);+ PASS();+}+TEST(cli_install_reset_deletion_waits_for_final_activation_guard) {char tmpdir[256];snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-daemon-install-reset-XXXXXX");@@ -20582,6 +20707,7 @@ SUITE(cli) {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_no_hooks_removes_codex_pretool_hook);+ RUN_TEST(cli_no_hooks_removes_augment_owned_scripts);RUN_TEST(cli_install_reset_deletion_waits_for_final_activation_guard);RUN_TEST(cli_remove_indexes_deletes_orphan_sqlite_sidecars_issue2054);RUN_TEST(cli_index_enumeration_skips_internal_cache_dbs);