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

Function loadPiConfig

packages/pi-plugin/src/config/index.ts:281–382  ·  view source on GitHub ↗
(
	opts: LoadPiConfigOptions = {},
)

Source from the content-addressed store, hash-verified

279}
280
281export 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> = {};

Callers 6

runHealthChecksFunction · 0.90
collectDiagnosticsFunction · 0.90
index.tsFile · 0.90
index.test.tsFile · 0.90

Calls 11

resolveFirstExistingFunction · 0.85
getProjectConfigPathsFunction · 0.85
resolvePiLegacyFallbackFunction · 0.85
loadConfigFileFunction · 0.85
getUserConfigPathsFunction · 0.85
mergeRawConfigsFunction · 0.85
parsePiConfigFunction · 0.85

Tested by

no test coverage detected