rvlib-shipkit 2.23.0 → 2.25.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 (150) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/package.json +1 -1
  3. package/src/agent-time/live.ts +153 -0
  4. package/src/agent-time/render.ts +28 -14
  5. package/src/agent-time/report.ts +46 -25
  6. package/src/agent-time/store.ts +30 -10
  7. package/src/agent-time/timeline.ts +43 -15
  8. package/src/annex/offload.ts +16 -7
  9. package/src/asks/asks-queue.ts +32 -11
  10. package/src/check.ts +3 -1
  11. package/src/checks/SK004-gitignore-policy.check.ts +32 -11
  12. package/src/checks/SK027-agent-wiki-links.check.ts +1 -1
  13. package/src/checks/SK033-global-contribution.check.ts +1 -1
  14. package/src/checks/SK036-draft-media-size.check.ts +1 -1
  15. package/src/checks/SK040-release-words.check.ts +1 -1
  16. package/src/checks/SK042-post-kinds.check.ts +1 -1
  17. package/src/checks/SK044-behind-upstream.check.ts +38 -0
  18. package/src/cli/cmd_Annex.ts +12 -7
  19. package/src/cli/cmd_Asks.ts +2 -0
  20. package/src/cli/cmd_Assets.ts +5 -5
  21. package/src/cli/cmd_Backup.ts +16 -8
  22. package/src/cli/cmd_Bump.ts +1 -0
  23. package/src/cli/cmd_Capacity.ts +30 -0
  24. package/src/cli/cmd_Check.ts +1 -0
  25. package/src/cli/cmd_Checks.ts +13 -1
  26. package/src/cli/cmd_Ci.ts +3 -2
  27. package/src/cli/cmd_Commands.ts +61 -16
  28. package/src/cli/cmd_ConfigKeys.ts +17 -0
  29. package/src/cli/cmd_Home.ts +1 -30
  30. package/src/cli/cmd_Hooks.ts +1 -0
  31. package/src/cli/cmd_Keys.ts +4 -1
  32. package/src/cli/cmd_Lanes.ts +35 -0
  33. package/src/cli/cmd_Mv.ts +7 -7
  34. package/src/cli/cmd_Rec.ts +22 -7
  35. package/src/cli/cmd_Reflect.ts +1 -0
  36. package/src/cli/cmd_Releases.ts +1 -0
  37. package/src/cli/cmd_Review.ts +200 -49
  38. package/src/cli/cmd_Secret.ts +41 -2
  39. package/src/cli/cmd_Shot.ts +16 -4
  40. package/src/cli/cmd_Status.ts +7 -5
  41. package/src/cli/cmd_Time.ts +13 -5
  42. package/src/cli/cmd_Tmp.ts +82 -0
  43. package/src/cli/cmd_Veille.ts +10 -6
  44. package/src/cli/cmd_Wiki.ts +1 -0
  45. package/src/cli/family-help.ts +136 -0
  46. package/src/cli/family-pages.ts +0 -19
  47. package/src/cli/kit/calls.ts +35 -0
  48. package/src/cli/kit/project-cli.ts +2 -12
  49. package/src/cli/registry.ts +52 -7
  50. package/src/cli.ts +8 -4
  51. package/src/collections/pings.ts +1 -1
  52. package/src/core/capacity.ts +127 -0
  53. package/src/core/check-runner.ts +91 -16
  54. package/src/core/floor-resolve.ts +6 -2
  55. package/src/core/floor.ts +6 -2
  56. package/src/core/history-files.ts +18 -0
  57. package/src/core/jobs.ts +35 -16
  58. package/src/core/layout.ts +2 -2
  59. package/src/core/motherhome.ts +67 -9
  60. package/src/core/nearest.ts +16 -0
  61. package/src/core/remove-tree.ts +19 -0
  62. package/src/core/runs.ts +12 -3
  63. package/src/core/slots.ts +49 -12
  64. package/src/core/throwaway-worktree.ts +22 -4
  65. package/src/core/trace-audit.ts +21 -5
  66. package/src/drill/run.ts +5 -2
  67. package/src/home/daemon-jobs.ts +41 -4
  68. package/src/home/gui-app/ShipkitGui.swift +1 -0
  69. package/src/home/home-launchd.ts +11 -3
  70. package/src/home/home-routes.ts +11 -4
  71. package/src/home/machine-host.ts +65 -0
  72. package/src/home/machine-stores.ts +19 -17
  73. package/src/home/machine-temp.ts +485 -0
  74. package/src/home/other-macs.ts +74 -0
  75. package/src/home/run-daemon.ts +10 -2
  76. package/src/home/serve-web.ts +2 -2
  77. package/src/home/via-hub.ts +6 -1
  78. package/src/init-repo.ts +7 -3
  79. package/src/ledger/gate-checks.ts +3 -2
  80. package/src/ledger/git-key.ts +25 -4
  81. package/src/ledger/git-scan.ts +10 -0
  82. package/src/ledger/ledger.ts +6 -0
  83. package/src/ledger/store.ts +6 -0
  84. package/src/media-store/backup/daemon.ts +92 -20
  85. package/src/media-store/backup/keys.ts +21 -6
  86. package/src/media-store/backup/manifest.ts +52 -11
  87. package/src/media-store/backup/restore.ts +17 -10
  88. package/src/media-store/backup/run.ts +26 -17
  89. package/src/media-store/backup/sources.ts +168 -22
  90. package/src/media-store/backup/watch.ts +106 -0
  91. package/src/media-store/daemon.ts +36 -8
  92. package/src/media-store/hand.ts +3 -1
  93. package/src/mv/mv-md.ts +167 -56
  94. package/src/pb/run-pb.ts +2 -10
  95. package/src/plan/repo-source.ts +25 -14
  96. package/src/recordings/model.ts +1 -1
  97. package/src/reflect/transcript.ts +56 -11
  98. package/src/release/run-bump.ts +3 -2
  99. package/src/release/run-release.ts +12 -4
  100. package/src/releases/from-card.ts +45 -3
  101. package/src/releases/model.ts +6 -0
  102. package/src/releases/store.ts +8 -1
  103. package/src/repo-config.ts +5 -3
  104. package/src/review/cells.ts +26 -4
  105. package/src/review/format.ts +34 -10
  106. package/src/review/media-kind.ts +14 -11
  107. package/src/review/media-read.ts +6 -5
  108. package/src/review/model.ts +85 -4
  109. package/src/review/paste.ts +2 -1
  110. package/src/review/previews.ts +123 -36
  111. package/src/review/routes.ts +29 -18
  112. package/src/review/store.ts +89 -19
  113. package/src/review/threads.ts +7 -5
  114. package/src/review/trailer-model.ts +2 -2
  115. package/src/secrets/copy.ts +110 -0
  116. package/src/secrets/list.ts +17 -7
  117. package/src/serve/hub-app/home-strip.css +5 -0
  118. package/src/serve/hub-app/home-strip.tsx +18 -0
  119. package/src/serve/hub-app/hub-app.tsx +2 -1
  120. package/src/serve/hub-app/hub.css +14 -0
  121. package/src/serve/hub-app/inbox.css +1 -0
  122. package/src/serve/hub-app/pull-refresh.tsx +88 -0
  123. package/src/serve/hub-app/review/review-cells.tsx +52 -13
  124. package/src/serve/hub-app/review/review-list.tsx +6 -1
  125. package/src/serve/hub-app/review/review-st.ts +6 -5
  126. package/src/serve/hub-app/review/review-thread.tsx +3 -1
  127. package/src/serve/hub-app/review/review-views.tsx +18 -11
  128. package/src/serve/hub-app/review/thread-st.ts +82 -14
  129. package/src/serve/hub-app/review.css +15 -2
  130. package/src/serve/hub-runtime.ts +2 -1
  131. package/src/serve/run-serve.ts +4 -2
  132. package/src/serve/serve-hub.ts +9 -2
  133. package/src/shot/client.ts +4 -2
  134. package/src/shot/serve-shot.ts +71 -2
  135. package/src/shot/shooter.ts +65 -11
  136. package/src/shot/shot-ask.ts +32 -9
  137. package/src/suite/child-tools.ts +45 -0
  138. package/src/suite/judge-suites.ts +10 -22
  139. package/src/suite/select.ts +95 -9
  140. package/src/suite/suite-cli.ts +38 -14
  141. package/src/suite/suite-cores.ts +68 -0
  142. package/src/suite/suite-reads-preload.ts +8 -6
  143. package/src/suite/test-units.ts +31 -12
  144. package/src/trailer/graph.ts +2 -1
  145. package/src/ts/config.ts +21 -0
  146. package/src/ts/rename.ts +37 -13
  147. package/src/ts/workspaces.ts +45 -0
  148. package/src/wiki/run-wiki.ts +7 -2
  149. package/src/wiki/scan-md.ts +2 -1
  150. package/src/home/claude-temp.ts +0 -139
