rushes 0.2.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-plugin/marketplace.json +14 -0
- package/.claude-plugin/plugin.json +10 -0
- package/.mcp.json +8 -0
- package/AGENTS.md +110 -0
- package/LICENSE +21 -0
- package/README.md +204 -0
- package/dist/cli/demo.js +339 -0
- package/dist/cli/doctor.js +307 -0
- package/dist/cli/index.js +11 -0
- package/dist/cli/main.js +469 -0
- package/dist/core/batches.js +58 -0
- package/dist/core/errors.js +37 -0
- package/dist/core/exportNotes.js +132 -0
- package/dist/core/ids.js +42 -0
- package/dist/core/media.js +128 -0
- package/dist/core/notes.js +117 -0
- package/dist/core/paths.js +17 -0
- package/dist/core/project.js +200 -0
- package/dist/core/schema.js +220 -0
- package/dist/core/script.js +113 -0
- package/dist/core/store.js +132 -0
- package/dist/core/tabs.js +24 -0
- package/dist/mcp/client.js +50 -0
- package/dist/mcp/ensure.js +69 -0
- package/dist/mcp/stdio.js +47 -0
- package/dist/mcp/tools.js +191 -0
- package/dist/server/app.js +710 -0
- package/dist/server/assets.js +234 -0
- package/dist/server/files.js +170 -0
- package/dist/server/lock.js +148 -0
- package/dist/server/loudness.js +331 -0
- package/dist/server/proxy.js +575 -0
- package/dist/server/reveal.js +71 -0
- package/dist/server/start.js +125 -0
- package/dist/server/watch.js +133 -0
- package/dist/setup/env.js +42 -0
- package/dist/setup/harnesses.js +93 -0
- package/dist/setup/setup.js +92 -0
- package/package.json +54 -0
- package/skills/rushes/SKILL.md +30 -0
- package/web-dist/assets/figtree-latin-400-normal-BD4aNku5.woff +0 -0
- package/web-dist/assets/figtree-latin-400-normal-g7Dtegnw.woff2 +0 -0
- package/web-dist/assets/figtree-latin-500-normal-BWnGEVsr.woff2 +0 -0
- package/web-dist/assets/figtree-latin-500-normal-B_yy1phn.woff +0 -0
- package/web-dist/assets/figtree-latin-600-normal-BM_oTo4n.woff +0 -0
- package/web-dist/assets/figtree-latin-600-normal-Cv_xCTDl.woff2 +0 -0
- package/web-dist/assets/figtree-latin-700-normal-BCCt2T1q.woff +0 -0
- package/web-dist/assets/figtree-latin-700-normal-th6qEP7c.woff2 +0 -0
- package/web-dist/assets/figtree-latin-ext-400-normal-CXAzuTZb.woff2 +0 -0
- package/web-dist/assets/figtree-latin-ext-400-normal-Gbh-3PTk.woff +0 -0
- package/web-dist/assets/figtree-latin-ext-500-normal-BOEJvrb_.woff +0 -0
- package/web-dist/assets/figtree-latin-ext-500-normal-Du0rIuHj.woff2 +0 -0
- package/web-dist/assets/figtree-latin-ext-600-normal-CQqsimlV.woff +0 -0
- package/web-dist/assets/figtree-latin-ext-600-normal-DJlfifZj.woff2 +0 -0
- package/web-dist/assets/figtree-latin-ext-700-normal-BoDi4KL2.woff +0 -0
- package/web-dist/assets/figtree-latin-ext-700-normal-CS4sQkGV.woff2 +0 -0
- package/web-dist/assets/index-BjDIT_wL.css +1 -0
- package/web-dist/assets/index-DF6Rl-Ac.js +3 -0
- package/web-dist/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-cyrillic-400-normal-ugxPyKxw.woff +0 -0
- package/web-dist/assets/jetbrains-mono-cyrillic-500-normal-DJqRU3vO.woff +0 -0
- package/web-dist/assets/jetbrains-mono-cyrillic-500-normal-DmUKJPL_.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-greek-400-normal-B9oWc5Lo.woff +0 -0
- package/web-dist/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-greek-500-normal-D7SFKleX.woff +0 -0
- package/web-dist/assets/jetbrains-mono-greek-500-normal-JpySY46c.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
- package/web-dist/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-latin-500-normal-CJOVTJB7.woff +0 -0
- package/web-dist/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-latin-ext-400-normal-fXTG6kC5.woff +0 -0
- package/web-dist/assets/jetbrains-mono-latin-ext-500-normal-Cut-4mMH.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-latin-ext-500-normal-ckzbgY84.woff +0 -0
- package/web-dist/assets/jetbrains-mono-vietnamese-400-normal-CqNFfHCs.woff +0 -0
- package/web-dist/assets/jetbrains-mono-vietnamese-500-normal-DNRqzVM1.woff +0 -0
- package/web-dist/index.html +14 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { slugify } from "./ids.js";
|
|
2
|
+
import { onLabel } from "./notes.js";
|
|
3
|
+
import { markLabel } from "./schema.js";
|
|
4
|
+
// Picture notes are grouped by film and version; the other stages list straight through.
|
|
5
|
+
// Script isn't included here -- script edits live in script.json, not notes.json.
|
|
6
|
+
const STAGE_ORDER = ["picture", "voice", "music", "sfx", "mix"];
|
|
7
|
+
const STAGE_TITLES = {
|
|
8
|
+
picture: "Picture",
|
|
9
|
+
voice: "Voiceover",
|
|
10
|
+
music: "Music",
|
|
11
|
+
sfx: "Sound effects",
|
|
12
|
+
mix: "Mix",
|
|
13
|
+
};
|
|
14
|
+
function pad(n) {
|
|
15
|
+
return String(n).padStart(2, "0");
|
|
16
|
+
}
|
|
17
|
+
/** The server's local date, as YYYY-MM-DD. */
|
|
18
|
+
function localDate(d) {
|
|
19
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
|
20
|
+
}
|
|
21
|
+
function localDateTime(d) {
|
|
22
|
+
return `${localDate(d)} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
|
23
|
+
}
|
|
24
|
+
// A small local copy of web/src/lib.ts's fmt()/noteTime(): minutes:seconds.hundredths, rounded to
|
|
25
|
+
// hundredths before splitting so 59.999s carries into the next minute rather than printing 60.00s.
|
|
26
|
+
// Duplicated rather than imported -- src/ and web/ are separate TypeScript projects.
|
|
27
|
+
function fmt(t) {
|
|
28
|
+
const cs = Math.round(Math.max(0, t) * 100);
|
|
29
|
+
const m = Math.floor(cs / 6000);
|
|
30
|
+
const s = ((cs - m * 6000) / 100).toFixed(2).padStart(5, "0");
|
|
31
|
+
return `${m}:${s}`;
|
|
32
|
+
}
|
|
33
|
+
function noteTime(t, tOut) {
|
|
34
|
+
if (t === null)
|
|
35
|
+
return "Whole";
|
|
36
|
+
return tOut !== null ? `${fmt(t)}–${fmt(tOut)}` : fmt(t);
|
|
37
|
+
}
|
|
38
|
+
/** `text`, with every line after the first indented to `indent` (M2): a multi-line note or
|
|
39
|
+
* reply would otherwise put an unindented line straight after a list item, which most Markdown
|
|
40
|
+
* renderers (this project's own built-in one included) read as ending the list rather than
|
|
41
|
+
* continuing it. */
|
|
42
|
+
function continued(text, indent) {
|
|
43
|
+
return text.split("\n").join(`\n${indent}`);
|
|
44
|
+
}
|
|
45
|
+
function noteLines(n, ctx) {
|
|
46
|
+
// What an audio note is on (M4): "Music · Warm keys", "S2 · Take 1", "Whole mix" ...
|
|
47
|
+
const label = onLabel(n, ctx);
|
|
48
|
+
const on = label ? ` · ${label}` : "";
|
|
49
|
+
const marks = n.marks.length ? ` · ${n.marks.map(markLabel).join(" · ")}` : "";
|
|
50
|
+
const shot = n.shot ? ` · shot ${pad(n.shot.n)}` : "";
|
|
51
|
+
const status = n.status === "done" ? "done" : "to do";
|
|
52
|
+
const lines = [`- **${noteTime(n.t, n.tOut)}**${on}${marks}${shot} · ${status} — ${continued(n.text, " ")}`];
|
|
53
|
+
if (n.reply)
|
|
54
|
+
lines.push(` - Reply: ${continued(n.reply, " ")}`);
|
|
55
|
+
if (n.grab)
|
|
56
|
+
lines.push(` - Screenshot: ${n.grab}`);
|
|
57
|
+
return lines;
|
|
58
|
+
}
|
|
59
|
+
// By timecode within a film and version, a whole-track note (t === null) last -- notes were
|
|
60
|
+
// otherwise listed in whatever order they happened to be created in, which usually isn't where
|
|
61
|
+
// they land on the timeline.
|
|
62
|
+
function byTimecode(a, b) {
|
|
63
|
+
return a.t === null ? 1 : b.t === null ? -1 : a.t - b.t;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The project's notes as Markdown: a title and export date, then one `##` section per stage
|
|
67
|
+
* that has notes, in workflow order (script is never included -- it lives in script.json).
|
|
68
|
+
* Picture notes are further grouped under a `### <Film> · <version>` heading per film and
|
|
69
|
+
* version that has notes, in the project's own video/version order. A note whose video or
|
|
70
|
+
* version no longer exists in the project (hand-edited away, say) is never dropped (M3): it's
|
|
71
|
+
* still exported, grouped under `### <Film> · <version> (removed)`, in the order those groups
|
|
72
|
+
* were first seen among the orphaned notes. An audio note says what it's on ("Music · Warm keys",
|
|
73
|
+
* "S2 · Take 1"), resolved against `script` and `picks` as the dashboard resolves it. Nothing is
|
|
74
|
+
* escaped (this is a file, not HTML), and the same input always produces the same string.
|
|
75
|
+
*/
|
|
76
|
+
export function notesMarkdown(project, notes, now, script = { sections: [] }, picks) {
|
|
77
|
+
const ctx = { project, script, picks };
|
|
78
|
+
const lines = [`# ${project.name} — notes`, `Exported ${localDateTime(now)}`];
|
|
79
|
+
for (const stage of STAGE_ORDER) {
|
|
80
|
+
const stageNotes = notes.filter((n) => n.stage === stage);
|
|
81
|
+
if (stageNotes.length === 0)
|
|
82
|
+
continue;
|
|
83
|
+
lines.push("", `## ${STAGE_TITLES[stage]}`);
|
|
84
|
+
if (stage === "picture") {
|
|
85
|
+
const matched = new Set();
|
|
86
|
+
for (const video of project.videos) {
|
|
87
|
+
for (const version of video.versions) {
|
|
88
|
+
const group = stageNotes
|
|
89
|
+
.filter((n) => n.video === video.id && n.version === version.id)
|
|
90
|
+
.sort(byTimecode);
|
|
91
|
+
if (group.length === 0)
|
|
92
|
+
continue;
|
|
93
|
+
lines.push("", `### ${video.name} · ${version.id}`);
|
|
94
|
+
for (const n of group) {
|
|
95
|
+
lines.push(...noteLines(n, ctx));
|
|
96
|
+
matched.add(n);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Orphaned: video and/or version no longer resolve against the project (M3). Grouped by
|
|
101
|
+
// the pair rather than just listed, so a reader can still tell which notes belonged
|
|
102
|
+
// together, in the order those pairs first turn up among the orphans.
|
|
103
|
+
const orphanGroups = new Map();
|
|
104
|
+
for (const n of stageNotes) {
|
|
105
|
+
if (matched.has(n))
|
|
106
|
+
continue;
|
|
107
|
+
const videoLabel = project.videos.find((v) => v.id === n.video)?.name ?? n.video ?? "Unknown film";
|
|
108
|
+
const label = `${videoLabel} · ${n.version ?? "no version"}`;
|
|
109
|
+
let g = orphanGroups.get(label);
|
|
110
|
+
if (!g) {
|
|
111
|
+
g = { label, notes: [] };
|
|
112
|
+
orphanGroups.set(label, g);
|
|
113
|
+
}
|
|
114
|
+
g.notes.push(n);
|
|
115
|
+
}
|
|
116
|
+
for (const g of orphanGroups.values()) {
|
|
117
|
+
lines.push("", `### ${g.label} (removed)`);
|
|
118
|
+
for (const n of [...g.notes].sort(byTimecode))
|
|
119
|
+
lines.push(...noteLines(n, ctx));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
for (const n of stageNotes)
|
|
124
|
+
lines.push(...noteLines(n, ctx));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return lines.join("\n") + "\n";
|
|
128
|
+
}
|
|
129
|
+
/** "<project-slug>-notes-<YYYY-MM-DD>.md", dated by the server's local clock. */
|
|
130
|
+
export function exportFileName(projectName, now) {
|
|
131
|
+
return `${slugify(projectName)}-notes-${localDate(now)}.md`;
|
|
132
|
+
}
|
package/dist/core/ids.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createHash, randomBytes, randomInt } from "node:crypto";
|
|
2
|
+
/** Short random id such as "n_k3f9x2". */
|
|
3
|
+
export function newId(prefix) {
|
|
4
|
+
return `${prefix}_${randomBytes(4).toString("hex").slice(0, 6)}`;
|
|
5
|
+
}
|
|
6
|
+
/** Lower-case letters and digits, without the look-alikes 0, o, 1, l and i. */
|
|
7
|
+
export const PROJECT_ID_ALPHABET = "abcdefghjkmnpqrstuvwxyz23456789";
|
|
8
|
+
/** 8 characters from PROJECT_ID_ALPHABET, crypto-random and free of modulo bias. */
|
|
9
|
+
export function newProjectId() {
|
|
10
|
+
let out = "";
|
|
11
|
+
for (let i = 0; i < 8; i++)
|
|
12
|
+
out += PROJECT_ID_ALPHABET[randomInt(PROJECT_ID_ALPHABET.length)];
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* "Hero 60s!" -> "hero-60s". When no ASCII letters or digits survive — a name in a non-Latin
|
|
17
|
+
* script ("日本"), or pure punctuation — two different such names would otherwise both fall
|
|
18
|
+
* back to the bare "item" and collide (addVersion would then merge the second film's cuts into
|
|
19
|
+
* the first). Falling back to "item-<hash>" instead keeps them apart, while a name slugified
|
|
20
|
+
* twice still gets the same id.
|
|
21
|
+
*/
|
|
22
|
+
export function slugify(text) {
|
|
23
|
+
const s = text
|
|
24
|
+
.normalize("NFKD")
|
|
25
|
+
.replace(/[̀-ͯ]/g, "")
|
|
26
|
+
.toLowerCase()
|
|
27
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
28
|
+
.replace(/^-+|-+$/g, "");
|
|
29
|
+
if (s)
|
|
30
|
+
return s;
|
|
31
|
+
const hash = createHash("sha1").update(text.normalize("NFC")).digest("hex").slice(0, 6);
|
|
32
|
+
return `item-${hash}`;
|
|
33
|
+
}
|
|
34
|
+
/** First id from base, base-2, base-3 ... not in `taken`. */
|
|
35
|
+
export function uniqueId(base, taken) {
|
|
36
|
+
const set = new Set(taken);
|
|
37
|
+
if (!set.has(base))
|
|
38
|
+
return base;
|
|
39
|
+
for (let i = 2;; i++)
|
|
40
|
+
if (!set.has(`${base}-${i}`))
|
|
41
|
+
return `${base}-${i}`;
|
|
42
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
const run = promisify(execFile);
|
|
4
|
+
const NO_PROBE = { duration: null, fps: null, codec: null, width: null, height: null, pixFmt: null };
|
|
5
|
+
let ffprobeChecked = null;
|
|
6
|
+
/** True when ffprobe is on PATH. Checked once per process. */
|
|
7
|
+
export function hasFfprobe() {
|
|
8
|
+
ffprobeChecked ??= run("ffprobe", ["-version"]).then(() => true, () => false);
|
|
9
|
+
return ffprobeChecked;
|
|
10
|
+
}
|
|
11
|
+
/** "30000/1001" -> 29.97. Returns null for "0/0" or junk. */
|
|
12
|
+
export function parseRate(rate) {
|
|
13
|
+
if (!rate)
|
|
14
|
+
return null;
|
|
15
|
+
const [a, b] = rate.split("/").map(Number);
|
|
16
|
+
const v = b ? a / b : a;
|
|
17
|
+
return Number.isFinite(v) && v > 0 ? Math.round(v * 1000) / 1000 : null;
|
|
18
|
+
}
|
|
19
|
+
/** How long one ffprobe may run before it's killed and treated as no probe (a stalled network volume, say). */
|
|
20
|
+
export const PROBE_TIMEOUT_MS = 20_000;
|
|
21
|
+
/**
|
|
22
|
+
* Read duration, frame rate, codec, size and pixel format with ffprobe. Returns nulls when ffprobe
|
|
23
|
+
* is missing or fails, takes longer than `timeout` (default 20 s), or `signal` aborts.
|
|
24
|
+
*/
|
|
25
|
+
export async function probe(file, opts = {}) {
|
|
26
|
+
if (opts.signal?.aborted || !(await hasFfprobe()))
|
|
27
|
+
return { ...NO_PROBE };
|
|
28
|
+
const timeout = opts.timeout ?? PROBE_TIMEOUT_MS;
|
|
29
|
+
// execFile kills ffprobe at `timeout` or on abort, but only answers once it has exited. A
|
|
30
|
+
// process stuck in an uninterruptible read can outlive SIGKILL, so give up on waiting too.
|
|
31
|
+
let timer;
|
|
32
|
+
let onAbort;
|
|
33
|
+
const giveUp = new Promise((res) => {
|
|
34
|
+
timer = setTimeout(() => res({ ...NO_PROBE }), timeout + 1_000);
|
|
35
|
+
onAbort = () => res({ ...NO_PROBE });
|
|
36
|
+
opts.signal?.addEventListener("abort", onAbort, { once: true });
|
|
37
|
+
});
|
|
38
|
+
try {
|
|
39
|
+
return await Promise.race([readProbe(file, timeout, opts.signal), giveUp]);
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
if (onAbort)
|
|
44
|
+
opts.signal?.removeEventListener("abort", onAbort);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async function readProbe(file, timeout, signal) {
|
|
48
|
+
try {
|
|
49
|
+
const { stdout } = await run("ffprobe", [
|
|
50
|
+
"-v", "error",
|
|
51
|
+
"-show_entries", "format=duration:stream=codec_type,codec_name,width,height,pix_fmt,avg_frame_rate,r_frame_rate",
|
|
52
|
+
"-of", "json",
|
|
53
|
+
file,
|
|
54
|
+
], { timeout, killSignal: "SIGKILL", signal });
|
|
55
|
+
const j = JSON.parse(stdout);
|
|
56
|
+
const video = j.streams?.find((s) => s.codec_type === "video");
|
|
57
|
+
const duration = j.format?.duration ? Number(j.format.duration) : null;
|
|
58
|
+
return {
|
|
59
|
+
duration: duration !== null && Number.isFinite(duration) ? duration : null,
|
|
60
|
+
fps: parseRate(video?.avg_frame_rate) ?? parseRate(video?.r_frame_rate),
|
|
61
|
+
codec: video?.codec_name ?? null,
|
|
62
|
+
width: positiveInt(video?.width),
|
|
63
|
+
height: positiveInt(video?.height),
|
|
64
|
+
pixFmt: video?.pix_fmt ?? null,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return { ...NO_PROBE };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function positiveInt(n) {
|
|
72
|
+
return typeof n === "number" && Number.isInteger(n) && n > 0 ? n : null;
|
|
73
|
+
}
|
|
74
|
+
// §19.5: when Rushes offers a proxy.
|
|
75
|
+
const PLAYABLE_CODECS = new Set(["h264", "vp9", "av1"]);
|
|
76
|
+
const MAX_EDGE = 3000;
|
|
77
|
+
const MAX_BYTES = 1.5e9;
|
|
78
|
+
/** ffprobe codec names in plain words. */
|
|
79
|
+
const CODEC_NAMES = {
|
|
80
|
+
prores: "ProRes",
|
|
81
|
+
dnxhd: "DNx",
|
|
82
|
+
hevc: "HEVC",
|
|
83
|
+
mpeg2video: "MPEG-2",
|
|
84
|
+
mpeg4: "MPEG-4",
|
|
85
|
+
mjpeg: "Motion JPEG",
|
|
86
|
+
vp8: "VP8",
|
|
87
|
+
cfhd: "CineForm",
|
|
88
|
+
qtrle: "QuickTime Animation",
|
|
89
|
+
png: "PNG",
|
|
90
|
+
rawvideo: "uncompressed",
|
|
91
|
+
};
|
|
92
|
+
function codecWords(codec, pixFmt) {
|
|
93
|
+
const name = CODEC_NAMES[codec] ?? codec.toUpperCase();
|
|
94
|
+
// "HEVC 10-bit": the case §19.5 names, and the one browsers fail on most.
|
|
95
|
+
if (codec === "hevc" && pixFmt && /p10/.test(pixFmt))
|
|
96
|
+
return `${name} 10-bit`;
|
|
97
|
+
return name;
|
|
98
|
+
}
|
|
99
|
+
/** "a" or "an" before `words`, by sound: "an HEVC", "an MPEG-2", "an uncompressed", "a ProRes". */
|
|
100
|
+
function article(words) {
|
|
101
|
+
const first = words.split(/[\s-]/)[0];
|
|
102
|
+
if (/^[aeiou]/.test(first))
|
|
103
|
+
return "an";
|
|
104
|
+
// An acronym read letter by letter: "an HEVC", "an MPEG-2", "an F…".
|
|
105
|
+
if (/^[A-Z0-9]+$/.test(first) && /^[AEFHILMNORSX]/.test(first))
|
|
106
|
+
return "an";
|
|
107
|
+
return "a";
|
|
108
|
+
}
|
|
109
|
+
/** "2.3 GB", in decimal gigabytes (the same unit the 1.5 GB threshold uses). */
|
|
110
|
+
function gigabytes(bytes) {
|
|
111
|
+
return `${(bytes / 1e9).toFixed(1)} GB`;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Why a cut is likely to play badly in a browser (§19.5), in a few plain words -- or null when it
|
|
115
|
+
* should play fine, or when nothing is known about it (no ffprobe). The reasons combine:
|
|
116
|
+
* "It's a 4K ProRes file (2.3 GB), which browsers struggle with".
|
|
117
|
+
*/
|
|
118
|
+
export function proxyNeed(p, bytes) {
|
|
119
|
+
const big = (p.width ?? 0) > MAX_EDGE || (p.height ?? 0) > MAX_EDGE;
|
|
120
|
+
const heavy = bytes !== null && bytes > MAX_BYTES;
|
|
121
|
+
const codec = p.codec !== null && !PLAYABLE_CODECS.has(p.codec) ? codecWords(p.codec, p.pixFmt) : null;
|
|
122
|
+
if (!big && !heavy && !codec)
|
|
123
|
+
return null;
|
|
124
|
+
const words = [big ? "4K" : null, codec].filter(Boolean).join(" ");
|
|
125
|
+
const what = words ? `${article(words)} ${words} file` : "a large file";
|
|
126
|
+
const size = heavy ? ` (${gigabytes(bytes)})` : "";
|
|
127
|
+
return { reason: `It's ${what}${size}, which browsers struggle with` };
|
|
128
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { NoteSchema, } from "./schema.js";
|
|
2
|
+
import { InvalidError, NotFoundError } from "./errors.js";
|
|
3
|
+
import { newId } from "./ids.js";
|
|
4
|
+
export function addNote(file, input, now = new Date()) {
|
|
5
|
+
const parsed = NoteSchema.safeParse({ ...input, id: newId("n"), createdAt: now.toISOString() });
|
|
6
|
+
if (!parsed.success)
|
|
7
|
+
throw new InvalidError("Note is invalid", parsed.error.issues);
|
|
8
|
+
file.notes.push(parsed.data);
|
|
9
|
+
return parsed.data;
|
|
10
|
+
}
|
|
11
|
+
function find(file, id) {
|
|
12
|
+
const n = file.notes.find((x) => x.id === id);
|
|
13
|
+
if (!n)
|
|
14
|
+
throw new NotFoundError("note", id);
|
|
15
|
+
return n;
|
|
16
|
+
}
|
|
17
|
+
/** A done note going back to todo leaves its batch, so the next Send includes it. */
|
|
18
|
+
function reopen(n, status) {
|
|
19
|
+
if (n.status === "done" && status === "todo")
|
|
20
|
+
n.batch = null;
|
|
21
|
+
}
|
|
22
|
+
export function applyReply(file, r) {
|
|
23
|
+
const n = find(file, r.id);
|
|
24
|
+
if (r.reply !== undefined)
|
|
25
|
+
n.reply = r.reply;
|
|
26
|
+
reopen(n, r.status);
|
|
27
|
+
if (r.status !== undefined)
|
|
28
|
+
n.status = r.status;
|
|
29
|
+
if (r.fixT !== undefined)
|
|
30
|
+
n.fixT = r.fixT;
|
|
31
|
+
if (r.fixVersion !== undefined)
|
|
32
|
+
n.fixVersion = r.fixVersion;
|
|
33
|
+
return n;
|
|
34
|
+
}
|
|
35
|
+
export function applyUserEdit(file, e) {
|
|
36
|
+
const n = find(file, e.id);
|
|
37
|
+
const next = { ...n };
|
|
38
|
+
for (const k of ["text", "box", "grab", "scope", "t", "tOut", "marks", "status"]) {
|
|
39
|
+
if (e[k] !== undefined)
|
|
40
|
+
next[k] = e[k];
|
|
41
|
+
}
|
|
42
|
+
const parsed = NoteSchema.safeParse(next);
|
|
43
|
+
if (!parsed.success)
|
|
44
|
+
throw new InvalidError("Note edit is invalid", parsed.error.issues);
|
|
45
|
+
reopen(n, e.status);
|
|
46
|
+
Object.assign(n, { ...parsed.data, batch: n.batch });
|
|
47
|
+
return n;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* What an audio note is `on`, in words, for export and the CLI (§17): the lane and variant
|
|
51
|
+
* ("Music · Warm keys"), a cue ("Sound effects · Pass A · Cue · Swipe"), a take ("S2 · Take 1"), a
|
|
52
|
+
* section ("S2"), the read ("Assembled read") or, on Mix, "Whole mix" / "Voiceover". Resolved in
|
|
53
|
+
* the same order as the dashboard: the exact lane-qualified variant (`"<lane>/<variant>"`) or cue
|
|
54
|
+
* (`"<lane>/<variant>:<cue>"`) first, then `"vo"`, a take (`"<section>:<take>"`), a section id, and
|
|
55
|
+
* last the older bare forms (a bare variant id, `"<variant>:<cue>"` or a bare cue id). Null on
|
|
56
|
+
* Picture and Script, or when `on` names nothing that's still there.
|
|
57
|
+
*/
|
|
58
|
+
export function onLabel(note, ctx) {
|
|
59
|
+
const { stage, on } = note;
|
|
60
|
+
if (stage !== "voice" && stage !== "music" && stage !== "sfx" && stage !== "mix")
|
|
61
|
+
return null;
|
|
62
|
+
if (on === null)
|
|
63
|
+
return stage === "mix" ? "Whole mix" : stage === "voice" ? "Assembled read" : null;
|
|
64
|
+
// Mix's own Music and Sound effects lanes; every other tab looks at its own stage only.
|
|
65
|
+
const stages = stage === "mix" ? ["music", "sfx"] : [stage];
|
|
66
|
+
const lanes = ctx.project.lanes.filter((l) => stages.includes(l.stage));
|
|
67
|
+
const variantLabel = (l, v) => `${l.name} · ${v.name}`;
|
|
68
|
+
const cueLabel = (l, v, cueId) => {
|
|
69
|
+
const cue = v.cues.find((c) => c.id === cueId);
|
|
70
|
+
return cue ? `${variantLabel(l, v)} · Cue · ${cue.name}` : null;
|
|
71
|
+
};
|
|
72
|
+
// 1. Lane-qualified variant or cue. Lane and variant ids are slugs, so `/` and `:` split cleanly.
|
|
73
|
+
const slash = on.indexOf("/");
|
|
74
|
+
if (slash > 0) {
|
|
75
|
+
const colon = on.indexOf(":", slash);
|
|
76
|
+
const laneId = on.slice(0, slash);
|
|
77
|
+
const variantId = on.slice(slash + 1, colon === -1 ? undefined : colon);
|
|
78
|
+
const lane = lanes.find((l) => l.id === laneId);
|
|
79
|
+
const variant = lane?.variants.find((v) => v.id === variantId);
|
|
80
|
+
const label = lane && variant ? (colon === -1 ? variantLabel(lane, variant) : cueLabel(lane, variant, on.slice(colon + 1))) : null;
|
|
81
|
+
if (label)
|
|
82
|
+
return label;
|
|
83
|
+
}
|
|
84
|
+
// 2–4. The read, a take, a section.
|
|
85
|
+
if (on === "vo" && (stage === "voice" || stage === "mix"))
|
|
86
|
+
return stage === "mix" ? "Voiceover" : "Assembled read";
|
|
87
|
+
if (stage === "voice") {
|
|
88
|
+
for (const s of ctx.script.sections) {
|
|
89
|
+
const i = s.takes.findIndex((t) => `${s.id}:${t.id}` === on);
|
|
90
|
+
if (i !== -1)
|
|
91
|
+
return `${s.id.toUpperCase()} · Take ${i + 1}`;
|
|
92
|
+
}
|
|
93
|
+
if (ctx.script.sections.some((s) => s.id === on))
|
|
94
|
+
return on.toUpperCase();
|
|
95
|
+
}
|
|
96
|
+
// 5. Older bare forms. On Mix, a picked variant first, as the dashboard prefers one being heard.
|
|
97
|
+
const picked = (l, v) => ctx.picks?.lanes[l.id] === v.id;
|
|
98
|
+
const pairs = lanes.flatMap((l) => l.variants.map((v) => ({ l, v })));
|
|
99
|
+
const ordered = stage === "mix" ? [...pairs.filter((p) => picked(p.l, p.v)), ...pairs.filter((p) => !picked(p.l, p.v))] : pairs;
|
|
100
|
+
const bare = ordered.find((p) => p.v.id === on);
|
|
101
|
+
if (bare)
|
|
102
|
+
return variantLabel(bare.l, bare.v);
|
|
103
|
+
const colon = on.indexOf(":");
|
|
104
|
+
if (colon > 0) {
|
|
105
|
+
const pass = pairs.find((p) => p.v.id === on.slice(0, colon) && p.v.cues.some((c) => c.id === on.slice(colon + 1)));
|
|
106
|
+
if (pass)
|
|
107
|
+
return cueLabel(pass.l, pass.v, on.slice(colon + 1));
|
|
108
|
+
}
|
|
109
|
+
const withCue = pairs.find((p) => p.v.cues.some((c) => c.id === on));
|
|
110
|
+
return withCue ? cueLabel(withCue.l, withCue.v, on) : null;
|
|
111
|
+
}
|
|
112
|
+
export function filterNotes(notes, f = {}) {
|
|
113
|
+
return notes.filter((n) => (f.stage === undefined || n.stage === f.stage) &&
|
|
114
|
+
(f.status === undefined || n.status === f.status) &&
|
|
115
|
+
(f.batch === undefined || n.batch === f.batch) &&
|
|
116
|
+
(f.version === undefined || n.version === f.version));
|
|
117
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* Store a media path the way the manifest wants it: relative to the project
|
|
4
|
+
* root with forward slashes when the file is inside the project, absolute
|
|
5
|
+
* when it lives elsewhere (renders often do).
|
|
6
|
+
*/
|
|
7
|
+
export function toManifestPath(root, file) {
|
|
8
|
+
const abs = isAbsolute(file) ? file : resolve(root, file);
|
|
9
|
+
const rel = relative(root, abs);
|
|
10
|
+
if (rel === "" || rel.startsWith("..") || isAbsolute(rel))
|
|
11
|
+
return abs;
|
|
12
|
+
return rel.split(sep).join("/");
|
|
13
|
+
}
|
|
14
|
+
/** Turn a manifest path back into an absolute path on disk. */
|
|
15
|
+
export function fromManifestPath(root, file) {
|
|
16
|
+
return isAbsolute(file) ? file : resolve(root, ...file.split("/"));
|
|
17
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
import { newProjectId, slugify, uniqueId } from "./ids.js";
|
|
3
|
+
import { InvalidError, NotFoundError } from "./errors.js";
|
|
4
|
+
/** Sets `p.id` when missing. Returns whether it changed anything. */
|
|
5
|
+
export function ensureProjectId(p) {
|
|
6
|
+
if (p.id)
|
|
7
|
+
return false;
|
|
8
|
+
p.id = newProjectId();
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
// One in-flight (or settled) promise per store, so the server's own startup ensure and the
|
|
12
|
+
// app's lazy one (a request that lands before startup's own ensure completes) always converge
|
|
13
|
+
// on the same call: whichever runs first registers the promise here, synchronously, before any
|
|
14
|
+
// `await` yields control, so a second caller for the same store only ever awaits it, never
|
|
15
|
+
// triggers a second store.update (which would otherwise bump project.json's rev a second time
|
|
16
|
+
// even though ensureProjectId itself is a no-op once the id is already set).
|
|
17
|
+
const ensuring = new WeakMap();
|
|
18
|
+
/** The project's id, generated and persisted the first time this is called for a given store. */
|
|
19
|
+
export function ensureProjectIdOnce(store) {
|
|
20
|
+
let p = ensuring.get(store);
|
|
21
|
+
if (!p) {
|
|
22
|
+
p = (async () => {
|
|
23
|
+
const project = await store.read("project");
|
|
24
|
+
if (project.id)
|
|
25
|
+
return project.id;
|
|
26
|
+
const { data } = await store.update("project", ensureProjectId);
|
|
27
|
+
return data.id;
|
|
28
|
+
})();
|
|
29
|
+
ensuring.set(store, p);
|
|
30
|
+
}
|
|
31
|
+
return p;
|
|
32
|
+
}
|
|
33
|
+
export function addVersion(p, input, now = new Date()) {
|
|
34
|
+
const vid = slugify(input.video);
|
|
35
|
+
let video = p.videos.find((v) => v.id === input.video || v.id === vid);
|
|
36
|
+
if (!video) {
|
|
37
|
+
video = { id: uniqueId(vid, p.videos.map((v) => v.id)), name: input.video, versions: [], lockedVersion: null };
|
|
38
|
+
p.videos.push(video);
|
|
39
|
+
}
|
|
40
|
+
const n = video.versions.reduce((max, v) => Math.max(max, Number(v.id.replace(/^v/, "")) || 0), 0) + 1;
|
|
41
|
+
const prev = latestVersion(video);
|
|
42
|
+
const duration = input.duration ?? null;
|
|
43
|
+
// Inherited shots are a copy of the previous version's, but one that starts at or past a
|
|
44
|
+
// shorter cut's duration can't belong to it: drop it rather than carry a shot nothing can
|
|
45
|
+
// ever reach (M4). Left alone when the duration isn't known yet.
|
|
46
|
+
const shots = prev ? (duration === null ? prev.shots : prev.shots.filter((s) => s.start < duration)) : [];
|
|
47
|
+
const version = {
|
|
48
|
+
id: `v${n}`,
|
|
49
|
+
file: input.file,
|
|
50
|
+
duration,
|
|
51
|
+
fps: input.fps ?? null,
|
|
52
|
+
addedAt: now.toISOString(),
|
|
53
|
+
note: input.note ?? "",
|
|
54
|
+
shots: shots.map((s) => ({ ...s })),
|
|
55
|
+
proxy: null,
|
|
56
|
+
};
|
|
57
|
+
video.versions.push(version);
|
|
58
|
+
return { video, version };
|
|
59
|
+
}
|
|
60
|
+
export function latestVersion(video) {
|
|
61
|
+
return video.versions[video.versions.length - 1];
|
|
62
|
+
}
|
|
63
|
+
/** The named version, or the newest when `versionId` is undefined. */
|
|
64
|
+
function resolveVersion(video, versionId) {
|
|
65
|
+
if (versionId === undefined) {
|
|
66
|
+
const v = latestVersion(video);
|
|
67
|
+
if (!v)
|
|
68
|
+
throw new NotFoundError("version", "(none)");
|
|
69
|
+
return v;
|
|
70
|
+
}
|
|
71
|
+
const v = video.versions.find((x) => x.id === versionId);
|
|
72
|
+
if (!v)
|
|
73
|
+
throw new NotFoundError("version", versionId);
|
|
74
|
+
return v;
|
|
75
|
+
}
|
|
76
|
+
const LANE_NAMES = { voice: "Voiceover", music: "Music", sfx: "Sound effects" };
|
|
77
|
+
export function addVariant(p, input) {
|
|
78
|
+
// Lane ids are capped at 64 by the schema; a slug can outgrow its source (NFKD splits ligatures).
|
|
79
|
+
const laneId = slugify(input.lane ?? input.round ?? input.stage).slice(0, 64).replace(/-+$/, "");
|
|
80
|
+
let lane = p.lanes.find((l) => l.id === laneId);
|
|
81
|
+
if (lane && lane.stage !== input.stage)
|
|
82
|
+
throw new InvalidError(`Lane "${laneId}" belongs to ${lane.stage}, not ${input.stage}`);
|
|
83
|
+
if (!lane) {
|
|
84
|
+
lane = { id: laneId, stage: input.stage, name: input.round ?? input.lane ?? LANE_NAMES[input.stage], variants: [] };
|
|
85
|
+
p.lanes.push(lane);
|
|
86
|
+
}
|
|
87
|
+
const cues = [];
|
|
88
|
+
for (const c of input.cues ?? []) {
|
|
89
|
+
cues.push({ id: uniqueId(slugify(c.name), cues.map((x) => x.id)), name: c.name, t: c.t });
|
|
90
|
+
}
|
|
91
|
+
const variant = {
|
|
92
|
+
id: uniqueId(slugify(input.name), lane.variants.map((v) => v.id)),
|
|
93
|
+
name: input.name,
|
|
94
|
+
file: input.file,
|
|
95
|
+
meta: input.description === undefined ? { ...input.meta } : { ...input.meta, description: input.description },
|
|
96
|
+
cues,
|
|
97
|
+
};
|
|
98
|
+
lane.variants.push(variant);
|
|
99
|
+
return { lane, variant };
|
|
100
|
+
}
|
|
101
|
+
const FILE_NAME_MAX = 120;
|
|
102
|
+
// Leaves room for uniqueId's "-2", "-3" ... suffix and the odd longer one, well inside the
|
|
103
|
+
// schema's 64-character id cap.
|
|
104
|
+
const FILE_SLUG_MAX = 58;
|
|
105
|
+
/** `base`, cut to at most `max` characters, preferring to cut at a `-` so the id still reads as
|
|
106
|
+
* whole words rather than stopping mid-word. */
|
|
107
|
+
function trimSlugBase(base, max) {
|
|
108
|
+
if (base.length <= max)
|
|
109
|
+
return base;
|
|
110
|
+
const cut = base.slice(0, max);
|
|
111
|
+
const dash = cut.lastIndexOf("-");
|
|
112
|
+
return dash > max / 2 ? cut.slice(0, dash) : cut;
|
|
113
|
+
}
|
|
114
|
+
/** Registers a project file (a doc, image, caption, export, delivery or edit file) in the library. */
|
|
115
|
+
export function addFile(p, input, now = new Date()) {
|
|
116
|
+
const given = input.name?.trim();
|
|
117
|
+
let name;
|
|
118
|
+
if (given) {
|
|
119
|
+
if (given.length > FILE_NAME_MAX)
|
|
120
|
+
throw new InvalidError("Name is over 120 characters");
|
|
121
|
+
name = given;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
const base = basename(input.file);
|
|
125
|
+
name = base.length > FILE_NAME_MAX ? `${base.slice(0, FILE_NAME_MAX - 1)}…` : base;
|
|
126
|
+
}
|
|
127
|
+
const video = input.video ? resolveVideo(p, input.video).id : null;
|
|
128
|
+
const entry = {
|
|
129
|
+
id: uniqueId(trimSlugBase(slugify(name), FILE_SLUG_MAX), p.files.map((f) => f.id)),
|
|
130
|
+
kind: input.kind,
|
|
131
|
+
file: input.file,
|
|
132
|
+
name,
|
|
133
|
+
note: input.note ?? "",
|
|
134
|
+
video,
|
|
135
|
+
addedAt: now.toISOString(),
|
|
136
|
+
};
|
|
137
|
+
p.files.push(entry);
|
|
138
|
+
return entry;
|
|
139
|
+
}
|
|
140
|
+
export function findVideo(p, id) {
|
|
141
|
+
const v = p.videos.find((x) => x.id === id);
|
|
142
|
+
if (!v)
|
|
143
|
+
throw new NotFoundError("video", id);
|
|
144
|
+
return v;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Finds a video by id, slug or name, so routes, MCP tools and the CLI all accept either
|
|
148
|
+
* "Hero 60s" or "hero-60s". Tried in order: exact id, then `slugify(ref)`, then a
|
|
149
|
+
* case-insensitive exact name match.
|
|
150
|
+
*/
|
|
151
|
+
export function resolveVideo(p, ref) {
|
|
152
|
+
const byId = p.videos.find((v) => v.id === ref);
|
|
153
|
+
if (byId)
|
|
154
|
+
return byId;
|
|
155
|
+
const slug = slugify(ref);
|
|
156
|
+
const bySlug = p.videos.find((v) => v.id === slug);
|
|
157
|
+
if (bySlug)
|
|
158
|
+
return bySlug;
|
|
159
|
+
const lower = ref.toLowerCase();
|
|
160
|
+
const byName = p.videos.find((v) => v.name.toLowerCase() === lower);
|
|
161
|
+
if (byName)
|
|
162
|
+
return byName;
|
|
163
|
+
throw new NotFoundError("video", ref);
|
|
164
|
+
}
|
|
165
|
+
/** Replaces a version's shot list: sorted by start, renumbered from 1. */
|
|
166
|
+
export function setShots(p, videoId, versionId, shots) {
|
|
167
|
+
const video = resolveVideo(p, videoId);
|
|
168
|
+
const version = resolveVersion(video, versionId);
|
|
169
|
+
if (shots.length > 200)
|
|
170
|
+
throw new InvalidError("A shot list holds at most 200 shots");
|
|
171
|
+
const sorted = [...shots].sort((a, b) => a.start - b.start);
|
|
172
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
173
|
+
if (sorted[i].start === sorted[i - 1].start)
|
|
174
|
+
throw new InvalidError(`Two shots start at ${sorted[i].start.toFixed(2)} s`);
|
|
175
|
+
}
|
|
176
|
+
if (version.duration !== null) {
|
|
177
|
+
const late = sorted.find((s) => s.start >= version.duration);
|
|
178
|
+
if (late)
|
|
179
|
+
throw new InvalidError(`Shot starts at ${late.start.toFixed(2)} s, at or after the cut's duration`);
|
|
180
|
+
}
|
|
181
|
+
version.shots = sorted.map((s, i) => ({ n: i + 1, name: s.name, start: s.start, tag: s.tag ?? "" }));
|
|
182
|
+
return version;
|
|
183
|
+
}
|
|
184
|
+
/** Locks a video's picture at a version, or unlocks it when `versionId` is null. */
|
|
185
|
+
export function lockPicture(p, videoId, versionId) {
|
|
186
|
+
const video = resolveVideo(p, videoId);
|
|
187
|
+
if (versionId !== null && !video.versions.some((v) => v.id === versionId))
|
|
188
|
+
throw new NotFoundError("version", versionId);
|
|
189
|
+
video.lockedVersion = versionId;
|
|
190
|
+
return video;
|
|
191
|
+
}
|
|
192
|
+
/** The last shot whose start is at or before `t`, or null when `t` is before the first shot. */
|
|
193
|
+
export function shotAt(shots, t) {
|
|
194
|
+
let found = null;
|
|
195
|
+
for (const s of shots) {
|
|
196
|
+
if (s.start <= t && (!found || s.start > found.start))
|
|
197
|
+
found = s;
|
|
198
|
+
}
|
|
199
|
+
return found ? { n: found.n, name: found.name } : null;
|
|
200
|
+
}
|