/**
* Diagnostic and health check formatting utilities
*
* Provides consistent markdown formatting for system health checks
* and diagnostic operations.
*/
/**
* Diagnostic check result type for formatting
*/
export interface DiagnosticCheckResult {
status: "pass" | "warn" | "fail";
message: string;
details?: string;
recommendations?: string;
}
/**
* Format host doctor diagnostic results as markdown
*/
export function formatHostDoctorMarkdown(
host: string,
checks: Record<string, DiagnosticCheckResult>
): string {
const lines = [`## 🏥 Health Check: ${host}`, ""];
// Individual check results (determine order and labels)
const checkOrder = ["docker", "network", "resources", "containers", "processes", "logs"];
const checkLabels: Record<string, string> = {
docker: "Docker Daemon",
network: "Network Connectivity",
resources: "System Resources",
containers: "Container Health",
processes: "Process Health",
logs: "System Logs",
};
// Build list of checks to display (only those that exist in checks object)
const checksToDisplay: Array<[string, DiagnosticCheckResult]> = [];
for (const checkName of checkOrder) {
const result = checks[checkName];
if (result) {
checksToDisplay.push([checkName, result]);
}
}
// Count status types (only from checks that will be displayed)
let passCount = 0;
let warnCount = 0;
let failCount = 0;
for (const [, result] of checksToDisplay) {
if (result.status === "pass") passCount++;
else if (result.status === "warn") warnCount++;
else if (result.status === "fail") failCount++;
}
// Overall status
const overallStatus = failCount > 0 ? "❌ CRITICAL" : warnCount > 0 ? "⚠️ WARNING" : "✅ HEALTHY";
lines.push(`**Overall Status:** ${overallStatus}`);
lines.push(`**Checks:** ${passCount} passed, ${warnCount} warnings, ${failCount} failed`);
lines.push("");
// Display each check
for (const [checkName, result] of checksToDisplay) {
const statusEmoji = result.status === "pass" ? "✅" : result.status === "warn" ? "⚠️" : "❌";
const statusText = result.status.toUpperCase();
const label = checkLabels[checkName] || checkName;
lines.push(`### ${statusEmoji} ${label} - ${statusText}`);
lines.push("");
lines.push(`**Message:** ${result.message}`);
if (result.details) {
lines.push("");
lines.push("**Details:**");
lines.push("```");
lines.push(result.details);
lines.push("```");
}
if (result.recommendations) {
lines.push("");
lines.push("**Recommendations:**");
for (const rec of result.recommendations.split("\n")) {
lines.push(`- ${rec}`);
}
}
lines.push("");
}
return lines.join("\n");
}