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:1871–1943  ·  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

1869 * one is spawned for this command — with a hint that `daemon start` removes
1870 * that per-command cost. Only supervised index workers stay in-process. */
1871static char *main_local_cli_daemon_execute(const char *tool_name, const char *args_json,
1872 bool quiet_requested) {
1873 cbm_daemon_ipc_endpoint_t *endpoint = main_daemon_endpoint_new();
1874 char executable_path[MAIN_PATH_CAP] = {0};
1875 cbm_daemon_build_identity_t identity;
1876 bool prepared =
1877 endpoint &&
1878 cbm_http_server_resolve_binary_path(NULL, executable_path, sizeof(executable_path)) &&
1879 main_build_identity(&identity) == MAIN_BUILD_IDENTITY_OK;
1880 if (!prepared) {
1881 (void)fprintf(stderr, "error: daemon-backed CLI coordination could not be prepared\n");
1882 cbm_daemon_ipc_endpoint_free(endpoint);
1883 return NULL;
1884 }
1885 cbm_daemon_bootstrap_config_t config = {
1886 .role = CBM_DAEMON_PROCESS_MCP_CLIENT,
1887 .endpoint = endpoint,
1888 .identity = &identity,
1889 .executable_path = executable_path,
1890 .connect_timeout_ms = MAIN_CONNECT_TIMEOUT_MS,
1891 .startup_timeout_ms = main_startup_timeout_ms(),
1892 };
1893 cbm_daemon_bootstrap_result_t bootstrap;
1894 cbm_daemon_bootstrap_status_t status =
1895 main_client_bootstrap_with_upgrade(&config, &bootstrap, !quiet_requested);
1896 cbm_daemon_ipc_endpoint_free(endpoint);
1897 if (status != CBM_DAEMON_BOOTSTRAP_CONNECTED || !bootstrap.client) {
1898 (void)fprintf(stderr, "error: %s\n",
1899 bootstrap.message[0] ? bootstrap.message
1900 : "no CBM daemon connection for CLI execution");
1901 if (bootstrap.remedy[0]) {
1902 (void)fprintf(stderr, "hint: %s\n", bootstrap.remedy);
1903 }
1904 return NULL;
1905 }
1906 if (bootstrap.daemon_spawned && cbm_log_get_level() <= CBM_LOG_INFO) {
1907 /* Routine cold-start advice is informational. Default one-shot CLI
1908 * output stays pipe-clean; `cli --verbose ...` (or CBM_LOG_LEVEL=info)
1909 * opts into this detail. It is advice for a person, so it is a plain
1910 * stderr line rather than a structured record whose value escaping
1911 * would turn `daemon start` into `daemon_start`. */
1912 (void)fprintf(stderr, "hint: this command started a temporary CBM daemon. "
1913 "`codebase-memory-mcp daemon start` keeps one warm and removes this "
1914 "startup cost from every CLI command.\n");
1915 }
1916 char session_root[MAIN_PATH_CAP];
1917 char allowed_root[MAIN_PATH_CAP];
1918 const char *allowed_root_ptr = NULL;
1919 char *result = NULL;
1920 uint8_t *response = NULL;
1921 uint32_t response_length = 0;
1922 bool context_ok =
1923 main_session_context(NULL, session_root, allowed_root, &allowed_root_ptr) &&
1924 main_set_client_context(bootstrap.client, session_root, CBM_MCP_TOOL_PROFILE_ALL, NULL,
1925 NULL, MAIN_CONNECT_TIMEOUT_MS);
1926 if (context_ok &&
1927 cbm_daemon_application_client_tool(bootstrap.client, tool_name, args_json, &response,
1928 &response_length, MAIN_REQUEST_TIMEOUT_MS) ==

Callers 1

run_cliFunction · 0.85

Tested by

no test coverage detected