@@ -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
+ }
@@ -7,13 +7,13 @@ import { dirname, extname, join } from 'node:path'
7
7
  import { isAnimFormat, isAnimLabels, isAnimMode, pairAnimation } from './anim.ts'
8
8
  import { startAuto } from './auto.ts'
9
9
  import { bad, KEEP, NO_STORE, ranged, tagged, TYPES } from './http.ts'
10
- import { viewFilesOf, type Rect, type ReviewItem, type Subject } from './model.ts'
10
+ import { verdictOf, viewFilesOf, type Rect, type ReviewItem, type ReviewStatus, type Subject } from './model.ts'
11
11
  import { stageGet, stagePost } from './stage-routes.ts'
12
12
  import { pasteHosts } from './paste.ts'
13
13
  import { openReview, partFile, viewOfItem } from './project.ts'
14
- import { isPreviewSize, previewOrRemote, warmPreviews } from './previews.ts'
14
+ import { CLIP, isPreviewSize, previewOrRemote, warmPreviews } from './previews.ts'
15
15
  import { roleOf } from './role.ts'
16
- import { addMessage, imageFile, itemOfRef, markRead, raiseItem, rateSubject, readAllCached, readItem, specOf, storeDir, storeStamp, threadImage, writeVerdict } from './store.ts'
16
+ import { addMessage, imageFile, itemOfRef, markRead, raiseItem, rateSubject, readAllCached, readItem, reopen, specOf, storeDir, storeStamp, threadImage, writeVerdict } from './store.ts'
17
17
  import { boardOf, pageOf, queryOf, threadIndex, threadOfId, threadView, type ThreadIndex } from './cells.ts'
