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

Function detect_session

src/mcp/mcp.c:17399–17426  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

17397
17398/* Detect session root from CWD (fallback: single indexed project from DB). */
17399static void detect_session(cbm_mcp_server_t *srv) {
17400 if (srv->session_detected) {
17401 return;
17402 }
17403 srv->session_detected = true;
17404
17405 /* 1. Try CWD */
17406 char cwd[CBM_SZ_1K];
17407 if (getcwd(cwd, sizeof(cwd)) != NULL) {
17408 const char *home = cbm_get_home_dir();
17409 /* Skip useless roots: / and $HOME */
17410 if (strcmp(cwd, "/") != 0 && (home == NULL || strcmp(cwd, home) != 0)) {
17411 snprintf(srv->session_root, sizeof(srv->session_root), "%s", cwd);
17412 cbm_log_info("session.root.cwd", "path", cwd);
17413 }
17414 }
17415
17416 /* Derive project name from path — must match cbm_project_name_from_path
17417 * used by the pipeline, otherwise session queries look for a .db file
17418 * that doesn't match the indexed project name. */
17419 if (srv->session_root[0]) {
17420 char *pname = cbm_project_name_from_path(srv->session_root);
17421 if (pname) {
17422 snprintf(srv->session_project, sizeof(srv->session_project), "%s", pname);
17423 free(pname);
17424 }
17425 }
17426}
17427
17428/* auto_watch config: gates background watcher registration (default on).
17429 * 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