rushes 0.2.2 → 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.
@@ -3,26 +3,28 @@ import { basename, extname, join } from "node:path";
3
3
  import { fromManifestPath } from "../core/paths.js";
4
4
  import { GRAB_PATH, SCREENSHOT_PATH, registeredMedia } from "./files.js";
5
5
  import { PROXY_PATH } from "./proxy.js";
6
+ import { chipOrder, labelOfId, versionFormats } from "../core/formats.js";
6
7
  /**
7
8
  * "hero-60s_v3_00m12.10s_f726.png": the time is frame/fps, rounded to hundredths before
8
9
  * splitting into minutes and seconds -- the same rule fmt() uses, so 59.999s carries into the
9
10
  * next minute rather than printing 00m60.00s.
10
11
  */
11
- export function screenshotName(video, version, frame, fps) {
12
+ export function screenshotName(video, version, frame, fps, format = null) {
12
13
  const t = frame / fps;
13
14
  const cs = Math.round(Math.max(0, t) * 100);
14
15
  const m = Math.floor(cs / 6000);
15
16
  const s = ((cs - m * 6000) / 100).toFixed(2).padStart(5, "0");
16
17
  const mm = String(m).padStart(2, "0");
17
- return `${video}_${version}_${mm}m${s}s_f${frame}.png`;
18
+ // §21.5: a grab of a cut with formats carries the ratio it shows ("hero_v1_9x16_00m01.00s_f30.png").
19
+ return `${video}_${version}${format ? `_${format}` : ""}_${mm}m${s}s_f${frame}.png`;
18
20
  }
19
21
  /** The fps to use for a grab or screenshot: the version's own, falling back to the project's. */
20
22
  export function fpsFor(project, video, version) {
21
23
  const v = project.videos.find((x) => x.id === video)?.versions.find((x) => x.id === version);
22
24
  return v?.fps ?? project.fps;
23
25
  }
24
- // Parses a name screenshotName() itself produced.
25
- const NEW_NAME = /^([a-z0-9][a-z0-9-]*)_(v\d+)_(\d{2})m(\d{2}\.\d{2})s_f(\d+)\.png$/;
26
+ // Parses a name screenshotName() itself produced, with or without a format's ratio (§21.5).
27
+ const NEW_NAME = /^([a-z0-9][a-z0-9-]*)_(v\d+)(?:_(\d+(?:\.\d+)?x\d+(?:\.\d+)?))?_(\d{2})m(\d{2}\.\d{2})s_f(\d+)\.png$/;
26
28
  // Parses a Plan 1-2 grab name: {video}_{version}_f{frame}.png.
27
29
  const OLD_NAME = /^([a-z0-9][a-z0-9-]*)_(v\d+)_f(\d+)\.png$/;
28
30
  async function statInfo(abs) {
@@ -68,8 +70,12 @@ async function scanScreenshotDir(store, names, manifestPrefix, safe, project) {
68
70
  if (newMatch) {
69
71
  asset.video = newMatch[1];
70
72
  asset.version = newMatch[2];
71
- asset.frame = Number(newMatch[5]);
73
+ asset.frame = Number(newMatch[6]);
72
74
  asset.t = asset.frame / fpsFor(project, asset.video, asset.version);
75
+ if (newMatch[3]) {
76
+ asset.format = newMatch[3];
77
+ asset.formatLabel = labelOfId(newMatch[3]);
78
+ }
73
79
  }
74
80
  else if (oldMatch) {
75
81
  asset.video = oldMatch[1];
@@ -183,7 +189,13 @@ function variantEntries(project, stage) {
183
189
  * in parallel within each group, so a large project doesn't pay for it one file at a time.
184
190
  */
185
191
  export async function listAssets(store, project, script) {
186
- const cutEntries = project.videos.flatMap((video) => [...video.versions].reverse().map((version) => ({ video: video.id, version: version.id, file: version.file })));
192
+ const cutEntries = project.videos.flatMap((video) => [...video.versions].reverse().flatMap((version) => {
193
+ const views = versionFormats(version);
194
+ const primary = views.find((f) => f.primary);
195
+ const own = { video: video.id, version: version.id, file: version.file, ...(version.formats.length > 0 && primary ? { formatLabel: primary.label } : {}) };
196
+ const subs = chipOrder(version.formats).map((f) => ({ video: video.id, version: version.id, file: f.file, format: f.id, formatLabel: labelOfId(f.id), width: f.width, height: f.height }));
197
+ return [own, ...subs];
198
+ }));
187
199
  const proxyEntries = project.videos.flatMap((video) =>
188
200
  // Only a file this server would have written into proxies/: a hand-edited record pointing
189
201
  // anywhere else (the original, say) is never offered for deletion as a proxy.
@@ -194,7 +206,7 @@ export async function listAssets(store, project, script) {
194
206
  const takeEntries = script.sections.flatMap((section) => section.takes.map((take, i) => ({ section: section.id, file: take.file, label: `Take ${i + 1}` })));
195
207
  const [[freshNames, oldNames], cuts, proxies, takes, voice, music, sfx] = await Promise.all([
196
208
  Promise.all([pngNames(store, SCREENSHOT_DIRS[0][0]), pngNames(store, SCREENSHOT_DIRS[1][0])]),
197
- Promise.all(cutEntries.map((e) => fileAsset(store, "cut", e.file, { video: e.video, version: e.version }))),
209
+ Promise.all(cutEntries.map((e) => fileAsset(store, "cut", e.file, { video: e.video, version: e.version, format: e.format, formatLabel: e.formatLabel, width: e.width, height: e.height }))),
198
210
  Promise.all(proxyEntries.map((e) => fileAsset(store, "proxy", e.proxy.file, { video: e.video, version: e.version, width: e.proxy.width, height: e.proxy.height }))),
199
211
  Promise.all(takeEntries.map((e) => fileAsset(store, "take", e.file, { section: e.section, label: e.label }))),
200
212
  Promise.all(variantEntries(project, "voice").map((e) => fileAsset(store, "voice", e.file, { lane: e.lane, laneName: e.laneName, variant: e.variant, label: e.label, meta: e.meta }))),
@@ -2,6 +2,7 @@ import { createReadStream } from "node:fs";
2
2
  import { lstat, realpath, stat } from "node:fs/promises";
3
3
  import { extname, isAbsolute, join, normalize, sep } from "node:path";
4
4
  import { Readable } from "node:stream";
5
+ import { VIDEO_EXT } from "../core/media.js";
5
6
  import { PROXY_PATH } from "./proxy.js";
6
7
  export const CONTENT_TYPES = {
7
8
  ".mp4": "video/mp4",
@@ -73,6 +74,9 @@ export function registeredMedia(project, script) {
73
74
  // server would write, so a hand-edited record can't open up any other file.
74
75
  if (ver.proxy && PROXY_PATH.test(ver.proxy.file))
75
76
  files.add(ver.proxy.file);
77
+ // §21: a cut's other formats play in Picture like the cut itself, under the same §15.5 rules.
78
+ for (const f of ver.formats)
79
+ files.add(f.file);
76
80
  }
77
81
  }
78
82
  for (const l of project.lanes)
@@ -117,6 +121,32 @@ export const OUTSIDE_MEDIA_EXT = new Set([
117
121
  "wav", "mp3", "m4a", "aac", "aif", "aiff", "flac", "ogg", "opus", "mp4", "mov", "m4v", "webm", "mkv",
118
122
  "png", "jpg", "jpeg", "gif", "webp", "pdf", "md", "txt", "srt", "vtt",
119
123
  ]);
124
+ /**
125
+ * Final review M2: a cut or a format whose real file lies outside the project is served only as
126
+ * video (the dashboard's VIDEO_EXT) or as the audio §15.5 already serves; never as text, an image
127
+ * or a PDF, which the library's other files may be. Inside the project nothing changes.
128
+ */
129
+ export const OUTSIDE_CUT_EXT = new Set([...VIDEO_EXT, "wav", "mp3", "m4a", "aac", "aif", "aiff", "flac", "ogg", "opus"]);
130
+ /** Every path registered as a cut or a cut's format, and as nothing else (a library file keeps its own rules). */
131
+ export function cutOnlyFiles(project, script) {
132
+ const other = new Set();
133
+ for (const l of project.lanes)
134
+ for (const variant of l.variants)
135
+ other.add(variant.file);
136
+ for (const s of script.sections)
137
+ for (const t of s.takes)
138
+ other.add(t.file);
139
+ for (const f of project.files)
140
+ other.add(f.file);
141
+ const cuts = new Set();
142
+ for (const v of project.videos) {
143
+ for (const ver of v.versions)
144
+ for (const file of [ver.file, ...ver.formats.map((f) => f.file)])
145
+ if (!other.has(file))
146
+ cuts.add(file);
147
+ }
148
+ return cuts;
149
+ }
120
150
  /**
121
151
  * The file /media sends for a path it has already accepted: its real path, every symlink
122
152
  * resolved. A real path inside the project is served whatever it is, as before. Policy (§15.5):
@@ -124,7 +154,7 @@ export const OUTSIDE_MEDIA_EXT = new Set([
124
154
  * (`OUTSIDE_MEDIA_EXT`), so a take swapped for a link to a key file is never served. Null means
125
155
  * refuse. A file that isn't there gives back the plain path, so the send reports it missing.
126
156
  */
127
- export async function servableFile(root, abs) {
157
+ export async function servableFile(root, abs, outsideExt = OUTSIDE_MEDIA_EXT) {
128
158
  let real;
129
159
  try {
130
160
  real = await realpath(abs);
@@ -142,7 +172,7 @@ export async function servableFile(root, abs) {
142
172
  if (real === realRoot || real.startsWith(realRoot.endsWith(sep) ? realRoot : realRoot + sep))
143
173
  return real;
144
174
  const ext = extname(real).toLowerCase().replace(/^\./, "");
145
- return OUTSIDE_MEDIA_EXT.has(ext) ? real : null;
175
+ return outsideExt.has(ext) ? real : null;
146
176
  }
147
177
  /** Parse a single "bytes=a-b" range against a file size. Returns null for a missing or unusable range. */
148
178
  export function parseRange(header, size) {
@@ -4,9 +4,11 @@ import { basename, extname, isAbsolute, join, resolve, sep } from "node:path";
4
4
  import { AUDIO_EXT, DEFAULT_LIMITS, SKIPPED_FOLDERS, VIDEO_EXT, commonWordsOf, kindOf, pickCurrentSet, scanFolder, scoreCandidate, wordsOf, } from "../core/found.js";
5
5
  import { InvalidError, RevConflictError, RushesError } from "../core/errors.js";
6
6
  import { slugify } from "../core/ids.js";
7
- import { probe as ffprobe } from "../core/media.js";
7
+ import { AUDIO_FORMATS, probe as ffprobe } from "../core/media.js";
8
8
  import { fromManifestPath, toManifestPath } from "../core/paths.js";
9
9
  import { addFile, addVariant, addVersion, resolveVideo } from "../core/project.js";
10
+ import { logBookFor } from "./logbook.js";
11
+ import { broughtInEvent, cutName } from "../core/logEvents.js";
10
12
  /** The audio kinds, which an include can settle. */
11
13
  const AUDIO_KINDS = new Set(["voice", "music", "sfx"]);
12
14
  /** The most cuts' settled kinds found.json keeps (the newest). */
@@ -203,7 +205,7 @@ const MAX_DISMISSED = 10000;
203
205
  /** How many probe results are remembered. */
204
206
  const DURATION_CACHE_LIMIT = 10000;
205
207
  /** The default probe: ffprobe's duration, or null without ffprobe. */
206
- export const ffprobeDuration = async (abs, signal) => (await ffprobe(abs, { signal })).duration;
208
+ export const ffprobeDuration = async (abs, signal) => (await ffprobe(abs, { signal, formats: AUDIO_FORMATS })).duration;
207
209
  /**
208
210
  * The scanner's `announce` for a server: a `change` event on the store, which the SSE route sends
209
211
  * to every open tab so it reads the state again. Its `file` is "found"; its `rev` counts the
@@ -215,12 +217,17 @@ export function foundAnnouncer(store) {
215
217
  store.emit("change", { file: "found", rev: ++seq });
216
218
  };
217
219
  }
218
- /** Every manifest path the project has registered: cuts, variants, library files and script takes. */
220
+ /** Every manifest path the project has registered: cuts and their formats, variants, library files and script takes. */
219
221
  export function registeredPaths(project, script) {
220
222
  const out = [];
221
- for (const v of project.videos)
222
- for (const ver of v.versions)
223
+ for (const v of project.videos) {
224
+ for (const ver of v.versions) {
223
225
  out.push(ver.file);
226
+ // §21: a cut's other formats are in the project too, so the scan never offers them as new cuts.
227
+ for (const f of ver.formats)
228
+ out.push(f.file);
229
+ }
230
+ }
224
231
  for (const l of project.lanes)
225
232
  for (const variant of l.variants)
226
233
  out.push(variant.file);
@@ -529,6 +536,8 @@ export class FoundScanner {
529
536
  return none();
530
537
  let picked;
531
538
  let byPath;
539
+ let anchor = null;
540
+ let films = 1;
532
541
  try {
533
542
  const ctx = await this.context();
534
543
  const unknown = await this.pendingLengths(ctx.project);
@@ -540,6 +549,8 @@ export class FoundScanner {
540
549
  const settled = await this.settledFor(ctx.project);
541
550
  picked = s.candidates.filter((f) => s.suggested.has(f.path) && !unknown.has(f.kind) && !skip.has(f.kind) && !settled.has(f.kind));
542
551
  byPath = s.byPath;
552
+ anchor = anchorCut(ctx.project, this.film);
553
+ films = ctx.project.videos.length;
543
554
  }
544
555
  catch {
545
556
  return none(); // project files unreadable right now: the watcher reports them
@@ -547,7 +558,13 @@ export class FoundScanner {
547
558
  if (picked.length === 0)
548
559
  return none();
549
560
  const reasons = new Map(picked.map((f) => [f.path, byPath.get(f.path)?.reasons ?? []]));
550
- return this.bringInNow(picked.map((f) => ({ path: f.path, kind: f.kind })), { reasons, film, origin: "auto" });
561
+ const result = await this.bringInNow(picked.map((f) => ({ path: f.path, kind: f.kind })), { reasons, film, origin: "auto" });
562
+ // §22.5: what the current set brought in is one line, by Rushes (R8, R9); its variants are dated (R5).
563
+ // Built inside add's guard, so a line that can't be made never undoes the bring-in (M1).
564
+ const cut = anchor;
565
+ if (result.added.length)
566
+ await logBookFor(this.store).add(() => broughtInEvent(result.added, cut ? cutName(films, cut.video, cut.version.id) : null), "rushes");
567
+ return result;
551
568
  });
552
569
  }
553
570
  /** The kinds an agent's include settled for the current anchor cut. */
@@ -0,0 +1,208 @@
1
+ // §22: the Change Log's keeper on the server. One per store, so every route, the found scanner and
2
+ // the state share its backfill and its cache. Every write goes through store.update, so writes
3
+ // serialise with each other (§22.9).
4
+ import { rename, stat } from "node:fs/promises";
5
+ import { basename } from "node:path";
6
+ import { CorruptFileError } from "../core/errors.js";
7
+ import { appendEvent, backfillLog, logView } from "../core/log.js";
8
+ import { LOG_MAX, logMarkdown } from "../core/logText.js";
9
+ /** R8: the dashboard sends its project id with every request (web/src/api.ts); MCP, the CLI and curl don't. */
10
+ export function byOf(projectHeader) {
11
+ return projectHeader ? "user" : "agent";
12
+ }
13
+ const books = new WeakMap();
14
+ /** The one LogBook for `store`, shared by the app's routes and the found scanner. */
15
+ export function logBookFor(store) {
16
+ let book = books.get(store);
17
+ if (!book) {
18
+ book = new LogBook(store);
19
+ books.set(store, book);
20
+ }
21
+ return book;
22
+ }
23
+ /**
24
+ * M2: where the backfill stops. A backfill that failed may have let live lines in first, and a
25
+ * restart starts later, so: only what's older than this server's start, than the start of the
26
+ * server that wrote the first of those lines (`began`), and than the oldest line in the file. The
27
+ * oldest line alone isn't enough: a cut is dated a moment before the line that logs it.
28
+ */
29
+ function backfillBefore(f, since) {
30
+ const began = f.began === undefined ? NaN : Date.parse(f.began);
31
+ let before = Number.isFinite(began) ? Math.min(since, began) : since;
32
+ for (const e of f.entries) {
33
+ const t = Date.parse(e.at);
34
+ if (t < before)
35
+ before = t;
36
+ }
37
+ return before;
38
+ }
39
+ /** Thrown inside an update to leave the file exactly as it was: nothing is written and rev stays. */
40
+ const UNCHANGED = Symbol("unchanged");
41
+ /** Thrown inside an append that finds the log no longer backfilled: it was deleted or replaced while this server ran. */
42
+ const STALE = Symbol("stale");
43
+ /** A log a newer Rushes wrote is read, never written: this Rushes would lose what it doesn't know (final review I2). */
44
+ function refuseNewer(f) {
45
+ if (f.newer)
46
+ throw new Error("a newer Rushes wrote this log, so this one leaves it alone");
47
+ }
48
+ export class LogBook {
49
+ store;
50
+ /** When this log began, for this server: the backfill reads in only what's older (R6). */
51
+ since = Date.now();
52
+ readying = null;
53
+ fixing = null;
54
+ cache = null;
55
+ /**
56
+ * M3: the log is known to be backfilled, so `ready` needn't read it first. This can't go stale
57
+ * unseen, because it's only a shortcut: every append checks the marker on the very copy it is
58
+ * rewriting, inside the store's one-at-a-time update (so for free), and every read checks it on
59
+ * what it read. A log deleted, reset or damaged by another process since is noticed at once,
60
+ * this flag drops, and the log is backfilled again or set aside before the line is written.
61
+ */
62
+ known = false;
63
+ /** Lines that couldn't be written since this server started; /api/health carries it for `rushes doctor` (ruling e). */
64
+ failures = 0;
65
+ constructor(store) {
66
+ this.store = store;
67
+ }
68
+ /** Backfills once (§22.6) and sets a corrupt file aside (R7). Never throws. Concurrent callers share one run. */
69
+ ready() {
70
+ this.readying ??= this.prepare()
71
+ .catch((e) => console.error(`Rushes: the Change Log isn't ready: ${e.message}`))
72
+ .finally(() => {
73
+ this.readying = null;
74
+ });
75
+ return this.readying;
76
+ }
77
+ async prepare() {
78
+ if (this.known)
79
+ return;
80
+ const file = await this.read(true);
81
+ // Ruling b: once backfilled, reading never writes. A newer Rushes' log is read as it is.
82
+ if (file.backfilled || file.newer) {
83
+ this.known = true;
84
+ return;
85
+ }
86
+ const [project, batches, script] = await Promise.all([this.store.read("project"), this.store.read("batches"), this.store.read("script")]);
87
+ // update runs one at a time per file, so a second LogBook racing this one finds the marker set
88
+ // and leaves the file untouched: the history is read in once and written once (Review Focus 1).
89
+ await this.store
90
+ .update("log", (f) => {
91
+ refuseNewer(f);
92
+ if (f.backfilled)
93
+ throw UNCHANGED;
94
+ backfillLog(f, { project, batches, script }, backfillBefore(f, this.since));
95
+ })
96
+ .catch((e) => {
97
+ if (e !== UNCHANGED)
98
+ throw e;
99
+ });
100
+ this.known = true;
101
+ }
102
+ /** The file, parsed once per change on disk. With `fix`, a corrupt one is set aside as log.json.bad and the log starts again (R7). */
103
+ async read(fix) {
104
+ const path = this.store.path("log");
105
+ const st = await stat(path).catch(() => null);
106
+ const key = st ? `${st.mtimeMs}:${st.ctimeMs}:${st.size}:${st.ino}` : "missing";
107
+ if (this.cache?.key === key)
108
+ return this.cache.file;
109
+ try {
110
+ const file = await this.store.read("log");
111
+ this.cache = { key, file };
112
+ return file;
113
+ }
114
+ catch (e) {
115
+ if (!fix || !(e instanceof CorruptFileError))
116
+ throw e;
117
+ // Requests that meet the same bad file at once share one fix, so it's set aside once.
118
+ this.fixing ??= this.setAside(path).finally(() => {
119
+ this.fixing = null;
120
+ });
121
+ return this.fixing;
122
+ }
123
+ }
124
+ async setAside(path) {
125
+ // Another server on the folder may have moved it already; then there's nothing to move. An
126
+ // earlier log.json.bad is kept: this one goes to .bad.2, .bad.3 and so on (final review I2).
127
+ let aside = `${path}.bad`;
128
+ for (let n = 2; await stat(aside).then(() => true, () => false); n++)
129
+ aside = `${path}.bad.${n}`;
130
+ await rename(path, aside).catch((e) => {
131
+ if (e.code !== "ENOENT")
132
+ throw e;
133
+ });
134
+ this.store.forget("log");
135
+ // It "reads as empty" (§22.9): a fresh log, marked as backfilled, so history isn't read in again.
136
+ const { data } = await this.store.update("log", (f) => {
137
+ f.backfilled = true;
138
+ });
139
+ console.error(`Rushes: ${path} couldn't be read, so it was set aside as ${basename(aside)} and the Change Log started again.`);
140
+ return data;
141
+ }
142
+ /**
143
+ * §22.5: writes one event. Routes pass a function that builds it, so a builder that throws is
144
+ * caught here too (M1). A failure is reported on the console, counted, and returns null: the
145
+ * change it describes has already been made.
146
+ */
147
+ async add(make, by, at = new Date()) {
148
+ try {
149
+ const event = typeof make === "function" ? make() : make;
150
+ await this.ready();
151
+ const write = () => this.store.update("log", (f) => {
152
+ refuseNewer(f);
153
+ if (!f.backfilled && this.known)
154
+ throw STALE;
155
+ // A line going into a log that isn't backfilled yet (its backfill failed): remember when
156
+ // this server started, so a later backfill never reads in what was logged live (M2).
157
+ if (!f.backfilled)
158
+ f.began ??= new Date(this.since).toISOString();
159
+ return appendEvent(f, event, by, at);
160
+ });
161
+ try {
162
+ return (await write()).result;
163
+ }
164
+ catch (e) {
165
+ // M3: the log was deleted, reset or damaged since it was last seen. Make it ready again
166
+ // (backfill it, or set it aside), then write the line once more.
167
+ if (e !== STALE && !(e instanceof CorruptFileError))
168
+ throw e;
169
+ this.known = false;
170
+ await this.ready();
171
+ return (await write()).result;
172
+ }
173
+ }
174
+ catch (e) {
175
+ this.failures += 1;
176
+ console.error(`Rushes: couldn't write to the Change Log: ${e.message}`);
177
+ return null;
178
+ }
179
+ }
180
+ /** §22.7: a page of the log, newest first. The first read backfills (R6). */
181
+ async view(q, ctx) {
182
+ await this.ready();
183
+ let file = await this.read(true);
184
+ if (!file.backfilled && this.known) {
185
+ // M3: deleted or reset since it was last seen: backfill it again before answering.
186
+ this.known = false;
187
+ await this.ready();
188
+ file = await this.read(true);
189
+ }
190
+ return logView(file, q, ctx);
191
+ }
192
+ /** The head for the header's dot. Read-only: it never backfills or fixes, and null means it couldn't be read. */
193
+ async head() {
194
+ try {
195
+ const f = await this.read(false);
196
+ const last = f.entries[f.entries.length - 1];
197
+ return { rev: f.rev, mark: last ? `${last.id}@${last.at}` : null, total: f.entries.length };
198
+ }
199
+ catch {
200
+ return null;
201
+ }
202
+ }
203
+ /** §22.7: the whole log as Markdown, what Export writes. */
204
+ async markdown(ctx, now) {
205
+ const v = await this.view({ limit: LOG_MAX }, ctx);
206
+ return logMarkdown({ project: ctx.project.name, entries: v.entries, undated: v.undated, dropped: v.dropped, now });
207
+ }
208
+ }
@@ -2,7 +2,7 @@ import { spawn } from "node:child_process";
2
2
  import { existsSync } from "node:fs";
3
3
  import { stat } from "node:fs/promises";
4
4
  import { RushesError } from "../core/errors.js";
5
- import { probe } from "../core/media.js";
5
+ import { AUDIO_FORMATS, probe } from "../core/media.js";
6
6
  import { fromManifestPath } from "../core/paths.js";
7
7
  /** Grace period between SIGTERM and SIGKILL when a run is aborted. */
8
8
  const KILL_GRACE_MS = 2_000;
@@ -112,8 +112,12 @@ export function mixInputs(project, picks, lanes, root) {
112
112
  }
113
113
  return out;
114
114
  }
115
+ /**
116
+ * Each input reads local files only, and only as an audio container (both are per-input options, so
117
+ * each `-i` gets its own): a playlist named .wav is refused, never mixed from the files it names.
118
+ */
115
119
  function inputArgs(inputs) {
116
- return inputs.flatMap((i) => ["-i", i.file]);
120
+ return inputs.flatMap((i) => ["-protocol_whitelist", "file", "-format_whitelist", AUDIO_FORMATS, "-i", i.file]);
117
121
  }
118
122
  function filterComplex(inputs) {
119
123
  // §19.6: each input's level is applied (volume=<db>dB) before the mix, right after its delay, so
@@ -172,7 +176,7 @@ async function runWithTimeout(run, args, timeoutMs) {
172
176
  clearTimeout(timer);
173
177
  }
174
178
  }
175
- const probeDuration = async (file) => (await probe(file)).duration;
179
+ const probeDuration = async (file) => (await probe(file, { formats: AUDIO_FORMATS })).duration;
176
180
  function voSpan(project, picks, root) {
177
181
  const voice = voiceSource(project, picks);
178
182
  if (voice.kind === "variant")
@@ -1,6 +1,7 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
2
  import { lstat, mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
+ import { AUDIO_FORMATS } from "../core/media.js";
4
5
  import { fromManifestPath } from "../core/paths.js";
5
6
  import { RUSHES_DIR } from "../core/store.js";
6
7
  import { defaultFfmpeg } from "./proxy.js";
@@ -40,9 +41,9 @@ export const PEAKS_FILE = /^[a-z0-9][a-z0-9-]*_v\d+_[0-9a-f]{16}\.json$/;
40
41
  /**
41
42
  * The containers a cut may be read as: the ordinary video and audio ones. Playlist and list
42
43
  * formats (HLS, concat, and the like) are left out, so a "cut" that is really a list can't make
43
- * ffmpeg open other files (fix round 3, M8).
44
+ * ffmpeg open other files (fix round 3, M8). One list with the probe's audio list (media.ts).
44
45
  */
45
- export const PEAKS_FORMATS = "mov,mp4,m4a,3gp,3g2,mj2,matroska,webm,avi,mpegts,mxf,wav,w64,aiff,mp3,aac,flac,ogg,caf,asf,mpeg,flv,dv";
46
+ export const PEAKS_FORMATS = AUDIO_FORMATS;
46
47
  /**
47
48
  * ffmpeg's arguments. Only local files (`file`, and `pipe` for stdout) in ordinary containers are
48
49
  * read. The first audio stream is decoded, if there is one (`-map 0:a:0?`; with none, ffmpeg says
@@ -3,7 +3,7 @@ import { randomUUID } from "node:crypto";
3
3
  import { access, constants, mkdir, readdir, rename, rm, stat } from "node:fs/promises";
4
4
  import { join } from "node:path";
5
5
  import { RushesError, NotFoundError } from "../core/errors.js";
6
- import { hasFfprobe, probe as ffprobe, proxyNeed } from "../core/media.js";
6
+ import { VIDEO_FORMATS, hasFfprobe, probe as ffprobe, proxyNeed } from "../core/media.js";
7
7
  import { fromManifestPath } from "../core/paths.js";
8
8
  /** Grace period between SIGTERM and SIGKILL when a job is cancelled. */
9
9
  export const KILL_GRACE_MS = 2_000;
@@ -87,7 +87,9 @@ export function hasFpsMode(v) {
87
87
  export function encodeArgs(orig, out, version = null) {
88
88
  const passthrough = hasFpsMode(version) ? ["-fps_mode", "passthrough"] : ["-vsync", "passthrough"];
89
89
  return [
90
- "-hide_banner", "-y", "-i", orig,
90
+ // Local files only, and only video containers (follow-up to final review I1): a cut that is
91
+ // really a playlist (ffconcat named .mp4) is refused, never encoded from the files it names.
92
+ "-hide_banner", "-y", "-protocol_whitelist", "file", "-format_whitelist", VIDEO_FORMATS, "-i", orig,
91
93
  "-vf", "scale='if(gt(iw,ih),min(1920,iw),-2)':'if(gt(iw,ih),-2,min(1920,ih))'",
92
94
  "-c:v", "libx264", "-preset", "veryfast", "-crf", "23", "-pix_fmt", "yuv420p", ...passthrough,
93
95
  "-c:a", "aac", "-b:a", "160k", "-movflags", "+faststart",
@@ -135,7 +137,8 @@ export class ProxyJobs {
135
137
  constructor(store, opts = {}) {
136
138
  this.store = store;
137
139
  this.run = opts.run ?? defaultFfmpeg;
138
- this.probeFile = opts.probe ?? ((abs, signal) => ffprobe(abs, { signal }));
140
+ // Everything this probes is a cut (or a proxy of one), so it is read only as a video container.
141
+ this.probeFile = opts.probe ?? ((abs, signal) => ffprobe(abs, { signal, formats: VIDEO_FORMATS }));
139
142
  this.needCacheLimit = opts.needCacheLimit ?? NEED_CACHE_LIMIT;
140
143
  const injected = opts.available;
141
144
  this.isAvailable = () => injected
@@ -236,7 +239,10 @@ export class ProxyJobs {
236
239
  c.abort();
237
240
  await Promise.all([...this.byId.keys()].map((id) => this.cancel(id).catch(() => undefined)));
238
241
  }
239
- /** Runs `work` with a signal close() aborts. Once closing, the signal starts aborted. */
242
+ /**
243
+ * Runs `work` with a signal close() aborts. Once closing, the signal starts aborted. The app
244
+ * reads formats' renders through this too (§21), so closing the server stops those reads.
245
+ */
240
246
  async tracked(work) {
241
247
  const c = new AbortController();
242
248
  if (this.closing)
@@ -545,6 +551,12 @@ export async function removePartials(root) {
545
551
  export function frameArgs(orig, seconds) {
546
552
  return [
547
553
  "-hide_banner", "-v", "error",
554
+ // Local files only, as for ffprobe: a container that names a URL is never followed. An input
555
+ // option, so the PNG still goes out through pipe:1.
556
+ "-protocol_whitelist", "file",
557
+ // Only video containers (final review I1): a cut or format that is really a playlist (ffconcat
558
+ // named .mp4) or a GIF is refused, never read through to the files it names.
559
+ "-format_whitelist", VIDEO_FORMATS,
548
560
  // -ss before -i seeks fast to the keyframe before, then accurate_seek decodes forward to the exact frame.
549
561
  "-accurate_seek", "-ss", seconds.toFixed(6), "-i", orig,
550
562
  "-frames:v", "1", "-an", "-pix_fmt", "rgb24", "-c:v", "png", "-f", "image2pipe", "pipe:1",
@@ -49,7 +49,7 @@ export async function startServer(rootDir, opts = {}) {
49
49
  const peakJobs = new PeakJobs(store, { available: () => proxyJobs.available(), ...opts.peaks });
50
50
  // §20: the project's other files. Its first scan starts once this server owns the project (below).
51
51
  const found = new FoundScanner({ store, probe: opts.found?.probe ?? ffprobeDuration, announce: foundAnnouncer(store), limits: opts.found?.limits });
52
- const appOpts = { webDir: opts.webDir, onShutdown: () => void close(), reveal: opts.reveal, proxyJobs, peakJobs, found };
52
+ const appOpts = { webDir: opts.webDir, onShutdown: () => void close(), reveal: opts.reveal, proxyJobs, peakJobs, found, formatProbe: opts.formats?.probe };
53
53
  const app = createApp(store, appOpts);
54
54
  const listener = getRequestListener(app.fetch);
55
55
  let lastRequest = Date.now();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rushes",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "A local review desk for video made with AI agents: timecoded notes, script edits and audio picks your agent can read and act on.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -10,17 +10,20 @@ Rushes shows your work to the user stage by stage (script, picture, voiceover, m
10
10
  If the user pastes a prompt copied from a locked tab, act on it directly — it already names the project, the film and the tool to use.
11
11
 
12
12
  1. Register what you made:
13
- - `rushes_add_version` for a render. If the cut is likely to play badly in a browser, the reply carries `proxySuggested: true` and `proxyReason`; Picture offers the user a proxy. Prefer H.264 MP4 to avoid this;
13
+ - `rushes_add_version` for a render. Give every cut a short `label` (48 characters at most) saying what changed, and put the detail in `note`. If the cut is likely to play badly in a browser, the reply carries `proxySuggested: true` and `proxyReason`; Picture offers the user a proxy. Prefer H.264 MP4 to avoid this;
14
+ - `rushes_add_format` for each other shape of a cut (a 9:16, 1:1 or 4:5 of the same edit): register every shape you rendered, main one first, or pass `formats: [{ file }]` to `rushes_add_version`. Its `label` is only a ratio hint such as 2.39:1, never the cut's short label;
14
15
  - `rushes_set_script` for the VO script. It merges by `id`, so send only the sections you changed; sections you leave out are kept. `rushes_get_script` reads the whole script;
15
16
  - `rushes_add_variant` for each voice read, music bed or SFX pass. Voice reads carry `stage: "voice"` and a `round` (its name — reads in one round are compared side by side; a new direction gets a new round); say what the read is, or what changed, in `description`. Music and SFX carry `meta.description` for their lane card;
16
17
  - `rushes_set_shots` for the storyboard's shots, once you have the first cut; send new timings when a later cut moves them.
17
18
  2. Call `rushes_open` and tell the user it's ready, with what it brought in and what it left (below). Each project's dashboard lives at its own address, `/p/<id>/`.
18
- 3. When the user sends a batch, call `rushes_get_batch` and fix every note in it. A note carries the `shot` it falls in; on an audio stage, call `rushes_get_picks` first — on Mix it also returns `levels` (dB per lane), which you read, not set. Its `on` says what it's about: `"<lane>/<variant>"` for a bed, pass or voice read (on Voiceover the lane names the round), `"<lane>/<variant>:<cue>"` for an SFX cue, `"vo"` for the Mix VO lane, or `null` for the whole mix; older notes may carry a section id or `"<section>:<take>"`. On Music, Sound effects and Mix treat `marks` (e.g. "Fall", "Quieter 3 dB") as part of the note; Voiceover notes carry none — they're Whole (`Speaker`, `Pacing`, `Tone`, `Overall`) or Point (`Fix this`, `Keep this`) instead. Picks are set from the dashboard only — no tool or CLI command sets one.
19
+ 3. When the user sends a batch, call `rushes_get_batch` and fix every note in it. A note carries the `shot` it falls in; on an audio stage, call `rushes_get_picks` first — on Mix it also returns `levels` (dB per lane), which you read, not set. Its `on` says what it's about: `"<lane>/<variant>"` for a bed, pass or voice read (on Voiceover the lane names the round), `"<lane>/<variant>:<cue>"` for an SFX cue, `"vo"` for the Mix VO lane, or `null` for the whole mix; older notes may carry a section id or `"<section>:<take>"`. On Music, Sound effects and Mix treat `marks` (e.g. "Fall", "Quieter 3 dB") as part of the note; Voiceover notes carry none — they're Whole (`Speaker`, `Pacing`, `Tone`, `Overall`) or Point (`Fix this`, `Keep this`) instead. A Picture note's `format` is null for every format, or a format id such as `"9x16"`: when it isn't null, fix only that format. Picks are set from the dashboard only — no tool or CLI command sets one.
19
20
  4. Register the new cut with `rushes_add_version`. On a locked video the reply carries a `warning`.
20
21
  5. Reply to all the notes in one `rushes_reply` call. For each note set `status: "done"`, a one-line `reply`, `fixT` (when the fix is visible in the new cut, in seconds) and `fixVersion`.
21
22
  6. For script batches: when a section's `proposed` differs from `current`, adopt it with `rushes_set_script`, sending just that section with its `id`. If voiceover already exists, re-record the picked voice with the corrected script and register it with `rushes_add_variant` as a new read in a new round.
22
23
  7. Lock picture with `rushes_lock_picture` only when the user says picture is locked; `version: null` unlocks it.
23
24
 
25
+ At the start of a session, call `rushes_get_log` to catch up (newest first; `limit`, `area`, `since`). When you change direction or make a decision, add one line per decision with `rushes_log`, not a running commentary, and never copy a note's or reply's text into it; Rushes logs cuts, formats, reads, beds, passes, takes, the script, picks, picture lock and unlock, notes sent, replies, files added and bring-ins itself. CLI: `rushes log`, `rushes log add`.
26
+
24
27
  Save renders, voice reads, beds and passes under the project's `renders/`, `audio/voiceover/`, `audio/music/` and `audio/sfx/` folders. Screenshots the user grabs with G or the camera button land in `screenshots/`. Use `rushes_list_assets` (optional `kind`) to find a file the user refers to but hasn't given you a path for, such as "use the screenshot I just took".
25
28
 
26
29
  The **Assets** tab is a library: Screenshots, Cuts, Voiceover, Music, Sound effects, Scripts & docs, Images, Captions, Exports, Delivery, Edit files and Proxies. Top-level `.md`, `.txt`, `.pdf`, `.srt` and `.vtt` files, and anything in `exports/`, are found automatically. Register everything else with `rushes_add_file` (`kind`, `file`, optional `name`, `note`, `video`): deliverables and platform exports as `delivery`, NLE project files as `edit`, storyboards/references/logos as `image`, briefs as `doc`. When the user wants to share notes, call `rushes_export_notes` — it writes a dated Markdown file to `exports/` and returns the path.
@@ -29,4 +32,4 @@ When asked to open or review work in Rushes, call `rushes_open`, then tell the u
29
32
 
30
33
  No project to show yet? Run `npx -y rushes demo <folder> --no-browser`, then `rushes_open` with `project: "<folder>"`. The demo builds a complete working example on the user's machine, with a cut, script, voice reads, music and notes already in place. Always pass `--no-browser`: without it the command stays running as the server and never returns.
31
34
 
32
- Rushes has nineteen tools: `rushes_open`, `rushes_status`, `rushes_add_version`, `rushes_add_variant`, `rushes_set_script`, `rushes_get_script`, `rushes_add_take`, `rushes_list_notes`, `rushes_list_assets`, `rushes_get_batch`, `rushes_reply`, `rushes_get_picks`, `rushes_set_shots`, `rushes_lock_picture`, `rushes_add_file`, `rushes_export_notes`, `rushes_scan`, `rushes_bring_in` and `rushes_doctor` (environment and project health check) — `rushes_add_take` stays only for compatibility and isn't used for voiceover. The full contract is in `AGENTS.md` at the package root.
35
+ Rushes has twenty-two tools: `rushes_open`, `rushes_status`, `rushes_add_version`, `rushes_add_format`, `rushes_add_variant`, `rushes_set_script`, `rushes_get_script`, `rushes_add_take`, `rushes_list_notes`, `rushes_list_assets`, `rushes_get_batch`, `rushes_reply`, `rushes_get_picks`, `rushes_set_shots`, `rushes_lock_picture`, `rushes_add_file`, `rushes_export_notes`, `rushes_log`, `rushes_get_log`, `rushes_scan`, `rushes_bring_in` and `rushes_doctor` (environment and project health check) — `rushes_add_take` stays only for compatibility and isn't used for voiceover. The full contract is in `AGENTS.md` at the package root.