import type { RuntimeDiagnostic } from "@arconym/core"; import { summarizeDiagnostics } from "@arconym/core"; import { colors } from "./colors.js"; export function printDiagnostics(diagnostics: RuntimeDiagnostic[]): void { if (diagnostics.length === 0) { console.log(colors.green("✓ All systems look good.")); return; } const summary = summarizeDiagnostics(diagnostics); const parts = [ summary.byLevel.error ? colors.red(`${summary.byLevel.error} error(s)`) : undefined, summary.byLevel.warning ? colors.yellow(`${summary.byLevel.warning} warning(s)`) : undefined, summary.byLevel.info ? colors.cyan(`${summary.byLevel.info} info message(s)`) : undefined, ].filter(Boolean); console.log(`Diagnostics: ${parts.join(", ")}`); for (const diagnostic of diagnostics) { const header = formatDiagnosticHeader(diagnostic); const message = formatDiagnosticMessage(diagnostic); console.log(` ${header} ${message}`); if (diagnostic.suggestion) { console.log(` ${colors.dim("Suggestion:")} ${diagnostic.suggestion}`); } if (diagnostic.details && Object.keys(diagnostic.details).length > 0) { console.log(` ${colors.dim("Details:")} ${JSON.stringify(diagnostic.details)}`); } } } function formatDiagnosticHeader(diagnostic: RuntimeDiagnostic): string { const levelText = diagnostic.level.toUpperCase(); switch (diagnostic.level) { case "error": return colors.red(levelText); case "warning": return colors.yellow(levelText); default: return colors.cyan(levelText); } } function formatDiagnosticMessage(diagnostic: RuntimeDiagnostic): string { const contextSegments = []; if (diagnostic.plugin) contextSegments.push(diagnostic.plugin); if (diagnostic.stage) contextSegments.push(diagnostic.stage); const context = contextSegments.length > 0 ? colors.dim(`[${contextSegments.join(" → ")}]`) : ""; const message = diagnostic.message; return context ? `${context} ${message}` : message; }