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

Function collectDiagnostics

packages/cli/src/lib/diagnostics-pi.ts:444–504  ·  view source on GitHub ↗
(cwd = process.cwd())

Source from the content-addressed store, hash-verified

442}
443
444export async function collectDiagnostics(cwd = process.cwd()): Promise<PiDiagnosticReport> {
445 const pi = detectPiBinary();
446 const settingsPath = getPiUserExtensionsPath();
447 const settingsParsed = readJsonc(settingsPath);
448 const packages = packageEntries(settingsParsed.value);
449 const userConfigPath = getPiUserConfigPath();
450 const projectConfigPath = getProjectConfigPath(cwd);
451 const loaded = loadPiConfig({ cwd });
452 const storageDirPath = getMagicContextStorageDir();
453 const dbPath = join(storageDirPath, "context.db");
454 const logPath = getMagicContextLogPath("pi");
455 const logFileSize = existsSync(logPath) ? statSync(logPath).size : 0;
456 const otherPiExtensions = packages
457 .filter((entry) => !isPiMagicContextPackageEntry(entry))
458 .map(describePiPackageEntry);
459 const recentSessions = collectPiRecentSessions();
460 const historianDumps = collectPiHistorianDumps(recentSessions);
461
462 return {
463 timestamp: new Date().toISOString(),
464 platform: process.platform,
465 arch: process.arch,
466 nodeVersion: process.version,
467 pluginVersion: getSelfVersion(),
468 piInstalled: pi !== null,
469 piPath: pi?.path ?? null,
470 piVersion: pi ? getPiVersion(pi.path) : null,
471 settings: {
472 path: settingsPath,
473 exists: existsSync(settingsPath),
474 ...(settingsParsed.parseError ? { parseError: settingsParsed.parseError } : {}),
475 hasMagicContextPackage: hasPiMagicContextPackage(packages),
476 packages: sanitizeValue(packages) as unknown[],
477 },
478 configPaths: {
479 agentDir: getPiAgentConfigDir(),
480 userConfig: userConfigPath,
481 projectConfig: projectConfigPath,
482 },
483 userConfig: readConfigDiagnostic(userConfigPath),
484 projectConfig: readConfigDiagnostic(projectConfigPath),
485 loadedConfigPaths: loaded.loadedFromPaths.map(sanitizeString),
486 loadWarnings: loaded.warnings.map(sanitizeString),
487 storageDir: {
488 path: storageDirPath,
489 exists: existsSync(storageDirPath),
490 contextDbSizeBytes: fileSize(dbPath),
491 },
492 conflicts: {
493 knownConflicts: [],
494 otherPiExtensions: otherPiExtensions.map(sanitizeString),
495 },
496 logFile: {
497 path: logPath,
498 exists: existsSync(logPath),
499 sizeKb: Math.round(logFileSize / 1024),
500 },
501 recentSessions,

Callers 1

runHealthChecksFunction · 0.90

Calls 15

detectPiBinaryFunction · 0.90
getPiUserExtensionsPathFunction · 0.90
getPiUserConfigPathFunction · 0.90
loadPiConfigFunction · 0.90
getMagicContextLogPathFunction · 0.90
getPiVersionFunction · 0.90
hasPiMagicContextPackageFunction · 0.90
getPiAgentConfigDirFunction · 0.90
packageEntriesFunction · 0.85
getProjectConfigPathFunction · 0.85

Tested by

no test coverage detected