rushes 0.8.1 → 0.9.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.
Files changed (112) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +26 -26
  3. package/README.md +60 -56
  4. package/dist/cli/demo.js +20 -8
  5. package/dist/cli/main.js +1 -1
  6. package/dist/core/approval.js +15 -0
  7. package/dist/core/batches.js +5 -4
  8. package/dist/core/exportNotes.js +6 -4
  9. package/dist/core/logText.js +1 -1
  10. package/dist/core/noteState.js +46 -0
  11. package/dist/core/notes.js +20 -12
  12. package/dist/core/picks.js +79 -0
  13. package/dist/core/project.js +27 -2
  14. package/dist/core/schema.js +20 -2
  15. package/dist/core/script.js +6 -2
  16. package/dist/core/tabs.js +3 -2
  17. package/dist/core/takes.js +73 -0
  18. package/dist/mcp/tools.js +10 -8
  19. package/dist/server/app.js +92 -23
  20. package/dist/server/brief.js +5 -2
  21. package/dist/server/loudness.js +20 -45
  22. package/dist/server/storyboard.js +4 -1
  23. package/package.json +3 -3
  24. package/skills/rushes/SKILL.md +13 -13
  25. package/web-dist/assets/geist-cyrillic-400-normal-DXusLSnH.woff2 +0 -0
  26. package/web-dist/assets/geist-cyrillic-400-normal-DkrqoNl2.woff +0 -0
  27. package/web-dist/assets/geist-cyrillic-500-normal-BboVsk8R.woff +0 -0
  28. package/web-dist/assets/geist-cyrillic-500-normal-NWpm63d5.woff2 +0 -0
  29. package/web-dist/assets/geist-cyrillic-600-normal-BeW5VFD_.woff2 +0 -0
  30. package/web-dist/assets/geist-cyrillic-600-normal-CnEeIcMC.woff +0 -0
  31. package/web-dist/assets/geist-cyrillic-700-normal-BH7gZKkM.woff +0 -0
  32. package/web-dist/assets/geist-cyrillic-700-normal-BSHy2ewF.woff2 +0 -0
  33. package/web-dist/assets/geist-cyrillic-ext-400-normal-ChfpGzr5.woff +0 -0
  34. package/web-dist/assets/geist-cyrillic-ext-500-normal-BXrH8YSv.woff +0 -0
  35. package/web-dist/assets/geist-cyrillic-ext-600-normal-PR76dHFV.woff +0 -0
  36. package/web-dist/assets/geist-cyrillic-ext-700-normal-CBIC21Ex.woff +0 -0
  37. package/web-dist/assets/geist-latin-400-normal-B40WzpMT.woff2 +0 -0
  38. package/web-dist/assets/geist-latin-400-normal-akEymXtG.woff +0 -0
  39. package/web-dist/assets/geist-latin-500-normal-BDXIbFrL.woff +0 -0
  40. package/web-dist/assets/geist-latin-500-normal-CTWBw9NS.woff2 +0 -0
  41. package/web-dist/assets/geist-latin-600-normal-CSETrqM2.woff2 +0 -0
  42. package/web-dist/assets/geist-latin-600-normal-DsPlZH-9.woff +0 -0
  43. package/web-dist/assets/geist-latin-700-normal-Bod5GerT.woff +0 -0
  44. package/web-dist/assets/geist-latin-700-normal-CFi8mLqe.woff2 +0 -0
  45. package/web-dist/assets/geist-latin-ext-400-normal-Bz1pQMyt.woff +0 -0
  46. package/web-dist/assets/geist-latin-ext-400-normal-CND6cjiG.woff2 +0 -0
  47. package/web-dist/assets/geist-latin-ext-500-normal-BovoTgeE.woff2 +0 -0
  48. package/web-dist/assets/geist-latin-ext-500-normal-C9fx-R30.woff +0 -0
  49. package/web-dist/assets/geist-latin-ext-600-normal-CVFbg5dS.woff2 +0 -0
  50. package/web-dist/assets/geist-latin-ext-600-normal-TmIUreF9.woff +0 -0
  51. package/web-dist/assets/geist-latin-ext-700-normal-BnofTsEi.woff2 +0 -0
  52. package/web-dist/assets/geist-latin-ext-700-normal-DKAtFBEc.woff +0 -0
  53. package/web-dist/assets/geist-mono-cyrillic-400-normal-C51Di1Mf.woff2 +0 -0
  54. package/web-dist/assets/geist-mono-cyrillic-400-normal-CPJFfJgk.woff +0 -0
  55. package/web-dist/assets/geist-mono-cyrillic-500-normal-D2cXvDHF.woff2 +0 -0
  56. package/web-dist/assets/geist-mono-cyrillic-500-normal-DfuvdVgn.woff +0 -0
  57. package/web-dist/assets/geist-mono-latin-400-normal-B2yvC1Cq.woff +0 -0
  58. package/web-dist/assets/geist-mono-latin-400-normal-DTRLJnHl.woff2 +0 -0
  59. package/web-dist/assets/geist-mono-latin-500-normal-D-GG86Jb.woff +0 -0
  60. package/web-dist/assets/geist-mono-latin-500-normal-YINYabwD.woff2 +0 -0
  61. package/web-dist/assets/geist-mono-latin-ext-400-normal-CfzLURNc.woff +0 -0
  62. package/web-dist/assets/geist-mono-latin-ext-400-normal-DI-rJ0UV.woff2 +0 -0
  63. package/web-dist/assets/geist-mono-latin-ext-500-normal-Buglb9-a.woff2 +0 -0
  64. package/web-dist/assets/geist-mono-latin-ext-500-normal-CrWEgvU_.woff +0 -0
  65. package/web-dist/assets/geist-mono-symbols2-400-normal-DjbiTEEA.woff +0 -0
  66. package/web-dist/assets/geist-mono-symbols2-500-normal-CmnCPGa0.woff +0 -0
  67. package/web-dist/assets/geist-mono-vietnamese-400-normal-CZEPLOgu.woff +0 -0
  68. package/web-dist/assets/geist-mono-vietnamese-500-normal-Dx9-epDo.woff +0 -0
  69. package/web-dist/assets/geist-vietnamese-400-normal-C8xY9-dI.woff +0 -0
  70. package/web-dist/assets/geist-vietnamese-500-normal-_b1ojCbH.woff +0 -0
  71. package/web-dist/assets/geist-vietnamese-600-normal-B5MZcNo4.woff +0 -0
  72. package/web-dist/assets/geist-vietnamese-600-normal-BFUgqsz8.woff2 +0 -0
  73. package/web-dist/assets/geist-vietnamese-700-normal-Dm6ODIDG.woff +0 -0
  74. package/web-dist/assets/index-D-520-nU.js +67 -0
  75. package/web-dist/assets/index-DebHxWrg.css +1 -0
  76. package/web-dist/index.html +2 -2
  77. package/web-dist/assets/figtree-latin-400-normal-BD4aNku5.woff +0 -0
  78. package/web-dist/assets/figtree-latin-400-normal-g7Dtegnw.woff2 +0 -0
  79. package/web-dist/assets/figtree-latin-500-normal-BWnGEVsr.woff2 +0 -0
  80. package/web-dist/assets/figtree-latin-500-normal-B_yy1phn.woff +0 -0
  81. package/web-dist/assets/figtree-latin-600-normal-BM_oTo4n.woff +0 -0
  82. package/web-dist/assets/figtree-latin-600-normal-Cv_xCTDl.woff2 +0 -0
  83. package/web-dist/assets/figtree-latin-700-normal-BCCt2T1q.woff +0 -0
  84. package/web-dist/assets/figtree-latin-700-normal-th6qEP7c.woff2 +0 -0
  85. package/web-dist/assets/figtree-latin-ext-400-normal-CXAzuTZb.woff2 +0 -0
  86. package/web-dist/assets/figtree-latin-ext-400-normal-Gbh-3PTk.woff +0 -0
  87. package/web-dist/assets/figtree-latin-ext-500-normal-BOEJvrb_.woff +0 -0
  88. package/web-dist/assets/figtree-latin-ext-500-normal-Du0rIuHj.woff2 +0 -0
  89. package/web-dist/assets/figtree-latin-ext-600-normal-CQqsimlV.woff +0 -0
  90. package/web-dist/assets/figtree-latin-ext-600-normal-DJlfifZj.woff2 +0 -0
  91. package/web-dist/assets/figtree-latin-ext-700-normal-BoDi4KL2.woff +0 -0
  92. package/web-dist/assets/figtree-latin-ext-700-normal-CS4sQkGV.woff2 +0 -0
  93. package/web-dist/assets/index-DhS2fPd_.js +0 -11
  94. package/web-dist/assets/index-jf-RHBPN.css +0 -1
  95. package/web-dist/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
  96. package/web-dist/assets/jetbrains-mono-cyrillic-400-normal-ugxPyKxw.woff +0 -0
  97. package/web-dist/assets/jetbrains-mono-cyrillic-500-normal-DJqRU3vO.woff +0 -0
  98. package/web-dist/assets/jetbrains-mono-cyrillic-500-normal-DmUKJPL_.woff2 +0 -0
  99. package/web-dist/assets/jetbrains-mono-greek-400-normal-B9oWc5Lo.woff +0 -0
  100. package/web-dist/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
  101. package/web-dist/assets/jetbrains-mono-greek-500-normal-D7SFKleX.woff +0 -0
  102. package/web-dist/assets/jetbrains-mono-greek-500-normal-JpySY46c.woff2 +0 -0
  103. package/web-dist/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
  104. package/web-dist/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
  105. package/web-dist/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
  106. package/web-dist/assets/jetbrains-mono-latin-500-normal-CJOVTJB7.woff +0 -0
  107. package/web-dist/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
  108. package/web-dist/assets/jetbrains-mono-latin-ext-400-normal-fXTG6kC5.woff +0 -0
  109. package/web-dist/assets/jetbrains-mono-latin-ext-500-normal-Cut-4mMH.woff2 +0 -0
  110. package/web-dist/assets/jetbrains-mono-latin-ext-500-normal-ckzbgY84.woff +0 -0
  111. package/web-dist/assets/jetbrains-mono-vietnamese-400-normal-CqNFfHCs.woff +0 -0
  112. package/web-dist/assets/jetbrains-mono-vietnamese-500-normal-DNRqzVM1.woff +0 -0
