MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / detect_session

Function detect_session

src/mcp/mcp.c:11465–11492  ·  view source on GitHub ↗

Detect session root from CWD (fallback: single indexed project from DB). */

Source from the content-addressed store, hash-verified

11463
11464/* Detect session root from CWD (fallback: single indexed project from DB). */
11465static void detect_session(cbm_mcp_server_t *srv) {
11466 if (srv->session_detected) {
11467 return;
11468 }
11469 srv->session_detected = true;
11470
11471 /* 1. Try CWD */
11472 char cwd[CBM_SZ_1K];
11473 if (getcwd(cwd, sizeof(cwd)) != NULL) {
11474 const char *home = cbm_get_home_dir();
11475 /* Skip useless roots: / and $HOME */
11476 if (strcmp(cwd, "/") != 0 && (home == NULL || strcmp(cwd, home) != 0)) {
11477 snprintf(srv->session_root, sizeof(srv->session_root), "%s", cwd);
11478 cbm_log_info("session.root.cwd", "path", cwd);
11479 }
11480 }
11481
11482 /* Derive project name from path — must match cbm_project_name_from_path
11483 * used by the pipeline, otherwise session queries look for a .db file
11484 * that doesn't match the indexed project name. */
11485 if (srv->session_root[0]) {
11486 char *pname = cbm_project_name_from_path(srv->session_root);
11487 if (pname) {
11488 snprintf(srv->session_project, sizeof(srv->session_project), "%s", pname);
11489 free(pname);
11490 }
11491 }
11492}
11493
11494/* auto_watch config: gates background watcher registration (default on).
11495 * Multi-project users can contain a session to its own project with

Callers 1

cbm_mcp_server_handleFunction · 0.85

Calls 2

cbm_get_home_dirFunction · 0.85

Tested by

no test coverage detected