// `umtool schedule` -- the recurring reports, from a terminal (R5). // // TypeScript, because the schedules are common's (lib/report/schedule/) and // umtool's reading of them is lib/schedules.ts: bin/umtool.mjs runs this file // through tsx, from umtool/ (the `@/` paths). Read-only: a schedule is // written through the editor (`pnpm ops report-schedule`), never here. // // umtool schedule list [--json] every schedule: its chip, its last tick, its spend // umtool schedule show [--json] one: its scope, its editions, its tick log import { readScheduleView, readSchedules } from "../lib/schedules"; import type { ScheduleView } from "../lib/schedule-types"; const args = process.argv.slice(2); const json = args.includes("--json"); const [sub, id] = args.filter((a) => !a.startsWith("--")); const usd = (n: number) => `$${n.toFixed(2)}`; function line(v: ScheduleView): string { const last = v.ticks.at(-1); const call = v.call ? ` ← your call: ${v.call.status}${v.call.reason ? ` (${v.call.reason})` : ""}` : ""; return `${v.shape.padEnd(7)} ${v.id.padEnd(32)} ${v.chip.padEnd(30)} ${(last ? `${last.status} ${last.at.slice(0, 16)}` : "never ticked").padEnd(28)} ${usd(v.spentUsd)}${v.running ? ` ticking (job ${v.running.jobId})` : ""}${call}`; } if (sub === "list" || sub === undefined) { const { schedules, problems } = await readSchedules(); if (json) { console.log(JSON.stringify({ schedules, problems }, null, 2)); } else { if (!schedules.length) console.log("no recurring reports (make one in Create, or `pnpm ops report-schedule`)"); for (const v of schedules) console.log(line(v)); for (const p of problems) console.log(`! ${p.id}: ${p.problem}`); } process.exit(problems.length ? 1 : 0); } if (sub === "show") { if (!id) { console.error("which schedule? `umtool schedule show `"); process.exit(2); } const r = await readScheduleView(id); if (!r) { console.error(`no schedule "${id}"`); process.exit(1); } if ("problem" in r) { console.error(`the schedule "${id}" does not read: ${r.problem}`); process.exit(1); } const v = r.view; if (json) { console.log(JSON.stringify(v, null, 2)); process.exit(0); } console.log(`${v.topic} (${v.shape} ${v.id})`); console.log(` ${v.chip} · ${v.cadenceWords} (${v.tz})${v.paused ? " · paused" : ""}`); console.log(` question ${v.question}`); console.log(` channels ${v.scope.channels.join(", ")}${v.scope.case ? ` (board ${v.scope.case})` : ""}`); if (v.scope.terms) console.log(` terms ${v.scope.terms}`); if (v.shape === "living") console.log(` article ${v.article ?? v.id}${v.autoMakeCurrent ? " (made current automatically)" : ""}`); console.log(` spent ${usd(v.spentUsd)} over ${v.ticks.length} tick${v.ticks.length === 1 ? "" : "s"}`); if (v.running) console.log(` ticking job ${v.running.jobId} (${v.running.trigger}, since ${v.running.at})`); if (v.editions?.length) { console.log("\n editions, newest first"); for (const e of [...v.editions].reverse()) { console.log(` #${String(e.n).padEnd(3)} ${e.status.padEnd(11)} ${e.window.from} … ${e.window.to} ${usd(e.usd).padStart(7)} ${e.article ?? "(quiet: no article)"} ${e.title}`); } } if (v.ticks.length) { console.log("\n ticks, newest first"); for (const t of [...v.ticks].reverse().slice(0, 20)) { console.log(` ${t.at.slice(0, 16)} ${t.trigger.padEnd(8)} ${t.status.padEnd(12)} ${usd(t.usd).padStart(7)} ${t.reason ?? ""}`); } } process.exit(0); } console.error(`unknown: umtool schedule ${sub} — list | show `); process.exit(2);