package/dist/cli/demo.js CHANGED
@@ -4,6 +4,7 @@ import { mkdir, readdir, rm } from "node:fs/promises";
4
4
  import { join, resolve } from "node:path";
5
5
  import { addVariant, addVersion, setShots, shotAt } from "../core/project.js";
6
6
  import { addNote } from "../core/notes.js";
7
+ import { setInUse } from "../core/picks.js";
7
8
  import { setSections } from "../core/script.js";
8
9
  import { toManifestPath } from "../core/paths.js";
9
10
  import { Store } from "../core/store.js";
@@ -234,6 +235,8 @@ export async function makeDemo(dir, deps) {
234
235
  let pictureNoteShot = null;
235
236
  const pictureNoteT = 10;
236
237
  await store.update("project", (p) => {
238
+ // The project's frame rate is its cuts' (the store starts a project at 30).
239
+ p.fps = 25;
237
240
  const { video, version: v1 } = addVersion(p, { video: `${PRODUCT} launch`, file: toManifestPath(root, v1Abs), duration: DURATION, fps: 25, note: "First cut of the test pattern" }, deps.now);
238
241
  videoId = video.id;
239
242
  const cut = setShots(p, video.id, v1.id, [0, 6, 12, 18, 24].map((start, i) => ({ name: `Shot ${i + 1}`, start })));
@@ -288,9 +291,11 @@ export async function makeDemo(dir, deps) {
288
291
  const pulseWav = join(musicDir, "pulse.wav");
289
292
  await renderChord(deps.ffmpeg, warmPadWav, { freqs: [196, 246.94, 293.66], seconds: 12 });
290
293
  await renderChord(deps.ffmpeg, pulseWav, { freqs: [220, 277.18, 329.63], seconds: 12, pulseHz: 2.5 });
294
+ let musicLaneId = "";
291
295
  let musicVariantId = "";
292
296
  await store.update("project", (p) => {
293
- const { variant } = addVariant(p, { stage: "music", name: "Warm pad", file: toManifestPath(root, warmPadWav) });
297
+ const { lane, variant } = addVariant(p, { stage: "music", name: "Warm pad", file: toManifestPath(root, warmPadWav) });
298
+ musicLaneId = lane.id;
294
299
  musicVariantId = variant.id;
295
300
  addVariant(p, { stage: "music", name: "Pulse", file: toManifestPath(root, pulseWav) });
296
301
  });
@@ -310,20 +315,27 @@ export async function makeDemo(dir, deps) {
310
315
  ],
311
316
  });
312
317
  });
