fablecut 1.18.0 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/server.js CHANGED
@@ -43,9 +43,11 @@ const {
43
43
  PROJECT_FILE, LIBRARY_SUBDIRS, FRAMES_DIR, PROXIES_DIR, ensureDirs, readSaved, writeSaved,
44
44
  } = require("./paths");
45
45
  const Templates = require("./templates");
46
+ const Workflows = require("./workflows");
46
47
  const { probeFile } = require("./media-probe");
47
48
  const MediaLib = require("./media-lib");
48
49
  const { createProxies } = require("./proxy");
50
+ const { createMediaFiles, canonicalSrc } = require("./media-files");
49
51
  const { createTranscripts } = require("./transcripts");
50
52
  const Delivery = require("./delivery");
51
53
  const { createProjects } = require("./projects");
@@ -127,6 +129,100 @@ function broadcast(event = "change", data = event) {
127
129
  const proxies = createProxies({ dir: PROXIES_DIR, resolveSrc, probe: probeFile, broadcast: (ev, data) => broadcast(ev, data) });
128
130
  /* Word transcripts, one per version of a file (fablecut_transcribe, the Transcript tab). */
129
131
  const transcripts = createTranscripts({ dir: path.join(ANALYSIS_DIR, "transcripts"), resolveSrc });
132
+ const mediaFiles = createMediaFiles({ mediaDir: MEDIA_DIR });
133
+ /* A /media/… src → its absolute path (whether or not the file is there now). */
134
+ function srcFile(src) {
135
+ if (!src || !String(src).startsWith("/media/")) return null;
136
+ let rel; try { rel = decodeURIComponent(String(src).slice(7)); } catch { return null; }
137
+ const f = path.normalize(path.join(MEDIA_DIR, rel));
138
+ return f.startsWith(path.normalize(MEDIA_DIR + path.sep)) ? f : null;
139
+ }
140
+ const srcKey = canonicalSrc;
141
+ /* Every project's document: the open one (./project.json) and the parked ones. A known
142
+ project whose document can't be read is listed in `unreadable`, so nobody takes its
143
+ silence for "uses nothing". */
144
+ function projectDocs() {
145
+ const docs = [], unreadable = [];
146
+ const active = projects.peekActive();
147
+ // `text` is the file as read: a write planned from it checks the file is still that
148
+ const read = (file) => { const text = fs.readFileSync(file, "utf8"); return { text, doc: JSON.parse(text.replace(/^/, "")) }; };
149
+ try { docs.push({ id: active, file: PROJECT_FILE, open: true, ...read(PROJECT_FILE) }); }
150
+ catch { unreadable.push("the open project"); }
151
+ let ids = [];
152
+ // no projects folder yet is the first-run state; any other failure means projects weren't checked
153
+ try { ids = fs.readdirSync(projects.DIR); } catch (e) { if (e.code !== "ENOENT") unreadable.push("the projects folder"); }
154
+ for (const id of ids) {
155
+ if (id === active || !fs.existsSync(path.join(projects.DIR, id, "meta.json"))) continue;
156
+ const file = path.join(projects.DIR, id, "project.json");
157
+ try { docs.push({ id, file, open: false, ...read(file) }); }
158
+ catch { unreadable.push(`project ${id}`); }
159
+ }
160
+ return { docs, unreadable };
161
+ }
162
+ /* Media entries (in any project) that use these /media/… srcs, with how many clips place each. */
163
+ function mediaUses(docs, srcs) {
164
+ const want = new Set(srcs.map(srcKey));
165
+ const out = [];
166
+ for (const d of docs) {
167
+ const text = JSON.stringify(d.doc);
168
+ for (const m of d.doc.media || []) {
169
+ if (!want.has(srcKey(m.src))) continue;
170
+ const clips = text.split(`"mediaId":${JSON.stringify(m.id)}`).length - 1;
171
+ out.push({ project: d.doc.name || d.id, open: d.open, media: m.id, name: m.name, src: m.src, clips });
172
+ }
173
+ }
174
+ return out;
175
+ }
176
+ /* Point media entries at files that moved ([{from, to}] srcs); a name that was the old file
177
+ name follows it. All or nothing: every new document is staged first, each project must
178
+ still be the one the plan was made from (else CONFLICT), and if one can't be put in place
179
+ the ones already replaced go back (atomically too). The error is thrown so the caller can
180
+ undo the move; `e.rollbackFailed` names projects that couldn't be put back. */
181
+ function repointMedia(moved, { force = false } = {}) {
182
+ const map = new Map(moved.filter((m) => m.from && m.to).map((m) => [srcKey(m.from), m.to]));
183
+ const plan = [];
184
+ const scan = projectDocs();
185
+ // a project that couldn't be read now (it could before) would keep the old place
186
+ if (scan.unreadable.length && !force) throw new Error(`can't read ${scan.unreadable.join(", ")}`);
187
+ for (const d of scan.docs) {
188
+ let n = 0;
189
+ for (const m of d.doc.media || []) {
190
+ const to = map.get(srcKey(m.src));
191
+ if (!to) continue;
192
+ if (m.name === path.basename(srcKey(m.src))) m.name = path.basename(srcKey(to));
193
+ m.src = to; n++;
194
+ }
195
+ if (n) plan.push({ d, n });
196
+ }
197
+ const staged = [], written = [];
198
+ const drop = () => { for (const s of staged) { try { fs.rmSync(s.tmp, { force: true }); } catch { } } };
199
+ try {
200
+ for (const { d } of plan) {
201
+ if (d.open) d.doc.revision = (d.doc.revision || 0) + 1;
202
+ const tmp = d.file + ".files.tmp";
203
+ fs.writeFileSync(tmp, JSON.stringify(d.doc, null, 2));
204
+ staged.push({ d, tmp });
205
+ }
206
+ } catch (e) { drop(); throw e; }
207
+ try {
208
+ for (const s of staged) {
209
+ // an edit saved since the plan was read would be lost: refuse instead
210
+ if (fs.readFileSync(s.d.file, "utf8") !== s.d.text) throw new Error(`CONFLICT — ${s.d.open ? "the open project" : `project "${s.d.doc.name || s.d.id}"`} changed meanwhile; try again`);
211
+ fs.renameSync(s.tmp, s.d.file);
212
+ written.push(s.d);
213
+ }
214
+ } catch (e) {
215
+ drop();
216
+ const failed = [];
217
+ for (const d of written) {
218
+ try { const tmp = d.file + ".files.undo"; fs.writeFileSync(tmp, d.text); fs.renameSync(tmp, d.file); }
219
+ catch { failed.push(d.open ? "the open project" : `project "${d.doc.name || d.id}"`); }
220
+ }
221
+ if (failed.length) e.rollbackFailed = failed;
222
+ throw e;
223
+ }
224
+ return plan.map(({ d, n }) => ({ project: d.doc.name || d.id, open: d.open, media: n }));
225
+ }
130
226
  let debounce = null;
131
227
  let profilesDebounce = null;
132
228
  function onFsChange() {
@@ -173,7 +269,8 @@ function readBody(req) {
173
269
  /** Claim final + sibling `.part` paths with exclusive create (`wx`) so concurrent
174
270
  * exports cannot pick the same free name before either file exists. */
175
271
  function reserveExportPaths(dir, baseName, ext) {
176
- const base = baseName.replace(/\.(mp4|mov|m4v|mkv|webm)$/i, "");
272
+ // as the Export dialog does: no extension typed twice, no leading dot (a dotfile isn't served)
273
+ const base = baseName.replace(/\.(mp4|mov|m4v|mkv|webm|mxf)$/i, "").replace(/^[.\s]+/, "") || "export";
177
274
  let i = 0;
178
275
  for (;;) {
179
276
  const stem = i === 0 ? base : `${base}_${i}`;
@@ -288,6 +385,27 @@ function deliveryEncoders() {
288
385
  return deliveryEncodersP;
289
386
  }
290
387
  /** Saved delivery presets: library/delivery/<id>.json, each a spec plus a label. */
388
+ /* The tools a workflow step may call: the MCP server's, as manifest.json lists them
389
+ (the same list fablecut_workflows checks against). */
390
+ let workflowTools;
391
+ function workflowToolNames() {
392
+ if (workflowTools === undefined) {
393
+ try { workflowTools = Workflows.manifestTools(JSON.parse(fs.readFileSync(path.join(APP_DIR, "manifest.json"), "utf8"))); }
394
+ catch { workflowTools = null; }
395
+ }
396
+ return workflowTools || undefined;
397
+ }
398
+ const savedWorkflows = () => Workflows.fromFiles(readSaved("workflows"));
399
+ /** Validate and save a workflow; one with the same id keeps its created date. */
400
+ function saveWorkflow(input, all) {
401
+ const w = Workflows.normalizeWorkflow(input, true, workflowToolNames());
402
+ const prev = all.find((x) => x.id === w.id);
403
+ const now = new Date().toISOString();
404
+ const item = { ...w, created: prev && prev.created || now, updated: now };
405
+ writeSaved("workflows", item.id, item);
406
+ Workflows.removeStale(path.join(LIBRARY_DIR, "workflows"), all, item.id, fs, path);
407
+ return item;
408
+ }
291
409
  function savedDeliveryPresets() { return Delivery.savedPresets(readSaved("delivery")); }
292
410
  /* One render, several files: `deliveries:[{delivery, name}, …]` (up to 8) or a
293
411
  single `delivery` + name. Every output gets its own ffmpeg, fed the same
@@ -312,7 +430,7 @@ async function beginDeliveryExport(rate, name, hasAudio, extra) {
312
430
  // one render has one frame rate: an output asking for another needs a render of its own
313
431
  const off = outs.map((o, i) => [o, i]).filter(([o]) => o.spec.fps != null && Math.abs(o.spec.fps - rate) > 0.01);
314
432
  if (off.length) throw new Error(off.map(([o, i]) => `output ${i + 1} asks for ${o.spec.fps} fps but this render is ${rate} fps`).join("; ") + " — render each frame rate separately");
315
- const input = outs.some((o) => Delivery.frameInput(o.spec) === "rgba") ? "rgba" : "jpeg";
433
+ const input = outs.some((o) => Delivery.frameInput(o.spec) === "png") ? "png" : "jpeg";
316
434
  // check every output on a 0.1 s synthetic canvas before the browser renders anything
317
435
  const dryDir = fs.mkdtempSync(path.join(os.tmpdir(), "fablecut-dry-"));
318
436
  try {
@@ -515,17 +633,32 @@ function startAnnexbEncoder(sess) {
515
633
  attachProc(sess, spawn("ffmpeg", args, { stdio: ["pipe", "ignore", "pipe"] }));
516
634
  return sess.proc;
517
635
  }
636
+ /** Stop an export's ffmpeg. An ffmpeg waiting on an input pipe that gets no more
637
+ * bytes ignores SIGTERM until some arrive (#165), so close its stdin first:
638
+ * that ends the input and it exits by itself. */
639
+ function stopExportProc(proc) {
640
+ if (!proc) return;
641
+ try { proc.stdin?.destroy(); } catch {}
642
+ try { proc.kill(); } catch {}
643
+ }
644
+ /** Remove a path now, and again once `proc` has exited (Windows won't delete a file ffmpeg still holds open). */
645
+ function removeAfter(proc, p, opts) {
646
+ if (!p) return;
647
+ const rm = () => { try { fs.rmSync(p, { force: true, ...opts }); } catch {} };
648
+ rm();
649
+ if (proc && proc.exitCode == null && proc.signalCode == null && fs.existsSync(p)) proc.once("exit", rm);
650
+ }
518
651
  function cleanupExport(id) {
519
652
  const s = exportSessions.get(id);
520
653
  if (!s) return;
521
654
  exportSessions.delete(id);
522
- try { s.proc?.kill(); } catch {}
655
+ stopExportProc(s.proc);
523
656
  for (const o of s.outputs || []) {
524
- try { o.proc?.kill(); } catch {}
525
- if (o.partPath) try { fs.rmSync(o.partPath, { force: true }); } catch {}
657
+ stopExportProc(o.proc);
658
+ removeAfter(o.proc, o.partPath);
526
659
  }
527
- try { fs.rmSync(s.dir, { recursive: true, force: true }); } catch {}
528
- if (s.partPath) try { fs.rmSync(s.partPath, { force: true }); } catch {}
660
+ removeAfter(s.proc || (s.outputs || []).find((o) => o.proc)?.proc, s.dir, { recursive: true });
661
+ removeAfter(s.proc, s.partPath);
529
662
  }
530
663
  function sweepIdleExports() {
531
664
  const now = Date.now();
@@ -771,7 +904,7 @@ const server = http.createServer(async (req, res) => {
771
904
  for (const e of list) {
772
905
  if (e.name.startsWith(".")) continue;
773
906
  const full = path.join(d, e.name);
774
- if (e.isDirectory()) { if (depth < 6 && !(root === LIBRARY_DIR && /^(presets|templates|fonts)$/.test(e.name) && depth === 0)) walk(root, prefix, full, depth + 1); continue; }
907
+ if (e.isDirectory()) { if (depth < 6 && !(root === LIBRARY_DIR && /^(presets|templates|workflows|fonts)$/.test(e.name) && depth === 0)) walk(root, prefix, full, depth + 1); continue; }
775
908
  let size = 0;
776
909
  try { size = fs.statSync(full).size; } catch { continue; }
777
910
  const rel = path.relative(root, full).split(path.sep).map(encodeURIComponent).join("/");
@@ -791,6 +924,113 @@ const server = http.createServer(async (req, res) => {
791
924
  return;
792
925
  }
793
926
 
927
+ /* API: files in media/ (media-files.js) — folders, moves and a trash; nothing is deleted.
928
+ POST /api/files {action:"list", dir?} → {dir, folders, files:[{name, src, size}]}
929
+ {action:"mkdir", dir} → {dir}
930
+ {action:"move", from, to} → {from, to, moved:[{from, to}], repointed:[{project, open, media}]}
931
+ {action:"trash", paths, force?} → {trashed:[{id, src}], offline:[…uses]}
932
+ (409 while a project uses one or can't be read to check — unless force:true)
933
+ {action:"trash-list"} → {items:[{id, src, kind, size, trashed}]}
934
+ {action:"restore", id} → {restored:{id, src}}
935
+ A move repoints every project's media entries at the new place (the open one gets a new
936
+ revision, so editor tabs reload) and takes the file's transcript with it; if a project
937
+ can't be written the move is undone. Every change also goes out as SSE "change". */
938
+ if (p === "/api/files" && req.method === "POST") {
939
+ try {
940
+ const opts = JSON.parse((await readBody(req)).toString("utf8") || "{}");
941
+ const a = opts.action;
942
+ if (a === "list") { sendJSON(res, 200, mediaFiles.list(opts.dir)); return; }
943
+ if (a === "mkdir") { sendJSON(res, 200, mediaFiles.mkdir(opts.dir)); broadcast("change"); return; }
944
+ if (a === "trash-list") { sendJSON(res, 200, { items: mediaFiles.trashList() }); return; }
945
+ if (a === "move") {
946
+ if (opts.force !== undefined && typeof opts.force !== "boolean") { sendJSON(res, 400, { error: "force is true or false" }); return; }
947
+ // a project that can't be read can't be repointed: it would keep the old place
948
+ const { unreadable } = projectDocs();
949
+ if (unreadable.length && opts.force !== true) {
950
+ sendJSON(res, 409, { error: `can't check ${unreadable.join(", ")} (can't be read) — fix it first, or pass force:true to move anyway (the file goes offline there)`, unreadable });
951
+ return;
952
+ }
953
+ let r, partial = null;
954
+ try { r = mediaFiles.move(opts.from, opts.to); }
955
+ catch (e) {
956
+ // copied whole across drives, but part of the original stayed: the move counts, with a warning
957
+ if (!e.published || !e.result) throw e;
958
+ r = e.result; partial = e.message;
959
+ }
960
+ // each file's transcript goes along; the ones that couldn't are reported (the file needs transcribing again)
961
+ const follow = (pairs) => {
962
+ const lost = [], went = [];
963
+ for (const m of pairs) {
964
+ const f = srcFile(m.from), t = srcFile(m.to);
965
+ if (!f || !t) continue;
966
+ const got = transcripts.follow(f, t);
967
+ if (got === false) lost.push(m.to); else if (got) went.push(m);
968
+ }
969
+ return { lost, went };
970
+ };
971
+ const { lost, went } = follow(r.moved);
972
+ let repointed;
973
+ try { repointed = repointMedia(r.moved, { force: opts.force === true }); }
974
+ catch (e) {
975
+ const notBack = e.rollbackFailed ? `; ${e.rollbackFailed.join(", ")} couldn't be put back — check it in the editor and relink` : "";
976
+ // a project couldn't be updated: put the files back exactly where every project expects them
977
+ // (never into something that appeared there meanwhile), with the transcripts that went along
978
+ try {
979
+ if (partial) throw new Error("part of the original is still there");
980
+ mediaFiles.move(r.to, r.from, { exact: true });
981
+ follow(went.map((m) => ({ from: m.to, to: m.from })));
982
+ }
983
+ catch (e2) {
984
+ broadcast("change");
985
+ throw new Error(`moved, but a project couldn't be updated (${e.message}) and moving back failed too (${e2.message}) — the files are at ${r.to}: relink them in the editor${notBack}`);
986
+ }
987
+ if (notBack) broadcast("change");
988
+ throw new Error(`not moved: a project couldn't be updated (${e.message})${notBack}`);
989
+ }
990
+ broadcast("change");
991
+ const out = { from: r.from, to: r.to, moved: r.moved, repointed };
992
+ const warn = [];
993
+ if (partial) warn.push(partial);
994
+ if (lost.length) warn.push(`the transcript of ${lost.length} file${lost.length === 1 ? "" : "s"} couldn't be moved with it — transcribe ${lost.length === 1 ? "it" : "them"} again`);
995
+ if (warn.length) out.warning = warn.join("; ");
996
+ sendJSON(res, 200, out);
997
+ return;
998
+ }
999
+ if (a === "trash") {
1000
+ if (opts.force !== undefined && typeof opts.force !== "boolean") { sendJSON(res, 400, { error: "force is true or false" }); return; }
1001
+ const paths = Array.isArray(opts.paths) ? opts.paths : [opts.paths];
1002
+ const files = paths.flatMap((x) => mediaFiles.filesOf(x));
1003
+ const { docs, unreadable } = projectDocs();
1004
+ const uses = mediaUses(docs, files);
1005
+ if (opts.force !== true && (uses.length || unreadable.length)) {
1006
+ const why = uses.length
1007
+ ? "in use — " + uses.map((u) => `"${u.name}" in ${u.open ? "the open project" : `project "${u.project}"`} (${u.clips} clip${u.clips === 1 ? "" : "s"})`).join("; ") +
1008
+ ". Take it out of those projects first (removeMedia)"
1009
+ : `can't check ${unreadable.join(", ")} (its project.json can't be read) — fix it first`;
1010
+ sendJSON(res, 409, { error: why + ", or pass force:true to trash it anyway (it goes offline there until restored)", uses, unreadable });
1011
+ return;
1012
+ }
1013
+ let r;
1014
+ try { r = mediaFiles.trash(paths); }
1015
+ catch (e) {
1016
+ // part of the batch went: say which (with their ids), so they can be restored
1017
+ if (!e.partial?.trashed.length) throw e;
1018
+ broadcast("change");
1019
+ sendJSON(res, 400, { error: `stopped at ${e.partial.failed}: ${e.message} — the ones before it are in the trash`, trashed: e.partial.trashed, failed: e.partial.failed });
1020
+ return;
1021
+ }
1022
+ broadcast("change");
1023
+ // a trash that left part of the original (a warning on that item) may still play there
1024
+ const offline = uses.filter((u) => !mediaFiles.pathOf(u.src));
1025
+ sendJSON(res, 200, { trashed: r.trashed, offline, ...(offline.length < uses.length ? { stillThere: uses.filter((u) => mediaFiles.pathOf(u.src)) } : {}) });
1026
+ return;
1027
+ }
1028
+ if (a === "restore") { const r = mediaFiles.restore(opts.id); broadcast("change"); sendJSON(res, 200, { restored: r.restored }); return; }
1029
+ sendJSON(res, 400, { error: "action is list, mkdir, move, trash, trash-list or restore" });
1030
+ } catch (e) { sendJSON(res, 400, { error: String(e.message || e) }); }
1031
+ return;
1032
+ }
1033
+
794
1034
  /* API: word transcripts (transcripts.js) — one per version of a file, times in file seconds.
795
1035
  GET /api/transcript?src= → {transcript} (null when there is none; 404 when the file is missing)
796
1036
  POST /api/transcript?src= {doc} → {src, words} — saved by the tab that transcribed it
@@ -911,6 +1151,38 @@ const server = http.createServer(async (req, res) => {
911
1151
  return;
912
1152
  }
913
1153
 
1154
+ /* API: saved workflows (library/workflows) — recipes an agent repeats on another project.
1155
+ GET /api/workflows → [ …validated workflows… ] (bad files skipped)
1156
+ GET /api/workflows?id= → one, or 404
1157
+ POST /api/workflows {workflow} → saved as library/workflows/<id>.json (same id: updated)
1158
+ POST /api/workflows/delete {id} */
1159
+ if (p === "/api/workflows" || p === "/api/workflows/delete") {
1160
+ try {
1161
+ if (req.method === "GET" && p === "/api/workflows") {
1162
+ const all = savedWorkflows();
1163
+ const id = url.searchParams.get("id");
1164
+ if (id == null) { sendJSON(res, 200, all); return; }
1165
+ const w = Workflows.findWorkflow(all, id);
1166
+ if (w) sendJSON(res, 200, w); else sendJSON(res, 404, { error: `no workflow "${id}"` });
1167
+ return;
1168
+ }
1169
+ if (req.method !== "POST") { sendJSON(res, 405, { error: "GET or POST" }); return; }
1170
+ const body = JSON.parse((await readBody(req)).toString("utf8") || "{}");
1171
+ // read now, after the body: another save may have landed while it arrived
1172
+ const all = savedWorkflows();
1173
+ if (p === "/api/workflows/delete") {
1174
+ const w = Workflows.findWorkflow(all, body.id);
1175
+ if (!w) { sendJSON(res, 404, { error: `no workflow "${body.id}"` }); return; }
1176
+ fs.rmSync(path.join(LIBRARY_DIR, "workflows", path.basename(w.file || w.id + ".json")), { force: true });
1177
+ sendJSON(res, 200, { deleted: w.id });
1178
+ return;
1179
+ }
1180
+ const item = saveWorkflow(body.workflow, all);
1181
+ sendJSON(res, 200, item);
1182
+ } catch (e) { sendJSON(res, 400, { error: String(e.message || e) }); }
1183
+ return;
1184
+ }
1185
+
914
1186
  /* API: upload → saved into ./media */
915
1187
  if (p === "/api/upload" && req.method === "POST") {
916
1188
  try {
@@ -993,7 +1265,10 @@ const server = http.createServer(async (req, res) => {
993
1265
  }
994
1266
  let revision = null;
995
1267
  try { revision = JSON.parse(fs.readFileSync(PROJECT_FILE, "utf8").replace(/^\uFEFF/, "")).revision ?? null; } catch {}
996
- const job = exportJobs.request({ range: opts.range, profile: opts.profile, delivery: deliveries ? null : delivery, deliveries, where: opts.where, revision });
1268
+ if (opts.name != null && typeof opts.name !== "string") { sendJSON(res, 400, { error: "name is a string" }); return; }
1269
+ const name = opts.name?.trim() || null; // blank = the default name
1270
+ if (name && deliveries) { sendJSON(res, 400, { error: "name goes with one file, not with outputs (give each output its own filename)" }); return; }
1271
+ const job = exportJobs.request({ range: opts.range, profile: opts.profile, delivery: deliveries ? null : delivery, deliveries, name, where: opts.where, revision, project: projects.peekActive() });
997
1272
  sendJSON(res, 200, deliveries ? { ...job, delivery: `${deliveries.length} outputs from one render`, notes: outNotes }
998
1273
  : delivery ? { ...job, delivery: Delivery.describe(delivery), notes } : job);
999
1274
  } catch (e) {
@@ -1020,7 +1295,7 @@ const server = http.createServer(async (req, res) => {
1020
1295
  if (mk != null && (typeof mk !== "object" || typeof mk.clip !== "string")) {
1021
1296
  sendJSON(res, 400, { error: "mask must be {clip: \"<clip id>\"}" }); return;
1022
1297
  }
1023
- sendJSON(res, 200, exportJobs.request({ kind: "scopes", time, where: opts.where, revision, matte: m || null, mask: mk || null, image: opts.image === true }));
1298
+ sendJSON(res, 200, exportJobs.request({ kind: "scopes", time, where: opts.where, revision, project: projects.peekActive(), matte: m || null, mask: mk || null, image: opts.image === true }));
1024
1299
  } catch (e) {
1025
1300
  sendJSON(res, e.code === 409 || e.code === 400 ? e.code : 500, { error: String(e.message || e) });
1026
1301
  }
@@ -1037,7 +1312,7 @@ const server = http.createServer(async (req, res) => {
1037
1312
  if (!t || typeof t !== "object" || Array.isArray(t) || typeof t.clip !== "string") { sendJSON(res, 400, { error: "track must be {clip: \"<clip id>\", …}" }); return; }
1038
1313
  const body = JSON.stringify(t);
1039
1314
  if (body.length > 8192) { sendJSON(res, 400, { error: "track spec too large" }); return; }
1040
- sendJSON(res, 200, exportJobs.request({ kind: "track", where: opts.where, revision, track: JSON.parse(body) }));
1315
+ sendJSON(res, 200, exportJobs.request({ kind: "track", where: opts.where, revision, project: projects.peekActive(), track: JSON.parse(body) }));
1041
1316
  } catch (e) {
1042
1317
  sendJSON(res, e.code === 409 || e.code === 400 ? e.code : 500, { error: String(e.message || e) });
1043
1318
  }