rvlib-shipkit 2.22.1 → 2.24.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 (139) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/package.json +1 -1
  3. package/src/agent-time/render.ts +28 -14
  4. package/src/agent-time/report.ts +46 -25
  5. package/src/agent-time/store.ts +30 -10
  6. package/src/agent-time/timeline.ts +43 -15
  7. package/src/annex/annex.ts +3 -0
  8. package/src/annex/born.ts +464 -0
  9. package/src/annex/flush.ts +46 -0
  10. package/src/annex/offload.ts +171 -38
  11. package/src/annex/snapshots.ts +53 -0
  12. package/src/annex/tidy.ts +368 -0
  13. package/src/asks/asks-queue.ts +32 -11
  14. package/src/checks/SK041-annex-links.check.ts +4 -2
  15. package/src/checks/SK043-scratch-on-the-mac.check.ts +45 -0
  16. package/src/checks/SK044-behind-upstream.check.ts +38 -0
  17. package/src/cli/cmd_Annex.ts +60 -9
  18. package/src/cli/cmd_Asks.ts +2 -0
  19. package/src/cli/cmd_Backup.ts +7 -5
  20. package/src/cli/cmd_Bump.ts +1 -0
  21. package/src/cli/cmd_Capacity.ts +26 -0
  22. package/src/cli/cmd_Check.ts +1 -0
  23. package/src/cli/cmd_Checks.ts +1 -0
  24. package/src/cli/cmd_Ci.ts +1 -0
  25. package/src/cli/cmd_Commands.ts +50 -14
  26. package/src/cli/cmd_Home.ts +0 -1
  27. package/src/cli/cmd_Hooks.ts +1 -0
  28. package/src/cli/cmd_Mv.ts +1 -0
  29. package/src/cli/cmd_Rec.ts +17 -7
  30. package/src/cli/cmd_Reflect.ts +1 -0
  31. package/src/cli/cmd_Releases.ts +1 -0
  32. package/src/cli/cmd_Review.ts +124 -17
  33. package/src/cli/cmd_Secret.ts +41 -2
  34. package/src/cli/cmd_Shot.ts +1 -0
  35. package/src/cli/cmd_Status.ts +1 -0
  36. package/src/cli/cmd_Time.ts +3 -1
  37. package/src/cli/cmd_Tmp.ts +82 -0
  38. package/src/cli/cmd_Wiki.ts +1 -0
  39. package/src/cli/registry.ts +13 -1
  40. package/src/collections/pings.ts +1 -1
  41. package/src/core/capacity.ts +71 -0
  42. package/src/core/check-runner.ts +86 -15
  43. package/src/core/machine-db.ts +8 -0
  44. package/src/core/motherhome.ts +67 -9
  45. package/src/core/slots.ts +49 -12
  46. package/src/core/trace-audit.ts +4 -1
  47. package/src/drill/run.ts +5 -2
  48. package/src/home/daemon-jobs.ts +10 -3
  49. package/src/home/global-units.ts +3 -0
  50. package/src/home/gui-app/ShipkitGui.swift +1 -0
  51. package/src/home/home-launchd.ts +11 -3
  52. package/src/home/home-routes.ts +11 -4
  53. package/src/home/machine-host.ts +65 -0
  54. package/src/home/machine-stores.ts +30 -4
  55. package/src/home/machine-temp.ts +493 -0
  56. package/src/home/other-macs.ts +74 -0
  57. package/src/home/pm.ts +4 -1
  58. package/src/home/run-daemon.ts +10 -2
  59. package/src/home/run-pm.ts +1 -0
  60. package/src/home/serve-web.ts +2 -2
  61. package/src/home/via-hub.ts +6 -1
  62. package/src/identities/identities.ts +92 -24
  63. package/src/init-repo.ts +7 -3
  64. package/src/ledger/ledger.ts +6 -0
  65. package/src/ledger/store.ts +6 -0
  66. package/src/media-store/backup/keys.ts +21 -6
  67. package/src/media-store/backup/manifest.ts +52 -11
  68. package/src/media-store/backup/restore.ts +17 -10
  69. package/src/media-store/backup/run.ts +5 -2
  70. package/src/media-store/backup/sources.ts +2 -1
  71. package/src/media-store/daemon.ts +2 -2
  72. package/src/media-store/purge.ts +4 -0
  73. package/src/mv/mv-md.ts +121 -42
  74. package/src/recordings/load.ts +3 -3
  75. package/src/recordings/model.ts +7 -0
  76. package/src/recordings/open.ts +12 -0
  77. package/src/recordings/presets.ts +12 -5
  78. package/src/recordings/recorder-app/Capture.swift +34 -5
  79. package/src/recordings/recorder-app/Clip.swift +126 -17
  80. package/src/recordings/recorder-app/Editor.swift +177 -7
  81. package/src/recordings/recorder-app/Hud.swift +189 -0
  82. package/src/recordings/recorder-app/Tray.swift +179 -36
  83. package/src/recordings/recorder-app/icon.svg +16 -0
  84. package/src/recordings/recorder-app/main.swift +349 -18
  85. package/src/recordings/recorder-app.ts +8 -4
  86. package/src/recordings/recorder.shipkit.ts +2 -1
  87. package/src/recordings/routes.ts +52 -6
  88. package/src/recordings/run-recorder.ts +2 -1
  89. package/src/recordings/share.ts +27 -0
  90. package/src/recordings/take.ts +36 -4
  91. package/src/recordings/view.ts +11 -0
  92. package/src/reflect/transcript.ts +56 -11
  93. package/src/releases/from-card.ts +45 -3
  94. package/src/releases/model.ts +6 -0
  95. package/src/releases/store.ts +8 -1
  96. package/src/repo-config.ts +14 -4
  97. package/src/review/cells.ts +24 -3
  98. package/src/review/format.ts +33 -9
  99. package/src/review/media-kind.ts +14 -11
  100. package/src/review/media-read.ts +6 -5
  101. package/src/review/model.ts +104 -7
  102. package/src/review/paste.ts +2 -1
  103. package/src/review/previews.ts +123 -36
  104. package/src/review/routes.ts +29 -18
  105. package/src/review/store.ts +74 -12
  106. package/src/review/threads.ts +7 -5
  107. package/src/secrets/copy.ts +110 -0
  108. package/src/secrets/list.ts +17 -7
  109. package/src/serve/hub-app/home-strip.css +5 -0
  110. package/src/serve/hub-app/home-strip.tsx +18 -0
  111. package/src/serve/hub-app/hub-app.tsx +2 -1
  112. package/src/serve/hub-app/hub.css +18 -0
  113. package/src/serve/hub-app/inbox.css +1 -0
  114. package/src/serve/hub-app/pull-refresh.tsx +88 -0
  115. package/src/serve/hub-app/recordings-st.ts +135 -24
  116. package/src/serve/hub-app/recordings-view.tsx +293 -54
  117. package/src/serve/hub-app/recordings.css +77 -24
  118. package/src/serve/hub-app/review/review-cells.tsx +52 -13
  119. package/src/serve/hub-app/review/review-list.tsx +6 -1
  120. package/src/serve/hub-app/review/review-st.ts +6 -5
  121. package/src/serve/hub-app/review/review-thread.tsx +3 -1
  122. package/src/serve/hub-app/review/review-views.tsx +18 -11
  123. package/src/serve/hub-app/review/thread-st.ts +82 -14
  124. package/src/serve/hub-app/review.css +15 -2
  125. package/src/serve/hub-runtime.ts +2 -1
  126. package/src/serve/run-serve.ts +4 -2
  127. package/src/serve/serve-hub.ts +9 -2
  128. package/src/shipkit-files.ts +5 -0
  129. package/src/social/drafts.ts +4 -3
  130. package/src/social/load.ts +7 -2
  131. package/src/social/publish/discord.ts +10 -3
  132. package/src/suite/child-tools.ts +45 -0
  133. package/src/suite/judge-suites.ts +10 -22
  134. package/src/suite/select.ts +83 -8
  135. package/src/suite/suite-cli.ts +38 -14
  136. package/src/suite/suite-cores.ts +68 -0
  137. package/src/suite/suite-reads-preload.ts +8 -6
  138. package/src/ts/config.ts +44 -0
  139. package/src/ts/rename.ts +11 -1