313
- // 6. Picks: music and round 1, with music's level set to -12 dB so Mix shows a level.
318
+ // 6. Picks: Warm pad and Round 1's Voice A in use on the film, as a pick on the desk makes them (setInUse, as the
319
+ // server's PUT /api/picks does), with the bed at -12 dB so the Timeline shows a level. A film plays its own picks.
320
+ const { lanes } = await store.read("project");
314
321
  await store.update("picks", (picks) => {
315
- picks.lanes.music = musicVariantId;
316
- picks.lanes[round1LaneId] = voiceAId;
317
- picks.levels.music = -12;
322
+ const own = (picks.videos[videoId] ??= { lanes: {}, levels: {} });
323
+ for (const [laneId, variantId] of [[round1LaneId, voiceAId], [musicLaneId, musicVariantId]]) {
324
+ const lane = lanes.find((l) => l.id === laneId);
325
+ if (!lane)
326
+ throw new Error(`The demo has no ${laneId} lane`);
327
+ setInUse(own, lanes, lane, variantId, deps.now);
328
+ }
329
+ own.levels.music = -12;
318
330
  });
319
331
  // 7. Example notes: a point on Picture, a whole note on a Round 1 read, a range note with "Fall"
320
332
  // on Music, and a whole note on Mix.
321
333
  const voiceNote = hasSay ? `${shortA} reads warmer than ${shortB}. Lean that way for launch.` : `${shortA} over ${shortB} for now. Swap in real reads before launch.`;
322
334
  await store.update("notes", (notes) => {
323
335
  addNote(notes, { stage: "picture", video: videoId, version: "v1", scope: "point", t: pictureNoteT, shot: pictureNoteShot, text: "Hold the opening frame a beat longer before the cut." }, deps.now);
324
- addNote(notes, { stage: "voice", on: `${round1LaneId}/${voiceAId}`, scope: "whole", text: voiceNote }, deps.now);
325
- addNote(notes, { stage: "music", on: `music/${musicVariantId}`, scope: "range", t: 6, tOut: 9, marks: [{ kind: "fall" }], text: "Let the pad fall away under the last line." }, deps.now);
326
- addNote(notes, { stage: "mix", on: null, scope: "whole", text: "Check the whole mix against a phone speaker before sign-off." }, deps.now);
336
+ addNote(notes, { stage: "voice", video: videoId, on: `${round1LaneId}/${voiceAId}`, scope: "whole", text: voiceNote }, deps.now);
337
+ addNote(notes, { stage: "music", video: videoId, on: `${musicLaneId}/${musicVariantId}`, scope: "range", t: 6, tOut: 9, marks: [{ kind: "fall" }], text: "Let the pad fall away under the last line." }, deps.now);
338
+ addNote(notes, { stage: "mix", video: videoId, on: null, scope: "whole", text: "Check the whole mix against a phone speaker before sign-off." }, deps.now);
327
339
  });
328
340
  return { dir: root };
329
341
  }
