// The reports digest: every report with its exchange, newest first, written // as reports.md beside a mirrored feedback.jsonl. Used by deploy/pull-reports.sh. // tsx deploy/report-digest.ts import { writeFileSync } from 'node:fs'; import { join } from 'node:path'; import { Reports } from '../server/src/reports'; const dir = process.argv[2]; if (!dir) { console.error('usage: report-digest.ts '); process.exit(2); } const when = (iso: string) => iso.slice(0, 16).replace('T', ' '); const reports = new Reports(dir).read().reverse(); const lines = ['# Hnefatafl reports', '', `${reports.length} reports; newest first. Pictures are in \`images/\`.`, '']; for (const r of reports) { lines.push(`## ${when(r.at)} — ${r.player} in ${r.roomId} (turn ${r.turn ?? '?'}, seq ${r.seq}) — id ${r.id}`, ''); lines.push(`**What happened:** ${r.happened.trim()}`); if (r.expected.trim()) lines.push(`**What they expected:** ${r.expected.trim()}`); if (r.image) lines.push(`**Picture:** ![${r.image}](images/${r.image})`); for (const line of r.thread) { const who = line.from === 'player' ? `${r.player} answers` : `**${line.status}**`; lines.push(`> ${who} (${when(line.at)}): ${line.text.trim()}`); } const last = r.thread[r.thread.length - 1]; if (!last || last.from === 'player') lines.push('> _awaiting the keeper_'); lines.push(''); } writeFileSync(join(dir, 'reports.md'), lines.join('\n')); console.log(`${reports.length} reports, ${reports.filter((r) => r.image).length} with pictures -> ${join(dir, 'reports.md')}`);