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

Function main_run_allow_root

src/main.c:942–1032  ·  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

940 * the MCP surface would be answered by the same agent that may have been
941 * influenced, so it would not be a human decision at all. */
942static int main_run_allow_root(int argc, char **argv) {
943 const char *path = NULL;
944 bool approve_sensitive = false;
945 bool list_only = false;
946 bool approve_manifest = false;
947 for (int i = 0; i < argc; i++) {
948 if (strcmp(argv[i], "--approve-sensitive") == 0) {
949 approve_sensitive = true;
950 } else if (strcmp(argv[i], "--list") == 0) {
951 list_only = true;
952 } else if (strcmp(argv[i], "--approve-manifest") == 0) {
953 approve_manifest = true;
954 } else if (argv[i][0] == '-') {
955 (void)fprintf(stderr, "error: unknown option: %s\n", argv[i]);
956 return EXIT_FAILURE;
957 } else if (!path) {
958 path = argv[i];
959 } else {
960 (void)fprintf(stderr, "error: only one path may be given\n");
961 return EXIT_FAILURE;
962 }
963 }
964
965 const char *cache_dir = cbm_workspace_cache_dir();
966 if (!cache_dir || !cache_dir[0]) {
967 (void)fprintf(stderr, "error: cache directory could not be resolved\n");
968 return EXIT_FAILURE;
969 }
970
971 if (list_only || !path) {
972 char listing[CBM_SZ_8K];
973 if (cbm_workspace_grant_list(cache_dir, listing, sizeof(listing))) {
974 printf("allowed roots:\n%s", listing);
975 } else {
976 printf("no allowed roots recorded — indexing is unconfined apart from the "
977 "always-refused roots (see docs/CONFIGURATION.md)\n");
978 }
979 if (!path && !list_only) {
980 (void)fprintf(stderr,
981 "usage: codebase-memory-mcp allow-root [--approve-sensitive] <path>\n"
982 " codebase-memory-mcp allow-root --approve-manifest <project>\n"
983 " codebase-memory-mcp allow-root --list\n");
984 return EXIT_FAILURE;
985 }
986 return 0;
987 }
988
989 if (approve_manifest) {
990 /* Approve the manifest a project ships, keyed to its current content. The
991 * file only ever requests; this is the human action that grants. */
992 char canonical_project[CBM_PATH_MAX];
993 if (!cbm_canonical_path(path, canonical_project, sizeof(canonical_project))) {
994 (void)fprintf(stderr, "error: cannot resolve path: %s\n", path);
995 return EXIT_FAILURE;
996 }
997 char merr[CBM_SZ_1K];
998 if (!cbm_workspace_manifest_approve(cache_dir, cbm_workspace_home_dir(), canonical_project,
999 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