// `umtool source-status [ls] [--json]` // `umtool source-status refresh [--dry-run] [--json]` // // THE SOURCE STATUS STAMP (lane source-status): what became of each recording a // project cites -- now private, members-only or deleted, and whether the archive's // records prove it was public at first -- written into the manifest's // `sourceStatus` so the deck's source line can say it (`deck.subtitle.status`, // umtool-report-to-video/source-status.mjs). A render reads only this stamp. // // ls each cited source, its stamped words, its state and when that was true // refresh reads each source's records -- the project's channels tree, then the // corpus behind it (common lib/sourceStatus-server.mjs: availability.json, // download-outcome.json, metadata.info.json, metadata.history.json, // live-recording.json; READ ONLY) -- else the published archive's record // (`state`, `stateSince`: the first state is not published, so no // parenthesis; its index re-read, not the cue cache's copy). Never a // platform. MERGED into the last stamp (mergeSourceEntry): a source it // cannot read keeps what the last refresh knew, an older reading never // replaces a newer one, and a corpus reading and an archive one that // disagree with no provable order draw nothing. One write to the draft, // one undo point, only when the stamp changed. // // Exit 0 done, 1 refused, 2 a usage error. Plain ESM: the CLI runs it under bare node. import { stat } from "node:fs/promises"; import { newestSourceRecordMs, readSourceStatus } from "yt-dlp-transcript-common/lib/sourceStatus-server.mjs"; import { resolveVideoDir } from "yt-dlp-transcript-common/lib/videoDir-server.mjs"; import { manifestSources } from "umtool-report-to-video/manifest-sources"; import { SOURCE_STATUS_STALE_DAYS, sourceStatusNotes, sourceStatusText, statusSourceKeys, subtitleStatusOn, } from "umtool-report-to-video/source-status"; import { presetManifest } from "umtool-report-to-video/presets"; import { REPORTS_ROOT, resolveProject } from "../projects/core.mjs"; import { channelsLayersFor, hasShadowChannels, readManifest } from "../projects/report.mjs"; import { withEditNotes } from "./edit-guard.mjs"; import { StaleToken, StructureRefused, manifestToken, structuralEdit } from "./manifest.mjs"; class CliError extends Error {} export const SOURCE_STATUS_USAGE = [ "usage: umtool source-status [ls] [--json]", " umtool source-status refresh [--dry-run] [--json]", " WHAT BECAME OF EACH CITED SOURCE: refresh stamps the manifest's sourceStatus from the archive's records (the", " corpus, else the published record; never a platform), which the deck's source line reads when", " deck.subtitle.status is \"end\" (umtool look

deck.subtitle.status=end): \"now private (public when streamed)\".", " Merged into the last stamp: a source it cannot read keeps its entry. One write, one undo point, only when", " the stamp changed. ls prints the stamp.", ].join("\n"); const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); /** * A published record's `state` as the stamp's `now` (availability.ts summaryState * for a record with none: the legacy `isDeleted` / `isUnlisted`, else still public * there). The archive's "deleted" is buildIndex's effective reading, a download's * loose class included (common lib/sourceStatus.mjs), so it draws nothing; a state * this does not know draws nothing. * * @returns {{ now: string|null, why?: string, state: string }} */ export function archiveReading(r) { const state = typeof r?.state === "string" && r.state ? r.state : r?.isDeleted ? "deleted" : r?.isUnlisted ? "unlisted" : "available"; const now = { available: "public", unlisted: "unlisted", private: "private", members_only: "members_only" }; if (Object.hasOwn(now, state)) return { now: now[state], state }; if (state === "deleted") { return { now: null, state, why: "the archive's deleted is its effective reading, a download's loose class included: a removal is drawn only from a check the corpus holds" }; } return { now: null, state, why: `the archive's state "${state}" is not one the line names` }; } /** A YYYYMMDD day as an ISO instant (its UTC midnight), else null. */ const dayIso = (d) => (typeof d === "string" && /^\d{8}$/.test(d) ? `${d.slice(0, 4)}-${d.slice(4, 6)}-${d.slice(6, 8)}T00:00:00.000Z` : null); /** The first video directory that exists for `/

refresh)"}`); for (const row of rows) { const state = row.stamped ? `${row.now ?? "no record"}${row.asOf ? ` as of ${row.asOf.slice(0, 10)}` : ""}` : "not stamped"; out(` ${row.key.padEnd(40)} ${state.padEnd(30)} ${row.words || "—"}${row.stale ? " (stale)" : ""}`); } return 0; } if (verb !== "refresh") throw new CliError(`unknown: source-status ${verb} — ls or refresh`); const shadowExists = await hasShadowChannels(project.dir); const layers = channelsLayersFor(project.dir, m, { shadowExists }); const reader = archive === undefined ? await archiveReaderFor(m) : archive; const { sources: fresh, unresolved } = await collectSourceStatus({ manifest: m, layers, archive: reader }); const prior = isObj(m.sourceStatus?.sources) ? m.sourceStatus.sources : null; const sources = mergeSourceStatus(prior, fresh, manifestSources(m).map((w) => w.key)); // Nothing read and nothing stamped before: no stamp to write (an empty one would say "refreshed"). const changed = !(prior === null && Object.keys(sources).length === 0) && !sameSources(prior, sources); let result = null; if (changed && !flags.has("dry-run")) { const refreshedAt = new Date(now()).toISOString(); const res = await withEditNotes(project, async () => structuralEdit(project.dir, "source-status", token, (mm) => { mm.sourceStatus = { refreshedAt, sources }; return { refreshedAt }; })); result = res.result; } const rows = sourceStatusRows({ ...m, sourceStatus: { refreshedAt: "", sources } }, { now: now() }); if (json) { out(JSON.stringify({ ok: true, project: project.id, on, changed, written: Boolean(result), dryRun: flags.has("dry-run"), sources: rows, unresolved }, null, 2)); } else { for (const row of rows) out(` ${row.key.padEnd(40)} ${String(row.now ?? "no record").padEnd(14)} ${row.words || "—"}`); for (const u of unresolved) out(` ${u.key.padEnd(40)} unresolved: ${u.why}`); out(!changed ? "unchanged" : flags.has("dry-run") ? "would write the stamp (dry run)" : "stamp written"); if (result?.snapshot?.rel && !result.snapshot.skipped) out(` undo point: ${result.snapshot.rel}`); if (!on) out(" the deck does not draw it yet: umtool look

deck.subtitle.status=end"); } return 0; } catch (e) { if (e instanceof StructureRefused) err(`umtool source-status: refused — the build would not take it:\n${e.errors.map((x) => ` ${x}`).join("\n")}`); else if (e instanceof StaleToken) err(`umtool source-status: ${e.message} — somebody else wrote it; run it again`); else err(`umtool source-status: ${e instanceof Error ? e.message : String(e)}`); return e instanceof CliError ? 2 : 1; } }