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

Function main_local_cli_daemon_execute

src/main.c:1524–1586  ·  view source on GitHub ↗

One-shot CLI commands execute through the shared daemon, exactly like MCP * sessions and hooks: an active daemon (any starter) is recycled, an absent * one is spawned for this command — with a hint that `daemon start` removes * that per-command cost. Only supervised index workers stay in-process. */

Source from the content-addressed store, hash-verified

1522 * one is spawned for this command — with a hint that `daemon start` removes
1523 * that per-command cost. Only supervised index workers stay in-process. */
1524static char *main_local_cli_daemon_execute(const char *tool_name, const char *args_json) {
1525 cbm_daemon_ipc_endpoint_t *endpoint = cbm_daemon_bootstrap_endpoint_new(NULL);
1526 char executable_path[MAIN_PATH_CAP] = {0};
1527 cbm_daemon_build_identity_t identity;
1528 bool prepared =
1529 endpoint &&
1530 cbm_http_server_resolve_binary_path(NULL, executable_path, sizeof(executable_path)) &&
1531 main_build_identity(&identity) == MAIN_BUILD_IDENTITY_OK;
1532 if (!prepared) {
1533 (void)fprintf(stderr, "error: daemon-backed CLI coordination could not be prepared\n");
1534 cbm_daemon_ipc_endpoint_free(endpoint);
1535 return NULL;
1536 }
1537 cbm_daemon_bootstrap_config_t config = {
1538 .role = CBM_DAEMON_PROCESS_MCP_CLIENT,
1539 .endpoint = endpoint,
1540 .identity = &identity,
1541 .executable_path = executable_path,
1542 .connect_timeout_ms = MAIN_CONNECT_TIMEOUT_MS,
1543 .startup_timeout_ms = MAIN_MCP_STARTUP_TIMEOUT_MS,
1544 };
1545 cbm_daemon_bootstrap_result_t bootstrap;
1546 cbm_daemon_bootstrap_status_t status = main_client_bootstrap_with_upgrade(&config, &bootstrap);
1547 cbm_daemon_ipc_endpoint_free(endpoint);
1548 if (status != CBM_DAEMON_BOOTSTRAP_CONNECTED || !bootstrap.client) {
1549 (void)fprintf(stderr, "error: %s\n",
1550 bootstrap.message[0] ? bootstrap.message
1551 : "no CBM daemon connection for CLI execution");
1552 return NULL;
1553 }
1554 if (bootstrap.daemon_spawned) {
1555 (void)fprintf(stderr, "hint: this command started a temporary CBM daemon. "
1556 "`codebase-memory-mcp daemon start` keeps one warm and removes this "
1557 "startup cost from every CLI command.\n");
1558 }
1559 char session_root[MAIN_PATH_CAP];
1560 char allowed_root[MAIN_PATH_CAP];
1561 const char *allowed_root_ptr = NULL;
1562 char *result = NULL;
1563 uint8_t *response = NULL;
1564 uint32_t response_length = 0;
1565 bool context_ok =
1566 main_session_context(NULL, session_root, allowed_root, &allowed_root_ptr) &&
1567 main_set_client_context(bootstrap.client, session_root, CBM_MCP_TOOL_PROFILE_ALL, NULL,
1568 NULL, MAIN_CONNECT_TIMEOUT_MS);
1569 if (context_ok &&
1570 cbm_daemon_application_client_tool(bootstrap.client, tool_name, args_json, &response,
1571 &response_length, MAIN_REQUEST_TIMEOUT_MS) ==
1572 CBM_DAEMON_RUNTIME_APPLICATION_OK &&
1573 response && response_length > 0) {
1574 result = malloc((size_t)response_length + 1U);
1575 if (result) {
1576 memcpy(result, response, response_length);
1577 result[response_length] = '\0';
1578 }
1579 }
1580 free(response);
1581 if (!result) {

Callers 1

run_cliFunction · 0.85

Tested by

no test coverage detected