// What got done: the last few days' work from CLIDE's records, `clide tickets` and `clide history`: tickets done, // tickets stuck and on what, the rest still open, and tool runs that failed. It reads and changes nothing. Run it from // its form in CLIDE, or here, with the clide command installed: // bun what-got-done.ts --days 7 import { parseArgs } from "node:util"; // CLIDE tells every run where its own `clide` command is (CLIDE_COMMAND, run with its Bun); from a terminal, it's // `clide` on the PATH, once Settings has installed it. /** What `clide --json` printed, parsed; it exits with a plain message when there's no `clide` to ask. */ async function clide(args: string[]): Promise { const command = process.env.CLIDE_COMMAND ? [process.execPath, process.env.CLIDE_COMMAND] : Bun.which("clide") ? ["clide"] : null; if (!command) { console.error("Run this from CLIDE, or install the clide command from CLIDE's Settings to run it here."); process.exit(7); } const done = Bun.spawnSync([...command, ...args, "--json"], { stdout: "pipe", stderr: "pipe" }); const text = done.stdout.toString(); let answer: { ok?: boolean; message?: string } & T; try { answer = JSON.parse(text); } catch { console.error(`clide ${args.join(" ")} didn't answer as it should: ${done.stderr.toString().trim() || text.trim()}`); process.exit(1); } if (answer.ok === false) { console.error(answer.message ?? `clide ${args.join(" ")} failed.`); process.exit(1); } return answer; } const { values } = parseArgs({ args: process.argv.slice(2), options: { days: { type: "string", default: "7" } } }); const days = String(Math.max(1, Math.round(Number(values.days) || 7))); type Ticket = { task: string; title: string; summary: string | null; completedAt: string | null; done: number; skipped: number; total: number; blocked: boolean; overdue: boolean; due: string | null; heldBy: string | null; openIssues: { says: string; tool?: string; error?: string }[] }; type Run = { tool: string; startedAt: string; status: string; message?: string }; const { tickets } = await clide<{ tickets: Ticket[] }>(["tickets", "--since", days]); const { runs } = await clide<{ runs: Run[] }>(["history", "--since", days, "--failed"]); const name = (ticket: Ticket) => `${ticket.title}${ticket.summary ? ` (${ticket.summary})` : ""}`; const done = tickets.filter((ticket) => ticket.completedAt !== null); const stuck = tickets.filter((ticket) => ticket.completedAt === null && (ticket.blocked || ticket.openIssues.length > 0)); const open = tickets.filter((ticket) => ticket.completedAt === null && !stuck.includes(ticket)); const section = (title: string, lines: string[]) => [`## ${title} (${lines.length})`, ...(lines.length === 0 ? ["None."] : lines), ""]; console.log( [ `# What got done in the last ${days} day${days === "1" ? "" : "s"}, to ${new Date().toLocaleDateString()}`, "", ...section("Done", done.map((ticket) => `- ${name(ticket)}, ${new Date(ticket.completedAt!).toLocaleDateString()}`)), ...section( "Stuck", stuck.map((ticket) => [`- ${name(ticket)}: ${ticket.done + ticket.skipped} of ${ticket.total} done${ticket.heldBy ? `, with ${ticket.heldBy}` : ""}`, ...ticket.openIssues.map((issue) => ` - ${issue.says}${issue.error ? `: ${issue.error}` : ""}`)].join("\n")), ), ...section("Still open", open.map((ticket) => `- ${name(ticket)}: ${ticket.done + ticket.skipped} of ${ticket.total} done${ticket.overdue ? ", overdue" : ticket.due ? `, due ${ticket.due}` : ""}${ticket.heldBy ? `, with ${ticket.heldBy}` : ""}`)), ...section("Runs that failed", runs.map((run) => `- ${run.tool}, ${new Date(run.startedAt).toLocaleString()}: ${run.status}${run.message ? `, ${run.message}` : ""}`)), ] .join("\n") .trim(), );