// THE INBOX'S RECURRING-REPORT DECISIONS (plans/umtool-redesign.md, R5). Pure, // over schedule views (lib/schedules.ts) and what the article store says is // current, so the rule is unit-tested and lib/inbox.ts only reads the disk. // // tick-failed the newest tick failed, or the editor stopped during it, // and nothing has ticked since -- Your call: Tick now // tick-held the newest tick was held by a cap (the day's, or the // job's over the policy's max) -- Your call: Raise cap // tick-partial (R6.1) the newest tick's scan hit a cap or did not reach a // channel and found nothing in what it read -- never quiet: // Your call, the reason naming what it did not reach // edition-ready a series' edition is done and its article has nothing // current yet -- Review: read it, make it current // worth-researching (R6) a watch's tick whose triage escalated: the flags // and what the sweep of them found -- Your call: open the // board (an R2 case of the flags, `by: triage`), whose // hand-offs make an article or a video. Gone once the board // has a hand-off or every flag of the run is marked // // A living report's refresh lands an `iteration-ready` card of its own (the // article's iterations, lib/inbox.ts); only its failed or held ticks are here. // An edition's article is the SERIES' piece's business: lib/inbox.ts does not // raise iteration cards for it, so a finished edition is one Review card on // the series, not two. const usd = (n) => `$${n.toFixed(2)}`; const timeOf = (iso) => { const t = iso ? Date.parse(iso) : NaN; return Number.isFinite(t) ? t : 0; }; /** * @param {Array<{ id: string, shape: string, topic: string, article?: string, href: string, piece: string, call: null | { at: string, status: string, reason?: string, estimateUsd?: number, usd: number }, editions?: Array<{ n: number, title: string, status: string, article?: string, usd: number, at: string, window: { from: string, to: string } }> }>} views * @param {{ current: (article: string) => number | null, articleHref: (article: string) => string, settingsHref: string, worth?: (schedule: string, k: number) => { href: string, settled: boolean, findings: number | null } | null }} how */ export function scheduleDecisions(views, how) { const out = []; for (const v of views) { const living = v.shape === "living"; const article = living ? (v.article ?? v.id) : null; const base = living ? { project: `sites/articles/${article}`, projectKind: "article", projectTitle: v.topic, piece: v.piece } : { project: `series/${v.id}`, projectKind: "series", projectTitle: v.topic, piece: v.piece }; const call = v.call; if (call) { const held = call.status === "held-by-cap"; const partial = call.status === "partial"; const est = call.estimateUsd !== undefined ? ` · up to ${usd(call.estimateUsd)} a tick` : ""; out.push({ ...base, kind: held ? "tick-held" : partial ? "tick-partial" : "tick-failed", target: call.at, why: partial ? `${call.reason ?? "partial"}${call.usd ? ` · ${usd(call.usd)} spent` : ""}` : `${held ? "held by a cap" : call.status === "interrupted" ? "interrupted" : "failed"}${call.reason ? `: ${call.reason}` : ""}${held ? est : call.usd ? ` · ${usd(call.usd)} spent` : ""}`, href: held ? how.settingsHref : v.href, severity: "open", at: timeOf(call.at), }); } if (v.shape === "watch") { for (const t of v.ticks ?? []) { const tri = t.triage; if (!tri?.escalated || t.status !== "done" || !t.article) continue; const w = how.worth?.(v.id, tri.k) ?? null; if (w?.settled) continue; const top = (tri.top ?? []).slice(0, 2).map((f) => `“${f.line}” — ${f.reason}`); out.push({ ...base, kind: "worth-researching", target: t.article, why: [ `${tri.flagged} flagged of ${tri.candidates} new`, ...top, w && w.findings !== null ? `the sweep kept ${w.findings} finding${w.findings === 1 ? "" : "s"}${t.usd ? ` · ${usd(t.usd)}` : ""}` : t.usd ? usd(t.usd) : null, ] .filter(Boolean) .join(" · "), href: w?.href ?? `/series/${encodeURIComponent(v.id)}/triage/${tri.k}`, severity: "open", at: timeOf(t.at), }); } } if (!living) { for (const e of v.editions ?? []) { if (e.status !== "done" || !e.article) continue; if (how.current(e.article) !== null) continue; out.push({ ...base, kind: "edition-ready", target: e.title, why: `${e.title} (${e.window.from} … ${e.window.to}) is done${e.usd ? ` · ${usd(e.usd)}` : ""}`, href: how.articleHref(e.article), severity: "open", at: timeOf(e.at), }); } } } return out; }