rvlib-shipkit 2.20.0 → 2.22.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 (156) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/package.json +1 -1
  3. package/src/asks/asks-queue.ts +8 -7
  4. package/src/assets/kits/identity-kit.ts +158 -2
  5. package/src/checks/SK004-gitignore-policy.check.ts +6 -3
  6. package/src/cli/cmd_Bump.ts +3 -3
  7. package/src/cli/cmd_GlobalProcesses.ts +2 -107
  8. package/src/cli/cmd_Home.ts +1 -1
  9. package/src/cli/cmd_Overview.ts +2 -1
  10. package/src/cli/cmd_Rec.ts +349 -0
  11. package/src/cli/cmd_Releases.ts +42 -3
  12. package/src/cli/cmd_Review.ts +22 -13
  13. package/src/cli/cmd_Secret.ts +10 -3
  14. package/src/cli/cmd_Sign.ts +24 -0
  15. package/src/cli/cmd_Social.ts +57 -8
  16. package/src/cli/cmd_Sound.ts +17 -4
  17. package/src/cli/cmd_Trailer.ts +67 -1
  18. package/src/cli/family-pages.ts +1 -0
  19. package/src/cli/registry.ts +6 -1
  20. package/src/collections/collection-types.ts +1 -1
  21. package/src/collections/review.ts +23 -4
  22. package/src/core/agent-spawn.ts +4 -17
  23. package/src/core/code-lines.ts +49 -0
  24. package/src/core/discover-checks.ts +27 -3
  25. package/src/core/hard-reset.ts +34 -0
  26. package/src/core/layout.ts +6 -0
  27. package/src/core/raw-access.ts +3 -13
  28. package/src/core/throwaway-worktree.ts +72 -0
  29. package/src/home/app-sign.ts +98 -0
  30. package/src/home/gui-app/ShipkitGui.swift +35 -0
  31. package/src/home/gui-app.ts +31 -11
  32. package/src/home/home-routes.ts +6 -0
  33. package/src/home/pm-switch.ts +112 -0
  34. package/src/home/serve-web.ts +1 -1
  35. package/src/identities/identities.ts +17 -6
  36. package/src/media-kinds.ts +5 -3
  37. package/src/media-store/forget.ts +54 -0
  38. package/src/media-store/put.ts +4 -3
  39. package/src/media-store/space.ts +63 -24
  40. package/src/messages/brief.ts +3 -3
  41. package/src/messages/score.ts +2 -0
  42. package/src/recordings/delete.ts +19 -0
  43. package/src/recordings/edit.ts +231 -0
  44. package/src/recordings/load.ts +37 -0
  45. package/src/recordings/marks-draw.ts +111 -0
  46. package/src/recordings/marks-png.ts +25 -0
  47. package/src/recordings/marks.ts +138 -0
  48. package/src/recordings/media-kind.ts +67 -0
  49. package/src/recordings/model.ts +170 -0
  50. package/src/recordings/open.ts +33 -0
  51. package/src/recordings/place.ts +89 -0
  52. package/src/recordings/presets.ts +99 -0
  53. package/src/recordings/recorder-app/Capture.swift +510 -0
  54. package/src/recordings/recorder-app/Clip.swift +107 -0
  55. package/src/recordings/recorder-app/Editor.swift +39 -0
  56. package/src/recordings/recorder-app/Tray.swift +298 -0
  57. package/src/recordings/recorder-app/main.swift +859 -0
  58. package/src/recordings/recorder-app.ts +46 -0
  59. package/src/recordings/recorder.shipkit.ts +11 -0
  60. package/src/recordings/routes.ts +140 -0
  61. package/src/recordings/run-recorder.ts +40 -0
  62. package/src/recordings/share.ts +107 -0
  63. package/src/recordings/take.ts +146 -0
  64. package/src/recordings/view.ts +40 -0
  65. package/src/release/gate-checkout.ts +74 -0
  66. package/src/release/release-scope.ts +35 -26
  67. package/src/release/run-bump.ts +79 -37
  68. package/src/release/run-release.ts +67 -53
  69. package/src/releases/add.ts +38 -5
  70. package/src/releases/before.ts +31 -0
  71. package/src/releases/from-card.ts +105 -20
  72. package/src/releases/model.ts +100 -18
  73. package/src/releases/pictures.ts +29 -8
  74. package/src/repo-config.ts +7 -3
  75. package/src/review/http.ts +1 -1
  76. package/src/review/model.ts +12 -2
  77. package/src/review/stage-card.ts +1 -1
  78. package/src/review/store.ts +12 -2
  79. package/src/review/trailer-desk.ts +20 -0
  80. package/src/review/trailer-model.ts +67 -0
  81. package/src/review/trailer-routes.ts +98 -1
  82. package/src/review/trailer-voices.ts +144 -0
  83. package/src/review/watchers.ts +58 -1
  84. package/src/secrets/manager.ts +18 -1
  85. package/src/serve/hub-app/benign-errors.ts +22 -0
  86. package/src/serve/hub-app/hash-route.ts +27 -15
  87. package/src/serve/hub-app/home-st.ts +23 -5
  88. package/src/serve/hub-app/home.html +1 -0
  89. package/src/serve/hub-app/hub-app.tsx +8 -1
  90. package/src/serve/hub-app/icons.tsx +2 -0
  91. package/src/serve/hub-app/palette-st.ts +1 -0
  92. package/src/serve/hub-app/project-list.css +7 -2
  93. package/src/serve/hub-app/project-list.tsx +10 -0
  94. package/src/serve/hub-app/projects-svc.ts +17 -7
  95. package/src/serve/hub-app/recordings-st.ts +641 -0
  96. package/src/serve/hub-app/recordings-view.tsx +504 -0
  97. package/src/serve/hub-app/recordings.css +82 -0
  98. package/src/serve/hub-app/releases/releases-page.tsx +121 -28
  99. package/src/serve/hub-app/releases/releases-st.ts +46 -4
  100. package/src/serve/hub-app/releases.css +30 -3
  101. package/src/serve/hub-app/repo-sections.ts +1 -1
  102. package/src/serve/hub-app/repo-st.ts +16 -11
  103. package/src/serve/hub-app/review/clip-st.ts +3 -1
  104. package/src/serve/hub-app/review/kit.tsx +3 -3
  105. package/src/serve/hub-app/review/trailer-page.tsx +32 -6
  106. package/src/serve/hub-app/review/trailer-st.ts +184 -8
  107. package/src/serve/hub-app/review/trailer-timeline.tsx +39 -4
  108. package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
  109. package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
  110. package/src/serve/hub-app/review.css +90 -0
  111. package/src/serve/hub-app/social/comms-page.tsx +10 -5
  112. package/src/serve/hub-app/social/next-release.tsx +118 -0
  113. package/src/serve/hub-app/social/post-card.tsx +31 -3
  114. package/src/serve/hub-app/social/social-model.ts +6 -0
  115. package/src/serve/hub-app/social/social-st.ts +50 -1
  116. package/src/serve/hub-app/social.css +12 -0
  117. package/src/serve/hub-app/tree-build.ts +2 -0
  118. package/src/serve/project-gutter-route.ts +8 -0
  119. package/src/serve/project-gutter.ts +4 -2
  120. package/src/shipkit.ts +2 -2
  121. package/src/shot/box.ts +49 -22
  122. package/src/shot/browser-slot.ts +13 -3
  123. package/src/shot/client.ts +1 -1
  124. package/src/shot/film-box.ts +193 -117
  125. package/src/shot/shooter.ts +20 -8
  126. package/src/smoke/run-smoke.ts +8 -6
  127. package/src/social/compose.ts +14 -0
  128. package/src/social/desk-index.ts +49 -8
  129. package/src/social/discord-layout.ts +6 -2
  130. package/src/social/drafts.ts +1 -1
  131. package/src/social/kinds.ts +3 -2
  132. package/src/social/load.ts +42 -9
  133. package/src/social/publish/index.ts +27 -10
  134. package/src/social/publish/secret.ts +12 -4
  135. package/src/social/release-card.ts +69 -0
  136. package/src/social/release-stage.ts +173 -30
  137. package/src/social/routes.ts +7 -1
  138. package/src/social/stage.ts +45 -22
  139. package/src/trailer/bed.ts +111 -0
  140. package/src/trailer/build.ts +81 -38
  141. package/src/trailer/ffmpeg.ts +14 -0
  142. package/src/trailer/grammar.ts +32 -4
  143. package/src/trailer/graph.ts +12 -1
  144. package/src/trailer/look.ts +7 -0
  145. package/src/trailer/shot-plan.ts +75 -0
  146. package/src/trailer/shot-state.ts +191 -0
  147. package/src/trailer/sound/audio.ts +28 -0
  148. package/src/trailer/sound/brand.ts +53 -3
  149. package/src/trailer/sound/gen.ts +61 -2
  150. package/src/trailer/sound/index.ts +25 -11
  151. package/src/trailer/sound/presets.ts +86 -5
  152. package/src/trailer/sound/run.ts +1 -1
  153. package/src/trailer/sound/takes.ts +94 -0
  154. package/src/trailer/titles.ts +36 -0
  155. package/src/trailer/url.ts +1 -1
  156. package/src/veille/chrome.ts +6 -3
