import type { Finding, SecurityCheckResult } from '../types.js'; const SEVERITY_EMOJI: Record = { critical: '🚨', high: '⚠️', medium: '🔶', low: '🔷', }; const STATUS_EMOJI: Record = { pass: '✅', warn: '⚠️', fail: '❌', }; export function formatAlert(findings: Finding[]): string { if (findings.length === 0) return ''; const lines: string[] = []; for (const f of findings) { const emoji = SEVERITY_EMOJI[f.severity] ?? '⚠️'; lines.push(` ${emoji} [${f.severity.toUpperCase()}] ${f.rule}: \`${f.matched}\``); } return lines.join('\n'); } export function formatStartupReport(checks: SecurityCheckResult[]): string { const lines: string[] = ['**OpenClaw Security Check**', '']; const passed = checks.filter((c) => c.status === 'pass').length; const warned = checks.filter((c) => c.status === 'warn').length; const failed = checks.filter((c) => c.status === 'fail').length; for (const check of checks) { const emoji = STATUS_EMOJI[check.status] ?? '❓'; lines.push(`${emoji} **${check.name}**: ${check.message}`); } lines.push(''); const score = Math.round((passed / checks.length) * 100); lines.push(`**Security Score: ${score}/100** (${passed} pass, ${warned} warn, ${failed} fail)`); if (failed > 0) { lines.push('> 🚨 Critical issues found — review your OpenClaw security configuration.'); } else if (warned > 0) { lines.push('> ⚠️ Some configuration improvements recommended.'); } else { lines.push('> ✅ All security checks passed.'); } return lines.join('\n'); }