@@ -1,8 +1,17 @@
1
1
  // what `sk review inbox`, `show`, `watch`, `next` and `board` print of an item and its answer (wiki tools/shipkit/review.md):
2
2
  // one record per thread, rectangles normalized and in pixels, a frame note's cut, shot and time into it, and the lines the
3
3
  // repo's unit adds (a kind's facts, a source's), handed in as `more` so this module stays pure
4
- import { aboutText, isFrame, isGallery, isPair, NO_SPEC, placeText, stateOf, unreadBy, verdictOf, type Message, type Rect, type ReviewItem, type Spec, type Subject } from './model.ts'
5
- import { answererOf, conversationOf, openingOf, type Thread } from './threads.ts'
4
+ import { aboutText, isFrame, isGallery, isPair, NO_SPEC, placeText, stateOf, takenBackOf, unreadBy, updateTag, verdictOf, type Message, type Rect, type ReviewItem, type ReviewStatus, type Spec, type Subject } from './model.ts'
5
+ import { answererOf, conversationOf, membersOf, openingOf, type Thread } from './threads.ts'
6
+
7
+ /** what a message is in a thread beyond its words: ` [update 2 (still broken)]` on an agent's update, ` (on update 2
8
+ * (still broken))` on his hint about one */
9
+ const updateText = (x: ReviewItem, m: Message): string => {
10
+ const own = m.update ? updateTag(x, m.id) : null
11
+ if (own) return ` [${own}]`
12
+ const re = m.re ? updateTag(x, m.re) : null
13
+ return re ? ` (on ${re})` : ''
14
+ }
6
15
 
7
16
  /** the lines a repo's unit adds under an item's head, and its spec for the words */
