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 main into mcp protocol branch

Martin Vogel345425a1bbf7
diff --cc src/mcp/mcp.c
index 5e034dee4,e146e9d20..a6bebb779
--- a/src/mcp/mcp.c
+++ b/src/mcp/mcp.c
@@@ -325,8 -287,6 +325,8 @@@ static const tool_def_t TOOLS[] =
"\"target_projects\":{\"type\":\"array\",\"items\":{\"type\":\"string\"},"
"\"description\":\"Projects to search for cross-repo links (cross-repo-intelligence mode). "
"Use [\\\"*\\\"] for all indexed projects. Run list_projects to see available projects.\"},"
+ "\"name\":{\"type\":\"string\",\"description\":"
- "\"Override the derived project name. Unicode is preserved and unsafe path characters are normalized.\"},"
++ "\"Override the derived project name. Non-ASCII bytes are encoded and unsafe path characters are normalized.\"},"
"\"persistence\":{\"type\":\"boolean\",\"default\":false,\"description\":"
"\"Write compressed artifact to .codebase-memory/graph.db.zst for team sharing. "
"Teammates can bootstrap from the artifact instead of full re-indexing.\"}"
diff --cc src/pipeline/fqn.c
index 2fa7b8cfd,449bc81ec..d70466d87
--- a/src/pipeline/fqn.c
+++ b/src/pipeline/fqn.c
@@@ -331,21 -363,43 +363,43 @@@ char *cbm_project_name_from_path(const
/* Normalize path separators */
cbm_normalize_path_sep(path);
- /* Map every character cbm_validate_project_name would reject to '-'. The
- /* Map every character cbm_validate_project_name would reject. The
-- * validator (used by resolve_store via project_db_path) allows only
-- * [A-Za-z0-9._-], so anything else — path separators, ':', spaces, '@',
- * '+', unicode bytes, … — must be normalized here. Otherwise a repo like
- * '+', … — must be normalized here. Otherwise a repo like
++ /* Map every character that is unsafe for portable project DB names. We
++ * keep derived names in [A-Za-z0-9._-], so anything else — path
++ * separators, ':', spaces, '@', '+', … — must be normalized here.
++ * Otherwise a repo like
* "/home/u/my project" yields the name "home-u-my project": indexing
* creates the DB and it shows in list_projects, but resolve_store rejects
- * the space and reports project-not-found (#349). */
+ * the space and reports project-not-found (#349).
+ *
+ * Non-ASCII bytes (UTF-8 of CJK and other scripts, all >= 0x80) are NOT
+ * dropped to '-' — that silently erased whole path segments and produced
+ * unrecognizable / colliding names (#571). Instead each non-ASCII byte is
+ * transliterated to its two lowercase hex digits, which use only [0-9a-f]
+ * and therefore stay validator-safe while preserving the segment. */
+ static const char hex_digits[] = "0123456789abcdef";
+ char *mapped = malloc(len * 2 + 1); /* worst case: every byte → 2 hex chars */
+ if (!mapped) {
+ free(path);
+ return strdup("root");
+ }
+ size_t mlen = 0;
for (size_t i = 0; i < len; i++) {
unsigned char c = (unsigned char)path[i];
- bool safe = (c >= 0x80) || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
- (c >= '0' && c <= '9') || c == '.' || c == '_' || c == '-';
- if (!safe) {
- path[i] = '-';
+ bool safe = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') ||
+ c == '.' || c == '_' || c == '-';
+ if (safe) {
+ mapped[mlen++] = (char)c;
+ } else if (c >= 0x80) {
+ mapped[mlen++] = hex_digits[(c >> 4) & 0xF];
+ mapped[mlen++] = hex_digits[c & 0xF];
+ } else {
+ mapped[mlen++] = '-';
}
}
+ mapped[mlen] = '\0';
+ free(path);
+ path = mapped;
+ len = mlen;
/* Collapse consecutive dashes, and consecutive dots (the validator also
* rejects any ".." sequence). */
diff --cc tests/test_fqn.c
index 6b098bb50,9ff999e60..69b87d053
--- a/tests/test_fqn.c
+++ b/tests/test_fqn.c
@@@ -478,21 -478,6 +478,20 @@@ TEST(project_name_always_validator_safe
PASS();
}
- TEST(project_name_preserves_unicode_segments_issue571) {
++TEST(project_name_encodes_unicode_segments_issue571) {
+ char *got = cbm_project_name_from_path(
+ "/Users/yunxin/Desktop/\xe5\xbc\x80\xe5\x8f\x91/"
+ "\xe5\x90\x8e\xe7\xab\xaf/"
+ "\xe4\xbf\xa1\xe7\xa7\x9f\xe9\xa3\x8e\xe6\x8e\xa7\xe9\x80\x9a\xe5\x90\x8e\xe7\xab\xaf");
+ ASSERT_NOT_NULL(got);
+ ASSERT_STR_EQ(got,
- "Users-yunxin-Desktop-\xe5\xbc\x80\xe5\x8f\x91-"
- "\xe5\x90\x8e\xe7\xab\xaf-"
- "\xe4\xbf\xa1\xe7\xa7\x9f\xe9\xa3\x8e\xe6\x8e\xa7\xe9\x80\x9a\xe5\x90\x8e\xe7\xab\xaf");
++ "Users-yunxin-Desktop-e5bc80e58f91-e5908ee7abaf-"
++ "e4bfa1e7a79fe9a38ee68ea7e9809ae5908ee7abaf");
+ ASSERT_TRUE(cbm_validate_project_name(got));
+ free(got);
+ PASS();
+}
+
/* ================================================================
* Suite
* ================================================================ */
@@@ -594,7 -579,6 +593,7 @@@ SUITE(fqn)
RUN_TEST(project_name_already_dashed);
RUN_TEST(project_name_deep_path);
RUN_TEST(project_name_always_validator_safe_issue349);
- RUN_TEST(project_name_preserves_unicode_segments_issue571);
++ RUN_TEST(project_name_encodes_unicode_segments_issue571);
RUN_TEST(project_name_colon_only);
RUN_TEST(project_name_backslash_only);
RUN_TEST(project_name_consecutive_colons);
diff --cc tests/test_mcp.c
index 25cedfc62,7dc7c1144..1e3461231
--- a/tests/test_mcp.c
+++ b/tests/test_mcp.c
@@@ -196,27 -188,6 +196,27 @@@ TEST(mcp_tools_list)
PASS();
}
+TEST(mcp_tools_list_latest_metadata) {
+ char *json = cbm_mcp_tools_list();
+ ASSERT_NOT_NULL(json);
+ ASSERT_NOT_NULL(strstr(json, "\"title\":\"Search graph\""));
+ ASSERT_NOT_NULL(strstr(json, "\"title\":\"Index repository\""));
+ ASSERT_NOT_NULL(strstr(json, "\"outputSchema\":{\"type\":\"object\""));
+ ASSERT_NOT_NULL(strstr(json, "\"additionalProperties\":true"));
+ free(json);
+ PASS();
+}
+
+TEST(mcp_index_repository_declares_name_override_issue571) {
+ char *json = cbm_mcp_tools_list();
+ ASSERT_NOT_NULL(json);
+ ASSERT_NOT_NULL(strstr(json, "\"index_repository\""));
+ ASSERT_NOT_NULL(strstr(json, "\"name\":{\"type\":\"string\""));
- ASSERT_NOT_NULL(strstr(json, "Override the derived project name"));
++ ASSERT_NOT_NULL(strstr(json, "Non-ASCII bytes are encoded"));
+ free(json);
+ PASS();
+}
+
TEST(mcp_tools_array_schemas_have_items) {
/* VS Code 1.112+ rejects array schemas without "items" (see
* https://github.com/microsoft/vscode/issues/248810).