package/dist/cli/main.js CHANGED
@@ -479,7 +479,7 @@ export async function main(argv, io) {
479
479
  if (o.json)
480
480
  return io.out(JSON.stringify(notes, null, 2)), 0;
481
481
  // What an audio note is on (M4) and a Picture note's format (§21.4, R4), from the state.
482
- const state = notes.some((n) => n.stage !== "script") ? await c.get("/api/state") : null;
482
+ const state = notes.some((n) => n.stage !== "script" || n.on != null) ? await c.get("/api/state") : null;
483
483
  for (const n of notes) {
484
484
  const label = state ? onLabel(n, state) : null;
485
485
  const on = label ? `${stripControl(label)} ` : "";
@@ -0,0 +1,15 @@
1
+ // The plan's approvals, one rule for all three pages: the brief, each script section and each storyboard shot.
2
+ // Pure (no Node imports). The user approves; an approval is for the words they read, so a change to the words of
3
+ // an approved item reopens it (back to draft), whoever makes it. On the agent's side that is setSections (script)
4
+ // and the agent rewriting brief.md or storyboard.md; on the user's, an edit in the dashboard, below.
5
+ //
6
+ // Prior art: GitHub's "dismiss stale pull request approvals when new commits are pushed".
7
+ /**
8
+ * The status an item has after the user's edit. A change to an approved item's words (or direction) reopens it,
9
+ * unless the same edit sets the status; a save that changes no words, and an item that isn't approved, keep theirs.
10
+ */
11
+ export function statusAfterEdit(was, edit) {
12
+ if (edit.status !== undefined)
13
+ return edit.status;
14
+ return was === "approved" && edit.wordsChanged ? "draft" : was;
15
+ }
@@ -2,6 +2,7 @@ import { chipOrder, versionFormats } from "./formats.js";
2
2
  import { STAGES } from "./schema.js";
3
3
  import { EmptyBatchError } from "./errors.js";
4
4
  import { noteInPlay } from "./project.js";
5
+ import { moveNote, noteState } from "./noteState.js";
5
6
  import { isChanged } from "./script.js";
6
7
  import { TAB_NAMES } from "./logEvents.js";
7
8
  const STAGE_NAMES = {
@@ -15,19 +16,19 @@ const STAGE_NAMES = {
15
16
  };
16
17
  /**
17
18
  * Gather open, unsent items into a batch: to-do notes with no batch yet, and changed or flagged
18
- * script sections. With a stage, only that tab's; with none (Send to agent), every tab's, on every
19
+ * script sections. With a stage, only that tab's; with none (Send), every tab's, on every
19
20
  * film in play. A batch whose items all come from one tab is that tab's batch; one that spans tabs
20
21
  * has no stage.
21
22
  */
22
23
  export function createBatch(ctx, stage, now = new Date()) {
23
24
  // §26: a shelved film is never asked about; its open notes stay unsent.
24
- const notes = ctx.notes.notes.filter((n) => (stage === undefined || n.stage === stage) && n.status === "todo" && n.batch === null && noteInPlay(n, ctx.project));
25
+ const notes = ctx.notes.notes.filter((n) => (stage === undefined || n.stage === stage) && noteState(n) === "todo" && noteInPlay(n, ctx.project));
25
26
  const sections = stage === undefined || stage === "script" ? ctx.script.sections.filter((s) => isChanged(s) || s.status === "flagged") : [];
26
27
  if (notes.length === 0 && sections.length === 0)
27
28
  throw new EmptyBatchError(stage);
28
29
  const id = `b_${ctx.batches.batches.length + 1}`;
29
30
  for (const n of notes)
30
- n.batch = id;
31
+ moveNote(n, { type: "send", batch: id });
31
32
  // The tabs it covers, in tab order.
32
33
  const stages = STAGES.filter((st) => (st === "script" && sections.length > 0) || notes.some((n) => n.stage === st));
33
34
  const only = stages.length === 1 ? stages[0] : null;
@@ -85,7 +86,7 @@ function stepsFor(stage) {
85
86
  return stage === "script"
86
87
  ? "Use rushes_get_batch, take each section's proposed line, then rushes_set_script with just those sections (it merges by 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."
87
88
  : stage === "voice"
88
- ? "Use rushes_get_batch and rushes_get_picks. Answer the notes with new whole reads (rushes_add_variant with stage voice and round): a new round for a new direction, or the current round for a small fix to a marked word. Say in each read's description what changed. Then rushes_reply."
89
+ ? "Use rushes_get_batch and rushes_get_picks. Answer the notes with new whole reads (rushes_add_variant with stage voice and round): a new round for a new direction, or the current round for a small fix to a marked word. A range note (t to tOut) is about that stretch of the read: replace or fix just that part. Say in each read's description what changed. Then rushes_reply."
89
90
  : stage === "mix"
90
91
  ? // §19.6: rushes_get_picks also carries each lane's level -- where the user wants it sitting.
91
92
  'Use rushes_get_batch and rushes_get_picks, fix each note (marks such as "Fall" or "Quieter 3 dB" are part of the note), register the new variant, then rushes_reply. The picks\' levels say where the user wants each lane to sit.'
@@ -5,10 +5,11 @@ import { noteInPlay } from "./project.js";
5
5
  import { markLabel } from "./schema.js";
6
6
  import { labelOfId } from "./formats.js";
7
7
  import { pinWords, regionWords } from "./visuals.js";
8
- // Picture notes are grouped by film and version; the other stages list straight through.
9
- // Script isn't included here -- script edits live in script.json, not notes.json.
10
- const STAGE_ORDER = ["picture", "voice", "music", "sfx", "mix", "visuals"];
8
+ // Picture notes are grouped by film and version; the other stages list straight through. The script's own edits
9
+ // live in script.json and are not exported here; notes on the script (§27, 5.8: on a line, or the whole script) are.
10
+ const STAGE_ORDER = ["script", "picture", "voice", "music", "sfx", "mix", "visuals"];
11
11
  const STAGE_TITLES = {
12
+ script: "Script",
12
13
  picture: "Picture",
13
14
  voice: "Voiceover",
14
15
  music: "Music",
@@ -83,7 +84,8 @@ function byTimecode(a, b) {
83
84
  }
84
85
  /**
85
86
  * The project's notes as Markdown: a title and export date, then one `##` section per stage
86
- * that has notes, in workflow order (script is never included -- it lives in script.json).
87
+ * that has notes, in workflow order (the script's own edits are never included -- they live in script.json; notes
88
+ * on the script are, each naming its line).
87
89
  * Picture notes are further grouped under a `### <Film> · <version>` heading per film and
88
90
  * version that has notes, in the project's own video/version order. A note whose video or
89
91
  * version no longer exists in the project (hand-edited away, say) is never dropped (M3): it's
@@ -113,7 +113,7 @@ export function logMarkdown(i) {
113
113
  lines.push("", "Earlier entries were removed.");
114
114
  return lines.join("\n") + "\n";
115
115
  }
116
- /** §22.7: Send to agent's "Recent changes" block. The last `max` lines, newest first; empty when there are none. */
116
+ /** §22.7: the "Recent changes" block of the prompt Send gives. The last `max` lines, newest first; empty when there are none. */
117
117
  export function recentChanges(entries, max = 5) {
118
118
  const top = entries.slice(0, max);
119
119
  if (top.length === 0)
@@ -0,0 +1,46 @@
1
+ export const NOTE_STATES = ["todo", "sent", "done"];
2
+ /** Every move a note can make: from a state, on an event, to a state. A move not listed is refused. */
3
+ export const NOTE_TRANSITIONS = {
4
+ todo: { send: "sent", resolve: "done" },
5
+ sent: { resolve: "done" },
6
+ done: { reopen: "todo" },
7
+ };
8
+ /** Each state in words, for a marker's or a dot's name and tooltip, and for an agent. */
9
+ export const NOTE_STATE_LABEL = { todo: "To do", sent: "With your agent", done: "Done" };
10
+ /** A to-do note is sent once a batch holds it; done wins over both. */
11
+ export function noteState(n) {
12
+ return n.status === "done" ? "done" : n.batch !== null ? "sent" : "todo";
13
+ }
14
+ export const canMove = (from, event) => NOTE_TRANSITIONS[from][event] !== undefined;
15
+ /** Makes the move on the note's stored fields, or throws when the table has no such move from its state. */
16
+ export function moveNote(n, event) {
17
+ const from = noteState(n);
18
+ if (!canMove(from, event.type))
19
+ throw new Error(`can't ${event.type} a note that is ${from}`);
20
+ if (event.type === "send")
21
+ n.batch = event.batch;
22
+ else if (event.type === "resolve")
23
+ n.status = "done";
24
+ else {
25
+ n.status = "todo";
26
+ n.batch = null;
27
+ }
28
+ }
29
+ /**
30
+ * Status as a person or an agent sets it ("todo" or "done"), made as moves: done to todo reopens, todo to done
31
+ * resolves, and the status a note already has changes nothing.
32
+ */
33
+ export function setStatus(n, status) {
34
+ if (status === undefined || status === n.status)
35
+ return;
36
+ moveNote(n, { type: status === "done" ? "resolve" : "reopen" });
37
+ }
38
+ /** Send: the batch's notes that are still to do and unsent are filed in it. Ones sent before, or done, stay as they are. */
39
+ export function markSent(notes, batch) {
40
+ const ids = new Set(batch.noteIds);
41
+ for (const n of notes)
42
+ if (ids.has(n.id) && noteState(n) === "todo")
43
+ moveNote(n, { type: "send", batch: batch.id });
44
+ }
45
+ /** The note with its state, as the server hands it out. A copy: the stored note never carries one. */
46
+ export const withState = (n) => ({ ...n, state: noteState(n) });
@@ -2,6 +2,7 @@ import { NoteSchema, } from "./schema.js";
2
2
  import { InvalidError, NotFoundError, RushesError } from "./errors.js";
3
3
  import { labelOfId, versionFormats } from "./formats.js";
4
4
  import { newId } from "./ids.js";
5
+ import { noteState, setStatus } from "./noteState.js";
5
6
  export function addNote(file, input, now = new Date()) {
6
7
  // Ids are short and random (24 bits), so a long file can draw one a note already has, and a reply
7
8
  // for one note would then land on the other. Draw again, as the log does.
@@ -20,18 +21,12 @@ function find(file, id) {
20
21
  throw new NotFoundError("note", id);
21
22
  return n;
22
23
  }
23
- /** A done note going back to todo leaves its batch, so the next Send includes it. */
24
- function reopen(n, status) {
25
- if (n.status === "done" && status === "todo")
26
- n.batch = null;
27
- }
28
24
  export function applyReply(file, r) {
29
25
  const n = find(file, r.id);
30
26
  if (r.reply !== undefined)
31
27
  n.reply = r.reply;
32
- reopen(n, r.status);
33
- if (r.status !== undefined)
34
- n.status = r.status;
28
+ // A status is a move in the note's lifecycle (noteState.ts): done to todo reopens it, which leaves its batch.
29
+ setStatus(n, r.status);
35
30
  if (r.fixT !== undefined)
36
31
  n.fixT = r.fixT;
37
32
  if (r.fixVersion !== undefined)
@@ -49,8 +44,10 @@ export function applyUserEdit(file, e, check) {
49
44
  if (!parsed.success)
50
45
  throw new InvalidError("Note edit is invalid", parsed.error.issues);
51
46
  check?.(parsed.data, n);
52
- reopen(n, e.status);
53
- Object.assign(n, { ...parsed.data, batch: n.batch });
47
+ // Status and batch move together, by the lifecycle's rules (noteState.ts); the rest is the user's edit.
48
+ const life = { status: n.status, batch: n.batch };
49
+ setStatus(life, e.status);
50
+ Object.assign(n, { ...parsed.data, ...life });
54
51
  return n;
55
52
  }
56
53
  /**
@@ -81,17 +78,27 @@ export function checkNoteFormat({ next, prev, boxRedrawn = false }, project) {
81
78
  }
82
79
  }
83
80
  }
81
+ /** A script line in words, as the Script page and the notes panel name it: "S2 · The scan finds it", cut at 48 characters. */
82
+ export function sectionLineLabel(section) {
83
+ const words = section.current.trim().replace(/\s+/g, " ");
84
+ return `${section.id.toUpperCase()} · ${words.length > 48 ? `${words.slice(0, 47).trimEnd()}…` : words}`;
85
+ }
84
86
  /**
85
87
  * What an audio note is `on`, in words, for export and the CLI (§17): the lane and variant
86
88
  * ("Music · Warm keys"), a cue ("Sound effects · Pass A · Cue · Swipe"), a take ("S2 · Take 1"), a
87
89
  * section ("S2"), the read ("Assembled read") or, on Mix, "Whole mix" / "Voiceover". Resolved in
88
90
  * the same order as the dashboard: the exact lane-qualified variant (`"<lane>/<variant>"`) or cue
89
91
  * (`"<lane>/<variant>:<cue>"`) first, then `"vo"`, a take (`"<section>:<take>"`), a section id, and
90
- * last the older bare forms (a bare variant id, `"<variant>:<cue>"` or a bare cue id). Null on
91
- * Picture and Script, or when `on` names nothing that's still there.
92
+ * last the older bare forms (a bare variant id, `"<variant>:<cue>"` or a bare cue id). On Script, the line a
93
+ * note is about (§27, 5.8: `on` is its section id), as "S2 · The scan finds it". Null on Picture, on a
94
+ * Script note with no line, or when `on` names nothing that's still there.
92
95
  */
93
96
  export function onLabel(note, ctx) {
94
97
  const { stage, on } = note;
98
+ if (stage === "script") {
99
+ const section = on === null ? undefined : ctx.script.sections.find((s) => s.id === on);
100
+ return section ? sectionLineLabel(section) : null;
101
+ }
95
102
  if (stage !== "voice" && stage !== "music" && stage !== "sfx" && stage !== "mix")
96
103
  return null;
97
104
  if (on === null)
@@ -147,6 +154,7 @@ export function onLabel(note, ctx) {
147
154
  export function filterNotes(notes, f = {}) {
148
155
  return notes.filter((n) => (f.stage === undefined || n.stage === f.stage) &&
149
156
  (f.status === undefined || n.status === f.status) &&
157
+ (f.state === undefined || noteState(n) === f.state) &&
150
158
  (f.batch === undefined || n.batch === f.batch) &&
151
159
  (f.version === undefined || n.version === f.version) &&
152
160
  (f.format === undefined || (n.stage === "picture" && (n.format === f.format || (!f.onlyThisFormat && n.format === null)))));
@@ -0,0 +1,79 @@
1
+ const STAGES = ["voice", "music", "sfx"];
2
+ /** A sound's per-lane picks, as `lanes` has them now. */
3
+ function stagePicks(lanes, picks, stage) {
4
+ const out = {};
5
+ for (const l of lanes)
6
+ if (l.stage === stage && picks[l.id] !== undefined)
7
+ out[l.id] = picks[l.id];
8
+ return out;
9
+ }
10
+ /**
11
+ * The take in use for each sound, among the takes `project.lanes` holds: hand it the lanes ONE FILM
12
+ * hears (lanesForVideo), with that film's picks, and a take that is not on the film is never in use.
13
+ *
14
+ * 1. Nothing stored, or the stored take is gone from these lanes: the newest lane of that sound with
15
+ * a pick that exists (the rule from before `use`). Its `at` is "".
16
+ * 2. Stored, and since it last saw them a pick in one of these lanes was set to another take that
17
+ * exists: an older Rushes did that (it knows only `lanes`), and the pick it made is the one in use.
18
+ * Of several, the newest lane's.
19
+ * 3. Stored, and its own lane still picks it: it stands, whatever was unpicked elsewhere.
20
+ * 4. Otherwise (its own lane's pick was cleared underneath it): rule 1.
21
+ */
22
+ export function inUse(project, picks) {
23
+ const out = {};
24
+ for (const stage of STAGES) {
25
+ const lanes = project.lanes.filter((l) => l.stage === stage);
26
+ const exists = (laneId, variantId) => variantId !== undefined && lanes.some((l) => l.id === laneId && l.variants.some((v) => v.id === variantId));
27
+ const newest = (wanted) => {
28
+ for (let i = lanes.length - 1; i >= 0; i--) {
29
+ const picked = picks.lanes[lanes[i].id];
30
+ if (exists(lanes[i].id, picked) && wanted(lanes[i]))
31
+ return { lane: lanes[i].id, variant: picked, at: "", seen: {} };
32
+ }
33
+ return undefined;
34
+ };
35
+ const stored = picks.use?.[stage];
36
+ let use;
37
+ // One with no time was only worked out (rule 1), never picked here: work it out again.
38
+ if (stored && stored.at !== "" && exists(stored.lane, stored.variant)) {
39
+ const seen = stored.seen ?? {};
40
+ use =
41
+ newest((l) => picks.lanes[l.id] !== seen[l.id] && !(l.id === stored.lane && picks.lanes[l.id] === stored.variant)) ??
42
+ (picks.lanes[stored.lane] === stored.variant ? stored : undefined);
43
+ }
44
+ use ??= newest(() => true);
45
+ if (use)
46
+ out[stage] = use;
47
+ }
48
+ return out;
49
+ }
50
+ /**
51
+ * Pick a take (or, with null, unpick its lane) in one film's picks. A take becomes the one in use for
52
+ * its sound; the lane's own pick is kept in step, which is all an older Rushes reads. Unpicking the
53
+ * lane in use clears it. Either way what stays in use re-records the picks it has seen, so an unpick
54
+ * in another round is never mistaken for an older Rushes at work.
55
+ */
56
+ export function setInUse(own, lanes, lane, variantId, now) {
57
+ const use = (own.use ??= {});
58
+ if (variantId === null) {
59
+ delete own.lanes[lane.id];
60
+ if (use[lane.stage]?.lane === lane.id)
61
+ delete use[lane.stage];
62
+ }
63
+ else {
64
+ own.lanes[lane.id] = variantId;
65
+ use[lane.stage] = { lane: lane.id, variant: variantId, at: now.toISOString(), seen: {} };
66
+ }
67
+ const kept = use[lane.stage];
68
+ if (kept)
69
+ kept.seen = stagePicks(lanes, own.lanes, lane.stage);
70
+ }
71
+ /** The lane and take in use for a sound, or null when there is none. */
72
+ export function inUseVariant(project, use, stage) {
73
+ const u = use[stage];
74
+ if (!u)
75
+ return null;
76
+ const lane = project.lanes.find((l) => l.id === u.lane && l.stage === stage);
77
+ const variant = lane?.variants.find((v) => v.id === u.variant);
78
+ return lane && variant ? { lane, variant } : null;
79
+ }
@@ -122,7 +122,7 @@ export function inferFilm(p, name, file) {
122
122
  return films.length === 1 ? films[0].id : undefined;
123
123
  }
124
124
  const LANE_NAMES = { voice: "Voiceover", music: "Music", sfx: "Sound effects" };
125
- export function addVariant(p, input) {
125
+ export function addVariant(p, input, now = new Date()) {
126
126
  // The film and (§23) the cues first, so an unknown film or a cue refused for its file leaves the
127
127
  // project untouched.
128
128
  const videos = input.video === undefined ? [inferFilm(p, input.name, input.file)].filter((v) => v !== undefined) : filmIds(p, input.video);
@@ -148,12 +148,25 @@ export function addVariant(p, input) {
148
148
  file: input.file,
149
149
  meta: input.description === undefined ? { ...input.meta } : { ...input.meta, description: input.description },
150
150
  cues,
151
+ addedAt: now.toISOString(),
151
152
  };
152
153
  if (videos.length > 0)
153
154
  variant.videos = videos;
155
+ for (const film of videos)
156
+ recordMadeFor(p, variant, film);
157
+ // On no named film, it is still on the film of a one-film project (schema.ts onFilm): the commonest route.
158
+ if (videos.length === 0 && p.videos.length === 1)
159
+ recordMadeFor(p, variant, p.videos[0].id);
154
160
  lane.variants.push(variant);
155
161
  return { lane, variant };
156
162
  }
163
+ /** §27.6: note the cut `film` is on now as the one this take was made for. A film with no cut leaves no entry. */
164
+ function recordMadeFor(p, variant, film) {
165
+ const video = p.videos.find((v) => v.id === film);
166
+ const cut = video && latestVersion(video);
167
+ if (cut)
168
+ (variant.madeFor ??= {})[film] = cut.id;
169
+ }
157
170
  /** Film ids for one ref or several (id or name each), each once, in the order given. Throws on an unknown film. */
158
171
  function filmIds(p, refs) {
159
172
  return [...new Set((Array.isArray(refs) ? refs : [refs]).map((r) => resolveVideo(p, r).id))];
@@ -168,12 +181,24 @@ export function setVariantFilms(p, laneId, variantId, refs) {
168
181
  if (!lane || !variant)
169
182
  throw new NotFoundError("variant", `${laneId}/${variantId}`);
170
183
  const videos = filmIds(p, refs);
171
- const left = variantFilms(variant).filter((v) => !videos.includes(v));
184
+ const was = variantFilms(variant);
185
+ const left = was.filter((v) => !videos.includes(v));
172
186
  delete variant.video;
173
187
  if (videos.length > 0)
174
188
  variant.videos = videos;
175
189
  else
176
190
  delete variant.videos;
191
+ // §27.6: a film it joins records the cut it has now; one it stays on keeps what it had; one it leaves is forgotten.
192
+ for (const film of videos)
193
+ if (!was.includes(film) && variant.madeFor?.[film] === undefined)
194
+ recordMadeFor(p, variant, film);
195
+ if (variant.madeFor) {
196
+ for (const film of Object.keys(variant.madeFor))
197
+ if (!videos.includes(film))
198
+ delete variant.madeFor[film];
199
+ if (Object.keys(variant.madeFor).length === 0)
200
+ delete variant.madeFor;
201
+ }
177
202
  return { lane, variant, left };
178
203
  }
179
204
  const FILE_NAME_MAX = 120;
@@ -106,6 +106,13 @@ export const VariantSchema = fileObject({
106
106
  videos: z.array(id).optional(),
107
107
  // The one film an older project named (0.7.x). Read as `videos: [video]`; set films replace it.
108
108
  video: id.optional(),
109
+ // §27.6, all absent on a take from before it. When it arrived:
110
+ addedAt: z.string().optional(),
111
+ // the cut that was current, per film it is on (film id -> version id), so a take made for an
112
+ // older cut can be told from one made for this one. No entry for a film that had no cut then.
113
+ madeFor: z.record(z.string(), z.string()).optional(),
114
+ // and when it was put away (hidden, never deleted).
115
+ putAway: z.string().optional(),
109
116
  });
110
117
  export const LaneSchema = fileObject({
111
118
  id,
@@ -275,9 +282,17 @@ export const LEVEL_STEP = 0.5;
275
282
  export const LevelsSchema = fileObject({ voice: z.number(), music: z.number(), sfx: z.number() }).partial().default({});
276
283
  // What one film hears: its own pick per lane and its own Mix levels. Music, sound effects, the
277
284
  // voiceover read and the levels belong to a film, so a second film never inherits the first's.
285
+ /**
286
+ * §27.6: the one read, bed or effects pass in use for a sound, and when it was picked. `seen` is that
287
+ * sound's per-lane picks as they stood right after the pick: an older Rushes knows only `lanes`, so a
288
+ * pick it makes shows up as `lanes` no longer matching `seen`, and its own rule then decides (picks.ts).
289
+ */
290
+ export const UseSchema = fileObject({ lane: id, variant: id, at: z.string(), seen: z.record(z.string(), z.string()).default({}) });
291
+ export const InUseSchema = fileObject({ voice: UseSchema, music: UseSchema, sfx: UseSchema }).partial();
278
292
  export const VideoPicksSchema = fileObject({
279
293
  lanes: z.record(z.string(), z.string()).default({}),
280
294
  levels: LevelsSchema,
295
+ use: InUseSchema.optional(),
281
296
  });
282
297
  export const PicksSchema = fileObject({
283
298
  schema: z.literal(1),
@@ -288,6 +303,9 @@ export const PicksSchema = fileObject({
288
303
  sections: z.record(z.string(), z.string()).default({}),
289
304
  // §19.6: each Mix lane's level in dB, defaulting to 0 (absent). Keyed the same as LaneStage.
290
305
  levels: LevelsSchema,
306
+ // §27.6: the take in use per sound. In this top-level place only for the picks of one film as
307
+ // picksForVideo hands them out (and a project from before picks were per film).
308
+ use: InUseSchema.optional(),
291
309
  // Each film's own picks and levels, keyed by video id. A film with no entry has picked nothing.
292
310
  videos: z.record(z.string(), VideoPicksSchema).default({}),
293
311
  });
@@ -296,7 +314,7 @@ export function picksForVideo(picks, videoId) {
296
314
  if (!videoId)
297
315
  return picks;
298
316
  const own = picks.videos[videoId];
299
- return { ...picks, lanes: { ...(own?.lanes ?? {}) }, levels: { ...(own?.levels ?? {}) }, sections: {}, videos: {} };
317
+ return { ...picks, lanes: { ...(own?.lanes ?? {}) }, levels: { ...(own?.levels ?? {}) }, use: { ...(own?.use ?? {}) }, sections: {}, videos: {} };
300
318
  }
301
319
  /** The films a read, bed or pass is on: its `videos`, or an older project's one `video`, or none. */
302
320
  export function variantFilms(v) {
@@ -321,7 +339,7 @@ export function lanesForVideo(lanes, videoId, filmCount) {
321
339
  }
322
340
  export const BatchSchema = fileObject({
323
341
  id,
324
- // The tab the batch's items all come from, or null when it spans tabs (Send to agent sends every tab).
342
+ // The tab the batch's items all come from, or null when it spans tabs (Send sends every tab).
325
343
  stage: StageSchema.nullable(),
326
344
  noteIds: z.array(z.string()).default([]),
327
345
  sectionIds: z.array(z.string()).default([]),
@@ -1,3 +1,4 @@
1
+ import { statusAfterEdit } from "./approval.js";
1
2
  import { InvalidError, NotFoundError } from "./errors.js";
2
3
  import { uniqueId } from "./ids.js";
3
4
  /** Does this line fit its slot at reading speed? "tight" means over 80% of the slot. */
@@ -104,14 +105,17 @@ export function findSection(script, id) {
104
105
  throw new NotFoundError("section", id);
105
106
  return s;
106
107
  }
108
+ /** The user's edit to a section. A change to an approved section's words or direction reopens it (approval.ts). */
107
109
  export function editSection(script, id, edit) {
108
110
  const s = findSection(script, id);
111
+ const words = (x) => (x.proposed ?? x.current).trim();
112
+ const wordsChanged = (edit.proposed !== undefined && words({ proposed: edit.proposed, current: s.current }) !== words(s)) ||
113
+ (edit.direction !== undefined && edit.direction.trim() !== s.direction.trim());
114
+ s.status = statusAfterEdit(s.status, { wordsChanged, status: edit.status });
109
115
  if (edit.proposed !== undefined)
110
116
  s.proposed = edit.proposed;
111
117
  if (edit.direction !== undefined)
112
118
  s.direction = edit.direction;
113
- if (edit.status !== undefined)
114
- s.status = edit.status;
115
119
  return s;
116
120
  }
117
121
  export function addTake(script, sectionId, input) {
package/dist/core/tabs.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { STAGES } from "./schema.js";
2
2
  import { noteInPlay } from "./project.js";
3
+ import { noteState } from "./noteState.js";
3
4
  import { isChanged } from "./script.js";
4
5
  function laneHasVariants(p, stage) {
5
6
  return p.lanes.some((l) => l.stage === stage && l.variants.length > 0);
@@ -21,8 +22,8 @@ export function tabStates(p, s, n, v = { visuals: [] }) {
21
22
  };
22
23
  return STAGES.map((stage) => {
23
24
  // §26: a shelved film's open notes are kept but do not count.
24
- const notes = n.notes.filter((x) => x.stage === stage && x.status === "todo" && noteInPlay(x, p)).length;
25
+ const open = n.notes.filter((x) => x.stage === stage && x.status === "todo" && noteInPlay(x, p));
25
26
  const rows = stage === "script" ? s.sections.filter((x) => isChanged(x) || x.status === "flagged").length : 0;
26
- return { stage, unlocked: unlocked[stage], todo: notes + rows };
27
+ return { stage, unlocked: unlocked[stage], todo: open.length + rows, sent: open.filter((x) => noteState(x) === "sent").length };
27
28
  });
28
29
  }
@@ -0,0 +1,73 @@
1
+ // §27.6: what a read, bed or effects pass knows about itself, and putting one away. Pure (no Node
2
+ // imports), so the dashboard asks the same questions the server does.
3
+ import { InvalidError, NotFoundError } from "./errors.js";
4
+ import { inUse } from "./picks.js";
5
+ import { lanesForVideo, picksForVideo } from "./schema.js";
6
+ /** Made for an earlier cut of this film than the one it has now. False for a take that recorded none. */
7
+ export function madeForStale(variant, video) {
8
+ const made = variant.madeFor?.[video.id];
9
+ if (made === undefined)
10
+ return false;
11
+ const latest = video.versions[video.versions.length - 1];
12
+ return latest !== undefined && latest.id !== made;
13
+ }
14
+ /**
15
+ * Waiting to be chosen: it arrived after this sound's take in use was picked, or nothing is in use
16
+ * yet. A take in use that was only worked out (`at` "", from before picks recorded a time) counts as
17
+ * picked before anything dated. Never one that was put away, or one from before takes recorded a date.
18
+ */
19
+ export function isNewTake(variant, use) {
20
+ if (variant.addedAt === undefined || variant.putAway !== undefined)
21
+ return false;
22
+ return use === undefined || variant.addedAt > use.at;
23
+ }
24
+ /**
25
+ * Put a take away (hidden from the lists, never deleted) or bring it back. `usedOn` names the films
26
+ * it is the take in use on: one in use cannot be put away. Bringing back is never refused.
27
+ */
28
+ export function putAway(p, laneId, variantId, away, usedOn, now = new Date()) {
29
+ const variant = p.lanes.find((l) => l.id === laneId)?.variants.find((v) => v.id === variantId);
30
+ if (!variant)
31
+ throw new NotFoundError("variant", `${laneId}/${variantId}`);
32
+ if (!away) {
33
+ delete variant.putAway;
34
+ return variant;
35
+ }
36
+ if (usedOn.length > 0)
37
+ throw new InvalidError(`This one is in use on ${usedOn.join(", ")}. Choose another first.`);
38
+ variant.putAway = now.toISOString();
39
+ return variant;
40
+ }
41
+ export function takeState(variant, lane, use) {
42
+ if (use !== undefined && use.lane === lane && use.variant === variant.id)
43
+ return "in-use";
44
+ if (variant.putAway !== undefined)
45
+ return "put-away";
46
+ return isNewTake(variant, use) ? "new" : "earlier";
47
+ }
48
+ const SOUNDS = ["voice", "music", "sfx"];
49
+ /** Every take one film hears (no film: the whole project), per sound, newest round first, with its state. */
50
+ export function filmTakes(project, picks, videoId) {
51
+ const lanes = lanesForVideo(project.lanes, videoId, project.videos.length);
52
+ const use = inUse({ lanes }, picksForVideo(picks, videoId));
53
+ const video = videoId ? project.videos.find((v) => v.id === videoId) : undefined;
54
+ const out = { voice: [], music: [], sfx: [] };
55
+ for (const stage of SOUNDS) {
56
+ for (const l of [...lanes].reverse()) {
57
+ if (l.stage !== stage)
58
+ continue;
59
+ for (const v of l.variants) {
60
+ out[stage].push({
61
+ lane: l.id,
62
+ variant: v.id,
63
+ name: v.name,
64
+ round: l.name,
65
+ state: takeState(v, l.id, use[stage]),
66
+ madeFor: (video && v.madeFor?.[video.id]) ?? null,
67
+ stale: video ? madeForStale(v, video) : false,
68
+ });
69
+ }
70
+ }
71
+ }
72
+ return out;
73
+ }