@@ -1,23 +1,31 @@
1
1
  // a release as the second source of a staged post (wiki tools/shipkit/social.md, A post staged): one draft for the
2
2
  // beat, a heading per venue the repo's social unit declares, the release's message under each, its notes in its angle,
3
- // its polish note raised. Its media is his pick, later, among the approved cards the release ships (a commit of theirs
4
- // in its range). Idempotent: one draft a release. A repo with no `release` headings stages nothing
3
+ // its polish note raised. Its media: the release file's pictures, each venue the one its place takes (`shotFor`): the
4
+ // safe one for the draft, a heading of its own where the place takes an nsfw one, and the nsfw twin of a venue that
5
+ // cannot (Discord's -nsfw channel), staged to wait for his Publish; else his pick, later, among the approved cards the
6
+ // release ships. Before all of them, the release card the brand draws (release-card.ts), the picture a heading with no
7
+ // media of its own attaches. Idempotent: one draft a release. A repo with no `release` headings stages nothing. Before
8
+ // the cut, Communications shows next.md as the same input loaded on a scratch copy (`previewNextRelease`), nothing written
5
9
  import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
6
10
  import { basename, dirname, join } from 'node:path'
7
- import { isPostRating, type PostRating } from '../identities/rating.ts'
11
+ import { loadIdentities } from '../identities/identities.ts'
12
+ import { isPostRating, POST_RATINGS, takes, type PostRating } from '../identities/rating.ts'
13
+ import { localPicture } from '../releases/pictures.ts'
14
+ import { ceilingAt, landing, placesOf } from './reach.ts'
8
15
  import { isApproved, verdictOf, type ReviewItem } from '../review/model.ts'
9
16
  import { stageablesOf, stageFileOf, type Stageable } from '../review/stage-card.ts'
10
17
  import { readAll, storeDir } from '../review/store.ts'
11
18
  import { threadsOf, type Thread } from '../review/threads.ts'
12
- import { changesOf, type Release } from '../releases/model.ts'
19
+ import { changesOf, NEXT, picturesOf, ratingOf, shotFor, type Picture, type Release } from '../releases/model.ts'
13
20
  import { hasReleases, readRelease } from '../releases/store.ts'
14
21
  import { gitBin } from '../core/git-bin.ts'
15
22
  import { setHeadingText } from './drafts.ts'
16
- import { DRAFT_NAME, draftsDir } from './load.ts'
23
+ import { DRAFT_NAME, draftsDir, type Draft } from './load.ts'
17
24
  import { parseFrontmatter, setMeta } from './md.ts'
18
- import { askPolish, dryLoad, mediaFile, stageDraft, type Staged } from './stage.ts'
25
+ import { releaseCard, type Card } from './release-card.ts'
26
+ import { askPolish, contextOf, draftText, dryLoad, mediaFile, stageDraft, stageDry, type Staged, type StageHeading, type StageInput, type StageMedia } from './stage.ts'
19
27
  import { stripCopy } from './strip.ts'
20
- import { guardWith, type SocialUnit } from './unit.ts'
28
+ import { guardWith, type ReleaseHeading, type SocialUnit } from './unit.ts'
21
29
  import { commitPaths } from './writes.ts'
22
30
 
