(
opts: LoadPiConfigOptions = {},
)
| 441 | } |
| 442 | |
| 443 | export function loadPiConfigDetailed( |
| 444 | opts: LoadPiConfigOptions = {}, |
| 445 | ): LoadPiConfigResultDetailed { |
| 446 | const cwd = opts.cwd ?? process.cwd(); |
| 447 | const loadedFiles: LoadedConfigFile[] = []; |
| 448 | const warnings: string[] = []; |
| 449 | const legacySources = resolveLegacyConfigSources(cwd); |
| 450 | const harnessLegacy = resolveLegacyConfigSourcesForHarness(cwd, "pi"); |
| 451 | |
| 452 | const projectPath = resolveFirstExisting(getProjectConfigPaths(cwd)); |
| 453 | const projectLegacyFallback = projectPath |
| 454 | ? null |
| 455 | : resolvePiLegacyFallback(harnessLegacy.project); |
| 456 | const projectReadPath = projectPath ?? projectLegacyFallback?.path; |
| 457 | if (projectReadPath) { |
| 458 | const loaded = loadConfigFile(projectReadPath, "project"); |
| 459 | if (loaded) loadedFiles.push(loaded); |
| 460 | } |
| 461 | const legacyProjectUnmigrated = |
| 462 | !projectPath && |
| 463 | !projectLegacyFallback && |
| 464 | legacySources.project.some((source) => existsSync(source.path)); |
| 465 | |
| 466 | const userPath = resolveFirstExisting(getUserConfigPaths()); |
| 467 | const userLegacyFallback = userPath |
| 468 | ? null |
| 469 | : resolvePiLegacyFallback(harnessLegacy.user); |
| 470 | const userReadPath = userPath ?? userLegacyFallback?.path; |
| 471 | if (userReadPath) { |
| 472 | const loaded = loadConfigFile(userReadPath, "user"); |
| 473 | if (loaded) loadedFiles.push(loaded); |
| 474 | } |
| 475 | const legacyUserUnmigrated = |
| 476 | !userPath && |
| 477 | !userLegacyFallback && |
| 478 | legacySources.user.some((source) => existsSync(source.path)); |
| 479 | |
| 480 | if (userLegacyFallback) { |
| 481 | warnings.push( |
| 482 | `[user config] reading legacy config from ${userLegacyFallback.path} until migration completes; run \`npx @cortexkit/magic-context doctor\` to consolidate into the shared CortexKit location.`, |
| 483 | ); |
| 484 | } else if (legacyUserUnmigrated) { |
| 485 | warnings.push( |
| 486 | "[user config] legacy Magic Context config exists but the shared CortexKit config is absent; embedding registration is paused until config migration completes.", |
| 487 | ); |
| 488 | } |
| 489 | |
| 490 | if (projectLegacyFallback) { |
| 491 | warnings.push( |
| 492 | `[project config] reading legacy config from ${projectLegacyFallback.path} until migration completes; run \`npx @cortexkit/magic-context doctor\` to consolidate into the shared CortexKit location.`, |
| 493 | ); |
| 494 | } else if (legacyProjectUnmigrated) { |
| 495 | warnings.push( |
| 496 | "[project config] legacy Magic Context config exists but the shared CortexKit config is absent; embedding registration is paused until config migration completes.", |
| 497 | ); |
| 498 | } |
| 499 | |
| 500 | let rawConfig: Record<string, unknown> = {}; |
no test coverage detected