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

Function main_run_allow_root

src/main.c:1185–1275  ·  view source on GitHub ↗

Try to handle a subcommand (cli/install/uninstall/update/config/--version/--help). * Returns -1 if no subcommand matched, otherwise the exit code. */ `allow-root [--approve-sensitive] ` — record an indexing root. * * Enrollment lives here, in a command a person types, and deliberately nowhere * else: the whole point of the grant store is that neither an indexed repository * nor a tool c

Source from the content-addressed store, hash-verified

1183 * the MCP surface would be answered by the same agent that may have been
1184 * influenced, so it would not be a human decision at all. */
1185static int main_run_allow_root(int argc, char **argv) {
1186 const char *path = NULL;
1187 bool approve_sensitive = false;
1188 bool list_only = false;
1189 bool approve_manifest = false;
1190 for (int i = 0; i < argc; i++) {
1191 if (strcmp(argv[i], "--approve-sensitive") == 0) {
1192 approve_sensitive = true;
1193 } else if (strcmp(argv[i], "--list") == 0) {
1194 list_only = true;
1195 } else if (strcmp(argv[i], "--approve-manifest") == 0) {
1196 approve_manifest = true;
1197 } else if (argv[i][0] == '-') {
1198 (void)fprintf(stderr, "error: unknown option: %s\n", argv[i]);
1199 return EXIT_FAILURE;
1200 } else if (!path) {
1201 path = argv[i];
1202 } else {
1203 (void)fprintf(stderr, "error: only one path may be given\n");
1204 return EXIT_FAILURE;
1205 }
1206 }
1207
1208 const char *cache_dir = cbm_workspace_cache_dir();
1209 if (!cache_dir || !cache_dir[0]) {
1210 (void)fprintf(stderr, "error: cache directory could not be resolved\n");
1211 return EXIT_FAILURE;
1212 }
1213
1214 if (list_only || !path) {
1215 char listing[CBM_SZ_8K];
1216 if (cbm_workspace_grant_list(cache_dir, listing, sizeof(listing))) {
1217 printf("allowed roots:\n%s", listing);
1218 } else {
1219 printf("no allowed roots recorded — indexing is unconfined apart from the "
1220 "always-refused roots (see docs/CONFIGURATION.md)\n");
1221 }
1222 if (!path && !list_only) {
1223 (void)fprintf(stderr,
1224 "usage: codebase-memory-mcp allow-root [--approve-sensitive] <path>\n"
1225 " codebase-memory-mcp allow-root --approve-manifest <project>\n"
1226 " codebase-memory-mcp allow-root --list\n");
1227 return EXIT_FAILURE;
1228 }
1229 return 0;
1230 }
1231
1232 if (approve_manifest) {
1233 /* Approve the manifest a project ships, keyed to its current content. The
1234 * file only ever requests; this is the human action that grants. */
1235 char canonical_project[CBM_PATH_MAX];
1236 if (!cbm_canonical_path(path, canonical_project, sizeof(canonical_project))) {
1237 (void)fprintf(stderr, "error: cannot resolve path: %s\n", path);
1238 return EXIT_FAILURE;
1239 }
1240 char merr[CBM_SZ_1K];
1241 if (!cbm_workspace_manifest_approve(cache_dir, cbm_workspace_home_dir(), canonical_project,
1242 merr, sizeof(merr))) {

Callers 1

handle_subcommandFunction · 0.85

Calls 7

cbm_workspace_cache_dirFunction · 0.85
cbm_workspace_grant_listFunction · 0.85
cbm_canonical_pathFunction · 0.85
cbm_workspace_home_dirFunction · 0.85
cbm_is_dirFunction · 0.85
cbm_workspace_grant_addFunction · 0.85

Tested by

no test coverage detected