23
31
  export type ReleaseAsk = {
@@ -60,41 +68,142 @@ export function noteLines(md: string): string[] {
60
68
  .map((l) => (/^[-*+]\s/.test(l) ? `- ${l.slice(2).trim()}` : l))
61
69
  }
62
70
 
71
+ type StageCtx = { speaksAs?: string; identitiesDir?: string | null }
72
+
73
+ const ctxOf = (unit: SocialUnit | null, o: StageCtx) => ({ unit, ...(o.speaksAs !== undefined ? { speaksAs: o.speaksAs } : {}), ...(o.identitiesDir !== undefined ? { identitiesDir: o.identitiesDir } : {}) })
74
+
75
+ /** a release's first picture, in the file's order, that a venue whose ceiling is `ceiling` shows; with `nsfw`, its first
76
+ * such picture rated above safe (what a venue that takes more shows that a safe one cannot); null, none */
77
+ function firstFor(file: Release, ceiling: PostRating, nsfw = false): Picture | null {
78
+ for (const ch of changesOf(file)) {
79
+ const s = shotFor(ch, ceiling)
80
+ if (s && (!nsfw || ratingOf(s.picture) !== 'safe')) return s.picture
81
+ }
82
+ return null
83
+ }
84
+
85
+ /** a release picture as a stage's media, its local file named by its rating and sha */
86
+ async function stagedPicture(root: string, p: Picture): Promise<StageMedia> {
87
+ const file = await localPicture(root, p.url)
88
+ return { file, name: `release-${ratingOf(p)}-${basename(file).slice(0, 12)}` }
89
+ }
90
+
91
+ /** each release heading with the picture its place takes (wiki tools/shipkit/social.md, A post staged): the draft's
92
+ * media is the release's first safe picture, which every place takes; an account heading whose place takes more gets
93
+ * the first nsfw picture its ceiling takes as its own, with its rating; and an account heading under the release's highest
94
+ * rating gets a twin, `name: nsfw`, on the place a message of that rating lands (Discord: its -nsfw channel), its
95
+ * nsfw picture. A group heading lands on many places, so it keeps the safe one */
96
+ async function venueMedia(root: string, file: Release | null, headings: readonly ReleaseHeading[], o: StageCtx): Promise<{ media: StageMedia | null; alt: string; headings: StageHeading[] }> {
97
+ const safe = file ? firstFor(file, 'safe') : null
98
+ const media = safe ? await stagedPicture(root, safe) : null
99
+ const top = file ? picturesOf({ shots: changesOf(file).flatMap((c) => c.shots) }).map(ratingOf).sort((a, b) => POST_RATINGS.indexOf(b) - POST_RATINGS.indexOf(a))[0] : undefined
100
+ if (file == null || top == null || top === 'safe') return { media, alt: safe?.alt ?? '', headings: [...headings] }
101
+ const c = await contextOf(root, { unit: null, ...(o.speaksAs !== undefined ? { speaksAs: o.speaksAs } : {}), ...(o.identitiesDir !== undefined ? { identitiesDir: o.identitiesDir } : {}) })
102
+ const ids = await loadIdentities({ ...(c.identitiesDir != null ? { dir: c.identitiesDir } : {}), cwd: root })
103
+ const accounts = ids.identities.find((i) => i.id === c.speaksAs)?.accounts ?? []
104
+ const out: StageHeading[] = []
105
+ for (const h of headings) {
106
+ const a = accounts.find((x) => x.id === h.id)
107
+ if (a == null) {
108
+ out.push(h)
109
+ continue
110
+ }
111
+ const errors: string[] = []
112
+ const places = placesOf(a, errors)
113
+ const ceiling = ceilingAt(a, places, h.place ?? '') ?? 'safe'
114
+ const own = firstFor(file, ceiling, true)
115
+ out.push(own ? { ...h, rating: ratingOf(own), media: await stagedPicture(root, own) } : h)
116
+ if (takes(ceiling, top)) continue
117
+ const l = landing({ name: a.name, place: h.place ?? '', ceiling: a.ceiling }, places, top)
118
+ if (!('place' in l) || l.place === (h.place ?? '')) continue
119
+ const twin = firstFor(file, ceilingAt(a, places, l.place) ?? 'safe', true)
120
+ if (twin) out.push({ id: h.id, name: 'nsfw', place: l.place, rating: ratingOf(twin), media: await stagedPicture(root, twin) })
121
+ }
122
+ return { media, alt: safe?.alt ?? '', headings: out }
123
+ }
124
+
125
+ /** what a release stages: its file's change titles when the repo keeps one (the notes handed in are only its fallback),
126
+ * else its notes' lines, its card and each venue's picture. The one builder of the stage and of its preview, so both
127
+ * write the same draft. A card that does not render leaves the draft without it, its reason in `warnings` */
128
+ async function releaseInput(root: string, ask: ReleaseAsk, file: Release | null, headings: readonly ReleaseHeading[], o: StageCtx, warnings: string[] = []): Promise<StageInput> {
129
+ const ref = `${ask.unit}@${ask.version}`
130
+ const lines = file ? changesOf(file).map((c) => `- ${c.title}`) : noteLines(ask.notes)
131
+ const m = await venueMedia(root, file, headings, o)
132
+ const fallback = noteLines(ask.message ?? '')[0] ?? noteLines(ask.notes)[0]
133
+ const card: Card | null = await releaseCard(root, { version: ask.version, release: file, ...(fallback ? { fallback: fallback.replace(/^- /, '') } : {}) }).catch((e: unknown) => {
134
+ warnings.push(`no release card: ${(e as Error).message}`)
135
+ return null
136
+ })
137
+ return {
138
+ source: { release: ref },
139
+ title: ask.title ?? (file?.title ? `${file.version}: ${file.title}` : `${ask.unit} ${ask.version}`),
140
+ text: (ask.message?.trim() ? noteLines(ask.message).join('\n') : lines.join('\n')) || `${ask.unit} ${ask.version} is out.`,
141
+ rating: 'safe',
142
+ status: 'draft',
143
+ headings: m.headings,
144
+ ...(m.media ? { media: m.media, alt: m.alt } : {}),
145
+ ...(card ? { cover: { file: card.file, name: card.name }, alt: card.alt } : {}),
146
+ angle: [`Staged from the release ${ref}${ask.tag ? ` (${ask.since ? `${ask.since}..` : ''}${ask.tag})` : ''}. Its notes:`, '', ...lines].join('\n'),
147
+ ...(ask.now ? { now: ask.now } : {}),
148
+ }
149
+ }
150
+
63
151
  /** one draft of the release, waiting in Communications: null when the unit declares no release headings; the draft
64
152
  * already staged for the same release when there is one, nothing written */
65
- export async function stageRelease(root: string, unit: SocialUnit | null, ask: ReleaseAsk, o: { speaksAs?: string; identitiesDir?: string | null } = {}): Promise<(Staged & { created: boolean }) | null> {
153
+ export async function stageRelease(root: string, unit: SocialUnit | null, ask: ReleaseAsk, o: StageCtx = {}): Promise<(Staged & { created: boolean }) | null> {
66
154
  const headings = unit?.release?.headings
67
155
  if (headings == null || headings.length === 0) return null
68
156
  const ref = `${ask.unit}@${ask.version}`
69
157
  const had = releaseDraft(root, ref)
70
158
  if (had != null) return { slug: had, files: [], draft: null, errors: [], created: false }
71
- // the release's file, when the repo keeps one, is its words: the notes handed in are only its fallback
72
- const file = releaseFileOf(root, ref)
73
- const lines = file ? changesOf(file).map((c) => `- ${c.title}`) : noteLines(ask.notes)
74
- const text = (ask.message?.trim() ? noteLines(ask.message).join('\n') : lines.join('\n')) || `${ask.unit} ${ask.version} is out.`
75
- const title = ask.title ?? (file?.title ? `${file.version}: ${file.title}` : `${ask.unit} ${ask.version}`)
76
- const r = await stageDraft(
77
- root,
78
- {
79
- source: { release: ref },
80
- title,
81
- text,
82
- rating: 'safe',
83
- status: 'draft',
84
- headings,
85
- angle: [`Staged from the release ${ref}${ask.tag ? ` (${ask.since ? `${ask.since}..` : ''}${ask.tag})` : ''}. Its notes:`, '', ...lines].join('\n'),
86
- ...(ask.now ? { now: ask.now } : {}),
87
- },
88
- { unit, ...(o.speaksAs !== undefined ? { speaksAs: o.speaksAs } : {}), ...(o.identitiesDir !== undefined ? { identitiesDir: o.identitiesDir } : {}) },
89
- )
159
+ const warnings: string[] = []
160
+ const input = await releaseInput(root, ask, releaseFileOf(root, ref), headings, o, warnings)
161
+ const r = await stageDraft(root, input, ctxOf(unit, o))
90
162
  // the range its media comes from, read back by Communications
91
163
  if (ask.tag) {
92
164
  const f = join(draftsDir(root), r.slug, 'draft.md')
93
165
  writeFileSync(f, setMeta(readFileSync(f, 'utf8'), 'range', `${ask.since ? `${ask.since}..` : ''}${ask.tag}`))
94
166
  commitPaths([f], `social: ${r.slug} names the range of ${ref}`)
95
167
  }
96
- await askPolish(root, r.slug, title, unit, 'release')
97
- return { ...r, created: true }
168
+ await askPolish(root, r.slug, input.title, unit, 'release')
169
+ return { ...r, errors: [...warnings, ...r.errors], created: true }
170
+ }
171
+
172
+ /** the release being filled as Communications shows it: next.md, and the draft a release would stage from it */
173
+ export type NextRelease = {
174
+ release: Release
175
+ /** `root@next`: the root unit, the only one with release files */
176
+ ref: string
177
+ headings: readonly ReleaseHeading[]
178
+ /** the draft as `stageRelease` writes it, loaded from a scratch folder; null when the unit declares no headings */
179
+ draft: Draft | null
180
+ /** its draft.md; empty when the unit declares no headings */
181
+ text: string
182
+ /** the guard's and the load's lines about it */
183
+ errors: string[]
184
+ }
185
+
186
+ /** next.md as the release that cuts it would stage it, `version` still `next`: the same input as `stageRelease`, loaded
187
+ * by `stageDry` from a scratch folder, so nothing in the repo is written. Null without next.md; a next.md that does
188
+ * not parse throws */
189
+ export async function previewNextRelease(root: string, unit: SocialUnit | null, o: StageCtx & { now?: Date } = {}): Promise<NextRelease | null> {
190
+ const release = hasReleases(root) ? readRelease(root, NEXT) : null
191
+ if (release == null) return null
192
+ const headings = unit?.release?.headings ?? []
193
+ const ask: ReleaseAsk = { unit: 'root', version: NEXT, notes: '', ...(o.now ? { now: o.now } : {}) }
194
+ const ref = `${ask.unit}@${ask.version}`
195
+ if (headings.length === 0) return { release, ref, headings, draft: null, text: '', errors: [] }
196
+ // a picture the disk and the Space cannot give (offline) leaves the preview its words, and says why
197
+ const warnings: string[] = []
198
+ const fetched = await releaseInput(root, ask, release, headings, o, warnings).then(
199
+ (input) => ({ input, why: null }),
200
+ async (e: unknown) => ({ input: await releaseInput(root, ask, null, headings, o, warnings).then((i) => ({ ...i, text: changesOf(release).map((c) => `- ${c.title}`).join('\n') || i.text })), why: `its pictures: ${(e as Error).message}` }),
201
+ )
202
+ const { input } = fetched
203
+ const r = await stageDry(root, input, ctxOf(unit, o))
204
+ // `next` is no version yet: the load's line on the ref is the one a cut release never meets
205
+ const errors = [...r.errors.filter((e) => !e.includes(`release "${ref}"`)), ...(fetched.why ? [fetched.why] : []), ...new Set(warnings)]
206
+ return { release, ref, headings, draft: r.draft, text: draftText(input, input.media ? mediaFile(input.media) : null), errors }
98
207
  }
99
208
 
100
209
  /** the commits of a range, full shas; the range `a..b`, or a tag alone (every commit up to it) */
@@ -164,10 +273,44 @@ export async function releaseMedia(
164
273
  const c = { ...(o.unit !== undefined ? { unit: o.unit } : {}), ...(o.speaksAs !== undefined ? { speaksAs: o.speaksAs } : {}) }
165
274
  const problems = guardWith(o.unit, { alt: ask.alt ?? '', texts: ask.text ? [ask.text] : [], files: [file] })
166
275
  if (problems.length > 0 && !ask.dry) throw new Error(`the repo's guard refuses it: ${problems.join('; ')}`)
167
- if (ask.dry) return dryLoad(root, slug, raw, { name, file }, c)
276
+ if (ask.dry) {
277
+ // the media the draft holds already (a heading's own picture) beside the one picked
278
+ const dir = join(draftsDir(root), slug)
279
+ const had = existsSync(join(dir, 'media')) ? readdirSync(join(dir, 'media')).map((n) => ({ name: `media/${n}`, file: join(dir, 'media', n) })) : []
280
+ return dryLoad(root, slug, raw, [...had.filter((x) => x.name !== name), { name, file }], c)
281
+ }
168
282
  mkdirSync(dirname(join(draftsDir(root), slug, name)), { recursive: true })
169
283
  stripCopy(file, join(draftsDir(root), slug, name))
170
284
  writeFileSync(f, raw)
171
285
  commitPaths([f, join(draftsDir(root), slug, name)], `social: ${slug} takes the media of the card ${card.id}`)
172
286
  return { slug, files: [f], draft: null, errors: [] }
173
287
  }
288
+
289
+ /** a staged release draft given its card: rendered into its media/, first in its `media`, its `alt` the card's, the two
290
+ * files committed. `feature` a SAFE still (null, the poster; unset, the release file's first safe still) */
291
+ export async function releaseCardDraft(
292
+ root: string,
293
+ slug: string,
294
+ ask: { feature?: string | null; headline?: string; focus?: number } = {},
295
+ o: { unit?: SocialUnit | null } = {},
296
+ ): Promise<Card & { media: string; files: string[] }> {
297
+ const f = join(draftsDir(root), slug, 'draft.md')
298
+ if (!DRAFT_NAME.test(slug) || !existsSync(f)) throw new Error(`no draft ${slug}`)
299
+ let raw = readFileSync(f, 'utf8')
300
+ const ref = head(raw).release
301
+ const version = ref ? /^[^@]+@(.+)$/.exec(ref)?.[1] : undefined
302
+ if (version == null) throw new Error(`${slug} names no release: the card is a release post's picture`)
303
+ const card = await releaseCard(root, { version, release: releaseFileOf(root, ref), ...ask })
304
+ if (card == null) throw new Error('the repo has no .shipkit/identity/brand.ts: the card is drawn from its brand')
305
+ const problems = guardWith(o.unit, { alt: card.alt, texts: [card.headline], files: [card.file] })
306
+ if (problems.length > 0) throw new Error(`the repo's guard refuses it: ${problems.join('; ')}`)
307
+ const media = mediaFile({ file: card.file, name: card.name })
308
+ const had = (head(raw).media ?? '').split(',').map((x) => x.trim()).filter((x) => x !== '' && x !== media)
309
+ raw = setMeta(setMeta(raw, 'media', [media, ...had].join(', ')), 'alt', card.alt)
310
+ const at = join(draftsDir(root), slug, media)
311
+ mkdirSync(dirname(at), { recursive: true })
312
+ stripCopy(card.file, at)
313
+ writeFileSync(f, raw)
314
+ commitPaths([f, at], `social: ${slug} takes its release card`)
315
+ return { ...card, media, files: [f, at] }
316
+ }
@@ -12,7 +12,7 @@ import { isPostRating } from '../identities/rating.ts'
12
12
  import { noteLines, releaseCards, releaseMedia } from './release-stage.ts'
13
13
  import { readAllCached, storeDir } from '../review/store.ts'
14
14
  import { DRAFT_NAME, draftsDir, type Desk } from './load.ts'
15
- import { deskAnswer } from './desk-index.ts'
15
+ import { deskAnswer, nextReleaseAnswer } from './desk-index.ts'
16
16
  import { socialMediaBack, socialMediaUrl } from './media-kind.ts'
17
17
  import { openDesk } from './open.ts'
18
18
  import { openAll } from '../veille/chrome.ts'
@@ -65,6 +65,7 @@ export async function socialRoutes(root: string, req: Request, path: string): Pr
65
65
  try {
66
66
  if (req.method === 'GET') {
67
67
  if (sub === 'desk.json') return deskAnswer(req, root)
68
+ if (sub === 'next-release.json') return nextReleaseAnswer(req, root)
68
69
  if (sub === 'stats.json') {
69
70
  const { desk } = await openDesk(root)
70
71
  const out: Record<string, Record<string, string>> = {}
@@ -157,6 +158,11 @@ export async function socialRoutes(root: string, req: Request, path: string): Pr
157
158
  Bun.spawn(['open', '-R', file], { stdout: 'ignore', stderr: 'ignore' })
158
159
  return Response.json({ ok: true })
159
160
  }
161
+ if (sub === 'media-back') {
162
+ // a draft's media on the disk, brought back from the Space when the disk let it go: its path is pasted
163
+ const { desk } = await openDesk(root)
164
+ return Response.json({ path: await socialMediaBack(root, draftMedia(desk, str(b.slug, 'draft', DRAFT_NAME), str(b.name, 'media'))) })
165
+ }
160
166
  const { desk } = await openDesk(root)
161
167
  if (sub === 'posted') return Response.json({ files: setPosted(desk, str(b.slug, 'draft', DRAFT_NAME), str(b.key, 'message', KEY), urlOrNull(b.url)) })
162
168
  if (sub === 'live') return Response.json({ files: setLive(desk, str(b.identity, 'identity', ID), str(b.account, 'account', ID), urlOrNull(b.url)) })
@@ -36,6 +36,9 @@ export type StageInput = {
36
36
  /** his text, under each heading */
37
37
  text: string
38
38
  media?: StageMedia | null
39
+ /** a picture before the media, the one a heading with no media of its own attaches: a release's card */
40
+ cover?: StageMedia | null
41
+ /** the first media's description: the cover's when there is one */
39
42
  alt?: string
40
43
  rating: PostRating
41
44
  /** unset, its source's: `feature` from a card, `release` from a release (wiki guides/post-kinds/index.md) */
@@ -50,16 +53,28 @@ export type StageInput = {
50
53
  tags?: string
51
54
  angle: string
52
55
  /** the headings the text goes under; unset, `short` */
53
- headings?: readonly ReleaseHeading[]
56
+ headings?: readonly StageHeading[]
54
57
  now?: Date
55
58
  }
56
59
 
57
- export type Staged = { slug: string; files: string[]; draft: Draft | null; errors: string[] }
60
+ /** a heading a stage writes: a venue of the unit, and what only this message carries, its own media and rating (a
61
+ * release's nsfw picture on the venue that takes it), its `name` beside another message on the same account */
62
+ export type StageHeading = ReleaseHeading & { name?: string; rating?: PostRating; media?: StageMedia }
63
+
64
+ /** every media a stage copies: the draft's (its cover first), then each heading's own, once a name */
65
+ export function stageMedia(input: Pick<StageInput, 'media' | 'cover' | 'headings'>): { name: string; file: string }[] {
66
+ const all = [input.cover, input.media, ...(input.headings ?? []).map((h) => h.media)].filter((m): m is StageMedia => m != null)
67
+ const out = new Map<string, string>()
68
+ for (const m of all) out.set(mediaFile(m), m.file)
69
+ return [...out].map(([name, file]) => ({ name, file }))
70
+ }
71
+
72
+ export type Staged = { slug: string; files: string[]; draft: Draft | null; errors: string[]; /** a dry run's draft.md, as it would be written */ text?: string }
58
73
 
59
74
  const sourceLine = (s: StageSource): string => ('review' in s ? `review: ${s.review}` : `release: ${s.release}`)
60
75
 
61
76
  /** the kind a stage writes: the one asked, else its source's */
62
- const kindOf = (input: Pick<StageInput, 'kind' | 'source'>): string => input.kind?.trim() || sourceKind(input.source)
77
+ export const stagedKind = (input: Pick<StageInput, 'kind' | 'source'>): string => input.kind?.trim() || sourceKind(input.source)
63
78
 
64
79
  /** the name a staged media's copy takes in its draft, `media/<name>[-vertical].<ext>` */
65
80
  export const mediaFile = (m: StageMedia): string => {
@@ -67,16 +82,17 @@ export const mediaFile = (m: StageMedia): string => {
67
82
  return `media/${m.name}${m.vertical && ext === '.mp4' ? '-vertical' : ''}${ext === '.jpeg' ? '.jpg' : ext}`
68
83
  }
69
84
 
70
- /** the draft.md a stage writes, `media` its media name as the draft gives it */
85
+ /** the draft.md a stage writes, `media` its media name as the draft gives it, after its cover's */
71
86
  export function draftText(input: StageInput, media: string | null): string {
72
87
  const one = (v: string | undefined): string => (v ?? '').replace(/\s*\n\s*/g, ' ').trim()
88
+ const listed = [...(input.cover ? [mediaFile(input.cover)] : []), ...(media ? [media] : [])]
73
89
  const head = [
74
90
  `title: ${one(input.title)}`,
75
- `kind: ${kindOf(input)}`,
91
+ `kind: ${stagedKind(input)}`,
76
92
  ...(one(input.kindWhy) ? [`kindWhy: ${one(input.kindWhy)}`] : []),
77
93
  `status: ${input.status ?? 'picked'}`,
78
94
  `rating: ${input.rating}`,
79
- ...(media ? [`media: ${media}`] : []),
95
+ ...(listed.length ? [`media: ${listed.join(', ')}`] : []),
80
96
  ...(one(input.alt) ? [`alt: ${one(input.alt)}`] : []),
81
97
  ...(input.slot ? [`slot: ${input.slot}`] : []),
82
98
  sourceLine(input.source),
@@ -84,8 +100,14 @@ export function draftText(input: StageInput, media: string | null): string {
84
100
  const text = input.text.trim()
85
101
  if (/^## /m.test(text)) throw new Error('the text holds a "## " line: it would start a heading')
86
102
  const tags = one(input.tags)
87
- const opts = (h: ReleaseHeading, tagged: boolean): string => {
88
- const o = [...(h.place ? [`place: ${h.place}`] : []), ...(tagged && tags ? [`tags: ${tags}`] : [])]
103
+ const opts = (h: StageHeading, tagged: boolean): string => {
104
+ const o = [
105
+ ...(h.name ? [`name: ${h.name}`] : []),
106
+ ...(h.place ? [`place: ${h.place}`] : []),
107
+ ...(h.rating ? [`rating: ${h.rating}`] : []),
108
+ ...(h.media ? [`media: ${mediaFile(h.media)}`] : []),
109
+ ...(tagged && tags ? [`tags: ${tags}`] : []),
110
+ ]
89
111
  return o.length ? ` (${o.join(', ')})` : ''
90
112
  }
91
113
  const headings = input.headings ?? [{ id: 'short' }]
@@ -100,16 +122,16 @@ export const stageSlug = (title: string, now: Date): string => idOf(now, title)
100
122
  /** the guard's problems with what the stage would write, and its kind's: run before any file is. A stage never writes
101
123
  * an old word or a custom with no reason, so every kind problem refuses it */
102
124
  export function guardStage(unit: SocialUnit | null, input: StageInput): string[] {
103
- const kind = kindProblem(kindOf(input), input.kindWhy ?? '', unit?.kinds ?? [])
125
+ const kind = kindProblem(stagedKind(input), input.kindWhy ?? '', unit?.kinds ?? [])
104
126
  return [
105
- ...guardWith(unit, { title: input.title, alt: input.alt ?? '', texts: [input.text, ...(input.tags?.trim() ? [input.tags] : [])], files: input.media ? [input.media.file] : [] }),
127
+ ...guardWith(unit, { title: input.title, alt: input.alt ?? '', texts: [input.text, ...(input.tags?.trim() ? [input.tags] : [])], files: stageMedia(input).map((m) => m.file) }),
106
128
  ...(kind ? [kind.text] : []),
107
129
  ]
108
130
  }
109
131
 
110
132
  type Ctx = { unit: SocialUnit | null; speaksAs: string | undefined; identitiesDir?: string | null }
111
133
 
112
- async function contextOf(root: string, o: Partial<Ctx>): Promise<Ctx> {
134
+ export async function contextOf(root: string, o: Partial<Ctx>): Promise<Ctx> {
113
135
  const speaksAs = 'speaksAs' in o ? o.speaksAs : (await loadRepoConfig(root, { fresh: true }).catch(() => null))?.speaksAs
114
136
  const unit = 'unit' in o ? (o.unit ?? null) : await loadSocialUnit(root)
115
137
  // the folder is the real repo's house, resolved here: a dry run loads from a scratch folder that has none
@@ -130,13 +152,14 @@ export async function stageDry(root: string, input: StageInput, o: Partial<Ctx>
130
152
  const slug = stageSlug(input.title, input.now ?? new Date())
131
153
  // a vertical's name, so the load reads it as one, on a link to the very file
132
154
  const media = input.media ? mediaFile(input.media) : null
133
- const r = await dryLoad(root, slug, draftText(input, media), input.media && media ? { name: media, file: input.media.file } : null, c)
134
- return { ...r, errors: [...new Set([...guardStage(c.unit, input), ...r.errors])] }
155
+ const text = draftText(input, media)
156
+ const r = await dryLoad(root, slug, text, stageMedia(input), c)
157
+ return { ...r, text, errors: [...new Set([...guardStage(c.unit, input), ...r.errors])] }
135
158
  }
136
159
 
137
160
  /** one draft's text loaded from a scratch copy of the social folder (its rhythm, a link to its media): the desk's own
138
161
  * lines about it, its path left out of each */
139
- export async function dryLoad(root: string, slug: string, raw: string, media: { name: string; file: string } | null, o: Partial<Ctx> = {}): Promise<Staged> {
162
+ export async function dryLoad(root: string, slug: string, raw: string, media: readonly { name: string; file: string }[], o: Partial<Ctx> = {}): Promise<Staged> {
140
163
  const c = await contextOf(root, o)
141
164
  const scratch = mkdtempSync(join(tmpdir(), 'stage-dry-'))
142
165
  try {
@@ -144,9 +167,9 @@ export async function dryLoad(root: string, slug: string, raw: string, media: {
144
167
  mkdirSync(dir, { recursive: true })
145
168
  const rhythm = join(root, LAYOUT.social, 'rhythm.md')
146
169
  if (existsSync(rhythm)) copyFileSync(rhythm, join(scratch, LAYOUT.social, 'rhythm.md'))
147
- if (media) {
148
- mkdirSync(dirname(join(dir, media.name)), { recursive: true })
149
- symlinkSync(media.file, join(dir, media.name))
170
+ for (const m of media) {
171
+ mkdirSync(dirname(join(dir, m.name)), { recursive: true })
172
+ symlinkSync(m.file, join(dir, m.name))
150
173
  }
151
174
  writeFileSync(join(dir, 'draft.md'), raw)
152
175
  const { draft, errors } = await loadOne(scratch, slug, c)
@@ -201,7 +224,7 @@ export async function stageDraft(root: string, input: StageInput, o: Partial<Ctx
201
224
  const c = await contextOf(root, o)
202
225
  const problems = guardStage(c.unit, input)
203
226
  if (problems.length > 0) throw new Error(`the repo's guard refuses it: ${problems.join('; ')}`)
204
- if (input.media && !existsSync(input.media.file)) throw new Error(`no media ${input.media.file}`)
227
+ for (const m of stageMedia(input)) if (!existsSync(m.file)) throw new Error(`no media ${m.file}`)
205
228
  const slug = stageSlug(input.title, input.now ?? new Date())
206
229
  if (!DRAFT_NAME.test(slug)) throw new Error(`draft ${slug}?`)
207
230
  const dir = join(draftsDir(root), slug)
@@ -210,10 +233,10 @@ export async function stageDraft(root: string, input: StageInput, o: Partial<Ctx
210
233
  const files: string[] = []
211
234
  mkdirSync(dir, { recursive: true })
212
235
  try {
213
- if (input.media && media) {
214
- mkdirSync(join(dir, 'media'), { recursive: true })
215
- stripCopy(input.media.file, join(dir, media))
216
- files.push(join(dir, media))
236
+ for (const m of stageMedia(input)) {
237
+ mkdirSync(dirname(join(dir, m.name)), { recursive: true })
238
+ stripCopy(m.file, join(dir, m.name))
239
+ files.push(join(dir, m.name))
217
240
  }
218
241
  writeFileSync(join(dir, 'draft.md'), draftText(input, media))
219
242
  files.unshift(join(dir, 'draft.md'))
@@ -0,0 +1,111 @@
1
+ // a cut's sound without its voice lines (wiki tools/trailer/trailer-sound.md, Your own voice): the music, ducked under
2
+ // each line as the cut ducks it, and the sfx, so a take is heard over what it will sit in. The mix of the build with
3
+ // every voice at volume 0, at the cut's own level; `.shipkit/cache/trailer/bed/<key>.m4a`, the key its ffmpeg words.
4
+ // Beside it, the whole cut in his voice or its standin's, and one line's passage
5
+ import { existsSync, mkdirSync, renameSync, statSync } from 'node:fs'
6
+ import { join } from 'node:path'
7
+ import { houseRequests, load, soundsOf } from './build.ts'
8
+ import { ffmpeg } from './ffmpeg.ts'
9
+ import { trailerCache } from './footage.ts'
10
+ import { mixArgs } from './graph.ts'
11
+ import { soundStates } from './sound/index.ts'
12
+ import { PASSAGE_PAD, type Timeline } from '../review/trailer-model.ts'
13
+
14
+ /** the bed of the cut in `file`, made when the cache misses; refused while a paid line of the cut is not made yet, so
15
+ * a click on the hub never bills */
16
+ export async function voiceBed(root: string, file: string): Promise<string> {
17
+ const l = await load(file, root)
18
+ const unpaid = (await soundStates(root, houseRequests(l))).filter((s) => 'cost' in s && s.cost !== null)
19
+ if (unpaid.length > 0) throw new Error(`${unpaid.length} paid line${unpaid.length > 1 ? 's' : ''} of this cut ${unpaid.length > 1 ? 'are' : 'is'} not made yet: sk trailer makes ${unpaid.length > 1 ? 'them' : 'it'}, then the bed plays`)
20
+ const sounds = await soundsOf(l, l.t.shots, () => undefined)
21
+ const silent = { ...l.t, shots: l.t.shots.map((s) => ({ ...s, voices: s.voices.map((v) => ({ ...v, volume: 0 })) })) }
22
+ const dir = join(trailerCache(root, 'pieces'), '..', 'bed')
23
+ const probe = mixArgs({ t: silent, ...sounds }, '{out}')
24
+ const key = new Bun.CryptoHasher('sha1').update(probe.join('\0')).digest('hex').slice(0, 16)
25
+ const out = join(dir, `${key}.m4a`)
26
+ if (existsSync(out)) return out
27
+ mkdirSync(dir, { recursive: true })
28
+ const tmp = join(dir, `${key}.part-${process.pid}.m4a`)
29
+ await ffmpeg(mixArgs({ t: silent, ...sounds }, tmp))
30
+ renameSync(tmp, out)
31
+ return out
32
+ }
33
+
34
+
35
+ const voicing = new Map<string, Promise<VoicedCut>>()
36
+
37
+ export interface VoicedCut {
38
+ file: string
39
+ /** the file's name in the cache: what the hub's url names */
40
+ key: string
41
+ }
42
+
43
+ /** the render `video` of the cut in `file` with the cut's whole sound mixed again, his takes on (`takes`, the standin
44
+ * where he made none) or off (the standin on every line): the build's own sounds and mix, its picture copied beside
45
+ * it. `.shipkit/cache/trailer/voiced/<key>.mp4`, the key the render's time and the mix's own; one make at a time per
46
+ * side, so the player's range requests never start a second. Refused while a paid line of that side is not made, so a
47
+ * click on the hub never bills, and when the cut's length is no longer its render's */
48
+ export function voicedCut(root: string, file: string, video: string, takes: boolean, rendered: Timeline | null = null): Promise<VoicedCut> {
49
+ const id = `${file}\0${video}\0${statSync(video).mtimeMs}\0${takes}`
50
+ const going = voicing.get(id)
51
+ if (going) return going
52
+ const p = makeVoiced(root, file, video, takes, rendered).finally(() => voicing.delete(id))
53
+ voicing.set(id, p)
54
+ return p
55
+ }
56
+
57
+ /** `rendered`: the timeline the render was made from, so a cut edited since is refused rather than mixed off its
58
+ * picture */
59
+ async function makeVoiced(root: string, file: string, video: string, takes: boolean, rendered: Timeline | null): Promise<VoicedCut> {
60
+ const [{ durationOf }, { renderMix }, { total }, { timelineOf }] = await Promise.all([import('./ffmpeg.ts'), import('./stitch.ts'), import('./grammar.ts'), import('../review/trailer-desk.ts')])
61
+ const l = await load(file, root, { check: false })
62
+ if (l.errors.length > 0) throw new Error(`${l.errors.length} error${l.errors.length > 1 ? 's' : ''} in the cut: ${l.errors[0]!.message} (line ${l.errors[0]!.line})`)
63
+ if (l.t.vertical) throw new Error("a vertical cut lays its outro's sound after the mix: its voice toggle is not made")
64
+ const unpaid = (await soundStates(root, houseRequests(l), takes)).filter((s) => 'cost' in s && s.cost !== null)
65
+ if (unpaid.length > 0) throw new Error(`${unpaid.length} paid line${unpaid.length > 1 ? 's' : ''} of this side ${unpaid.length > 1 ? 'are' : 'is'} not made yet: sk trailer makes ${unpaid.length > 1 ? 'them' : 'it'}, then it plays`)
66
+ const [seconds, T] = [await durationOf(video), total(l.t)]
67
+ const now = timelineOf(l.t).shots
68
+ const moved = rendered?.shots.find((s, i) => s.name !== now[i]?.name || Math.abs(s.start - (now[i]?.start ?? -1)) > 1e-3)
69
+ if (Math.abs(seconds - T) > 0.1 || (rendered && rendered.shots.length !== now.length) || moved)
70
+ throw new Error(`the cut changed since its render${moved ? ` (shot ${moved.name})` : `: ${T.toFixed(2)} s now, ${seconds.toFixed(2)} s rendered`}: sk trailer renders it again, then both voices play`)
71
+ const mix = await renderMix({ t: l.t, ...(await soundsOf(l, l.t.shots, () => undefined, takes)), cache: trailerCache(root, 'pieces') })
72
+ const dir = join(trailerCache(root, 'pieces'), '..', 'voiced')
73
+ const key = new Bun.CryptoHasher('sha1').update(`${video}\0${statSync(video).mtimeMs}\0${mix.key}`).digest('hex').slice(0, 16)
74
+ const out = join(dir, `${key}.mp4`)
75
+ if (existsSync(out)) return { file: out, key }
76
+ mkdirSync(dir, { recursive: true })
77
+ const tmp = join(dir, `${key}.part-${process.pid}.mp4`)
78
+ await ffmpeg(['-i', video, '-i', mix.file, '-map', '0:v', '-map', '1:a', '-c', 'copy', '-movflags', '+faststart', tmp])
79
+ renameSync(tmp, out)
80
+ return { file: out, key }
81
+ }
82
+
83
+ /** a made voiced cut by its key; null when absent */
84
+ export function voicedFile(root: string, key: string): string | null {
85
+ if (!/^[0-9a-f]{16}$/.test(key)) return null
86
+ const f = join(trailerCache(root, 'pieces'), '..', 'voiced', `${key}.mp4`)
87
+ return existsSync(f) ? f : null
88
+ }
89
+
90
+ /** a voice line's passage as one file: the cut's picture from PASSAGE_PAD before the line to PASSAGE_PAD after its
91
+ * longer version, its bed under it, and one version of the line (`voice`, else none) at its place and volume. One
92
+ * element plays it all on one clock. `.shipkit/cache/trailer/passage/<key>.mp4`, the key its ffmpeg words and the
93
+ * render's time */
94
+ export async function voicePassage(root: string, o: { video: string; videoMtime: number; bed: string; at: number; seconds: number; total: number; voice: string | null; volume: number }): Promise<{ file: string; lead: number }> {
95
+ const lead = Math.min(PASSAGE_PAD, o.at)
96
+ const from = o.at - lead
97
+ const len = Math.min(o.total - from, lead + o.seconds + PASSAGE_PAD)
98
+ const n = (x: number): string => x.toFixed(3)
99
+ const voice = o.voice ? ['-i', o.voice] : []
100
+ const mix = o.voice ? `[2:a]aresample=48000,aformat=channel_layouts=stereo,volume=${n(o.volume)},adelay=${Math.round(lead * 1000)}:all=1[v];[1:a][v]amix=inputs=2:normalize=0:duration=first[a]` : '[1:a]anull[a]'
101
+ const args = (out: string): string[] => ['-ss', n(from), '-t', n(len), '-i', o.video, '-ss', n(from), '-t', n(len), '-i', o.bed, ...voice, '-filter_complex', mix, '-map', '0:v', '-map', '[a]', '-c:v', 'libx264', '-preset', 'veryfast', '-crf', '20', '-pix_fmt', 'yuv420p', '-c:a', 'aac', '-b:a', '192k', '-movflags', '+faststart', '-t', n(len), out]
102
+ const dir = join(trailerCache(root, 'pieces'), '..', 'passage')
103
+ const key = new Bun.CryptoHasher('sha1').update(`${o.videoMtime}\0${args('{out}').join('\0')}`).digest('hex').slice(0, 16)
104
+ const file = join(dir, `${key}.mp4`)
105
+ if (existsSync(file)) return { file, lead }
106
+ mkdirSync(dir, { recursive: true })
107
+ const tmp = join(dir, `${key}.part-${process.pid}.mp4`)
108
+ await ffmpeg(args(tmp))
109
+ renameSync(tmp, file)
110
+ return { file, lead }
111
+ }