8
17
  export interface Say {
@@ -46,11 +55,21 @@ export const refOf = (x: ReviewItem): string => (x.item.origin.by === 'player' ?
46
55
 
47
56
  /** one owner reply, for a monitor; on an item a card answers, it reads on the card's thread */
48
57
  export const replyLine = (x: ReviewItem, m: Message, card: ReviewItem | null = null): string =>
49
- `${(card ?? x).item.id} reply "${(card ?? x).item.title}"${card ? ` (on ${refOf(x)})` : ''}: ${flat(m.text ?? '')}${m.image ? ` [image thread/${m.image}]` : ''}`
58
+ `${(card ?? x).item.id} reply "${(card ?? x).item.title}"${card ? ` (on ${refOf(x)})` : ''}${updateText(x, m)}: ${flat(m.text ?? '')}${m.image ? ` [image thread/${m.image}]` : ''}`
59
+
60
+ const TOOK: Record<ReviewStatus, string> = { approved: 'approval', 'approved-with-fix': '« ok with a fix »', rejected: 'rejection', archived: '« archived, later »' }
61
+
62
+ /** each verdict he took back, unseen: what it was, when he gave it, and that it no longer holds */
63
+ export const takeBackTexts = (x: ReviewItem): { m: Message; text: string }[] =>
64
+ takenBackOf(x).map(({ m, took, given }) => ({
65
+ m,
66
+ text: `he took his ${TOOK[took]} back (given ${given}): the card waits for his answer again and that ${TOOK[took]} no longer holds; hold or undo what you did on it, then sk review seen ${x.item.id}`,
67
+ }))
50
68
 
51
- /** what watch prints of an item, each with the key it prints once under: an unseen feedback (again when sent again), each unseen reply */
69
+ /** what watch prints of an item, each with the key it prints once under: a verdict he took back, an unseen feedback (again
70
+ * when sent again), each unseen reply */
52
71
  export function watchLines(x: ReviewItem, items: readonly ReviewItem[] = []): { key: string; text: string }[] {
53
- const out: { key: string; text: string }[] = []
72
+ const out: { key: string; text: string }[] = takeBackTexts(x).map((t) => ({ key: `${x.item.id}#${t.m.id}`, text: `${x.item.id} taken back "${x.item.title}": ${t.text}` }))
54
73
  const f = verdictOf(x)
55
74
  if (f && !f.seen) out.push({ key: `${x.item.id}@${f.at}`, text: line(x) })
56
75
  const card = x.item.origin.by === 'agent' ? null : answererOf(x.item.id, items)
@@ -83,7 +102,11 @@ export function threadDetail(t: Thread, dir: string, full = false, say: Say = PL
83
102
  if (full) {
84
103
  const conv = conversationOf(t)
85
104
  if (conv.length > 0) out.push(' thread:')
86
- for (const m of conv) out.push(` ${m.who} ${m.at}${m.on === t.head.item.id ? '' : ` [on ${m.on}]`}: ${flat(m.text ?? '')}${m.image ? ` [image ${dir}/${m.on}/thread/${m.image}]` : ''}`)
105
+ const members = membersOf(t)
106
+ for (const m of conv) {
107
+ const of = members.find((y) => y.item.id === m.on)
108
+ out.push(` ${m.who} ${m.at}${m.on === t.head.item.id ? '' : ` [on ${m.on}]`}${of ? updateText(of, m) : ''}: ${flat(m.text ?? '')}${m.image ? ` [image ${dir}/${m.on}/thread/${m.image}]` : ''}`)
109
+ }
87
110
  }
88
111
  return out.join('\n')
89
112
  }
@@ -120,7 +143,7 @@ export function detail(x: ReviewItem, dir: string, full = false, followed = fals
120
143
  const head = ` "${r.title}" (${aboutText(r, say.spec)})`
121
144
  const frame = subjectText(r.subject)
122
145
  const sub = [...(frame ? [frame] : []), ...say.more(x)]
123
- const replies = unreadBy(x, 'agent').map((m) => ` reply ${m.at}: ${m.text}${m.image ? ` [image ${dir}/${r.id}/thread/${m.image}]` : ''}`)
146
+ const replies = unreadBy(x, 'agent').map((m) => ` reply ${m.at}${updateText(x, m)}: ${m.text}${m.image ? ` [image ${dir}/${r.id}/thread/${m.image}]` : ''}`)
124
147
  if (r.origin.by !== 'agent') {
125
148
  const st = stateOf(x, followed)
126
149
  const said = x.thread.filter((m) => m.who === 'owner' || m.who === 'player')
@@ -139,9 +162,10 @@ export function detail(x: ReviewItem, dir: string, full = false, followed = fals
139
162
  ...(image.length > 0 ? [` image: ${image.map((n) => `${dir}/${r.id}/${n}`).join(' ')}`] : []),
140
163
  ].join('\n')
141
164
  }
142
- if (!f) return [`${r.id} NO VERDICT YET`, head, ...sub, ...replies].join('\n')
165
+ const back = takeBackTexts(x).map((t) => ` taken back ${t.m.at}: ${t.text}`)
166
+ if (!f) return [`${r.id} ${back.length > 0 ? 'TAKEN BACK, NO VERDICT NOW' : 'NO VERDICT YET'}`, head, ...sub, ...back, ...replies].join('\n')
143
167
  const pick = pickText(x)
144
- const out = [`${r.id} ${f.status.toUpperCase()} ${f.at}`, head, ...sub, ...(pick ? [` ${pick}`] : []), ` comment: ${f.comment || '(none)'}`]
168
+ const out = [`${r.id} ${f.status.toUpperCase()} ${f.at}`, head, ...sub, ...back, ...(pick ? [` ${pick}`] : []), ` comment: ${f.comment || '(none)'}`]
145
169
  for (const t of reactionTexts(x)) out.push(` view ${t}`)
146
170
  const px = (v: number, of: number): number => Math.round(v * of)
147
171
  const views = r.views
@@ -1,6 +1,6 @@
1
1
  // the review store as a kind of the media store (wiki tools/shipkit/review.md, Media in the Space): each file a card's
2
2
  // views name, by the facts its item.json keeps; kept on the disk while its thread is active or spoke in the window; an
3
- // image's previews sent up before it goes
3
+ // image's previews and a clip's play copy sent up before it goes
4
4
  import { existsSync, statSync } from 'node:fs'
5
5
  import { join } from 'node:path'
6
6
  import type { MediaKind, MediaRow } from '../media-store/kind.ts'
@@ -9,7 +9,7 @@ import type { Space } from '../media-store/space.ts'
9
9
  import { threadIndex } from './cells.ts'
10
10
  import { previewKey, REVIEW_KIND } from './media-read.ts'
11
11
  import { mediaFilesOf } from './model.ts'
12
- import { previewFile, PREVIEW_W, type PreviewSize } from './previews.ts'
12
+ import { playsCopy, previewFile, PREVIEW_W, type PreviewSize } from './previews.ts'
13
13
  import { fillMedia, readAll, readAllCached, storeDir, storeStamp } from './store.ts'
14
14
  import { membersOf } from './threads.ts'
15
15
 
@@ -63,22 +63,25 @@ export const reviewMedia: MediaKind = {
63
63
  return (r) => ({ pinned: pinned.has(r.item), used: used.get(r.item) })
64
64
  },
65
65
  async beforePurge(dir, space, r) {
66
- if (IMAGE.test(r.name) && !r.name.startsWith('thread/')) await previewsUp(dir, space, r)
66
+ if (r.name.startsWith('thread/')) return
67
+ if (IMAGE.test(r.name)) await previewsUp(dir, space, r, Object.keys(PREVIEW_W) as PreviewSize[], 'webp')
68
+ else if (playsCopy(dir, r.item, r.name)) await previewsUp(dir, space, r, ['fit'], 'mp4')
67
69
  },
68
70
  }
69
71
 
70
- /** an image's previews made (when the cache lacks them) and sent up, before the image leaves the disk: a PUT and a
71
- * HEAD each, none for a preview the index saw up */
72
- async function previewsUp(dir: string, space: Space, r: { item: string; name: string; key: string }): Promise<void> {
72
+ /** a file's previews made (when the cache lacks them) and sent up, before the file leaves the disk: an image's webps,
73
+ * a clip's play copy; a PUT and a HEAD each, none for a preview the index saw up */
74
+ async function previewsUp(dir: string, space: Space, r: { item: string; name: string; key: string }, sizes: readonly PreviewSize[], ext: 'webp' | 'mp4'): Promise<void> {
73
75
  const sha = r.key.slice(`${REVIEW_KIND}/`.length).replace(/\.[^.]+$/, '')
74
- for (const size of Object.keys(PREVIEW_W) as PreviewSize[]) {
75
- const key = previewKey({ sha }, size)
76
- // up already: a card that shares the image, or a purge that stopped after it
76
+ for (const size of sizes) {
77
+ const key = previewKey({ sha }, size, ext)
78
+ // up already: a card that shares the file, or a purge that stopped after it
77
79
  if (isUp(key)) continue
78
80
  const file = await previewFile(dir, r.item, r.name, size)
79
- if (!file || !existsSync(file)) continue
81
+ // a copy that failed answers the clip itself, never sent up as its preview
82
+ if (!file || !existsSync(file) || file === join(dir, r.item, r.name)) continue
80
83
  const n = statSync(file).size
81
- await space.put(key, file, 'image/webp')
84
+ await space.put(key, file, ext === 'mp4' ? 'video/mp4' : 'image/webp')
82
85
  if ((await space.head(key))?.size === n) recordUp(key, n)
83
86
  }
84
87
  }
@@ -11,8 +11,9 @@ export const REVIEW_KIND = 'review'
11
11
 
12
12
  /** where the Space keeps a file of a card */
13
13
  export const reviewKey = (f: Pick<MediaFact, 'sha'>, name: string): string => mediaKey(REVIEW_KIND, f, name)
14
- /** where the Space keeps an image's preview at a size: by the image's own sha, so it is found from the item alone */
15
- export const previewKey = (f: Pick<MediaFact, 'sha'>, size: string): string => `${REVIEW_KIND}/${f.sha}.${size}.webp`
14
+ /** where the Space keeps a file's preview at a size (an image's webp, a clip's play copy): by the file's own sha, so it
15
+ * is found from the item alone */
16
+ export const previewKey = (f: Pick<MediaFact, 'sha'>, size: string, ext: 'webp' | 'mp4' = 'webp'): string => `${REVIEW_KIND}/${f.sha}.${size}.${ext}`
16
17
 
17
18
  /** the fact a head keeps for one of its files, read from its item.json alone */
18
19
  export function factOfFile(dir: string, id: string, name: string): MediaFact | null {
@@ -31,10 +32,10 @@ export async function remoteUrl(dir: string, id: string, name: string): Promise<
31
32
  return f ? signedUrl(reviewKey(f, name), f.size) : null
32
33
  }
33
34
 
34
- /** a signed URL for an image's preview at a size, when the Space holds it */
35
- export async function remotePreviewUrl(dir: string, id: string, name: string, size: string): Promise<string | null> {
35
+ /** a signed URL for a file's preview at a size, when the Space holds it */
36
+ export async function remotePreviewUrl(dir: string, id: string, name: string, size: string, ext: 'webp' | 'mp4' = 'webp'): Promise<string | null> {
36
37
  const f = factOfFile(dir, id, name)
37
- return f ? signedIfUp(previewKey(f, size)) : null
38
+ return f ? signedIfUp(previewKey(f, size, ext)) : null
38
39
  }
39
40
 
40
41
  /** the path of an item's file on the disk, fetched back from the Space first when the disk let it go; null when neither
@@ -378,6 +378,17 @@ export interface ReviewReaction {
378
378
  export const OPS = ['dispatch', 'ask', 'answer', 'reassign', 'claim', 'release', 'blocked', 'fixed', 'done', 'wontfix', 'drop', 'withdraw', 'reopen', 'ready', 'seen'] as const
379
379
  export type Op = (typeof OPS)[number]
380
380
 
381
+ /** what an agent's update says of the work, at a glance: still broken, better, or fixed (it asks the owner's verdict again) */
382
+ export const UPDATE_STATES = ['broken', 'better', 'fixed'] as const
383
+ export type UpdateState = (typeof UPDATE_STATES)[number]
384
+ export const UPDATE_WORDS: Record<UpdateState, string> = { broken: 'still broken', better: 'better', fixed: 'fixed' }
385
+
386
+ /** an agent's progress post on a card: its state, and the view of the card that holds its picture, clip or sound */
387
+ export interface MessageUpdate {
388
+ state: UpdateState
389
+ view?: number
390
+ }
391
+
381
392
  /** one act on an item, one file of `thread/`, never rewritten */
382
393
  export interface Message {
383
394
  id: string
@@ -403,6 +414,10 @@ export interface Message {
403
414
  /** `seen`: the messages it read */
404
415
  of?: string[]
405
416
  fix?: { commit: string }
417
+ /** an agent's update: its line in `text`, its media a view of the item */
418
+ update?: MessageUpdate
419
+ /** his word on one message of the thread (a hint on an update): its id */
420
+ re?: string
406
421
  }
407
422
 
408
423
  /** what the store reads of one folder, what the list sends */
@@ -449,10 +464,28 @@ export function textOf(v: unknown): { text: string } | { error: string } {
449
464
  const readBy = (x: ReviewItem, party: Party): Set<string> =>
450
465
  new Set(x.thread.flatMap((m) => (m.op === 'seen' && partyOf(m.who) === party ? (m.of ?? []) : [])))
451
466
 
452
- /** the talk of the other party that `party` has not read: replies, verdicts, ratings */
467
+ /** the owner took a verdict back on an agent's card: news for the agent, which may have acted on that verdict */
468
+ const isTakeBack = (x: ReviewItem, m: Message): boolean => m.op === 'reopen' && m.who === 'owner' && x.item.origin.by === 'agent'
469
+
470
+ /** the talk of the other party that `party` has not read: replies, verdicts, ratings, his verdicts taken back */
453
471
  const unreadTalk = (x: ReviewItem, party: Party): Message[] => {
454
472
  const read = readBy(x, party)
455
- return x.thread.filter((m) => isTalk(m) && partyOf(m.who) !== party && !read.has(m.id))
473
+ return x.thread.filter((m) => (isTalk(m) || isTakeBack(x, m)) && partyOf(m.who) !== party && !read.has(m.id))
474
+ }
475
+
476
+ /** each verdict the owner took back that no agent marked seen: his reopen and the verdict it took back */
477
+ export function takenBackOf(x: ReviewItem): { m: Message; took: ReviewStatus; given: string }[] {
478
+ const unread = new Set(unreadTalk(x, 'agent').map((m) => m.id))
479
+ const out: { m: Message; took: ReviewStatus; given: string }[] = []
480
+ let v: Message | undefined
481
+ for (const n of x.thread) {
482
+ if (n.verdict !== undefined) v = n
483
+ else if (n.op === 'reopen' || isFixedUpdate(n)) {
484
+ if (v?.verdict && isTakeBack(x, n) && unread.has(n.id)) out.push({ m: n, took: v.verdict, given: v.at })
485
+ v = undefined
486
+ }
487
+ }
488
+ return out
456
489
  }
457
490
 
458
491
  /** the replies of the other party `party` has not read; a verdict is no reply (verdictOf says whether it was seen) */
@@ -474,12 +507,26 @@ export interface Verdict {
474
507
  seen: boolean
475
508
  }
476
509
 
510
+ /** an agent's update saying the work is fixed: it asks the owner's verdict again, as a reopen does */
511
+ const isFixedUpdate = (m: Message): boolean => m.update?.state === 'fixed' && partyOf(m.who) === 'agent'
512
+
513
+ /** the agent's updates on an item, oldest first */
514
+ export const updatesOf = (x: ReviewItem): Message[] => x.thread.filter((m) => m.update !== undefined && partyOf(m.who) === 'agent')
515
+
516
+ /** an update as the CLI and the page name it: `update 3 (still broken)`; null for a message that is no update */
517
+ export function updateTag(x: ReviewItem, id: string): string | null {
518
+ const all = updatesOf(x)
519
+ const k = all.findIndex((m) => m.id === id)
520
+ const u = all[k]?.update
521
+ return u ? `update ${k + 1} (${UPDATE_WORDS[u.state]})` : null
522
+ }
523
+
477
524
  export function verdictOf(x: ReviewItem): Verdict | null {
478
525
  let m: Message | undefined
479
526
  let text: string | undefined
480
527
  let rects: Rect[] | undefined
481
528
  for (const n of x.thread) {
482
- if (n.op === 'reopen') [m, text, rects] = [undefined, undefined, undefined]
529
+ if (n.op === 'reopen' || isFixedUpdate(n)) [m, text, rects] = [undefined, undefined, undefined]
483
530
  else if (n.verdict !== undefined) {
484
531
  if (m?.verdict !== n.verdict) [text, rects] = [undefined, undefined]
485
532
  m = n
@@ -574,6 +621,14 @@ export function stateOf(x: ReviewItem, superseded: boolean): ItemState {
574
621
  s = { ...keep, state: 'closed', why: 'rated' }
575
622
  continue
576
623
  }
624
+ // an agent's update on its card: still broken or better holds it in work, fixed asks the owner's verdict again
625
+ if (m.update !== undefined && i.origin.by === 'agent' && partyOf(m.who) === 'agent') {
626
+ if (m.update.state === 'fixed') {
627
+ if (s.state === 'draft' || s.state === 'claimed' || s.state === 'closed') s = { ...keep, state: 'asks' }
628
+ given = s
629
+ } else if (s.state === 'asks') s = { ...keep, state: 'draft' }
630
+ continue
631
+ }
577
632
  // the owner's words on a question answer it: it goes back to the dispatcher
578
633
  if (m.op === undefined && partyOf(m.who) === 'owner' && m.text !== undefined && s.state === 'question') {
579
634
  s = { ...keep, state: 'new' }
@@ -599,6 +654,9 @@ export function stateOf(x: ReviewItem, superseded: boolean): ItemState {
599
654
  case 'blocked':
600
655
  s = { ...keep, state: 'blocked' }
601
656
  break
657
+ case 'ready':
658
+ if (s.state === 'draft') s = { ...keep, state: 'asks' }
659
+ break
602
660
  case 'fixed':
603
661
  s = { ...keep, state: 'closed', why: 'fixed' }
604
662
  break
@@ -628,6 +686,9 @@ export function stateOf(x: ReviewItem, superseded: boolean): ItemState {
628
686
  return s
629
687
  }
630
688
 
689
+ /** a card in work: a draft on a live shot, or an agent's card its latest update calls still broken or better */
690
+ export const inWork = (x: ReviewItem): boolean => stateOf(x, false).state === 'draft'
691
+
631
692
  /** the states each op leaves from */
632
693
  const FROM: Record<Exclude<Op, 'seen'>, readonly State[]> = {
633
694
  dispatch: ['new', 'blocked'],
@@ -711,15 +772,44 @@ export interface Watcher extends WatchFilter {
711
772
  export const coversCard = (f: WatchFilter, x: ReviewItem): boolean =>
712
773
  (f.session === null || (x.item.origin.by === 'agent' && x.item.origin.session === f.session)) && (f.lane === null || laneOf(x) === f.lane)
713
774
 
775
+ /** who answers an agent's card, its reply or its seen: the worker of a live claim on it, else the lane that made it,
776
+ * else (a card with no lane) the session that sent it. null when `me` is that one, else why not and the way out.
777
+ * Another session hearing the verdict (a bare watch) is refused, so it never answers over the maker; a plain approval,
778
+ * which owes nothing, anyone marks seen. An item he raised, a player's or an auto one: the claim rules decide */
779
+ export function notAnswererOf(x: ReviewItem, me: { lane: string | null; session: string | null }, op: 'reply' | 'seen'): string | null {
780
+ const o = x.item.origin
781
+ if (o.by !== 'agent') return null
782
+ const s = stateOf(x, false)
783
+ if (op === 'seen' && s.state === 'closed' && s.why === 'approved') return null
784
+ const id = x.item.id
785
+ const takeOver = `another lane takes it over with sk review claim ${id} --as <lane>`
786
+ const claimed = s.state === 'claimed' && s.since !== undefined ? s.worker : undefined
787
+ const lane = claimed ?? o.lane
788
+ if (lane) return me.lane === lane ? null : `${id} is answered by lane ${lane} (${claimed ? 'its claim' : 'it made the card'}): as that lane, SK_AGENT=${lane} or --as ${lane}; ${takeOver}`
789
+ if (!o.session || me.session === o.session) return null
790
+ return `${id} is answered by the session that sent it (${o.session.slice(0, 8)}): ${takeOver}`
791
+ }
792
+
714
793
  /** the live watchers that will read his answer on any of these cards */
715
794
  export const listenersOf = (cards: readonly ReviewItem[], watchers: readonly Watcher[]): Watcher[] => watchers.filter((w) => cards.some((x) => coversCard(w, x)))
716
795
 
717
796
  /** who listens, in plain words: one lane's watch by its lane, any other by « an agent », several by their count */
718
797
  export function listenWords(ws: readonly Watcher[]): string {
719
- const [w] = ws
720
- if (w === undefined) return 'nobody listens'
721
- if (ws.length > 1) return `${ws.length} agents listening`
722
- return w.lane ? `the ${w.lane} lane is listening` : 'an agent is listening'
798
+ if (ws.length === 0) return 'nobody listens'
799
+ // a filtered watch is the card's own (its session or its lane); a bare one hears every card, for the dispatcher
800
+ const own = ws.filter((w) => w.lane !== null || w.session !== null)
801
+ const bare = ws.length - own.length
802
+ if (own.length === 0) return 'only a watch of every card hears it'
803
+ const lane = own.find((w) => w.lane !== null)?.lane
804
+ const head = lane ? `the ${lane} lane is listening` : 'its agent is listening'
805
+ return bare === 0 ? head : `${head} · ${bare} more ${bare === 1 ? 'watches' : 'watch'} every card`
806
+ }
807
+
808
+ /** why a bare watch may not start: another one lives in the repo, so a verdict would reach two sessions. null when
809
+ * none does. A repo keeps one, the dispatcher's; every other session watches its own cards or its lane's */
810
+ export function bareWatchTaken(live: readonly Watcher[], self: number): string | null {
811
+ const other = live.find((w) => w.pid !== self && w.lane === null && w.session === null)
812
+ return other ? `a watch of every card already runs (pid ${other.pid}): a repo keeps one, the dispatcher's. Yours: sk review watch --mine, or --lane <id>` : null
723
813
  }
724
814
 
725
815
  /** what `review add` says when no live watch of the card's own session or lane will read his answer, else null: an
@@ -906,6 +996,13 @@ export function messageProblems(v: unknown, name: string): string[] {
906
996
  for (const k of ['text', 'image', 'note']) if (v[k] !== undefined && typeof v[k] !== 'string') out.push(`${k}: a text`)
907
997
  if (v.pick !== undefined && !(Number.isInteger(v.pick) && (v.pick as number) >= 0 && v.verdict !== undefined)) out.push('pick: a view index, on a verdict')
908
998
  if (v.op === 'seen' && !(Array.isArray(v.of) && v.of.every((x) => typeof x === 'string'))) out.push('of: the ids a seen message read')
999
+ if (v.update !== undefined) {
1000
+ const u = v.update
1001
+ if (!obj(u) || !UPDATE_STATES.includes(u.state as UpdateState) || (u.view !== undefined && !(Number.isInteger(u.view) && (u.view as number) >= 0)))
1002
+ out.push(`update: { state: ${UPDATE_STATES.join(', ')}, view? }`)
1003
+ if (typeof v.text !== 'string') out.push('update: its line in text')
1004
+ }
1005
+ if (v.re !== undefined && !(typeof v.re === 'string' && MESSAGE_RE.test(v.re))) out.push('re: the id of a message of the thread')
909
1006
  if (v.op === undefined && v.verdict === undefined && v.rate === undefined && typeof v.text !== 'string' && !Array.isArray(v.rects))
910
1007
  out.push('a message says something: text, rects, verdict, rate or op')
911
1008
  return out
@@ -5,6 +5,7 @@ import { homedir } from 'node:os'
5
5
  import { homePort } from '../home/home-paths.ts'
6
6
  import { loadRepoConfig } from '../repo-config.ts'
7
7
  import { defaultHubPort } from '../serve/hub-port.ts'
8
+ import { machinePublicHost } from '../home/machine-host.ts'
8
9
 
9
10
  export interface PasteHosts {
10
11
  /** the repo's path, `~` for the home folder */
@@ -18,7 +19,7 @@ export interface PasteHosts {
18
19
  export async function pasteHosts(root: string): Promise<PasteHosts> {
19
20
  const c = await loadRepoConfig(root)
20
21
  const home = homedir()
21
- const host = c.serve?.publicHost
22
+ const host = machinePublicHost(c)
22
23
  return {
23
24
  root: root.startsWith(`${home}/`) ? `~${root.slice(home.length)}` : root,
24
25
  open: `http://localhost:${homePort()}/r/${encodeURIComponent(c.name)}/`,
@@ -1,12 +1,14 @@
1
- // a view's image at the size the page draws it (wiki tools/shipkit/review.md, Previews): a webp made once per media
2
- // file, kept in the repo's cache (`.shipkit/cache/review-previews/<id>/<name>.<size>.webp`, local, never in the store),
3
- // made again only when its source is newer. The full file is fetched only on zoom
1
+ // a view's image at the size the page draws it, a clip as the page plays it (wiki tools/shipkit/review-store.md,
2
+ // Previews, A clip's play copy): made once per media file, kept in the repo's cache
3
+ // (`.shipkit/cache/review-previews/<id>/<name>.<size>.<webp|mp4>`, local, never in the store), made again only when its
4
+ // source is newer. The full file is fetched only on zoom and download
4
5
  import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync } from 'node:fs'
5
6
  import { dirname, join } from 'node:path'
6
7
  import { LAYOUT } from '../core/layout.ts'
7
- import { FILE_RE, firstView, ID_RE, isGallery, isPair, thumbFileOf, type Item, type ReviewItem } from './model.ts'
8
+ import { ffmpeg } from '../trailer/ffmpeg.ts'
9
+ import { FILE_RE, firstView, ID_RE, isGallery, isPair, thumbFileOf, type Item, type ReviewItem, type ReviewView } from './model.ts'
8
10
  import { probe, stillAt } from './media.ts'
9
- import { ensureLocal, remotePreviewUrl } from './media-read.ts'
11
+ import { ensureLocal, remotePreviewUrl, remoteUrl } from './media-read.ts'
10
12
 
11
13
  /** `thumb` a list row's picture, `fit` a view in the card column: the widest each is drawn, at 2x */
12
14
  export const PREVIEW_W = { thumb: 480, fit: 1600 } as const
@@ -14,11 +16,26 @@ export type PreviewSize = keyof typeof PREVIEW_W
14
16
  export const isPreviewSize = (s: string): s is PreviewSize => s in PREVIEW_W
15
17
 
16
18
  const IMAGE = /\.(png|jpe?g|webp)$/i
19
+ export const CLIP = /\.(mp4|webm|mov|m4v)$/i
20
+ /** a clip over this many bits a second plays from its copy: what a phone streams over the tailnet and decodes smoothly */
21
+ export const PLAY_OVER = 25_000_000
22
+
23
+ /** the copy: the clip's own size and frames, each at its own pts, a keyframe every half second, at most 20 Mbit/s */
24
+ const playArgs = (src: string, fps: number, out: string): string[] => [
25
+ '-i', src, '-map', '0:v:0', '-map', '0:a:0?',
26
+ '-vf', 'crop=trunc(iw/2)*2:trunc(ih/2)*2', '-fps_mode', 'passthrough',
27
+ '-c:v', 'libx264', '-preset', 'veryfast', '-profile:v', 'high', '-pix_fmt', 'yuv420p',
28
+ '-crf', '16', '-maxrate', '20M', '-bufsize', '40M', '-g', String(Math.max(1, Math.round(fps / 2))),
29
+ '-c:a', 'aac', '-b:a', '192k', '-movflags', '+faststart', '-f', 'mp4', out,
30
+ ]
17
31
 
18
32
  const JOBS = 3
19
33
  let running = 0
20
34
  const waiting: (() => void)[] = []
21
35
  const making = new Map<string, Promise<string | null>>()
36
+ /** copies that failed, by their path and their clip's time: logged once, then the clip itself plays, never encoded
37
+ * again on each range request */
38
+ const failed = new Set<string>()
22
39
 
23
40
  async function slot<T>(work: () => Promise<T>): Promise<T> {
24
41
  if (running >= JOBS) await new Promise<void>((go) => waiting.push(go))
@@ -34,34 +51,75 @@ async function slot<T>(work: () => Promise<T>): Promise<T> {
34
51
  /** the preview folder of a store: `<repo>/.shipkit/cache/review-previews`, the store being `<repo>/.shipkit/review` */
35
52
  export const previewDir = (dir: string): string => join(dirname(dirname(dir)), LAYOUT.cache, 'review-previews')
36
53
 
54
+ /** what a preview of a file is: a webp of an image, the play copy of a clip; null for any other file or size */
55
+ const kindOf = (name: string, size: PreviewSize): 'image' | 'clip' | null => (IMAGE.test(name) ? 'image' : CLIP.test(name) && size === 'fit' ? 'clip' : null)
56
+
37
57
  // a poster's preview may come from a lit frame of its clip: its own name, so the black ones made before are not reused
38
- const outOf = (dir: string, id: string, name: string, size: PreviewSize): string => join(previewDir(dir), id, `${name}.${size}${POSTER.test(name) ? '.lit' : ''}.webp`)
58
+ const outOf = (dir: string, id: string, name: string, size: PreviewSize): string =>
59
+ join(previewDir(dir), id, CLIP.test(name) ? `${name}.${size}.mp4` : `${name}.${size}${POSTER.test(name) ? '.lit' : ''}.webp`)
60
+
61
+ /** the item.json of a card as a preview reads it: its media facts and its views */
62
+ const headOf = (dir: string, id: string): Pick<Item, 'media' | 'views'> => {
63
+ try {
64
+ return JSON.parse(readFileSync(join(dir, id, 'item.json'), 'utf8')) as Item
65
+ } catch {
66
+ return { views: [] }
67
+ }
68
+ }
39
69
 
40
- /** the preview of an item's image at a size, made on the first ask; null when the name is no image of the item or
41
- * the image does not read. A made preview of an image the disk let go stays good; else the image is fetched back */
70
+ /** the length in seconds of the clip a view names, from the views alone */
71
+ const lengthOf = (views: readonly ReviewView[], name: string): number | undefined => {
72
+ for (const v of views) if (!isGallery(v) && v.clip && Object.values(v.files).includes(name)) return v.clip.duration
73
+ return undefined
74
+ }
75
+
76
+ /** a clip of a card over the play line: its bytes from the disk, else from its fact, over the length its view keeps,
77
+ * so a clip the disk let go is judged without fetching it back */
78
+ export function playsCopy(dir: string, id: string, name: string): boolean {
79
+ if (!ID_RE.test(id) || !FILE_RE.test(name) || !CLIP.test(name)) return false
80
+ const head = headOf(dir, id)
81
+ const bytes = statSync(join(dir, id, name), { throwIfNoEntry: false })?.size ?? head.media?.[name]?.size
82
+ const seconds = lengthOf(head.views, name)
83
+ return bytes !== undefined && seconds !== undefined && seconds > 0 && (bytes * 8) / seconds > PLAY_OVER
84
+ }
85
+
86
+ /** the preview of an item's file at a size, made on the first ask; null when the name is no image or clip of the item
87
+ * or it does not read. A clip under the play line is its own preview, and a clip whose copy failed plays itself. A
88
+ * made preview of a file the disk let go stays good; else the file is fetched back */
42
89
  export async function previewFile(dir: string, id: string, name: string, size: PreviewSize): Promise<string | null> {
43
- if (!ID_RE.test(id) || !FILE_RE.test(name) || !IMAGE.test(name)) return null
90
+ if (!ID_RE.test(id) || !FILE_RE.test(name)) return null
91
+ const kind = kindOf(name, size)
92
+ if (!kind) return null
93
+ if (kind === 'clip' && !playsCopy(dir, id, name)) return ensureLocal(dir, id, name)
44
94
  const out = outOf(dir, id, name, size)
45
95
  const here = join(dir, id, name)
46
96
  if (!existsSync(here) && existsSync(out)) return out
47
97
  const src = await ensureLocal(dir, id, name)
48
98
  if (!src) return null
49
- if (existsSync(out) && statSync(out).mtimeMs >= statSync(src).mtimeMs) return out
99
+ const at = statSync(src).mtimeMs
100
+ if (existsSync(out) && statSync(out).mtimeMs >= at) return out
101
+ if (failed.has(`${out}@${at}`)) return src
50
102
  const pending = making.get(out)
51
103
  if (pending) return pending
52
104
  const job = slot(async () => {
53
105
  mkdirSync(dirname(out), { recursive: true })
54
106
  const tmp = `${out}.${process.pid}.tmp`
55
107
  try {
56
- const { default: sharp } = await import('sharp')
57
- const still = POSTER.test(name) ? await litStill(dir, id, name, src, out) : src
58
- await sharp(still === src ? src : readFileSync(still))
59
- .resize({ width: PREVIEW_W[size], withoutEnlargement: true })
60
- .webp({ quality: size === 'thumb' ? 75 : 82 })
61
- .toFile(tmp)
108
+ if (kind === 'clip') await ffmpeg(playArgs(src, probe(src).video?.fps ?? 30, tmp), { nice: 10 })
109
+ else {
110
+ const { default: sharp } = await import('sharp')
111
+ const still = POSTER.test(name) ? await litStill(dir, id, name, src, out) : src
112
+ await sharp(still === src ? src : readFileSync(still))
113
+ .resize({ width: PREVIEW_W[size], withoutEnlargement: true })
114
+ .webp({ quality: size === 'thumb' ? 75 : 82 })
115
+ .toFile(tmp)
116
+ }
62
117
  } catch (e) {
63
- console.error(`FAIL: review preview ${size} of ${id}/${name}: ${(e as Error).message}`)
64
- return null
118
+ console.error(`FAIL: review ${kind === 'clip' ? 'play copy' : `preview ${size}`} of ${id}/${name}: ${(e as Error).message}`)
119
+ rmSync(tmp, { force: true })
120
+ if (kind === 'image') return null
121
+ failed.add(`${out}@${at}`)
122
+ return src
65
123
  }
66
124
  renameSync(tmp, out)
67
125
  rmSync(`${out}.still.png`, { force: true })
@@ -74,18 +132,26 @@ export async function previewFile(dir: string, id: string, name: string, size: P
74
132
  /** every preview being made has landed: a test removes its folder only after */
75
133
  export const previewsSettled = async (): Promise<void> => void (await Promise.all([...making.values()]))
76
134
 
77
- /** a preview to answer: its file, or when neither it nor its image is on the disk, a signed URL of the Space's copy */
135
+ /** a preview to answer: its file, or when neither it nor its source is on the disk, a signed URL of the Space's copy
136
+ * (a clip under the play line: the clip's own) */
78
137
  export async function previewOrRemote(dir: string, id: string, name: string, size: PreviewSize): Promise<{ file: string } | { url: string } | null> {
79
- if (!ID_RE.test(id) || !FILE_RE.test(name) || !IMAGE.test(name)) return null
80
- if (!existsSync(join(dir, id, name)) && !existsSync(outOf(dir, id, name, size))) {
81
- const url = await remotePreviewUrl(dir, id, name, size)
138
+ if (!ID_RE.test(id) || !FILE_RE.test(name)) return null
139
+ const kind = kindOf(name, size)
140
+ if (!kind) return null
141
+ const here = join(dir, id, name)
142
+ if (kind === 'clip' && !playsCopy(dir, id, name)) {
143
+ if (existsSync(here)) return { file: here }
144
+ const url = await remoteUrl(dir, id, name)
145
+ return url ? { url } : null
146
+ }
147
+ if (!existsSync(here) && !existsSync(outOf(dir, id, name, size))) {
148
+ const url = await remotePreviewUrl(dir, id, name, size, kind === 'clip' ? 'mp4' : 'webp')
82
149
  if (url) return { url }
83
150
  }
84
151
  const file = await previewFile(dir, id, name, size)
85
152
  return file ? { file } : null
86
153
  }
87
154
 
88
-
89
155
  const POSTER = /^(v\d+-)?poster\.png$/
90
156
  /** a picture whose brightest channel averages under this is black: a trailer's first frame fades in from black */
91
157
  const BLACK = 12
@@ -105,7 +171,7 @@ async function litStill(dir: string, id: string, name: string, poster: string, o
105
171
  if (!(await isBlack(poster))) return poster
106
172
  const prefix = name.slice(0, name.length - 'poster.png'.length)
107
173
  const clipRe = new RegExp(`^${prefix}(video|after)\\.(mp4|webm)$`)
108
- const clip = readdirSync(join(dir, id)).find((f) => clipRe.test(f)) ?? Object.keys(mediaOf(dir, id)).find((f) => clipRe.test(f))
174
+ const clip = readdirSync(join(dir, id)).find((f) => clipRe.test(f)) ?? Object.keys(headOf(dir, id).media ?? {}).find((f) => clipRe.test(f))
109
175
  const video = clip ? await ensureLocal(dir, id, clip) : null
110
176
  if (!video) return poster
111
177
  const still = `${out}.still.png`
@@ -121,15 +187,6 @@ async function litStill(dir: string, id: string, name: string, poster: string, o
121
187
  return poster
122
188
  }
123
189
 
124
- /** the media facts a head keeps, by name: what names a file the disk let go */
125
- const mediaOf = (dir: string, id: string): Record<string, unknown> => {
126
- try {
127
- return (JSON.parse(readFileSync(join(dir, id, 'item.json'), 'utf8')) as { media?: Record<string, unknown> }).media ?? {}
128
- } catch {
129
- return {}
130
- }
131
- }
132
-
133
190
  /** every image a card draws: each view's image or pair, a clip's poster, a sound's waveforms, a gallery's tiles */
134
191
  export function imagesOf(i: Item): string[] {
135
192
  const names = i.views.flatMap((v) => {
@@ -140,14 +197,44 @@ export function imagesOf(i: Item): string[] {
140
197
  return [...new Set(names)].filter((n) => IMAGE.test(n))
141
198
  }
142
199
 
143
- /** the previews of these cards made ahead, so each opens on them: its list thumb, every image at the fit size. Already
144
- * made ones cost a stat */
200
+ /** every clip a card plays: each clip view's video, or both sides of its pair */
201
+ export const clipsOf = (i: Pick<Item, 'views'>): string[] => [...new Set(i.views.flatMap((v) => (isGallery(v) || !v.clip ? [] : Object.values(v.files).filter((n) => CLIP.test(n)))))]
202
+
203
+ /** the previews of these cards made ahead, so each opens on them: its list thumb, every image at the fit size, the
204
+ * play copy of every clip over the line. Already made ones cost a stat, a copy the Space holds costs nothing */
145
205
  export async function warmPreviews(dir: string, cards: readonly ReviewItem[]): Promise<void> {
146
206
  await Promise.all(
147
207
  cards.flatMap((x) => {
208
+ const id = x.item.id
148
209
  const first = firstView(x.item)
149
210
  const thumb = first ? thumbFileOf(first) : ''
150
- return [...(IMAGE.test(thumb) ? [previewFile(dir, x.item.id, thumb, 'thumb')] : []), ...imagesOf(x.item).map((n) => previewFile(dir, x.item.id, n, 'fit'))]
211
+ return [
212
+ ...(IMAGE.test(thumb) ? [previewFile(dir, id, thumb, 'thumb')] : []),
213
+ ...imagesOf(x.item).map((n) => previewFile(dir, id, n, 'fit')),
214
+ ...clipsOf(x.item).filter((n) => playsCopy(dir, id, n)).map((n) => previewOrRemote(dir, id, n, 'fit')),
215
+ ]
151
216
  }),
152
217
  )
153
218
  }
219
+
220
+ const mb = (bytes: number): string => `${(bytes / 1e6).toFixed(1)} MB`
221
+ const mbit = (bytes: number, seconds: number): string => `${((bytes * 8) / seconds / 1e6).toFixed(1)} Mbit/s`
222
+
223
+ /** the play copies of a card's clips from view `from` on, made now: one line each, what it weighs and what it cost */
224
+ export async function playCopies(dir: string, item: Pick<Item, 'id' | 'views'>, from = 0): Promise<string[]> {
225
+ const views = item.views.slice(from)
226
+ return Promise.all(
227
+ clipsOf({ views })
228
+ .filter((n) => playsCopy(dir, item.id, n))
229
+ .map(async (n) => {
230
+ const t0 = performance.now()
231
+ const src = join(dir, item.id, n)
232
+ const out = await previewFile(dir, item.id, n, 'fit')
233
+ const took = ((performance.now() - t0) / 1000).toFixed(1)
234
+ if (!out || out === src) return `play copy of ${n}: FAIL after ${took} s, the hub plays the clip itself`
235
+ const seconds = lengthOf(views, n) ?? 1
236
+ const [a, b] = [statSync(src).size, statSync(out).size]
237
+ return `play copy of ${n}: ${mb(a)} at ${mbit(a, seconds)} → ${mb(b)} at ${mbit(b, seconds)}, made in ${took} s`
238
+ }),
239
+ )
240
+ }