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

Function cbm_daemon_process_role

src/daemon/bootstrap.c:147–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145}
146
147cbm_daemon_process_role_t cbm_daemon_process_role(int argc, char *const argv[]) {
148 if (argc <= 0 || !argv || !argv[0] || argv[0][0] == '\0') {
149 return CBM_DAEMON_PROCESS_INVALID;
150 }
151
152 int daemon_arg = bootstrap_find_arg(argc, argv, CBM_DAEMON_INTERNAL_ARG);
153 if (daemon_arg >= 0) {
154 /* Byte-exact daemon-role grammar, deliberately unforgiving: the bare
155 * internal marker, or the marker followed by exactly the permanent
156 * flag. Every other shape — reordered, repeated, or extended — is
157 * INVALID, so argv smuggling cannot reach the daemon role. */
158 if (argc == 2 && daemon_arg == 1) {
159 return CBM_DAEMON_PROCESS_DAEMON;
160 }
161 if (argc == 3 && daemon_arg == 1 && bootstrap_arg_is(argv[2], CBM_DAEMON_PERMANENT_ARG)) {
162 return CBM_DAEMON_PROCESS_DAEMON;
163 }
164 return CBM_DAEMON_PROCESS_INVALID;
165 }
166
167 int worker_arg = bootstrap_find_arg(argc, argv, "--index-worker");
168 if (worker_arg >= 0) {
169 return bootstrap_worker_argv_exact(argc, argv) ? CBM_DAEMON_PROCESS_WORKER
170 : CBM_DAEMON_PROCESS_INVALID;
171 }
172
173 static const char *const stateless_commands[] = {
174 "install",
175 "uninstall",
176 "update",
177 /* allow-root writes one line of user-level config and reads nothing from a
178 * project, so it needs no daemon. Listed here rather than routed through
179 * the daemon so enrolling a root cannot depend on daemon state. */
180 "allow-root",
181 /* test-impact runs its own frozen index of a pinned tree in process
182 * (CI: publish the team artifact, select tests); it never reads or
183 * writes the daemon's projects, so it needs no daemon. */
184 "test-impact",
185 };
186 /* Stop at the first top-level mode token. Tool names, flag values, and JSON
187 * following `cli` are opaque user input: a search query named "install"
188 * or containing "--version" must never bypass the mandatory daemon. */
189 for (int arg = 1; arg < argc; arg++) {
190 if (bootstrap_arg_is(argv[arg], "cli")) {
191 if (bootstrap_has_help_after(argc, argv, arg + 1)) {
192 return CBM_DAEMON_PROCESS_STATELESS;
193 }
194 return CBM_DAEMON_PROCESS_LOCAL_CLI;
195 }
196 if (bootstrap_arg_is(argv[arg], "hook-augment")) {
197 return CBM_DAEMON_PROCESS_HOOK_CLIENT;
198 }
199 if (bootstrap_arg_is(argv[arg], "config")) {
200 return bootstrap_has_help_after(argc, argv, arg + 1) ? CBM_DAEMON_PROCESS_STATELESS
201 : CBM_DAEMON_PROCESS_LOCAL_CLI;
202 }
203 /* Placed after the `cli` check on purpose: `cbm cli search "daemon
204 * start"` is opaque tool input and must stay LOCAL_CLI. */

Callers 3

mainFunction · 0.85
classifyFunction · 0.85

Calls 4

bootstrap_find_argFunction · 0.85
bootstrap_arg_isFunction · 0.85
bootstrap_has_help_afterFunction · 0.85

Tested by 1

classifyFunction · 0.68