Files
ipal-kit/src/modules/doctor/format.ts
T
Radosław SmolińskiandClaude Opus 5.5 a4e8cfeae8 ipal-doctor: one command that checks a site against the team rules
bin ipal-doctor + @intecion/ipal-kit/doctor: static rules (versions, Node 22, AGENT.md §3
layout and naming, database names, env rules, headers, X-Powered-By, CSP, 2FA, cookie
scanner, adminMeta, AGENTS.md, skills, seeds, block library via blockLibraryManifest,
ipal-audit --quick), registry rules (latest plugin, pnpm audit --prod), live rules (--url,
ipal-seo-check), deep rules (--deep via payload run; GET /api/ipal/doctor, off until
IPAL_DOCTOR_TOKEN). Human / JSON output, --strict, exit codes 0/1/2/3, --sites drift table,
ipal-doctor.json with reasons, until, files, seen.

Fixes found on the way: sitemap leaves out the System pages 404 page; ipal-audit finds
array labels after fields, any form seed, runs grep in UTF-8; ipal-seo-check counts
duplicate titles per language. Reference site at zero findings (static), CI steps on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-29 16:03:00 +01:00

47 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { DoctorReport, DoctorSeverity } from './types.js'
const MARK: Record<DoctorSeverity, string> = { error: '✗', info: 'i', warning: '!' }
const COLOR: Record<DoctorSeverity, string> = { error: '\x1b[31m', info: '\x1b[36m', warning: '\x1b[33m' }
const summaryLine = (r: DoctorReport) =>
`${r.summary.error} error(s), ${r.summary.warning} warning(s), ${r.summary.info} info${r.summary.silenced ? ` (${r.summary.silenced} silenced)` : ''}`
/** Human-readable report: header, findings worst first with fix and doc link, summary. */
export function formatReport(report: DoctorReport, { color = false }: { color?: boolean } = {}): string {
const c = (sev: DoctorSeverity, text: string) => (color ? `${COLOR[sev]}${text}\x1b[0m` : text)
const lines = [`ipal-doctor ${report.rulesVersion} — ${report.site.path}`, `site: ${report.site.domain ?? '(no domain)'} · ipal-kit ${report.site.plugin ?? 'not installed'}`, '']
const active = report.findings.filter((f) => !f.silenced)
if (!active.length) {lines.push('No findings.')}
for (const f of active) {
lines.push(c(f.severity, `${MARK[f.severity]} [${f.severity}] ${f.rule}: ${f.message}`))
if (f.file) {lines.push(` file: ${f.file}`)}
if (f.fix) {lines.push(` fix: ${f.fix}`)}
if (f.docs) {lines.push(` docs: node_modules/@intecion/ipal-kit/${f.docs}`)}
}
const silenced = report.findings.filter((f) => f.silenced)
if (silenced.length) {
lines.push('', 'Silenced:')
for (const f of silenced) {lines.push(` - ${f.rule}: ${f.message} — ${f.reason}`)}
}
if (report.skipped.length) {lines.push('', `Not run: ${report.skipped.join(', ')} (--url, --deep, or without --offline)`)}
lines.push('', `ipal-doctor: ${summaryLine(report)}`)
return lines.join('\n')
}
const cell = (report: DoctorReport, rule: string) => {
const hits = report.findings.filter((f) => !f.silenced && (f.rule === rule || f.rule.startsWith(`${rule}:`)))
if (!hits.length) {return report.findings.some((f) => f.silenced && f.rule === rule) ? 'silenced' : '✅'}
const worst = hits.some((f) => f.severity === 'error') ? '❌' : hits.some((f) => f.severity === 'warning') ? '⚠️' : 'ℹ️'
return `${worst} ${hits.length > 1 ? hits.length : ''}`.trim()
}
/** One Markdown table: rule × site (the drift sweep, `--sites … --md`). */
export function formatDriftTable(reports: DoctorReport[]): string {
const name = (r: DoctorReport) => r.site.path.split('/').filter(Boolean).at(-1) ?? r.site.path
const rules = [...new Set(reports.flatMap((r) => r.findings.map((f) => f.rule.split(':')[0])))].sort()
const head = `| Rule | ${reports.map(name).join(' | ')} |`
const sep = `|---|${reports.map(() => '---').join('|')}|`
const totals = `| **errors / warnings / info** | ${reports.map((r) => `${r.summary.error} / ${r.summary.warning} / ${r.summary.info}`).join(' | ')} |`
return [head, sep, totals, ...rules.map((rule) => `| \`${rule}\` | ${reports.map((r) => cell(r, rule)).join(' | ')} |`)].join('\n')
}