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

Function build_project_json_entry

src/mcp/mcp.c:2499–2555  ·  view source on GitHub ↗

Open a .db file briefly, collect node/edge counts and root_path, * then append a JSON entry to arr. */

Source from the content-addressed store, hash-verified

2497/* Open a .db file briefly, collect node/edge counts and root_path,
2498 * then append a JSON entry to arr. */
2499static void build_project_json_entry(yyjson_mut_doc *doc, yyjson_mut_val *arr, const char *dir_path,
2500 const char *name, size_t name_len, int64_t size_bytes,
2501 bool metadata_only) {
2502 (void)name_len;
2503
2504 char full_path[CBM_SZ_2K];
2505 snprintf(full_path, sizeof(full_path), "%s/%s", dir_path, name);
2506
2507 /* #704: key on the db's INTERNAL project name, not its filename. Node/edge
2508 * rows are tagged with the internal name, so a drifted filename (copied or
2509 * renamed db, legacy '.'-vs-'-' username twin) would otherwise report 0
2510 * nodes/edges and be unresolvable. Skip ghost/empty/corrupt dbs entirely so
2511 * they don't appear as resolvable projects. */
2512 char project_name[CBM_SZ_1K];
2513 cbm_store_t *pstore = NULL;
2514 if (!db_internal_project_name(full_path, project_name, sizeof(project_name), &pstore)) {
2515 return; /* ghost / unreadable — not a resolvable project */
2516 }
2517
2518 int nodes = 0;
2519 int edges = 0;
2520 if (!metadata_only) {
2521 nodes = cbm_store_count_nodes(pstore, project_name);
2522 edges = cbm_store_count_edges(pstore, project_name);
2523 }
2524 char root_path_buf[CBM_SZ_1K] = "";
2525 cbm_project_t proj = {0};
2526 if (cbm_store_get_project(pstore, project_name, &proj) == CBM_STORE_OK) {
2527 if (proj.root_path) {
2528 snprintf(root_path_buf, sizeof(root_path_buf), "%s", proj.root_path);
2529 }
2530 cbm_project_free_fields(&proj);
2531 }
2532 cbm_store_close(pstore);
2533
2534 yyjson_mut_val *p = yyjson_mut_obj(doc);
2535 yyjson_mut_obj_add_strcpy(doc, p, "name", project_name);
2536 yyjson_mut_obj_add_strcpy(doc, p, "root_path", root_path_buf);
2537 /* Listing stays lean: only the branch (the one git fact that
2538 * disambiguates same-repo projects). The 12-field git block — mostly
2539 * null for non-git roots — cost ~10KB across a full cache and is one
2540 * index_status call away for the project you actually care about. */
2541 if (!metadata_only && root_path_buf[0]) {
2542 cbm_git_context_t gctx = {0};
2543 (void)cbm_git_context_resolve(root_path_buf, &gctx);
2544 if (gctx.is_git && gctx.branch) {
2545 yyjson_mut_obj_add_strcpy(doc, p, "branch", gctx.branch);
2546 }
2547 cbm_git_context_free(&gctx);
2548 }
2549 if (!metadata_only) {
2550 yyjson_mut_obj_add_int(doc, p, "nodes", nodes);
2551 yyjson_mut_obj_add_int(doc, p, "edges", edges);
2552 yyjson_mut_obj_add_int(doc, p, "size_bytes", size_bytes);
2553 }
2554 yyjson_mut_arr_add_val(arr, p);
2555}
2556

Callers 1

handle_list_projectsFunction · 0.85

Calls 8

db_internal_project_nameFunction · 0.85
cbm_store_count_nodesFunction · 0.85
cbm_store_count_edgesFunction · 0.85
cbm_store_get_projectFunction · 0.85
cbm_project_free_fieldsFunction · 0.85
cbm_store_closeFunction · 0.85
cbm_git_context_resolveFunction · 0.85
cbm_git_context_freeFunction · 0.85

Tested by

no test coverage detected