rushes 0.2.2 → 0.4.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 +21 -7
- package/README.md +46 -4
- package/dist/cli/doctor.js +35 -10
- package/dist/cli/main.js +100 -10
- package/dist/core/batches.js +35 -3
- package/dist/core/cues.js +39 -0
- package/dist/core/exportNotes.js +9 -5
- package/dist/core/formats.js +159 -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 +118 -14
- package/dist/core/notes.js +35 -4
- package/dist/core/project.js +78 -5
- package/dist/core/schema.js +136 -2
- package/dist/core/store.js +9 -5
- package/dist/mcp/tools.js +120 -7
- package/dist/server/app.js +376 -36
- package/dist/server/assets.js +25 -12
- package/dist/server/files.js +36 -2
- package/dist/server/found.js +27 -6
- 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 +1 -1
- package/package.json +1 -1
- package/skills/rushes/SKILL.md +7 -4
- package/web-dist/assets/index-BFr1m3wH.css +1 -0
- package/web-dist/assets/index-BZnZV0XS.js +3 -0
- package/web-dist/index.html +2 -2
- package/web-dist/assets/index-DpiDziCn.js +0 -3
- package/web-dist/assets/index-DqCXH_lZ.css +0 -1
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// §22.5: the words for each thing Rushes logs, one builder per event. Built from short labels and
|
|
2
|
+
// names, never from a note's or a reply's text. R9 fixes the wording.
|
|
3
|
+
import { clip, oneLineOf, shortLabel } from "./labels.js";
|
|
4
|
+
import { PICKS_MERGE_MS } from "./logText.js";
|
|
5
|
+
/** The tabs' own names, as the dashboard shows them. */
|
|
6
|
+
export const TAB_NAMES = { script: "Script", picture: "Picture", voice: "Voiceover", music: "Music", sfx: "Sound effects", mix: "Mix" };
|
|
7
|
+
/** How a lane's stage starts a line. It's also its default lane's name (project.ts LANE_NAMES), which "to <lane>" leaves out. */
|
|
8
|
+
export const STAGE_WORDS = { voice: "Voiceover", music: "Music", sfx: "Sound effects" };
|
|
9
|
+
/** §16.1's Assets folders, by the kind of file they hold (web/src/lib.ts FOLDERS; test/core/log.test.ts keeps them equal). */
|
|
10
|
+
export const FILE_FOLDERS = { doc: "Scripts & docs", image: "Images", caption: "Captions", export: "Exports", delivery: "Delivery", edit: "Edit files" };
|
|
11
|
+
const PICK_WORDS = { voice: "voice", music: "music", sfx: "sound effects" };
|
|
12
|
+
const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
13
|
+
// Minor 2: a name is cut to fit, so a long one can't push out what the line is about (its lane,
|
|
14
|
+
// its folder, the closing quote). A name: a variant or a pick in quotes. A place: a lane or a film.
|
|
15
|
+
const NAME_MAX = 48;
|
|
16
|
+
const PLACE_MAX = 40;
|
|
17
|
+
/** `s` on one line, cut to `max`; "" when nothing in it shows (minor 3). */
|
|
18
|
+
function named(s, max) {
|
|
19
|
+
const n = clip(oneLineOf(s), max);
|
|
20
|
+
return n === "…" ? "" : n;
|
|
21
|
+
}
|
|
22
|
+
/** `“Night drive”`, or `fallback` for a name that shows nothing. */
|
|
23
|
+
const quoted = (s, fallback) => {
|
|
24
|
+
const n = named(s, NAME_MAX);
|
|
25
|
+
return n ? `“${n}”` : fallback;
|
|
26
|
+
};
|
|
27
|
+
/** "v6" on a one-film project; "Teaser v2" when there are more (R9). */
|
|
28
|
+
export function cutName(films, video, versionId) {
|
|
29
|
+
const film = named(video.name, PLACE_MAX);
|
|
30
|
+
return films > 1 && film ? `${film} ${versionId}` : versionId;
|
|
31
|
+
}
|
|
32
|
+
/** "9:16", "9:16 and 1:1", "9:16, 1:1 and 4:5". */
|
|
33
|
+
function andList(items) {
|
|
34
|
+
return items.length <= 1 ? (items[0] ?? "") : `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`;
|
|
35
|
+
}
|
|
36
|
+
/** A format's ratio label as stored ("9:16", "2.39:1"): never a free text, so nothing else gets in. */
|
|
37
|
+
const RATIO_LABEL = /^\d+(\.\d+)?:\d+(\.\d+)?$/;
|
|
38
|
+
const ratioLabels = (labels = []) => labels.map((l) => oneLineOf(l)).filter((l) => RATIO_LABEL.test(l));
|
|
39
|
+
/**
|
|
40
|
+
* "v6 added: launch 1.45x slower". A cut registered with its other shapes in the same call
|
|
41
|
+
* (§21.4 `formats`) is still one line, one write: "v6 and its 9:16 and 1:1 added: launch 1.45x slower".
|
|
42
|
+
*/
|
|
43
|
+
export function cutEvent(films, video, version, formatLabels) {
|
|
44
|
+
const name = cutName(films, video, version.id);
|
|
45
|
+
const label = shortLabel(version);
|
|
46
|
+
const shapes = ratioLabels(formatLabels);
|
|
47
|
+
return {
|
|
48
|
+
area: "picture", kind: "cut", merge: "count", subject: video.id,
|
|
49
|
+
text: shapes.length ? `${name} and its ${andList(shapes)} added: ${label}` : `${name} added: ${label}`,
|
|
50
|
+
video: video.id, version: version.id,
|
|
51
|
+
many: (n, subject) => {
|
|
52
|
+
const film = named(video.name, PLACE_MAX);
|
|
53
|
+
return `${n} cuts added${films > 1 && subject && film ? ` to ${film}` : ""}, the latest ${name}: ${label}`;
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* §22.5: "9:16 added to v2" (POST /api/formats). Named as cuts are ("Teaser v2" when there are more
|
|
59
|
+
* films); only the ratio and the cut, never a note. Formats added to one cut in a burst are one line
|
|
60
|
+
* that names each ("9:16, 1:1 and 4:5 added to v2"); to several cuts, "3 formats added". A retried
|
|
61
|
+
* request (the same format of the same cut) is absorbed.
|
|
62
|
+
*/
|
|
63
|
+
export function formatEvent(films, video, versionId, format) {
|
|
64
|
+
const name = cutName(films, video, versionId);
|
|
65
|
+
const label = ratioLabels([format.label])[0] ?? "A format";
|
|
66
|
+
const tail = ` added to ${name}`;
|
|
67
|
+
return {
|
|
68
|
+
area: "picture", kind: "format", merge: "count", subject: `${video.id}/${versionId}`,
|
|
69
|
+
text: `${label}${tail}`,
|
|
70
|
+
video: video.id, version: versionId, ref: format.id,
|
|
71
|
+
many: (n, subject, before) => {
|
|
72
|
+
if (!subject)
|
|
73
|
+
return `${n} formats added`;
|
|
74
|
+
// The line so far names the ratios already in it; add this one when every name still reads as a ratio.
|
|
75
|
+
const head = before?.endsWith(tail) ? before.slice(0, -tail.length) : "";
|
|
76
|
+
const names = head.split(/, | and /);
|
|
77
|
+
if (head && names.every((x) => RATIO_LABEL.test(x)) && names.length + 1 === n && !names.includes(label))
|
|
78
|
+
return `${andList([...names, label])}${tail}`;
|
|
79
|
+
return `${n} formats added to ${name}`;
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** `Music: “Night drive, driving drop” added to night-drive`; a voice read is a "read". */
|
|
84
|
+
export function variantEvent(lane, variant) {
|
|
85
|
+
const word = STAGE_WORDS[lane.stage];
|
|
86
|
+
const [one, many] = lane.stage === "voice" ? ["read", "reads"] : ["variant", "variants"];
|
|
87
|
+
const to = (name) => {
|
|
88
|
+
const place = named(name, PLACE_MAX);
|
|
89
|
+
return place && place !== word ? ` to ${place}` : "";
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
area: lane.stage, kind: "variant", merge: "count", subject: lane.name,
|
|
93
|
+
text: `${word}: ${quoted(variant.name, `a ${one}`)} added${to(lane.name)}`,
|
|
94
|
+
ref: `${lane.id}/${variant.id}`,
|
|
95
|
+
many: (n, subject) => `${word}: ${plural(n, one, many)} added${to(subject)}`,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/** `Voiceover: take 2 added to S1 “Every launch starts with a…”`. */
|
|
99
|
+
export function takeEvent(section, take, number) {
|
|
100
|
+
const where = section.id.toUpperCase();
|
|
101
|
+
const line = oneLineOf(section.current);
|
|
102
|
+
return {
|
|
103
|
+
area: "voice", kind: "take", merge: "count", subject: where,
|
|
104
|
+
text: `Voiceover: take ${number} added to ${where}${line ? ` ${quoted(clip(line, 32), "")}` : ""}`,
|
|
105
|
+
ref: `${section.id}:${take.id}`,
|
|
106
|
+
many: (n, subject) => `Voiceover: ${plural(n, "take", "takes")} added${subject ? ` to ${subject}` : ""}`,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/** "Script set: 6 sections". */
|
|
110
|
+
export function scriptEvent(sections) {
|
|
111
|
+
return { area: "script", kind: "script", merge: "replace", text: `Script set: ${plural(sections, "section", "sections")}` };
|
|
112
|
+
}
|
|
113
|
+
/** `Picks: voice “Vo Jules, full read”, music “Night drive, held back”`, the whole set after the change. */
|
|
114
|
+
export function picksEvent(project, lanes) {
|
|
115
|
+
const parts = [];
|
|
116
|
+
for (const lane of project.lanes) {
|
|
117
|
+
const v = lane.variants.find((x) => x.id === lanes[lane.id]);
|
|
118
|
+
if (v)
|
|
119
|
+
parts.push(`${PICK_WORDS[lane.stage]} ${quoted(v.name, lane.stage === "voice" ? "a read" : "a variant")}`);
|
|
120
|
+
}
|
|
121
|
+
return { area: "mix", kind: "picks", merge: "replace", windowMs: PICKS_MERGE_MS, text: parts.length ? `Picks: ${parts.join(", ")}` : "Picks cleared" };
|
|
122
|
+
}
|
|
123
|
+
/** "Picture locked at v6", "Picture unlocked". */
|
|
124
|
+
export function lockEvent(films, video) {
|
|
125
|
+
const film = named(video.name, PLACE_MAX);
|
|
126
|
+
const text = video.lockedVersion ? `Picture locked at ${cutName(films, video, video.lockedVersion)}` : `Picture unlocked${films > 1 && film ? ` for ${film}` : ""}`;
|
|
127
|
+
return { area: "picture", kind: "lock", merge: "replace", subject: video.id, text, video: video.id, version: video.lockedVersion };
|
|
128
|
+
}
|
|
129
|
+
/** "3 notes sent from Picture"; on Script, "1 note and 2 script edits sent from Script". */
|
|
130
|
+
export function notesSentEvent(batch) {
|
|
131
|
+
const tab = TAB_NAMES[batch.stage];
|
|
132
|
+
const notes = batch.noteIds.length;
|
|
133
|
+
const edits = batch.sectionIds.length;
|
|
134
|
+
const what = notes && edits
|
|
135
|
+
? `${plural(notes, "note", "notes")} and ${plural(edits, "script edit", "script edits")}`
|
|
136
|
+
: edits ? plural(edits, "script edit", "script edits") : plural(notes, "note", "notes");
|
|
137
|
+
return {
|
|
138
|
+
area: "notes", kind: "notes-sent", merge: "count", count: Math.max(1, notes + edits), subject: tab, tab: batch.stage,
|
|
139
|
+
text: `${what} sent from ${tab}`,
|
|
140
|
+
many: (n, subject) => `${plural(n, "note", "notes")} sent from ${subject || "several tabs"}`,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* What identifies a reply, so a retried request isn't counted twice while a different one is: its
|
|
145
|
+
* note ids, in order. A very long set is cut to a fingerprint, so the line's `ref` (300 characters)
|
|
146
|
+
* always holds it.
|
|
147
|
+
*/
|
|
148
|
+
function replyKey(ids) {
|
|
149
|
+
const key = [...ids].sort().join(",");
|
|
150
|
+
if (key.length <= 200)
|
|
151
|
+
return `notes:${key}`;
|
|
152
|
+
let h = 0x811c9dc5;
|
|
153
|
+
for (let i = 0; i < key.length; i++)
|
|
154
|
+
h = Math.imul(h ^ key.charCodeAt(i), 0x01000193) >>> 0;
|
|
155
|
+
return `notes:${ids.length}:${h.toString(36)}:${key.length}`;
|
|
156
|
+
}
|
|
157
|
+
const doneIn = (text) => Number(/\((\d+) done\)/.exec(text)?.[1] ?? 0);
|
|
158
|
+
/** "Agent replied to 3 notes (2 done)"; replies in a burst are one line that counts every note (R4, final review I1). */
|
|
159
|
+
export function repliesEvent(notes) {
|
|
160
|
+
const said = (n, done) => `Agent replied to ${plural(n, "note", "notes")}${done ? ` (${done} done)` : ""}`;
|
|
161
|
+
const done = notes.filter((n) => n.status === "done").length;
|
|
162
|
+
const stages = new Set(notes.map((n) => n.stage));
|
|
163
|
+
return {
|
|
164
|
+
area: "notes", kind: "replies", merge: "count", count: Math.max(1, notes.length), tab: stages.size === 1 ? [...stages][0] : null,
|
|
165
|
+
ref: replyKey(notes.map((n) => n.id)),
|
|
166
|
+
text: said(notes.length, done),
|
|
167
|
+
// The line says how many were done as it stood, so this call's are added to that.
|
|
168
|
+
many: (n, _subject, before = "") => said(n, doneIn(before) + done),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/** "File added: Creative brief (Scripts & docs)"; merged, "2 files added: Scripts & docs". */
|
|
172
|
+
export function fileEvent(entry) {
|
|
173
|
+
const folder = FILE_FOLDERS[entry.kind];
|
|
174
|
+
const name = named(entry.name, 60);
|
|
175
|
+
return {
|
|
176
|
+
area: "assets", kind: "files", merge: "count", subject: folder,
|
|
177
|
+
text: name ? `File added: ${name} (${folder})` : `A file added: ${folder}`,
|
|
178
|
+
many: (n, subject) => `${plural(n, "file", "files")} added${subject ? `: ${subject}` : ""}`,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/** "Brought in 3 files with v6" (R9). Its variants leave Before the log (R5). */
|
|
182
|
+
export function broughtInEvent(added, cut) {
|
|
183
|
+
return {
|
|
184
|
+
area: "assets", kind: "files", merge: "count", count: Math.max(1, added.length), subject: cut ?? "",
|
|
185
|
+
text: `Brought in ${plural(added.length, "file", "files")}${cut ? ` with ${cut}` : ""}`,
|
|
186
|
+
clears: added.filter((a) => a.lane && a.variant).map((a) => `${a.lane}/${a.variant}`),
|
|
187
|
+
many: (n, subject) => `Brought in ${plural(n, "file", "files")}${subject ? ` with ${subject}` : ""}`,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/** A line somebody wrote (§22.7): never merged, except that an identical repeat isn't doubled. */
|
|
191
|
+
export function lineEvent(text, area, link = {}) {
|
|
192
|
+
return { area, kind: "entry", merge: "once", text, ...link };
|
|
193
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// §22: the Change Log's shared words and dates, for the server, the CLI and the dashboard alike.
|
|
2
|
+
// Pure; its only import is labels.ts, which has none, because the dashboard bundles this file
|
|
3
|
+
// (test/core/logText.test.ts checks it).
|
|
4
|
+
import { oneLine, oneLineOf } from "./labels.js";
|
|
5
|
+
export const LOG_AREAS = ["script", "picture", "voice", "music", "sfx", "mix", "notes", "assets", "project"];
|
|
6
|
+
export const LOG_KINDS = ["cut", "variant", "take", "script", "picks", "notes-sent", "replies", "lock", "files", "entry", "format"];
|
|
7
|
+
export const LOG_BY = ["user", "agent", "rushes"];
|
|
8
|
+
/** The most lines log.json keeps; past it the oldest go (§22.3). */
|
|
9
|
+
export const LOG_MAX = 5000;
|
|
10
|
+
/** A line is at most this long (§22.3). */
|
|
11
|
+
export const LOG_TEXT_MAX = 160;
|
|
12
|
+
/** §22.5: a line of the same kind and area by the same writer within this long merges (R4). */
|
|
13
|
+
export const MERGE_MS = 2 * 60_000;
|
|
14
|
+
/** §22.5: consecutive pick changes within this long are one line. */
|
|
15
|
+
export const PICKS_MERGE_MS = 10 * 60_000;
|
|
16
|
+
/** The words for an area: the filter chips, the row tags, the Markdown and the CLI (the mockup's labels). */
|
|
17
|
+
export const AREA_LABELS = {
|
|
18
|
+
script: "Script", picture: "Picture", voice: "Voice", music: "Music", sfx: "Sound effects", mix: "Mix", notes: "Notes", assets: "Files", project: "Project",
|
|
19
|
+
};
|
|
20
|
+
/** Who wrote a line, in the Markdown and the CLI. */
|
|
21
|
+
export const BY_WORDS = { user: "you", agent: "agent", rushes: "Rushes" };
|
|
22
|
+
/** An area's words; one a newer Rushes wrote and this build doesn't know prints as it came. */
|
|
23
|
+
export function areaWord(area) {
|
|
24
|
+
return AREA_LABELS[area] ?? oneLineOf(area);
|
|
25
|
+
}
|
|
26
|
+
/** A writer's words, with the same fallback. */
|
|
27
|
+
export function byWord(by) {
|
|
28
|
+
return BY_WORDS[by] ?? oneLineOf(by);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A line of text as the log keeps it: one line (labels.ts's oneLineOf), 160 code points at most,
|
|
32
|
+
* never cut inside an emoji. Empty only when nothing in `text` is visible; the log refuses that.
|
|
33
|
+
*/
|
|
34
|
+
export function logText(text) {
|
|
35
|
+
return oneLine(text, LOG_TEXT_MAX);
|
|
36
|
+
}
|
|
37
|
+
const DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
38
|
+
const MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
39
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
40
|
+
const valid = (d) => Number.isFinite(d.getTime());
|
|
41
|
+
/**
|
|
42
|
+
* How many calendar days, in local time, from the day of `iso` to the day of `now`: 0 is today, 1 is
|
|
43
|
+
* yesterday, negative is a clock ahead; null when `iso` isn't a date. A day with a clock change (23 or
|
|
44
|
+
* 25 hours) still counts as one. The version list (web/src/versions.ts) and the log's day headings both use it.
|
|
45
|
+
*/
|
|
46
|
+
export function dayDiff(iso, now) {
|
|
47
|
+
const t = Date.parse(iso);
|
|
48
|
+
if (!Number.isFinite(t))
|
|
49
|
+
return null;
|
|
50
|
+
const d = new Date(t);
|
|
51
|
+
const day = (x) => Date.UTC(x.getFullYear(), x.getMonth(), x.getDate()) / 86_400_000;
|
|
52
|
+
return day(now) - day(d);
|
|
53
|
+
}
|
|
54
|
+
/** "14:32", local time; "--:--" for a date that doesn't parse (a hand-edited line). */
|
|
55
|
+
export function clock(d) {
|
|
56
|
+
return valid(d) ? `${pad(d.getHours())}:${pad(d.getMinutes())}` : "--:--";
|
|
57
|
+
}
|
|
58
|
+
/** "2026-10-07", the local date. */
|
|
59
|
+
export function localDate(d) {
|
|
60
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
|
61
|
+
}
|
|
62
|
+
/** "2026-10-07 14:32", local; "date unknown" for a date that doesn't parse. */
|
|
63
|
+
export function localStamp(d) {
|
|
64
|
+
return valid(d) ? `${localDate(d)} ${clock(d)}` : "date unknown";
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A day's heading (§22.8). In the drawer: "Today", "Yesterday", then "Mon 5 Oct" (with the year
|
|
68
|
+
* when it isn't this one). In a file, where "today" goes stale: "Wednesday 7 October 2026".
|
|
69
|
+
*/
|
|
70
|
+
export function dayHeading(d, now, relative) {
|
|
71
|
+
if (!valid(d))
|
|
72
|
+
return "Date unknown";
|
|
73
|
+
if (!relative)
|
|
74
|
+
return `${DAYS[d.getDay()]} ${d.getDate()} ${MONTHS[d.getMonth()]} ${d.getFullYear()}`;
|
|
75
|
+
const days = dayDiff(d.toISOString(), now);
|
|
76
|
+
if (days === 0)
|
|
77
|
+
return "Today";
|
|
78
|
+
if (days === 1)
|
|
79
|
+
return "Yesterday";
|
|
80
|
+
const year = d.getFullYear() === now.getFullYear() ? "" : ` ${d.getFullYear()}`;
|
|
81
|
+
return `${DAYS[d.getDay()].slice(0, 3)} ${d.getDate()} ${MONTHS[d.getMonth()].slice(0, 3)}${year}`;
|
|
82
|
+
}
|
|
83
|
+
/** §22.7 (R17): the export's name, dated by the local clock. */
|
|
84
|
+
export function changeLogFileName(now) {
|
|
85
|
+
return `change-log-${localDate(now)}.md`;
|
|
86
|
+
}
|
|
87
|
+
/** §22.7: the log as Markdown. Newest first, one heading per day; what Export writes and `rushes log --md` prints. */
|
|
88
|
+
export function logMarkdown(i) {
|
|
89
|
+
const project = oneLine(i.project, LOG_TEXT_MAX) || "Untitled project";
|
|
90
|
+
const only = i.area === undefined ? "" : areaWord(i.area);
|
|
91
|
+
const lines = [`# ${project} — change log${only ? `: ${only}` : ""}`, `Exported ${localStamp(i.now)}`];
|
|
92
|
+
if (i.entries.length === 0 && i.undated.length === 0)
|
|
93
|
+
lines.push("", only ? `Nothing in ${only} yet.` : "Nothing yet.");
|
|
94
|
+
let day = "";
|
|
95
|
+
for (const e of i.entries) {
|
|
96
|
+
const d = new Date(e.at);
|
|
97
|
+
const heading = dayHeading(d, i.now, false);
|
|
98
|
+
if (heading !== day) {
|
|
99
|
+
day = heading;
|
|
100
|
+
lines.push("", `## ${heading}`);
|
|
101
|
+
}
|
|
102
|
+
// The words are made one clean line here too, whoever sent them (an older server doesn't clean what it reads).
|
|
103
|
+
lines.push(`- ${clock(d)} · ${areaWord(e.area)} · ${oneLineOf(e.text)} (${byWord(e.by)})`);
|
|
104
|
+
}
|
|
105
|
+
if (i.earlier)
|
|
106
|
+
lines.push("", `${i.earlier} earlier entr${i.earlier === 1 ? "y" : "ies"} not shown.`);
|
|
107
|
+
if (i.undated.length) {
|
|
108
|
+
lines.push("", "## Before the log");
|
|
109
|
+
for (const u of i.undated)
|
|
110
|
+
lines.push(`- ${oneLineOf(u.text)}`);
|
|
111
|
+
}
|
|
112
|
+
if (i.dropped > 0)
|
|
113
|
+
lines.push("", "Earlier entries were removed.");
|
|
114
|
+
return lines.join("\n") + "\n";
|
|
115
|
+
}
|
|
116
|
+
/** §22.7: Send to agent's "Recent changes" block. The last `max` lines, newest first; empty when there are none. */
|
|
117
|
+
export function recentChanges(entries, max = 5) {
|
|
118
|
+
const top = entries.slice(0, max);
|
|
119
|
+
if (top.length === 0)
|
|
120
|
+
return "";
|
|
121
|
+
return ["Recent changes (newest first):", ...top.map((e) => `- ${localStamp(new Date(e.at))} ${oneLineOf(e.text)}`)].join("\n");
|
|
122
|
+
}
|
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,12 +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",
|
|
51
|
-
// Local files only: a playlist or container that names a URL is never followed.
|
|
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.
|
|
52
67
|
"-protocol_whitelist", "file",
|
|
68
|
+
"-format_whitelist", formats,
|
|
53
69
|
"-show_entries", "format=duration:stream=codec_type,codec_name,width,height,pix_fmt,avg_frame_rate,r_frame_rate",
|
|
54
70
|
"-of", "json",
|
|
55
71
|
file,
|
|
@@ -73,6 +89,94 @@ async function readProbe(file, timeout, signal) {
|
|
|
73
89
|
function positiveInt(n) {
|
|
74
90
|
return typeof n === "number" && Number.isInteger(n) && n > 0 ? n : null;
|
|
75
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
|
+
}
|
|
76
180
|
// §19.5: when Rushes offers a proxy.
|
|
77
181
|
const PLAYABLE_CODECS = new Set(["h264", "vp9", "av1"]);
|
|
78
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
|
}
|