()
| 713 | // ── Main entry ───────────────────────────────────────────────────── |
| 714 | |
| 715 | export async function collectDiagnostics(): Promise<DiagnosticReport> { |
| 716 | const pluginVersion = getSelfVersion(); |
| 717 | const configPaths = detectConfigPaths(); |
| 718 | const opencodeConfig = readConfig(configPaths.opencodeConfig); |
| 719 | const tuiConfig = readConfig(configPaths.tuiConfig); |
| 720 | const magicContextConfig = readConfig(configPaths.magicContextConfig); |
| 721 | const storageDirPath = getStorageDir(); |
| 722 | const contextDbPath = join(storageDirPath, "context.db"); |
| 723 | |
| 724 | const logPath = getMagicContextLogPath("opencode"); |
| 725 | const logFileSize = existsSync(logPath) ? statSync(logPath).size : 0; |
| 726 | |
| 727 | const conflictResult = detectConflicts(process.cwd()); |
| 728 | const recentSessions = await collectRecentSessions(); |
| 729 | const openCodeDetection = detectOpenCode(); |
| 730 | const openCodeInstallKind = openCodeDetection.kind; |
| 731 | const openCodeBinary = openCodeDetection.kind === "cli" ? openCodeDetection.binary : null; |
| 732 | |
| 733 | return { |
| 734 | timestamp: new Date().toISOString(), |
| 735 | platform: process.platform, |
| 736 | arch: process.arch, |
| 737 | nodeVersion: process.version, |
| 738 | pluginVersion, |
| 739 | opencodeInstalled: openCodeInstallKind !== "none", |
| 740 | opencodeInstallKind: openCodeInstallKind, |
| 741 | opencodeVersion: getOpenCodeVersion(openCodeBinary), |
| 742 | configPaths, |
| 743 | opencodeConfigHasPlugin: configHasPluginEntry(opencodeConfig.value), |
| 744 | tuiConfigHasPlugin: configHasPluginEntry(tuiConfig.value), |
| 745 | magicContextConfig: { |
| 746 | exists: existsSync(configPaths.magicContextConfig), |
| 747 | ...(magicContextConfig.error ? { parseError: magicContextConfig.error } : {}), |
| 748 | flags: (sanitizeValue(magicContextConfig.value ?? {}) as Record<string, unknown>) ?? {}, |
| 749 | }, |
| 750 | pluginCache: getPluginCacheInfo(), |
| 751 | storageDir: { |
| 752 | path: storageDirPath, |
| 753 | exists: existsSync(storageDirPath), |
| 754 | contextDbSizeBytes: fileSize(contextDbPath), |
| 755 | }, |
| 756 | conflicts: { |
| 757 | hasConflict: conflictResult.hasConflict, |
| 758 | reasons: conflictResult.reasons, |
| 759 | }, |
| 760 | logFile: { |
| 761 | path: logPath, |
| 762 | exists: existsSync(logPath), |
| 763 | sizeKb: Math.round(logFileSize / 1024), |
| 764 | }, |
| 765 | recentSessions, |
| 766 | historianDumps: collectHistorianDumps(recentSessions), |
| 767 | historianFailures: await collectHistorianFailures(storageDirPath), |
| 768 | historianRuns: await collectHistorianRuns(storageDirPath), |
| 769 | }; |
| 770 | } |
| 771 | |
| 772 | function formatBytes(bytes: number): string { |
no test coverage detected