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:1539–1601  ·  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

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

Callers 1

run_cliFunction · 0.85

Tested by

no test coverage detected