rvlib-shipkit 2.19.0 → 2.20.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 (158) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +1 -1
  3. package/src/annex/annex.ts +227 -0
  4. package/src/annex/offload.ts +279 -0
  5. package/src/checks/SK040-release-words.check.ts +43 -0
  6. package/src/checks/SK041-annex-links.check.ts +28 -0
  7. package/src/checks/SK042-post-kinds.check.ts +73 -0
  8. package/src/cli/cmd_Annex.ts +179 -0
  9. package/src/cli/cmd_Commands.ts +4 -1
  10. package/src/cli/cmd_Home.ts +3 -2
  11. package/src/cli/cmd_Messages.ts +155 -0
  12. package/src/cli/cmd_Releases.ts +48 -0
  13. package/src/cli/cmd_Review.ts +161 -6
  14. package/src/cli/cmd_Shot.ts +4 -4
  15. package/src/cli/cmd_Social.ts +143 -6
  16. package/src/cli/family-pages.ts +2 -0
  17. package/src/cli/kit/index.ts +1 -1
  18. package/src/cli/kit/verb.ts +11 -3
  19. package/src/cli/registry.ts +6 -1
  20. package/src/collections/collection-types.ts +8 -1
  21. package/src/collections/providers.ts +4 -1
  22. package/src/commands/model.ts +36 -0
  23. package/src/commands/registry.ts +49 -0
  24. package/src/commands/routes.ts +59 -0
  25. package/src/commands/runner.ts +35 -0
  26. package/src/commands/runs.ts +112 -0
  27. package/src/core/app-icon.ts +4 -3
  28. package/src/core/icon-type.ts +8 -0
  29. package/src/core/jobs.ts +4 -3
  30. package/src/core/layout.ts +5 -2
  31. package/src/core/squircle.ts +95 -0
  32. package/src/home/daemon-jobs.ts +26 -2
  33. package/src/home/global-units.ts +3 -0
  34. package/src/home/gui-app/ShipkitGui.swift +302 -5
  35. package/src/home/gui-app.ts +63 -33
  36. package/src/home/hmr-keep.ts +134 -0
  37. package/src/home/home-start.ts +2 -2
  38. package/src/home/lib-watch.ts +21 -11
  39. package/src/home/pm.ts +1 -1
  40. package/src/home/process-apps.ts +181 -0
  41. package/src/home/resources.ts +3 -3
  42. package/src/home/run-web.ts +7 -4
  43. package/src/home/serve-web.ts +64 -14
  44. package/src/identities/collection.ts +49 -0
  45. package/src/identities/identities.ts +110 -8
  46. package/src/identities/machine.ts +4 -3
  47. package/src/identities/rating.ts +33 -0
  48. package/src/identities/shown.ts +170 -0
  49. package/src/identities/steps.ts +5 -0
  50. package/src/media-store/purge.ts +15 -1
  51. package/src/media-store/remote.ts +22 -6
  52. package/src/messages/brief.ts +117 -0
  53. package/src/messages/collection.ts +40 -0
  54. package/src/messages/model.ts +171 -0
  55. package/src/messages/routes.ts +15 -0
  56. package/src/messages/score.ts +180 -0
  57. package/src/messages/tabs.ts +13 -0
  58. package/src/release/notes.ts +130 -0
  59. package/src/release/run-bump.ts +41 -18
  60. package/src/release/run-release.ts +22 -4
  61. package/src/release/run-releases.ts +17 -15
  62. package/src/release/unit-resolve.ts +9 -0
  63. package/src/releases/add.ts +66 -0
  64. package/src/releases/collection.ts +36 -0
  65. package/src/releases/from-card.ts +66 -0
  66. package/src/releases/model.ts +267 -0
  67. package/src/releases/pictures.ts +89 -0
  68. package/src/releases/routes.ts +36 -0
  69. package/src/releases/store.ts +71 -0
  70. package/src/repo-config.ts +5 -0
  71. package/src/review/cells.ts +0 -11
  72. package/src/review/format.ts +10 -6
  73. package/src/review/model.ts +92 -3
  74. package/src/review/notes.ts +2 -48
  75. package/src/review/routes.ts +28 -10
  76. package/src/review/stage-card.ts +197 -0
  77. package/src/review/stage-routes.ts +123 -0
  78. package/src/review/store.ts +36 -0
  79. package/src/review/trailer-card.ts +99 -0
  80. package/src/review/trailer-desk.ts +57 -4
  81. package/src/review/trailer-model.ts +41 -7
  82. package/src/review/trailer-notes.ts +45 -0
  83. package/src/review/trailer-routes.ts +22 -13
  84. package/src/serve/hub-app/app-bridge.ts +71 -0
  85. package/src/serve/hub-app/commands/commands-page.tsx +122 -0
  86. package/src/serve/hub-app/commands/commands-st.ts +177 -0
  87. package/src/serve/hub-app/commands.css +24 -0
  88. package/src/serve/hub-app/hash-route.ts +40 -1
  89. package/src/serve/hub-app/home-st.ts +11 -2
  90. package/src/serve/hub-app/home.html +3 -0
  91. package/src/serve/hub-app/hub-app.tsx +6 -0
  92. package/src/serve/hub-app/icons.tsx +5 -0
  93. package/src/serve/hub-app/identities-view.tsx +4 -1
  94. package/src/serve/hub-app/identities.css +1 -0
  95. package/src/serve/hub-app/index.html +3 -0
  96. package/src/serve/hub-app/keys.ts +2 -2
  97. package/src/serve/hub-app/machine-st.ts +41 -10
  98. package/src/serve/hub-app/messages/messages-page.tsx +354 -0
  99. package/src/serve/hub-app/messages/messages-st.ts +74 -0
  100. package/src/serve/hub-app/messages.css +35 -0
  101. package/src/serve/hub-app/releases/releases-page.tsx +94 -0
  102. package/src/serve/hub-app/releases/releases-st.ts +69 -0
  103. package/src/serve/hub-app/releases.css +25 -0
  104. package/src/serve/hub-app/repo-sections.ts +15 -1
  105. package/src/serve/hub-app/repo-st.ts +56 -5
  106. package/src/serve/hub-app/review/clip-st.ts +31 -3
  107. package/src/serve/hub-app/review/note-place.ts +31 -0
  108. package/src/serve/hub-app/review/review-cells.tsx +27 -3
  109. package/src/serve/hub-app/review/review-st.ts +77 -2
  110. package/src/serve/hub-app/review/review-thread.tsx +9 -31
  111. package/src/serve/hub-app/review/review-views.tsx +164 -58
  112. package/src/serve/hub-app/review/thread-st.ts +108 -41
  113. package/src/serve/hub-app/review/trailer-card.tsx +187 -0
  114. package/src/serve/hub-app/review/trailer-page.tsx +62 -31
  115. package/src/serve/hub-app/review/trailer-st.ts +138 -26
  116. package/src/serve/hub-app/review/trailer-timeline.tsx +39 -26
  117. package/src/serve/hub-app/review.css +49 -6
  118. package/src/serve/hub-app/social/comms-page.tsx +55 -23
  119. package/src/serve/hub-app/social/identity-pictures.ts +46 -8
  120. package/src/serve/hub-app/social/kit.tsx +9 -6
  121. package/src/serve/hub-app/social/post-card.tsx +10 -2
  122. package/src/serve/hub-app/social/social-model.ts +37 -3
  123. package/src/serve/hub-app/social/social-page.tsx +179 -65
  124. package/src/serve/hub-app/social/social-st.ts +79 -26
  125. package/src/serve/hub-app/social/stage-popup.tsx +268 -0
  126. package/src/serve/hub-app/social/stage-st.ts +310 -0
  127. package/src/serve/hub-app/social/step-layout.ts +42 -0
  128. package/src/serve/hub-app/social.css +60 -1
  129. package/src/serve/hub-app/tree-build.ts +38 -1
  130. package/src/serve/hub-app/tree-svc.ts +10 -3
  131. package/src/serve/project-gutter-route.ts +4 -2
  132. package/src/serve/same-origin.ts +24 -1
  133. package/src/serve/serve-hub.ts +15 -1
  134. package/src/shipkit-files.ts +9 -7
  135. package/src/shot/shooter.ts +3 -3
  136. package/src/shot/shot-ask.ts +14 -3
  137. package/src/shot/shot.shipkit.ts +1 -1
  138. package/src/social/discord-layout.ts +48 -5
  139. package/src/social/fit.ts +84 -0
  140. package/src/social/identity-words.ts +74 -0
  141. package/src/social/kind-pages.ts +41 -0
  142. package/src/social/kinds.ts +92 -0
  143. package/src/social/load.ts +105 -9
  144. package/src/social/media-limit.ts +63 -2
  145. package/src/social/presence.ts +1 -1
  146. package/src/social/publish/bluesky.ts +58 -19
  147. package/src/social/publish/index.ts +31 -5
  148. package/src/social/reach.ts +49 -0
  149. package/src/social/release-stage.ts +173 -0
  150. package/src/social/routes.ts +42 -7
  151. package/src/social/stage.ts +227 -0
  152. package/src/social/strip.ts +85 -0
  153. package/src/social/text.ts +6 -2
  154. package/src/social/unit.ts +57 -1
  155. package/src/social/writes.ts +11 -0
  156. package/src/trailer/build.ts +15 -2
  157. package/src/trailer/grammar.ts +14 -4
  158. package/src/trailer/public-words.ts +41 -0
