// THE INBOX'S ORDER: which group a decision is in, how the groups rank, and // the one action each offers (plans/umtool-redesign.md, "Target information // architecture", Inbox). Pure functions over decision rows -- no disk, no // clock -- so the ranking is unit-tested and the API, the CLI and (P3) the page // share one definition. // // GROUPS, in order: // // your-call research proposals, then failed runs: money is waiting // on a yes or no ("spend") // review a finished iteration that is not current; a cut whose // drafted fields nobody has reviewed (r28's drafts, P2b); // a fact-check's proposed verdicts (release 29 M8) // blocking something downstream would lie, on an ACTIVE piece // notes the operator's open notes // open every other open decision (a variant with no verdict, a // link only the operator can choose, …) // ready-to-finish a piece that looks done: mark it done, or keep it going // quiet true facts that are not decisions; collapsed // // A decision on a PARKED or DONE piece keeps its group and is `hidden`. The // API never drops it (one row per decision, the MCP reads every row); the // inbox shows a hidden count instead of the rows. export const GROUPS = [ { id: "your-call", label: "Your call", collapsed: false }, { id: "review", label: "Review", collapsed: false }, { id: "blocking", label: "Blocking", collapsed: false }, { id: "notes", label: "Notes", collapsed: false }, { id: "open", label: "Open", collapsed: false }, { id: "ready-to-finish", label: "Ready to finish", collapsed: false }, { id: "quiet", label: "Quiet", collapsed: true }, ]; export const GROUP_IDS = GROUPS.map((g) => g.id); /** * A decision's CATEGORY: what kind of thing it is, independent of where it * sits. `spend` is research proposals plus failed runs (there is no "waiting * on a cap" state: the daily cap refuses at start, a per-job cap ends the run). */ export const CATEGORIES = ["spend", "review", "fix", "note", "choose", "finish", "info"]; const KIND_CATEGORY = { "research-proposal": "spend", "iteration-failed": "spend", "iteration-ready": "review", "drafts-unreviewed": "review", "open-note": "note", "unreadable-notes": "fix", "link-ambiguous": "choose", "looks-done": "finish", // Recurring reports (R5, lib/inbox/schedules.mjs): a tick that failed or was // held by a cap is money or work waiting on a yes; a finished edition is a // review gate, like a finished iteration. "tick-failed": "spend", "tick-held": "spend", // R6.1: a tick whose scan hit a cap and found nothing — not quiet: the // operator's call (narrow the scope, reset the triage, tick again). "tick-partial": "spend", "edition-ready": "review", // R6: a watch found something: the operator's call, research it or not. "worth-researching": "spend", // R4: a refresh the cap held is money waiting on a yes or no; new // recordings since the current report are something to review. "refresh-held": "spend", "refresh-available": "review", // UI notes item 16: a report video's cited channels are all downloaded and // transcribed -- a re-sweep to review (lib/inbox/sourceWatch.ts). "sources-complete": "review", // Release 29 M8: a model's proposed verdicts for a fact-check's unruled // claims, each waiting on the operator's approve or reject. "verdict-proposed": "review", "unreadable-proposals": "fix", // The redesign's "What needs you" (L4): a rendered version nobody judged, // the draft's clips nobody walked, a research case's new transcripts since // its last scan -- each something to look at; X's login when X work waits // on it -- a fix, like a missing tool. A stale quote check is an open call. "version-unjudged": "review", "clips-unwalked": "review", "case-new-cues": "review", "x-jar-stale": "fix", }; const CATEGORY_GROUP = { spend: "your-call", review: "review", fix: "blocking", note: "notes", choose: "open", finish: "ready-to-finish", info: "quiet", }; /** @param {{ kind: string, severity: string }} d */ export function categoryOf(d) { const named = KIND_CATEGORY[d.kind]; if (named) return named; return d.severity === "blocking" ? "fix" : d.severity === "open" ? "choose" : "info"; } /** @param {{ kind: string, severity: string }} d */ export function groupOf(d) { // Information is quiet whatever its kind: a fact is not a decision. if (d.severity === "info") return "quiet"; return CATEGORY_GROUP[categoryOf(d)]; } // Within a group: the brief's order first (proposals before failed runs), then // everything else as equals. const KIND_RANK = { "worth-researching": 0, "research-proposal": 0, "iteration-failed": 1, "tick-held": 2, "tick-failed": 2, "tick-partial": 2, "iteration-ready": 0, "edition-ready": 0, "drafts-unreviewed": 1, "verdict-proposed": 1, "unreadable-notes": 0, "unreadable-proposals": 0, "refresh-held": 2, "refresh-available": 2, "sources-complete": 2, "version-unjudged": 1, "case-new-cues": 2, "clips-unwalked": 3, "x-jar-stale": 0 }; const SEVERITY_RANK = { blocking: 0, open: 1, info: 2 }; // ONE primary action per decision, its button copy naming the result. const ACTION_LABEL = { "research-proposal": "Approve acquisition", "iteration-failed": "Retry run", "iteration-ready": (d) => `Make ${d.target} current`, "drafts-unreviewed": "Review drafts", "verdict-proposed": "Review verdicts", "unreadable-proposals": "Repair verdicts.proposed.json", "open-note": "Answer note", "unreadable-notes": "Repair notes.json", "link-ambiguous": "Link the video", "looks-done": "Mark done", "tick-failed": "Tick now", "tick-held": "Raise cap", "tick-partial": "See what was missed", "edition-ready": "Review edition", "worth-researching": "Open the board", "claim-unadjudicated": "Adjudicate claim", "claim-incoherent": "Rule on the flag", "clip-no-cues": "Fix the cue source", "clip-unfetchable": "Replace the source", "clip-unchecked": "Re-check later", "clip-mid-sentence": "Trim to the sentence", "clip-cue-gap": "Fix the window", "clip-cut-outside": "Fix the cut", "clip-gap-invalid": "Fix the gaps", "clip-incorrect": "Remove or fix the clip", "clip-rejected": "Take the clip out", "window-overlap": "Fix the windows", "clip-cite-off": "Move the cite to the clip", "patch-markers-stale": "Fix the take patch", "link-dead": "Fix the links", "links-unverified": "Check links again", "links-unchecked": "Check links", "site-deploy-behind": (d) => (d.settle?.kind === "publish-site" ? d.settle.label : "Publish the site"), "clip-link-policy": "Link it by the policy", "no-punctuation": "Check the windows", "manifest-invalid": "Fix the manifest", "stale-build": "Rebuild the video", unbuilt: "Build the video", "storage-unreachable": "Reconnect the media drive", "storage-mismatch": "Settle the storage", "source-status-stale": "Refresh the source status", "unjudged-variant": "Judge variant", "missing-cut": "Ship the cut", "stale-recipe": "Record the recipe", "no-recipe": "Record the recipe", "spec-problem": "Fix the spec", "no-plan": "Name the plan", unattributed: "Attribute variant", "thumb-unaccepted": "Accept a cover", loudness: "Re-render at the target", "shadowed-name": "Rename the project", "unroutable-name": "Rename the project", "ambiguous-project": "Fix the project's files", "refresh-held": "Refresh", "refresh-available": "Refresh", "sources-complete": "Re-sweep", "version-unjudged": "Play and judge", "clips-unwalked": "Walk the clips", "quote-check-stale": "Run quote-check", "case-new-cues": "Scan again", "x-jar-stale": "Refresh X's cookies", }; const CATEGORY_LABEL = { fix: "Fix it", choose: "Decide", info: "Open", spend: "Decide", review: "Review", note: "Answer note", finish: "Mark done" }; /** * The decision's one action: `{ label, href }`. The href is the decision's * own, untouched -- a note's still ends in `note=` (the MCP relies on it). * * @param {{ kind: string, severity: string, target: string, href: string }} d */ export function actionOf(d) { const named = ACTION_LABEL[d.kind]; const label = typeof named === "function" ? named(d) : (named ?? CATEGORY_LABEL[categoryOf(d)]); return { label, href: d.href }; } /** * Add the inbox's fields to each row: `piece`, `category`, `group`, `action`, * `lifecycle`, `hidden`, and -- when hidden -- `hiddenBy`, why: the piece is * `parked` or `done` (its lifecycle, which wins), or this kind of call on it is * `muted` (lib/mutes.mjs). Never drops or merges a row. * * @template {{ kind: string, severity: string, target: string, href: string, project: string }} D * @param {D[]} items * @param {{ * pieceOf: (d: D) => string | null, * lifecycleOf: (piece: string) => string, * isMuted?: (piece: string, kind: string) => boolean, * }} how */ export function annotate(items, { pieceOf, lifecycleOf, isMuted = () => false }) { return items.map((d) => { const piece = d.piece ?? pieceOf(d); const lifecycle = piece ? lifecycleOf(piece) : "active"; const quiet = lifecycle === "parked" || lifecycle === "done"; const muted = !!piece && isMuted(piece, d.kind); const { hiddenBy: _was, ...row } = d; return { ...row, ...(piece ? { piece } : {}), category: categoryOf(d), group: groupOf(d), action: actionOf(d), lifecycle, muted, hidden: quiet || muted, ...(quiet ? { hiddenBy: lifecycle } : muted ? { hiddenBy: "muted" } : {}), }; }); } /** * The inbox's order: visible before hidden, then by group, then the kind's * rank in its group, then severity, then newest first. Stable for equals (by * piece, kind, target), so two reads of the same disk give the same list. */ export function rankDecisions(items) { const g = (d) => GROUP_IDS.indexOf(d.group ?? groupOf(d)); return [...items].sort( (a, b) => Number(!!a.hidden) - Number(!!b.hidden) || g(a) - g(b) || (KIND_RANK[a.kind] ?? 9) - (KIND_RANK[b.kind] ?? 9) || (SEVERITY_RANK[a.severity] ?? 3) - (SEVERITY_RANK[b.severity] ?? 3) || (b.at ?? 0) - (a.at ?? 0) || String(a.piece ?? a.project).localeCompare(String(b.piece ?? b.project)) || a.kind.localeCompare(b.kind) || String(a.target).localeCompare(String(b.target)), ); } /** * The grouped summary, for a page or a terminal: per group, its CARDS (one per * piece and kind -- 483 unadjudicated claims on one video are one card), how * many decisions they hold, and how many are hidden. Rows are counted, never * dropped: `decisions + hidden` over every group is `items.length`. * * @param {Array>} items annotated rows */ export function summarizeGroups(items) { const ranked = rankDecisions(items); const out = GROUPS.map((g) => ({ ...g, decisions: 0, hidden: 0, cards: [] })); const byId = new Map(out.map((g) => [g.id, g])); const cardOf = new Map(); for (const d of ranked) { const group = byId.get(d.group ?? groupOf(d)); if (d.hidden) { group.hidden += 1; continue; } group.decisions += 1; const key = `${group.id}\u0000${d.piece ?? d.project}\u0000${d.kind}`; let card = cardOf.get(key); if (!card) { card = { piece: d.piece ?? null, project: d.project, title: d.projectTitle ?? d.project, kind: d.kind, severity: d.severity, count: 0, why: d.why, // A decision that names its own card title (drafts: "Narration draft · // 5 fields"); else the page labels the card by its kind. what: d.what ?? null, action: d.action ?? actionOf(d), at: d.at ?? 0, // The one-press settle the card offers in place (L4), when its rows agree on one. settle: d.settle ?? null, }; cardOf.set(key, card); group.cards.push(card); } else card.settle = mergeSettle(card.settle, d.settle ?? null); card.count += 1; if ((SEVERITY_RANK[d.severity] ?? 3) < (SEVERITY_RANK[card.severity] ?? 3)) card.severity = d.severity; card.at = Math.max(card.at, d.at ?? 0); } return out; } /** * The settle a CARD offers for all its rows (umtool redesign L4: one-click * actions in the Inbox), from two rows' (lib/decisions.ts `settle`): a quote * check runs on every clip either names; the same project-wide settle (a link * check, a publish) is kept; anything else -- two clip patches, two different * presses -- is no settle, and the card's link is the way. A row without one * leaves the card without one. * * @param {Record | null} a * @param {Record | null} b */ export function mergeSettle(a, b) { if (!a || !b) return null; if (a.kind === "quote-check" && b.kind === "quote-check") { return { ...a, clips: [...new Set([...(a.clips ?? []), ...(b.clips ?? [])])] }; } if (a.kind === "patch" || b.kind === "patch") return null; return JSON.stringify(a) === JSON.stringify(b) ? a : null; }