// QUOTE CHECKS GONE STALE (umtool redesign L4, "What needs you"): a project
// that uses the quote check (`
/quote-check.json`, lib/report/quoteCheck.mjs)
// and has clips the check no longer vouches for -- the cut or the quote changed
// since its row (rowIsCurrent), or a clip with a quote that was never checked
// -- is a call: one row per clip, one card per piece, its one-press action
// **Run quote-check** on those clips (the durable queue: it transcribes through
// the editor), its terminal twin `umtool quote-check
--clips a,b`.
//
// The failing rows themselves (moved, not-found) are the project reducer's,
// blocking: clip-quote-moved / clip-quote-missing (lib/projects/report.mjs),
// with their own one-press settles. A project with no quote-check.json raises
// nothing here: the check is opt-in.
//
// Pure: lib/inbox/projectCalls.ts reads the manifest and the file.
import { rowIsCurrent } from "../report/quoteCheck.mjs";
export const QUOTE_CHECK_STALE = "quote-check-stale";
/**
* The clips the check does not vouch for: `{ id, why: "stale" | "unchecked" }`, timeline order.
* @param {Array>} timeline
* @param {{ clips?: Record } | null} doc readQuoteCheck()
*/
export function staleQuoteChecks(timeline, doc) {
const rows = doc?.clips && typeof doc.clips === "object" ? doc.clips : null;
if (!rows || !Object.keys(rows).length) return [];
const out = [];
for (const e of Array.isArray(timeline) ? timeline : []) {
if (e?.type !== "clip" || e.src || e.quoteRuled || !String(e.quote ?? "").trim()) continue;
const row = rows[e.id];
if (!row) out.push({ id: String(e.id), why: "unchecked" });
else if (!rowIsCurrent(row, e)) out.push({ id: String(e.id), why: "stale" });
}
return out;
}
/**
* The `quote-check-stale` rows of one project, each with the one-press settle
* for the whole set (the card's button runs the check on every clip it lists).
*
* @param {{ project: string, projectTitle: string, projectKind?: string, timeline: any[], doc: any, href: string, at: number }} o
*/
export function quoteCheckDecisions({ project, projectTitle, projectKind, timeline, doc, href, at }) {
const stale = staleQuoteChecks(timeline, doc);
if (!stale.length) return [];
const n = stale.length;
const what = `${n} quote check${n === 1 ? "" : "s"} out of date`;
const moved = stale.filter((s) => s.why === "stale").map((s) => s.id);
const never = stale.filter((s) => s.why === "unchecked").map((s) => s.id);
const list = (ids) => `${ids.slice(0, 6).join(", ")}${ids.length > 6 ? ` and ${ids.length - 6} more` : ""}`;
const why = [what, moved.length ? `cut or quote changed since: ${list(moved)}` : null, never.length ? `never checked: ${list(never)}` : null].filter(Boolean).join(" ยท ");
const clips = stale.map((s) => s.id);
return stale.map((s) => ({
project,
projectTitle,
...(projectKind ? { projectKind } : {}),
kind: QUOTE_CHECK_STALE,
target: s.id,
what,
why,
href,
severity: "open",
at,
fix: `umtool quote-check ${project} --clips ${clips.join(",")}`,
settle: { kind: "quote-check", clips: [s.id], label: "Run quote-check" },
}));
}