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/log.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// §22.5–§22.6: the Change Log's engine. Appending with collapsing (R4) and the 5000 cap, the
|
|
2
|
+
// one-time backfill (R6), "Before the log" (R5) and reading a page back. Pure apart from new ids;
|
|
3
|
+
// the server's LogBook owns the file.
|
|
4
|
+
import { newId } from "./ids.js";
|
|
5
|
+
import { oneLineOf } from "./labels.js";
|
|
6
|
+
import { STAGE_WORDS, cutEvent, fileEvent, notesSentEvent } from "./logEvents.js";
|
|
7
|
+
import { LOG_MAX, MERGE_MS, logText } from "./logText.js";
|
|
8
|
+
/** The newest entry this event may merge into: same kind, area and writer, within the window (R4). */
|
|
9
|
+
function mergeTarget(entries, event, by, t) {
|
|
10
|
+
const window = event.windowMs ?? MERGE_MS;
|
|
11
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
12
|
+
const e = entries[i];
|
|
13
|
+
const age = t - Date.parse(e.at);
|
|
14
|
+
// More than a window ahead (written while a clock was ahead): never a target, or it would take
|
|
15
|
+
// in everything until its time came round (I2). Look past it.
|
|
16
|
+
if (age < -window)
|
|
17
|
+
continue;
|
|
18
|
+
if (!(age <= window))
|
|
19
|
+
return -1; // older than the window, and so is everything before it
|
|
20
|
+
if (e.kind === event.kind && e.area === event.area && e.by === by)
|
|
21
|
+
return i;
|
|
22
|
+
}
|
|
23
|
+
return -1;
|
|
24
|
+
}
|
|
25
|
+
/** `wanted` when no line has it yet, otherwise a new id that none has. Ids are short and random, so a long log can draw one twice (I1). */
|
|
26
|
+
function freshId(taken, wanted) {
|
|
27
|
+
let id = wanted ?? newId("l");
|
|
28
|
+
while (taken(id))
|
|
29
|
+
id = newId("l");
|
|
30
|
+
return id;
|
|
31
|
+
}
|
|
32
|
+
// §22.9: a retried request repeats the event it already logged. For a count, that's the same cut
|
|
33
|
+
// (video and version) or the same variant or take (ref) as the line's latest; files and notes have
|
|
34
|
+
// no identity, so two of them are two.
|
|
35
|
+
const sameThing = (e, link) => (link.version !== null || link.ref !== null) && e.video === link.video && e.version === link.version && e.ref === link.ref;
|
|
36
|
+
function mergeInto(e, event, text, subject, count, link) {
|
|
37
|
+
// A repeat is the same words about the same place (minor 4).
|
|
38
|
+
if (event.merge === "once")
|
|
39
|
+
return e.text === text && e.video === link.video && e.version === link.version && e.ref === link.ref && e.tab === link.tab;
|
|
40
|
+
if (event.merge === "replace") {
|
|
41
|
+
if (e.subject !== subject)
|
|
42
|
+
return false;
|
|
43
|
+
e.text = text;
|
|
44
|
+
e.n += 1;
|
|
45
|
+
Object.assign(e, link);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
if (sameThing(e, link))
|
|
49
|
+
return true;
|
|
50
|
+
e.n += count;
|
|
51
|
+
e.subject = e.subject === subject ? subject : "";
|
|
52
|
+
e.text = logText(event.many ? event.many(e.n, e.subject, e.text) : text) || text;
|
|
53
|
+
// A line opens a tab only when every event in it came from that one (minor 5).
|
|
54
|
+
Object.assign(e, link, { tab: e.tab === link.tab ? link.tab : null });
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* §22.5: writes `event` into `file` at `at`, merging it into a recent line when R4 says so, and keeps
|
|
59
|
+
* the newest LOG_MAX. Returns the line written or updated. A line with nothing visible in it is
|
|
60
|
+
* refused with an error, and the file is left as it was.
|
|
61
|
+
*/
|
|
62
|
+
export function appendEvent(file, event, by, at, id) {
|
|
63
|
+
return place(file, event, by, at, id, (x) => file.entries.some((e) => e.id === x), true);
|
|
64
|
+
}
|
|
65
|
+
// appendEvent's work. `taken` says whether an id is in use; `cap` keeps the newest LOG_MAX as it
|
|
66
|
+
// goes. The backfill passes a Set and caps once at the end, so 30,000 dated items stay linear.
|
|
67
|
+
function place(file, event, by, at, id, taken, cap) {
|
|
68
|
+
const t = at.getTime();
|
|
69
|
+
const iso = at.toISOString();
|
|
70
|
+
const text = logText(event.text);
|
|
71
|
+
if (!text)
|
|
72
|
+
throw new Error("A Change Log line can't be blank");
|
|
73
|
+
// The schema keeps a subject to 200 characters; a lane name has no limit of its own.
|
|
74
|
+
const subject = Array.from(event.subject ?? "").slice(0, 200).join("");
|
|
75
|
+
const count = Math.max(1, Math.floor(event.count ?? 1));
|
|
76
|
+
const link = { video: event.video ?? null, version: event.version ?? null, ref: event.ref ?? null, tab: event.tab ?? null };
|
|
77
|
+
const dated = [...(event.ref ? [event.ref] : []), ...(event.clears ?? [])];
|
|
78
|
+
if (dated.length && file.undated.length) {
|
|
79
|
+
const gone = new Set(dated);
|
|
80
|
+
file.undated = file.undated.filter((r) => !gone.has(r));
|
|
81
|
+
}
|
|
82
|
+
const i = mergeTarget(file.entries, event, by, t);
|
|
83
|
+
if (i >= 0) {
|
|
84
|
+
const e = file.entries[i];
|
|
85
|
+
if (mergeInto(e, event, text, subject, count, link)) {
|
|
86
|
+
if (!(Date.parse(e.at) > t))
|
|
87
|
+
e.at = iso;
|
|
88
|
+
file.entries.splice(i, 1);
|
|
89
|
+
file.entries.push(e);
|
|
90
|
+
return e;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const entry = { id: freshId(taken, id), at: iso, area: event.area, kind: event.kind, text, ...link, by, n: count, subject };
|
|
94
|
+
file.entries.push(entry);
|
|
95
|
+
const extra = file.entries.length - LOG_MAX;
|
|
96
|
+
if (cap && extra > 0) {
|
|
97
|
+
file.entries.splice(0, extra);
|
|
98
|
+
file.dropped += extra;
|
|
99
|
+
}
|
|
100
|
+
return entry;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* §22.6: reads in, once, the history a project already has. Every cut, batch and file dated before
|
|
104
|
+
* `before` (when this server's log began, R6) becomes a line by Rushes, in time order and collapsed
|
|
105
|
+
* as live lines are. The variants and takes already there become `undated` (R5), less any a line in
|
|
106
|
+
* the log already dates. A no-op once done.
|
|
107
|
+
*/
|
|
108
|
+
export function backfillLog(file, src, before) {
|
|
109
|
+
if (file.backfilled)
|
|
110
|
+
return;
|
|
111
|
+
const films = src.project.videos.length;
|
|
112
|
+
const dated = [];
|
|
113
|
+
const add = (when, event) => {
|
|
114
|
+
const t = Date.parse(when);
|
|
115
|
+
if (Number.isFinite(t) && t < before)
|
|
116
|
+
dated.push({ t, event });
|
|
117
|
+
};
|
|
118
|
+
for (const video of src.project.videos)
|
|
119
|
+
for (const version of video.versions)
|
|
120
|
+
add(version.addedAt, cutEvent(films, video, version));
|
|
121
|
+
for (const batch of src.batches.batches)
|
|
122
|
+
add(batch.sentAt, notesSentEvent(batch));
|
|
123
|
+
for (const entry of src.project.files)
|
|
124
|
+
add(entry.addedAt, fileEvent(entry));
|
|
125
|
+
dated.sort((a, b) => a.t - b.t);
|
|
126
|
+
const past = { schema: 1, rev: 0, backfilled: true, undated: [], dropped: 0, entries: [] };
|
|
127
|
+
// Ids are drawn against the live lines too, so none is shared (I1).
|
|
128
|
+
const ids = new Set(file.entries.map((e) => e.id));
|
|
129
|
+
const taken = (x) => {
|
|
130
|
+
if (ids.has(x))
|
|
131
|
+
return true;
|
|
132
|
+
ids.add(x); // freshId keeps the first id that isn't taken, so it's now in use
|
|
133
|
+
return false;
|
|
134
|
+
};
|
|
135
|
+
for (const d of dated)
|
|
136
|
+
place(past, d.event, "rushes", new Date(d.t), undefined, taken, false);
|
|
137
|
+
file.entries = [...past.entries, ...file.entries];
|
|
138
|
+
const extra = file.entries.length - LOG_MAX;
|
|
139
|
+
if (extra > 0) {
|
|
140
|
+
file.entries.splice(0, extra);
|
|
141
|
+
file.dropped += extra;
|
|
142
|
+
}
|
|
143
|
+
const live = new Set(file.entries.map((e) => e.ref));
|
|
144
|
+
file.undated = undatedRefs(src.project, src.script).filter((r) => !live.has(r));
|
|
145
|
+
file.backfilled = true;
|
|
146
|
+
}
|
|
147
|
+
/** Every variant ("<lane>/<variant>") and take ("<section>:<take>") the project has. */
|
|
148
|
+
export function undatedRefs(project, script) {
|
|
149
|
+
const refs = [
|
|
150
|
+
...project.lanes.flatMap((l) => l.variants.map((v) => `${l.id}/${v.id}`)),
|
|
151
|
+
...script.sections.flatMap((s) => s.takes.map((t) => `${s.id}:${t.id}`)),
|
|
152
|
+
];
|
|
153
|
+
return refs.slice(0, LOG_MAX);
|
|
154
|
+
}
|
|
155
|
+
/** §22.6's "Before the log": one line per lane, and one for takes, computed now from the refs that still exist. */
|
|
156
|
+
export function undatedLines(refs, ctx) {
|
|
157
|
+
const set = new Set(refs);
|
|
158
|
+
const out = [];
|
|
159
|
+
for (const lane of ctx.project.lanes) {
|
|
160
|
+
const n = lane.variants.filter((v) => set.has(`${lane.id}/${v.id}`)).length;
|
|
161
|
+
if (n === 0)
|
|
162
|
+
continue;
|
|
163
|
+
const noun = lane.stage === "voice" ? (n === 1 ? "read" : "reads") : n === 1 ? "variant" : "variants";
|
|
164
|
+
// A lane that carries its stage's own name (every 0.2.x project's defaults) isn't named twice.
|
|
165
|
+
const word = STAGE_WORDS[lane.stage];
|
|
166
|
+
const name = oneLineOf(lane.name);
|
|
167
|
+
out.push({ area: lane.stage, text: logText(name && name !== word ? `${word}: ${lane.name} (${n} ${noun})` : `${word}: ${n} ${noun}`) });
|
|
168
|
+
}
|
|
169
|
+
const sections = ctx.script.sections.filter((s) => s.takes.some((t) => set.has(`${s.id}:${t.id}`))).length;
|
|
170
|
+
if (sections)
|
|
171
|
+
out.push({ area: "voice", text: `Voiceover: ${sections} section${sections === 1 ? "" : "s"} with takes` });
|
|
172
|
+
return out;
|
|
173
|
+
}
|
|
174
|
+
/** §22.7: the newest `limit` lines (default 30), newest first, matching `area` and `since`. */
|
|
175
|
+
export function logView(file, q, ctx) {
|
|
176
|
+
const asked = Number.isFinite(q.limit) ? Math.floor(q.limit) : 30;
|
|
177
|
+
const limit = Math.min(LOG_MAX, Math.max(1, asked));
|
|
178
|
+
const from = q.since === undefined ? null : Date.parse(q.since);
|
|
179
|
+
const matching = [];
|
|
180
|
+
for (let i = file.entries.length - 1; i >= 0; i--) {
|
|
181
|
+
const e = file.entries[i];
|
|
182
|
+
if (q.area !== undefined && e.area !== q.area)
|
|
183
|
+
continue;
|
|
184
|
+
if (from !== null && !(Date.parse(e.at) > from))
|
|
185
|
+
continue;
|
|
186
|
+
matching.push(e);
|
|
187
|
+
}
|
|
188
|
+
const undated = from !== null ? [] : undatedLines(file.undated, ctx).filter((l) => q.area === undefined || l.area === q.area);
|
|
189
|
+
return { entries: matching.slice(0, limit), earlier: Math.max(0, matching.length - limit), undated, dropped: file.dropped, total: file.entries.length };
|
|
190
|
+
}
|
|
@@ -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
|
+
}
|