MCPcopy Index your code
hub / github.com/PatrickSys/codebase-context / resolveProjectFromAbsolutePath

Function resolveProjectFromAbsolutePath

src/index.ts:504–573  ·  view source on GitHub ↗
(resolvedPath: string)

Source from the content-addressed store, hash-verified

502}
503
504async function resolveProjectFromAbsolutePath(resolvedPath: string): Promise<ProjectResolution> {
505 const absolutePath = path.resolve(resolvedPath);
506 const containingRoot = getContainingKnownRoot(absolutePath);
507
508 if (clientRootsEnabled && getKnownRootPaths().length > 0 && !containingRoot) {
509 return {
510 ok: false,
511 response: buildProjectSelectionError(
512 'unknown_project',
513 'Requested project is not under an active MCP root.'
514 )
515 };
516 }
517
518 let stats;
519 try {
520 stats = await fs.stat(absolutePath);
521 } catch {
522 return {
523 ok: false,
524 response: buildProjectSelectionError(
525 'unknown_project',
526 `project does not exist: ${absolutePath}`
527 )
528 };
529 }
530
531 const lookupPath = stats.isDirectory() ? absolutePath : path.dirname(absolutePath);
532 const exactDescriptor = listProjectDescriptors().find(
533 (descriptor) => normalizeRootKey(descriptor.rootPath) === normalizeRootKey(lookupPath)
534 );
535 if (exactDescriptor) {
536 const project = getOrCreateProject(exactDescriptor.rootPath);
537 if (exactDescriptor.source === 'subdirectory') {
538 registerDiscoveredProjectPath(exactDescriptor.rootPath, 'subdirectory');
539 } else {
540 rememberProjectPath(exactDescriptor.rootPath, exactDescriptor.source, { touch: false });
541 }
542 return { ok: true, project };
543 }
544
545 const nearestBoundary = await findNearestProjectBoundary(absolutePath, containingRoot);
546 const resolvedProjectPath =
547 nearestBoundary?.rootPath ?? containingRoot ?? (stats.isDirectory() ? absolutePath : undefined);
548
549 if (!resolvedProjectPath) {
550 return {
551 ok: false,
552 response: buildProjectSelectionError(
553 'unknown_project',
554 `project was not found from path: ${absolutePath}`
555 )
556 };
557 }
558
559 const invalidProjectResponse = await validateResolvedProjectPath(resolvedProjectPath);
560 if (invalidProjectResponse) {
561 return { ok: false, response: invalidProjectResponse };

Callers 1

resolveProjectSelectorFunction · 0.85

Calls 11

getContainingKnownRootFunction · 0.85
getKnownRootPathsFunction · 0.85
listProjectDescriptorsFunction · 0.85
normalizeRootKeyFunction · 0.85
getOrCreateProjectFunction · 0.85
rememberProjectPathFunction · 0.85

Tested by

no test coverage detected