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

Function cbm_workspace_root_allowed

src/foundation/workspace.c:541–615  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

539}
540
541bool cbm_workspace_root_allowed(const char *canonical_path, const char *home_dir,
542 const char *cache_dir, const char *configured_root, char *err,
543 size_t err_sz) {
544 if (err && err_sz) {
545 err[0] = '\0';
546 }
547 if (!canonical_path || !canonical_path[0]) {
548 if (err) {
549 snprintf(err, err_sz, "no repository path given");
550 }
551 return false;
552 }
553
554 ws_match_t match = {canonical_path, false, false};
555 int grants = ws_grant_walk(cache_dir, ws_match_visit, &match);
556
557 /* A configured root behaves as an additional grant so existing
558 * CBM_ALLOWED_ROOT deployments keep working unchanged. */
559 bool configured = configured_root && configured_root[0];
560 bool configured_contains = configured && cbm_path_within_root(configured_root, canonical_path);
561
562 /* Containment first when a boundary has actually been declared. A path
563 * outside a configured root is best explained as exactly that, and the
564 * wording is what callers and the shell contracts already match on. Breadth
565 * then applies to paths that ARE inside the declared root but are still too
566 * broad to index as one unit. */
567 bool boundary_declared = grants > 0 || configured;
568 /* No manifest consultation here, deliberately.
569 *
570 * A project's manifest authorizes outside roots FOR THAT PROJECT, so the
571 * question it answers is "may project P pull in tree T", not "may T be indexed
572 * standalone". This function only ever sees one path, so it has no project
573 * context to ask that question with — an earlier draft passed the candidate as
574 * its own project root, which read a manifest that by definition was not the
575 * one that requested it and so never authorized anything.
576 *
577 * The consuming half belongs where the project context exists: discovery
578 * walking a project's approved extra roots. cbm_workspace_manifest_allows is
579 * the query that half will use. */
580 if (boundary_declared && !match.contained && !configured_contains) {
581 if (err) {
582 /* Keep the "outside the allowed root" wording: changing it broke an
583 * assertion whose early return then leaked CBM_ALLOWED_ROOT into
584 * every later test in that suite. Guidance is appended, not
585 * substituted. */
586 snprintf(err, err_sz,
587 "%s is outside the allowed root. To allow it, run: "
588 "codebase-memory-mcp allow-root %s",
589 canonical_path, canonical_path);
590 }
591 return false;
592 }
593
594 cbm_ws_verdict_t verdict = cbm_workspace_classify_root(canonical_path, home_dir, cache_dir);
595 if (verdict == CBM_WS_ALLOW) {
596 return true;
597 }
598 /* An explicit human approval recorded for exactly this path is the only thing

Callers 6

index_status_project_keyFunction · 0.85
handle_index_repositoryFunction · 0.85
maybe_auto_indexFunction · 0.85
handle_index_startFunction · 0.85
test_workspace.cFile · 0.85

Calls 5

ws_grant_walkFunction · 0.85
cbm_path_within_rootFunction · 0.85

Tested by

no test coverage detected