rvlib-shipkit 2.19.0 → 2.21.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/CHANGELOG.md +32 -0
- package/package.json +1 -1
- package/src/annex/annex.ts +227 -0
- package/src/annex/offload.ts +279 -0
- package/src/checks/SK004-gitignore-policy.check.ts +6 -3
- package/src/checks/SK040-release-words.check.ts +43 -0
- package/src/checks/SK041-annex-links.check.ts +28 -0
- package/src/checks/SK042-post-kinds.check.ts +73 -0
- package/src/cli/cmd_Annex.ts +179 -0
- package/src/cli/cmd_Commands.ts +4 -1
- package/src/cli/cmd_GlobalProcesses.ts +2 -107
- package/src/cli/cmd_Home.ts +4 -3
- package/src/cli/cmd_Messages.ts +155 -0
- package/src/cli/cmd_Overview.ts +2 -1
- package/src/cli/cmd_Releases.ts +84 -0
- package/src/cli/cmd_Review.ts +176 -12
- package/src/cli/cmd_Shot.ts +4 -4
- package/src/cli/cmd_Social.ts +151 -8
- package/src/cli/cmd_Sound.ts +17 -4
- package/src/cli/cmd_Trailer.ts +67 -1
- package/src/cli/family-pages.ts +2 -0
- package/src/cli/kit/index.ts +1 -1
- package/src/cli/kit/verb.ts +11 -3
- package/src/cli/registry.ts +7 -1
- package/src/collections/collection-types.ts +8 -1
- package/src/collections/providers.ts +4 -1
- package/src/collections/review.ts +23 -4
- package/src/commands/model.ts +36 -0
- package/src/commands/registry.ts +49 -0
- package/src/commands/routes.ts +59 -0
- package/src/commands/runner.ts +35 -0
- package/src/commands/runs.ts +112 -0
- package/src/core/app-icon.ts +4 -3
- package/src/core/icon-type.ts +8 -0
- package/src/core/jobs.ts +4 -3
- package/src/core/layout.ts +11 -2
- package/src/core/squircle.ts +95 -0
- package/src/home/daemon-jobs.ts +26 -2
- package/src/home/global-units.ts +3 -0
- package/src/home/gui-app/ShipkitGui.swift +337 -5
- package/src/home/gui-app.ts +64 -33
- package/src/home/hmr-keep.ts +134 -0
- package/src/home/home-start.ts +2 -2
- package/src/home/lib-watch.ts +21 -11
- package/src/home/pm-switch.ts +112 -0
- package/src/home/pm.ts +1 -1
- package/src/home/process-apps.ts +181 -0
- package/src/home/resources.ts +3 -3
- package/src/home/run-web.ts +7 -4
- package/src/home/serve-web.ts +64 -14
- package/src/identities/collection.ts +49 -0
- package/src/identities/identities.ts +121 -14
- package/src/identities/machine.ts +4 -3
- package/src/identities/rating.ts +33 -0
- package/src/identities/shown.ts +170 -0
- package/src/identities/steps.ts +5 -0
- package/src/media-store/purge.ts +15 -1
- package/src/media-store/remote.ts +22 -6
- package/src/messages/brief.ts +117 -0
- package/src/messages/collection.ts +40 -0
- package/src/messages/model.ts +171 -0
- package/src/messages/routes.ts +15 -0
- package/src/messages/score.ts +182 -0
- package/src/messages/tabs.ts +13 -0
- package/src/release/notes.ts +130 -0
- package/src/release/run-bump.ts +41 -18
- package/src/release/run-release.ts +22 -4
- package/src/release/run-releases.ts +17 -15
- package/src/release/unit-resolve.ts +9 -0
- package/src/releases/add.ts +94 -0
- package/src/releases/before.ts +31 -0
- package/src/releases/collection.ts +36 -0
- package/src/releases/from-card.ts +151 -0
- package/src/releases/model.ts +327 -0
- package/src/releases/pictures.ts +110 -0
- package/src/releases/routes.ts +36 -0
- package/src/releases/store.ts +71 -0
- package/src/repo-config.ts +5 -0
- package/src/review/cells.ts +0 -11
- package/src/review/format.ts +10 -6
- package/src/review/http.ts +1 -1
- package/src/review/model.ts +102 -3
- package/src/review/notes.ts +2 -48
- package/src/review/routes.ts +28 -10
- package/src/review/stage-card.ts +197 -0
- package/src/review/stage-routes.ts +123 -0
- package/src/review/store.ts +47 -1
- package/src/review/trailer-card.ts +99 -0
- package/src/review/trailer-desk.ts +76 -4
- package/src/review/trailer-model.ts +106 -7
- package/src/review/trailer-notes.ts +45 -0
- package/src/review/trailer-routes.ts +119 -13
- package/src/review/trailer-voices.ts +144 -0
- package/src/review/watchers.ts +58 -1
- package/src/serve/hub-app/app-bridge.ts +71 -0
- package/src/serve/hub-app/benign-errors.ts +22 -0
- package/src/serve/hub-app/commands/commands-page.tsx +122 -0
- package/src/serve/hub-app/commands/commands-st.ts +177 -0
- package/src/serve/hub-app/commands.css +24 -0
- package/src/serve/hub-app/hash-route.ts +59 -8
- package/src/serve/hub-app/home-st.ts +19 -2
- package/src/serve/hub-app/home.html +3 -0
- package/src/serve/hub-app/hub-app.tsx +8 -0
- package/src/serve/hub-app/icons.tsx +5 -0
- package/src/serve/hub-app/identities-view.tsx +4 -1
- package/src/serve/hub-app/identities.css +1 -0
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/keys.ts +2 -2
- package/src/serve/hub-app/machine-st.ts +41 -10
- package/src/serve/hub-app/messages/messages-page.tsx +354 -0
- package/src/serve/hub-app/messages/messages-st.ts +74 -0
- package/src/serve/hub-app/messages.css +35 -0
- package/src/serve/hub-app/project-list.css +7 -2
- package/src/serve/hub-app/project-list.tsx +9 -0
- package/src/serve/hub-app/projects-svc.ts +16 -6
- package/src/serve/hub-app/releases/releases-page.tsx +187 -0
- package/src/serve/hub-app/releases/releases-st.ts +111 -0
- package/src/serve/hub-app/releases.css +52 -0
- package/src/serve/hub-app/repo-sections.ts +16 -2
- package/src/serve/hub-app/repo-st.ts +66 -10
- package/src/serve/hub-app/review/clip-st.ts +34 -4
- package/src/serve/hub-app/review/kit.tsx +3 -3
- package/src/serve/hub-app/review/note-place.ts +31 -0
- package/src/serve/hub-app/review/review-cells.tsx +27 -3
- package/src/serve/hub-app/review/review-st.ts +77 -2
- package/src/serve/hub-app/review/review-thread.tsx +9 -31
- package/src/serve/hub-app/review/review-views.tsx +164 -58
- package/src/serve/hub-app/review/thread-st.ts +108 -41
- package/src/serve/hub-app/review/trailer-card.tsx +187 -0
- package/src/serve/hub-app/review/trailer-page.tsx +92 -36
- package/src/serve/hub-app/review/trailer-st.ts +306 -34
- package/src/serve/hub-app/review/trailer-timeline.tsx +68 -23
- package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
- package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
- package/src/serve/hub-app/review.css +137 -6
- package/src/serve/hub-app/social/comms-page.tsx +65 -28
- package/src/serve/hub-app/social/identity-pictures.ts +46 -8
- package/src/serve/hub-app/social/kit.tsx +9 -6
- package/src/serve/hub-app/social/next-release.tsx +118 -0
- package/src/serve/hub-app/social/post-card.tsx +10 -2
- package/src/serve/hub-app/social/social-model.ts +39 -3
- package/src/serve/hub-app/social/social-page.tsx +179 -65
- package/src/serve/hub-app/social/social-st.ts +117 -27
- package/src/serve/hub-app/social/stage-popup.tsx +268 -0
- package/src/serve/hub-app/social/stage-st.ts +310 -0
- package/src/serve/hub-app/social/step-layout.ts +42 -0
- package/src/serve/hub-app/social.css +68 -1
- package/src/serve/hub-app/tree-build.ts +40 -1
- package/src/serve/hub-app/tree-svc.ts +10 -3
- package/src/serve/project-gutter-route.ts +12 -2
- package/src/serve/project-gutter.ts +4 -2
- package/src/serve/same-origin.ts +24 -1
- package/src/serve/serve-hub.ts +15 -1
- package/src/shipkit-files.ts +9 -7
- package/src/shot/box.ts +33 -12
- package/src/shot/client.ts +1 -1
- package/src/shot/shooter.ts +22 -12
- package/src/shot/shot-ask.ts +14 -3
- package/src/shot/shot.shipkit.ts +1 -1
- package/src/social/desk-index.ts +49 -8
- package/src/social/discord-layout.ts +54 -7
- package/src/social/drafts.ts +1 -1
- package/src/social/fit.ts +84 -0
- package/src/social/identity-words.ts +74 -0
- package/src/social/kind-pages.ts +41 -0
- package/src/social/kinds.ts +93 -0
- package/src/social/load.ts +125 -10
- package/src/social/media-limit.ts +63 -2
- package/src/social/presence.ts +1 -1
- package/src/social/publish/bluesky.ts +58 -19
- package/src/social/publish/index.ts +47 -6
- package/src/social/reach.ts +49 -0
- package/src/social/release-stage.ts +277 -0
- package/src/social/routes.ts +44 -8
- package/src/social/stage.ts +246 -0
- package/src/social/strip.ts +85 -0
- package/src/social/text.ts +6 -2
- package/src/social/unit.ts +57 -1
- package/src/social/writes.ts +11 -0
- package/src/trailer/bed.ts +111 -0
- package/src/trailer/build.ts +72 -40
- package/src/trailer/ffmpeg.ts +6 -0
- package/src/trailer/grammar.ts +37 -6
- package/src/trailer/graph.ts +12 -1
- package/src/trailer/public-words.ts +41 -0
- package/src/trailer/shot-plan.ts +75 -0
- package/src/trailer/shot-state.ts +191 -0
- package/src/trailer/sound/audio.ts +28 -0
- package/src/trailer/sound/brand.ts +53 -3
- package/src/trailer/sound/gen.ts +61 -2
- package/src/trailer/sound/index.ts +25 -11
- package/src/trailer/sound/presets.ts +86 -5
- package/src/trailer/sound/run.ts +1 -1
- package/src/trailer/sound/takes.ts +94 -0
- package/src/trailer/titles.ts +36 -0
- package/src/trailer/url.ts +1 -1
package/src/trailer/build.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { filmLineOf, type Recipe, takesOf, trailerCache } from './footage.ts'
|
|
|
8
8
|
import type { BrandLike, TrailerLook } from './look.ts'
|
|
9
9
|
import { fresh, isTake, movedParts, type Refilm, recipeWords, type Take, takeIsStill, takesToFilm, type World, type WorldState, worldFor } from './plan.ts'
|
|
10
10
|
import { decodeStates, edgeChanges } from './states.ts'
|
|
11
|
+
import { type CardAnswer, type CutPlan, shotStatus, type ShotStatus, statusText, summaryOf, summaryText, type TakeFact, type TakeFacts } from './shot-state.ts'
|
|
11
12
|
import { type CompiledScore, compileScore } from './score/score.ts'
|
|
12
13
|
import { GROW_RES, type Source, titleMotions } from './graph.ts'
|
|
13
14
|
import type { TitleMotion } from './motion.ts'
|
|
@@ -124,8 +125,21 @@ export async function load(file: string, root: string, o: { text?: string; dir?:
|
|
|
124
125
|
l.score = c.score
|
|
125
126
|
l.errors.push(...c.errors)
|
|
126
127
|
}
|
|
127
|
-
if (l.errors.length === 0 &&
|
|
128
|
-
|
|
128
|
+
if (l.errors.length === 0 && o.check !== false) {
|
|
129
|
+
// the cut's public words through the repo's one guard, beside the unit's own check
|
|
130
|
+
const { cutProblems, cutWords } = await import('./public-words.ts')
|
|
131
|
+
const { loadSocialUnit } = await import('../social/unit.ts')
|
|
132
|
+
const guarded = await loadSocialUnit(root).then(
|
|
133
|
+
(social) => {
|
|
134
|
+
const { words, unread } = cutWords(t, (p) => fileOf(p, l))
|
|
135
|
+
// with no guard there is nothing to read the voices with, and nothing to say about them
|
|
136
|
+
if (social?.guard != null) l.warnings.push(...unread.map((u) => ({ line: u.line, message: u.why })))
|
|
137
|
+
return cutProblems(social, words)
|
|
138
|
+
},
|
|
139
|
+
(e: Error) => [{ line: 1, message: `the social unit does not load, so no guard read the cut's words: ${e.message}` }],
|
|
140
|
+
)
|
|
141
|
+
if (l.unit?.check) for (const f of await l.unit.check(checkInput(l))) (f.warn ? l.warnings : l.errors).push({ line: f.line, message: f.message })
|
|
142
|
+
l.errors.push(...guarded)
|
|
129
143
|
l.warnings.sort((a, b) => a.line - b.line)
|
|
130
144
|
}
|
|
131
145
|
l.errors.sort((a, b) => a.line - b.line)
|
|
@@ -286,15 +300,15 @@ export function soundIds(t: Trailer): { line: number; kind: 'music' | 'sfx' | 'v
|
|
|
286
300
|
}
|
|
287
301
|
|
|
288
302
|
/** a sound that is no plain file: the repo's unit first (an id it knows), else the house's maker (a prompt, a run, a
|
|
289
|
-
* `.mid`, an id the unit answers null) */
|
|
290
|
-
export async function soundFile(l: Pick<Loaded, 'root' | 'file' | 'unit'>, req: SoundRequest, say: Say): Promise<string> {
|
|
303
|
+
* `.mid`, an id the unit answers null); `takes` forces his takes on or off (sound/index.ts brandSound) */
|
|
304
|
+
export async function soundFile(l: Pick<Loaded, 'root' | 'file' | 'unit'>, req: SoundRequest, say: Say, takes?: boolean): Promise<string> {
|
|
291
305
|
const unit = l.unit
|
|
292
306
|
const own = houseOnly(req) ? null : req.kind === 'music' ? unit?.sound?.music && ((x: string) => unit.sound!.music!(x, { ...(req.take ? { take: req.take } : {}), seconds: req.seconds ?? 0 })) : req.kind === 'sfx' ? unit?.sound?.sfx : unit?.sound?.voice
|
|
293
307
|
const got = own ? await own(req.text) : null
|
|
294
308
|
if (got) return got
|
|
295
309
|
const house = await houseSound()
|
|
296
310
|
if (!house) throw new Refused(`${relative(l.root, l.file)}:${req.line}: ${req.kind} ${req.run ? 'run' : req.prompt ? `"${req.text}"` : req.text} is no file, and neither a trailer unit (a <name>.shipkit.ts default-exporting trailer({ sound })) nor the house's sound maker makes it`)
|
|
297
|
-
return house.resolveSound(l.root, req, say)
|
|
311
|
+
return house.resolveSound(l.root, req, say, takes)
|
|
298
312
|
}
|
|
299
313
|
|
|
300
314
|
/** a request the repo's unit never sees: a prompt, a run, a `.mid` */
|
|
@@ -349,9 +363,9 @@ export async function soundLines(l: Loaded): Promise<string[]> {
|
|
|
349
363
|
}
|
|
350
364
|
|
|
351
365
|
/** the house's sound maker (design call 9, src/trailer/sound/index.ts), null until it exists */
|
|
352
|
-
async function houseSound(): Promise<{ resolveSound(root: string, req: SoundRequest, say: Say): Promise<string> } | null> {
|
|
366
|
+
async function houseSound(): Promise<{ resolveSound(root: string, req: SoundRequest, say: Say, takes?: boolean): Promise<string> } | null> {
|
|
353
367
|
const p = join(import.meta.dir, 'sound', 'index.ts')
|
|
354
|
-
return existsSync(p) ? ((await import(p)) as { resolveSound(root: string, req: SoundRequest, say: Say): Promise<string> }) : null
|
|
368
|
+
return existsSync(p) ? ((await import(p)) as { resolveSound(root: string, req: SoundRequest, say: Say, takes?: boolean): Promise<string> }) : null
|
|
355
369
|
}
|
|
356
370
|
|
|
357
371
|
/** the errors, which stop the build, then the warnings, which do not */
|
|
@@ -361,11 +375,6 @@ export function sayErrors(l: Loaded, say: Say, cwd: string): boolean {
|
|
|
361
375
|
return l.errors.length === 0
|
|
362
376
|
}
|
|
363
377
|
|
|
364
|
-
const ago = (iso: string): string => {
|
|
365
|
-
const m = Math.round((Date.now() - Date.parse(iso)) / 60_000)
|
|
366
|
-
return m < 60 ? `${m} min ago` : m < 48 * 60 ? `${Math.round(m / 60)} h ago` : `${Math.round(m / 1440)} days ago`
|
|
367
|
-
}
|
|
368
|
-
|
|
369
378
|
const filmText = (f: Film | null): string => {
|
|
370
379
|
if (!f) return 'nothing'
|
|
371
380
|
if (f.kind === 'clip' || f.kind === 'image') return `${f.kind} ${f.path}`
|
|
@@ -387,46 +396,68 @@ function edgesOf(s: Shot, tk: Take, fps: number, rule: TrailerUnit['states']): s
|
|
|
387
396
|
return found.length > 0 ? `, AT ITS EDGES: ${found.join('; ')}` : ''
|
|
388
397
|
}
|
|
389
398
|
|
|
390
|
-
/**
|
|
391
|
-
*
|
|
392
|
-
export function
|
|
399
|
+
/** each shot's and footage block's take against the world: filmed or not, when, the parts that moved since; what the
|
|
400
|
+
* timeline says and what the hub's trailer page reads (shot-plan.ts writeFacts) */
|
|
401
|
+
export function takeFactsOf(l: Pick<Loaded, 't'>, takes: readonly Take[], world: World | null, now = new Date()): TakeFacts {
|
|
402
|
+
const takeOf = (s: Shot): Take | undefined => takes.find((x) => x.shot === s)
|
|
403
|
+
const filmed = (s: Shot | undefined): boolean => s !== undefined && (!isTake(s.film) || takeOf(s)?.stamp != null)
|
|
404
|
+
const factOf = (s: Shot): TakeFact => {
|
|
405
|
+
const f = s.film
|
|
406
|
+
if (f?.kind === 'grid' || f?.kind === 'split') {
|
|
407
|
+
const cells = gridCells(l.t, f.cells)
|
|
408
|
+
const n = cells.filter(filmed).length
|
|
409
|
+
return { kind: 'grid', filmed: n === cells.length, cells: { of: cells.length, filmed: n } }
|
|
410
|
+
}
|
|
411
|
+
if (!isTake(f)) return { kind: f?.kind === 'card' ? 'drawn' : 'file', filmed: true }
|
|
412
|
+
const tk = takeOf(s)
|
|
413
|
+
if (!tk?.stamp) return { kind: 'take', filmed: false }
|
|
414
|
+
const w = world === null ? null : worldFor(world, tk)
|
|
415
|
+
return { kind: 'take', filmed: true, filmedAt: tk.stamp.filmedAt, ...(w && !fresh(tk.stamp, w) ? { moved: movedParts(tk.stamp, w) ?? [] } : {}) }
|
|
416
|
+
}
|
|
417
|
+
return { at: now.toISOString(), shots: Object.fromEntries([...l.t.shots, ...l.t.footage].map((s) => [s.name, factOf(s)])) }
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** the timeline with the cut's plan and its cards' answers; the takes' facts written for the hub's trailer page unless
|
|
421
|
+
* `record` is false (a draft's takes are not the cut's) */
|
|
422
|
+
export async function planTimeline(l: Loaded, takes: readonly Take[], world: World | null, cwd: string, record = true): Promise<string[]> {
|
|
423
|
+
const { cutIdOf, readPlan, cardAnswers, writeFacts } = await import('./shot-plan.ts')
|
|
424
|
+
const { trailer, cut } = cutIdOf(l.file)
|
|
425
|
+
if (record) writeFacts(l.root, trailer, cut, takeFactsOf(l, takes, world))
|
|
426
|
+
const plan = readPlan(l.root, trailer, cut)
|
|
427
|
+
return timeline(l, takes, world, cwd, { plan, cards: await cardAnswers(l.root, plan) })
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/** the timeline, one line a shot then one a footage block, each shot's state in plain words (shot-state.ts: the
|
|
431
|
+
* lanes' plan over its take), its take's details: when and on which world it was filmed, its last frame held, a
|
|
432
|
+
* change at its edges; then the cut at a glance */
|
|
433
|
+
export function timeline(l: Loaded, takes: readonly Take[], world: World | null, cwd: string, o: { plan?: CutPlan; cards?: (id: string) => CardAnswer | null } = {}): string[] {
|
|
393
434
|
const st = starts(l.t)
|
|
394
435
|
const out = [`${relative(cwd, l.file)}: ${l.t.shots.length} shots, ${total(l.t).toFixed(2)} s, ${l.t.size.join('x')} at ${l.t.fps} fps`]
|
|
395
436
|
const takeOf = (s: Shot): Take | undefined => takes.find((x) => x.shot === s)
|
|
437
|
+
const facts = takeFactsOf(l, takes, world)
|
|
438
|
+
const statusOf = (s: Shot): ShotStatus => {
|
|
439
|
+
const e = o.plan?.shots[s.name]
|
|
440
|
+
return shotStatus(e, facts.shots[s.name], e?.card ? (o.cards?.(e.card) ?? null) : null)
|
|
441
|
+
}
|
|
396
442
|
const line = (s: Shot, head: string): void => {
|
|
397
443
|
const tk = takeOf(s)
|
|
398
|
-
const
|
|
399
|
-
const
|
|
400
|
-
const
|
|
401
|
-
f?.kind === 'grid' || f?.kind === 'split'
|
|
402
|
-
? `a ${f.kind} of ${cells.length}, ${cells.filter((c) => c?.stamp).length} filmed`
|
|
403
|
-
: !isTake(f)
|
|
404
|
-
? f?.kind === 'card' ? 'drawn' : 'a file'
|
|
405
|
-
: !tk?.stamp
|
|
406
|
-
? 'NOT FILMED'
|
|
407
|
-
: world === null || fresh(tk.stamp, worldFor(world, tk))
|
|
408
|
-
? 'filmed'
|
|
409
|
-
: `filmed on an older world, ${ago(tk.stamp.filmedAt)}${movedText(movedParts(tk.stamp, worldFor(world, tk)))} (--refilm ${s.name})`
|
|
444
|
+
const status = statusOf(s)
|
|
445
|
+
const refilm = facts.shots[s.name]?.moved !== undefined ? ` (--refilm ${s.name})` : ''
|
|
446
|
+
const detail = status.detail.length > 0 ? ` · ${status.detail.join('; ')}${refilm}` : ''
|
|
410
447
|
const held = tk?.stamp && !takeIsStill(tk.film) && tk.stamp.seconds - s.from < s.length - 0.05 ? `, its last frame held ${(s.length - (tk.stamp.seconds - s.from)).toFixed(2)} s` : ''
|
|
411
448
|
const edges = tk ? edgesOf(s, tk, l.t.fps, l.unit?.states) : ''
|
|
412
449
|
const sec = s.section ? ` [section ${s.section.name} at ${+s.section.at.toFixed(3)} s]` : ''
|
|
413
450
|
const fit = s.written !== undefined ? ` (fitted, written ${s.written} s)` : ''
|
|
414
|
-
out.push(` ${head} ${s.name.padEnd(20)} ${s.length.toFixed(2).padStart(5)} s${fit} ${
|
|
451
|
+
out.push(` ${head} ${s.name.padEnd(20)} ${s.length.toFixed(2).padStart(5)} s${fit} ${statusText(status)}${detail}${held}${edges}${sec}`)
|
|
415
452
|
}
|
|
416
453
|
l.t.shots.forEach((s, i) => line(s, `${String(i + 1).padStart(2)} ${st[i]!.toFixed(2).padStart(6)} s `))
|
|
417
454
|
for (const s of l.t.footage) line(s, ' footage ')
|
|
418
455
|
const sc = l.score
|
|
419
456
|
if (sc) out.push(` score: ${sc.sections.length} sections, ${sc.notes.length} notes, ${(sc.seconds - SCORE_LEAD).toFixed(2)} s from the cut's ${(l.t.timelineAt ?? 0).toFixed(2)} s${sc.stop !== null ? `, cut dead at its ${(sc.stop - SCORE_LEAD).toFixed(2)} s` : ''}`)
|
|
457
|
+
out.push(` ${summaryText(summaryOf(l.t.shots.map((s) => ({ name: s.name, status: statusOf(s) }))))}`)
|
|
420
458
|
return out
|
|
421
459
|
}
|
|
422
460
|
|
|
423
|
-
/** the parts of the world that moved, as the timeline says them; nothing when the stamp kept no parts */
|
|
424
|
-
function movedText(parts: string[] | null): string {
|
|
425
|
-
if (parts === null || parts.length === 0) return ''
|
|
426
|
-
const shown = parts.slice(0, 4).join(', ')
|
|
427
|
-
return `: ${shown}${parts.length > 4 ? ` and ${parts.length - 4} more` : ''} moved`
|
|
428
|
-
}
|
|
429
|
-
|
|
430
461
|
function secs(x: number): string {
|
|
431
462
|
return `${+x.toFixed(2)} s`
|
|
432
463
|
}
|
|
@@ -535,9 +566,9 @@ export async function scoreFile(l: Loaded, seconds: number, say: Say): Promise<s
|
|
|
535
566
|
}
|
|
536
567
|
|
|
537
568
|
/** every sound the shots play, made where the house or the unit has to: the music cues, each shot's sfx and voices */
|
|
538
|
-
async function soundsOf(l: Loaded, shots: readonly Shot[], say: Say) {
|
|
569
|
+
export async function soundsOf(l: Loaded, shots: readonly Shot[], say: Say, takes?: boolean) {
|
|
539
570
|
const { durationOf } = await import('./ffmpeg.ts')
|
|
540
|
-
const resolve = (req: SoundRequest): Promise<string> => soundFile(l, req, say)
|
|
571
|
+
const resolve = (req: SoundRequest): Promise<string> => soundFile(l, req, say, takes)
|
|
541
572
|
const ask = (kind: SoundRequest['kind'], text: string, x: { prompt?: true; gen?: SoundGen; run?: SoundRun; line: number }, seconds?: number, take?: string): SoundRequest => soundRequest(kind, text, x, l.dir, seconds, take)
|
|
542
573
|
const music = await timed('sounds', () => Promise.all(
|
|
543
574
|
musicCues(l.t).map(({ cue, at, end }) => {
|
|
@@ -561,7 +592,7 @@ async function soundsOf(l: Loaded, shots: readonly Shot[], say: Say) {
|
|
|
561
592
|
/** everything the stitch reads but its output: sources, titles, sounds (`sounds` when the caller started them), the look */
|
|
562
593
|
async function stitchInput(l: Loaded, takes: readonly Take[], shots: readonly Shot[], silent: boolean, say: Say = () => undefined, sounds?: ReturnType<typeof soundsOf>) {
|
|
563
594
|
const { gridMask, splitMasks } = await import('./stitch.ts')
|
|
564
|
-
const [{ cardPng, titlePng }, { lookOf }, { durationOf }, { trailerCache }, { loadBrand, identityLogo }] = await Promise.all([
|
|
595
|
+
const [{ bandHeight, bandPng, cardPng, titlePng }, { lookOf }, { durationOf }, { trailerCache }, { loadBrand, identityLogo }] = await Promise.all([
|
|
565
596
|
import('./titles.ts'),
|
|
566
597
|
import('./look.ts'),
|
|
567
598
|
import('./ffmpeg.ts'),
|
|
@@ -571,8 +602,9 @@ async function stitchInput(l: Loaded, takes: readonly Take[], shots: readonly Sh
|
|
|
571
602
|
const brand = await loadBrand(l.root)
|
|
572
603
|
if (typeof brand === 'string') throw new Refused(brand)
|
|
573
604
|
const look = lookOf(brand, await identityLogo(l.root))
|
|
574
|
-
const base = { look, brand }
|
|
575
605
|
const titles = trailerCache(l.root, 'titles')
|
|
606
|
+
const b = l.t.band
|
|
607
|
+
const base = { look, brand, ...(b ? { band: { file: bandPng(titles, b.text, l.t.size, look, l.root), h: bandHeight(l.t.size[1]), over: b.over } } : {}) }
|
|
576
608
|
const pieces = trailerCache(l.root, 'pieces')
|
|
577
609
|
const takeOf = (s: Shot): Take | undefined => takes.find((x) => x.shot === s) ?? takes.find((x) => x.shot.name === s.name)
|
|
578
610
|
const sources = await Promise.all(shots.map(async (s): Promise<Source> => {
|
|
@@ -719,7 +751,7 @@ export async function build(l: Loaded, o: BuildOptions): Promise<string> {
|
|
|
719
751
|
}
|
|
720
752
|
}
|
|
721
753
|
if (!small) writeFileSync(join(outDir(l), `${l.t.name}.montage.md`), montage(l.t, basename(l.file)))
|
|
722
|
-
for (const line of
|
|
754
|
+
for (const line of await planTimeline(l, takes, world, o.cwd, !small)) o.say(line)
|
|
723
755
|
const what = small ? `a draft at ${small.size.join('x')}, ` : ''
|
|
724
756
|
o.say(`ok: ${out} (${what}${(finished?.seconds ?? total(lv.t)).toFixed(2)} s) in ${((performance.now() - t0) / 1000).toFixed(1)} s: filming ${((tFilm - t0) / 1000).toFixed(1)} s, ${rendered(done)}${finished ? `, ${finished.note}` : ''}`)
|
|
725
757
|
if (withStrip) o.say(`ok: ${stripFile}`)
|
package/src/trailer/ffmpeg.ts
CHANGED
|
@@ -88,6 +88,12 @@ export async function loudness(file: string): Promise<{ lufs: number; truePeak:
|
|
|
88
88
|
return { lufs, truePeak }
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
/** each channel's RMS level in dB, in channel order; a silent channel -120 */
|
|
92
|
+
export async function channelLevels(file: string): Promise<number[]> {
|
|
93
|
+
const log = await ffmpeg(['-nostats', '-loglevel', 'info', '-i', file, '-map', '0:a', '-af', 'astats=measure_overall=none:measure_perchannel=RMS_level', '-f', 'null', '-'])
|
|
94
|
+
return [...log.matchAll(/RMS level dB: (\S+)/g)].map((m) => (m[1] === '-inf' ? -120 : Math.max(-120, Number(m[1]))))
|
|
95
|
+
}
|
|
96
|
+
|
|
91
97
|
/** loudness() of a file that never changes under its name (a cached render), kept beside it */
|
|
92
98
|
export async function loudnessKept(file: string): Promise<{ lufs: number; truePeak: number }> {
|
|
93
99
|
const json = `${file}.loudness.json`
|
package/src/trailer/grammar.ts
CHANGED
|
@@ -137,6 +137,14 @@ export interface Vertical {
|
|
|
137
137
|
outro: 'card' | 'none' | { clip: string }
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
/** a thin band of words across the top of every frame (`band "<text>" [over]`): in a strip of its own, the picture
|
|
141
|
+
* scaled under it so it covers nothing; `over`: laid over the picture's top instead */
|
|
142
|
+
export interface Band {
|
|
143
|
+
line: number
|
|
144
|
+
text: string
|
|
145
|
+
over: boolean
|
|
146
|
+
}
|
|
147
|
+
|
|
140
148
|
/** the size a vertical short films at when the file names none */
|
|
141
149
|
export const VERTICAL_SIZE: [number, number] = [1080, 1920]
|
|
142
150
|
|
|
@@ -216,6 +224,9 @@ export interface SoundRun {
|
|
|
216
224
|
reads?: string[]
|
|
217
225
|
/** the work runs on another machine (ElevenLabs, the comfy box): it never waits on this machine's load */
|
|
218
226
|
remote?: true
|
|
227
|
+
/** the work is a second of ffmpeg on this machine (his take levelled): it never waits on the load either, which is
|
|
228
|
+
* for a render that loads it (FluidSynth) */
|
|
229
|
+
light?: true
|
|
219
230
|
}
|
|
220
231
|
|
|
221
232
|
export interface Sfx {
|
|
@@ -314,6 +325,9 @@ export interface Shot {
|
|
|
314
325
|
music: Music | null
|
|
315
326
|
/** its own line failed: nothing else is checked against it */
|
|
316
327
|
broken?: true
|
|
328
|
+
/** broken by its film line alone: its length and its place on the cut still hold, so a parse that does not know a
|
|
329
|
+
* film word (the hub's, with no project CLI) times the cut as the build does */
|
|
330
|
+
filmOnly?: true
|
|
317
331
|
/** a `footage` block: filmed, never cut in */
|
|
318
332
|
offcut?: true
|
|
319
333
|
}
|
|
@@ -407,6 +421,8 @@ export interface Trailer {
|
|
|
407
421
|
timelineAt: number | null
|
|
408
422
|
/** the cut is a vertical short (`vertical`), finished with the brand's lockup, watermark and end card */
|
|
409
423
|
vertical: Vertical | null
|
|
424
|
+
/** the band across the top of every frame (`band "<text>"`); null: none */
|
|
425
|
+
band: Band | null
|
|
410
426
|
/** the global process whose url a `film url` route resolves against (`base <id>`); null: the repo's one */
|
|
411
427
|
base: string | null
|
|
412
428
|
/** the music variants the file names, and the one it was read as (null: it names none) */
|
|
@@ -1062,7 +1078,7 @@ export function parseTrailer(text: string, o: ParseOptions = {}): { trailer: Tra
|
|
|
1062
1078
|
const verbs = o.verbs ?? null
|
|
1063
1079
|
const variants = variantsOf(text)
|
|
1064
1080
|
const variant = o.variant ?? variants[0] ?? null
|
|
1065
|
-
const t: Trailer = { name: '', footage: [], size: [1920, 1080], fps: 30, music: null, duck: -10, duckSfx: null, master: null, fadeIn: 0, shots: [], sections: [], score: null, timelineAt: null, vertical: null, base: null, variants, variant }
|
|
1081
|
+
const t: Trailer = { name: '', footage: [], size: [1920, 1080], fps: 30, music: null, duck: -10, duckSfx: null, master: null, fadeIn: 0, shots: [], sections: [], score: null, timelineAt: null, vertical: null, band: null, base: null, variants, variant }
|
|
1066
1082
|
/** a music line of another variant plays elsewhere; one of this variant takes the place of the line with none */
|
|
1067
1083
|
const mine = (m: Music, had: Music | null, what: string): boolean => {
|
|
1068
1084
|
if (m.variant !== undefined && m.variant !== variant) return false
|
|
@@ -1106,7 +1122,7 @@ export function parseTrailer(text: string, o: ParseOptions = {}): { trailer: Tra
|
|
|
1106
1122
|
if ('error' in tk) {
|
|
1107
1123
|
errors.push({ line: n, message: tk.error })
|
|
1108
1124
|
// its own line failed: the shot is not also told it films nothing
|
|
1109
|
-
if (shot && /^\s*film(\s|$)/.test(lines[n - 1]!)) shot
|
|
1125
|
+
if (shot && /^\s*film(\s|$)/.test(lines[n - 1]!)) filmFailed(shot)
|
|
1110
1126
|
continue
|
|
1111
1127
|
}
|
|
1112
1128
|
const ws = tk.words
|
|
@@ -1283,6 +1299,14 @@ export function parseTrailer(text: string, o: ParseOptions = {}): { trailer: Tra
|
|
|
1283
1299
|
t.vertical = { line: n, outro: (p.outro as Vertical['outro'] | undefined) ?? 'card', ...(p.mark ? { mark: p.mark as 'left' | 'right' } : {}) }
|
|
1284
1300
|
break
|
|
1285
1301
|
}
|
|
1302
|
+
case 'band': {
|
|
1303
|
+
once('band')
|
|
1304
|
+
const [text, ...more] = rest
|
|
1305
|
+
if (!text?.quoted || text.text.trim() === '' || more.some((w) => w.quoted || w.text !== 'over') || more.length > 1)
|
|
1306
|
+
bad(`band wants its words in quotes, then over or nothing (band "WIP - alpha version"), got ${rest.map((w) => (w.quoted ? `"${w.text}"` : w.text)).join(' ') || 'nothing'}`)
|
|
1307
|
+
t.band = { line: n, text: text!.text, over: more.length === 1 }
|
|
1308
|
+
break
|
|
1309
|
+
}
|
|
1286
1310
|
case 'preset': {
|
|
1287
1311
|
const name = word('preset', rest[0], /^[a-z][a-z0-9-]*$/)
|
|
1288
1312
|
if (presets.has(name)) bad(`preset ${name} is already a preset of this file`)
|
|
@@ -1333,7 +1357,7 @@ export function parseTrailer(text: string, o: ParseOptions = {}): { trailer: Tra
|
|
|
1333
1357
|
break
|
|
1334
1358
|
}
|
|
1335
1359
|
default:
|
|
1336
|
-
bad(`unknown word ${head.text} before the first shot (trailer, size, fps, music, duck, master, fade-in, vertical, base, preset, score, track, drums, section, defaults, shot)`)
|
|
1360
|
+
bad(`unknown word ${head.text} before the first shot (trailer, size, fps, music, duck, master, fade-in, vertical, band, base, preset, score, track, drums, section, defaults, shot)`)
|
|
1337
1361
|
}
|
|
1338
1362
|
continue
|
|
1339
1363
|
}
|
|
@@ -1504,7 +1528,7 @@ export function parseTrailer(text: string, o: ParseOptions = {}): { trailer: Tra
|
|
|
1504
1528
|
} catch (e) {
|
|
1505
1529
|
if (!(e instanceof LineError)) throw e
|
|
1506
1530
|
errors.push({ line: n, message: e.message })
|
|
1507
|
-
if (shot && head.text === 'film') shot
|
|
1531
|
+
if (shot && head.text === 'film') filmFailed(shot)
|
|
1508
1532
|
}
|
|
1509
1533
|
}
|
|
1510
1534
|
if (!seen.has('trailer')) errors.push({ line: 1, message: 'the file names its trailer first: trailer <name>' })
|
|
@@ -1567,6 +1591,12 @@ export function parseTrailer(text: string, o: ParseOptions = {}): { trailer: Tra
|
|
|
1567
1591
|
/** the least a fitted shot keeps past its cut out */
|
|
1568
1592
|
const FIT_MIN_S = 0.3
|
|
1569
1593
|
|
|
1594
|
+
/** a shot's film line failed: nothing more is checked against it, and when its own line held, its timing still does */
|
|
1595
|
+
function filmFailed(s: Shot): void {
|
|
1596
|
+
if (!s.broken) s.filmOnly = true
|
|
1597
|
+
s.broken = true
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1570
1600
|
/** a section's start, or a mark's moment, in the timeline's seconds; null when no section or mark has that name */
|
|
1571
1601
|
function momentOf(t: Pick<Trailer, 'sections'>, name: string): number | null {
|
|
1572
1602
|
for (const sec of t.sections) {
|
|
@@ -1584,8 +1614,9 @@ function momentOf(t: Pick<Trailer, 'sections'>, name: string): number | null {
|
|
|
1584
1614
|
*/
|
|
1585
1615
|
function landShots(t: Trailer): TrailerError[] {
|
|
1586
1616
|
const out: TrailerError[] = []
|
|
1617
|
+
const timed = (s: Shot): boolean => !s.broken || s.filmOnly === true
|
|
1587
1618
|
t.shots.forEach((s, i) => {
|
|
1588
|
-
if (s
|
|
1619
|
+
if (!timed(s)) return
|
|
1589
1620
|
const land = s.lands ?? (s.section ? { line: s.section.line, on: s.section.name, offset: 0 } : null)
|
|
1590
1621
|
if (!land) return
|
|
1591
1622
|
const moment = momentOf(t, land.on)
|
|
@@ -1599,7 +1630,7 @@ function landShots(t: Trailer): TrailerError[] {
|
|
|
1599
1630
|
return
|
|
1600
1631
|
}
|
|
1601
1632
|
const prev = t.shots[i - 1]
|
|
1602
|
-
if (!prev || prev
|
|
1633
|
+
if (!prev || !timed(prev)) {
|
|
1603
1634
|
out.push({ line: land.line, message: `shot ${s.name}: no shot before it to fit` })
|
|
1604
1635
|
return
|
|
1605
1636
|
}
|
package/src/trailer/graph.ts
CHANGED
|
@@ -51,6 +51,9 @@ export interface StitchInput {
|
|
|
51
51
|
/** each voice line's file and its length, shot by shot */
|
|
52
52
|
voices: { file: string; seconds: number }[][]
|
|
53
53
|
look: TrailerLook
|
|
54
|
+
/** the band across the top of every frame: its PNG (the frame's width, `h` tall); `over` the picture, else in a
|
|
55
|
+
* strip of its own with the picture scaled under it */
|
|
56
|
+
band?: { file: string; h: number; over: boolean }
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
const n3 = (x: number): string => (+x.toFixed(4)).toString()
|
|
@@ -293,7 +296,7 @@ export function titleMotions(t: Pick<Trailer, 'shots' | 'fps'> & Parameters<type
|
|
|
293
296
|
|
|
294
297
|
/** the ffmpeg arguments that render a piece's frames, no sound, and the row of its shots' middle frames for the
|
|
295
298
|
* contact strip (`thumbs`, when a middle falls in it) */
|
|
296
|
-
export function pieceArgs(a: Pick<StitchInput, 't' | 'sources' | 'titles' | 'look'>, p: Piece, out: string, encoder: Encoder = 'draft', thumbs?: string): string[] {
|
|
299
|
+
export function pieceArgs(a: Pick<StitchInput, 't' | 'sources' | 'titles' | 'look' | 'band'>, p: Piece, out: string, encoder: Encoder = 'draft', thumbs?: string): string[] {
|
|
297
300
|
const { t } = a
|
|
298
301
|
const [W, H] = t.size
|
|
299
302
|
const fps = t.fps
|
|
@@ -492,6 +495,14 @@ export function pieceArgs(a: Pick<StitchInput, 't' | 'sources' | 'titles' | 'loo
|
|
|
492
495
|
cur = `v${i}_${j}`
|
|
493
496
|
})
|
|
494
497
|
})
|
|
498
|
+
// the band over every frame, titles and the ending included; in its own strip the picture is scaled under it,
|
|
499
|
+
// centred, so the band covers no face and no row of a page
|
|
500
|
+
if (a.band) {
|
|
501
|
+
const k = input('-i', a.band.file)
|
|
502
|
+
const under = a.band.over ? '' : `scale=${even((W * (H - a.band.h)) / H)}:${H - a.band.h},pad=${W}:${H}:(ow-iw)/2:${a.band.h}:color=${ff(a.look.edge)},setsar=1,`
|
|
503
|
+
graph.push(`[${cur}]${under}format=yuv420p[under]`, `[under][${k}:v]overlay=x=0:y=0:eof_action=repeat[band]`)
|
|
504
|
+
cur = 'band'
|
|
505
|
+
}
|
|
495
506
|
graph.push(`[${cur}]trim=end_frame=${p.to - base},format=yuv420p,${TAGS}[vout]`)
|
|
496
507
|
|
|
497
508
|
// the contact strip's row: the middle frame of each shot whose middle is in the piece, side by side
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// a cut's public words through the repo's one guard (wiki tools/trailer/index.md, Its public words): each title and each
|
|
2
|
+
// voice line of a shot that is cut in, held to the rules of a public word by the social unit's `guard` (social/unit.ts
|
|
3
|
+
// guardWith), never a word list of the trailer's own. A recorded voice is read through its transcript beside the clip
|
|
4
|
+
// (`<clip>.txt`); one with none is said, so no spoken line passes unread in silence. A film line is how a take is made,
|
|
5
|
+
// never on screen: what its words turn on is the repo's own knowledge, read by its trailer unit's `check`
|
|
6
|
+
import { readFileSync } from 'node:fs'
|
|
7
|
+
import { guardWith, type GuardInput, type SocialUnit } from '../social/unit.ts'
|
|
8
|
+
import type { Trailer, TrailerError } from './grammar.ts'
|
|
9
|
+
|
|
10
|
+
/** one word of the cut a stranger reads or hears, at its line, as the guard reads it */
|
|
11
|
+
export type CutWord = { line: number; what: 'title' | 'voice line'; input: Partial<GuardInput> }
|
|
12
|
+
|
|
13
|
+
/** a voice the guard cannot read: a clip with no transcript beside it, a line a command makes */
|
|
14
|
+
export type Unread = { line: number; why: string }
|
|
15
|
+
|
|
16
|
+
const transcriptPath = (file: string): string => file.replace(/\.[^./]+$/, '.txt')
|
|
17
|
+
|
|
18
|
+
/** every title and voice line of the shots that are cut in, in line order, and the voices it cannot read; `find` finds
|
|
19
|
+
* a file as the cut finds its clips */
|
|
20
|
+
export function cutWords(t: Pick<Trailer, 'shots'>, find: (path: string) => string | null): { words: CutWord[]; unread: Unread[] } {
|
|
21
|
+
const words: CutWord[] = []
|
|
22
|
+
const unread: Unread[] = []
|
|
23
|
+
for (const s of t.shots) {
|
|
24
|
+
for (const ti of s.titles) if (ti.text.trim() !== '') words.push({ line: ti.line, what: 'title', input: { texts: [ti.text] } })
|
|
25
|
+
for (const v of s.voices) {
|
|
26
|
+
if (v.text != null && v.text.trim() !== '') words.push({ line: v.line, what: 'voice line', input: { texts: [v.text] } })
|
|
27
|
+
else if (v.file != null) {
|
|
28
|
+
const at = find(transcriptPath(v.file))
|
|
29
|
+
const said = at == null ? '' : readFileSync(at, 'utf8').trim()
|
|
30
|
+
if (said !== '') words.push({ line: v.line, what: 'voice line', input: { texts: [said] } })
|
|
31
|
+
else unread.push({ line: v.line, why: `voice file ${v.file}: no transcript beside it (${transcriptPath(v.file)}), so no guard read what it says` })
|
|
32
|
+
} else if (v.run != null) unread.push({ line: v.line, why: 'a voice a command makes: no guard read what it says' })
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return { words: words.sort((a, b) => a.line - b.line), unread }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** the guard's problems with a cut, each an error at its line; no unit or no guard, none */
|
|
39
|
+
export function cutProblems(unit: SocialUnit | null, words: readonly CutWord[]): TrailerError[] {
|
|
40
|
+
return words.flatMap((w) => guardWith(unit, w.input).map((p) => ({ line: w.line, message: `the repo's guard refuses this ${w.what}: ${p}` })))
|
|
41
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// a cut's plan and its takes' facts on disk (wiki tools/trailer/index.md, Shot states): the plan the lanes write through
|
|
2
|
+
// `sk trailer plan`, `.shipkit/trailer-plan/<trailer>/<cut>.json`, and the takes as the last build or check read them,
|
|
3
|
+
// `.shipkit/cache/trailer-takes/<trailer>--<cut>.json`, so the hub reads both without loading a cut. A plan write
|
|
4
|
+
// holds the file's lock over its read and write: two lanes marking at once both land
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync } from 'node:fs'
|
|
6
|
+
import { basename, dirname, join } from 'node:path'
|
|
7
|
+
import { LAYOUT } from '../core/layout.ts'
|
|
8
|
+
import { atomicWrite, withFileLock } from '../core/locked-write.ts'
|
|
9
|
+
import { isApproved, type ReviewItem, verdictOf } from '../review/model.ts'
|
|
10
|
+
import { type CardAnswer, markShots, parsePlan, type CutPlan, type PlanEntry, type TakeFacts } from './shot-state.ts'
|
|
11
|
+
|
|
12
|
+
export const planFile = (root: string, trailer: string, cut: string): string => join(root, LAYOUT.trailerPlan, trailer, `${cut}.json`)
|
|
13
|
+
export const factsFile = (root: string, trailer: string, cut: string): string => join(root, LAYOUT.cache, 'trailer-takes', `${trailer}--${cut}.json`)
|
|
14
|
+
|
|
15
|
+
/** a loaded cut's trailer folder and cut: `trailer/<trailer>/<cut>.trailer` */
|
|
16
|
+
export const cutIdOf = (file: string): { trailer: string; cut: string } => ({ trailer: basename(dirname(file)), cut: basename(file, '.trailer') })
|
|
17
|
+
|
|
18
|
+
/** the cut's plan, empty when no lane wrote one; a file that does not parse fails loud */
|
|
19
|
+
export function readPlan(root: string, trailer: string, cut: string): CutPlan {
|
|
20
|
+
const f = planFile(root, trailer, cut)
|
|
21
|
+
if (!existsSync(f)) return { shots: {} }
|
|
22
|
+
try {
|
|
23
|
+
return parsePlan(readFileSync(f, 'utf8'))
|
|
24
|
+
} catch (e) {
|
|
25
|
+
throw new Error(`${f}: ${(e as Error).message} (sk trailer plan writes it; delete it to start the plan again)`)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** these shots marked in the cut's plan, or their entries dropped (`mark` null); the plan as written */
|
|
30
|
+
export function writePlan(root: string, trailer: string, cut: string, shots: readonly string[], mark: Omit<PlanEntry, 'at'> | null, at = new Date().toISOString()): CutPlan {
|
|
31
|
+
const f = planFile(root, trailer, cut)
|
|
32
|
+
mkdirSync(dirname(f), { recursive: true })
|
|
33
|
+
for (let i = 0; i < 40; i++) {
|
|
34
|
+
const got = withFileLock(f, () => {
|
|
35
|
+
const next = markShots(readPlan(root, trailer, cut), shots, mark, at)
|
|
36
|
+
atomicWrite(f, `${JSON.stringify(next, null, 2)}\n`)
|
|
37
|
+
return next
|
|
38
|
+
})
|
|
39
|
+
if (got.ok) return got.value
|
|
40
|
+
Bun.sleepSync(50)
|
|
41
|
+
}
|
|
42
|
+
throw new Error(`${f} stayed locked by another writer for 2 s: nothing written`)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** the owner's answer on each card a plan names, read from the review store only when one names a card */
|
|
46
|
+
export async function cardAnswers(root: string, plan: CutPlan): Promise<(id: string) => CardAnswer | null> {
|
|
47
|
+
const ids = new Set(Object.values(plan.shots).flatMap((e) => (e.card ? [e.card] : [])))
|
|
48
|
+
if (ids.size === 0) return () => null
|
|
49
|
+
const { readItem, storeDir } = await import('../review/store.ts')
|
|
50
|
+
const got = new Map([...ids].map((id) => [id, answerOf(readItem(storeDir(root), id))]))
|
|
51
|
+
return (id) => got.get(id) ?? null
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** a card's answer as a shot's state reads it: null while he has not answered, or when the store has no such card */
|
|
55
|
+
export function answerOf(x: ReviewItem | null): CardAnswer | null {
|
|
56
|
+
const v = x ? verdictOf(x) : null
|
|
57
|
+
return v ? { status: v.status, approved: isApproved(v.status) } : null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function readFacts(root: string, trailer: string, cut: string): TakeFacts | null {
|
|
61
|
+
const f = factsFile(root, trailer, cut)
|
|
62
|
+
if (!existsSync(f)) return null
|
|
63
|
+
try {
|
|
64
|
+
return JSON.parse(readFileSync(f, 'utf8')) as TakeFacts
|
|
65
|
+
} catch {
|
|
66
|
+
// a cache file torn by hand: the next check writes it again
|
|
67
|
+
return null
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function writeFacts(root: string, trailer: string, cut: string, facts: TakeFacts): void {
|
|
72
|
+
const f = factsFile(root, trailer, cut)
|
|
73
|
+
mkdirSync(dirname(f), { recursive: true })
|
|
74
|
+
atomicWrite(f, `${JSON.stringify(facts)}\n`)
|
|
75
|
+
}
|