fablecut 1.21.0 → 1.22.1

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/clips.js ADDED
@@ -0,0 +1,207 @@
1
+ /* FableCut clips — a long video into short clips, one call. The agent picks the
2
+ segments (from the transcript: a tip, an answer, a story); for each one this makes
3
+ a new sequence on the clip's canvas holding only that part of the open timeline,
4
+ then frames it (reframe), adds a hook title and captions, and can export it.
5
+ Zero dependencies; loaded by the editor as a plain script (global
6
+ `FableCutClips`) and required by the MCP server, so fablecut_clips and Studio
7
+ run the same steps. The steps themselves are the editor's own tools, passed in
8
+ as `env`: read() the project, patch(ops), reframe(args), captions(args),
9
+ exportClip(args) — each answering text, or throwing — and, optionally, progress(text)
10
+ as each clip and step starts. exportClip gets a `timeout` (seconds) for that clip and
11
+ answers once its export has ended (done, failed, or stopped when its time was up): the
12
+ next clip opens another sequence, and the editor renders the open one live. An answer
13
+ that says it is still running stops the batch there. */
14
+ (function (root, factory) {
15
+ const api = factory();
16
+ if (typeof module === "object" && module.exports) module.exports = api;
17
+ else root.FableCutClips = api;
18
+ })(typeof self !== "undefined" ? self : this, function () {
19
+ "use strict";
20
+
21
+ const ASPECTS = { "9:16": [9, 16], "1:1": [1, 1], "4:5": [4, 5], "16:9": [16, 9] };
22
+ const CAPTION_STYLES = ["pop", "highlight", "karaoke", "subtitle"];
23
+ const MAX_CLIPS = 10, MIN_LEN = 3, MAX_LEN = 180, TITLE_SECS = 3;
24
+ // each clip's export gets this long (3 min, or 6 s per second of the clip): one stuck past it is stopped
25
+ // and reported, so it can't hold up the clips after it
26
+ const EXPORT_MIN_S = 180, EXPORT_PER_S = 6;
27
+
28
+ /** The canvas for a shape, keeping the project's shorter side (1920×1080 → 1080×1920 for 9:16), even sizes. */
29
+ function canvasFor(aspect, W, H) {
30
+ const r = ASPECTS[aspect];
31
+ if (!r) throw new Error(`aspect must be one of ${Object.keys(ASPECTS).join(", ")}`);
32
+ const short = Math.min(W || 1920, H || 1080);
33
+ const even = (v) => Math.max(16, Math.round(v / 2) * 2);
34
+ return r[0] <= r[1] ? { width: even(short), height: even(short * r[1] / r[0]) } : { width: even(short * r[0] / r[1]), height: even(short) };
35
+ }
36
+ const end = (doc) => (doc.clips || []).reduce((m, c) => Math.max(m, (+c.start || 0) + (+c.duration || 0)), 0);
37
+ const clean = (s, n) => String(s == null ? "" : s).replace(/\s+/g, " ").trim().slice(0, n);
38
+ const fileName = (s) => clean(s, 60).replace(/[\\/:*?"<>|]+/g, "").replace(/\s+/g, "-").toLowerCase() || "clip";
39
+
40
+ /** Checked arguments: {clips:[{from, to, name, title}], aspect, captions, title, exportPreset}. Throws on anything wrong. */
41
+ function options(args, doc) {
42
+ args = args || {};
43
+ const list = args.clips;
44
+ if (!Array.isArray(list) || !list.length) throw new Error("clips must be a list of {from, to, name?, title?} — the parts of the timeline to make into clips (seconds)");
45
+ if (list.length > MAX_CLIPS) throw new Error(`up to ${MAX_CLIPS} clips at a time`);
46
+ const len = end(doc);
47
+ if (!(len > 0)) throw new Error("the open timeline is empty — put the long video on it first");
48
+ // each clip is cut out of a copy by extracting the rest, and an extract leaves locked material as it is:
49
+ // the copy would keep it whole and out of step with the rest, so the call is refused before anything changes
50
+ const lockedLanes = new Set(Array.isArray(doc.lockedTracks) ? doc.lockedTracks : []);
51
+ const locked = (doc.clips || []).filter((c) => c && (c.locked || lockedLanes.has(c.track)));
52
+ if (locked.length) throw new Error(`the timeline has locked material (${locked.slice(0, 4).map((c) => c.id + " on " + c.track).join(", ")}${locked.length > 4 ? ", …" : ""}): ` +
53
+ "clips are cut out of a copy by extracting the rest, and locked clips can't be cut — unlock them (updateClip set:{locked:null}, or the lane's lock) only if the user agrees, then call again");
54
+ const clips = list.map((c, i) => {
55
+ const from = +(c && c.from), to = +(c && c.to);
56
+ if (!Number.isFinite(from) || !Number.isFinite(to)) throw new Error(`clip ${i + 1}: from and to must be numbers (timeline seconds)`);
57
+ if (from < 0 || to > len + 0.05) throw new Error(`clip ${i + 1}: ${from}–${to} s is outside the timeline (0–${len.toFixed(2)} s)`);
58
+ if (to - from < MIN_LEN) throw new Error(`clip ${i + 1}: at least ${MIN_LEN} s`);
59
+ if (to - from > MAX_LEN) throw new Error(`clip ${i + 1}: at most ${MAX_LEN} s`);
60
+ return { from: Math.round(from * 1000) / 1000, to: Math.round(Math.min(to, len) * 1000) / 1000,
61
+ name: clean(c.name, 80) || `Clip ${i + 1}`, title: clean(c.title, 120) };
62
+ });
63
+ const aspect = args.aspect == null ? "9:16" : String(args.aspect);
64
+ if (!ASPECTS[aspect]) throw new Error(`aspect must be one of ${Object.keys(ASPECTS).join(", ")}`);
65
+ let captions = args.captions == null ? "pop" : args.captions;
66
+ if (captions !== false && !CAPTION_STYLES.includes(captions)) throw new Error(`captions must be one of ${CAPTION_STYLES.join(", ")}, or false`);
67
+ const exportPreset = args.export == null || args.export === false ? null : String(args.export);
68
+ return { clips, aspect, captions, title: args.title !== false, reframe: args.reframe !== false, exportPreset };
69
+ }
70
+
71
+ /** The hook title: big outlined words in the top third, popping in for the first seconds. */
72
+ function titleClip(id, text, track, W, H, len) {
73
+ const size = Math.round(Math.min(W, H) * 0.085);
74
+ return { id, kind: "text", mediaId: null, track, start: 0, in: 0, duration: Math.min(TITLE_SECS, len), name: "Hook title",
75
+ props: { text, font: "Anton", fontSize: size, uppercase: true, color: "#ffffff", strokeWidth: Math.max(3, Math.round(size * 0.07)),
76
+ strokeColor: "#000000", textShadow: 12, align: "center", boxW: Math.round(W * 0.86), boxH: Math.round(H * 0.22), boxFit: true,
77
+ y: -Math.round(H * 0.36), textAnim: "word-pop", wordRate: 0.12 },
78
+ transitionOut: { type: "fade", duration: 0.3 } };
79
+ }
80
+ /** The top video lane, when nothing is on it during the title; else null (the title is left out). */
81
+ function freeTopLane(doc, until) {
82
+ const lanes = (Array.isArray(doc.tracks) && doc.tracks.length ? doc.tracks : [{ id: "V3", kind: "video" }, { id: "V2", kind: "video" }, { id: "V1", kind: "video" }])
83
+ .filter((t) => t && t.kind === "video").map((t) => t.id).sort((a, b) => +b.slice(1) - +a.slice(1));
84
+ const top = lanes[0];
85
+ if (!top || (doc.lockedTracks || []).includes(top)) return null;
86
+ return (doc.clips || []).some((c) => c.track === top && c.start < until && c.start + c.duration > 0) ? null : top;
87
+ }
88
+ const first = (s) => String(s || "").split("\n")[0].slice(0, 200);
89
+ /** An export answer that says it hasn't ended ("Export x_1 running — 40% …"). */
90
+ const RUNNING = /\bExport (?:\S+ )?(?:pending|running|queued)\b/;
91
+
92
+ /** exportClip for a host whose exports run as jobs it can poll and cancel: start one, wait up to
93
+ * a.timeout for its end, cancel it past that, and answer once its status says it ended — else
94
+ * "Export <id> running: …", which stops the batch. io: start(a) → text naming the job (throws only
95
+ * when nothing was accepted), status(id, waitSecs) → text, cancel(id), sleep(ms). */
96
+ async function exportUntilEnded(io, a) {
97
+ const started = String(await io.start(a));
98
+ const id = (/\bExport (\S+) /.exec(started) || [])[1];
99
+ if (!id || !RUNNING.test(started)) return started;
100
+ let r;
101
+ try { r = String(await io.status(id, a.timeout)); }
102
+ catch (e) { r = `Export ${id} running (its status couldn't be read: ${first(e && e.message)})`; }
103
+ if (!RUNNING.test(r)) return r;
104
+ try { await io.cancel(id); } catch { }
105
+ await io.sleep(2000); // a running tab hears the cancel in the answer to its next progress report, once a second
106
+ let now = "";
107
+ try { now = String(await io.status(id, 0)); } catch { }
108
+ if (/\bExport \S+ done\b/.test(now)) return now;
109
+ if (/\bExport \S+ (?:cancelled|failed)\b/.test(now)) return `Export ${id} stopped: it didn't finish in ${a.timeout} s`;
110
+ return `Export ${id} running: it couldn't be confirmed stopped${now ? " (" + first(now) + ")" : ""}`;
111
+ }
112
+
113
+ /** Make the clips. Returns the reply text. */
114
+ async function run(args, env) {
115
+ const doc0 = await env.read();
116
+ const o = options(args, doc0);
117
+ const canvas = canvasFor(o.aspect, doc0.width, doc0.height);
118
+ const reshaped = canvas.width * (doc0.height || 1080) !== canvas.height * (doc0.width || 1920);
119
+ let source = doc0.sequence || null, opened = false, halted = null;
120
+ const taken = new Set((doc0.sequences || []).map((s) => s.id));
121
+ const made = [], lines = [];
122
+ const step = (i, what) => { if (typeof env.progress === "function") env.progress(`clip ${i + 1} of ${o.clips.length}, ${what}`, made.length); };
123
+ // measured on the source as it was (the open sequence may be the last clip by now); every lane named,
124
+ // since an extract given none skips the untargeted ones, and those must be cut too
125
+ const total = end(doc0);
126
+ const lanes = doc0.tracks && doc0.tracks.length ? doc0.tracks.map((t) => t.id) : [...new Set((doc0.clips || []).map((x) => x.track).filter(Boolean))];
127
+ for (let i = 0; i < o.clips.length; i++) {
128
+ const c = o.clips[i];
129
+ step(i, "cutting");
130
+ let id = "seq_clip" + (i + 1);
131
+ for (let n = 2; taken.has(id); n++) id = "seq_clip" + (i + 1) + "_" + n;
132
+ taken.add(id);
133
+ // the copy: the source timeline on the clip's canvas, cut down to from → to
134
+ const ops = [];
135
+ if (opened) ops.push({ op: "openSequence", id: source }); // the last clip's sequence is open
136
+ ops.push({ op: "addSequence", id, name: c.name, from: "open", width: canvas.width, height: canvas.height, open: true });
137
+ if (c.to < total - 0.001) ops.push({ op: "extract", from: c.to, to: total + 1, tracks: lanes });
138
+ if (c.from > 0.001) ops.push({ op: "extract", from: 0, to: c.from, tracks: lanes });
139
+ ops.push({ op: "setProject", set: { inPoint: null, outPoint: null } });
140
+ // a patch saves all of it or nothing: a clip that can't be cut is reported, and the next one goes on
141
+ try { await env.patch(ops); }
142
+ catch (e) { lines.push(` ${i + 1}. "${c.name}": not made (${first(e.message)})`); continue; }
143
+ opened = true;
144
+ if (!source) source = ((await env.read()).sequences || []).find((s) => s.id !== id)?.id || "main";
145
+ const len = Math.round((c.to - c.from) * 1000) / 1000, notes = [];
146
+ if (o.reframe && reshaped) {
147
+ step(i, "framing");
148
+ // the editor may save while the footage is read (just after opening, probing media): try once more
149
+ let err = null;
150
+ for (let k = 0; k < 2; k++) {
151
+ try { await env.reframe({}); err = null; break; }
152
+ catch (e) { err = e; if (!/changed/i.test(e.message)) break; }
153
+ }
154
+ notes.push(err ? "not reframed (" + first(err.message) + ")" : "framed on the subject");
155
+ }
156
+ if (o.title && c.title) {
157
+ const now = await env.read(), lane = freeTopLane(now, Math.min(TITLE_SECS, len));
158
+ if (lane) {
159
+ try { await env.patch([{ op: "addClip", clip: titleClip(id + "_title", c.title, lane, canvas.width, canvas.height, len) }]); notes.push(`hook title "${c.title}"`); }
160
+ catch (e) { notes.push("no title (" + first(e.message) + ")"); }
161
+ } else notes.push("no title (the top video lane is busy or locked — add a lane, then a title)");
162
+ }
163
+ if (o.captions) {
164
+ step(i, "captions");
165
+ try {
166
+ const r = String(await env.captions({ style: o.captions }));
167
+ // still transcribing (Studio answers before a long first transcription is done): say so, don't claim them
168
+ if (/call \S+ again|carries on/i.test(r)) notes.push("captions not added yet: the speech is still being transcribed — then openSequence and fablecut_captions {style:\"" + o.captions + "\"}");
169
+ else notes.push(o.captions + " captions");
170
+ }
171
+ catch (e) { notes.push("no captions (" + first(e.message) + ")"); }
172
+ }
173
+ let file = "", haltWhy = "";
174
+ if (o.exportPreset) {
175
+ step(i, "exporting");
176
+ try {
177
+ const r = String(await env.exportClip({ preset: o.exportPreset, name: fileName(c.name), timeout: Math.max(EXPORT_MIN_S, Math.ceil(len * EXPORT_PER_S)) }));
178
+ file = (r.match(/exports\/[^\s"'),]+/) || [""])[0];
179
+ // an export that hasn't ended still renders the open sequence: opening another one would change its frames
180
+ if (RUNNING.test(r)) { file = ""; haltWhy = "its export is still running"; notes.push("not exported (" + first(r) + ")"); }
181
+ // only a finished export counts: a stopped one is reported as it is
182
+ else if (file && !/ (failed|cancelled)\b|check again/i.test(r)) notes.push("exported → " + file);
183
+ else { file = ""; notes.push("not exported (" + first(r) + ")"); }
184
+ } catch (e) {
185
+ // the request failed: whether the export started isn't known, and one that did renders the open sequence
186
+ notes.push("not exported (" + first(e.message) + ")");
187
+ haltWhy = "its export request failed, so whether it started isn't known";
188
+ }
189
+ }
190
+ made.push({ id, name: c.name, file });
191
+ lines.push(` ${i + 1}. "${c.name}" (${id}, ${len.toFixed(1)} s from ${c.from.toFixed(2)}–${c.to.toFixed(2)} s): ${notes.join(", ") || "made"}`);
192
+ if (haltWhy) {
193
+ halted = { clip: c.name, why: haltWhy };
194
+ if (i + 1 < o.clips.length) lines.push(` The clips after "${c.name}" weren't made: ${halted.why}, and opening another sequence would change what a running export renders. ` +
195
+ "Check fablecut_export (its job, or the export queue), then call again with those parts.");
196
+ break;
197
+ }
198
+ }
199
+ if (!made.length) throw new Error("no clip was made:\n" + lines.join("\n"));
200
+ if (made.length > 1 && !halted) { try { await env.patch([{ op: "openSequence", id: made[0].id }]); } catch { } }
201
+ return `Made ${made.length} clip${made.length === 1 ? "" : "s"} on ${canvas.width}×${canvas.height} (${o.aspect}), each its own sequence; the source timeline is left as it was:\n` +
202
+ lines.join("\n") + (halted ? `\n"${halted.clip}" stays open (${halted.why}). ` : `\nOpened "${made[0].name}". `) + "Check each with fablecut_frame {time} after openSequence; " +
203
+ (o.exportPreset ? "the files are in exports/." : "export one with openSequence then fablecut_export {preset, name}, or call again with export:\"tiktok\".");
204
+ }
205
+
206
+ return { ASPECTS, CAPTION_STYLES, MAX_CLIPS, MIN_LEN, MAX_LEN, canvasFor, options, titleClip, freeTopLane, exportUntilEnded, run };
207
+ });
package/doc-guard.js ADDED
@@ -0,0 +1,97 @@
1
+ /* What a project.json may carry where the editor expects a word or a number.
2
+
3
+ A project can come from anywhere: a shared file, a template, an agent. Text
4
+ people write (names, titles, notes, credits, tags) may hold any character and
5
+ is escaped wherever it is shown. Nothing else in a project is prose: an id, a
6
+ kind, a colour, an option name, a size never needs the characters markup is
7
+ made of, so they are taken out here, once, as a document is loaded. In an id
8
+ each of them becomes a character of its own instead, in every reference too:
9
+ two ids that differ still differ, and a reference still finds its item.
10
+ Well-formed projects come through unchanged.
11
+
12
+ clean(doc) works in place and returns doc: a project, a saved template or
13
+ preset, or a list of them. Loaded by the editor as a plain script (global
14
+ `FableCutGuard`) and required by the tests. */
15
+ (function (root, factory) {
16
+ if (typeof module === "object" && module.exports) module.exports = factory();
17
+ else root.FableCutGuard = factory();
18
+ })(typeof self !== "undefined" ? self : this, function () {
19
+ "use strict";
20
+
21
+ // text people write, or copy from somewhere: kept exactly, escaped where it is shown
22
+ const PROSE = new Set(["name", "text", "label", "title", "note", "notes", "description", "artist", "author", "creator", "copyright", "date", "keywords",
23
+ "filename", "caption", "license", "licenseUrl", "attribution", "credit", "source", "url", "link", "landing", "src", "tags", "placeholder", "default", "group",
24
+ "why", "reason", "words"]);
25
+ const MARKUP = /[<>"'`\u0000-\u0008\u000b-\u001f]/g;
26
+ const IN_FONT = /[<>"`\u0000-\u0008\u000b-\u001f]/g; // a family name may have an apostrophe
27
+ const IN_WORD = /[<>"'`&\\\u0000-\u001f]/g;
28
+ // a colour as CSS writes it, or a plain word ("red", or a delivery colour such as "bt709")
29
+ const COLOR = /^(#[0-9a-f]{3,8}|[a-z][a-z0-9-]{1,30}|(rgb|hsl)a?\([\d\s.,%/a-z+-]{3,60}\))$/i;
30
+ // names in the document: ids and the references to them alike (a template's target is "<clip id>:<path>")
31
+ const IDS = new Set(["id", "ids", "mediaId", "clipId", "compId", "folderId", "parentId", "linkGroup", "linkedId", "parent", "track", "out", "sequence", "media",
32
+ "derivedFrom", "matteTrack", "targets"]);
33
+ const WORDS = new Set(["kind", "type"]); // names in the editor's own lists
34
+ const SIZES = new Set(["width", "height", "fps"]);
35
+ const isColorKey = (k) => /colou?r\d?$/i.test(k) || k === "background" || k === "fill" || k === "stroke";
36
+ const DEPTH = 60;
37
+
38
+ const strip = (s, re) => s.replace(re, "");
39
+ /** One character for one (a braille pattern per code, or the same place in a later block), so an id keeps its length. */
40
+ const word = (s, block = 0x2800) => s.replace(IN_WORD, (c) => String.fromCharCode(block + c.charCodeAt(0)));
41
+
42
+ function clean(doc) {
43
+ const ids = new Map(), taken = new Set(); // id as written → as loaded · every id the document has
44
+ allIds(doc, taken, 0);
45
+ ids.taken = taken;
46
+ for (const id of [...taken]) rename(id, ids); // first, so that a reference is found under any key
47
+ walk(doc, "", 0, ids);
48
+ return doc;
49
+ }
50
+ function allIds(o, taken, depth) {
51
+ if (!o || typeof o !== "object" || depth > DEPTH) return;
52
+ if (!Array.isArray(o) && typeof o.id === "string") taken.add(o.id);
53
+ for (const k of Object.keys(o)) allIds(o[k], taken, depth + 1);
54
+ }
55
+ /** An id, or a reference to one: the same answer for both, and never another item's id. */
56
+ function rename(s, ids) {
57
+ if (ids.has(s)) return ids.get(s);
58
+ let to = word(s);
59
+ if (to === s) return s;
60
+ for (let block = 0x2900; ids.taken.has(to) && block < 0xd800; block += 0x100) to = word(s, block);
61
+ while (ids.taken.has(to)) to += "\u28ff"; // every block taken (a file made for it): longer, but its own
62
+ ids.taken.add(to);
63
+ ids.set(s, to);
64
+ return to;
65
+ }
66
+ function target(s, ids) { // "<clip id>:<path>"
67
+ const i = s.indexOf(":");
68
+ return i < 0 ? rename(s, ids) : rename(s.slice(0, i), ids) + word(s.slice(i));
69
+ }
70
+ function text(v, k, ids) {
71
+ if (PROSE.has(k)) return v;
72
+ if (/^font/i.test(k)) return strip(v, IN_FONT); // never a reference, even when an id reads the same
73
+ if (k === "targets") return target(v, ids);
74
+ if (IDS.has(k) || /Tracks$/.test(k) || ids.has(v)) return rename(v, ids);
75
+ return strip(v, WORDS.has(k) ? IN_WORD : MARKUP);
76
+ }
77
+ function walk(o, key, depth, ids) {
78
+ if (!o || typeof o !== "object") return;
79
+ if (depth > DEPTH) { for (const k of Object.keys(o)) delete o[k]; return; } // nothing real is nested that deep
80
+ if (Array.isArray(o)) {
81
+ for (let i = 0; i < o.length; i++) if (typeof o[i] === "string") { const t = text(o[i], key, ids); if (t !== o[i]) o[i] = t; } else walk(o[i], key, depth + 1, ids);
82
+ return;
83
+ }
84
+ if (o.type === "media" && ids.has(o.default)) o.default = ids.get(o.default); // a template field's file; other defaults are text
85
+ for (let k of Object.keys(o)) {
86
+ const v = o[k];
87
+ if (ids.has(k)) { delete o[k]; k = ids.get(k); o[k] = v; } // a table with a row per id
88
+ if (strip(k, MARKUP) !== k) { delete o[k]; continue; } // the editor prints property and channel names
89
+ if (typeof v !== "string") { walk(v, k, depth + 1, ids); continue; }
90
+ if (SIZES.has(k)) { const n = parseFloat(v); if (Number.isFinite(n)) o[k] = n; else delete o[k]; }
91
+ else if (isColorKey(k)) { if (v && !COLOR.test(v.trim())) delete o[k]; } // its default takes over
92
+ else { const t = text(v, k, ids); if (t !== v) o[k] = t; }
93
+ }
94
+ }
95
+
96
+ return { clean, word, COLOR, PROSE };
97
+ });
package/index.html CHANGED
@@ -709,6 +709,7 @@
709
709
 
710
710
  <div id="toast"></div>
711
711
 
712
+ <script src="doc-guard.js"></script>
712
713
  <script src="loudness.js"></script>
713
714
  <script src="ducking.js"></script>
714
715
  <script src="silence.js"></script>
@@ -719,6 +720,7 @@
719
720
  <script src="mask.js"></script>
720
721
  <script src="tracker.js"></script>
721
722
  <script src="reframe.js"></script>
723
+ <script src="clips.js"></script>
722
724
  <script src="highlights.js"></script>
723
725
  <script src="motion.js"></script>
724
726
  <script src="color.js"></script>
package/manifest.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "manifest_version": "0.2",
3
3
  "name": "fablecut",
4
4
  "display_name": "FableCut",
5
- "version": "1.21.0",
5
+ "version": "1.22.1",
6
6
  "description": "Zero-dependency browser video editor that AI agents can drive — JSON timeline, MCP tools, live-reloading UI.",
7
7
  "long_description": "FableCut is a Premiere-style non-linear video editor that runs in the browser with zero npm dependencies. An AI agent edits video by patching a single project.json timeline (clips, keyframes, transitions, text animations, filters, speed ramps, adjustment layers) through MCP tools, with color grading, masks and tracking, an audio mixer with effects, motion graphics (shape layers, compositions, animation presets and templates), and media management with offline relink and proxies; the open editor UI live-reloads within ~150 ms and exports through ffmpeg with delivery presets (YouTube, Reels, TikTok, Broadcast ProRes, lossless archive…), batch outputs from one render, loudness normalization and a check of every file. Includes reference-video analysis (shot cuts, beats, BPM, energy, drop) so agents can remake an edit with new footage.",
8
8
  "author": {
@@ -43,6 +43,7 @@
43
43
  { "name": "fablecut_beats", "description": "Find the music's beat (BPM, a steady beat grid, the drop), mark it, snap cuts to it, or re-cut a track's clips on it" },
44
44
  { "name": "fablecut_reframe", "description": "Reframe for another shape (9:16, 1:1, 4:5): a copy of the sequence on that canvas whose shots follow the subject" },
45
45
  { "name": "fablecut_highlights", "description": "The best moments of long footage (movement, sound, a clear picture) cut into a short edit in a new sequence" },
46
+ { "name": "fablecut_clips", "description": "A long video into short clips in one call: each part a new 9:16 sequence, framed on the subject, with a hook title, captions and an optional export" },
46
47
  { "name": "fablecut_transcribe", "description": "Transcribe speech word by word in the browser, read it on the timeline, find a phrase and cut it out (text-based editing)" },
47
48
  { "name": "fablecut_captions", "description": "Make captions from the transcript (subtitle, karaoke, word highlight, word pop), timed word by word; export or import SRT / WebVTT" },
48
49
  { "name": "fablecut_proxy", "description": "Make, check or delete proxies: light copies of heavy footage the editor plays while editing (export always uses the originals)" },
package/mcp-server.js CHANGED
@@ -355,6 +355,26 @@ const TOOLS = [
355
355
  },
356
356
  },
357
357
  },
358
+ {
359
+ name: "fablecut_clips",
360
+ description: "A long video into short clips, in one call: the clipper's job (a podcast, an interview, a talk, a stream into Shorts / Reels / TikToks). First read what is said with fablecut_transcribe and pick the parts that stand on their own (a tip, an answer, a story, a strong opinion; usually 20–60 s each, starting and ending on a full sentence), then pass them here as timeline seconds. For each one it makes a new sequence on the clip's canvas (default 9:16) holding only that part of the open timeline — the source is left as it was — frames each shot on the subject (as fablecut_reframe), adds a hook title in the top third for the first 3 s (when you give `title`), makes captions timed to the words (as fablecut_captions, default style pop), and with export:\"tiktok\" (or any delivery preset) renders each one to exports/, named after the clip. The reply lists each clip and what was done; the first clip is opened. A version is saved first.",
361
+ inputSchema: {
362
+ type: "object",
363
+ required: ["clips"],
364
+ properties: {
365
+ clips: { type: "array", minItems: 1, maxItems: 10, description: "The clips to make, up to 10", items: { type: "object", required: ["from", "to"], properties: {
366
+ from: { type: "number", description: "Start, timeline seconds (start on a sentence)" },
367
+ to: { type: "number", description: "End, timeline seconds (3…180 s after from; end after a sentence)" },
368
+ name: { type: "string", description: "The clip's sequence (and file) name, e.g. \"Tip 1 - comfort zone\"" },
369
+ title: { type: "string", description: "The hook title shown for its first 3 s, a few punchy words (left out: no title)" } } } },
370
+ aspect: { type: "string", enum: ["9:16", "1:1", "4:5", "16:9"], description: "The clips' shape (default 9:16)" },
371
+ captions: { anyOf: [{ type: "string", enum: ["pop", "highlight", "karaoke", "subtitle"] }, { type: "boolean", enum: [false] }], description: "Caption style (default pop), or false for none" },
372
+ reframe: { type: "boolean", description: "Follow the subject on the new canvas (default true)" },
373
+ title: { type: "boolean", description: "false leaves the hook titles out even where clips give one" },
374
+ export: { type: "string", description: "Render each clip with this delivery preset (tiktok, youtube-shorts, instagram-reels, …; see fablecut_encode_profiles). Left out: no export" },
375
+ },
376
+ },
377
+ },
358
378
  {
359
379
  name: "fablecut_transcribe",
360
380
  description: "What is said, word by word, with times — and text-based editing. Transcribes the clips' speech with Whisper in the editor (an open tab, else headless Chrome / Edge; the speech model downloads once, the audio never leaves the machine), keeps one transcript per file (analysis/transcripts/), and answers with the timeline's words as timed lines (timeline seconds), so you can read an interview, pick the good takes, or find where something is said. find:\"phrase\" (or a list) reports every place it is said — case, punctuation and spacing ignored, whole words only — with the exact span; cut:true then extracts each of them on the targeted tracks (or `tracks`), the words and the pause after them, last first, in one revision: later material moves up, linked stems stay in sync, locked clips stay put (lock the music bed first). A version is saved before a cut. Files already transcribed aren't done again unless again:true. Default clips: every video / audio clip with sound on the open timeline. mediaIds reads whole files instead (file seconds; no cut). The same as the editor's Transcript tab.",
@@ -964,6 +984,29 @@ async function highlightsTool(args) {
964
984
  "\nCheck a moment with fablecut_frame {time}; with music under it, fablecut_beats {clipId, retime:{every:2}} cuts it on the beat." +
965
985
  (verWarn || "\nThe project as it was is kept as a version (fablecut_versions; restore undoes it).");
966
986
  }
987
+ /* fablecut_clips: clips.js runs the steps, each through the tool that does it here. */
988
+ async function clipsTool(args) {
989
+ const Clips = require("./clips.js");
990
+ Clips.options(args, readProject()); // refuse bad arguments before anything changes
991
+ let verWarn = "";
992
+ try { createHistory({ projects: createProjects({ dataDir: DATA_DIR, projectFile: PROJECT_FILE, libraryDir: LIBRARY_DIR }) }).beforeAgent("Before making clips"); }
993
+ catch (e) { verWarn = ` Warning: no version was saved first (${e.message}).`; }
994
+ const text = (r) => (typeof r === "string" ? r : (r?.content || []).map((c) => c.text || "").join("\n"));
995
+ const reply = await Clips.run(args, {
996
+ read: () => readProject(),
997
+ patch: async (ops) => text(await callTool("fablecut_patch_project", { ops }, 0)),
998
+ reframe: (a) => reframeTool(a),
999
+ captions: (a) => captionsTool(a),
1000
+ // answers once its export has ended, before the next clip opens another sequence (clips.js)
1001
+ exportClip: (a) => Clips.exportUntilEnded({
1002
+ start: async (x) => text(await exportTool({ ...x, wait: false })),
1003
+ status: async (id, secs) => text(await exportTool(secs ? { job: id, wait: true, timeout: secs } : { job: id })),
1004
+ cancel: (id) => exportTool({ cancel: id }),
1005
+ sleep,
1006
+ }, a),
1007
+ });
1008
+ return reply + (verWarn || "\nThe project as it was is kept as a version (fablecut_versions; restore undoes it).");
1009
+ }
967
1010
  /** What words are placed by and cuts land on: where each clip sits and plays from, the track
968
1011
  * switches and the frame rate. An editor saving probed media details while a transcription runs
969
1012
  * doesn't change it; a moved, trimmed or cut clip does. */
@@ -1830,6 +1873,8 @@ async function callTool(name, args, attempt = 0) {
1830
1873
  return reframeTool(args);
1831
1874
  case "fablecut_highlights":
1832
1875
  return highlightsTool(args);
1876
+ case "fablecut_clips":
1877
+ return clipsTool(args);
1833
1878
  case "fablecut_transcribe":
1834
1879
  return transcribeTool(args);
1835
1880
  case "fablecut_captions":
@@ -2245,7 +2290,7 @@ async function handle(msg) {
2245
2290
  result: {
2246
2291
  protocolVersion: negotiateProtocolVersion(params?.protocolVersion),
2247
2292
  capabilities: { tools: {} },
2248
- serverInfo: { name: "fablecut", version: "1.21.0" },
2293
+ serverInfo: { name: "fablecut", version: "1.22.1" },
2249
2294
  },
2250
2295
  });
2251
2296
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fablecut",
3
- "version": "1.21.0",
3
+ "version": "1.22.1",
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": {
package/project-ops.js CHANGED
@@ -53,7 +53,7 @@
53
53
  text: "Title", fontSize: 72, color: "#ffffff", color2: "", font: "Segoe UI",
54
54
  bold: true, weight: 0, italic: false, uppercase: false, align: "center",
55
55
  letterSpacing: 0, lineHeight: 1.2, textShadow: 12, glow: 0, glowColor: "",
56
- strokeWidth: 0, strokeColor: "#000", bgColor: "#000", bgOpacity: 0,
56
+ strokeWidth: 0, strokeColor: "#000", bgColor: "#000", bgOpacity: 0, bgShape: "lines",
57
57
  textAnim: "none", wordRate: 0.15, highlightColor: "#ffd166", direction: "auto", boxW: 0, boxH: 0, boxFit: false, vAlign: "middle",
58
58
  anchorX: 0, anchorY: 0, trimStart: 0, trimEnd: 100, trimOffset: 0,
59
59
  autoOrient: false, motionBlur: 0, motionBlurSamples: 8, pathOffset: 0, pathAlign: "start",
@@ -279,6 +279,7 @@
279
279
  if (p.motionBlurSamples != null && !(Number.isInteger(p.motionBlurSamples) && p.motionBlurSamples >= 2 && p.motionBlurSamples <= 32)) throw new Error(`${label}: props.motionBlurSamples is a whole number 2…32`);
280
280
  if (p.autoOrient != null && typeof p.autoOrient !== "boolean") throw new Error(`${label}: props.autoOrient is true or false`);
281
281
  if (p.pathAlign != null && !["start", "center", "end"].includes(p.pathAlign)) throw new Error(`${label}: props.pathAlign is start | center | end`);
282
+ if (p.bgShape != null && !["lines", "box"].includes(p.bgShape)) throw new Error(`${label}: props.bgShape is lines | box`);
282
283
  if (p.textPath != null) {
283
284
  if (c.kind !== "text") throw new Error(`${label}: textPath goes on text clips`);
284
285
  try { p.textPath = Motion.normalizeTextPath(p.textPath, true); } catch (err) { throw new Error(`${label}: props.${err.message}`); }