// `umtool inbox` -- the inbox's grouped list, from a terminal (lib/inbox.ts). // // TypeScript, because the inbox is: the song reducer, the article side and the // iteration readers are the app's own modules, and printing them from a second // implementation is the thing lib/projects/core.mjs exists to avoid. So // bin/umtool.mjs runs this file through tsx, from umtool/ (the `@/` paths). // // umtool inbox [--all] [--json] // // Per group: its cards (one per piece and kind), the decisions they hold, and // how many are hidden on parked or done pieces. `--all` lists the hidden ones // too, and the quiet group's cards. Read-only. import { readInbox, type GroupCard, type GroupSummary } from "../lib/inbox"; import { summarizeGroups } from "../lib/inbox/groups.mjs"; const args = process.argv.slice(2); const all = args.includes("--all"); const json = args.includes("--json"); const inbox = await readInbox(); const visible = inbox.items.filter((d) => !d.hidden); if (json) { console.log( JSON.stringify( { groups: inbox.groups, hidden: inbox.hidden, decisions: visible.length, ...(inbox.lifecycleError ? { lifecycleError: inbox.lifecycleError } : {}), ...(all ? { items: inbox.items } : {}), }, null, 2, ), ); process.exit(0); } const clip = (s: string, n = 110) => (s.length > n ? `${s.slice(0, n - 1)}…` : s); const card = (c: GroupCard) => ` ${c.severity === "blocking" ? "BLOCKING " : ""}${c.piece ?? c.project} ${c.kind}${c.count > 1 ? ` ×${c.count}` : ""}` + `\n ${clip(c.why)}\n → ${c.action.label} ${c.action.href}`; // The hidden rows, carded as if visible, for --all. const hiddenGroups = all ? (summarizeGroups(inbox.items.filter((d) => d.hidden).map((d) => ({ ...d, hidden: false }))) as GroupSummary[]) : []; let cards = 0; for (const g of inbox.groups) { if (!g.decisions && !g.hidden) continue; cards += g.cards.length; const hidden = g.hidden ? ` · ${g.hidden} hidden` : ""; console.log(`\n## ${g.label} — ${g.cards.length} card${g.cards.length === 1 ? "" : "s"}, ${g.decisions} decision${g.decisions === 1 ? "" : "s"}${hidden}`); if (g.collapsed && !all) { if (g.decisions) console.log(" (collapsed; --all lists it)"); } else { for (const c of g.cards) console.log(card(c)); } const h = hiddenGroups.find((x) => x.id === g.id); if (h?.cards.length) { console.log(" hidden (parked or done):"); for (const c of h.cards) console.log(card(c).replace(/^ {2}/gm, " ")); } } console.log( `\n${visible.length} decision${visible.length === 1 ? "" : "s"} in ${cards} card${cards === 1 ? "" : "s"}` + (inbox.hidden ? ` · ${inbox.hidden} hidden on parked or done pieces${all ? "" : " (--all lists them)"}` : ""), ); if (inbox.lifecycleError) console.log(`lifecycle: ${inbox.lifecycleError} — every piece reads as active`);