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

Function listProjectDescriptors

src/index.ts:357–411  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

355}
356
357function listProjectDescriptors(): ProjectDescriptor[] {
358 const rootPaths = new Map<string, string>();
359 for (const rootPath of getKnownRootPaths()) {
360 rootPaths.set(normalizeRootKey(rootPath), rootPath);
361 }
362 for (const [projectKey, rootPath] of discoveredProjectPaths.entries()) {
363 rootPaths.set(projectKey, rootPath);
364 }
365 for (const project of getAllProjects()) {
366 rootPaths.set(normalizeRootKey(project.rootPath), project.rootPath);
367 }
368
369 const descriptors = Array.from(rootPaths.values())
370 .map((rootPath) => buildProjectDescriptor(rootPath))
371 .sort((a, b) => {
372 if (a.active !== b.active) return a.active ? -1 : 1;
373 if (a.source !== b.source) {
374 const weight: Record<ProjectDescriptor['source'], number> = {
375 root: 0,
376 subdirectory: 1,
377 ad_hoc: 2
378 };
379 return weight[a.source] - weight[b.source];
380 }
381 return a.label.localeCompare(b.label);
382 });
383
384 const duplicates = new Set<string>();
385 const counts = new Map<string, number>();
386 for (const descriptor of descriptors) {
387 counts.set(descriptor.label, (counts.get(descriptor.label) ?? 0) + 1);
388 }
389 for (const [label, count] of counts.entries()) {
390 if (count > 1) {
391 duplicates.add(label);
392 }
393 }
394
395 return descriptors.map((descriptor) => {
396 if (!duplicates.has(descriptor.label)) {
397 return descriptor;
398 }
399
400 const containingRoot = getContainingKnownRoot(descriptor.rootPath);
401 const rootHint =
402 (containingRoot && getKnownRootLabel(containingRoot)) ||
403 (containingRoot && path.basename(containingRoot)) ||
404 path.basename(descriptor.rootPath);
405
406 return {
407 ...descriptor,
408 label: `${descriptor.label} (${rootHint})`
409 };
410 });
411}
412
413function getActiveProjectDescriptor(): ProjectDescriptor | undefined {
414 if (!activeProjectKey) return undefined;

Callers 9

createToolContextFunction · 0.85
resolveProjectSelectorFunction · 0.85
buildResourcesFunction · 0.85
resolveProjectForToolFunction · 0.85

Calls 10

getKnownRootPathsFunction · 0.85
normalizeRootKeyFunction · 0.85
getAllProjectsFunction · 0.85
buildProjectDescriptorFunction · 0.85
getContainingKnownRootFunction · 0.85
getKnownRootLabelFunction · 0.85
setMethod · 0.80
hasMethod · 0.80
getMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected