briefings-file.ts
Language TypeScript1.5 KB39 lines
/*** The model-written briefings, as produced by `analysis/brief.py`. Node only.** The page's own `briefingProse()` assembles sentences deterministically in* TypeScript from the snapshot, a different artifact from what the model* writes. This file is how the model's briefing, and its per-person views,* reach the board.** The chain is deliberately one-directional and file-mediated:** pnpm dashboard -> briefing-payload.json (numbers)* brief.py -> briefings.json (prose, written from those numbers)* pnpm dashboard -> dashboard.html (renders both)** which is why `pnpm morning` runs the dashboard twice. The alternative (having* the renderer call a model) would put a paid network round-trip inside a page* build and make the board unrenderable whenever the model was unavailable.*/import { readFile } from 'node:fs/promises'import type { Briefings } from './briefings.js'export type { Briefings }export const BRIEFINGS_FILE = new URL('../../../briefings.json', import.meta.url)export async function readBriefings(file: URL = BRIEFINGS_FILE): Promise<Briefings | null> {try {const parsed: unknown = JSON.parse(await readFile(file, 'utf8'))if (!parsed || typeof parsed !== 'object') return nullconst b = parsed as Briefingsreturn b.briefings && typeof b.briefings === 'object' ? b : null} catch {// Absent is the normal case before the first run. The page renders the// deterministic briefing and says the written one has not been generated.return null}}