MCPcopy Create free account
hub / github.com/cortexkit/magic-context / loadPluginConfigDetailed

Function loadPluginConfigDetailed

packages/plugin/src/config/index.ts:441–570  ·  view source on GitHub ↗
(directory: string)

Source from the content-addressed store, hash-verified

439}
440
441export function loadPluginConfigDetailed(directory: string): LoadResultDetailed {
442 const userDetected = detectConfigFile(getUserConfigBasePath());
443 const projectDetected = detectConfigFile(getProjectConfigBasePath(directory));
444 // Both-harness sources drive the GC-suppression signal; this-harness sources
445 // (OpenCode) drive the non-destructive read fallback when the base is absent.
446 const legacySources = resolveLegacyConfigSources(directory);
447 const harnessLegacy = resolveLegacyConfigSourcesForHarness(directory, "opencode");
448
449 // When the CortexKit base is absent (migration refused on a differing
450 // OpenCode/Pi pair, or hasn't run), read THIS harness's own legacy file
451 // instead of falling to schema defaults that would silently re-enable
452 // features the user disabled.
453 const userLegacyFallback =
454 userDetected.format === "none"
455 ? resolveLegacyReadFallback(harnessLegacy.user)
456 : { source: null };
457 const projectLegacyFallback =
458 projectDetected.format === "none"
459 ? resolveLegacyReadFallback(harnessLegacy.project)
460 : { source: null };
461
462 // "Unmigrated" (→ untrusted, GC suppressed) ONLY when the base is absent,
463 // some legacy config exists, AND we did NOT read this harness's own legacy.
464 // If we read our own legacy the config is real → trusted. If only the OTHER
465 // harness's legacy exists we fell to defaults → keep GC suppressed so a
466 // default-config start can't reap the other harness's embedding vectors.
467 const legacyUserUnmigrated =
468 userDetected.format === "none" &&
469 !userLegacyFallback.source &&
470 legacySources.user.some((source) => existsSync(source.path));
471 const legacyProjectUnmigrated =
472 projectDetected.format === "none" &&
473 !projectLegacyFallback.source &&
474 legacySources.project.some((source) => existsSync(source.path));
475
476 const userLoaded =
477 userDetected.format !== "none"
478 ? loadConfigFileDetailed(userDetected.path, "user")
479 : userLegacyFallback.source
480 ? loadConfigFileDetailed(userLegacyFallback.source.path, "user")
481 : null;
482 const projectLoaded =
483 projectDetected.format !== "none"
484 ? loadConfigFileDetailed(projectDetected.path, "project")
485 : projectLegacyFallback.source
486 ? loadConfigFileDetailed(projectLegacyFallback.source.path, "project")
487 : null;
488
489 const allWarnings: string[] = [];
490 let mergedRaw: Record<string, unknown> = {};
491
492 if (userLegacyFallback.source) {
493 allWarnings.push(
494 `[user config] reading legacy config from ${userLegacyFallback.source.path} until migration completes; run \`npx @cortexkit/magic-context doctor\` to consolidate into the shared CortexKit location.`,
495 );
496 } else if (legacyUserUnmigrated) {
497 allWarnings.push(
498 "[user config] legacy Magic Context config exists but the shared CortexKit config is absent; embedding registration is paused until config migration completes.",

Callers 3

index.test.tsFile · 0.90
loadPluginConfigFunction · 0.85

Calls 13

detectConfigFileFunction · 0.90
getUserConfigBasePathFunction · 0.85
getProjectConfigBasePathFunction · 0.85
loadConfigFileDetailedFunction · 0.85
deepMergeRawConfigFunction · 0.85
parsePluginConfigFunction · 0.85
bindSubstitutionFailuresFunction · 0.70

Tested by

no test coverage detected