(
opts: LoadPiConfigOptions = {},
)
| 279 | } |
| 280 | |
| 281 | export function loadPiConfig( |
| 282 | opts: LoadPiConfigOptions = {}, |
| 283 | ): LoadPiConfigResult { |
| 284 | const cwd = opts.cwd ?? process.cwd(); |
| 285 | const loadedFiles: LoadedConfigFile[] = []; |
| 286 | const warnings: string[] = []; |
| 287 | const legacySources = resolveLegacyConfigSources(cwd); |
| 288 | const harnessLegacy = resolveLegacyConfigSourcesForHarness(cwd, "pi"); |
| 289 | |
| 290 | const projectPath = resolveFirstExisting(getProjectConfigPaths(cwd)); |
| 291 | const projectLegacyFallback = projectPath |
| 292 | ? null |
| 293 | : resolvePiLegacyFallback(harnessLegacy.project); |
| 294 | const projectReadPath = projectPath ?? projectLegacyFallback?.path; |
| 295 | if (projectReadPath) { |
| 296 | const loaded = loadConfigFile(projectReadPath, "project"); |
| 297 | if (loaded) loadedFiles.push(loaded); |
| 298 | } |
| 299 | const legacyProjectUnmigrated = |
| 300 | !projectPath && |
| 301 | !projectLegacyFallback && |
| 302 | legacySources.project.some((source) => existsSync(source.path)); |
| 303 | |
| 304 | const userPath = resolveFirstExisting(getUserConfigPaths()); |
| 305 | const userLegacyFallback = userPath |
| 306 | ? null |
| 307 | : resolvePiLegacyFallback(harnessLegacy.user); |
| 308 | const userReadPath = userPath ?? userLegacyFallback?.path; |
| 309 | if (userReadPath) { |
| 310 | const loaded = loadConfigFile(userReadPath, "user"); |
| 311 | if (loaded) loadedFiles.push(loaded); |
| 312 | } |
| 313 | const legacyUserUnmigrated = |
| 314 | !userPath && |
| 315 | !userLegacyFallback && |
| 316 | legacySources.user.some((source) => existsSync(source.path)); |
| 317 | |
| 318 | if (userLegacyFallback) { |
| 319 | warnings.push( |
| 320 | `[user config] reading legacy config from ${userLegacyFallback.path} until migration completes; run \`npx @cortexkit/magic-context doctor\` to consolidate into the shared CortexKit location.`, |
| 321 | ); |
| 322 | } else if (legacyUserUnmigrated) { |
| 323 | warnings.push( |
| 324 | "[user config] legacy Magic Context config exists but the shared CortexKit config is absent; embedding registration is paused until config migration completes.", |
| 325 | ); |
| 326 | } |
| 327 | |
| 328 | if (projectLegacyFallback) { |
| 329 | warnings.push( |
| 330 | `[project config] reading legacy config from ${projectLegacyFallback.path} until migration completes; run \`npx @cortexkit/magic-context doctor\` to consolidate into the shared CortexKit location.`, |
| 331 | ); |
| 332 | } else if (legacyProjectUnmigrated) { |
| 333 | warnings.push( |
| 334 | "[project config] legacy Magic Context config exists but the shared CortexKit config is absent; embedding registration is paused until config migration completes.", |
| 335 | ); |
| 336 | } |
| 337 | |
| 338 | let rawConfig: Record<string, unknown> = {}; |
no test coverage detected