import { loadHealthConfig, resolveOrg } from '../../health/config.ts' import { buildHealthReport, loadHealthFacts } from '../../health/signals.ts' import { initSchema, listFingerprints } from '../../health/store.ts' /** * Read-only factory health snapshot: switches, overall level, each signal, * fingerprint counts by status, the wake lease, and recent fingerprints. * * @param input - `{ limit? }` recent fingerprints to include (default 20, max 100) * @returns Health report without secrets or credential names * * @example * import healthStatus from 'kody:@kody/kody-factory/health/status' * await healthStatus() */ export default async function healthStatus(input: { limit?: number } = {}) { await initSchema() const config = await loadHealthConfig() const report = buildHealthReport(await loadHealthFacts(config)) const recent = await listFingerprints({ limit: Math.min(Math.max(input?.limit ?? 20, 1), 100) }) return { org: await resolveOrg(config), switches: { intakeEnabled: config.intakeEnabled, reconcileEnabled: config.reconcileEnabled, wakesEnabled: config.wakesEnabled }, level: report.level, summary: report.summary, reasons: report.reasons, signals: report.signals, counts: report.facts.counts, wakesThisHour: report.facts.wakesThisHour, lease: report.facts.lease, recent: recent.map((r) => ({ fingerprint: r.fingerprint, status: r.status, count: r.count, first_seen: r.first_seen, last_seen: r.last_seen, outcome: r.outcome })), } }