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

Function syncKnownRoots

src/index.ts:431–480  ·  view source on GitHub ↗
(rootEntries: Array<{ rootPath: string; label?: string }>)

Source from the content-addressed store, hash-verified

429}
430
431function syncKnownRoots(rootEntries: Array<{ rootPath: string; label?: string }>): void {
432 const nextRoots = new Map<string, { rootPath: string; label?: string }>();
433 const normalizedRoots =
434 rootEntries.length > 0 ? rootEntries : primaryRootPath ? [{ rootPath: primaryRootPath }] : [];
435
436 for (const entry of normalizedRoots) {
437 const resolvedRootPath = path.resolve(entry.rootPath);
438 nextRoots.set(normalizeRootKey(resolvedRootPath), {
439 rootPath: resolvedRootPath,
440 label: entry.label?.trim() || undefined
441 });
442 }
443
444 // Always include config-registered roots — config is additive (REPO-03)
445 for (const [rootKey, rootEntry] of configRoots.entries()) {
446 if (!nextRoots.has(rootKey)) {
447 nextRoots.set(rootKey, rootEntry);
448 }
449 }
450
451 for (const [rootKey, existingRoot] of knownRoots.entries()) {
452 if (!nextRoots.has(rootKey)) {
453 removeProject(existingRoot.rootPath);
454 forgetProjectPath(existingRoot.rootPath);
455 }
456 }
457
458 for (const project of getAllProjects()) {
459 const stillAllowed = Array.from(nextRoots.values()).some((knownRoot) =>
460 isPathWithin(knownRoot.rootPath, project.rootPath)
461 );
462 if (!stillAllowed) {
463 removeProject(project.rootPath);
464 forgetProjectPath(project.rootPath);
465 }
466 }
467
468 knownRoots.clear();
469 clearDiscoveredProjectPaths();
470 for (const [rootKey, rootEntry] of nextRoots.entries()) {
471 knownRoots.set(rootKey, rootEntry);
472 rememberProjectPath(rootEntry.rootPath, 'root', { touch: false });
473 }
474
475 if (activeProjectKey) {
476 if (!getTrackedRootPathByKey(activeProjectKey)) {
477 activeProjectKey = undefined;
478 }
479 }
480}
481
482function parseProjectSelector(value: unknown): string | undefined {
483 if (typeof value !== 'string') return undefined;

Callers 1

Calls 11

normalizeRootKeyFunction · 0.85
removeProjectFunction · 0.85
forgetProjectPathFunction · 0.85
getAllProjectsFunction · 0.85
isPathWithinFunction · 0.85
rememberProjectPathFunction · 0.85
getTrackedRootPathByKeyFunction · 0.85
setMethod · 0.80
hasMethod · 0.80
clearMethod · 0.65

Tested by

no test coverage detected