rushes 0.2.1 → 0.3.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/plugin.json +1 -1
- package/AGENTS.md +36 -8
- package/README.md +75 -4
- package/dist/cli/doctor.js +35 -10
- package/dist/cli/main.js +200 -18
- package/dist/core/batches.js +35 -3
- package/dist/core/exportNotes.js +9 -5
- package/dist/core/formats.js +159 -0
- package/dist/core/found.js +333 -0
- package/dist/core/labels.js +192 -0
- package/dist/core/log.js +190 -0
- package/dist/core/logEvents.js +193 -0
- package/dist/core/logText.js +122 -0
- package/dist/core/media.js +119 -13
- package/dist/core/notes.js +35 -4
- package/dist/core/project.js +69 -1
- package/dist/core/schema.js +147 -1
- package/dist/core/store.js +19 -3
- package/dist/mcp/client.js +13 -1
- package/dist/mcp/tools.js +181 -11
- package/dist/server/app.js +495 -38
- package/dist/server/assets.js +19 -7
- package/dist/server/files.js +61 -4
- package/dist/server/found.js +1216 -0
- package/dist/server/logbook.js +208 -0
- package/dist/server/loudness.js +7 -3
- package/dist/server/peaks.js +3 -2
- package/dist/server/proxy.js +16 -4
- package/dist/server/start.js +15 -2
- package/package.json +1 -1
- package/skills/rushes/SKILL.md +9 -4
- package/web-dist/assets/index-BDMm5p1-.css +1 -0
- package/web-dist/assets/index-C9dBtlRy.js +3 -0
- package/web-dist/index.html +2 -2
- package/web-dist/assets/index-ChXjhVC5.js +0 -3
- package/web-dist/assets/index-Cj_tr1I-.css +0 -1
package/dist/core/media.js
CHANGED
|
@@ -18,25 +18,27 @@ export function parseRate(rate) {
|
|
|
18
18
|
}
|
|
19
19
|
/** How long one ffprobe may run before it's killed and treated as no probe (a stalled network volume, say). */
|
|
20
20
|
export const PROBE_TIMEOUT_MS = 20_000;
|
|
21
|
+
/** How long past its timeout a probe is waited for before Rushes stops waiting. */
|
|
22
|
+
export const GIVE_UP_GRACE_MS = 1_000;
|
|
21
23
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
+
* Waits for `work` (an ffprobe run), but not past `timeout` + GIVE_UP_GRACE_MS and not past
|
|
25
|
+
* `signal` aborting: then it answers `gaveUp(why)` instead. execFile kills ffprobe at its timeout
|
|
26
|
+
* or on abort, but only answers once ffprobe has exited, and a process stuck in an uninterruptible
|
|
27
|
+
* read (a stalled network drive) can outlive SIGKILL. Every ffprobe in Rushes waits through this.
|
|
24
28
|
*/
|
|
25
|
-
export async function
|
|
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.
|
|
29
|
+
export async function giveUpAfter(work, opts) {
|
|
31
30
|
let timer;
|
|
32
31
|
let onAbort;
|
|
33
32
|
const giveUp = new Promise((res) => {
|
|
34
|
-
timer = setTimeout(() => res(
|
|
35
|
-
onAbort = () => res(
|
|
36
|
-
opts.signal?.
|
|
33
|
+
timer = setTimeout(() => res(opts.gaveUp("timeout")), opts.timeout + GIVE_UP_GRACE_MS);
|
|
34
|
+
onAbort = () => res(opts.gaveUp("aborted"));
|
|
35
|
+
if (opts.signal?.aborted)
|
|
36
|
+
onAbort();
|
|
37
|
+
else
|
|
38
|
+
opts.signal?.addEventListener("abort", onAbort, { once: true });
|
|
37
39
|
});
|
|
38
40
|
try {
|
|
39
|
-
return await Promise.race([
|
|
41
|
+
return await Promise.race([work, giveUp]);
|
|
40
42
|
}
|
|
41
43
|
finally {
|
|
42
44
|
clearTimeout(timer);
|
|
@@ -44,10 +46,26 @@ export async function probe(file, opts = {}) {
|
|
|
44
46
|
opts.signal?.removeEventListener("abort", onAbort);
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Read duration, frame rate, codec, size and pixel format with ffprobe. Returns nulls when ffprobe
|
|
51
|
+
* is missing or fails, takes longer than `timeout` (default 20 s), or `signal` aborts.
|
|
52
|
+
* `formats` is the containers it may read the file as: VIDEO_FORMATS for a cut, AUDIO_FORMATS
|
|
53
|
+
* (the default) for audio. Any other container, a playlist named .mp4 say, reads as nothing.
|
|
54
|
+
*/
|
|
55
|
+
export async function probe(file, opts = {}) {
|
|
56
|
+
if (opts.signal?.aborted || !(await hasFfprobe()))
|
|
57
|
+
return { ...NO_PROBE };
|
|
58
|
+
const timeout = opts.timeout ?? PROBE_TIMEOUT_MS;
|
|
59
|
+
return giveUpAfter(readProbe(file, timeout, opts.signal, opts.formats ?? AUDIO_FORMATS), { timeout, signal: opts.signal, gaveUp: () => ({ ...NO_PROBE }) });
|
|
60
|
+
}
|
|
61
|
+
async function readProbe(file, timeout, signal, formats) {
|
|
48
62
|
try {
|
|
49
63
|
const { stdout } = await run("ffprobe", [
|
|
50
64
|
"-v", "error",
|
|
65
|
+
// Local files only: a playlist or container that names a URL is never followed. And only
|
|
66
|
+
// the caller's containers: a playlist named .mp4 is never read through to the files it names.
|
|
67
|
+
"-protocol_whitelist", "file",
|
|
68
|
+
"-format_whitelist", formats,
|
|
51
69
|
"-show_entries", "format=duration:stream=codec_type,codec_name,width,height,pix_fmt,avg_frame_rate,r_frame_rate",
|
|
52
70
|
"-of", "json",
|
|
53
71
|
file,
|
|
@@ -71,6 +89,94 @@ async function readProbe(file, timeout, signal) {
|
|
|
71
89
|
function positiveInt(n) {
|
|
72
90
|
return typeof n === "number" && Number.isInteger(n) && n > 0 ? n : null;
|
|
73
91
|
}
|
|
92
|
+
/** §21.6: the extensions a cut or a format may have. Anything else isn't video. */
|
|
93
|
+
export const VIDEO_EXT = new Set(["mp4", "mov", "m4v", "webm", "mkv"]);
|
|
94
|
+
/**
|
|
95
|
+
* The only containers a render or a cut is read as (final review I1): ffprobe and ffmpeg pick a
|
|
96
|
+
* demuxer by the file's content, not its name, so without this a playlist named cat.mp4 (ffconcat)
|
|
97
|
+
* or a GIF would be read, and a playlist would open the files it names. The video demuxers the
|
|
98
|
+
* dashboard's cuts can be: MP4/MOV, Matroska/WebM, AVI, MPEG-TS, MXF, ASF, MPEG-PS, FLV, DV and Ogg.
|
|
99
|
+
*/
|
|
100
|
+
export const VIDEO_FORMATS = "mov,mp4,m4a,3gp,3g2,mj2,matroska,webm,avi,mpegts,mxf,asf,mpeg,flv,dv,ogg";
|
|
101
|
+
/**
|
|
102
|
+
* The containers audio is read as: the audio ones, and the video ones a voice read, a bed or a
|
|
103
|
+
* cut's sound can come in (M4A is the MP4 demuxer). Never a playlist, an image or a GIF. It is the
|
|
104
|
+
* waveform list (peaks.ts's PEAKS_FORMATS) and the default for `probe`.
|
|
105
|
+
*/
|
|
106
|
+
export const AUDIO_FORMATS = "mov,mp4,m4a,3gp,3g2,mj2,matroska,webm,avi,mpegts,mxf,wav,w64,aiff,mp3,aac,flac,ogg,caf,asf,mpeg,flv,dv";
|
|
107
|
+
/** ffprobe's "[concat @ 0x…] Format not on whitelist": the container it found, or null. */
|
|
108
|
+
function refusedContainer(stderr) {
|
|
109
|
+
return /\[([a-z0-9_]+) @ 0x[0-9a-f]+\] Format not on whitelist/i.exec(stderr)?.[1] ?? null;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* ffprobe's `-show_format -show_streams` JSON as a VideoProbe. The size is the one on screen (Review
|
|
113
|
+
* Focus 2): non-square pixels widen it, and a quarter turn of rotation metadata swaps its sides.
|
|
114
|
+
*/
|
|
115
|
+
export function parseVideoProbe(json) {
|
|
116
|
+
const j = (json ?? {});
|
|
117
|
+
if (/(^|,)image2(,|$)|_pipe(,|$)/.test(j.format?.format_name ?? ""))
|
|
118
|
+
return { ok: false, code: "not_video", reason: "it's a still image" };
|
|
119
|
+
const s = j.streams?.find((x) => x.codec_type === "video" && x.disposition?.attached_pic !== 1);
|
|
120
|
+
if (!s)
|
|
121
|
+
return { ok: false, code: "not_video", reason: "it has no video stream" };
|
|
122
|
+
const w = positiveInt(s.width);
|
|
123
|
+
const h = positiveInt(s.height);
|
|
124
|
+
if (w === null || h === null)
|
|
125
|
+
return { ok: false, code: "unreadable", reason: "it has no picture size" };
|
|
126
|
+
const sar = /^(\d+):(\d+)$/.exec(s.sample_aspect_ratio ?? "");
|
|
127
|
+
const pixel = sar && Number(sar[1]) > 0 && Number(sar[2]) > 0 ? Number(sar[1]) / Number(sar[2]) : 1;
|
|
128
|
+
let width = Math.round(w * pixel);
|
|
129
|
+
let height = h;
|
|
130
|
+
const rotation = s.side_data_list?.find((d) => typeof d.rotation === "number")?.rotation ?? Number(s.tags?.rotate ?? 0);
|
|
131
|
+
if (Math.abs(Math.round(rotation)) % 180 === 90)
|
|
132
|
+
[width, height] = [height, width];
|
|
133
|
+
const d = j.format?.duration ? Number(j.format.duration) : Number.NaN;
|
|
134
|
+
return { ok: true, width, height, duration: Number.isFinite(d) && d >= 0 ? d : null, fps: parseRate(s.avg_frame_rate) ?? parseRate(s.r_frame_rate) };
|
|
135
|
+
}
|
|
136
|
+
/** Why a render wasn't read, when the reading itself was cut short. */
|
|
137
|
+
const TOO_LONG = { ok: false, code: "unreadable", reason: "ffprobe took too long" };
|
|
138
|
+
const STOPPED = { ok: false, code: "unreadable", reason: "ffprobe was stopped" };
|
|
139
|
+
/** giveUpAfter's answer for a render: it took too long, or it was stopped. */
|
|
140
|
+
export function videoGaveUp(why) {
|
|
141
|
+
return { ...(why === "timeout" ? TOO_LONG : STOPPED) };
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* §21.3: reads a render with ffprobe, local files only. The reason never repeats the file's path.
|
|
145
|
+
* Like `probe`, it gives up `timeout` (default 20 s) plus a second on, or when `signal` aborts.
|
|
146
|
+
*/
|
|
147
|
+
export async function probeVideo(file, opts = {}) {
|
|
148
|
+
if (opts.signal?.aborted)
|
|
149
|
+
return videoGaveUp("aborted");
|
|
150
|
+
if (!(await hasFfprobe()))
|
|
151
|
+
return { ok: false, code: "no_ffprobe", reason: "needs ffprobe to read the ratio" };
|
|
152
|
+
const timeout = opts.timeout ?? PROBE_TIMEOUT_MS;
|
|
153
|
+
return giveUpAfter(readVideoProbe(file, timeout, opts.signal), { timeout, signal: opts.signal, gaveUp: videoGaveUp });
|
|
154
|
+
}
|
|
155
|
+
async function readVideoProbe(file, timeout, signal) {
|
|
156
|
+
try {
|
|
157
|
+
const { stdout } = await run("ffprobe",
|
|
158
|
+
// Local files only: a playlist or container that names a URL is never followed. And only video
|
|
159
|
+
// containers: a playlist named .mp4 is refused, never read through to the files it names.
|
|
160
|
+
["-v", "error", "-protocol_whitelist", "file", "-format_whitelist", VIDEO_FORMATS, "-show_format", "-show_streams", "-of", "json", file], { timeout, killSignal: "SIGKILL", maxBuffer: 8 * 1024 * 1024, signal });
|
|
161
|
+
return parseVideoProbe(JSON.parse(stdout));
|
|
162
|
+
}
|
|
163
|
+
catch (e) {
|
|
164
|
+
if (signal?.aborted)
|
|
165
|
+
return videoGaveUp("aborted");
|
|
166
|
+
// Killed at its timeout (execFile sets `killed`), so there are no last words to report.
|
|
167
|
+
if (e.killed)
|
|
168
|
+
return videoGaveUp("timeout");
|
|
169
|
+
const stderr = String(e.stderr ?? "");
|
|
170
|
+
const container = refusedContainer(stderr);
|
|
171
|
+
if (container)
|
|
172
|
+
return { ok: false, code: "not_video", reason: `it's a ${container} file`, container };
|
|
173
|
+
const last = stderr.trim().split("\n").pop() ?? "";
|
|
174
|
+
const trimmed = last.startsWith(`${file}: `) ? last.slice(file.length + 2) : last;
|
|
175
|
+
// Belt and braces: the path never appears anywhere in what goes back to the caller.
|
|
176
|
+
const reason = trimmed.split(file).join("the file");
|
|
177
|
+
return { ok: false, code: "unreadable", reason: reason.slice(0, 200) || "ffprobe couldn't read it" };
|
|
178
|
+
}
|
|
179
|
+
}
|
|
74
180
|
// §19.5: when Rushes offers a proxy.
|
|
75
181
|
const PLAYABLE_CODECS = new Set(["h264", "vp9", "av1"]);
|
|
76
182
|
const MAX_EDGE = 3000;
|
package/dist/core/notes.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NoteSchema, } from "./schema.js";
|
|
2
|
-
import { InvalidError, NotFoundError } from "./errors.js";
|
|
2
|
+
import { InvalidError, NotFoundError, RushesError } from "./errors.js";
|
|
3
|
+
import { labelOfId, versionFormats } from "./formats.js";
|
|
3
4
|
import { newId } from "./ids.js";
|
|
4
5
|
export function addNote(file, input, now = new Date()) {
|
|
5
6
|
const parsed = NoteSchema.safeParse({ ...input, id: newId("n"), createdAt: now.toISOString() });
|
|
@@ -32,20 +33,49 @@ export function applyReply(file, r) {
|
|
|
32
33
|
n.fixVersion = r.fixVersion;
|
|
33
34
|
return n;
|
|
34
35
|
}
|
|
35
|
-
export function applyUserEdit(file, e) {
|
|
36
|
+
export function applyUserEdit(file, e, check) {
|
|
36
37
|
const n = find(file, e.id);
|
|
37
38
|
const next = { ...n };
|
|
38
|
-
for (const k of ["text", "box", "grab", "scope", "t", "tOut", "marks", "status"]) {
|
|
39
|
+
for (const k of ["text", "box", "grab", "scope", "t", "tOut", "marks", "status", "format"]) {
|
|
39
40
|
if (e[k] !== undefined)
|
|
40
41
|
next[k] = e[k];
|
|
41
42
|
}
|
|
42
43
|
const parsed = NoteSchema.safeParse(next);
|
|
43
44
|
if (!parsed.success)
|
|
44
45
|
throw new InvalidError("Note edit is invalid", parsed.error.issues);
|
|
46
|
+
check?.(parsed.data, n);
|
|
45
47
|
reopen(n, e.status);
|
|
46
48
|
Object.assign(n, { ...parsed.data, batch: n.batch });
|
|
47
49
|
return n;
|
|
48
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* §21.3 and R7, checked when a note is written: a format must be one of the note's version's;
|
|
53
|
+
* only Picture notes have one; on a cut with two or more formats a box needs a format, and a box
|
|
54
|
+
* kept from before stays on the format it was drawn on (the primary, for a note from before formats).
|
|
55
|
+
*/
|
|
56
|
+
export function checkNoteFormat({ next, prev, boxRedrawn = false }, project) {
|
|
57
|
+
if (next.format !== null && next.stage !== "picture")
|
|
58
|
+
throw new RushesError("Only Picture notes belong to a format.", 400, "format_not_picture");
|
|
59
|
+
if (next.stage !== "picture")
|
|
60
|
+
return;
|
|
61
|
+
const version = project.videos.find((v) => v.id === next.video)?.versions.find((v) => v.id === next.version);
|
|
62
|
+
const shapes = version ? versionFormats(version) : [];
|
|
63
|
+
if (next.format !== null && !shapes.some((f) => f.id === next.format)) {
|
|
64
|
+
throw new RushesError(`${next.version ?? "That cut"} has no ${labelOfId(next.format)} format.`, 400, "unknown_format", { format: next.format });
|
|
65
|
+
}
|
|
66
|
+
if (!next.box || !version || version.formats.length === 0)
|
|
67
|
+
return;
|
|
68
|
+
if (next.format === null)
|
|
69
|
+
throw new RushesError("A drawn box belongs to one frame, so this note stays on one format.", 400, "box_needs_format");
|
|
70
|
+
if (prev?.box && !boxRedrawn) {
|
|
71
|
+
// An older note drew its box on the primary. If the primary's size isn't stored, nobody can say
|
|
72
|
+
// which format that is, so the box isn't judged (and no primary is invented).
|
|
73
|
+
const drawnOn = prev.format ?? shapes.find((f) => f.primary)?.id;
|
|
74
|
+
if (drawnOn !== undefined && next.format !== drawnOn) {
|
|
75
|
+
throw new RushesError(`A drawn box belongs to the frame it was drawn on (${labelOfId(drawnOn)}), so this note stays there.`, 400, "box_fixes_format", { format: drawnOn });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
49
79
|
/**
|
|
50
80
|
* What an audio note is `on`, in words, for export and the CLI (§17): the lane and variant
|
|
51
81
|
* ("Music · Warm keys"), a cue ("Sound effects · Pass A · Cue · Swipe"), a take ("S2 · Take 1"), a
|
|
@@ -113,5 +143,6 @@ export function filterNotes(notes, f = {}) {
|
|
|
113
143
|
return notes.filter((n) => (f.stage === undefined || n.stage === f.stage) &&
|
|
114
144
|
(f.status === undefined || n.status === f.status) &&
|
|
115
145
|
(f.batch === undefined || n.batch === f.batch) &&
|
|
116
|
-
(f.version === undefined || n.version === f.version)
|
|
146
|
+
(f.version === undefined || n.version === f.version) &&
|
|
147
|
+
(f.format === undefined || (n.stage === "picture" && (n.format === f.format || (!f.onlyThisFormat && n.format === null)))));
|
|
117
148
|
}
|
package/dist/core/project.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { basename } from "node:path";
|
|
2
2
|
import { newProjectId, slugify, uniqueId } from "./ids.js";
|
|
3
|
-
import { InvalidError, NotFoundError } from "./errors.js";
|
|
3
|
+
import { InvalidError, NotFoundError, RushesError } from "./errors.js";
|
|
4
|
+
import { MAX_FORMATS, durationWarning, ratioId, sameShape, settleLabel, versionFormats } from "./formats.js";
|
|
5
|
+
import { oneLineOf } from "./labels.js";
|
|
4
6
|
/** Sets `p.id` when missing. Returns whether it changed anything. */
|
|
5
7
|
export function ensureProjectId(p) {
|
|
6
8
|
if (p.id)
|
|
@@ -51,8 +53,12 @@ export function addVersion(p, input, now = new Date()) {
|
|
|
51
53
|
fps: input.fps ?? null,
|
|
52
54
|
addedAt: now.toISOString(),
|
|
53
55
|
note: input.note ?? "",
|
|
56
|
+
label: oneLineOf(input.label ?? ""),
|
|
54
57
|
shots: shots.map((s) => ({ ...s })),
|
|
55
58
|
proxy: null,
|
|
59
|
+
width: input.width ?? null,
|
|
60
|
+
height: input.height ?? null,
|
|
61
|
+
formats: [],
|
|
56
62
|
};
|
|
57
63
|
video.versions.push(version);
|
|
58
64
|
return { video, version };
|
|
@@ -189,6 +195,68 @@ export function lockPicture(p, videoId, versionId) {
|
|
|
189
195
|
video.lockedVersion = versionId;
|
|
190
196
|
return video;
|
|
191
197
|
}
|
|
198
|
+
/** The cut `videoRef`/`versionId` names, defaulting to the newest cut of the only or newest film (§21.4, R16). */
|
|
199
|
+
export function resolveCut(p, videoRef, versionId) {
|
|
200
|
+
let video;
|
|
201
|
+
if (videoRef !== undefined)
|
|
202
|
+
video = resolveVideo(p, videoRef);
|
|
203
|
+
else {
|
|
204
|
+
let newest = null;
|
|
205
|
+
for (const v of p.videos) {
|
|
206
|
+
const last = latestVersion(v);
|
|
207
|
+
if (last && (newest === null || last.addedAt >= newest)) {
|
|
208
|
+
newest = last.addedAt;
|
|
209
|
+
video = v;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (!video)
|
|
214
|
+
throw new RushesError("There's no cut to add a format to yet. Register one with rushes_add_version first.", 404, "no_cut");
|
|
215
|
+
return { video, version: resolveVersion(video, versionId) };
|
|
216
|
+
}
|
|
217
|
+
/** A size the probe or the caller gave that isn't a picture size is a refusal, not a crash. */
|
|
218
|
+
function checkedLabel(width, height, hint) {
|
|
219
|
+
try {
|
|
220
|
+
return settleLabel(width, height, hint);
|
|
221
|
+
}
|
|
222
|
+
catch (e) {
|
|
223
|
+
if (e instanceof RangeError)
|
|
224
|
+
throw new RushesError(`${width}×${height} isn't a picture size.`, 400, "bad_size", { width, height });
|
|
225
|
+
throw e;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* §21.3: registers another shape of a cut. Refuses a ratio the cut already has, and a ninth shape.
|
|
230
|
+
* Atomic: every check runs on local values, and the version is written only once all of them pass.
|
|
231
|
+
*/
|
|
232
|
+
export function addFormat(p, input, now = new Date()) {
|
|
233
|
+
const { video, version } = resolveCut(p, input.video, input.version);
|
|
234
|
+
let primary = version.width !== null && version.height !== null ? { width: version.width, height: version.height } : null;
|
|
235
|
+
if (!primary) {
|
|
236
|
+
if (!input.primarySize) {
|
|
237
|
+
throw new RushesError(`Rushes can't read ${version.id}'s own picture size, so it can't tell a new shape from it. Check that the cut's file is there and that ffprobe is installed.`, 422, "no_primary_size", { version: version.id });
|
|
238
|
+
}
|
|
239
|
+
primary = { width: input.primarySize.width, height: input.primarySize.height };
|
|
240
|
+
checkedLabel(primary.width, primary.height);
|
|
241
|
+
}
|
|
242
|
+
const { label, note } = checkedLabel(input.width, input.height, input.label);
|
|
243
|
+
const id = ratioId(label);
|
|
244
|
+
const shapes = versionFormats({ ...version, width: primary.width, height: primary.height });
|
|
245
|
+
// The same id, or a ratio within 1% under another label (final review M1): either way, one shape.
|
|
246
|
+
const taken = shapes.find((f) => f.id === id) ?? shapes.find((f) => sameShape(f, input));
|
|
247
|
+
if (taken) {
|
|
248
|
+
throw new RushesError(`${version.id} already has ${taken.label}. Register a re-render as a new version.`, 409, "same_ratio", { version: version.id, id: taken.id, label: taken.label, file: taken.file });
|
|
249
|
+
}
|
|
250
|
+
if (shapes.length >= MAX_FORMATS) {
|
|
251
|
+
throw new RushesError(`${version.id} already has ${MAX_FORMATS} formats, the most one cut can have.`, 400, "too_many_formats", { version: version.id });
|
|
252
|
+
}
|
|
253
|
+
const format = { id, label, file: input.file, width: input.width, height: input.height, duration: input.duration, fps: input.fps, addedAt: now.toISOString() };
|
|
254
|
+
// Every check has passed: now, and only now, the version changes.
|
|
255
|
+
version.width = primary.width;
|
|
256
|
+
version.height = primary.height;
|
|
257
|
+
version.formats.push(format);
|
|
258
|
+
return { video, version, format, warning: durationWarning(label, input.duration, version.duration), labelNote: note };
|
|
259
|
+
}
|
|
192
260
|
/** The last shot whose start is at or before `t`, or null when `t` is before the first shot. */
|
|
193
261
|
export function shotAt(shots, t) {
|
|
194
262
|
let found = null;
|
package/dist/core/schema.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { FORMAT_ID_RE, isPictureSize, labelOfId, ratioId, ratioLabel } from "./formats.js";
|
|
3
|
+
import { oneLineOf } from "./labels.js";
|
|
4
|
+
import { LOG_AREAS, LOG_BY, LOG_KINDS, LOG_MAX, LOG_TEXT_MAX } from "./logText.js";
|
|
2
5
|
export const STAGES = ["script", "picture", "voice", "music", "sfx", "mix"];
|
|
3
6
|
export const StageSchema = z.enum(STAGES);
|
|
4
7
|
export const LaneStageSchema = z.enum(["voice", "music", "sfx"]);
|
|
@@ -19,16 +22,52 @@ export const ProxySchema = z.object({
|
|
|
19
22
|
bytes: z.number().int().nonnegative(),
|
|
20
23
|
createdAt: z.string(),
|
|
21
24
|
});
|
|
22
|
-
|
|
25
|
+
// §21.3: another render of the same cut at another aspect ratio. Its id is its label with ":" as "x".
|
|
26
|
+
export const FormatSchema = z.object({
|
|
27
|
+
id: z.string().max(16).regex(FORMAT_ID_RE),
|
|
28
|
+
label: z.string().min(3).max(16),
|
|
29
|
+
file: z.string().min(1),
|
|
30
|
+
width: z.number().int().positive(),
|
|
31
|
+
height: z.number().int().positive(),
|
|
32
|
+
duration: seconds.nullable().default(null),
|
|
33
|
+
fps: z.number().positive().nullable().default(null),
|
|
34
|
+
addedAt: z.string(),
|
|
35
|
+
});
|
|
36
|
+
export const VersionSchema = z
|
|
37
|
+
.object({
|
|
23
38
|
id,
|
|
24
39
|
file: z.string().min(1),
|
|
25
40
|
duration: seconds.nullable().default(null),
|
|
26
41
|
fps: z.number().positive().nullable().default(null),
|
|
27
42
|
addedAt: z.string(),
|
|
28
43
|
note: z.string().default(""),
|
|
44
|
+
// §22.3: a short label the agent writes, shown in the version list. The 48-character limit is
|
|
45
|
+
// enforced where labels come in (the route, the tool, the CLI). A hand-edited longer one still
|
|
46
|
+
// loads, and shortLabel shows it cut (§22.9, R2). Not the same thing as a format's `label`
|
|
47
|
+
// (its aspect ratio, "9:16").
|
|
48
|
+
label: z.string().default(""),
|
|
29
49
|
shots: z.array(ShotSchema).max(200).default([]),
|
|
30
50
|
// §19.5: a lightweight H.264 copy for smooth preview. Set only once a render has completed.
|
|
31
51
|
proxy: ProxySchema.nullable().default(null),
|
|
52
|
+
// §21.3 (R2): the primary render's picture size as shown, read when the cut is added. Null for a
|
|
53
|
+
// cut from before formats until its first format is registered.
|
|
54
|
+
width: z.number().int().positive().nullable().default(null),
|
|
55
|
+
height: z.number().int().positive().nullable().default(null),
|
|
56
|
+
// §21.3: the other renders of this cut, one per aspect ratio. The primary (`file`) is a format too.
|
|
57
|
+
formats: z.array(FormatSchema).max(8).default([]),
|
|
58
|
+
})
|
|
59
|
+
.superRefine((v, ctx) => {
|
|
60
|
+
// One shape per ratio: no two formats share an id, and none repeats the primary's.
|
|
61
|
+
// A bad width or height is reported by its own field check; the ratio is only worked out for a real size.
|
|
62
|
+
const primary = v.width !== null && v.height !== null && isPictureSize(v.width, v.height) ? ratioId(ratioLabel(v.width, v.height)) : null;
|
|
63
|
+
const seen = new Set(primary ? [primary] : []);
|
|
64
|
+
v.formats.forEach((f, i) => {
|
|
65
|
+
if (f.label !== labelOfId(f.id))
|
|
66
|
+
ctx.addIssue({ code: "custom", path: ["formats", i, "label"], message: `label "${f.label}" doesn't match id "${f.id}"` });
|
|
67
|
+
if (seen.has(f.id))
|
|
68
|
+
ctx.addIssue({ code: "custom", path: ["formats", i, "id"], message: `${v.id} already has ${f.label}` });
|
|
69
|
+
seen.add(f.id);
|
|
70
|
+
});
|
|
32
71
|
});
|
|
33
72
|
export const VideoSchema = z.object({
|
|
34
73
|
id,
|
|
@@ -142,6 +181,9 @@ export const NoteSchema = z
|
|
|
142
181
|
grab: z.string().nullable().default(null),
|
|
143
182
|
shot: z.object({ n: z.number().int().positive(), name: z.string() }).nullable().default(null),
|
|
144
183
|
marks: z.array(MarkSchema).max(4).default([]),
|
|
184
|
+
// §21.3: the format this note belongs to (a Format id such as "9x16"), or null for every format:
|
|
185
|
+
// the default, and every note from before formats. The server checks it against the note's version.
|
|
186
|
+
format: z.string().max(16).regex(FORMAT_ID_RE).nullable().default(null),
|
|
145
187
|
status: z.enum(["todo", "done"]).default("todo"),
|
|
146
188
|
reply: z.string().default(""),
|
|
147
189
|
fixT: seconds.nullable().default(null),
|
|
@@ -211,10 +253,114 @@ export const BatchesFileSchema = z.object({
|
|
|
211
253
|
rev: z.number().int().nonnegative(),
|
|
212
254
|
batches: z.array(BatchSchema).default([]),
|
|
213
255
|
});
|
|
256
|
+
// §20.6: the found files the user dismissed ("Not these"), as manifest paths. The candidates
|
|
257
|
+
// themselves live in the server's memory; only this list is kept. Created on its first write.
|
|
258
|
+
export const FoundFileSchema = z.object({
|
|
259
|
+
schema: z.literal(1),
|
|
260
|
+
rev: z.number().int().nonnegative(),
|
|
261
|
+
dismissed: z.array(z.string().max(1024)).max(10000).default([]),
|
|
262
|
+
// §20.7: the kinds an agent's `include` settled for a cut (the anchor: its video and version
|
|
263
|
+
// ids), so the scoring never also adds a file of that kind for that cut, on any later scan,
|
|
264
|
+
// start-up or restart. Files from before this field read as empty.
|
|
265
|
+
settled: z
|
|
266
|
+
.array(z.object({
|
|
267
|
+
video: z.string().max(200),
|
|
268
|
+
version: z.string().max(200),
|
|
269
|
+
kinds: z.array(z.enum(["voice", "music", "sfx", "cut", "other"])).max(5),
|
|
270
|
+
}))
|
|
271
|
+
.max(200)
|
|
272
|
+
.default([]),
|
|
273
|
+
});
|
|
274
|
+
// §22.3: the Change Log, .rushes/log.json, oldest first on disk. Written by the server as things
|
|
275
|
+
// happen, created on its first write. Every field is new, so nothing older reads differently.
|
|
276
|
+
export const LogEntrySchema = z.object({
|
|
277
|
+
id,
|
|
278
|
+
at: z.string(),
|
|
279
|
+
area: z.enum(LOG_AREAS),
|
|
280
|
+
kind: z.enum(LOG_KINDS),
|
|
281
|
+
text: z.string().min(1).max(LOG_TEXT_MAX),
|
|
282
|
+
video: z.string().nullable().default(null),
|
|
283
|
+
version: z.string().nullable().default(null),
|
|
284
|
+
ref: z.string().max(300).nullable().default(null),
|
|
285
|
+
by: z.enum(LOG_BY),
|
|
286
|
+
// R3: the tab a Notes line opens, how many events the line stands for, and what a run of them
|
|
287
|
+
// is about (a lane, a section, a film, a folder), so a burst collapses (§22.5).
|
|
288
|
+
tab: StageSchema.nullable().default(null),
|
|
289
|
+
n: z.number().int().positive().default(1),
|
|
290
|
+
subject: z.string().max(200).default(""),
|
|
291
|
+
});
|
|
292
|
+
export const LogFileSchema = z.object({
|
|
293
|
+
schema: z.literal(1),
|
|
294
|
+
rev: z.number().int().nonnegative(),
|
|
295
|
+
// §22.6: set once the dated history has been read in, so it never happens twice.
|
|
296
|
+
backfilled: z.boolean().default(false),
|
|
297
|
+
// M2: when the server that first wrote a line into a log not yet backfilled started. The backfill
|
|
298
|
+
// stops there, since everything after it was logged live (a cut is dated just before its line).
|
|
299
|
+
began: z.string().optional(),
|
|
300
|
+
// R5: the variants and takes already there when the log began ("<lane>/<variant>", "<section>:<take>").
|
|
301
|
+
undated: z.array(z.string().max(300)).max(LOG_MAX).default([]),
|
|
302
|
+
// §22.9: how many lines the 5000 cap has dropped.
|
|
303
|
+
dropped: z.number().int().nonnegative().default(0),
|
|
304
|
+
entries: z.array(LogEntrySchema).max(LOG_MAX).default([]),
|
|
305
|
+
// Set by the tolerant read, never written: a newer Rushes wrote this log (its `schema` is above 1).
|
|
306
|
+
// Its lines can be read, but this Rushes never rewrites the file (final review I2).
|
|
307
|
+
newer: z.literal(true).optional(),
|
|
308
|
+
});
|
|
309
|
+
const isRecord = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
|
|
310
|
+
/**
|
|
311
|
+
* I3, in the spirit of R2: log.json is read tolerantly, so one bad line never loses the log. A line
|
|
312
|
+
* that fails the schema (a hand edit over 160 characters, a kind or an area from a newer Rushes) is
|
|
313
|
+
* left out and counted in `dropped`, as are lines past the newest LOG_MAX (two logs merged by git);
|
|
314
|
+
* undated refs that aren't refs are left out; an id seen twice gets "-2", "-3". The text of a line
|
|
315
|
+
* is read as one clean line (oneLineOf), so a hand edit can't carry a terminal escape, a bidi
|
|
316
|
+
* override or hidden tag characters to anything that prints it. A `rev` that isn't a count reads as
|
|
317
|
+
* 0. A `schema` above 1 is a newer Rushes' log: its lines are read, and `newer` is set so nothing
|
|
318
|
+
* writes the file back. The next write of an ordinary file keeps the cleaned lines. What isn't an
|
|
319
|
+
* object with a list of entries is still corrupt (R7). Writing is checked against LogFileSchema as
|
|
320
|
+
* strictly as ever.
|
|
321
|
+
*/
|
|
322
|
+
function tolerantLog(raw) {
|
|
323
|
+
if (!isRecord(raw) || !Array.isArray(raw.entries))
|
|
324
|
+
return raw;
|
|
325
|
+
const entries = [];
|
|
326
|
+
const ids = new Set();
|
|
327
|
+
let bad = 0;
|
|
328
|
+
for (const item of raw.entries) {
|
|
329
|
+
const line = LogEntrySchema.safeParse(isRecord(item) ? cleanLine(item) : item);
|
|
330
|
+
if (!line.success) {
|
|
331
|
+
bad += 1;
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
let id = line.data.id;
|
|
335
|
+
for (let k = 2; ids.has(id); k++)
|
|
336
|
+
id = `${line.data.id.slice(0, 58)}-${k}`;
|
|
337
|
+
ids.add(id);
|
|
338
|
+
entries.push({ ...line.data, id });
|
|
339
|
+
}
|
|
340
|
+
const over = Math.max(0, entries.length - LOG_MAX);
|
|
341
|
+
const dropped = typeof raw.dropped === "number" && Number.isInteger(raw.dropped) && raw.dropped >= 0 ? raw.dropped : 0;
|
|
342
|
+
const undated = Array.isArray(raw.undated) ? raw.undated.filter((r) => typeof r === "string" && r.length <= 300).slice(0, LOG_MAX) : raw.undated;
|
|
343
|
+
const rev = typeof raw.rev === "number" && Number.isInteger(raw.rev) && raw.rev >= 0 ? raw.rev : 0;
|
|
344
|
+
const newer = typeof raw.schema === "number" && Number.isInteger(raw.schema) && raw.schema > 1;
|
|
345
|
+
return { ...raw, schema: 1, rev, newer: newer ? true : undefined, undated, dropped: dropped + bad + over, entries: entries.slice(over) };
|
|
346
|
+
}
|
|
347
|
+
/** A stored line with its words made one clean line. What isn't text is left for the schema to refuse. */
|
|
348
|
+
function cleanLine(item) {
|
|
349
|
+
const out = { ...item };
|
|
350
|
+
if (typeof out.text === "string")
|
|
351
|
+
out.text = oneLineOf(out.text);
|
|
352
|
+
if (typeof out.subject === "string")
|
|
353
|
+
out.subject = oneLineOf(out.subject);
|
|
354
|
+
return out;
|
|
355
|
+
}
|
|
356
|
+
/** How log.json is read (see tolerantLog); the store writes it against LogFileSchema. */
|
|
357
|
+
export const LogFileReadSchema = z.preprocess(tolerantLog, LogFileSchema);
|
|
214
358
|
export const FILES = {
|
|
215
359
|
project: { name: "project.json", schema: ProjectSchema },
|
|
216
360
|
script: { name: "script.json", schema: ScriptSchema },
|
|
217
361
|
notes: { name: "notes.json", schema: NotesFileSchema },
|
|
218
362
|
picks: { name: "picks.json", schema: PicksSchema },
|
|
219
363
|
batches: { name: "batches.json", schema: BatchesFileSchema },
|
|
364
|
+
found: { name: "found.json", schema: FoundFileSchema },
|
|
365
|
+
log: { name: "log.json", schema: LogFileSchema, read: LogFileReadSchema },
|
|
220
366
|
};
|
package/dist/core/store.js
CHANGED
|
@@ -4,7 +4,7 @@ import { join } from "node:path";
|
|
|
4
4
|
import { FILES } from "./schema.js";
|
|
5
5
|
import { CorruptFileError, InvalidError, RevConflictError } from "./errors.js";
|
|
6
6
|
export const RUSHES_DIR = ".rushes";
|
|
7
|
-
const GITIGNORE = "proxies/\npeaks/\nserver.json\nserver.log\n*.tmp\n*.bak\n";
|
|
7
|
+
const GITIGNORE = "proxies/\npeaks/\nserver.json\nserver.log\nlog.json.bad*\n*.tmp\n*.bak\n";
|
|
8
8
|
function defaults(key, name) {
|
|
9
9
|
switch (key) {
|
|
10
10
|
case "project":
|
|
@@ -17,8 +17,17 @@ function defaults(key, name) {
|
|
|
17
17
|
return { schema: 1, rev: 0, lanes: {}, sections: {}, levels: {} };
|
|
18
18
|
case "batches":
|
|
19
19
|
return { schema: 1, rev: 0, batches: [] };
|
|
20
|
+
case "found":
|
|
21
|
+
return { schema: 1, rev: 0, dismissed: [], settled: [] };
|
|
22
|
+
case "log":
|
|
23
|
+
return { schema: 1, rev: 0, backfilled: false, undated: [], dropped: 0, entries: [] };
|
|
20
24
|
}
|
|
21
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Files `init` doesn't write (found.json, log.json). Each is created by its first write, and reads
|
|
28
|
+
* as its default until then, so a project made before the file existed needs nothing done to it.
|
|
29
|
+
*/
|
|
30
|
+
const CREATED_ON_WRITE = new Set(["found", "log"]);
|
|
22
31
|
/**
|
|
23
32
|
* The only writer of a project's .rushes folder. Every write is validated,
|
|
24
33
|
* serialised per file, written atomically (tmp + rename) and announced with
|
|
@@ -42,6 +51,8 @@ export class Store extends EventEmitter {
|
|
|
42
51
|
await mkdir(join(this.dir, "grabs"), { recursive: true });
|
|
43
52
|
await writeIfMissing(join(this.dir, ".gitignore"), GITIGNORE);
|
|
44
53
|
for (const key of Object.keys(FILES)) {
|
|
54
|
+
if (CREATED_ON_WRITE.has(key))
|
|
55
|
+
continue;
|
|
45
56
|
await writeIfMissing(this.path(key), serialise(defaults(key, name)));
|
|
46
57
|
}
|
|
47
58
|
}
|
|
@@ -52,8 +63,11 @@ export class Store extends EventEmitter {
|
|
|
52
63
|
raw = await readFile(this.path(key), "utf8");
|
|
53
64
|
}
|
|
54
65
|
catch (e) {
|
|
55
|
-
if (e.code === "ENOENT")
|
|
66
|
+
if (e.code === "ENOENT") {
|
|
67
|
+
if (CREATED_ON_WRITE.has(key))
|
|
68
|
+
return FILES[key].schema.parse(defaults(key, ""));
|
|
56
69
|
throw new CorruptFileError(file, "missing; run rushes init");
|
|
70
|
+
}
|
|
57
71
|
throw e;
|
|
58
72
|
}
|
|
59
73
|
let json;
|
|
@@ -63,7 +77,9 @@ export class Store extends EventEmitter {
|
|
|
63
77
|
catch (e) {
|
|
64
78
|
throw new CorruptFileError(file, `invalid JSON (${e.message})`);
|
|
65
79
|
}
|
|
66
|
-
|
|
80
|
+
// A file may be read more leniently than it's written (log.json, I3).
|
|
81
|
+
const def = FILES[key];
|
|
82
|
+
const parsed = ("read" in def ? def.read : def.schema).safeParse(json);
|
|
67
83
|
if (!parsed.success)
|
|
68
84
|
throw new CorruptFileError(file, parsed.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; "));
|
|
69
85
|
return parsed.data;
|
package/dist/mcp/client.js
CHANGED
|
@@ -21,7 +21,19 @@ export class RushesClient {
|
|
|
21
21
|
body: json === undefined ? undefined : JSON.stringify(json),
|
|
22
22
|
});
|
|
23
23
|
const text = await res.text();
|
|
24
|
-
|
|
24
|
+
let body = {};
|
|
25
|
+
try {
|
|
26
|
+
body = text ? JSON.parse(text) : {};
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// Not JSON: an older Rushes answering a route it doesn't have, or something else on the port.
|
|
30
|
+
throw new ApiError(res.status, {
|
|
31
|
+
error: "not_json",
|
|
32
|
+
message: res.status === 404
|
|
33
|
+
? "The Rushes server running for this project is older than this command and doesn't have that feature. Run `rushes stop`, then try again."
|
|
34
|
+
: `Rushes server returned ${res.status} with a body that isn't JSON`,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
25
37
|
if (!res.ok)
|
|
26
38
|
throw new ApiError(res.status, body);
|
|
27
39
|
return body;
|