@@ -35,8 +35,10 @@ import {
35
35
  toAcknowledge,
36
36
  verdictMessageOf,
37
37
  verdictOf,
38
+ viewIndexOf,
38
39
  withdrawnOf,
39
40
  type GalleryTile,
41
+ type CardChangelog,
40
42
  type Item,
41
43
  type Message,
42
44
  type Op,
@@ -48,6 +50,7 @@ import {
48
50
  type ReviewItem,
49
51
  type ReviewMark,
50
52
  type ReviewView,
53
+ type TrailerCard,
51
54
  type Spec,
52
55
  type Subject,
53
56
  viewFilesOf,
@@ -103,6 +106,10 @@ export interface ViewInput {
103
106
  export interface AddInput {
104
107
  title: string
105
108
  what: string
109
+ /** the public line for a post of it (`--post`); the caller runs the repo's guard on it first */
110
+ post?: string
111
+ /** the change its approval adds to next.md (`--changelog`); the caller runs the repo's guard on it first */
112
+ changelog?: CardChangelog
106
113
  /** what is judged; a plain shot by default */
107
114
  subject?: Subject
108
115
  topic?: string
@@ -133,6 +140,10 @@ export interface AddInput {
133
140
  wip?: { live: string }
134
141
  /** every view is an option he picks one of */
135
142
  choice?: boolean
143
+ /** on a choice: the option the agent suggests, by its label or its letter */
144
+ agentPick?: string
145
+ /** a trailer card: the cut the hub plays in its body; its one view is the cut's strip */
146
+ trailer?: TrailerCard
136
147
  now?: Date
137
148
  }
138
149
 
@@ -315,6 +326,8 @@ export async function addItem(dir: string, input: AddInput): Promise<Item> {
315
326
  if (given.length === 0) throw new Error('give --image, --video or --audio, or --before and --after, or --view "<label>" <image>')
316
327
  for (const [i, v] of given.entries()) if (i > 0 && !v.label.trim()) throw new Error('--view: every view after the first needs its label')
317
328
  if (input.choice && given.length < 2) throw new Error('--choice: a choice has two options or more, one --view each')
329
+ if (input.agentPick !== undefined && !input.choice) throw new Error('--pick: only on a --choice card')
330
+ const agentPick = input.agentPick === undefined ? undefined : pickIndex(given, input.agentPick)
318
331
  for (const v of given) if (v.note !== undefined && v.gallery) throw new Error(`--view "${v.label}": a note goes on an image, a clip or a sound, never a gallery`)
319
332
  const loaded = await Promise.all(given.map((v, i) => loadView(v, i === 0 ? 'the first view' : `--view "${v.label}"`)))
320
333
  if (input.supersedes !== undefined && !existsSync(join(dir, input.supersedes, 'item.json'))) throw new Error(`--supersedes ${input.supersedes}: no such card in ${dir}`)
@@ -366,6 +379,8 @@ export async function addItem(dir: string, input: AddInput): Promise<Item> {
366
379
  origin: { by: 'agent', ...(lane ? { lane } : {}), ...(session ? { session } : {}) },
367
380
  title: input.title.trim(),
368
381
  what: input.what.trim(),
382
+ ...(input.post?.trim() ? { post: input.post.trim() } : {}),
383
+ ...(input.changelog ? { changelog: { category: input.changelog.category.trim(), line: input.changelog.line.trim() } } : {}),
369
384
  ...(topic ? { topic } : {}),
370
385
  ...(input.commit ? { commit: input.commit } : {}),
371
386
  views: loaded.map((v, n) => viewOf(v, n, input.marks?.[n], given[n]?.note)),
@@ -376,6 +391,8 @@ export async function addItem(dir: string, input: AddInput): Promise<Item> {
376
391
  ...(input.light ? { light: input.light } : {}),
377
392
  ...(input.wip ? { wip: { live: input.wip.live, frame: 1 } } : {}),
378
393
  ...(input.choice ? { choice: true as const } : {}),
394
+ ...(agentPick !== undefined ? { agentPick } : {}),
395
+ ...(input.trailer ? { trailer: input.trailer } : {}),
379
396
  }
380
397
  const problems = itemProblems(item)
381
398
  if (problems.length > 0) throw new Error(problems.join('; '))
@@ -423,6 +440,25 @@ export async function addView(dir: string, id: string, v: ViewInput, o: { marks?
423
440
  })
424
441
  }
425
442
 
443
+ /** the option the agent suggests, by its label or its letter; throws naming every option */
444
+ function pickIndex(views: readonly { label: string }[], ref: string, flag = '--pick'): number {
445
+ try {
446
+ return viewIndexOf(views, ref)
447
+ } catch (e) {
448
+ throw new Error(`${flag}: ${(e as Error).message}`)
449
+ }
450
+ }
451
+
452
+ /** the agent's pick set on an open choice card, by the view's label or letter; refused once he answered */
453
+ export function setAgentPick(dir: string, id: string, ref: string): Item {
454
+ const x = readItem(dir, id)
455
+ if (!x) throw new Error(`no card ${id}`)
456
+ if (verdictOf(x)) throw new Error(`${id} has his answer already: the pick shows what was suggested, never rewritten after`)
457
+ if (x.item.choice !== true) throw new Error(`${id} is no choice card: a pick names one of its options`)
458
+ const n = pickIndex(x.item.views, ref, 'pick')
459
+ return updateHead(dir, id, (cur) => ({ ...cur, agentPick: n }))
460
+ }
461
+
426
462
  /** the head rewritten under the item's lock, from what the file says now: a write that raced this one is never lost */
427
463
  export function updateHead(dir: string, id: string, fn: (cur: Item) => Item): Item {
428
464
  return locked(dir, id, () => {
@@ -0,0 +1,99 @@
1
+ // a trailer card as `sk review add --trailer` makes it (wiki tools/shipkit/review.md, A trailer): the cut a .trailer file
2
+ // names, a kept version of it, the render it is compared with, each render pinned by its mtime, the shots the change
3
+ // touched. No video is made: the hub plays the pinned renders in the trailer entry's player
4
+ import { existsSync, readFileSync } from 'node:fs'
5
+ import { relative, resolve, sep } from 'node:path'
6
+ import type { Shot, Trailer } from '../trailer/grammar.ts'
7
+ import { versionName, versionOf } from '../trailer/versions.ts'
8
+ import { stillAt } from './media.ts'
9
+ import type { TrailerCard, TrailerSide } from './model.ts'
10
+ import { cutOf, parseCut, stripOf, timelineOf, trailerDir, videoOf, viewOf } from './trailer-desk.ts'
11
+
12
+ export interface TrailerCardInput {
13
+ /** a `.trailer` file: a cut of `trailer/<id>/`, or a kept version in its `versions/` */
14
+ file: string
15
+ /** a kept version of that cut, `v<n>` */
16
+ version?: string
17
+ /** the render it is compared with: a kept version `v<n>` of the same cut, or another cut of the folder */
18
+ before?: string
19
+ /** the shots the change touched; absent: the shots whose block differs from the before's */
20
+ shots?: string[]
21
+ }
22
+
23
+ /** the trailer and the cuts a card plays, read from the input's words alone */
24
+ export function cardCuts(root: string, cwd: string, o: TrailerCardInput): { trailer: string; after: string; before?: string } {
25
+ const rel = relative(root, resolve(cwd, o.file)).split(sep)
26
+ if (!rel.at(-1)?.endsWith('.trailer') || rel[0] !== 'trailer' || !(rel.length === 3 || (rel.length === 4 && rel[2] === 'versions')))
27
+ throw new Error(`--trailer ${o.file}: a cut is trailer/<name>/<cut>.trailer, or a kept one trailer/<name>/versions/<v>.trailer`)
28
+ const trailer = rel[1] ?? ''
29
+ const name = (rel.at(-1) ?? '').slice(0, -'.trailer'.length)
30
+ const kept = rel.length === 4
31
+ if (kept && o.version !== undefined) throw new Error(`--version: ${o.file} is a kept version already`)
32
+ const stem = kept ? (versionOf(name)?.cut ?? name) : name
33
+ const after = kept ? name : o.version !== undefined ? versionName(stem, o.version) : name
34
+ const before = o.before === undefined ? undefined : /^v\d+$/.test(o.before) ? versionName(stem, o.before) : o.before
35
+ if (before === after) throw new Error(`--before ${o.before}: it is the cut the card plays`)
36
+ return { trailer, after, ...(before !== undefined ? { before } : {}) }
37
+ }
38
+
39
+ /** a .trailer file as a card compares it: its parse and its text */
40
+ export interface CutText {
41
+ trailer: Trailer
42
+ text: string
43
+ }
44
+
45
+ /** a shot's block as it compares: its header and indented lines, comments and blank lines left out (a film line the
46
+ * parse cannot read without the project's words is still its text), then every parsed field but the lines it sits on
47
+ * (a length a section fits) */
48
+ function shotKey(s: Shot, lines: readonly string[]): string {
49
+ const block: string[] = []
50
+ for (let i = s.line - 1; i < lines.length; i++) {
51
+ const l = lines[i] ?? ''
52
+ if (i > s.line - 1 && l.trim() !== '' && !/^\s/.test(l)) break
53
+ if (l.trim() !== '' && !l.trim().startsWith('#')) block.push(l.trim())
54
+ }
55
+ return `${block.join('\n')}\n${JSON.stringify(s, (k, v: unknown) => (k === 'line' ? undefined : v))}`
56
+ }
57
+
58
+ /** the shots of `after` that `before` lacks, or whose block reads differently there, in the order of `after` */
59
+ export function changedShots(before: CutText, after: CutText): string[] {
60
+ const was = new Map<string, string>()
61
+ const old = before.text.split('\n')
62
+ for (const s of before.trailer.shots) if (!was.has(s.name)) was.set(s.name, shotKey(s, old))
63
+ const now = after.text.split('\n')
64
+ return [...new Set(after.trailer.shots.filter((s) => was.get(s.name) !== shotKey(s, now)).map((s) => s.name))]
65
+ }
66
+
67
+ /** the card's trailer, its pinned renders and its shots, and the image the store keeps for it: the cut's contact strip,
68
+ * else a still of its render cut into `still` */
69
+ export async function trailerCardOf(root: string, cwd: string, o: TrailerCardInput, still: string): Promise<{ card: TrailerCard; image: string }> {
70
+ const cuts = cardCuts(root, cwd, o)
71
+ const dir = trailerDir(root, cuts.trailer)
72
+ if (!dir) throw new Error(`--trailer: no trailer folder trailer/${cuts.trailer}`)
73
+ const pin = (cut: string, flag: string): { side: TrailerSide; file: string | null; video: string; strip: string; size: [number, number] } => {
74
+ const c = cutOf(dir, cut)
75
+ if (!c) throw new Error(`${flag}: no cut ${cut} in trailer/${cuts.trailer} (sk trailer keep <v> keeps a version)`)
76
+ const { view, rendering } = viewOf(root, dir, cuts.trailer, c)
77
+ if (rendering) throw new Error(`${flag}: a render of ${cut} is being written: send the card once it is done`)
78
+ if (!view) throw new Error(`${flag}: ${cut} has no render: sk trailer ${c.trailer ? relative(cwd, c.trailer) : cut}`)
79
+ return { side: { cut, render: view.mtime }, file: c.trailer, video: videoOf(dir, c), strip: stripOf(dir, c), size: view.size }
80
+ }
81
+ const after = pin(cuts.after, '--trailer')
82
+ const before = cuts.before !== undefined ? pin(cuts.before, '--before') : null
83
+ const parsed = (f: string | null): CutText | null => (f ? { trailer: parseCut(f).trailer, text: readFileSync(f, 'utf8') } : null)
84
+ let shots: string[]
85
+ if (o.shots !== undefined) {
86
+ const tl = parsed(after.file)?.trailer
87
+ const known = new Set(tl ? timelineOf(tl).shots.map((s) => s.name) : [])
88
+ const unknown = o.shots.filter((s) => !known.has(s))
89
+ if (unknown.length > 0) throw new Error(`--shots: ${unknown.join(', ')} ${unknown.length > 1 ? 'are no shots' : 'is no shot'} of ${cuts.after}`)
90
+ shots = [...new Set(o.shots)]
91
+ } else {
92
+ const a = parsed(after.file)
93
+ const b = before ? parsed(before.file) : null
94
+ shots = a && b ? changedShots(b, a) : []
95
+ }
96
+ if (!existsSync(after.strip)) await stillAt(after.video, 0.5, still)
97
+ const image = existsSync(after.strip) ? after.strip : still
98
+ return { card: { trailer: cuts.trailer, after: after.side, ...(before ? { before: before.side } : {}), shots, size: after.size }, image }
99
+ }
@@ -10,10 +10,11 @@ import type { MediaFact } from '../media-store/fact.ts'
10
10
  import { fetchBack, signedUrl } from '../media-store/remote.ts'
11
11
  import { parseTrailer, starts, total, type Trailer } from '../trailer/grammar.ts'
12
12
  import { THUMB_W } from '../trailer/graph.ts'
13
+ import { ffmpeg } from '../trailer/ffmpeg.ts'
13
14
  import { probe, stillAt } from './media.ts'
14
15
  import type { FrameSubject } from './model.ts'
15
16
  import { readAllCached, storeDir } from './store.ts'
16
- import { CUT_RE, notesOf, shotAt, TRAILER_ID_RE, type CutInfo, type SectionSpan, type ShotSpan, type Timeline, type TrailerInfo } from './trailer-model.ts'
17
+ import { CUT_RE, notesOf, shotAt, TRAILER_ID_RE, type CutInfo, type PinnedRender, type SectionSpan, type ShotSpan, type Timeline, type TrailerInfo } from './trailer-model.ts'
17
18
 
18
19
  const round = (v: number, d = 4): number => Number(v.toFixed(d))
19
20
 
@@ -134,7 +135,7 @@ export const montageOf = (dir: string, c: CutFiles): string => join(dir, 'out',
134
135
 
135
136
  /** a cut's .trailer parsed: the film lines need the project CLI's words, which a timeline never does, so their errors
136
137
  * are left out */
137
- function parseCut(file: string): { trailer: Trailer; errors: string[] } {
138
+ export function parseCut(file: string): { trailer: Trailer; errors: string[] } {
138
139
  const text = readFileSync(file, 'utf8')
139
140
  const lines = text.split('\n')
140
141
  const { trailer, errors } = parseTrailer(text, { verbs: null })
@@ -168,9 +169,32 @@ export interface View {
168
169
  fps: number
169
170
  size: [number, number]
170
171
  timeline: Timeline | null
172
+ /** the timing rule its timeline was read with (TIMING); an older one is read again from its unchanged .trailer */
173
+ timing?: number
171
174
  media?: ViewMedia
172
175
  }
173
176
 
177
+ /** 2: a shot whose film words the hub does not know keeps its fitted length, as in the build */
178
+ const TIMING = 2
179
+
180
+ /** a record's timeline read with an older rule, read again from its .trailer when that file is the one it was rendered
181
+ * from (saved before it); one saved after may differ, so the old timeline stays */
182
+ function retimed(root: string, id: string, cut: string, v: View): View {
183
+ if (v.timing === TIMING || v.timeline === null) return v
184
+ const dir = trailerDir(root, id)
185
+ const c = dir ? cutOf(dir, cut) : null
186
+ if (!c?.trailer || statSync(c.trailer).mtimeMs > v.mtime) return v
187
+ let timeline: Timeline
188
+ try {
189
+ timeline = timelineOf(parseCut(c.trailer).trailer)
190
+ } catch {
191
+ return v
192
+ }
193
+ const out: View = { ...v, timeline, timing: TIMING }
194
+ writeView(root, id, cut, out)
195
+ return out
196
+ }
197
+
174
198
  export const viewBase = (root: string, id: string, cut: string, mtime: number): string => join(viewDir(root), `${id}--${cut}--${Math.round(mtime)}`)
175
199
  export const viewVideo = (root: string, id: string, cut: string, mtime: number): string => `${viewBase(root, id, cut, mtime)}.mp4`
176
200
  export const viewStrip = (root: string, id: string, cut: string, mtime: number): string => `${viewBase(root, id, cut, mtime)}.strip.png`
@@ -188,7 +212,7 @@ export function readView(root: string, id: string, cut: string, mtime: number):
188
212
  const f = `${viewBase(root, id, cut, mtime)}.json`
189
213
  if (!existsSync(f)) return null
190
214
  const v = JSON.parse(readFileSync(f, 'utf8')) as View
191
- return v.media?.video || existsSync(viewVideo(root, id, cut, mtime)) ? v : null
215
+ return v.media?.video || existsSync(viewVideo(root, id, cut, mtime)) ? retimed(root, id, cut, v) : null
192
216
  }
193
217
 
194
218
  /** a render's record written whole, through a file beside it renamed */
@@ -252,7 +276,7 @@ export function viewOf(root: string, dir: string, id: string, c: CutFiles, now =
252
276
  } catch {
253
277
  timeline = null
254
278
  }
255
- const view: View = { mtime, ...p, timeline }
279
+ const view: View = { mtime, ...p, timeline, timing: TIMING }
256
280
  writeView(root, id, c.cut, view)
257
281
  keepStrip(root, dir, id, c, mtime)
258
282
  views.set(key, view)
@@ -356,6 +380,17 @@ export function trailerInfo(root: string, id: string): TrailerInfo | null {
356
380
  return { id, cuts: cutsOf(dir).map((c) => cutInfo(root, dir, id, c)), notes: notesOf(readAllCached(storeDir(root)).items, id) }
357
381
  }
358
382
 
383
+ /** a render a trailer card pinned: its record, its timeline (else the cut's file as it stands, as on the page), its
384
+ * strip's grid; null when nothing holds its video */
385
+ export function pinnedRender(root: string, id: string, cut: string, mtime: number): PinnedRender | null {
386
+ const v = readView(root, id, cut, mtime)
387
+ const dir = trailerDir(root, id)
388
+ const c = dir ? cutOf(dir, cut) : null
389
+ if (!v || !c) return null
390
+ const tl = v.timeline ?? (c.trailer ? timelineOf(parseCut(c.trailer).trailer) : wholeTimeline(v.duration, v.fps, v.size))
391
+ return { duration: v.duration, fps: v.fps, timeline: tl, strip: stripInfo(viewStrip(root, id, cut, mtime), v, tl) }
392
+ }
393
+
359
394
  /** the montage page of a cut, null when its build wrote none */
360
395
  export function montagePage(root: string, id: string, cut: string): string | null {
361
396
  const dir = trailerDir(root, id)
@@ -374,6 +409,24 @@ export function frameAt(time: number, fps: number, duration: number): { frame: n
374
409
  return { frame, time: (frame + 0.5) / fps }
375
410
  }
376
411
 
412
+ /** a still the rail draws a note on is this wide */
413
+ const STILL_W = 320
414
+
415
+ /** frame `frame` of a render, a small jpg cut once beside its record and kept; null when nothing holds the render */
416
+ export async function frameStill(root: string, id: string, cut: string, mtime: number, frame: number): Promise<string | null> {
417
+ const v = readView(root, id, cut, mtime)
418
+ if (!v || !Number.isInteger(frame) || frame < 0) return null
419
+ const f = frameAt((frame + 0.5) / v.fps, v.fps, v.duration)
420
+ const out = `${viewBase(root, id, cut, mtime)}--f${f.frame}.jpg`
421
+ if (existsSync(out)) return out
422
+ const video = await viewMedia(root, id, cut, mtime, 'video', { bytes: true })
423
+ if (!video || !('path' in video)) return null
424
+ const tmp = `${out}.${process.pid}.jpg`
425
+ await ffmpeg(['-y', '-ss', f.time.toFixed(5), '-i', video.path, '-frames:v', '1', '-vf', `scale=${STILL_W}:-2`, '-q:v', '4', tmp])
426
+ renameSync(tmp, out)
427
+ return out
428
+ }
429
+
377
430
  export interface NewNote {
378
431
  cut: string
379
432
  /** the render on screen, by its mtime: the still is cut from that version, whatever came after */
@@ -4,17 +4,43 @@ import { isFrame, isReply, partyOf, stateOf, type ReviewItem } from './model.ts'
4
4
 
5
5
  export type NoteState = 'open' | 'done' | 'wontfix'
6
6
 
7
- export interface NotePin {
8
- /** 0 to 1 over the frame, from the left and from the top */
7
+ /** what a frame note marks on its frame: a review card's rectangle (x, y, w, h, 0 to 1 over the frame from the left and
8
+ * the top, so any render or size of the player shows it in place); w = h = 0 is a point */
9
+ export interface NoteMark {
9
10
  x: number
10
11
  y: number
12
+ w: number
13
+ h: number
14
+ }
15
+
16
+ /** a mark read from a request, kept inside the frame; undefined when it is none */
17
+ export function noteMarkOf(v: unknown): NoteMark | undefined {
18
+ const m = v as { x?: unknown; y?: unknown; w?: unknown; h?: unknown } | null | undefined
19
+ if (!m || typeof m.x !== 'number' || typeof m.y !== 'number' || !Number.isFinite(m.x) || !Number.isFinite(m.y)) return undefined
20
+ const r4 = (n: number): number => Number(Math.min(1, Math.max(0, n)).toFixed(4))
21
+ const x = r4(m.x)
22
+ const y = r4(m.y)
23
+ const side = (n: unknown, at: number): number => (typeof n === 'number' && Number.isFinite(n) && n > 0 ? r4(Math.min(n, 1 - at)) : 0)
24
+ return { x, y, w: side(m.w, x), h: side(m.h, y) }
25
+ }
26
+
27
+ /** one marker of the timeline's notes lane, a trailer card's note or a page's frame note: its number in the order of
28
+ * the cut, its time, its tone, its words; `go` lands on its frame */
29
+ export interface LaneMark {
30
+ key: string
31
+ n: number
32
+ at: number
33
+ tone: 'draft' | 'sent' | NoteState
34
+ text: string
35
+ selected: boolean
36
+ go: () => void
11
37
  }
12
38
 
13
39
  /** one note as the view shows it: an item of the one store whose subject is a frame */
14
40
  export interface TrailerNote {
15
41
  /** its item's id */
16
42
  id: string
17
- /** its number on the trailer, in the order written: the label of its pin */
43
+ /** its number on the trailer, in the order written */
18
44
  n: number
19
45
  trailer: string
20
46
  cut: string
@@ -26,7 +52,7 @@ export interface TrailerNote {
26
52
  shotTime: number
27
53
  section: string | null
28
54
  text: string
29
- pin?: NotePin
55
+ mark?: NoteMark
30
56
  state: NoteState
31
57
  /** done: the commit or the answer; wontfix: the reason */
32
58
  reply?: string
@@ -36,14 +62,22 @@ export interface TrailerNote {
36
62
  still: string
37
63
  }
38
64
 
39
- /** a frame item as a note: its words and pin are the owner's latest, its state the lifecycle's (fixed is done); null
65
+ /** a render as a trailer card pins it: its length, rate, timeline and strip, whatever render the cut has now */
66
+ export interface PinnedRender {
67
+ duration: number
68
+ fps: number
69
+ timeline: Timeline
70
+ strip: CutInfo['strip']
71
+ }
72
+
73
+ /** a frame item as a note: its words and mark are the owner's latest, its state the lifecycle's (fixed is done); null
40
74
  * when the item is no frame */
41
75
  export function noteOf(x: ReviewItem, n: number): TrailerNote | null {
42
76
  const s = x.item.subject
43
77
  if (!isFrame(s)) return null
44
78
  const said = x.thread.filter((m) => partyOf(m.who) === 'owner' && m.op === undefined)
45
79
  const text = said.filter(isReply).at(-1)?.text ?? ''
46
- const pinned = said.filter((m) => m.rects !== undefined).at(-1)?.rects?.[0]
80
+ const marked = said.filter((m) => m.rects !== undefined).at(-1)?.rects?.[0]
47
81
  const st = stateOf(x, false)
48
82
  const closing = st.state === 'closed' ? x.thread.filter((m) => m.op === 'fixed' || m.op === 'wontfix').at(-1) : undefined
49
83
  const first = x.item.views[0]
@@ -58,7 +92,7 @@ export function noteOf(x: ReviewItem, n: number): TrailerNote | null {
58
92
  shotTime: s.shotTime,
59
93
  section: s.section,
60
94
  text,
61
- ...(pinned ? { pin: { x: pinned.x, y: pinned.y } } : {}),
95
+ ...(marked ? { mark: { x: marked.x, y: marked.y, w: marked.w, h: marked.h } } : {}),
62
96
  state: closing?.op === 'wontfix' ? 'wontfix' : closing ? 'done' : 'open',
63
97
  ...(closing?.note ? { reply: closing.note } : {}),
64
98
  written: x.item.created,
@@ -0,0 +1,45 @@
1
+ // a trailer card's notes in the order of the cut (wiki tools/shipkit/review.md, A trailer): the card's own rectangles,
2
+ // sent with its verdicts or still in the draft, as the lane, the rail, the frame and the verdict's rows show them.
3
+ // Pure: the hub and its tests share it
4
+ import { onFrame, type Rect, type Side } from './model.ts'
5
+
6
+ export interface LaneNote {
7
+ /** `s:<verdict>:<k>` for a sent rectangle, `d:<i>` for the draft's i-th */
8
+ key: string
9
+ /** its number in the order of the cut, over every note of the version */
10
+ n: number
11
+ /** seconds on the render it was drawn on */
12
+ t: number
13
+ side?: Side
14
+ shot?: { name: string; time: number }
15
+ rect: Rect
16
+ /** its index in the draft, null once sent */
17
+ draft: number | null
18
+ }
19
+
20
+ /** every rectangle on a trailer card's frame, sent or drafted, in the order of the cut (its time, then before ahead of
21
+ * after); a rectangle with no time is no trailer note */
22
+ export function laneNotes(sent: readonly { id: string; rects: readonly Rect[] }[], draft: readonly Rect[]): LaneNote[] {
23
+ const all = [
24
+ ...sent.flatMap((v) => v.rects.flatMap((r, k) => ((r.view ?? 0) === 0 && r.t !== undefined ? [{ key: `s:${v.id}:${k}`, rect: r, t: r.t, draft: null }] : []))),
25
+ ...draft.flatMap((r, i) => ((r.view ?? 0) === 0 && r.t !== undefined ? [{ key: `d:${i}`, rect: r, t: r.t, draft: i }] : [])),
26
+ ]
27
+ const sideRank = (r: Rect): number => (r.side === 'before' ? 0 : 1)
28
+ return all
29
+ .sort((a, b) => a.t - b.t || sideRank(a.rect) - sideRank(b.rect))
30
+ .map((x, i) => ({ ...x, n: i + 1, ...(x.rect.side ? { side: x.rect.side } : {}), ...(x.rect.shot ? { shot: x.rect.shot } : {}) }))
31
+ }
32
+
33
+ /** a playing note lights this long either side of its time */
34
+ export const LIT_S = 0.5
35
+
36
+ /** the notes the frame shows now: on the render on screen, on this very frame while paused, within LIT_S while it plays */
37
+ export function notesNow(notes: readonly LaneNote[], at: { time: number; fps: number; paused: boolean; side: Side | undefined }): LaneNote[] {
38
+ return notes.filter((n) => n.side === at.side && (at.paused ? onFrame(n.t, at.time, at.fps) : Math.abs(n.t - at.time) <= LIT_S))
39
+ }
40
+
41
+ /** a draft in the order of the cut once a rectangle joins it: where that rectangle went */
42
+ export function sortedDraft(rects: readonly Rect[], added: Rect): { rects: Rect[]; at: number } {
43
+ const out = [...rects, added].sort((a, b) => (a.t ?? 0) - (b.t ?? 0))
44
+ return { rects: out, at: out.indexOf(added) }
45
+ }
@@ -7,15 +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, montagePage, trailerDir, trailerIds, trailerInfo, videoOf, viewMedia } from './trailer-desk.ts'
11
- import { CUT_RE, noteOf, TRAILER_ID_RE, type NotePin, type NoteState, type TrailerDesk } from './trailer-model.ts'
10
+ import { cutOf, frameNote, frameStill, montagePage, pinnedRender, trailerDir, trailerIds, trailerInfo, videoOf, viewMedia } from './trailer-desk.ts'
11
+ import { CUT_RE, noteMarkOf, noteOf, TRAILER_ID_RE, type NoteMark, type NoteState, type TrailerDesk } from './trailer-model.ts'
12
12
 
13
- const clamp = (v: number): number => Number(Math.min(1, Math.max(0, v)).toFixed(4))
14
-
15
- const pinOf = (v: unknown): NotePin | undefined => {
16
- const p = v as { x?: unknown; y?: unknown } | null | undefined
17
- return p && typeof p.x === 'number' && typeof p.y === 'number' ? { x: p.x, y: p.y } : undefined
18
- }
13
+ /** a note's mark as its message stores it: a review card's Rect */
14
+ const rectsOf = (m: NoteMark) => [{ ...m, comment: '' }]
19
15
 
20
16
  const STATES: readonly NoteState[] = ['open', 'done', 'wontfix']
21
17
 
@@ -59,6 +55,19 @@ export async function trailerRoutes(req: Request, path: string, root: string, di
59
55
  // a render the disk let go plays from the Space: the signed URL lives an hour, the browser keeps half of it
60
56
  return 'path' in at ? ranged(req, at.path) : new Response(null, { status: 302, headers: { Location: at.url, 'Cache-Control': 'private, max-age=1800' } })
61
57
  }
58
+ const pinned = /^\/api\/trailer\/render\/([^/]+)\/([^/]+)\/(\d+)$/.exec(path)
59
+ if (pinned && req.method === 'GET') {
60
+ const [, id = '', cut = '', version = ''] = pinned
61
+ const r = TRAILER_ID_RE.test(id) && CUT_RE.test(cut) ? pinnedRender(root, id, cut, Number(version)) : null
62
+ return r ? Response.json(r, { headers: NO_STORE }) : bad(`no render ${id}/${cut} at ${version}: neither the disk nor the media store holds it`, 404)
63
+ }
64
+ const still = /^\/api\/trailer\/still\/([^/]+)\/([^/]+)\/(\d+)\/(\d+)\.jpg$/.exec(path)
65
+ if (still && req.method === 'GET') {
66
+ // one frame of a render, small, cut once and kept: a note's row in the rail and the verdict
67
+ const [, id = '', cut = '', version = '', frame = ''] = still
68
+ const f = TRAILER_ID_RE.test(id) && CUT_RE.test(cut) ? await frameStill(root, id, cut, Number(version), Number(frame)) : null
69
+ return f ? new Response(Bun.file(f), { headers: { 'Content-Type': 'image/jpeg', 'Cache-Control': 'private, max-age=86400' } }) : bad(`no frame ${frame} of ${id}/${cut} at ${version}`, 404)
70
+ }
62
71
  const mont = /^\/api\/trailer\/montage\/([^/]+)\/([^/]+)$/.exec(path)
63
72
  if (mont && req.method === 'GET') {
64
73
  const page = montagePage(root, mont[1] ?? '', mont[2] ?? '')
@@ -83,7 +92,7 @@ export async function trailerRoutes(req: Request, path: string, root: string, di
83
92
  if (!trailerDir(root, id)) return bad(`no trailer ${id}`)
84
93
  const text = String(b.text ?? '')
85
94
  if (text.trim() === '') return bad('a note says something')
86
- const pin = pinOf(b.pin)
95
+ const mark = noteMarkOf(b.mark)
87
96
  const tmp = mkdtempSync(join(tmpdir(), 'trailer-note-'))
88
97
  try {
89
98
  const still = join(tmp, 'still.png')
@@ -95,7 +104,7 @@ export async function trailerRoutes(req: Request, path: string, root: string, di
95
104
  topic: 'film',
96
105
  title: titleOf(text),
97
106
  text,
98
- ...(pin ? { rects: [{ x: clamp(pin.x), y: clamp(pin.y), w: 0, h: 0, comment: '' }] } : {}),
107
+ ...(mark ? { rects: rectsOf(mark) } : {}),
99
108
  image: still,
100
109
  ...(commit ? { commit } : {}),
101
110
  })
@@ -118,12 +127,12 @@ export async function trailerRoutes(req: Request, path: string, root: string, di
118
127
  if (typeof b.state === 'string' && !STATES.includes(b.state as NoteState)) return bad(`state ${b.state}?`)
119
128
  const text = typeof b.text === 'string' ? b.text.trim() : undefined
120
129
  if (text === '') return bad('a note says something')
121
- const pin = b.pin === null ? null : pinOf(b.pin)
122
- if (text !== undefined || pin !== undefined)
130
+ const mark = b.mark === null ? null : noteMarkOf(b.mark)
131
+ if (text !== undefined || mark !== undefined)
123
132
  appendMessage(dir, nid, {
124
133
  who: 'owner',
125
134
  ...(text !== undefined ? { text } : {}),
126
- ...(pin !== undefined ? { rects: pin ? [{ x: clamp(pin.x), y: clamp(pin.y), w: 0, h: 0, comment: '' }] : [] } : {}),
135
+ ...(mark !== undefined ? { rects: mark ? rectsOf(mark) : [] } : {}),
127
136
  })
128
137
  const reply = typeof b.reply === 'string' ? b.reply : undefined
129
138
  if (b.state === 'open') act(dir, nid, 'reopen', 'owner')
@@ -0,0 +1,71 @@
1
+ // the shipkit macOS app's Dock badge and notifications, fed by the page (wiki tools/shipkit/home-pages.md, the
2
+ // shipkit app's Dock badge): the count the rail draws, posted when it changes, and each card that starts waiting.
3
+ // The app's WebKit message handler `shipkit` is the only listener: a browser tab has none, and nothing is posted.
4
+ //
5
+ // the one constraint a reader breaks first: the first answer of the daemon is the seed, so the backlog at app start
6
+ // never notifies; the list this browser kept from its last load is not that answer
7
+ import { reaction } from 'mobx'
8
+ import type { Project } from './projects-svc.ts'
9
+
10
+ /** a card that started waiting, as the app's notification names it; `url` opens it where no page answers */
11
+ export type AppCard = { id: string; title: string; repo: string; url: string }
12
+ /** `seed`: every card waiting at the page's first daemon answer; the app notifies those it never saw, unless it is
13
+ * the first seed of its life (the backlog at start) */
14
+ export type AppNote = { waiting: number; keys: string[] } | { seed: AppCard[] } | { card: AppCard }
15
+ export type Post = (note: AppNote) => void
16
+ /** the absolute address of a card's review page */
17
+ export type CardUrl = (repo: string, id: string) => string
18
+
19
+ /** the app's handler, or null in a browser tab */
20
+ export function appPost(w: unknown = globalThis): Post | null {
21
+ const h = (w as { webkit?: { messageHandlers?: { shipkit?: { postMessage(m: unknown): void } } } }).webkit?.messageHandlers?.shipkit
22
+ return h == null ? null : (note) => h.postMessage(note)
23
+ }
24
+
25
+ /** the house wide count the badge shows: the rail's per repo numbers summed */
26
+ export const waitingOf = (list: Project[]): number => list.reduce((n, p) => n + p.cards.length, 0)
27
+
28
+ /** what one daemon answer posts: the count and the `repo/id` keys waiting when either moved (the app removes the
29
+ * banners of every other card), the seed at the first answer, then each card this page had not seen. The app owns
30
+ * the set of cards notified: this one only keeps a poll from posting them again */
31
+ export class AppBridge {
32
+ private seen: Set<string> | null = null
33
+ private last: string | null = null
34
+
35
+ constructor(private readonly post: Post, private readonly cardUrl: CardUrl) {}
36
+
37
+ update(list: Project[]): void {
38
+ const cards = list.flatMap((p) => p.cards.map((c) => ({ key: `${p.name}/${c.id}`, card: { id: c.id, title: c.title, repo: p.name, url: this.cardUrl(p.name, c.id) } })))
39
+ const keys = cards.map((c) => c.key)
40
+ const now = JSON.stringify(keys)
41
+ if (now !== this.last) {
42
+ this.last = now
43
+ this.post({ waiting: waitingOf(list), keys })
44
+ }
45
+ const seen = this.seen
46
+ if (seen == null) {
47
+ this.seen = new Set(cards.map((c) => c.key))
48
+ this.post({ seed: cards.map((c) => c.card) })
49
+ return
50
+ }
51
+ for (const c of cards) {
52
+ if (seen.has(c.key)) continue
53
+ seen.add(c.key)
54
+ this.post({ card: c.card })
55
+ }
56
+ }
57
+ }
58
+
59
+ /** what the app calls on a notification's click: that card in this window, in place, or the inbox */
60
+ export type AppHooks = { openCard(repo: string, id: string): void; openInbox(): void }
61
+
62
+ /** feeds the app from the project list once it is the daemon's, and hands the app the page's hooks; a no-op
63
+ * outside the app. Returns the stop */
64
+ export function startAppBridge(o: { projects: { fresh: boolean; list: Project[] }; hooks: AppHooks; cardUrl: CardUrl; post?: Post | null; w?: unknown }): () => void {
65
+ const w = o.w ?? globalThis
66
+ const post = o.post === undefined ? appPost(w) : o.post
67
+ if (post == null) return () => {}
68
+ const bridge = new AppBridge(post, o.cardUrl)
69
+ ;(w as { shipkitApp?: AppHooks }).shipkitApp = o.hooks
70
+ return reaction(() => (o.projects.fresh ? o.projects.list : null), (list) => { if (list != null) bridge.update(list) }, { fireImmediately: true })
71
+ }