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/CLAUDE.md +144 -11
- package/README.md +18 -16
- package/app.js +648 -110
- package/command-search.js +79 -0
- package/delivery.js +12 -7
- package/export-jobs.js +4 -2
- package/focus.js +165 -0
- package/index.html +33 -0
- package/manifest.json +59 -0
- package/mcp-server.js +124 -4
- package/media-files.js +271 -0
- package/package.json +3 -2
- package/paths.js +4 -3
- package/select-menu.js +295 -0
- package/server.js +286 -11
- package/style.css +318 -1
- package/transcripts.js +10 -0
- package/workflows.js +153 -0
package/mcp-server.js
CHANGED
|
@@ -38,6 +38,7 @@ const Motion = require("./motion");
|
|
|
38
38
|
const CompLib = require("./comp");
|
|
39
39
|
const SeqLib = require("./sequences");
|
|
40
40
|
const Templates = require("./templates");
|
|
41
|
+
const Workflows = require("./workflows");
|
|
41
42
|
const Delivery = require("./delivery");
|
|
42
43
|
const { probeFile, infoForEntry } = require("./media-probe");
|
|
43
44
|
const { findProxies } = require("./proxy");
|
|
@@ -50,8 +51,8 @@ const ROOT = APP_DIR;
|
|
|
50
51
|
ensureDirs();
|
|
51
52
|
const PORT = process.env.FABLECUT_PORT || 7777;
|
|
52
53
|
const BASE = `http://localhost:${PORT}`;
|
|
53
|
-
// Requests go to the address the server binds
|
|
54
|
-
// resolve to ::1 first
|
|
54
|
+
// Requests go to the address the server binds rather than "localhost", which
|
|
55
|
+
// can resolve to ::1 first; this does not rely on a fallback to 127.0.0.1.
|
|
55
56
|
const API = `http://${process.env.HOST === "::1" ? "[::1]" : "127.0.0.1"}:${PORT}`;
|
|
56
57
|
|
|
57
58
|
/* MCP initialize must echo a version we actually speak. Echoing an unknown
|
|
@@ -231,6 +232,22 @@ const TOOLS = [
|
|
|
231
232
|
required: ["path"],
|
|
232
233
|
},
|
|
233
234
|
},
|
|
235
|
+
{
|
|
236
|
+
name: "fablecut_files",
|
|
237
|
+
description: "The project's files on disk, inside ./media/ (the folder fablecut_import_media copies into): list a folder, make folders, move or rename files and folders, and throw away what isn't needed. Nothing is deleted: trash moves a file into media/.trash/ and restore puts it back. A move repoints every project's media entries at the new place, so no clip goes offline, and the file keeps its transcript. Trash refuses a file a project still uses (removeMedia it first, or force:true to trash it anyway: it goes offline there until restored). The media bin's folders (folderId) are separate: they organize entries, these are the real folders. Paths are relative to media/ ('b-roll/day 1/a.mp4') or /media/… srcs. Move, rename and trash only when the user asked for it.",
|
|
238
|
+
inputSchema: {
|
|
239
|
+
type: "object",
|
|
240
|
+
properties: {
|
|
241
|
+
action: { type: "string", enum: ["list", "mkdir", "move", "trash", "trash-list", "restore"], description: "list (default) · mkdir · move (also renames) · trash · trash-list · restore" },
|
|
242
|
+
dir: { type: "string", description: "list: the folder (default media/ itself) · mkdir: the folder to make (parents too)" },
|
|
243
|
+
from: { type: "string", description: "move: the file or folder" },
|
|
244
|
+
to: { type: "string", description: "move: an existing folder to move it into, or the new path (a rename)" },
|
|
245
|
+
paths: { type: "array", items: { type: "string" }, description: "trash: files or folders" },
|
|
246
|
+
force: { type: "boolean", description: "trash: even files a project still uses (they go offline until restored); move: even while a project can't be read (the file goes offline there)" },
|
|
247
|
+
id: { type: "string", description: "restore: a trashed item's id (trash-list shows them)" },
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
},
|
|
234
251
|
{
|
|
235
252
|
name: "fablecut_encode_profiles",
|
|
236
253
|
description: "List what fablecut_export can make. DELIVERY PRESETS (structured settings, the Export dialog's Preset list): youtube, youtube-shorts, instagram-reels, tiktok, x, linkedin, master (project size), broadcast (ProRes 422 HQ), web (720p), archive (lossless FFV1), custom — plus presets the user saved — each a spec of resolution, fps, codec (h264, hevc, av1, vp9, prores, dnxhr, mpeg2 XDCAM, ffv1), rate control (crf / vbr / cbr), keyframe interval, pixel format, color, container, audio, a file-name template and metadata. {preset:'youtube'} returns one preset's full spec; the encoders this ffmpeg can use are listed (hardware ones only when they work on this machine). ENCODING PROFILES (encoding-profiles.json): raw ffmpeg argument lists plus jpegQuality, extension and color, for anything the presets do not cover; edit the file on disk (hot-reloaded); {profile:'hq'} returns one, detail:true includes every args array. Both are dry-run against ffmpeg when an export starts, so bad settings are refused before rendering.",
|
|
@@ -433,6 +450,27 @@ const TOOLS = [
|
|
|
433
450
|
},
|
|
434
451
|
},
|
|
435
452
|
},
|
|
453
|
+
{
|
|
454
|
+
name: "fablecut_workflows",
|
|
455
|
+
description: "Saved workflows: recipes the user wants repeated on other projects (\"my podcast clean-up\", \"the weekly reel\"). A workflow is a name, what it is for, and its steps in order; each step says in plain words what to do and may carry the tool call that did it last time. Actions: list (default) · show {id} — the steps, to follow now · save {workflow:{name, description?, tags?, steps:[{text, call?:{tool, args}}]}} — keep one (the same name updates it) · delete {id} (only when the user asks). To run one: show it, then do each step yourself on the open project, using judgement where the footage differs (which clips, where cuts land); a step's call is a worked example, not a script, so change its ids and times to fit. Save one when the user asks to keep or repeat what you just did: write the steps the way you would explain them to another editor, and attach the calls that worked. Saved in library/workflows/, shared by every project.",
|
|
456
|
+
inputSchema: {
|
|
457
|
+
type: "object",
|
|
458
|
+
properties: {
|
|
459
|
+
action: { type: "string", enum: ["list", "show", "save", "delete"], description: "What to do (default list)" },
|
|
460
|
+
id: { type: "string", description: "show / delete: the workflow's id or name" },
|
|
461
|
+
workflow: {
|
|
462
|
+
type: "object",
|
|
463
|
+
description: "save: {name, description?, tags?, steps:[{text, call?:{tool, args}}]} (a step may also be a plain string)",
|
|
464
|
+
properties: {
|
|
465
|
+
name: { type: "string" },
|
|
466
|
+
description: { type: "string" },
|
|
467
|
+
tags: { type: "array", items: { type: "string" } },
|
|
468
|
+
steps: { type: "array", items: { anyOf: [{ type: "string" }, { type: "object" }] } },
|
|
469
|
+
},
|
|
470
|
+
},
|
|
471
|
+
},
|
|
472
|
+
},
|
|
473
|
+
},
|
|
436
474
|
{
|
|
437
475
|
name: "fablecut_proxy",
|
|
438
476
|
description: "Proxies: light H.264 copies (540p by default, 720p or 1080p; never larger than the source) of heavy footage — 4K, HEVC, ProRes, long phone clips — that the editor plays while the user edits, so playback and scrubbing stay smooth. Export, fablecut_frame, fablecut_scopes and every measurement always read the original, so a proxy never changes the result. Without create or delete it reports each video's proxy (ready, being made with its progress, failed, none). create:true makes them (one at a time, in the background on the server) and waits until they are done unless wait:false; delete:true removes them. mediaIds defaults to every video in the project. The user turns proxy playback on or off with the monitor's Proxy button. Needs ffmpeg on PATH.",
|
|
@@ -455,6 +493,7 @@ const TOOLS = [
|
|
|
455
493
|
type: "object",
|
|
456
494
|
properties: {
|
|
457
495
|
range: { type: "string", enum: ["entire", "in-out"], description: "Whole timeline, or the project's inPoint→outPoint (default: in-out when either is set)" },
|
|
496
|
+
name: { type: "string", description: "The file's name, without the extension. Default: a delivery preset's filename pattern, which starts with the project's name (with an encoding profile, the project's name) — so name the file after what it is (e.g. 'salon-promo-15s') whenever the project holds more than this one video. The editor's own Export dialog asks the user for a name; this is that answer. Only the name changes: the preset, delivery or encoding profile the export uses stays the same. Not with outputs" },
|
|
458
497
|
preset: { type: "string", description: "Delivery preset: youtube, youtube-shorts, instagram-reels, tiktok, x, linkedin, master, broadcast, web, archive, custom, or a saved preset's id (fablecut_encode_profiles lists them). The output is reframed to the preset's size — cropped from the middle (or from the project's exportFrame), or padded with reframe:'fit'" },
|
|
459
498
|
delivery: { type: "object", description: "Delivery settings over the preset (or over custom): {width, height (null = the picture's size), fps (null = the project's), reframe:'fill'|'fit'|'stretch', container:'mp4'|'mov'|'mkv'|'webm'|'mxf', video:{codec:'h264'|'hevc'|'av1'|'vp9'|'prores'|'dnxhr'|'mpeg2'|'ffv1', encoder?, rate:'crf'|'vbr'|'cbr', crf, bitrate (kb/s), maxrate (kb/s), keyint (s), pixFmt, speed:'fast'|'balanced'|'best', profile (prores: proxy|lt|standard|hq|4444|4444xq · dnxhr: lb|sq|hq|hqx|444)}, audio:{codec:'aac'|'opus'|'mp3'|'pcm16'|'pcm24'|'flac'|'none', bitrate (kb/s), sampleRate, channels, loudness (LUFS target: -14 streaming/social, -16 podcast, -23 EBU R128, -24 ATSC; null = as mixed), truePeak (dBTP ceiling, default -1)}, color:'bt709'|'bt709-full'|'bt601-625'|'bt601-525', filename:'{project}_{preset}_{res}' (tokens {project} {preset} {res} {w} {h} {fps} {codec} {date} {time} {range} {n}), metadata:{title, artist, description, copyright, date, keywords}}. Anything left out comes from the preset; impossible combinations are corrected and the reply says how. Every finished file is checked against what was asked (size, fps, frames, codecs, length, loudness, true peak, file size) and the reply lists the checks" },
|
|
460
499
|
outputs: { description: "Several files, rendered once per frame rate (up to 8 outputs per render): true = the project's checked batch outputs (project.outputs, set with setProject {outputs:[…]}), or a list like [{preset:'master'}, {preset:'youtube'}, {preset:'instagram-reels'}, {preset:'custom', width:1080, height:1080, filename:'{project}_square_{res}'}, {preset:'web', filename:'{project}_preview_{res}'}]. Outputs with the same fps share one render; the reply lists every file", anyOf: [{ type: "boolean" }, { type: "array", items: { anyOf: [{ type: "string" }, { type: "object" }] } }] },
|
|
@@ -1259,6 +1298,35 @@ async function projectsTool(args) {
|
|
|
1259
1298
|
if (out.from) return `Opened ${describeProject(out.project)}\nThe editor switched to it (${out.from} was saved first). Read it with fablecut_get_project {compact:true} before editing.`;
|
|
1260
1299
|
return describeProject(out.project);
|
|
1261
1300
|
}
|
|
1301
|
+
/* fablecut_workflows: saved recipes in library/workflows/, read and written here directly
|
|
1302
|
+
(like saved presets), so it works without the editor server. */
|
|
1303
|
+
function savedWorkflows() {
|
|
1304
|
+
return Workflows.fromFiles(readSaved("workflows"));
|
|
1305
|
+
}
|
|
1306
|
+
function workflowsTool(args) {
|
|
1307
|
+
const action = args.action || "list", all = savedWorkflows();
|
|
1308
|
+
if (action === "list") return all.length
|
|
1309
|
+
? [`${all.length} saved workflow(s) — {action:"show", id} gives the steps:`, ...all.map(Workflows.workflowLine)].join("\n")
|
|
1310
|
+
: "No saved workflows yet. When the user wants something you did kept for next time, save it: {action:\"save\", workflow:{name, description, steps:[{text, call?}]}}.";
|
|
1311
|
+
if (action === "show" || action === "delete") {
|
|
1312
|
+
const w = Workflows.findWorkflow(all, args.id);
|
|
1313
|
+
if (!w) throw new Error(`no workflow "${args.id || ""}"` + (all.length ? ` — saved: ${all.map((x) => x.id).join(", ")}` : " — none saved yet"));
|
|
1314
|
+
if (action === "show") return Workflows.describeWorkflow(w) +
|
|
1315
|
+
"\n\nDo each step on the open project. A \"last time\" call is an example: fit its ids, times and values to this project.";
|
|
1316
|
+
fs.rmSync(path.join(LIBRARY_DIR, "workflows", path.basename(w.file || w.id + ".json")), { force: true });
|
|
1317
|
+
return `Deleted workflow "${w.name}" (${w.id}).`;
|
|
1318
|
+
}
|
|
1319
|
+
if (action === "save") {
|
|
1320
|
+
const w = Workflows.normalizeWorkflow(args.workflow, true, TOOLS.map((t) => t.name));
|
|
1321
|
+
const prev = all.find((x) => x.id === w.id), now = new Date().toISOString();
|
|
1322
|
+
const item = { ...w, created: prev && prev.created || now, updated: now };
|
|
1323
|
+
writeSaved("workflows", item.id, item);
|
|
1324
|
+
Workflows.removeStale(path.join(LIBRARY_DIR, "workflows"), all, item.id, fs, path);
|
|
1325
|
+
return `${prev ? "Updated" : "Saved"} workflow "${item.name}" (${item.id}), ${item.steps.length} step(s), in library/workflows/${item.id}.json. {action:"show", id:"${item.id}"} reads it back.`;
|
|
1326
|
+
}
|
|
1327
|
+
throw new Error(`unknown action "${action}" — list, show, save or delete`);
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1262
1330
|
/* fablecut_versions: through the editor server, like fablecut_projects. */
|
|
1263
1331
|
const KIND_LABEL = { manual: "", auto: " (auto)", agent: " (before agent edits)", restore: " (before a restore)" };
|
|
1264
1332
|
function describeVersion(e) {
|
|
@@ -1345,6 +1413,51 @@ async function proxyTool(args) {
|
|
|
1345
1413
|
};
|
|
1346
1414
|
return list.map(line).join("\n") + (busy() ? "\nStill working — call fablecut_proxy again (without create) to check." : "");
|
|
1347
1415
|
}
|
|
1416
|
+
/* ── Files in media/ (fablecut_files) ── */
|
|
1417
|
+
async function filesTool(args) {
|
|
1418
|
+
if (!(await ensureUIServer())) throw new Error(`the editor server is not running and could not be started on port ${PORT}`);
|
|
1419
|
+
const action = args.action || "list";
|
|
1420
|
+
const body = { action, dir: args.dir, from: args.from, to: args.to, paths: args.paths, force: args.force, id: args.id };
|
|
1421
|
+
const r = await apiJSON("POST", "/api/files", body);
|
|
1422
|
+
const name = (src) => { try { return decodeURIComponent(String(src).replace(/^\/media\//, "")); } catch { return src; } };
|
|
1423
|
+
const restoreWith = (t) => `Trashed ${name(t.src)} (id ${t.id} — restore with {action:"restore", id:"${t.id}"})${t.warning ? ` — ${t.warning}` : ""}`;
|
|
1424
|
+
if (r.status !== 200) {
|
|
1425
|
+
// a trash that stopped part-way: the ones that went still need their ids
|
|
1426
|
+
if (r.body?.trashed?.length) throw new Error(r.body.error + "\n" + r.body.trashed.map(restoreWith).join("\n"));
|
|
1427
|
+
throw new Error(r.body?.error || `files request failed (${r.status})`);
|
|
1428
|
+
}
|
|
1429
|
+
const b = r.body;
|
|
1430
|
+
const kb = (n) => n >= 1048576 ? (n / 1048576).toFixed(1) + " MB" : Math.max(1, Math.round(n / 1024)) + " KB";
|
|
1431
|
+
if (action === "list") {
|
|
1432
|
+
const lines = [`media/${b.dir ? b.dir + "/" : ""} — ${b.folders.length} folder${b.folders.length === 1 ? "" : "s"}, ${b.files.length} file${b.files.length === 1 ? "" : "s"}`];
|
|
1433
|
+
for (const f of b.folders) lines.push(` ${f}/`);
|
|
1434
|
+
for (const f of b.files) lines.push(` ${f.name} ${kb(f.size)} ${f.src}`);
|
|
1435
|
+
return lines.join("\n");
|
|
1436
|
+
}
|
|
1437
|
+
if (action === "mkdir") return `Made media/${b.dir}/`;
|
|
1438
|
+
if (action === "move") {
|
|
1439
|
+
if (b.from === b.to) return "Nothing moved (it is already there).";
|
|
1440
|
+
if (!b.moved.length) return `Moved ${name(b.from)}/ → ${name(b.to)}/ (an empty folder)`;
|
|
1441
|
+
const lines = [`Moved ${b.moved.length} file${b.moved.length === 1 ? "" : "s"}:`, ...b.moved.slice(0, 20).map((m) => ` ${name(m.from)} → ${name(m.to)}`)];
|
|
1442
|
+
if (b.moved.length > 20) lines.push(` … +${b.moved.length - 20} more`);
|
|
1443
|
+
lines.push(b.repointed.length ? "Media entries repointed: " + b.repointed.map((x) => `${x.media} in ${x.open ? "the open project" : `"${x.project}"`}`).join(", ") : "No project used them.");
|
|
1444
|
+
if (b.warning) lines.push("Warning: " + b.warning);
|
|
1445
|
+
return lines.join("\n");
|
|
1446
|
+
}
|
|
1447
|
+
if (action === "trash") {
|
|
1448
|
+
const lines = b.trashed.map(restoreWith);
|
|
1449
|
+
if (b.stillThere?.length) lines.push("Still playing (part of the original stayed): " + b.stillThere.map((u) => `"${u.name}"`).join(", "));
|
|
1450
|
+
if (b.offline.length) lines.push("Now OFFLINE: " + b.offline.map((u) => `"${u.name}" in ${u.open ? "the open project" : `"${u.project}"`}`).join(", "));
|
|
1451
|
+
return lines.join("\n");
|
|
1452
|
+
}
|
|
1453
|
+
if (action === "trash-list") {
|
|
1454
|
+
if (!b.items.length) return "The trash is empty.";
|
|
1455
|
+
return b.items.map((t) => `${t.id} ${name(t.src)}${t.kind === "folder" ? `/ (${t.size} files)` : " " + kb(t.size)} trashed ${t.trashed}`).join("\n");
|
|
1456
|
+
}
|
|
1457
|
+
if (action === "restore") return `Restored ${name(b.restored.src)}` + (b.restored.warning ? ` — ${b.restored.warning}` : "");
|
|
1458
|
+
return JSON.stringify(b);
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1348
1461
|
async function exportTool(args) {
|
|
1349
1462
|
if (!(await ensureUIServer())) throw new Error(`the editor server is not running and could not be started on port ${PORT}`);
|
|
1350
1463
|
let startNote = "";
|
|
@@ -1359,7 +1472,10 @@ async function exportTool(args) {
|
|
|
1359
1472
|
if (r.status !== 200) throw new Error(r.body?.error || "no such export job");
|
|
1360
1473
|
job = r.body;
|
|
1361
1474
|
} else {
|
|
1362
|
-
|
|
1475
|
+
if (args.name != null && typeof args.name !== "string") throw new Error("name is a string: the file's name, without the extension");
|
|
1476
|
+
const name = args.name?.trim() || undefined;
|
|
1477
|
+
if (name && args.outputs) throw new Error("name goes with one file, not with outputs (give each output its own filename)");
|
|
1478
|
+
const r = await apiJSON("POST", "/api/export/request", { range: args.range, profile: args.profile, preset: args.preset, delivery: args.delivery, outputs: args.outputs, name, where: args.where || "auto" });
|
|
1363
1479
|
if (r.status !== 200) throw new Error(r.body?.error || `export request failed (${r.status})`);
|
|
1364
1480
|
job = r.body;
|
|
1365
1481
|
if (job.notes && job.notes.length) startNote = `Settings adjusted: ${job.notes.join("; ")}\n`;
|
|
@@ -1600,6 +1716,8 @@ async function callTool(name, args, attempt = 0) {
|
|
|
1600
1716
|
return projectsTool(args);
|
|
1601
1717
|
case "fablecut_versions":
|
|
1602
1718
|
return versionsTool(args);
|
|
1719
|
+
case "fablecut_workflows":
|
|
1720
|
+
return workflowsTool(args);
|
|
1603
1721
|
case "fablecut_status": {
|
|
1604
1722
|
const up = await ensureUIServer();
|
|
1605
1723
|
const proj = readProject();
|
|
@@ -1911,6 +2029,8 @@ async function callTool(name, args, attempt = 0) {
|
|
|
1911
2029
|
`REMAKE RECIPE: 1) set project width/height/fps to ${bp.width}x${bp.height} @ ${bp.fps} — 2) write beats[] into project markers — 3) extracted music on A1 — 4) one clip per shots[] entry at the same start/duration on V1 (hard cuts; footage energy should track each shot's energy value) — 5) biggest moment on drop (${bp.drop}s)${bp.bpm ? ` — tempo ${bp.bpm} BPM` : ""}. Full recipe: fablecut_docs → "Remake a reference video".`,
|
|
1912
2030
|
].join("\n");
|
|
1913
2031
|
}
|
|
2032
|
+
case "fablecut_files":
|
|
2033
|
+
return filesTool(args);
|
|
1914
2034
|
case "fablecut_import_media": {
|
|
1915
2035
|
const src = args.path;
|
|
1916
2036
|
if (!src) throw new Error("path is required");
|
|
@@ -2013,7 +2133,7 @@ async function handle(msg) {
|
|
|
2013
2133
|
result: {
|
|
2014
2134
|
protocolVersion: negotiateProtocolVersion(params?.protocolVersion),
|
|
2015
2135
|
capabilities: { tools: {} },
|
|
2016
|
-
serverInfo: { name: "fablecut", version: "1.
|
|
2136
|
+
serverInfo: { name: "fablecut", version: "1.20.0" },
|
|
2017
2137
|
},
|
|
2018
2138
|
});
|
|
2019
2139
|
}
|
package/media-files.js
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/* The project's files on disk: folders, moves and a trash, all inside media/.
|
|
2
|
+
|
|
3
|
+
The media bin's folders and collections only organize entries in
|
|
4
|
+
project.json; this is the folder itself — so an agent (or the user) can
|
|
5
|
+
tidy downloads into subfolders, rename a file, and throw away what isn't
|
|
6
|
+
used, without leaving the editor. Nothing here deletes a file: "trash"
|
|
7
|
+
moves it into media/.trash/<id>/files/ beside a note of where it came from
|
|
8
|
+
(<id>/item.json), and "restore" puts it back. Dot-folders are never listed,
|
|
9
|
+
served as media or offered by Relink, so trashed files are out of the way
|
|
10
|
+
but still there.
|
|
11
|
+
|
|
12
|
+
createMediaFiles({mediaDir}) → {
|
|
13
|
+
list(dir?) → {dir, folders:[name], files:[{name, src, size}]} (one level)
|
|
14
|
+
mkdir(dir) → {dir} (parents too; an existing one is fine)
|
|
15
|
+
move(from, to, {exact}?) → {from, to, moved:[{from, to}]} (srcs: the item, and every file in it;
|
|
16
|
+
exact: `to` is the new path itself, never a folder to go into)
|
|
17
|
+
trash(paths) → {trashed:[{id, src}], moved:[{from, to}]}
|
|
18
|
+
trashList() → [{id, src, kind, size, trashed}]
|
|
19
|
+
restore(id) → {restored:{id, src}, moved:[{from, to}]}
|
|
20
|
+
filesOf(path) → the /media/… srcs of the files at or under a path
|
|
21
|
+
pathOf(src) → the absolute path of a /media/… src inside media/, or null
|
|
22
|
+
}
|
|
23
|
+
canonicalSrc(src) → a /media/… src decoded with doubled slashes folded,
|
|
24
|
+
the form two srcs of the same file share
|
|
25
|
+
Paths are relative to media/ ("b-roll/day 1/a.mp4") or /media/… srcs; "..",
|
|
26
|
+
dot-segments and symlinks on the way are refused. `moved` lists every file
|
|
27
|
+
that changed place as /media/… srcs, so callers can repoint media entries. */
|
|
28
|
+
"use strict";
|
|
29
|
+
const fs = require("fs");
|
|
30
|
+
const path = require("path");
|
|
31
|
+
|
|
32
|
+
const TRASH = ".trash";
|
|
33
|
+
const toSrc = (rel) => "/media/" + rel.split(/[\\/]/).map(encodeURIComponent).join("/");
|
|
34
|
+
function canonicalSrc(src) {
|
|
35
|
+
let s = String(src || "").split("?")[0];
|
|
36
|
+
try { s = decodeURIComponent(s); } catch { }
|
|
37
|
+
return s.replace(/\\/g, "/").replace(/\/{2,}/g, "/");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function createMediaFiles({ mediaDir }) {
|
|
41
|
+
const root = path.resolve(mediaDir);
|
|
42
|
+
const trashDir = path.join(root, TRASH);
|
|
43
|
+
|
|
44
|
+
/** Throws when a path on the way from media/ to `abs` (as far as it exists) is a symlink. */
|
|
45
|
+
function noLinks(abs) {
|
|
46
|
+
const parts = path.relative(root, abs).split(path.sep).filter(Boolean);
|
|
47
|
+
let cur = root;
|
|
48
|
+
for (const part of parts) {
|
|
49
|
+
cur = path.join(cur, part);
|
|
50
|
+
let st;
|
|
51
|
+
try { st = fs.lstatSync(cur); } catch { return; } // nothing there yet: nothing to follow
|
|
52
|
+
if (st.isSymbolicLink()) throw new Error(`${JSON.stringify(path.relative(root, cur).split(path.sep).join("/"))} is a link — FableCut only moves real files and folders in media/`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** "a/b.mp4" or "/media/a/b.mp4" → {rel, abs}; throws on anything outside media/.
|
|
56
|
+
raw: a path as stored (no "/media" / "media" shorthand for the folder itself). */
|
|
57
|
+
function resolve(p, { allowRoot = false, raw = false } = {}) {
|
|
58
|
+
let s = String(p == null ? "" : p).replace(/\\/g, "/");
|
|
59
|
+
if (!raw) s = s.trim(); // a stored path keeps its spaces: " take.mp4" is a real name
|
|
60
|
+
if (!raw) {
|
|
61
|
+
if (s.startsWith("/media/")) { try { s = decodeURIComponent(s.slice(7)); } catch { throw new Error(`bad path ${JSON.stringify(p)}`); } }
|
|
62
|
+
else if (s === "/media" || s === "media" || s === "media/") s = "";
|
|
63
|
+
}
|
|
64
|
+
s = s.replace(/^\/+|\/+$/g, "");
|
|
65
|
+
const parts = s ? s.split("/") : [];
|
|
66
|
+
if (parts.some((x) => !x || x === "." || x === ".." || x.startsWith(".")))
|
|
67
|
+
throw new Error(`${JSON.stringify(p)} is not a path inside media/ (no "..", no dot-folders)`);
|
|
68
|
+
if (parts.some((x) => /[<>:"|?*\x00-\x1f]/.test(x) || x.length > 120))
|
|
69
|
+
throw new Error(`${JSON.stringify(p)} has a name that isn't allowed (< > : " | ? * or over 120 characters)`);
|
|
70
|
+
if (!parts.length && !allowRoot) throw new Error("name a file or folder inside media/");
|
|
71
|
+
const rel = parts.join("/");
|
|
72
|
+
const abs = rel ? path.join(root, ...parts) : root;
|
|
73
|
+
noLinks(abs);
|
|
74
|
+
return { rel, abs };
|
|
75
|
+
}
|
|
76
|
+
const stat = (abs) => { try { return fs.statSync(abs); } catch { return null; } };
|
|
77
|
+
/** Every file under `abs` as paths relative to media/ (a file: itself). */
|
|
78
|
+
function filesUnder(abs) {
|
|
79
|
+
const st = stat(abs);
|
|
80
|
+
if (!st) return [];
|
|
81
|
+
if (st.isFile()) return [path.relative(root, abs).split(path.sep).join("/")];
|
|
82
|
+
const out = [];
|
|
83
|
+
const walk = (d) => {
|
|
84
|
+
for (const e of fs.readdirSync(d, { withFileTypes: true })) {
|
|
85
|
+
const full = path.join(d, e.name);
|
|
86
|
+
if (e.isSymbolicLink()) throw new Error(`${JSON.stringify(path.relative(root, full).split(path.sep).join("/"))} is a link — FableCut only moves real files and folders in media/`);
|
|
87
|
+
if (e.isDirectory()) walk(full); else if (e.isFile()) out.push(path.relative(root, full).split(path.sep).join("/"));
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
walk(abs);
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
const relOf = (abs) => path.relative(root, abs).split(path.sep).join("/");
|
|
94
|
+
const taken = (toAbs) => Object.assign(new Error(`${JSON.stringify(relOf(toAbs))} already exists — pick another name`), { code: "EEXIST" });
|
|
95
|
+
/** Put `fromAbs` at `toAbs` without replacing anything there: a file is hard-linked to
|
|
96
|
+
its new name (which fails if the name is taken) and then unlinked; a folder is
|
|
97
|
+
renamed, which never lands on a folder with something in it. */
|
|
98
|
+
function publish(fromAbs, toAbs) {
|
|
99
|
+
if (fs.lstatSync(fromAbs).isFile()) {
|
|
100
|
+
try { fs.linkSync(fromAbs, toAbs); }
|
|
101
|
+
catch (e) {
|
|
102
|
+
if (e.code === "EEXIST") throw taken(toAbs);
|
|
103
|
+
if (e.code === "EXDEV") throw e;
|
|
104
|
+
// a file system without hard links: check, then rename
|
|
105
|
+
if (fs.existsSync(toAbs)) throw taken(toAbs);
|
|
106
|
+
fs.renameSync(fromAbs, toAbs);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
fs.unlinkSync(fromAbs);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
// a folder: Windows never renames onto an existing folder; elsewhere an empty folder made
|
|
113
|
+
// here first holds the name (mkdir fails if it is taken), and the rename replaces only it
|
|
114
|
+
if (process.platform === "win32") {
|
|
115
|
+
if (fs.existsSync(toAbs)) throw taken(toAbs);
|
|
116
|
+
fs.renameSync(fromAbs, toAbs);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
try { fs.mkdirSync(toAbs); } catch (e) { if (e.code === "EEXIST") throw taken(toAbs); throw e; }
|
|
120
|
+
try { fs.renameSync(fromAbs, toAbs); }
|
|
121
|
+
catch (e) { try { fs.rmdirSync(toAbs); } catch { } throw e.code === "ENOTEMPTY" || e.code === "EEXIST" ? taken(toAbs) : e; }
|
|
122
|
+
}
|
|
123
|
+
/** Move `fromAbs` to `toAbs` (both inside media/), creating the folder above; a name
|
|
124
|
+
taken meanwhile is refused, never replaced. Across drives the copy goes to a staging
|
|
125
|
+
name first (timestamps kept, so the file's transcript still matches it) and takes
|
|
126
|
+
the final name only once it is complete. If removing the original then fails, the
|
|
127
|
+
error says so with `published: true`: the copy is whole and stays. */
|
|
128
|
+
function rename(fromAbs, toAbs) {
|
|
129
|
+
fs.mkdirSync(path.dirname(toAbs), { recursive: true });
|
|
130
|
+
try { publish(fromAbs, toAbs); return; }
|
|
131
|
+
catch (e) { if (e.code !== "EXDEV") throw e; }
|
|
132
|
+
const stage = path.join(path.dirname(toAbs), `.fc-move-${process.pid}-${Date.now().toString(36)}`);
|
|
133
|
+
try {
|
|
134
|
+
fs.cpSync(fromAbs, stage, { recursive: true, errorOnExist: true, force: false, preserveTimestamps: true });
|
|
135
|
+
publish(stage, toAbs);
|
|
136
|
+
} catch (e) {
|
|
137
|
+
fs.rmSync(stage, { recursive: true, force: true });
|
|
138
|
+
throw e;
|
|
139
|
+
}
|
|
140
|
+
try { fs.rmSync(fromAbs, { recursive: true, force: true }); }
|
|
141
|
+
catch (e) {
|
|
142
|
+
throw Object.assign(new Error(`copied to ${relOf(toAbs)}, but the original could not be removed (${e.code || e.message}) — both copies are there`), { published: true });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** [{from, to}] srcs for what moved from `fromRel` to `toRel`, given the files that were under fromRel. */
|
|
146
|
+
const pairs = (files, fromRel, toRel) => files.map((f) => ({ from: toSrc(f), to: toSrc(toRel + f.slice(fromRel.length)) }));
|
|
147
|
+
const readItem = (id) => {
|
|
148
|
+
if (!/^t[a-z0-9]{4,20}$/.test(String(id || ""))) return null;
|
|
149
|
+
try { return JSON.parse(fs.readFileSync(path.join(trashDir, id, "item.json"), "utf8")); } catch { return null; }
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
filesOf(p) { const r = resolve(p); if (!stat(r.abs)) throw new Error(`no file or folder ${JSON.stringify(r.rel)} in media/`); return filesUnder(r.abs).map(toSrc); },
|
|
154
|
+
pathOf(src) { try { const r = resolve(src); return stat(r.abs)?.isFile() ? r.abs : null; } catch { return null; } },
|
|
155
|
+
list(dir) {
|
|
156
|
+
const { rel, abs } = resolve(dir, { allowRoot: true });
|
|
157
|
+
const st = stat(abs);
|
|
158
|
+
if (!st || !st.isDirectory()) throw new Error(`no folder ${rel ? JSON.stringify(rel) : "media/"}`);
|
|
159
|
+
const folders = [], files = [];
|
|
160
|
+
for (const e of fs.readdirSync(abs, { withFileTypes: true })) {
|
|
161
|
+
if (e.name.startsWith(".") || e.isSymbolicLink()) continue;
|
|
162
|
+
const r = rel ? rel + "/" + e.name : e.name;
|
|
163
|
+
if (e.isDirectory()) folders.push(e.name);
|
|
164
|
+
else if (e.isFile()) files.push({ name: e.name, src: toSrc(r), size: stat(path.join(abs, e.name))?.size || 0 });
|
|
165
|
+
}
|
|
166
|
+
const byName = (a, b) => String(a.name || a).localeCompare(String(b.name || b), undefined, { numeric: true });
|
|
167
|
+
return { dir: rel, folders: folders.sort(byName), files: files.sort(byName) };
|
|
168
|
+
},
|
|
169
|
+
mkdir(dir) {
|
|
170
|
+
const { rel, abs } = resolve(dir);
|
|
171
|
+
const st = stat(abs);
|
|
172
|
+
if (st && !st.isDirectory()) throw new Error(`${JSON.stringify(rel)} is a file`);
|
|
173
|
+
fs.mkdirSync(abs, { recursive: true });
|
|
174
|
+
return { dir: rel };
|
|
175
|
+
},
|
|
176
|
+
move(from, to, { exact = false } = {}) {
|
|
177
|
+
if (to == null || String(to).trim() === "") throw new Error("say where to move it: a folder, a new name, or \"/media/\" for the top of media/");
|
|
178
|
+
const a = resolve(from), b = resolve(to, { allowRoot: true });
|
|
179
|
+
const st = stat(a.abs);
|
|
180
|
+
if (!st) throw new Error(`no file or folder ${JSON.stringify(a.rel)} in media/`);
|
|
181
|
+
// into an existing folder keeps the name; otherwise `to` is the new path
|
|
182
|
+
const into = !exact && stat(b.abs)?.isDirectory();
|
|
183
|
+
const destRel = into ? (b.rel ? b.rel + "/" : "") + path.basename(a.abs) : b.rel;
|
|
184
|
+
const destAbs = into ? path.join(b.abs, path.basename(a.abs)) : b.abs;
|
|
185
|
+
if (destAbs === a.abs) return { from: toSrc(a.rel), to: toSrc(a.rel), moved: [] };
|
|
186
|
+
if (st.isDirectory() && (destAbs + path.sep).startsWith(a.abs + path.sep)) throw new Error(`can't move ${JSON.stringify(a.rel)} into itself`);
|
|
187
|
+
if (stat(destAbs)) throw new Error(`${JSON.stringify(destRel)} already exists — pick another name`);
|
|
188
|
+
noLinks(destAbs);
|
|
189
|
+
const files = filesUnder(a.abs);
|
|
190
|
+
const result = { from: toSrc(a.rel), to: toSrc(destRel), moved: pairs(files, a.rel, destRel) };
|
|
191
|
+
// a copy that is whole at the new place but left part of the original: it moved (with a warning)
|
|
192
|
+
try { rename(a.abs, destAbs); } catch (e) { if (e.published) e.result = result; throw e; }
|
|
193
|
+
return result;
|
|
194
|
+
},
|
|
195
|
+
trash(paths) {
|
|
196
|
+
const list = (Array.isArray(paths) ? paths : [paths]).map((p) => resolve(p));
|
|
197
|
+
for (const r of list) if (!stat(r.abs)) throw new Error(`no file or folder ${JSON.stringify(r.rel)} in media/`);
|
|
198
|
+
// one item inside another would be gone by the time its turn came
|
|
199
|
+
for (const r of list) for (const o of list) {
|
|
200
|
+
if (r === o) continue;
|
|
201
|
+
if (r.rel === o.rel) throw new Error(`${JSON.stringify(r.rel)} is listed twice`);
|
|
202
|
+
if ((r.rel + "/").startsWith(o.rel + "/")) throw new Error(`${JSON.stringify(r.rel)} is inside ${JSON.stringify(o.rel)} — trash the folder, or the file, not both`);
|
|
203
|
+
}
|
|
204
|
+
const trashed = [], moved = [];
|
|
205
|
+
// a failure part-way through says what already went (`partial`), so those can be restored
|
|
206
|
+
const fail = (e, src) => { throw Object.assign(e, { partial: { trashed, moved, failed: src } }); };
|
|
207
|
+
fs.mkdirSync(trashDir, { recursive: true });
|
|
208
|
+
for (const r of list) {
|
|
209
|
+
const st = stat(r.abs);
|
|
210
|
+
const files = filesUnder(r.abs);
|
|
211
|
+
// each item's folder is made without `recursive`, so a taken id is never shared
|
|
212
|
+
let id, box;
|
|
213
|
+
for (let i = 0; ; i++) {
|
|
214
|
+
id = "t" + Date.now().toString(36) + Math.random().toString(36).slice(2, 6);
|
|
215
|
+
box = path.join(trashDir, id);
|
|
216
|
+
try { fs.mkdirSync(box); break; }
|
|
217
|
+
catch (e) { if (e.code !== "EEXIST" || i > 20) fail(e, toSrc(r.rel)); }
|
|
218
|
+
}
|
|
219
|
+
// the record goes first: if the move then fails it is removed, and nothing is lost either way
|
|
220
|
+
try {
|
|
221
|
+
fs.writeFileSync(path.join(box, "item.json"), JSON.stringify({
|
|
222
|
+
id, src: toSrc(r.rel), rel: r.rel, kind: st.isDirectory() ? "folder" : "file",
|
|
223
|
+
size: st.isDirectory() ? files.length : st.size, trashed: new Date().toISOString(),
|
|
224
|
+
}, null, 2));
|
|
225
|
+
rename(r.abs, path.join(box, "files", path.basename(r.abs)));
|
|
226
|
+
} catch (e) {
|
|
227
|
+
if (e.published) {
|
|
228
|
+
// the trash holds a whole copy, and part of the original may be gone: keep the copy
|
|
229
|
+
trashed.push({ id, src: toSrc(r.rel), warning: e.message });
|
|
230
|
+
for (const f of files) moved.push({ from: toSrc(f), to: null });
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
fs.rmSync(box, { recursive: true, force: true });
|
|
234
|
+
fail(e, toSrc(r.rel));
|
|
235
|
+
}
|
|
236
|
+
trashed.push({ id, src: toSrc(r.rel) });
|
|
237
|
+
for (const f of files) moved.push({ from: toSrc(f), to: null });
|
|
238
|
+
}
|
|
239
|
+
return { trashed, moved };
|
|
240
|
+
},
|
|
241
|
+
trashList() {
|
|
242
|
+
let ids = [];
|
|
243
|
+
try { ids = fs.readdirSync(trashDir); } catch { return []; }
|
|
244
|
+
const out = [];
|
|
245
|
+
for (const id of ids) {
|
|
246
|
+
const it = readItem(id);
|
|
247
|
+
if (it) out.push({ id: it.id, src: it.src, kind: it.kind, size: it.size, trashed: it.trashed });
|
|
248
|
+
}
|
|
249
|
+
return out.sort((a, b) => String(b.trashed).localeCompare(String(a.trashed)));
|
|
250
|
+
},
|
|
251
|
+
restore(id) {
|
|
252
|
+
const it = readItem(id);
|
|
253
|
+
if (!it) throw new Error(`no trashed item ${JSON.stringify(id)} (list the trash first)`);
|
|
254
|
+
const back = resolve(it.rel, { raw: true });
|
|
255
|
+
if (stat(back.abs)) throw new Error(`${JSON.stringify(it.rel)} exists again — move it away first, then restore`);
|
|
256
|
+
const src = path.join(trashDir, id, "files", path.basename(back.abs));
|
|
257
|
+
if (!fs.existsSync(src)) throw new Error(`trashed item ${id} has no files left to restore`);
|
|
258
|
+
const inner = filesUnder(src).map((f) => f.slice((TRASH + "/" + id + "/files/").length));
|
|
259
|
+
let warning;
|
|
260
|
+
try { rename(src, back.abs); }
|
|
261
|
+
catch (e) { if (!e.published) throw e; warning = e.message; }
|
|
262
|
+
// the file is back: a record left behind is only clutter in the trash list
|
|
263
|
+
try { if (!warning) fs.rmSync(path.join(trashDir, id), { recursive: true, force: true }); }
|
|
264
|
+
catch (e) { warning = `restored, but its trash entry ${id} couldn't be removed (${e.code || e.message})`; }
|
|
265
|
+
const parent = back.rel.slice(0, back.rel.length - path.basename(back.abs).length);
|
|
266
|
+
return { restored: { id, src: it.src, ...(warning ? { warning } : {}) }, moved: inner.map((f) => ({ from: null, to: toSrc(parent + f) })) };
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
module.exports = { createMediaFiles, canonicalSrc, TRASH };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fablecut",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
4
4
|
"description": "Zero-dependency browser video editor that AI agents can drive — JSON timeline, MCP server, REST API, live-reloading UI.",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"bin": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"favicon.svg",
|
|
14
14
|
"icons/",
|
|
15
15
|
"encoding-profiles.json",
|
|
16
|
+
"manifest.json",
|
|
16
17
|
"CLAUDE.md",
|
|
17
18
|
"library/README.md",
|
|
18
19
|
"library/elements/",
|
|
@@ -42,6 +43,6 @@
|
|
|
42
43
|
"mcpName": "io.github.ronak-create/fablecut",
|
|
43
44
|
"license": "MIT",
|
|
44
45
|
"engines": {
|
|
45
|
-
"node": ">=
|
|
46
|
+
"node": ">=22"
|
|
46
47
|
}
|
|
47
48
|
}
|
package/paths.js
CHANGED
|
@@ -40,7 +40,7 @@ const FRAMES_DIR = path.join(ANALYSIS_DIR, "frames");
|
|
|
40
40
|
A regenerable cache too, so also inside analysis/. */
|
|
41
41
|
const PROXIES_DIR = path.join(ANALYSIS_DIR, "proxies");
|
|
42
42
|
const PROJECT_FILE = path.join(DATA_DIR, "project.json");
|
|
43
|
-
const LIBRARY_SUBDIRS = ["sfx", "elements", "svg", "fonts", "presets", "templates"];
|
|
43
|
+
const LIBRARY_SUBDIRS = ["sfx", "elements", "svg", "fonts", "presets", "templates", "workflows"];
|
|
44
44
|
|
|
45
45
|
/* The asset library ships with the repo but users also drop their own files in
|
|
46
46
|
(library/sfx is gitignored precisely for that). When the data dir is split
|
|
@@ -106,8 +106,9 @@ function ensureDirs() {
|
|
|
106
106
|
seedLibrary();
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
/* Saved animation presets and
|
|
110
|
-
and library/
|
|
109
|
+
/* Saved animation presets, templates and workflows: one JSON file each in library/presets/,
|
|
110
|
+
library/templates/ and library/workflows/ (templates.js / workflows.js validate them).
|
|
111
|
+
Unreadable files are skipped. */
|
|
111
112
|
function readSaved(kind) {
|
|
112
113
|
const dir = path.join(LIBRARY_DIR, kind);
|
|
113
114
|
let names = [];
|