commit cfccf67e9efc30c168e80673d348b4845fd4835b
parent 571c1a96d4ba203d9742a01cff86a77eca29eabd
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 2 Nov 2026 13:43:52 -0500
umtool fetch --take: a take's clips asked of the editor as the cut's are (one fetch-windows batch, recorded in fetch-runs.json with `take`), from the take's manifest -- a clip only the take has is fetched, a draft needs no render; the cut's last run never reads a take's; export --fetch on a take asks with the take's manifest, not the project's under the take's name
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
6 files changed, 199 insertions(+), 32 deletions(-)
diff --git a/umtool/app/api/report/clip-export/route.ts b/umtool/app/api/report/clip-export/route.ts
@@ -58,9 +58,9 @@ export async function POST(request: Request) {
if (running) return Response.json({ error: `a job is already running (${running.kind}) — export when it is done`, running: jobView(running) }, { status: 409, headers });
let manifestPath: string | null = null;
if (take && !need.held) {
- const { writePlayManifest } = await import("@/lib/report/takeManifest.mjs");
- const { readManifest } = await import("@/lib/projects/report.mjs");
- manifestPath = await writePlayManifest(project.dir, take, await readManifest(project.dir));
+ // The take's own manifest (a take-only clip, a take's bounds), never the project's under the take's name.
+ const { resolveTakeManifest, writePlayManifest } = await import("@/lib/report/takeManifest.mjs");
+ manifestPath = await writePlayManifest(project.dir, take, (await resolveTakeManifest(project.dir, take)).manifest);
}
const steps = await exportSteps(project, clip, {
take,
diff --git a/umtool/bin/umtool.mjs b/umtool/bin/umtool.mjs
@@ -783,8 +783,10 @@ async function runFetchViaEditor(p, clipId, need, { take = null } = {}) {
const { editorFetchSteps } = await import("../lib/report/driver.mjs");
let manifestPath = null;
if (take) {
- const { writePlayManifest } = await import("../lib/report/takeManifest.mjs");
- manifestPath = await writePlayManifest(p.dir, take, await readManifest(p.dir));
+ // The TAKE's manifest (its walk's: the project's now with the take's patches), so a clip only
+ // the take has -- or the take's own bounds for a clip of the cut's id -- is what is asked for.
+ const { resolveTakeManifest, writePlayManifest } = await import("../lib/report/takeManifest.mjs");
+ manifestPath = await writePlayManifest(p.dir, take, (await resolveTakeManifest(p.dir, take)).manifest);
}
const [step] = editorFetchSteps(p, clipId, { padBefore: need.padBefore, padAfter: need.padAfter }, { manifestPath });
const { spawn } = await import("node:child_process");
diff --git a/umtool/lib/report/clipExport.mjs b/umtool/lib/report/clipExport.mjs
@@ -393,15 +393,20 @@ export async function exportNeeds(project, clipId, { take = null, kind = "cut",
const e = got.entry;
if (kind === "cut") return { entry: e, want: null, held: !!got.source, padBefore: 0, padAfter: 0 };
const want = exportSpan(e, got.render, { kind, context, span });
- const held = !!(await heldWindow(project, e, want));
+ const held = !!(await heldWindow(project, e, want, take));
const pad = (v) => Math.min(EXPORT_CONTEXT.max, Math.max(0, Math.ceil(v)));
return { entry: e, want, held, padBefore: pad(e.start - want.from), padAfter: pad(want.to - e.end) };
}
-/** The tightest cached window of the clip's recording holding [want.from, want.to] (projectCache: out/clips-raw and the corpus's windows). */
-async function heldWindow(project, entry, want) {
+/**
+ * The tightest cached window of the clip's recording holding [want.from, want.to] (projectCache: out/clips-raw and the corpus's windows).
+ * A take's clip is looked up through the TAKE's manifest: the corpus dirs listed are its clips' videos, and a clip only the take has
+ * cites a recording the cut may not.
+ */
+async function heldWindow(project, entry, want, take = null) {
const { projectCache } = await import("./serve.mjs");
- const cache = await projectCache(project);
+ const manifest = take ? (await (await import("./takeManifest.mjs")).resolveTakeManifest(project.dir, take)).manifest : null;
+ const cache = await projectCache(project, manifest);
return cache.containing(entry.video, want.from + 0.02, want.to - 0.02) ?? null;
}
diff --git a/umtool/lib/report/fetchCli.mjs b/umtool/lib/report/fetchCli.mjs
@@ -10,6 +10,8 @@
// … [--reason "…"] the provenance reason (default: "<title> montage", or the title)
// … --refetch <clipId>[,<clipId>…] evict those clips' cached windows first (the editor's evict-clips,
// --refetch-video <slug>/<id> `covering` their fetch spans), then fetch as usual
+// … --take <id> a TAKE's clips (its walk's manifest; a draft's too), the run
+// recorded with `take` in fetch-runs.json
import { REPORTS_ROOT, resolveProject } from "../projects/core.mjs";
import {
EditorError,
@@ -40,6 +42,8 @@ export const FETCH_USAGE = [
" … --refetch <clipId>[,<clipId>…] evict the cached windows overlapping those clips' fetch spans first",
" … --refetch-video <slug>/<id> the same for every window this project asks of that video",
" (the editor's evict-clips; with --dry-run the eviction is a dry run too and nothing is deleted)",
+ " … --take <id> a take's clips instead of the cut's: the take's manifest as its walk reads it (a draft's",
+ " too — nothing rendered), so a clip only the take has is fetched; --status follows its last run",
"",
`Every run is recorded in <project>/${FETCH_RUNS_FILE}; \`umtool fallback\` reads it for the refused windows.`,
"The editor: ARCHILYZER_EDITOR_URL (default http://localhost:3001), WORKER_TOKEN (else the editor's env files).",
@@ -77,12 +81,20 @@ export async function fetchCommand(args, { root = REPORTS_ROOT, out = (s) => con
const json = args.includes("--json");
const words = [];
let reason = null;
+ let take = null;
const refetchClips = [];
const refetchVideos = [];
for (let i = 0; i < args.length; i += 1) {
if (args[i] === "--reason") {
reason = args[i + 1] ?? "";
i += 1;
+ } else if (args[i] === "--take") {
+ take = args[i + 1] ?? "";
+ i += 1;
+ if (!take || take.startsWith("--")) {
+ err(`--take needs a take id\n${FETCH_USAGE}`);
+ return 2;
+ }
} else if (args[i] === "--refetch" || args[i] === "--refetch-video") {
const v = args[i + 1];
if (!v || v.startsWith("--")) {
@@ -103,31 +115,43 @@ export async function fetchCommand(args, { root = REPORTS_ROOT, out = (s) => con
if (r.ambiguous) throw new CliError(`"${projectArg}" is the name of ${r.ambiguous.length} projects — pass its id`);
if (!r.project) throw new CliError(`no project matches "${projectArg}"`);
const project = r.project;
+ const who = take ? `${project.id} take ${take}` : project.id;
+ if (take) {
+ const { isTakeId } = await import("./takes.mjs");
+ if (!isTakeId(take)) throw new CliError(`"${take}" is not a take id`);
+ }
if (args.includes("--status")) {
- const run = lastStartedRun(await readFetchRuns(project.dir));
- if (!run) throw new CliError(`${project.id} has no started fetch run in ${FETCH_RUNS_FILE}`);
+ const run = lastStartedRun(await readFetchRuns(project.dir), { take });
+ if (!run) throw new CliError(`${who} has no started fetch run in ${FETCH_RUNS_FILE}`);
const states = await followRun(cfg, project.dir, run);
// A run that has ended landed what it landed: the bench's prep for it.
if (states.length && states.every((st) => TERMINAL.has(st.status)) && states.some((st) => st.status === "done")) {
- benchPrepAfterWrite(project.dir, null, { excerptsOnly: false });
+ benchPrepAfterWrite(project.dir, null, { excerptsOnly: false, take });
}
- if (json) out(JSON.stringify({ project: project.id, run: { at: run.at, jobIds: run.jobIds }, jobs: states }, null, 2));
+ if (json) out(JSON.stringify({ project: project.id, ...(take ? { take } : {}), run: { at: run.at, jobIds: run.jobIds }, jobs: states }, null, 2));
else {
- out(`${project.id}: the run of ${run.at}`);
+ out(`${who}: the run of ${run.at}`);
for (const st of states) out(stateLine(st));
for (const st of states) for (const f of st.failed ?? []) out(` ✗ ${f.clipId ?? `${f.slug}/${f.id}`}: ${f.class} — ${f.message}`);
}
return 0;
}
- const { body, skipped } = await projectFetchBody(project, { reason });
+ let fetched;
+ try {
+ fetched = await projectFetchBody(project, { reason, take });
+ } catch (e) {
+ if (take) throw new CliError(`${project.id}: ${e instanceof Error ? e.message : String(e)}`);
+ throw e;
+ }
+ const { body, skipped } = fetched;
if (args.includes("--body")) {
out(JSON.stringify(body, null, 1));
return 0;
}
if (!body.items.length) {
- out(`${project.id}: no clip windows to fetch${skipped.length ? ` (${skipped.length} skipped)` : ""}`);
+ out(`${who}: no clip windows to fetch${skipped.length ? ` (${skipped.length} skipped)` : ""}`);
return 0;
}
const dryRun = args.includes("--dry-run");
@@ -157,27 +181,27 @@ export async function fetchCommand(args, { root = REPORTS_ROOT, out = (s) => con
if (dryRun && !json) out(" (a dry run evicts nothing, so those windows still read as cached below)");
}
const answer = await postFetchWindows(cfg, body, { dryRun });
- const run = await recordFetchRun(project.dir, { body, answer, refetch });
+ const run = await recordFetchRun(project.dir, { body, answer, refetch, take });
const summary = summarizeAnswer(answer);
if (!dryRun && !args.includes("--wait")) {
- if (json) out(JSON.stringify({ project: project.id, items: body.items.length, skipped, ...(refetch ? { refetch } : {}), ...summary }, null, 2));
+ if (json) out(JSON.stringify({ project: project.id, ...(take ? { take } : {}), items: body.items.length, skipped, ...(refetch ? { refetch } : {}), ...summary }, null, 2));
else {
- out(`${project.id}: ${body.items.length} window(s) asked${skipped.length ? `, ${skipped.length} skipped` : ""}`);
+ out(`${who}: ${body.items.length} window(s) asked${skipped.length ? `, ${skipped.length} skipped` : ""}`);
for (const l of summaryLines(summary)) out(l);
}
return summary.refused.length && !summary.jobs.length ? 1 : 0;
}
if (dryRun) {
- if (json) out(JSON.stringify({ project: project.id, items: body.items.length, skipped, ...(refetch ? { refetch } : {}), ...summary }, null, 2));
+ if (json) out(JSON.stringify({ project: project.id, ...(take ? { take } : {}), items: body.items.length, skipped, ...(refetch ? { refetch } : {}), ...summary }, null, 2));
else {
- out(`${project.id}: ${body.items.length} window(s) — the dry run${skipped.length ? ` (${skipped.length} skipped: ${skipped.map((s) => `${s.clipId} ${s.why}`).join(", ")})` : ""}`);
+ out(`${who}: ${body.items.length} window(s) — the dry run${skipped.length ? ` (${skipped.length} skipped: ${skipped.map((s) => `${s.clipId} ${s.why}`).join(", ")})` : ""}`);
for (const l of summaryLines(summary)) out(l);
}
return 0;
}
// --wait: follow every job to its end.
if (!json) {
- out(`${project.id}: ${body.items.length} window(s) asked`);
+ out(`${who}: ${body.items.length} window(s) asked`);
for (const l of summaryLines(summary)) out(l);
}
let states = [];
@@ -195,9 +219,9 @@ export async function fetchCommand(args, { root = REPORTS_ROOT, out = (s) => con
await sleep(pollMs);
}
// What landed, prepared for the walk (a runner in the background; bin/umtool.mjs waits for the queueing only).
- if (states.some((st) => st.status === "done")) benchPrepAfterWrite(project.dir, null, { excerptsOnly: false });
+ if (states.some((st) => st.status === "done")) benchPrepAfterWrite(project.dir, null, { excerptsOnly: false, take });
const failed = states.flatMap((st) => st.failed ?? []);
- if (json) out(JSON.stringify({ project: project.id, items: body.items.length, skipped, ...(refetch ? { refetch } : {}), ...summary, jobsEnded: states }, null, 2));
+ if (json) out(JSON.stringify({ project: project.id, ...(take ? { take } : {}), items: body.items.length, skipped, ...(refetch ? { refetch } : {}), ...summary, jobsEnded: states }, null, 2));
else {
for (const f of failed) out(` ✗ ${f.clipId ?? `${f.slug}/${f.id}`}: ${f.class} — ${f.message}`);
if (failed.length) out(`${failed.length} window(s) failed — \`umtool fallback ${project.id} --dry-run\` finds a stand-in for each refused one`);
diff --git a/umtool/lib/report/fetchTake.test.mjs b/umtool/lib/report/fetchTake.test.mjs
@@ -0,0 +1,116 @@
+// `umtool fetch <p> --take <id>`: a take's clips asked of the editor as the
+// cut's are -- one fetch-windows batch, recorded in fetch-runs.json -- from
+// the take's manifest as its walk reads it, so a DRAFT take (nothing
+// rendered) whose clip is only in its patch is fetched with no hand JSON.
+//
+// Run with: pnpm test:scripts
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
+import os from "node:os";
+import path from "node:path";
+
+const root = await mkdtemp(path.join(os.tmpdir(), "umtool-fetch-take-"));
+process.env.REPORTS_DIR = root;
+process.env.UMTOOL_CACHE_DIR = path.join(root, ".cache");
+delete process.env.UMTOOL_BENCH_PREP;
+const { lastStartedRun, projectFetchBody, readFetchRuns } = await import("./fetchWindows.mjs");
+const { fetchCommand } = await import("./fetchCli.mjs");
+const trigger = await import("./benchPrepTrigger.mjs");
+test.after(() => rm(root, { recursive: true, force: true }));
+
+const clip = (id, video, start, end) => ({ type: "clip", id, channel: "chan", video, start, end });
+const MANIFEST = { slug: "p", title: "In her words", provenance: { channelSlug: "chan" }, render: { fetchPad: 3 }, timeline: [clip("kf3", "vid", 10, 14)] };
+const TAKE = {
+ id: "spin",
+ group: "takes",
+ order: 1,
+ label: "Spin-off",
+ kind: "different",
+ summary: "",
+ changes: [],
+ preview: "preview.mp4",
+ seconds: null,
+ builtAt: null,
+ style: null,
+ window: null,
+ draft: true,
+ draftedAt: "2026-11-02T12:00:00.000Z",
+ // Its own timeline: the cut's kf3 widened, and ke1 only the take has.
+ patch: { timeline: [clip("kf3", "vid", 8, 20), clip("ke1", "vnew", 100, 110)] },
+};
+const dir = path.join(root, "folder", "p");
+
+/** A fake editor: routes -> answers, every request recorded. */
+function fakeEditor(routes) {
+ const seen = [];
+ const f = async (url, init = {}) => {
+ const u = new URL(url);
+ const key = `${init.method ?? "GET"} ${u.pathname}`;
+ seen.push({ key, body: init.body ? JSON.parse(init.body) : null });
+ const r = typeof routes[key] === "function" ? routes[key](init.body ? JSON.parse(init.body) : null) : routes[key];
+ if (!r) return new Response(JSON.stringify({ ok: false, error: "not found" }), { status: 404 });
+ return new Response(JSON.stringify(r), { status: 200, headers: { "content-type": "application/json" } });
+ };
+ return { fetch: f, seen };
+}
+
+test("fetch --take: the take's clips (a draft's), one batch, the run recorded as the take's; the cut's last run is not it", async () => {
+ await mkdir(path.join(dir, "takes", "spin"), { recursive: true });
+ await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(MANIFEST, null, 2));
+ await writeFile(path.join(dir, "takes", "spin", "take.json"), JSON.stringify(TAKE, null, 2));
+ const manifestBefore = await readFile(path.join(dir, "video.manifest.json"), "utf8");
+
+ const { body } = await projectFetchBody({ id: "folder/p", dir }, { take: "spin" });
+ assert.deepEqual(body.items.map((i) => [i.clipId, i.id, i.from, i.to]), [
+ ["kf3", "vid", 5, 23],
+ ["ke1", "vnew", 97, 113],
+ ]);
+ assert.equal(body.manifest, path.join(dir, "takes", "spin", "take.json"));
+ assert.equal(body.requestedBy, "umtool:folder/p");
+ const cutBody = (await projectFetchBody({ id: "folder/p", dir })).body;
+ assert.deepEqual(cutBody.items.map((i) => [i.clipId, i.from, i.to]), [["kf3", 7, 17]]);
+
+ let polls = 0;
+ const ed = fakeEditor({
+ "POST /api/ops/fetch-windows": (b) => ({ ok: true, dryRun: false, groups: [], cached: [], inFlight: [], unresolved: [], refused: [], jobs: [{ platform: "youtube", queueKey: "clips:youtube", jobId: "J9", items: b.items.length }], jobIds: ["J9"], jobId: "J9" }),
+ "GET /api/ops/job/J9": () => ({ ok: true, job: { id: "J9", status: ++polls < 2 ? "running" : "done" } }),
+ "GET /api/jobs/J9/log": { content: "Fetch windows: 2 fetched.\n", nextOffset: 10, status: "archived" },
+ });
+ const cfg = { url: "http://editor.test", token: "tok", fetch: ed.fetch };
+ const lines = [];
+ const asked = [];
+ trigger.setBenchPrepQueue(async (p, clips, opts) => {
+ asked.push([p.id, clips, opts.take ?? null, opts.excerptsOnly]);
+ });
+ try {
+ const run = (args) => fetchCommand(args, { root, out: (s) => lines.push(s), err: (s) => lines.push(s), cfg, pollMs: 1 });
+ assert.equal(await run(["folder/p", "--take", "spin", "--wait"]), 0, lines.join("\n"));
+ await trigger.settleBenchPrepTriggers();
+ assert.deepEqual(ed.seen[0].body.items.map((i) => i.clipId), ["kf3", "ke1"]);
+ assert.match(lines.join("\n"), /folder\/p take spin: 2 window\(s\) asked/);
+ // What landed is prepared for the TAKE's walk.
+ assert.deepEqual(asked, [["folder/p", null, "spin", false]]);
+
+ const doc = await readFetchRuns(dir);
+ assert.equal(doc.runs.length, 1);
+ assert.equal(doc.runs[0].take, "spin");
+ assert.equal(lastStartedRun(doc), null, "the cut has no started run of its own");
+ assert.deepEqual(lastStartedRun(doc, { take: "spin" }).jobIds, ["J9"]);
+
+ lines.length = 0;
+ assert.equal(await run(["folder/p", "--status", "--take", "spin"]), 0);
+ assert.match(lines.join("\n"), /folder\/p take spin: the run of/);
+ lines.length = 0;
+ assert.equal(await run(["folder/p", "--status"]), 1, "the cut's --status does not read the take's run");
+ assert.match(lines.join("\n"), /folder\/p has no started fetch run/);
+
+ lines.length = 0;
+ assert.equal(await run(["folder/p", "--take", "nope", "--body"]), 1);
+ assert.match(lines.join("\n"), /no take nope/);
+ assert.equal(await run(["folder/p", "--take"]), 2);
+ } finally {
+ trigger.setBenchPrepQueue(null);
+ }
+ assert.equal(await readFile(path.join(dir, "video.manifest.json"), "utf8"), manifestBefore, "the project's manifest is untouched");
+});
diff --git a/umtool/lib/report/fetchWindows.mjs b/umtool/lib/report/fetchWindows.mjs
@@ -170,12 +170,26 @@ export function bodyHash(body) {
/**
* The body for a project on disk: its manifest, its rulings.
+ *
+ * `take` (`umtool fetch <p> --take <id>`): the TAKE's clips -- its manifest
+ * as its walk reads it (takeManifest.mjs resolveTakeManifest: the project's
+ * now, the style's patch, the take's), so a clip only the take has (in its
+ * patch, not the cut) is asked for, and a DRAFT take needs no render first.
+ * The body names takes/<id>/take.json as the manifest it came from.
+ *
* @param {{ id: string, dir: string }} project
- * @param {{ reason?: string | null }} [opts]
+ * @param {{ reason?: string | null, take?: string | null }} [opts]
*/
-export async function projectFetchBody(project, { reason = null } = {}) {
- const manifestPath = path.join(project.dir, MANIFEST_FILE);
- const manifest = JSON.parse(await readFile(manifestPath, "utf8"));
+export async function projectFetchBody(project, { reason = null, take = null } = {}) {
+ let manifestPath = path.join(project.dir, MANIFEST_FILE);
+ let manifest;
+ if (take) {
+ const [{ resolveTakeManifest }, { takesDirOf, TAKE_FILE }] = await Promise.all([import("./takeManifest.mjs"), import("./takes.mjs")]);
+ manifest = (await resolveTakeManifest(project.dir, take)).manifest;
+ manifestPath = path.join(takesDirOf(project.dir), take, TAKE_FILE);
+ } else {
+ manifest = JSON.parse(await readFile(manifestPath, "utf8"));
+ }
const rulings = await readMontageRulings(project.dir);
return { manifest, manifestPath, ...fetchWindowsBody(manifest, { manifestPath, project: project.id, rulings, reason }) };
}
@@ -367,10 +381,11 @@ async function writeRuns(projectDir, doc) {
/**
* Record a run (the dry run or the start).
* @param {string} projectDir
- * @param {{ body: Record<string, any>, answer: Record<string, any>, refetch?: Record<string, any>[] | null, now?: Date }} r
+ * @param {{ body: Record<string, any>, answer: Record<string, any>, refetch?: Record<string, any>[] | null, take?: string | null, now?: Date }} r
* `refetch`: what a `--refetch` evicted first (one entry per video).
+ * `take`: the run asked for a take's clips (`umtool fetch --take`); recorded on the run.
*/
-export function recordFetchRun(projectDir, { body, answer, refetch = null, now = new Date() }) {
+export function recordFetchRun(projectDir, { body, answer, refetch = null, take = null, now = new Date() }) {
return withRunsLock(async () => {
const doc = await readFetchRuns(projectDir);
const summary = summarizeAnswer(answer);
@@ -382,6 +397,7 @@ export function recordFetchRun(projectDir, { body, answer, refetch = null, now =
jobIds: summary.jobs.map((j) => j.jobId),
summary,
...(refetch ? { refetch } : {}),
+ ...(take ? { take } : {}),
};
doc.runs.push(run);
doc.runs = doc.runs.slice(-FETCH_RUNS_KEPT);
@@ -407,8 +423,12 @@ export function recordJobOutcome(projectDir, jobId, { status, platform = null, f
});
}
-/** The newest run that started jobs, or null. */
-export const lastStartedRun = (doc) => [...(doc?.runs ?? [])].reverse().find((r) => !r.dryRun && r.jobIds?.length) ?? null;
+/**
+ * The newest run that started jobs, or null: of the cut (no `take`), or of
+ * that take -- a take's run is never read as the cut's last, nor the other way.
+ */
+export const lastStartedRun = (doc, { take = null } = {}) =>
+ [...(doc?.runs ?? [])].reverse().find((r) => !r.dryRun && r.jobIds?.length && (r.take ?? null) === (take ?? null)) ?? null;
/**
* Follow a run's jobs once: each job not yet recorded as ended is asked for its