import { loadConfig } from '../core/config.js'; import { getDecision, listDecisions } from '../core/services/decisionService.js'; import { designTokensCss, escapeHtml } from './ui-shared.js'; import type { Decision } from '../core/schema.js'; function ago(iso: string): string { const t = Date.parse(iso); if (Number.isNaN(t)) return ''; const s = Math.max(0, Math.floor((Date.now() - t) / 1000)); if (s < 60) return `${s}s ago`; const m = Math.floor(s / 60); if (m < 60) return `${m}m ago`; const h = Math.floor(m / 60); if (h < 24) return `${h}h ago`; return `${Math.floor(h / 24)}d ago`; } export function renderDecisionsHtml(cwd: string): string { const config = loadConfig(cwd); const decisions: Decision[] = listDecisions(cwd).map((entry) => { try { return getDecision(cwd, entry.id).decision; } catch { return { id: entry.id, title: entry.title, status: 'accepted', context: '', decision: entry.content, consequences: [], alternatives: [], relatedDecisions: [], createdAt: entry.createdAt, updatedAt: entry.updatedAt, }; } }); const rows = decisions.length ? decisions .map( (d) => `
${escapeHtml(d.id)} ${escapeHtml(d.status)} ${escapeHtml(ago(d.updatedAt || d.createdAt))}

${escapeHtml(d.title)}

${escapeHtml(d.decision)}

${ d.consequences?.length ? `
Consequences${d.consequences.map((c) => `${escapeHtml(c)}`).join('')}
` : '' }
`, ) .join('') : '
No decisions yet.
'; return ` AgentHub Decisions
AgentHub ${escapeHtml(config.projectName)}

Decision Log

${rows}
`; }