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

Function run_cli

src/main.c:664–887  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

662static char *main_local_cli_daemon_execute(const char *tool_name, const char *args_json);
663
664static int run_cli(int argc, char **argv, cbm_project_lock_manager_t *project_locks,
665 main_local_maintenance_context_t *maintenance_context) {
666 if (argc == 1 && argv && (strcmp(argv[0], "--help") == 0 || strcmp(argv[0], "-h") == 0)) {
667 (void)fputs(CLI_USAGE, stdout);
668 return 0;
669 }
670 if (argc < MAIN_MIN_ARGC) {
671 (void)fprintf(stderr, CLI_USAGE);
672 return SKIP_ONE;
673 }
674
675 bool progress_requested = cli_strip_flag(&argc, argv, "--progress");
676 bool raw_json = cli_strip_flag(&argc, argv, "--json");
677
678 /* Supervisor worker role: when this process was spawned as a supervised index
679 * worker, run indexing in-process (never re-supervise) and write the result to
680 * the given file for the parent to read back. Stripped here so the tool
681 * dispatch below sees only the tool name + its args. */
682 bool index_worker = cli_strip_flag(&argc, argv, "--index-worker");
683 (void)cli_strip_flag_value(&argc, argv, CBM_INDEX_WORKER_BUILD_ARG);
684 const char *response_out = cli_strip_flag_value(&argc, argv, "--response-out");
685 (void)cli_strip_flag_value(&argc, argv, CBM_INDEX_WORKER_MEMORY_BUDGET_ARG);
686 bool worker_single_thread = cli_strip_flag(&argc, argv, CBM_INDEX_WORKER_SINGLE_THREAD_ARG);
687 const char *worker_marker = cli_strip_flag_value(&argc, argv, CBM_INDEX_WORKER_MARKER_ARG);
688 const char *worker_quarantine =
689 cli_strip_flag_value(&argc, argv, CBM_INDEX_WORKER_QUARANTINE_ARG);
690 cbm_index_set_worker_role_options(index_worker, response_out, worker_single_thread,
691 worker_marker, worker_quarantine,
692 cbm_index_worker_memory_budget_bytes());
693
694 if (argc < MAIN_MIN_ARGC) {
695 (void)fprintf(stderr, CLI_USAGE);
696 return SKIP_ONE;
697 }
698
699 const char *tool_name = argv[0];
700 int rem_argc = argc - SKIP_ONE; /* args following the tool name */
701 char **rem_argv = argv + SKIP_ONE;
702
703 /* --help / -h : print per-tool help (from the tool's input_schema) and exit
704 * before any server work. */
705 for (int i = 0; i < rem_argc; i++) {
706 if (strcmp(rem_argv[i], "--help") == 0 || strcmp(rem_argv[i], "-h") == 0) {
707 if (cbm_cli_print_tool_help(tool_name) != 0) {
708 (void)fprintf(stderr, "error: unknown tool '%s'\n", tool_name);
709 return SKIP_ONE;
710 }
711 return 0;
712 }
713 }
714
715 /* Resolve the JSON arguments. Precedence: --args-file, then raw JSON
716 * (back-compat), then --flags, then piped stdin, then empty {}. */
717 char *heap_args = NULL; /* freed before return when set */
718 const char *args_json = "{}";
719
720 int args_file_idx = -1;
721 for (int i = 0; i < rem_argc; i++) {

Callers 1

handle_subcommandFunction · 0.70

Calls 15

cli_strip_flagFunction · 0.85
cli_strip_flag_valueFunction · 0.85
cbm_cli_print_tool_helpFunction · 0.85
cli_slurp_fileFunction · 0.85
cbm_cli_build_args_jsonFunction · 0.85
cli_slurp_streamFunction · 0.85
cbm_cli_progress_enabledFunction · 0.85
cbm_now_msFunction · 0.85

Tested by

no test coverage detected