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
Add configurable database directory via CBM_CACHE_DIR env var
Martin Vogele07443b75f05
diff --git a/src/cli/cli.c b/src/cli/cli.cindex 01f76bd64..4c2f7165d 100644--- a/src/cli/cli.c+++ b/src/cli/cli.c@@ -2094,7 +2094,7 @@ static const char *get_cache_dir(const char *home_dir) {if (!home_dir) {return NULL;}- snprintf(buf, sizeof(buf), "%s/.cache/codebase-memory-mcp", home_dir);+ snprintf(buf, sizeof(buf), "%s", cbm_resolve_cache_dir());return buf;}@@ -2320,7 +2320,7 @@ int cbm_cmd_config(int argc, char **argv) {}char cache_dir[CLI_BUF_1K];- snprintf(cache_dir, sizeof(cache_dir), "%s/.cache/codebase-memory-mcp", home);+ snprintf(cache_dir, sizeof(cache_dir), "%s", cbm_resolve_cache_dir());cbm_config_t *cfg = cbm_config_open(cache_dir);if (!cfg) {diff --git a/src/foundation/platform.c b/src/foundation/platform.cindex 5b2f56707..d9b7cbdf5 100644--- a/src/foundation/platform.c+++ b/src/foundation/platform.c@@ -354,3 +354,22 @@ const char *cbm_app_local_dir(void) {return cbm_app_config_dir();#endif}++/* ── Cache directory ─────────────────────────────────────────── */++const char *cbm_resolve_cache_dir(void) {+ static char buf[CBM_SZ_1K];+ char tmp[CBM_SZ_256] = "";+ cbm_safe_getenv("CBM_CACHE_DIR", tmp, sizeof(tmp), NULL);+ if (tmp[0]) {+ snprintf(buf, sizeof(buf), "%s", tmp);+ cbm_normalize_path_sep(buf);+ return buf;+ }+ const char *home = cbm_get_home_dir();+ if (!home) {+ return NULL;+ }+ snprintf(buf, sizeof(buf), "%s/.cache/codebase-memory-mcp", home);+ return buf;+}diff --git a/src/foundation/platform.h b/src/foundation/platform.hindex 99df10128..5624810c7 100644--- a/src/foundation/platform.h+++ b/src/foundation/platform.h@@ -93,6 +93,13 @@ const char *cbm_app_config_dir(void);* macOS/Linux: same as cbm_app_config_dir(). */const char *cbm_app_local_dir(void);+/* ── Cache directory ────────────────────────────────────────────── */++/* Resolve the database cache directory. All project indexes are stored here.+ * Priority: CBM_CACHE_DIR env var > ~/.cache/codebase-memory-mcp (default).+ * Returns static buffer or NULL if home is unavailable. */+const char *cbm_resolve_cache_dir(void);+/* ── File system ───────────────────────────────────────────────── *//* Check if a path exists. */diff --git a/src/main.c b/src/main.cindex a612d3f82..9a79d05e9 100644--- a/src/main.c+++ b/src/main.c@@ -294,7 +294,7 @@ int main(int argc, char **argv) {const char *cfg_home = cbm_get_home_dir();cbm_config_t *runtime_config = NULL;if (cfg_home) {- snprintf(config_dir, sizeof(config_dir), "%s/.cache/codebase-memory-mcp", cfg_home);+ snprintf(config_dir, sizeof(config_dir), "%s", cbm_resolve_cache_dir());runtime_config = cbm_config_open(config_dir);}diff --git a/src/mcp/mcp.c b/src/mcp/mcp.cindex 06735eac7..c4073e597 100644--- a/src/mcp/mcp.c+++ b/src/mcp/mcp.c@@ -646,14 +646,13 @@ bool cbm_mcp_server_has_cached_store(cbm_mcp_server_t *srv) {/* ── Cache dir + project DB path helpers ───────────────────────── */-/* Returns the platform cache directory: ~/.cache/codebase-memory-mcp- * Writes to buf, returns buf for convenience. */+/* Returns the cache directory. Writes to buf, returns buf for convenience. */static const char *cache_dir(char *buf, size_t bufsz) {- const char *home = cbm_get_home_dir();- if (!home) {- home = cbm_tmpdir();+ const char *dir = cbm_resolve_cache_dir();+ if (!dir) {+ dir = cbm_tmpdir();}- snprintf(buf, bufsz, "%s/.cache/codebase-memory-mcp", home);+ snprintf(buf, bufsz, "%s", dir);return buf;}@@ -3162,7 +3161,7 @@ static void maybe_auto_index(cbm_mcp_server_t *srv) {const char *home = cbm_get_home_dir();if (home) {char db_check[CBM_SZ_1K];- snprintf(db_check, sizeof(db_check), "%s/.cache/codebase-memory-mcp/%s.db", home,+ snprintf(db_check, sizeof(db_check), "%s/%s.db", cbm_resolve_cache_dir(),srv->session_project);struct stat st;if (stat(db_check, &st) == 0) {diff --git a/src/pipeline/pipeline.c b/src/pipeline/pipeline.cindex 02b99f1ca..b78322921 100644--- a/src/pipeline/pipeline.c+++ b/src/pipeline/pipeline.c@@ -166,11 +166,7 @@ static char *resolve_db_path(const cbm_pipeline_t *p) {if (p->db_path) {snprintf(path, 1024, "%s", p->db_path);} else {- const char *home = cbm_get_home_dir();- if (!home) {- home = cbm_tmpdir();- }- snprintf(path, 1024, "%s/.cache/codebase-memory-mcp/%s.db", home, p->project_name);+ snprintf(path, 1024, "%s/%s.db", cbm_resolve_cache_dir(), p->project_name);}return path;}@@ -595,16 +591,15 @@ static int64_t stat_mtime_ns(const struct stat *fst) {static int dump_and_persist_hashes(cbm_pipeline_t *p, const cbm_file_info_t *files, int file_count,struct timespec *t) {cbm_clock_gettime(CLOCK_MONOTONIC, t);- const char *home = cbm_get_home_dir();char db_path[CBM_SZ_1K];if (p->db_path) {snprintf(db_path, sizeof(db_path), "%s", p->db_path);} else {- if (!home) {- home = cbm_tmpdir();+ const char *cdir = cbm_resolve_cache_dir();+ if (!cdir) {+ cdir = cbm_tmpdir();}- snprintf(db_path, sizeof(db_path), "%s/.cache/codebase-memory-mcp/%s.db", home,- p->project_name);+ snprintf(db_path, sizeof(db_path), "%s/%s.db", cdir, p->project_name);}char db_dir[CBM_SZ_1K];snprintf(db_dir, sizeof(db_dir), "%s", db_path);diff --git a/src/store/store.c b/src/store/store.cindex ac9c347bb..4920732e8 100644--- a/src/store/store.c+++ b/src/store/store.c@@ -508,13 +508,12 @@ cbm_store_t *cbm_store_open(const char *project) {if (!project) {return NULL;}- /* Build path: ~/.cache/codebase-memory-mcp/<project>.db */- const char *home = cbm_get_home_dir();- if (!home) {- home = cbm_tmpdir();+ const char *cdir = cbm_resolve_cache_dir();+ if (!cdir) {+ cdir = cbm_tmpdir();}char path[CBM_SZ_1K];- snprintf(path, sizeof(path), "%s/.cache/codebase-memory-mcp/%s.db", home, project);+ snprintf(path, sizeof(path), "%s/%s.db", cdir, project);return store_open_internal(path, false);}@@ -2121,11 +2120,12 @@ int cbm_store_search(cbm_store_t *s, const cbm_search_params_t *params, cbm_searchar count_sql[CBM_SZ_4K];int bind_idx = 0;- const char *select_cols =- "SELECT n.id, n.project, n.label, n.name, n.qualified_name, "- "n.file_path, n.start_line, n.end_line, n.properties, "- "(SELECT COUNT(*) FROM edges e WHERE e.target_id = n.id AND e.type = 'CALLS') AS in_deg, "- "(SELECT COUNT(*) FROM edges e WHERE e.source_id = n.id AND e.type = 'CALLS') AS out_deg ";+ const char *select_cols = "SELECT n.id, n.project, n.label, n.name, n.qualified_name, "+ "n.file_path, n.start_line, n.end_line, n.properties, "+ "(SELECT COUNT(*) FROM edges e WHERE e.target_id = n.id AND "+ "e.type = 'CALLS') AS in_deg, "+ "(SELECT COUNT(*) FROM edges e WHERE e.source_id = n.id AND "+ "e.type = 'CALLS') AS out_deg ";char where[CBM_SZ_2K] = "";search_bind_t binds[ST_SEARCH_MAX_BINDS];@@ -4324,8 +4324,8 @@ int cbm_store_adr_store(cbm_store_t *s, const char *project, const char *content}int cbm_store_adr_get(cbm_store_t *s, const char *project, cbm_adr_t *out) {- const char *sql =- "SELECT project, summary, created_at, updated_at FROM project_summaries WHERE project=?1";+ const char *sql = "SELECT project, summary, created_at, updated_at FROM project_summaries "+ "WHERE project=?1";sqlite3_stmt *stmt = NULL;if (sqlite3_prepare_v2(s->db, sql, CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) {store_set_error_sqlite(s, "adr_get");diff --git a/src/ui/config.c b/src/ui/config.cindex 8e41027c8..678c3fada 100644--- a/src/ui/config.c+++ b/src/ui/config.c@@ -21,11 +21,11 @@/* ── Path ────────────────────────────────────────────────────── */void cbm_ui_config_path(char *buf, int bufsz) {- const char *home = cbm_get_home_dir();- if (!home) {- home = cbm_tmpdir();+ const char *dir = cbm_resolve_cache_dir();+ if (!dir) {+ dir = cbm_tmpdir();}- snprintf(buf, (size_t)bufsz, "%s/.cache/codebase-memory-mcp/config.json", home);+ snprintf(buf, (size_t)bufsz, "%s/config.json", dir);}/* ── Load ────────────────────────────────────────────────────── */diff --git a/src/ui/http_server.c b/src/ui/http_server.cindex 5a07d24bb..053f317ba 100644--- a/src/ui/http_server.c+++ b/src/ui/http_server.c@@ -72,8 +72,7 @@ static void update_cors(struct mg_http_message *hm) {"Access-Control-Allow-Methods: POST, GET, DELETE, OPTIONS\r\n""Access-Control-Allow-Headers: Content-Type\r\n");}- snprintf(g_cors_json, sizeof(g_cors_json),- "%sContent-Type: application/json\r\n", g_cors);+ snprintf(g_cors_json, sizeof(g_cors_json), "%sContent-Type: application/json\r\n", g_cors);}/* ── Server state ─────────────────────────────────────────────── */@@ -123,6 +122,15 @@ static bool serve_embedded(struct mg_connection *c, const char *path) {/* Forward declaration */static bool get_query_param(struct mg_str query, const char *name, char *buf, int bufsz);+/* Build DB path for a project: <cache_dir>/<project>.db */+static void db_path_for_project(const char *project, char *buf, size_t bufsz) {+ const char *dir = cbm_resolve_cache_dir();+ if (!dir) {+ dir = cbm_tmpdir();+ }+ snprintf(buf, bufsz, "%s/%s.db", dir, project);+}+/* ── Log ring buffer ──────────────────────────────────────────── */#define LOG_RING_SIZE 500@@ -291,8 +299,7 @@ static void handle_processes(struct mg_connection *c) {/* POST /api/process-kill — kill a process by PID */static void handle_process_kill(struct mg_connection *c, struct mg_http_message *hm) {if (hm->body.len == 0 || hm->body.len > 256) {- mg_http_reply(c, 400, g_cors_json,- "{\"error\":\"invalid body\"}");+ mg_http_reply(c, 400, g_cors_json, "{\"error\":\"invalid body\"}");return;}@@ -302,16 +309,14 @@ static void handle_process_kill(struct mg_connection *c, struct mg_http_messageyyjson_doc *doc = yyjson_read(body, hm->body.len, 0);if (!doc) {- mg_http_reply(c, 400, g_cors_json,- "{\"error\":\"invalid json\"}");+ mg_http_reply(c, 400, g_cors_json, "{\"error\":\"invalid json\"}");return;}yyjson_val *root = yyjson_doc_get_root(doc);yyjson_val *v_pid = yyjson_obj_get(root, "pid");if (!v_pid || !yyjson_is_int(v_pid)) {yyjson_doc_free(doc);- mg_http_reply(c, 400, g_cors_json,- "{\"error\":\"missing pid\"}");+ mg_http_reply(c, 400, g_cors_json, "{\"error\":\"missing pid\"}");return;}int target_pid = (int)yyjson_get_int(v_pid);@@ -351,21 +356,18 @@ static void handle_process_kill(struct mg_connection *c, struct mg_http_messageif (!hproc || !TerminateProcess(hproc, 1)) {if (hproc)CloseHandle(hproc);- mg_http_reply(c, 500, g_cors_json,- "{\"error\":\"kill failed\"}");+ mg_http_reply(c, 500, g_cors_json, "{\"error\":\"kill failed\"}");return;}CloseHandle(hproc);#elseif (kill(target_pid, SIGTERM) != 0) {- mg_http_reply(c, 500, g_cors_json,- "{\"error\":\"kill failed\"}");+ mg_http_reply(c, 500, g_cors_json, "{\"error\":\"kill failed\"}");return;}#endif- mg_http_reply(c, 200, g_cors_json, "{\"killed\":%d}",- target_pid);+ mg_http_reply(c, 200, g_cors_json, "{\"killed\":%d}", target_pid);}/* ── Directory browser ────────────────────────────────────────── */@@ -375,9 +377,9 @@ static void handle_process_kill(struct mg_connection *c, struct mg_http_message/* GET /api/browse?path=/some/dir — list subdirectories for file picker */static void handle_browse(struct mg_connection *c, struct mg_http_message *hm) {char path[1024] = {0};+ const char *home = cbm_get_home_dir();if (!get_query_param(hm->query, "path", path, (int)sizeof(path)) || path[0] == '\0') {/* Default to home directory */- const char *home = cbm_get_home_dir();if (home)snprintf(path, sizeof(path), "%s", home);else@@ -385,15 +387,13 @@ static void handle_browse(struct mg_connection *c, struct mg_http_message *hm) {}if (!cbm_is_dir(path)) {- mg_http_reply(c, 400, g_cors_json,- "{\"error\":\"not a directory\"}");+ mg_http_reply(c, 400, g_cors_json, "{\"error\":\"not a directory\"}");return;}DIR *dir = opendir(path);if (!dir) {- mg_http_reply(c, 403, g_cors_json,- "{\"error\":\"cannot open directory\"}");+ mg_http_reply(c, 403, g_cors_json, "{\"error\":\"cannot open directory\"}");return;}@@ -447,21 +447,16 @@ static void handle_browse(struct mg_connection *c, struct mg_http_message *hm) {static void handle_adr_get(struct mg_connection *c, struct mg_http_message *hm) {char name[256] = {0};if (!get_query_param(hm->query, "project", name, (int)sizeof(name)) || name[0] == '\0') {- mg_http_reply(c, 400, g_cors_json,- "{\"error\":\"missing project\"}");+ mg_http_reply(c, 400, g_cors_json, "{\"error\":\"missing project\"}");return;}- const char *home = cbm_get_home_dir();- if (!home)- home = cbm_tmpdir();char db_path[1024];- snprintf(db_path, sizeof(db_path), "%s/.cache/codebase-memory-mcp/%s.db", home, name);+ db_path_for_project(name, db_path, sizeof(db_path));cbm_store_t *store = cbm_store_open_path(db_path);if (!store) {- mg_http_reply(c, 200, g_cors_json,- "{\"has_adr\":false}");+ mg_http_reply(c, 200, g_cors_json, "{\"has_adr\":false}");return;}@@ -502,8 +497,7 @@ static void handle_adr_get(struct mg_connection *c, struct mg_http_message *hm)}cbm_store_adr_free(&adr);} else {- mg_http_reply(c, 200, g_cors_json,- "{\"has_adr\":false}");+ mg_http_reply(c, 200, g_cors_json, "{\"has_adr\":false}");}cbm_store_close(store);}@@ -511,8 +505,7 @@ static void handle_adr_get(struct mg_connection *c, struct mg_http_message *hm)/* POST /api/adr — save ADR content. Body: {"project":"...","content":"..."} */static void handle_adr_save(struct mg_connection *c, struct mg_http_message *hm) {if (hm->body.len == 0 || hm->body.len > 16384) {- mg_http_reply(c, 400, g_cors_json,- "{\"error\":\"invalid body\"}");+ mg_http_reply(c, 400, g_cors_json, "{\"error\":\"invalid body\"}");return;}@@ -527,8 +520,7 @@ static void handle_adr_save(struct mg_connection *c, struct mg_http_message *hm)yyjson_doc *doc = yyjson_read(body, hm->body.len, 0);free(body);if (!doc) {- mg_http_reply(c, 400, g_cors_json,- "{\"error\":\"invalid json\"}");+ mg_http_reply(c, 400, g_cors_json, "{\"error\":\"invalid json\"}");return;}@@ -537,25 +529,20 @@ static void handle_adr_save(struct mg_connection *c, struct mg_http_message *hm)yyjson_val *v_content = yyjson_obj_get(root, "content");if (!v_proj || !yyjson_is_str(v_proj) || !v_content || !yyjson_is_str(v_content)) {yyjson_doc_free(doc);- mg_http_reply(c, 400, g_cors_json,- "{\"error\":\"missing project or content\"}");+ mg_http_reply(c, 400, g_cors_json, "{\"error\":\"missing project or content\"}");return;}const char *proj = yyjson_get_str(v_proj);const char *content = yyjson_get_str(v_content);- const char *home = cbm_get_home_dir();- if (!home)- home = cbm_tmpdir();char db_path[1024];- snprintf(db_path, sizeof(db_path), "%s/.cache/codebase-memory-mcp/%s.db", home, proj);+ db_path_for_project(proj, db_path, sizeof(db_path));cbm_store_t *store = cbm_store_open_path(db_path);yyjson_doc_free(doc);if (!store) {- mg_http_reply(c, 500, g_cors_json,- "{\"error\":\"cannot open store\"}");+ mg_http_reply(c, 500, g_cors_json, "{\"error\":\"cannot open store\"}");return;}@@ -563,11 +550,9 @@ static void handle_adr_save(struct mg_connection *c, struct mg_http_message *hm)cbm_store_close(store);if (rc == CBM_STORE_OK) {- mg_http_reply(c, 200, g_cors_json,- "{\"saved\":true}");+ mg_http_reply(c, 200, g_cors_json, "{\"saved\":true}");} else {- mg_http_reply(c, 500, g_cors_json,- "{\"error\":\"save failed\"}");+ mg_http_reply(c, 500, g_cors_json, "{\"error\":\"save failed\"}");}}@@ -748,8 +733,7 @@ static void *index_thread_fn(void *arg) {/* POST /api/index — body: {"root_path": "/abs/path"} → starts background indexing */static void handle_index_start(struct mg_connection *c, struct mg_http_message *hm) {if (hm->body.len == 0 || hm->body.len > 4096) {- mg_http_reply(c, 400, g_cors_json,- "{\"error\":\"invalid body\"}");+ mg_http_reply(c, 400, g_cors_json, "{\"error\":\"invalid body\"}");return;}@@ -759,16 +743,14 @@ static void handle_index_start(struct mg_connection *c, struct mg_http_message *yyjson_doc *doc = yyjson_read(body_buf, hm->body.len, 0);if (!doc) {- mg_http_reply(c, 400, g_cors_json,- "{\"error\":\"invalid json\"}");+ mg_http_reply(c, 400, g_cors_json, "{\"error\":\"invalid json\"}");return;}yyjson_val *root = yyjson_doc_get_root(doc);yyjson_val *v_path = yyjson_obj_get(root, "root_path");if (!v_path || !yyjson_is_str(v_path)) {yyjson_doc_free(doc);- mg_http_reply(c, 400, g_cors_json,- "{\"error\":\"missing root_path\"}");+ mg_http_reply(c, 400, g_cors_json, "{\"error\":\"missing root_path\"}");return;}const char *rpath = yyjson_get_str(v_path);@@ -776,8 +758,7 @@ static void handle_index_start(struct mg_connection *c, struct mg_http_message */* Check path exists */if (!cbm_is_dir(rpath)) {yyjson_doc_free(doc);- mg_http_reply(c, 400, g_cors_json,- "{\"error\":\"directory not found\"}");+ mg_http_reply(c, 400, g_cors_json, "{\"error\":\"directory not found\"}");return;}@@ -792,8 +773,7 @@ static void handle_index_start(struct mg_connection *c, struct mg_http_message *}if (slot < 0) {yyjson_doc_free(doc);- mg_http_reply(c, 429, g_cors_json,- "{\"error\":\"all index slots busy\"}");+ mg_http_reply(c, 429, g_cors_json, "{\"error\":\"all index slots busy\"}");return;}@@ -808,13 +788,12 @@ static void handle_index_start(struct mg_connection *c, struct mg_http_message *if (cbm_thread_create(&tid, 0, index_thread_fn, job) != 0) {atomic_store(&job->status, 3);snprintf(job->error_msg, sizeof(job->error_msg), "thread creation failed");- mg_http_reply(c, 500, g_cors_json,- "{\"error\":\"thread creation failed\"}");+ mg_http_reply(c, 500, g_cors_json, "{\"error\":\"thread creation failed\"}");return;}- mg_http_reply(c, 202, g_cors_json,- "{\"status\":\"indexing\",\"slot\":%d,\"path\":\"%s\"}", slot, job->root_path);+ mg_http_reply(c, 202, g_cors_json, "{\"status\":\"indexing\",\"slot\":%d,\"path\":\"%s\"}",+ slot, job->root_path);}/* GET /api/index-status — returns status of all index jobs */@@ -841,26 +820,20 @@ static void handle_index_status(struct mg_connection *c) {static void handle_delete_project(struct mg_connection *c, struct mg_http_message *hm) {char name[256] = {0};if (!get_query_param(hm->query, "name", name, (int)sizeof(name)) || name[0] == '\0') {- mg_http_reply(c, 400, g_cors_json,- "{\"error\":\"missing name\"}");+ mg_http_reply(c, 400, g_cors_json, "{\"error\":\"missing name\"}");return;}- const char *home = cbm_get_home_dir();- if (!home)- home = cbm_tmpdir();char db_path[1024];- snprintf(db_path, sizeof(db_path), "%s/.cache/codebase-memory-mcp/%s.db", home, name);+ db_path_for_project(name, db_path, sizeof(db_path));if (!cbm_file_exists(db_path)) {- mg_http_reply(c, 404, g_cors_json,- "{\"error\":\"project not found\"}");+ mg_http_reply(c, 404, g_cors_json, "{\"error\":\"project not found\"}");return;}if (unlink(db_path) != 0) {- mg_http_reply(c, 500, g_cors_json,- "{\"error\":\"failed to delete\"}");+ mg_http_reply(c, 500, g_cors_json, "{\"error\":\"failed to delete\"}");return;}@@ -879,27 +852,21 @@ static void handle_delete_project(struct mg_connection *c, struct mg_http_messagstatic void handle_project_health(struct mg_connection *c, struct mg_http_message *hm) {char name[256] = {0};if (!get_query_param(hm->query, "name", name, (int)sizeof(name)) || name[0] == '\0') {- mg_http_reply(c, 400, g_cors_json,- "{\"error\":\"missing name\"}");+ mg_http_reply(c, 400, g_cors_json, "{\"error\":\"missing name\"}");return;}- const char *home = cbm_get_home_dir();- if (!home)- home = cbm_tmpdir();char db_path[1024];- snprintf(db_path, sizeof(db_path), "%s/.cache/codebase-memory-mcp/%s.db", home, name);+ db_path_for_project(name, db_path, sizeof(db_path));if (!cbm_file_exists(db_path)) {- mg_http_reply(c, 200, g_cors_json,- "{\"status\":\"missing\"}");+ mg_http_reply(c, 200, g_cors_json, "{\"status\":\"missing\"}");return;}cbm_store_t *store = cbm_store_open_path(db_path);if (!store) {- mg_http_reply(c, 200, g_cors_json,- "{\"status\":\"corrupt\",\"reason\":\"cannot open\"}");+ mg_http_reply(c, 200, g_cors_json, "{\"status\":\"corrupt\",\"reason\":\"cannot open\"}");return;}@@ -929,8 +896,7 @@ static void handle_layout(struct mg_connection *c, struct mg_http_message *hm) {if (!get_query_param(hm->query, "project", project, (int)sizeof(project)) ||project[0] == '\0') {- mg_http_reply(c, 400, g_cors_json,- "{\"error\":\"missing project parameter\"}");+ mg_http_reply(c, 400, g_cors_json, "{\"error\":\"missing project parameter\"}");return;}@@ -942,22 +908,17 @@ static void handle_layout(struct mg_connection *c, struct mg_http_message *hm) {}/* Open a read-only store for this project */- const char *home = cbm_get_home_dir();- if (!home)- home = cbm_tmpdir();char db_path[1024];- snprintf(db_path, sizeof(db_path), "%s/.cache/codebase-memory-mcp/%s.db", home, project);+ db_path_for_project(project, db_path, sizeof(db_path));if (!cbm_file_exists(db_path)) {- mg_http_reply(c, 404, g_cors_json,- "{\"error\":\"project not found\"}");+ mg_http_reply(c, 404, g_cors_json, "{\"error\":\"project not found\"}");return;}cbm_store_t *store = cbm_store_open_path(db_path);if (!store) {- mg_http_reply(c, 500, g_cors_json,- "{\"error\":\"cannot open store\"}");+ mg_http_reply(c, 500, g_cors_json, "{\"error\":\"cannot open store\"}");return;}@@ -966,8 +927,7 @@ static void handle_layout(struct mg_connection *c, struct mg_http_message *hm) {cbm_store_close(store);if (!layout) {- mg_http_reply(c, 500, g_cors_json,- "{\"error\":\"layout computation failed\"}");+ mg_http_reply(c, 500, g_cors_json, "{\"error\":\"layout computation failed\"}");return;}@@ -975,8 +935,7 @@ static void handle_layout(struct mg_connection *c, struct mg_http_message *hm) {cbm_layout_free(layout);if (!json) {- mg_http_reply(c, 500, g_cors_json,- "{\"error\":\"JSON serialization failed\"}");+ mg_http_reply(c, 500, g_cors_json, "{\"error\":\"JSON serialization failed\"}");return;}@@ -1028,7 +987,7 @@ static void http_handler(struct mg_connection *c, int ev, void *ev_data) {/* OPTIONS preflight for CORS */if (mg_strcmp(hm->method, mg_str("OPTIONS")) == 0) {- char opt_hdrs[512];+ char opt_hdrs[512];snprintf(opt_hdrs, sizeof(opt_hdrs), "%sContent-Length: 0\r\n", g_cors);mg_http_reply(c, 204, opt_hdrs, "");return;