18
18
  import { membersOf, threadsOf, type Thread } from './threads.ts'
19
19
  import { putMedia } from '../media-store/put.ts'
@@ -50,17 +50,15 @@ async function project(root: string): Promise<{ dir: string; unit: ReviewUnit |
50
50
  return { dir, unit }
51
51
  }
52
52
 
53
- /** an approved card's changelog line into next.md (releases/from-card.ts), after the verdict answered: a failure says so
54
- * on the card's thread and in the hub's log, so the change is never lost in silence */
55
- async function changeOnVerdict(dir: string, id: string): Promise<void> {
56
- try {
57
- const { onVerdict } = await import('../releases/from-card.ts')
58
- await onVerdict(dirname(dirname(dir)), id)
59
- } catch (e) {
60
- const why = (e as Error).message
61
- console.error(`FAIL: the release did not take the change of ${id}: ${why}`)
62
- addMessage(dir, id, 'releases', `the release did not take this change: ${why}. Run sk releases add --card ${id}`)
63
- }
53
+ /** next.md follows his answer (releases/from-card.ts), after the request answered; `was` the status before it */
54
+ async function releaseFollows(dir: string, id: string, was: ReviewStatus | null): Promise<void> {
55
+ const { followAnswer } = await import('../releases/from-card.ts')
56
+ await followAnswer(dirname(dirname(dir)), id, was)
57
+ }
58
+
59
+ const statusNow = (dir: string, id: string): ReviewStatus | null => {
60
+ const x = readItem(dir, id)
61
+ return x ? (verdictOf(x)?.status ?? null) : null
64
62
  }
65
63
 
66
64
  /** an image the page sent as a data url, written to a scratch file the caller removes */
@@ -230,14 +228,15 @@ async function reviewRoute(req: Request, path: string, dir: string, unit: Review
230
228
  const url = await remoteUrl(dir, t[1] ?? '', `thread/${t[2] ?? ''}`)
231
229
  return url ? toSpace(url) : bad('no such image', 404)
232
230
  }
233
- // a view's image at the size the page draws it; `thumb/<name>` is the preview's thumb size
231
+ // a view's image at the size the page draws it, a clip as the page plays it; `thumb/<name>` is the preview's thumb size
234
232
  const pv = /^\/api\/review\/([^/]+)\/(?:preview\/([^/]+)|thumb)\/([^/]+)$/.exec(path)
235
233
  if (pv && req.method === 'GET') {
236
234
  const size = pv[2] ?? 'thumb'
237
235
  if (!isPreviewSize(size)) return bad(`preview size ${size}: thumb or fit`, 404)
238
236
  const p = await previewOrRemote(dir, pv[1] ?? '', pv[3] ?? '', size)
239
237
  if (p && 'url' in p) return toSpace(p.url)
240
- return p ? new Response(Bun.file(p.file), { headers: { 'Content-Type': 'image/webp', ...KEEP } }) : bad('no such image', 404)
238
+ if (p && CLIP.test(p.file)) return ranged(req, p.file)
239
+ return p ? new Response(Bun.file(p.file), { headers: { 'Content-Type': 'image/webp', ...KEEP } }) : bad('no such image or clip', 404)
241
240
  }
242
241
  const m = /^\/api\/review\/([^/]+)\/([^/]+)$/.exec(path)
243
242
  if (!m) return null
@@ -245,12 +244,24 @@ async function reviewRoute(req: Request, path: string, dir: string, unit: Review
245
244
  if (req.method === 'POST') {
246
245
  try {
247
246
  if (name === 'feedback') {
247
+ const was = statusNow(dir, id)
248
248
  const r = writeVerdict(dir, id, await req.json())
249
- if (r.ok) void changeOnVerdict(dir, id)
249
+ if (r.ok) void releaseFollows(dir, id, was)
250
250
  return r.ok ? Response.json(r.message, { headers: NO_STORE }) : Response.json({ error: r.errors.join('\n'), errors: r.errors }, { status: 400, headers: NO_STORE })
251
251
  }
252
+ // a click on his lit verdict: he takes it back, the card waits for him again (the CLI's reopen, by the owner)
253
+ if (name === 'reopen') {
254
+ const v = reopen(dir, id, { who: 'owner' })
255
+ if (!v) return bad(`${id}: no such card, or no answer to take back`, 404)
256
+ void releaseFollows(dir, id, v.status)
257
+ return Response.json({ reopened: v.id }, { headers: NO_STORE })
258
+ }
252
259
  if (name === 'stage') return await stagePost(dirname(dirname(dir)), dir, id, unit, (await req.json().catch(() => ({}))) as Record<string, unknown>)
253
- if (name === 'reply') return Response.json(addMessage(dir, id, 'owner', ((await req.json()) as { text?: unknown }).text), { headers: NO_STORE })
260
+ if (name === 'reply') {
261
+ // `re`: the message his word answers, a hint on an agent's update
262
+ const b = (await req.json()) as { text?: unknown; re?: unknown }
263
+ return Response.json(addMessage(dir, id, 'owner', b.text, undefined, new Date(), b.re), { headers: NO_STORE })
264
+ }
254
265
  if (name === 'read') {
255
266
  // the page names the words it drew: a word that came after them stays unread
256
267
  const b = (await req.json().catch(() => ({}))) as { of?: unknown }
@@ -36,7 +36,11 @@ import {
36
36
  verdictMessageOf,
37
37
  verdictOf,
38
38
  viewIndexOf,
39
- withdrawnOf,
39
+ inWork,
40
+ UPDATE_STATES,
41
+ UPDATE_WORDS,
42
+ updatesOf,
43
+ type UpdateState,
40
44
  type GalleryTile,
41
45
  type CardChangelog,
42
46
  type Item,
@@ -53,9 +57,11 @@ import {
53
57
  type TrailerCard,
54
58
  type Spec,
55
59
  type Subject,
60
+ type Verdict,
56
61
  viewFilesOf,
57
62
  mediaFilesOf,
58
63
  threadMediaOf,
64
+ isGallery,
59
65
  } from './model.ts'
60
66
  import { beatRole, roleOf } from './role.ts'
61
67
  import { chainOf, coveringHead, followedIds, isFollowed } from './threads.ts'
@@ -418,11 +424,15 @@ function copyFiles(v: Loaded, n: number, into: string): void {
418
424
  }
419
425
  }
420
426
 
421
- /** another angle of an open card's subject, appended as its next view; refused once he answered */
422
- export async function addView(dir: string, id: string, v: ViewInput, o: { marks?: ReviewMark[]; light?: 'review' } = {}): Promise<Item> {
427
+ /** the command that posts an update, as a refusal names it */
428
+ const updateLine = (id: string): string => `sk review update ${id} <${UPDATE_STATES.join('|')}> "<one line>" <file> | <before> <after>`
429
+
430
+ /** another angle of an open card's subject, appended as its next view; refused once he answered, except the view of an
431
+ * update (`update`), which goes on at any time */
432
+ export async function addView(dir: string, id: string, v: ViewInput, o: { marks?: ReviewMark[]; light?: 'review'; update?: true } = {}): Promise<Item> {
423
433
  const x = readItem(dir, id)
424
434
  if (!x) throw new Error(`no card ${id}`)
425
- if (verdictOf(x)) throw new Error(`${id} has his answer already: a new version passes --supersedes ${id}`)
435
+ if (verdictOf(x) && !o.update) throw new Error(`${id} has his answer already: a picture of the work since goes on as an update, ${updateLine(id)}; a new version passes --supersedes ${id}`)
426
436
  if (v.note !== undefined && v.gallery) throw new Error(`"${v.label}": a note goes on an image, a clip or a sound, never a gallery`)
427
437
  if (!v.label.trim()) throw new Error('add-view: the view needs its label')
428
438
  const loaded = await loadView(v, `the view "${v.label}"`)
@@ -556,12 +566,56 @@ export function appendMessage(dir: string, id: string, m: Omit<Message, 'id' | '
556
566
  return out
557
567
  }
558
568
 
559
- /** a reply on an item from `who` (the owner, or an agent by its name), with an optional image; throws with the reason */
560
- export function addMessage(dir: string, id: string, who: string, text: unknown, image?: string, now = new Date()): Message {
561
- if (!readItem(dir, id)) throw new Error(`no card ${id}`)
569
+ /** a reply on an item from `who` (the owner, or an agent by its name), with an optional image; `re` the message of the
570
+ * item it answers (his hint on an update); throws with the reason */
571
+ export function addMessage(dir: string, id: string, who: string, text: unknown, image?: string, now = new Date(), re?: unknown): Message {
572
+ const x = readItem(dir, id)
573
+ if (!x) throw new Error(`no card ${id}`)
562
574
  const t = textOf(text)
563
575
  if ('error' in t) throw new Error(t.error)
564
- return appendMessage(dir, id, { who, text: t.text }, { ...(image !== undefined ? { image } : {}), now })
576
+ if (re !== undefined && !(typeof re === 'string' && x.thread.some((m) => m.id === re))) throw new Error(`re: ${String(re)} is no message of ${id}`)
577
+ return appendMessage(dir, id, { who, text: t.text, ...(typeof re === 'string' ? { re } : {}) }, { ...(image !== undefined ? { image } : {}), now })
578
+ }
579
+
580
+ /** a view of files as typed: one file an image, a clip or a sound (by its extension), two a before and an after; loadView
581
+ * checks them */
582
+ export function filesView(label: string, files: readonly string[], usage: string): ViewInput {
583
+ const [a, b] = files
584
+ if (files.length === 1 && a !== undefined) return { label, image: a }
585
+ if (files.length === 2 && a !== undefined && b !== undefined) return { label, before: a, after: b }
586
+ throw new Error(usage)
587
+ }
588
+
589
+ /** what an agent's update says: its state, its line, its media as it is, one file or a before and an after (none: the
590
+ * state alone) */
591
+ export interface UpdateInput {
592
+ who: string
593
+ state: string
594
+ text: unknown
595
+ files?: readonly string[]
596
+ now?: Date
597
+ }
598
+
599
+ /** an agent's update on its card, at any time, before or after his answer: its file, or its pair, becomes the card's next view
600
+ * (labelled `update <k>: <state>`, the line its note), then one message carries the state and the line. Still broken
601
+ * or better holds the card in work, fixed asks the owner's verdict again (model.ts stateOf) */
602
+ export async function postUpdate(dir: string, id: string, u: UpdateInput): Promise<{ item: Item; message: Message; tag: string; view: number | null }> {
603
+ const x = readItem(dir, id)
604
+ if (!x) throw new Error(`no card ${id}`)
605
+ if (x.item.origin.by !== 'agent') throw new Error(`${id} was raised, not sent by an agent: an update goes on the card that answers it`)
606
+ if (x.item.wip) throw new Error(`${id} is a draft on a live shot: its frame refreshes itself, sk review ready ${id} when it is done`)
607
+ if (!UPDATE_STATES.includes(u.state as UpdateState)) throw new Error(`the state: one of ${UPDATE_STATES.join(', ')}, not « ${u.state} »`)
608
+ const state = u.state as UpdateState
609
+ const t = textOf(u.text)
610
+ if ('error' in t) throw new Error(`the line: ${t.error.replace(/^text: /, '')}`)
611
+ const files = u.files ?? []
612
+ for (const f of files) if (!existsSync(f)) throw new Error(`${f}: no such file`)
613
+ const k = updatesOf(x).length + 1
614
+ const label = `update ${k}: ${UPDATE_WORDS[state]}`
615
+ const item = files.length === 0 ? x.item : await addView(dir, id, { ...filesView(label, files, `an update holds one file, or a before and an after: ${updateLine(id)}`), note: t.text }, { update: true })
616
+ const view = files.length === 0 ? null : item.views.length - 1
617
+ const message = appendMessage(dir, id, { who: u.who, text: t.text, update: { state, ...(view !== null ? { view } : {}) } }, u.now ? { now: u.now } : {})
618
+ return { item, message, tag: `update ${k} (${UPDATE_WORDS[state]})`, view }
565
619
  }
566
620
 
567
621
  /** `party` read what the other party wrote on an item: one `seen` message naming them; how many it read. `only`: the
@@ -740,20 +794,30 @@ export function markSeen(dir: string, id: string, now = new Date()): boolean {
740
794
  return verdictOf(x) !== null || read > 0
741
795
  }
742
796
 
743
- /** takes an unanswered card back: false when it is unknown or already answered */
744
- export function withdraw(dir: string, id: string, why: string, now = new Date()): boolean {
797
+ /** takes an unanswered card back; `already` names who took it back before, `refused` says why it may not and what to type */
798
+ export function withdraw(dir: string, id: string, why: string, now = new Date()): { already?: string } | { refused: string } {
745
799
  const x = ID_RE.test(id) ? readItem(dir, id) : null
746
- if (!x || verdictOf(x) || withdrawnOf(x) !== undefined) return false
800
+ if (!x) return { refused: `no card ${id}` }
801
+ const before = x.thread.filter((m) => m.op === 'withdraw').at(-1)
802
+ if (before) return { already: `by ${before.who}, ${before.at.slice(0, 16).replace('T', ' ')} UTC` }
803
+ const v = verdictOf(x)
804
+ if (v) {
805
+ const owes = v.status === 'approved-with-fix' ? `sk review done ${id} "<what changed>", ` : ''
806
+ const close = v.status === 'approved-with-fix' || v.status === 'rejected' ? `; what it owes: ${owes}--supersedes ${id} on its new card, or sk review wontfix ${id} --note "<why>"` : ''
807
+ return { refused: `${id}: he answered it (${v.status}), so it waits on him no more${close}` }
808
+ }
747
809
  appendMessage(dir, id, { who: agentName(), op: 'withdraw', note: why }, { now })
748
- return true
810
+ return {}
749
811
  }
750
812
 
751
- /** an answered card waits for his answer again: its verdict stays in the thread, before the reopen; false when it has none */
752
- export function reopen(dir: string, id: string, now = new Date()): boolean {
813
+ /** an answered card waits for his answer again: its verdict stays in the thread, before the reopen. `who`: an agent
814
+ * (the CLI), or the owner taking the verdict back (the hub). The verdict reopened, null when it has none */
815
+ export function reopen(dir: string, id: string, o: { who?: string; now?: Date } = {}): Verdict | null {
753
816
  const x = ID_RE.test(id) ? readItem(dir, id) : null
754
- if (!x || !verdictOf(x)) return false
755
- appendMessage(dir, id, { who: agentName(), op: 'reopen' }, { now })
756
- return true
817
+ const v = x ? verdictOf(x) : null
818
+ if (!v) return null
819
+ appendMessage(dir, id, { who: o.who ?? agentName(), op: 'reopen' }, { now: o.now ?? new Date() })
820
+ return v
757
821
  }
758
822
 
759
823
  /** the path of one image, clip or poster of an item, null for any other name */
@@ -1001,7 +1065,7 @@ export async function refreshDraft(dir: string, id: string, o: { image: string;
1001
1065
  const r = x.item
1002
1066
  if (!r.wip || verdictOf(x)) throw new Error(`${id} is not a draft card waiting`)
1003
1067
  const f0 = r.views[0]
1004
- if (!f0 || !('files' in f0) || !('image' in f0.files)) throw new Error(`${id}: its first view is no image`)
1068
+ if (!f0 || isGallery(f0) || !('image' in f0.files)) throw new Error(`${id}: its first view is no image`)
1005
1069
  const folder = join(dir, id)
1006
1070
  const main = await loadView({ label: f0.label, image: o.image }, 'the live frame')
1007
1071
  const image = f0.files.image
@@ -1031,11 +1095,17 @@ export async function readyItem(dir: string, id: string, o: { image?: string; no
1031
1095
  const x = readItem(dir, id)
1032
1096
  if (!x) throw new Error(`no card ${id}`)
1033
1097
  const { wip, ...rest } = x.item
1098
+ if (!wip && inWork(x)) {
1099
+ // a card its updates hold in work: ready asks the owner's verdict, its newest picture goes on as an update
1100
+ if (o.image !== undefined) throw new Error(`${id} is in work by its updates: its new picture goes on as one, ${updateLine(id).replace('<broken|better|fixed>', 'fixed')}`)
1101
+ appendMessage(dir, id, { who: agentName(), op: 'ready' }, o.now ? { now: o.now } : {})
1102
+ return x.item
1103
+ }
1034
1104
  if (!wip) throw new Error(`${id} is not a draft card: it already takes a verdict`)
1035
1105
  let item: Item = rest
1036
1106
  if (o.image !== undefined) {
1037
1107
  const f0 = rest.views[0]
1038
- if (!f0 || !('files' in f0)) throw new Error(`${id} has no image to replace`)
1108
+ if (!f0 || isGallery(f0)) throw new Error(`${id} has no image to replace`)
1039
1109
  const loaded = await loadView({ label: f0.label, image: o.image }, '--image')
1040
1110
  const folder = join(dir, id)
1041
1111
  const old = 'image' in f0.files ? f0.files.image : undefined
@@ -2,11 +2,13 @@
2
2
  // items (a report, his note) the card answers, read as one thread per bug; their status, conversation and order, and
3
3
  // the active thread a new card already covers. Pure, over the items of review/model.ts
4
4
  import {
5
+ inWork,
5
6
  isReply,
6
7
  partyOf,
7
8
  reworkOf,
8
9
  stateOf,
9
10
  subjectKey,
11
+ takenBackOf,
10
12
  unreadBy,
11
13
  verdictOf,
12
14
  withdrawnOf,
@@ -147,12 +149,12 @@ export function conversationOf(t: Thread): (Message & { on: string })[] {
147
149
  }
148
150
 
149
151
  /** a head waits for the owner's verdict: an agent's card, none yet, not withdrawn, not a draft */
150
- export const waits = (x: ReviewItem): boolean => x.item.origin.by === 'agent' && !x.item.wip && verdictOf(x) === null && withdrawnOf(x) === undefined
152
+ export const waits = (x: ReviewItem): boolean => x.item.origin.by === 'agent' && !inWork(x) && verdictOf(x) === null && withdrawnOf(x) === undefined
151
153
 
152
154
  /** the active pending heads first in the order they were sent, then every other thread, newest first */
153
155
  export function orderedThreads(items: readonly ReviewItem[]): Thread[] {
154
156
  const all = threadsOf(items)
155
- const first = (x: ReviewItem): boolean => waits(x) || (x.item.wip !== undefined && verdictOf(x) === null && withdrawnOf(x) === undefined)
157
+ const first = (x: ReviewItem): boolean => waits(x) || (x.item.origin.by === 'agent' && inWork(x))
156
158
  const pending = all.filter((t) => first(t.head)).sort((a, b) => oldest(a.head, b.head))
157
159
  const rest = all.filter((t) => !first(t.head)).sort((a, b) => newest(a.head, b.head))
158
160
  return [...pending, ...rest]
@@ -209,16 +211,16 @@ export function statusOf(x: ReviewItem, items: readonly ReviewItem[]): ShownStat
209
211
  const v = verdictOf(x)
210
212
  if (v) return v.status
211
213
  if (withdrawnOf(x) !== undefined) return 'withdrawn'
212
- if (x.item.wip) return 'wip'
214
+ if (inWork(x)) return 'wip'
213
215
  return supersederOf(x.item.id, items) ? 'superseded' : 'pending'
214
216
  }
215
217
 
216
- /** the latest thing on `x` the agent has not seen: its verdict or a reply of the owner */
218
+ /** the latest thing on `x` the agent has not seen: its verdict, a reply of the owner, or a verdict he took back */
217
219
  const lastUnseen = (x: ReviewItem, answered: boolean): string => {
218
220
  const v = verdictOf(x)
219
221
  const opening = answered || stateOf(x, false).state === 'closed' ? openingOf(x) : undefined
220
222
  const replies = unreadBy(x, 'agent').filter((m) => m !== opening)
221
- return [...(v && !v.seen ? [v.at] : []), ...replies.map((m) => m.at)].sort().at(-1) ?? ''
223
+ return [...(v && !v.seen ? [v.at] : []), ...replies.map((m) => m.at), ...takenBackOf(x).map((t) => t.m.at)].sort().at(-1) ?? ''
222
224
  }
223
225
 
224
226
  /** the items with a verdict or an owner reply the agent has not marked seen yet, oldest first */
@@ -1,6 +1,6 @@
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
- import { isFrame, isReply, partyOf, stateOf, type ReviewItem } from './model.ts'
3
+ import { isFrame, isGallery, isReply, partyOf, stateOf, type ReviewItem } from './model.ts'
4
4
  import type { CutStates } from '../trailer/shot-state.ts'
5
5
 
6
6
  export type NoteState = 'open' | 'done' | 'wontfix'
@@ -98,7 +98,7 @@ export function noteOf(x: ReviewItem, n: number): TrailerNote | null {
98
98
  ...(closing?.note ? { reply: closing.note } : {}),
99
99
  written: x.item.created,
100
100
  ...(closing ? { closed: closing.at } : {}),
101
- still: first && 'files' in first && 'image' in first.files ? first.files.image : 'image.png',
101
+ still: first && !isGallery(first) && 'image' in first.files ? first.files.image : 'image.png',
102
102
  }
103
103
  }
104
104