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): load runtime config for the hook-augment worktree note
Nohj5d5c9621eb3e
diff --git a/src/cli/hook_augment.c b/src/cli/hook_augment.cindex 1043b48cd..a389e487f 100644--- a/src/cli/hook_augment.c+++ b/src/cli/hook_augment.c@@ -1475,14 +1475,28 @@ static char *ha_lifecycle_json_from_root(cbm_mcp_server_t *srv, yyjson_val *rootchar cwd_buffer[4096];cbm_mcp_server_t *owned_server = NULL;+ cbm_config_t *owned_config = NULL;if (!srv) {owned_server = cbm_mcp_server_new(NULL);srv = owned_server;}+ /* cbm_mcp_server_new(NULL) does not attach the runtime store. The production+ * hook uses that constructor, so ignore_worktrees would stay at its default+ * (off) and the "not indexed" note would still tell the agent to run+ * index_repository in a linked worktree the setting refuses. Load the store+ * only when the caller has not already set one, then drop it before return+ * so a caller-owned server is not left pointing at a closed config. */+ if (srv) {+ owned_config = cbm_mcp_server_attach_runtime_config(srv);+ }const char *cwd = ha_normalized_cwd_with_server(root, srv, cwd_buffer, sizeof(cwd_buffer));char *project = srv && cwd ? ha_resolve_indexed_project(srv, cwd) : NULL;bool worktree_ignored = !project && srv && cwd && cbm_mcp_ignore_worktrees_enabled(srv) &&cbm_git_is_linked_worktree(cwd);+ if (owned_config) {+ cbm_mcp_server_set_config(srv, NULL);+ cbm_config_close(owned_config);+ }cbm_mcp_server_free(owned_server);char context[2048];diff --git a/src/mcp/mcp.c b/src/mcp/mcp.cindex 41a63273e..19083feee 100644--- a/src/mcp/mcp.c+++ b/src/mcp/mcp.c@@ -1751,6 +1751,18 @@ void cbm_mcp_server_set_config(cbm_mcp_server_t *srv, struct cbm_config *cfg) {}}+struct cbm_config *cbm_mcp_server_attach_runtime_config(cbm_mcp_server_t *srv) {+ if (!srv || srv->config) {+ return NULL;+ }+ cbm_config_t *cfg = cbm_config_open(cbm_resolve_cache_dir());+ if (!cfg) {+ return NULL;+ }+ srv->config = cfg;+ return cfg;+}+#ifdef CBM_ENABLE_TEST_SEAMSvoid cbm_mcp_server_set_auto_index_count_test_hook(cbm_mcp_server_t *srv,cbm_mcp_auto_index_count_test_hook_fn hook,diff --git a/src/mcp/mcp.h b/src/mcp/mcp.hindex 09befb780..6fb110181 100644--- a/src/mcp/mcp.h+++ b/src/mcp/mcp.h@@ -158,6 +158,12 @@ void cbm_mcp_server_set_watcher(cbm_mcp_server_t *srv, struct cbm_watcher *w);/* Set external config store reference (for auto_index setting). Not owned. */void cbm_mcp_server_set_config(cbm_mcp_server_t *srv, struct cbm_config *cfg);+/* Open the runtime config and attach it when srv has none. The returned store+ * is owned by the caller, who must clear it with cbm_mcp_server_set_config+ * before closing. Returns NULL when a config is already set or the store+ * cannot be opened. */+struct cbm_config *cbm_mcp_server_attach_runtime_config(cbm_mcp_server_t *srv);+/* Set an explicit session context for an embedded/daemon-backed server.* session_root is copied and its project name is derived using the same naming* rule as indexing. allowed_root is copied when non-NULL; an explicit NULLdiff --git a/tests/test_cli.c b/tests/test_cli.cindex 14553ef68..5d7441ec4 100644--- a/tests/test_cli.c+++ b/tests/test_cli.c@@ -10629,9 +10629,21 @@ TEST(cli_hook_unindexed_worktree_reports_no_match_not_silent) {snprintf(input, sizeof(input), "{\"hook_event_name\":\"SessionStart\",\"cwd\":\"%s\"}", wtdir);char *wt_out = cbm_hook_augment_lifecycle_json(input);bool deliberate = wt_out && wt_out[0] && strstr(wt_out, "no indexed graph project matched") &&- !strstr(wt_out, "is indexed");+ strstr(wt_out, "Run index_repository") &&+ !strstr(wt_out, "ignore_worktrees is enabled") && !strstr(wt_out, "is indexed");free(wt_out);+ /* The hook must read the runtime store. With the key off the note still+ * says to index; with it on, the same unindexed worktree must not. */+ cbm_config_t *cfg = cbm_config_open(cache);+ bool configured = cfg && cbm_config_set(cfg, CBM_CONFIG_IGNORE_WORKTREES, "true") == 0;+ cbm_config_close(cfg);+ char *ignored_out = configured ? cbm_hook_augment_lifecycle_json(input) : NULL;+ bool honored = ignored_out && strstr(ignored_out, "ignore_worktrees is enabled") &&+ strstr(ignored_out, "do not run index_repository") &&+ !strstr(ignored_out, "is indexed");+ free(ignored_out);+snprintf(input, sizeof(input), "{\"hook_event_name\":\"SessionStart\",\"cwd\":\"%s\"}",maindir);char *main_out = cbm_hook_augment_lifecycle_json(input);@@ -10647,6 +10659,8 @@ TEST(cli_hook_unindexed_worktree_reports_no_match_not_silent) {if (!deliberate)FAIL("unindexed worktree must get a deliberate no-match notice, never a silent 0 bytes");+ if (!honored)+ FAIL("ignore_worktrees in the runtime config must change the unindexed-worktree note");if (!main_ok)FAIL("the indexed main checkout must still resolve in the same matrix");PASS();