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(arch): normalize path trailing slashes; align MCP path_scoped with store (#604)
Berserk Agent55058c05f0be
diff --git a/src/mcp/mcp.c b/src/mcp/mcp.cindex b7456c779..45be91cc8 100644--- a/src/mcp/mcp.c+++ b/src/mcp/mcp.c@@ -1975,7 +1975,8 @@ static char *handle_get_architecture(cbm_mcp_server_t *srv, const char *args) {int node_count = cbm_store_count_nodes_scoped(store, project, scope_path);int edge_count = cbm_store_count_edges_scoped(store, project, scope_path);- bool path_scoped = scope_path && scope_path[0];+ char norm_path[CBM_SZ_512];+ bool path_scoped = cbm_store_normalize_arch_path(scope_path, norm_path, sizeof(norm_path));yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);yyjson_mut_val *root = yyjson_mut_obj(doc);@@ -1985,7 +1986,7 @@ static char *handle_get_architecture(cbm_mcp_server_t *srv, const char *args) {yyjson_mut_obj_add_str(doc, root, "project", project);}if (path_scoped) {- yyjson_mut_obj_add_str(doc, root, "path", scope_path);+ yyjson_mut_obj_add_str(doc, root, "path", norm_path);int root_nodes = cbm_store_count_nodes(store, project);int root_edges = cbm_store_count_edges(store, project);yyjson_mut_obj_add_int(doc, root, "root_total_nodes", root_nodes);diff --git a/src/store/store.c b/src/store/store.cindex 152c8c614..116dbd141 100644--- a/src/store/store.c+++ b/src/store/store.c@@ -2942,9 +2942,19 @@ static bool arch_path_prepare(const char *path, char *norm_out, size_t norm_sz,strncpy(norm_out, path, norm_sz - 1);norm_out[norm_sz - 1] = '\0';size_t len = strlen(norm_out);- while (len > 0 && (norm_out[len - 1] == ' ' || norm_out[len - 1] == '\t')) {+ while (len > 0 && (norm_out[len - 1] == ' ' || norm_out[len - 1] == '\t' ||+ norm_out[len - 1] == '/')) {norm_out[--len] = '\0';}+ /* Collapse duplicate slashes */+ size_t w = 0;+ for (size_t r = 0; norm_out[r] != '\0'; r++) {+ if (norm_out[r] == '/' && w > 0 && norm_out[w - 1] == '/') {+ continue;+ }+ norm_out[w++] = norm_out[r];+ }+ norm_out[w] = '\0';if (norm_out[0] == '\0') {return false;}@@ -2962,6 +2972,17 @@ static void arch_bind_path_scope(sqlite3_stmt *stmt, int exact_idx, int like_idxbind_text(stmt, like_idx, like_pat);}+bool cbm_store_arch_path_scoped(const char *path) {+ char norm[CBM_SZ_512];+ char like[CBM_SZ_512 + 4];+ return arch_path_prepare(path, norm, sizeof(norm), like, sizeof(like));+}++bool cbm_store_normalize_arch_path(const char *path, char *norm_out, size_t norm_sz) {+ char like[CBM_SZ_512 + 4];+ return arch_path_prepare(path, norm_out, norm_sz, like, sizeof(like));+}+int cbm_store_count_nodes_scoped(cbm_store_t *s, const char *project, const char *path) {if (!s || !s->db || !project) {return 0;diff --git a/src/store/store.h b/src/store/store.hindex b52e889a1..43c87f572 100644--- a/src/store/store.h+++ b/src/store/store.h@@ -318,6 +318,12 @@ int cbm_store_count_nodes_scoped(cbm_store_t *s, const char *project, const charint cbm_store_count_edges_scoped(cbm_store_t *s, const char *project, const char *path);+/* True when path is a non-empty scope after normalization (issue #604). */+bool cbm_store_arch_path_scoped(const char *path);++/* When scoped, writes normalized directory prefix into norm_out. Returns false if unscoped. */+bool cbm_store_normalize_arch_path(const char *path, char *norm_out, size_t norm_sz);+/* Delete all nodes for a project (cascade deletes edges). */int cbm_store_delete_nodes_by_project(cbm_store_t *s, const char *project);diff --git a/tests/test_store_arch.c b/tests/test_store_arch.cindex 110ec6550..777140aa9 100644--- a/tests/test_store_arch.c+++ b/tests/test_store_arch.c@@ -277,6 +277,19 @@ TEST(arch_path_scoping) {ASSERT_TRUE(cbm_store_count_nodes(s, "pscope") > cbm_store_count_nodes_scoped(s, "pscope", "apps/foo"));+ cbm_architecture_info_t scoped_slash;+ memset(&scoped_slash, 0, sizeof(scoped_slash));+ ASSERT_EQ(cbm_store_get_architecture(s, "pscope", "apps/foo/", aspects, 2, &scoped_slash),+ CBM_STORE_OK);+ int slash_go = 0;+ for (int i = 0; i < scoped_slash.language_count; i++) {+ if (strcmp(scoped_slash.languages[i].language, "Go") == 0) {+ slash_go = scoped_slash.languages[i].file_count;+ }+ }+ ASSERT_EQ(slash_go, scoped_go);++ cbm_store_architecture_free(&scoped_slash);cbm_store_architecture_free(&whole);cbm_store_architecture_free(&scoped);cbm_store_close(s);