// TAKE HOUSEKEEPING (UI notes 2026-10-30, item 19): wrong labels ("draft 9…" // on draft-10), cancelled and superseded takes left in the list. // // relabel take.json's label takeEdit.mjs relabelTake // supersede verdicts.json's `superseded` takes.mjs setTakeSuperseded // delete takes// whole delete.mjs planTakeDelete / deleteTake // // What a running render names is respected by all three, through one reader // (renderHolds): a take whose own build lock (`takes//.building.json`, // takePrune.mjs) is live is RENDERING -- its take.json is written last, from // the label it started with, and its directory is its output -- and a take // another live build names as its `from` is that build's base. A relabel or a // delete is refused for either, in words; a supersede mark (verdicts.json, // which no render writes) is not. // // Plain ESM: the CLI runs it under bare node. import { readdir } from "node:fs/promises"; import path from "node:path"; import { BUILD_LOCK, lockIsLive, readBuildLock } from "./takePrune.mjs"; import { isTakeId, listTakes, readVerdicts, takesDirOf } from "./takes.mjs"; /** * Every reason a running render has to keep take `takeId` as it is: its own * live build, and any live build made from it. [] when none. * * @param {string} projectDir * @param {string} takeId * @param {{ host?: string, alive?: (pid: number) => boolean }} [opts] for tests * @returns {Promise} */ export async function renderHolds(projectDir, takeId, opts = {}) { if (!isTakeId(takeId)) return []; const root = takesDirOf(projectDir); const holds = []; const live = (lock) => lockIsLive(lock, opts.host || opts.alive ? { ...(opts.host ? { host: opts.host } : {}), ...(opts.alive ? { alive: opts.alive } : {}) } : undefined); const own = await readBuildLock(path.join(root, takeId, BUILD_LOCK)); if (own && live(own)) holds.push(`it is rendering now (pid ${own.pid}${own.startedAt ? `, since ${own.startedAt}` : ""}) — wait for it, or cancel it`); const names = await readdir(root).catch(() => []); for (const n of names) { if (n === takeId || !isTakeId(n)) continue; const lock = await readBuildLock(path.join(root, n, BUILD_LOCK)); if (lock && lock.from === takeId && live(lock)) holds.push(`take ${n} is being rendered from it (pid ${lock.pid})`); } return holds; } /** * The takes as `umtool takes ls` prints them: id, label, built, picked, * superseded (and by what), rendering now. * * @param {string} projectDir */ export async function takesOverview(projectDir) { const [listing, verdicts] = await Promise.all([listTakes(projectDir), readVerdicts(projectDir)]); const rows = []; for (const t of listing.takes) { const v = verdicts[t.id]; const holds = await renderHolds(projectDir, t.id); rows.push({ id: t.id, label: t.label, group: t.group, seconds: t.seconds, builtAt: t.builtAt, draft: t.draft, verdict: v?.verdict ?? null, picked: v?.picked === true, pinned: v?.pinned === true, superseded: v?.superseded ?? null, rendering: holds.some((h) => h.startsWith("it is rendering")), base: holds.some((h) => !h.startsWith("it is rendering")), holds, }); } return { rows, skipped: listing.skipped }; } /** One line of `umtool takes ls`. */ export function takeLine(r) { const marks = [ r.latest ? "latest" : null, r.picked ? (r.pinned ? "picked, pinned" : "picked") : null, r.superseded ? `superseded${r.superseded.by ? ` by ${r.superseded.by}` : ""}` : null, r.draft ? "draft" : null, r.rendering ? "RENDERING" : null, r.base ? "a render is made from it" : null, r.verdict, ].filter(Boolean); return `${r.id.padEnd(14)} ${typeof r.seconds === "number" ? `${r.seconds.toFixed(1)}s`.padStart(8) : " "} ${r.label}${marks.length ? ` [${marks.join(", ")}]` : ""}`; }