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,6 +1,7 @@
1
1
  // the trailer view's shapes (wiki tools/trailer/index.md, Frame notes): what the hub answers about a repo's cuts, and a frame
2
2
  // note as the view shows it, read from its item of the one store. Pure: the routes and the page share them
3
3
  import { isFrame, isReply, partyOf, stateOf, type ReviewItem } from './model.ts'
4
+ import type { CutStates } from '../trailer/shot-state.ts'
4
5
 
5
6
  export type NoteState = 'open' | 'done' | 'wontfix'
6
7
 
@@ -128,6 +129,8 @@ export interface ShotSpan {
128
129
  length: number
129
130
  section: string | null
130
131
  captions: CaptionSpan[]
132
+ /** the screen recorder's take it plays (`film recording <name>`): the page offers to shoot it again */
133
+ recording?: string
131
134
  }
132
135
 
133
136
  export interface SectionSpan {
@@ -169,6 +172,9 @@ export interface CutInfo {
169
172
  fileMtime: number
170
173
  /** a kept version (`versions/<v>.trailer` and `versions/<v>/`): it never changes */
171
174
  version: boolean
175
+ /** each shot of its timeline in plain words: ready, queued, filming, waiting on a card, not filmed (trailer/shot-state.ts);
176
+ * null with no timeline */
177
+ shots: CutStates | null
172
178
  }
173
179
 
174
180
  export interface TrailerInfo {
@@ -181,6 +187,67 @@ export interface TrailerDesk {
181
187
  trailers: TrailerInfo[]
182
188
  }
183
189
 
190
+ /** the seconds of picture a voice line's passage shows before the line starts, and after the longer of its versions
191
+ * (trailer/bed.ts voicePassage) */
192
+ export const PASSAGE_PAD = 1
193
+
194
+ /** one place a voice line is spoken: its cut, its line, its shot's span and its own start on the cut's timeline */
195
+ export interface VoiceUse {
196
+ cut: string
197
+ line: number
198
+ /** the .trailer file, repo relative */
199
+ file: string
200
+ shot: string
201
+ shotStart: number
202
+ shotEnd: number
203
+ /** seconds on the cut the line starts */
204
+ at: number
205
+ /** seconds it has before the next line starts, or the cut ends */
206
+ room: number
207
+ /** its `volume` in the cut */
208
+ volume: number
209
+ /** the brand voice it names, null for the brand's own */
210
+ by: string | null
211
+ /** it reads a recorded voice: his take, or a standin until he makes one */
212
+ mine: boolean
213
+ /** who the cut plays now, in words */
214
+ reader: string
215
+ /** the sound the cut plays now, its cache key; null until a build makes it */
216
+ made: string | null
217
+ /** a line of a recorded voice: who stands in, and its line's cache key whether it plays or not (null until made) */
218
+ standin: { name: string; made: string | null } | null
219
+ /** the cut's render on screen, null before its first */
220
+ video: { mtime: number } | null
221
+ }
222
+
223
+ /** one text of a trailer's lines: one take serves every use of the same words */
224
+ export interface VoiceLine {
225
+ /** the take's key: the words alone, tags and case dropped */
226
+ key: string
227
+ /** as written, tags included: a tag is how to say it */
228
+ text: string
229
+ words: string
230
+ /** the recorded voice his take is kept under; null when the brand has none */
231
+ voice: string | null
232
+ /** some use reads a recorded voice: it waits for him until he has a take */
233
+ mine: boolean
234
+ /** his take: the file he recorded; where its own 0 sits on the line's time (`dragged`: his, else at its first
235
+ * sound); the ranges of it he masked, in its own seconds; and the line made of it as the cut plays it, starting at
236
+ * the line's 0 (its cache key; null until made) */
237
+ take: { file: string; mtime: number; offset: number; dragged: boolean; mask: [number, number][]; made: string | null } | null
238
+ uses: VoiceUse[]
239
+ }
240
+
241
+ export interface VoicesDesk {
242
+ trailer: string
243
+ /** the brand's first recorded voice and his name, null when the brand has none */
244
+ recorder: { voice: string; who: string; takes: boolean } | null
245
+ lines: VoiceLine[]
246
+ /** lines of a recorded voice with no take yet */
247
+ waiting: number
248
+ errors: string[]
249
+ }
250
+
184
251
  /** the shot on screen at `t`: the last one started */
185
252
  export function shotAt(tl: Pick<Timeline, 'shots'>, t: number): ShotSpan | null {
186
253
  let out: ShotSpan | null = null
@@ -7,8 +7,11 @@ import { join, relative } from 'node:path'
7
7
  import { bad, NO_STORE, ranged } from './http.ts'
8
8
  import { ID_RE, isFrame } from './model.ts'
9
9
  import { act, appendMessage, deleteRaised, raiseItem, readAllCached, readItem } from './store.ts'
10
- import { cutOf, frameNote, frameStill, montagePage, pinnedRender, trailerDir, trailerIds, trailerInfo, videoOf, viewMedia } from './trailer-desk.ts'
10
+ import { cutOf, frameNote, frameStill, montagePage, pinnedRender, readView, trailerDir, trailerIds, trailerInfo, videoOf, viewMedia } from './trailer-desk.ts'
11
11
  import { CUT_RE, noteMarkOf, noteOf, TRAILER_ID_RE, type NoteMark, type NoteState, type TrailerDesk } from './trailer-model.ts'
12
+ import { madeFile, voicesDesk, voicesWaiting } from './trailer-voices.ts'
13
+ import { dropTake, setTakeEdit, writeTake, type TakeExt } from '../trailer/sound/takes.ts'
14
+ import type { Take } from '../trailer/sound/presets.ts'
12
15
 
13
16
  /** a note's mark as its message stores it: a review card's Rect */
14
17
  const rectsOf = (m: NoteMark) => [{ ...m, comment: '' }]
@@ -38,10 +41,104 @@ function noteAfter(dir: string, nid: string): Response {
38
41
  return note ? Response.json(note, { headers: NO_STORE }) : bad(`no note ${nid}`, 404)
39
42
  }
40
43
 
44
+ const TAKE_TYPES: Record<string, TakeExt> = { 'audio/webm': 'webm', 'audio/ogg': 'ogg', 'audio/mp4': 'm4a', 'audio/x-m4a': 'm4a', 'audio/wav': 'wav', 'audio/x-wav': 'wav', 'audio/mpeg': 'mp3', 'audio/flac': 'flac' }
45
+ const AUDIO_TYPE: Record<string, string> = { webm: 'audio/webm', ogg: 'audio/ogg', m4a: 'audio/mp4', mp4: 'audio/mp4', wav: 'audio/wav', mp3: 'audio/mpeg', flac: 'audio/flac' }
46
+
47
+ /** his take made as the cut will play it, the build's own run: its waveform and its sound on the page are the cut's */
48
+ async function makeTake(root: string, voice: string, text: string, take: Take): Promise<void> {
49
+ const [{ takeRun }, { soundRun }, { brandSound }, { voiceTweak }] = await Promise.all([import('../trailer/sound/presets.ts'), import('../trailer/sound/run.ts'), import('../trailer/sound/index.ts'), import('../trailer/sound/brand.ts')])
50
+ await soundRun(takeRun(text, take, voiceTweak(await brandSound(root), voice)), { root, dir: root }, () => undefined)
51
+ }
52
+
53
+ /** the Voices routes: the lines of a trailer, the sound a cut plays now, his take of a text (kept, played, edited,
54
+ * dropped) */
55
+ async function voiceRoutes(req: Request, path: string, root: string): Promise<Response | null> {
56
+ if (path === '/api/trailer/voices' && req.method === 'GET') return Response.json(await voicesWaiting(root), { headers: NO_STORE })
57
+ const made = /^\/api\/trailer\/voices\/made\/([0-9a-f]{16})\.wav$/.exec(path)
58
+ if (made && req.method === 'GET') {
59
+ const f = madeFile(root, made[1] ?? '')
60
+ return f ? ranged(req, f) : bad('that line is not made: sk trailer makes it', 404)
61
+ }
62
+ const passage = /^\/api\/trailer\/voices\/passage\/([^/]+)\/([0-9a-f]{12})\/([^/]+)\/(\d+)\/(ref|take|none)\.mp4$/.exec(path)
63
+ if (passage && req.method === 'GET') {
64
+ // one line's passage, picture and bed and one version of the line, as one file (trailer/bed.ts voicePassage)
65
+ const [, id = '', key = '', cut = '', lineNo = '', hear = 'none'] = passage
66
+ const tdir = trailerDir(root, id)
67
+ const c = tdir ? cutOf(tdir, cut) : null
68
+ const line = (await voicesDesk(root, id))?.lines.find((l) => l.key === key)
69
+ const use = line?.uses.find((u) => u.cut === cut && u.line === Number(lineNo))
70
+ if (!tdir || !c?.trailer || !line || !use?.video) return bad(`no rendered use of line ${key} in ${id}/${cut}:${lineNo}`, 404)
71
+ const media = await viewMedia(root, id, cut, use.video.mtime, 'video')
72
+ if (!media || !('path' in media)) return bad(`the render of ${cut} is not on this disk`, 404)
73
+ const ref = madeFile(root, (use.standin ? use.standin.made : use.made) ?? '')
74
+ const take = madeFile(root, line.take?.made ?? '')
75
+ const voice = hear === 'ref' ? ref : hear === 'take' ? take : null
76
+ if (hear !== 'none' && !voice) return bad(`no ${hear === 'ref' ? 'reference' : 'take'} of this line is made yet`, 404)
77
+ const [{ voiceBed, voicePassage }, { durationOf }] = await Promise.all([import('../trailer/bed.ts'), import('../trailer/ffmpeg.ts')])
78
+ const seconds = Math.max(0, ...(await Promise.all([ref, take].flatMap((f) => (f ? [durationOf(f)] : [])))))
79
+ const p = await voicePassage(root, { video: media.path, videoMtime: use.video.mtime, bed: await voiceBed(root, c.trailer), at: use.at, seconds, total: await durationOf(media.path), voice, volume: use.volume })
80
+ return ranged(req, p.file)
81
+ }
82
+ const voicedMp4 = /^\/api\/trailer\/voiced\/([0-9a-f]{16})\.mp4$/.exec(path)
83
+ if (voicedMp4 && req.method === 'GET') {
84
+ const { voicedFile } = await import('../trailer/bed.ts')
85
+ const f = voicedFile(root, voicedMp4[1] ?? '')
86
+ return f ? ranged(req, f) : bad('that voice of the cut is not made: the player asks for it first', 404)
87
+ }
88
+ const voiced = /^\/api\/trailer\/voiced\/([^/]+)\/([^/]+)\/(\d+)\/(takes|standin)$/.exec(path)
89
+ if (voiced && req.method === 'GET') {
90
+ // the whole cut in his voice or its standin's, its picture the render on screen (trailer/bed.ts voicedCut)
91
+ const [, id = '', cut = '', version = '', side = ''] = voiced
92
+ const tdir = TRAILER_ID_RE.test(id) && CUT_RE.test(cut) ? trailerDir(root, id) : null
93
+ const c = tdir ? cutOf(tdir, cut) : null
94
+ if (!c?.trailer || c.version) return bad(`${id}/${cut} is no working cut: only a working cut plays in either voice`, 404)
95
+ const media = await viewMedia(root, id, cut, Number(version), 'video')
96
+ if (!media || !('path' in media)) return bad(`the render of ${cut} at ${version} is not on this disk`, 404)
97
+ const { voicedCut } = await import('../trailer/bed.ts')
98
+ const v = await voicedCut(root, c.trailer, media.path, side === 'takes', readView(root, id, cut, Number(version))?.timeline ?? null)
99
+ return Response.json({ key: v.key }, { headers: NO_STORE })
100
+ }
101
+ const desk = /^\/api\/trailer\/voices\/([^/]+)$/.exec(path)
102
+ if (desk && req.method === 'GET') {
103
+ const d = await voicesDesk(root, desk[1] ?? '')
104
+ return d ? Response.json(d, { headers: NO_STORE }) : bad(`no trailer ${desk[1]}`, 404)
105
+ }
106
+ const take = /^\/api\/trailer\/voices\/([^/]+)\/take\/([0-9a-f]{12})(\/edit)?$/.exec(path)
107
+ if (!take) return null
108
+ const [, id = '', key = '', edit] = take
109
+ const d = await voicesDesk(root, id)
110
+ const line = d?.lines.find((l) => l.key === key)
111
+ if (!d || !line) return bad(`no line ${key} in trailer ${id}`, 404)
112
+ if (req.method === 'GET') {
113
+ if (!line.take) return bad('no take of that line yet', 404)
114
+ const ext = line.take.file.split('.').pop() ?? ''
115
+ return new Response(Bun.file(join(root, line.take.file)), { headers: { 'Content-Type': AUDIO_TYPE[ext] ?? 'application/octet-stream', ...NO_STORE } })
116
+ }
117
+ if (!line.voice) return bad("the brand has no voice of yours: add one to trailer.voices in .shipkit/identity/brand.ts, { record: '<your name>' }")
118
+ if (req.method === 'PUT') {
119
+ const type = (req.headers.get('content-type') ?? '').split(';')[0]?.trim() ?? ''
120
+ const ext = TAKE_TYPES[type]
121
+ if (!ext) return bad(`a take is audio (${Object.keys(TAKE_TYPES).join(', ')}), got ${type || 'no type'}`)
122
+ const file = writeTake(root, line.voice, line.text, new Uint8Array(await req.arrayBuffer()), ext)
123
+ await makeTake(root, line.voice, line.text, { path: relative(root, file), offset: null, mask: [] })
124
+ return Response.json({ ok: true, file: relative(root, file) }, { headers: NO_STORE })
125
+ }
126
+ if (req.method === 'POST' && edit) {
127
+ // his drag and his mask, kept beside the take, the line made again at once
128
+ const e = setTakeEdit(root, line.voice, line.text, await req.json())
129
+ await makeTake(root, line.voice, line.text, { path: line.take?.file ?? '', ...e })
130
+ return Response.json({ ok: true, ...e }, { headers: NO_STORE })
131
+ }
132
+ if (req.method === 'DELETE') return Response.json({ ok: dropTake(root, line.voice, line.text) }, { headers: NO_STORE })
133
+ return null
134
+ }
135
+
41
136
  export async function trailerRoutes(req: Request, path: string, root: string, dir: string): Promise<Response | null> {
42
137
  const API = '/api/trailer'
43
138
  if (path !== API && !path.startsWith(`${API}/`)) return null
44
139
  try {
140
+ const voices = await voiceRoutes(req, path, root)
141
+ if (voices) return voices
45
142
  if (path === API && req.method === 'GET') {
46
143
  const desk: TrailerDesk = { trailers: trailerIds(root).flatMap((id) => trailerInfo(root, id) ?? []) }
47
144
  return Response.json(desk, { headers: NO_STORE })
@@ -0,0 +1,144 @@
1
+ // the trailer page's Voices (wiki tools/trailer/trailer-sound.md, Your own voice): every `voice "<line>"` of a trailer's
2
+ // working cuts, one row a text, with the sound the cut plays now, his take, and where it sits in each cut. A line of a
3
+ // recorded voice he has not read yet is waiting: the count on the page, its trailer and the hub's trailer row
4
+ import { existsSync, statSync } from 'node:fs'
5
+ import { join, relative } from 'node:path'
6
+ import { recordVoices, type TrailerSoundInput, voiceTweak } from '../trailer/sound/brand.ts'
7
+ import { recordedLine, standinPreset, takeRun } from '../trailer/sound/presets.ts'
8
+ import { brandSound, repoTakes, runOf } from '../trailer/sound/index.ts'
9
+ import { runSpec, soundCache, soundRun } from '../trailer/sound/run.ts'
10
+ import { takeKey, takeOf, takeWords } from '../trailer/sound/takes.ts'
11
+ import { cutInfo, cutsOf, parseCut, timelineOf, trailerDir, trailerIds } from './trailer-desk.ts'
12
+ import type { VoiceLine, VoicesDesk, VoiceUse } from './trailer-model.ts'
13
+
14
+ /** a line's sound as the cut plays it now, or as its standin reads it: its cache key when it is made */
15
+ function madeKey(root: string, dir: string, text: string, by: string | undefined, seed: number | undefined, line: number, brand: TrailerSoundInput | undefined, standin = false): string | null {
16
+ try {
17
+ const req = { kind: 'voice' as const, text, ...(by ? { by } : {}), ...(seed !== undefined ? { seed } : {}), line, dir }
18
+ const run = standin ? standinPreset(req, brand) : runOf(root, req, brand)
19
+ if (!run) return null
20
+ const spec = runSpec(run, { root, dir })
21
+ return existsSync(spec.file) ? spec.key : null
22
+ } catch {
23
+ return null
24
+ }
25
+ }
26
+
27
+ /** the voices of one trailer folder; null when it is none */
28
+ export async function voicesDesk(root: string, id: string, brand?: TrailerSoundInput): Promise<VoicesDesk | null> {
29
+ const dir = trailerDir(root, id)
30
+ if (!dir) return null
31
+ const b = brand ?? (await brandSound(root).catch(() => undefined))
32
+ const recorders = recordVoices(b)
33
+ const errors: string[] = []
34
+ const byKey = new Map<string, VoiceLine>()
35
+ for (const c of cutsOf(dir)) {
36
+ if (c.version || !c.trailer) continue
37
+ let parsed
38
+ try {
39
+ parsed = parseCut(c.trailer).trailer
40
+ } catch (e) {
41
+ errors.push(`${c.cut}.trailer: ${(e as Error).message}`)
42
+ continue
43
+ }
44
+ const info = cutInfo(root, dir, id, c)
45
+ const own = timelineOf(parsed)
46
+ const tl = info.timeline ?? own
47
+ const spanOf = (name: string) => tl.shots.find((x) => x.name === name) ?? own.shots.find((x) => x.name === name)
48
+ // every line's start on the cut: a line has the room until the next one starts, or the cut ends
49
+ const starts = parsed.shots.flatMap((s) => (s.offcut ? [] : s.voices.map((v) => (spanOf(s.name)?.start ?? 0) + v.at))).sort((a, z) => a - z)
50
+ for (const s of parsed.shots) {
51
+ if (s.offcut) continue
52
+ const span = spanOf(s.name)
53
+ if (!span) continue
54
+ for (const v of s.voices) {
55
+ if (v.text === undefined || v.run) continue
56
+ const by = v.gen?.by
57
+ let rec = null
58
+ let reader: string
59
+ try {
60
+ rec = recordedLine({ text: v.text, ...(by ? { by } : {}) }, b, repoTakes(root))
61
+ const standin = rec?.standin.name ?? "the brand's voice"
62
+ reader = !rec ? (by ?? "the brand's voice") : rec.take ? rec.who : rec.kept ? `${standin}: takes off, ${rec.who}'s take kept` : `${standin}, standing in for ${rec.who}`
63
+ } catch (e) {
64
+ errors.push(`${c.cut}.trailer:${v.line}: ${(e as Error).message}`)
65
+ continue
66
+ }
67
+ const key = takeKey(v.text)
68
+ const use: VoiceUse = {
69
+ cut: c.cut,
70
+ line: v.line,
71
+ file: relative(root, c.trailer),
72
+ shot: s.name,
73
+ shotStart: span.start,
74
+ shotEnd: span.end,
75
+ at: span.start + v.at,
76
+ room: (starts.find((x) => x > span.start + v.at + 1e-6) ?? tl.total) - (span.start + v.at),
77
+ volume: v.volume,
78
+ by: by ?? null,
79
+ mine: rec !== null,
80
+ reader,
81
+ made: madeKey(root, c.trailer.replace(/\/[^/]+$/, ''), v.text, by, v.gen?.seed, v.line, b),
82
+ standin: rec ? { name: rec.standin.name ?? "the brand's voice", made: madeKey(root, c.trailer.replace(/\/[^/]+$/, ''), v.text, by, v.gen?.seed, v.line, b, true) } : null,
83
+ video: info.video ? { mtime: info.video.mtime } : null,
84
+ }
85
+ const row = byKey.get(key)
86
+ if (row) {
87
+ row.uses.push(use)
88
+ if (rec && !row.mine) row.voice = rec.voice
89
+ row.mine ||= use.mine
90
+ continue
91
+ }
92
+ byKey.set(key, { key, text: v.text, words: takeWords(v.text), voice: rec?.voice ?? recorders[0]?.name ?? null, mine: use.mine, take: null, uses: [use] })
93
+ }
94
+ }
95
+ }
96
+ const lines = [...byKey.values()]
97
+ for (const l of lines) {
98
+ const t = l.voice ? takeOf(root, l.voice, l.text) : null
99
+ const tweak = l.voice ? voiceTweak(b, l.voice) : undefined
100
+ const made = t ? runSpec(takeRun(l.text, t, tweak), { root, dir: root }) : null
101
+ // a take not made with this leveller or tweak yet (a new one, a take from before it) is made in the background:
102
+ // the next read draws and plays it
103
+ if (t && made && !existsSync(made.file)) void soundRun(takeRun(l.text, t, tweak), { root, dir: root }, () => undefined).catch((e: Error) => console.error(`FAIL: take ${l.key}: ${e.message}`))
104
+ l.take = t ? { file: t.path, mtime: t.mtime, offset: t.offset ?? (await autoOffsetKept(root, t)), dragged: t.offset !== null, mask: t.mask, made: made && existsSync(made.file) ? made.key : null } : null
105
+ }
106
+ const first = recorders[0]
107
+ return {
108
+ trailer: id,
109
+ recorder: first ? { voice: first.name, who: first.voice.record, takes: first.voice.takes !== false } : null,
110
+ lines,
111
+ waiting: lines.filter((l) => l.mine && !l.take).length,
112
+ errors,
113
+ }
114
+ }
115
+
116
+ /** each trailer folder's waiting lines, the brand read once; a repo with no trailer never loads its brand */
117
+ export async function voicesWaiting(root: string): Promise<Record<string, number>> {
118
+ if (trailerIds(root).length === 0) return {}
119
+ const b = await brandSound(root).catch(() => undefined)
120
+ if (recordVoices(b).length === 0) return {}
121
+ const out: Record<string, number> = {}
122
+ for (const id of trailerIds(root)) out[id] = (await voicesDesk(root, id, b))?.waiting ?? 0
123
+ return out
124
+ }
125
+
126
+ const autos = new Map<string, number>()
127
+
128
+ /** a take's offset when he never dragged it, as the build finds it (gen.ts autoOffset), read once a recording and mask */
129
+ async function autoOffsetKept(root: string, t: { path: string; mtime: number; mask: [number, number][] }): Promise<number> {
130
+ const key = `${t.path}\0${t.mtime}\0${JSON.stringify(t.mask)}`
131
+ const kept = autos.get(key)
132
+ if (kept !== undefined) return kept
133
+ const { autoOffset } = await import('../trailer/sound/gen.ts')
134
+ const o = await autoOffset(join(root, t.path), t.mask).catch(() => 0)
135
+ autos.set(key, o)
136
+ return o
137
+ }
138
+
139
+ /** a made line's file in the sound cache, by its key; null when absent */
140
+ export function madeFile(root: string, key: string): string | null {
141
+ if (!/^[0-9a-f]{16}$/.test(key)) return null
142
+ const f = join(soundCache(root), `${key}.wav`)
143
+ return existsSync(f) && statSync(f).isFile() ? f : null
144
+ }
@@ -1,6 +1,7 @@
1
1
  // who listens: each `sk review watch` registers one file per process beside the store (`.shipkit/review-watchers/`),
2
2
  // out of its watch, so a registration never wakes the watchers. A file alone is never trusted: its pid is probed
3
- import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'
3
+ import { spawnSync } from 'node:child_process'
4
+ import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync, writeSync } from 'node:fs'
4
5
  import { join } from 'node:path'
5
6
  import type { WatchFilter, Watcher } from './model.ts'
6
7
 
@@ -33,6 +34,62 @@ export function registerWatch(dir: string, filter: WatchFilter, now = new Date()
33
34
  })
34
35
  }
35
36
 
37
+ /** what a watch lives for: its parent at start, every process above it then, and the reader of its output */
38
+ export interface Owner {
39
+ parent: number
40
+ above: readonly number[]
41
+ }
42
+
43
+ /** the processes above `pid`, nearest first, launchd left out, from the lines of `ps -axo pid=,ppid=` */
44
+ export function ancestorsOf(pid: number, table: string): number[] {
45
+ const up = new Map<number, number>()
46
+ for (const line of table.split('\n')) {
47
+ const [p, pp] = line.trim().split(/\s+/).map(Number)
48
+ if (Number.isInteger(p) && Number.isInteger(pp)) up.set(p as number, pp as number)
49
+ }
50
+ const out: number[] = []
51
+ for (let p = up.get(pid); p !== undefined && p > 1 && !out.includes(p); p = up.get(p)) out.push(p)
52
+ return out
53
+ }
54
+
55
+ /** why the watch has no owner any more, else null */
56
+ export function ownerGone(o: Owner, now: { ppid: number; alive: (pid: number) => boolean; readerGone: boolean }): string | null {
57
+ if (now.ppid !== o.parent) return `its parent ${o.parent} is gone`
58
+ const dead = o.above.find((p) => !now.alive(p))
59
+ if (dead !== undefined) return `process ${dead} above it is gone`
60
+ return now.readerGone ? 'nothing reads its output' : null
61
+ }
62
+
63
+ /** a zero byte write to a pipe nobody reads fails with EPIPE on macOS (Linux answers 0: a real line's EPIPE ends it there) */
64
+ function readerGone(): boolean {
65
+ try {
66
+ writeSync(1, new Uint8Array(0))
67
+ return false
68
+ } catch (e) {
69
+ return (e as NodeJS.ErrnoException).code === 'EPIPE'
70
+ }
71
+ }
72
+
73
+ /** this process exits once its owner is gone, checked every `everyMs`: a killed agent's shell often lives on, waiting
74
+ * on a pipeline, so the parent alone is not enough */
75
+ export function exitWithOwner(everyMs = 2000): void {
76
+ const ps = spawnSync('ps', ['-axo', 'pid=,ppid='], { encoding: 'utf8' })
77
+ const owner: Owner = { parent: process.ppid, above: ancestorsOf(process.pid, ps.stdout ?? '') }
78
+ const end = (why: string): never => {
79
+ try {
80
+ process.stderr.write(`review watch: exits, ${why}\n`)
81
+ } catch {}
82
+ process.exit(0)
83
+ }
84
+ process.stdout.on('error', (e: NodeJS.ErrnoException) => {
85
+ if (e.code === 'EPIPE') end('nothing reads its output')
86
+ })
87
+ setInterval(() => {
88
+ const why = ownerGone(owner, { ppid: process.ppid, alive: pidAlive, readerGone: readerGone() })
89
+ if (why !== null) end(why)
90
+ }, everyMs)
91
+ }
92
+
36
93
  /** every live watcher, by pid; a file whose process is gone is deleted */
37
94
  export function liveWatchers(dir: string, alive: (pid: number) => boolean = pidAlive): Watcher[] {
38
95
  const folder = watchersDir(dir)
@@ -2,10 +2,12 @@
2
2
  // `credsReadCommand` reads, the repo's own line before the house's. Every
3
3
  // write goes through `storeArgv`: `sk secret set` with the terminal on stdin,
4
4
  // the hub with the pasted value on stdin. A value never rides argv, a log or
5
- // an answer: a failure line comes back with it replaced by ‹value›.
5
+ // an answer: a failure line comes back with it replaced by ‹value›. A read of
6
+ // a scoped name from a repo out of its scope is refused (`readRefusal`).
6
7
  import { existsSync } from 'fs'
7
8
  import { basename, join } from 'path'
8
9
  import { gitRoot } from '../core/git-root.ts'
10
+ import { inScope, scopesAll, scopeText, type Scope } from '../core/scope.ts'
9
11
  import { houseRootOf } from '../home/home-start.ts'
10
12
  import { loadIdentities, speakerOf } from '../identities/identities.ts'
11
13
  import { loadRepoConfig, type RepoConfig } from '../repo-config.ts'
@@ -31,6 +33,21 @@ export function managerTemplate(w: SecretsWhere, key: 'credsReadCommand' | 'cred
31
33
  return t
32
34
  }
33
35
 
36
+ /** the scope the house gives a name: its registry row, else every repo */
37
+ export const houseScopeOf = (w: SecretsWhere, name: string): Scope | undefined => w.house?.creds?.find((c) => c.name === name)?.for
38
+
39
+ /** why the repo at `w` may not read a name scoped to `scope`, or null when it may.
40
+ * A scoped name needs a repo with its own repo.config.ts: a folder name alone never opens one */
41
+ export function readRefusal(name: string, scope: Scope | undefined, w: SecretsWhere): string | null {
42
+ if (scopesAll(scope)) return null
43
+ if (w.own != null && inScope(scope, w)) return null
44
+ const who = w.own == null ? `${w.repos[0]} is no repo with a repo.config.ts` : `repo ${w.repos.join(' / ')} speaks as ${w.identity ?? 'no identity'}`
45
+ return `REFUSED ${name} is for ${scopeText(scope)}, and ${who}: read it from a repo in its scope, or set its registry row's for to all (wiki services/secrets, Who may read a secret)`
46
+ }
47
+
48
+ /** the exit code of a refused read, apart from a missing secret's */
49
+ export const REFUSED_EXIT = 3
50
+
34
51
  /** the one argv every write runs; the value goes on its stdin */
35
52
  export const storeArgv = (template: string, name: string, account?: string): string[] =>
36
53
  [...template.trim().split(/\s+/).map((x) => x.replaceAll('{name}', name)), ...(account != null ? [account] : [])]
@@ -0,0 +1,22 @@
1
+ // the browser reports a ResizeObserver loop as a window 'error' event, yet it
2
+ // is a notice, not a failure: the spec delivers the skipped notifications next
3
+ // frame. Bun's dev overlay listens for 'error' and paints it as a runtime
4
+ // error. A capture listener on the target runs before Bun's bubble one, so
5
+ // stopImmediatePropagation keeps the overlay for real errors only.
6
+ const BENIGN = [
7
+ 'ResizeObserver loop completed with undelivered notifications.', // webkit, chromium
8
+ 'ResizeObserver loop limit exceeded', // older chromium
9
+ ]
10
+
11
+ export const isBenignError = (message: unknown): boolean =>
12
+ typeof message === 'string' && BENIGN.some(b => message.includes(b))
13
+
14
+ export const quietBenignErrors = (target: EventTarget): void => {
15
+ target.addEventListener(
16
+ 'error',
17
+ e => {
18
+ if (isBenignError((e as ErrorEvent).message)) e.stopImmediatePropagation()
19
+ },
20
+ { capture: true },
21
+ )
22
+ }
@@ -43,11 +43,12 @@ export type HashSel =
43
43
  | { t: 'review'; id: string | null; q?: string }
44
44
  /** a trailer's cuts, played with their notes: a trailer folder and one of its cuts, null for the first; the note
45
45
  * open on it, and the notes filter when it is not the page's default (all) */
46
- | { t: 'trailer'; trailer: string | null; cut: string | null; note?: string | null; filter?: 'open' | 'all' | null }
46
+ | { t: 'trailer'; trailer: string | null; cut: string | null; note?: string | null; filter?: 'open' | 'all' | null; voices?: string }
47
47
  /** the store pages: a store, null for the first; a thing of it to scroll to (a picture's path, `field:<heading>`) */
48
48
  | { t: 'stores'; store: string | null; asset?: string | null }
49
- /** the releases page on a version (`next` or X.Y.Z), null for the first */
50
- | { t: 'releases'; version: string | null }
49
+ /** the releases page on a version (`next` or X.Y.Z), null for the first; its view when the address names one, else
50
+ * the one this browser remembers */
51
+ | { t: 'releases'; version: string | null; tab?: ReleasesTab }
51
52
  /** the messages page: its tab, the run it scores by when not the newest */
52
53
  | { t: 'messages'; tab: MessagesTab; run?: string }
53
54
  /** the Veille: the post picked, null for none; the window, chips, folds and lightbox as `window=3d&tags=a,b` */
@@ -60,6 +61,9 @@ export type HashSel =
60
61
  /** a repo's own page (wiki tools/shipkit/project-pages.md): the repo, the page, the page's own keys as a query */
61
62
  | { t: 'page'; repo: string; id: string; q?: string }
62
63
 
64
+ /** the releases page's two views: the changes as a grid of cards, or the release as one long page of notes */
65
+ export type ReleasesTab = 'cards' | 'notes'
66
+
63
67
  /** whose a gate check is */
64
68
  export type CheckOwner = 'shipkit' | 'repo'
65
69
 
@@ -74,7 +78,9 @@ export type ParsedHash = {
74
78
  /** a trailer address only: the note open, the notes filter */
75
79
  note?: string
76
80
  filter?: 'open' | 'all'
77
- /** a review address only: its view and list filters, as `view=1&subject=place` */
81
+ /** a trailer address only: the Voices view, on its line's key ('' its first) */
82
+ voices?: string
83
+ /** a review address: its view and list filters, as `view=1&subject=place`; a releases address: `notes` */
78
84
  q?: string
79
85
  }
80
86
 
@@ -125,14 +131,15 @@ export function hashFor(sel: HashSel | null): string | null {
125
131
  // page:review:<id>?view=1&subject=place, the query only when it says something
126
132
  case 'review': return `${sel.id == null ? REVIEW : `${REVIEW}:${sel.id}`}${sel.q ? `?${sel.q}` : ''}`
127
133
  case 'trailer': {
128
- // page:trailer:<trailer>/<cut>/<note>?filter=all, each part only when it says something
134
+ // page:trailer:<trailer>/<cut>/<note>?filter=all&voices=<line>, each part only when it says something
129
135
  const note = sel.trailer != null && sel.note ? `/${sel.cut ?? ''}/${sel.note}` : sel.cut == null ? '' : `/${sel.cut}`
130
- return `${sel.trailer == null ? TRAILER : `${TRAILER}:${sel.trailer}${note}`}${sel.filter ? `?filter=${sel.filter}` : ''}`
136
+ const q = [sel.filter ? `filter=${sel.filter}` : '', sel.voices !== undefined ? (sel.voices ? `voices=${sel.voices}` : 'voices') : ''].filter(Boolean).join('&')
137
+ return `${sel.trailer == null ? TRAILER : `${TRAILER}:${sel.trailer}${note}`}${q ? `?${q}` : ''}`
131
138
  }
132
139
  // page:stores:<store>/<asset>, the asset as it is: a path or a heading carries any character
133
140
  case 'stores': return sel.store == null ? STORES : `${STORES}:${sel.store}${sel.asset ? `/${sel.asset}` : ''}`
134
- // page:releases:<version>
135
- case 'releases': return sel.version == null ? RELEASES : `${RELEASES}:${sel.version}`
141
+ // page:releases:<version>?view=notes, the view only for the notes
142
+ case 'releases': return `${sel.version == null ? RELEASES : `${RELEASES}:${sel.version}`}${sel.tab === 'notes' ? '?view=notes' : ''}`
136
143
  // page:messages:<tab>?run=<run>, the tab only past the first, the run only when picked
137
144
  case 'messages': return `${sel.tab === 'messages' ? MESSAGES : `${MESSAGES}:${sel.tab}`}${sel.run ? `?run=${sel.run}` : ''}`
138
145
  // page:veille:<platform>:<id>?window=3d, the query only when it says something
@@ -179,8 +186,10 @@ export function parseHash(raw: string): ParsedHash {
179
186
  const qi = raw.indexOf('?')
180
187
  const path = qi === -1 ? raw : raw.slice(0, qi)
181
188
  const [trailer = '', cut = '', note = ''] = path.slice(TRAILER.length + 1).split('/')
182
- const f = qi === -1 ? null : new URLSearchParams(raw.slice(qi + 1)).get('filter')
183
- return { kind: 'trailer', col: trailer === '' ? null : trailer, id: cut, tools: null, ...(note ? { note } : {}), ...(f === 'open' || f === 'all' ? { filter: f } : {}) }
189
+ const params = new URLSearchParams(qi === -1 ? '' : raw.slice(qi + 1))
190
+ const f = params.get('filter')
191
+ const voices = params.get('voices')
192
+ return { kind: 'trailer', col: trailer === '' ? null : trailer, id: cut, tools: null, ...(note ? { note } : {}), ...(f === 'open' || f === 'all' ? { filter: f } : {}), ...(voices !== null ? { voices } : {}) }
184
193
  }
185
194
  // the store rides in `col`, the thing named in `id`: everything after the first slash
186
195
  // the tab rides in `id`, the run in `q`; a tab this build does not name opens the first
@@ -190,9 +199,12 @@ export function parseHash(raw: string): ParsedHash {
190
199
  const run = qi === -1 ? null : new URLSearchParams(raw.slice(qi + 1)).get('run')
191
200
  return { kind: 'messages', col: null, id: isMessagesTab(tab) ? tab : 'messages', tools: null, ...(run ? { q: run } : {}) }
192
201
  }
193
- if (raw === RELEASES || raw.startsWith(`${RELEASES}:`)) {
194
- const v = raw.slice(RELEASES.length + 1)
195
- return { kind: 'releases', col: null, id: isVersion(v) ? v : '', tools: null }
202
+ // the view rides in `q`, only the notes
203
+ if (raw === RELEASES || raw.startsWith(`${RELEASES}:`) || raw.startsWith(`${RELEASES}?`)) {
204
+ const qi = raw.indexOf('?')
205
+ const v = (qi === -1 ? raw : raw.slice(0, qi)).slice(RELEASES.length + 1)
206
+ const notes = qi !== -1 && new URLSearchParams(raw.slice(qi + 1)).get('view') === 'notes'
207
+ return { kind: 'releases', col: null, id: isVersion(v) ? v : '', tools: null, ...(notes ? { q: 'notes' } : {}) }
196
208
  }
197
209
  if (raw === STORES || raw.startsWith(`${STORES}:`)) {
198
210
  const rest = raw.slice(STORES.length + 1)
@@ -274,9 +286,9 @@ export function selOf(p: ParsedHash): HashSel | null {
274
286
  case 'when': return { t: 'when' }
275
287
  case 'checks': return { t: 'checks', from: p.id as CheckOwner }
276
288
  case 'review': return { t: 'review', id: p.id === '' ? null : p.id, ...(p.q ? { q: p.q } : {}) }
277
- case 'trailer': return { t: 'trailer', trailer: p.col, cut: p.id === '' ? null : p.id, ...(p.note ? { note: p.note } : {}), ...(p.filter ? { filter: p.filter } : {}) }
289
+ case 'trailer': return { t: 'trailer', trailer: p.col, cut: p.id === '' ? null : p.id, ...(p.note ? { note: p.note } : {}), ...(p.filter ? { filter: p.filter } : {}), ...(p.voices !== undefined ? { voices: p.voices } : {}) }
278
290
  case 'stores': return { t: 'stores', store: p.col, ...(p.id ? { asset: p.id } : {}) }
279
- case 'releases': return { t: 'releases', version: p.id === '' ? null : p.id }
291
+ case 'releases': return { t: 'releases', version: p.id === '' ? null : p.id, ...(p.q === 'notes' ? { tab: 'notes' as const } : {}) }
280
292
  case 'messages': return { t: 'messages', tab: isMessagesTab(p.id) ? p.id : 'messages', ...(p.q ? { run: p.q } : {}) }
281
293
  case 'veille': return { t: 'veille', post: p.id === '' ? null : p.id, ...(p.q ? { q: p.q } : {}) }
282
294
  case 'comms': return { t: 'comms', draft: p.col, ...(p.id ? { part: p.id } : {}), ...(p.q ? { q: p.q } : {}) }