rvlib-shipkit 2.10.0 → 2.11.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 (63) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/package.json +1 -1
  3. package/src/cli/cmd_Media.ts +164 -0
  4. package/src/cli/family-pages.ts +1 -0
  5. package/src/cli/registry.ts +2 -0
  6. package/src/collections/pings.ts +6 -4
  7. package/src/core/app-icon.ts +17 -4
  8. package/src/core/scratch-objects.ts +56 -0
  9. package/src/core/trace-audit.ts +13 -1
  10. package/src/home/home-paths.ts +4 -0
  11. package/src/home/home-routes.ts +36 -2
  12. package/src/home/hubs.ts +5 -0
  13. package/src/home/inbox-shape.ts +182 -0
  14. package/src/home/inbox.ts +48 -0
  15. package/src/home/run-daemon.ts +12 -2
  16. package/src/home/serve-web.ts +155 -16
  17. package/src/ledger/git-scan.ts +73 -25
  18. package/src/ledger/repo-view.ts +2 -22
  19. package/src/media-kinds.ts +7 -0
  20. package/src/media-store/content.ts +51 -0
  21. package/src/media-store/daemon.ts +91 -0
  22. package/src/media-store/db.ts +74 -0
  23. package/src/media-store/fact.ts +9 -0
  24. package/src/media-store/kind.ts +44 -0
  25. package/src/media-store/purge.ts +139 -0
  26. package/src/media-store/remote.ts +93 -0
  27. package/src/media-store/space.ts +124 -0
  28. package/src/media-store/sync.ts +101 -0
  29. package/src/media-store/upload.ts +98 -0
  30. package/src/repo-config.ts +4 -0
  31. package/src/review/anim.ts +6 -5
  32. package/src/review/cells.ts +5 -1
  33. package/src/review/media-kind.ts +84 -0
  34. package/src/review/media-read.ts +48 -0
  35. package/src/review/model.ts +14 -1
  36. package/src/review/previews.ts +41 -12
  37. package/src/review/routes.ts +28 -7
  38. package/src/review/store.ts +100 -40
  39. package/src/review/trailer-desk.ts +79 -46
  40. package/src/review/trailer-media.ts +163 -0
  41. package/src/review/trailer-routes.ts +5 -2
  42. package/src/serve/hub-app/home-st.ts +39 -9
  43. package/src/serve/hub-app/home.html +2 -1
  44. package/src/serve/hub-app/hub-app.tsx +7 -23
  45. package/src/serve/hub-app/icons.tsx +2 -0
  46. package/src/serve/hub-app/inbox-st.ts +144 -0
  47. package/src/serve/hub-app/inbox-view.tsx +205 -0
  48. package/src/serve/hub-app/inbox.css +73 -0
  49. package/src/serve/hub-app/item-view.tsx +19 -0
  50. package/src/serve/hub-app/keys.ts +4 -3
  51. package/src/serve/hub-app/palette-st.ts +2 -1
  52. package/src/serve/hub-app/project-list.tsx +1 -0
  53. package/src/serve/hub-app/projects-svc.ts +1 -1
  54. package/src/serve/hub-app/repo-st.ts +1 -1
  55. package/src/serve/hub-app/review/review-st.ts +1 -0
  56. package/src/serve/hub-app/review/review-thread.tsx +5 -4
  57. package/src/serve/hub-app/review.css +1 -1
  58. package/src/serve/hub-runtime.ts +9 -4
  59. package/src/serve/serve-hub.ts +4 -1
  60. package/src/serve/warm-cell.ts +6 -1
  61. package/src/trailer/footage.ts +6 -2
  62. package/src/trailer/passage.ts +4 -2
  63. package/src/trailer/prune.ts +6 -10
@@ -2,9 +2,12 @@
2
2
  // is raised with: the note itself is an item of the one store, its subject the frame, anchored on its shot's name, so it
3
3
  // survives a new render of the cut. A cut is a `trailer/<id>/<cut>.trailer` and its render `out/<name>.mp4` (`<name>`
4
4
  // its `trailer` line), or a render with no file beside it. The trailer core (src/trailer/) is read, never changed
5
- import { constants, copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'
5
+ import { constants, copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs'
6
6
  import { join, relative } from 'node:path'
7
7
  import { LAYOUT } from '../core/layout.ts'
8
+ import { mediaKey } from '../media-store/content.ts'
9
+ import type { MediaFact } from '../media-store/fact.ts'
10
+ import { fetchBack, signedUrl } from '../media-store/remote.ts'
8
11
  import { parseTrailer, starts, total, type Trailer } from '../trailer/grammar.ts'
9
12
  import { THUMB_W } from '../trailer/graph.ts'
10
13
  import { probe, stillAt } from './media.ts'
@@ -126,7 +129,7 @@ export function trailerIds(root: string): string[] {
126
129
  export const cutOf = (dir: string, cut: string): CutFiles | null => (CUT_RE.test(cut) ? (cutsOf(dir).find((c) => c.cut === cut) ?? null) : null)
127
130
  /** a cut's render: out/<name>.mp4, or a version's own */
128
131
  export const videoOf = (dir: string, c: CutFiles): string => (c.version ? (versionFile(dir, c.cut, '.mp4') ?? join(dir, 'versions', c.cut, `${c.cut}.mp4`)) : join(dir, 'out', `${c.name}.mp4`))
129
- const stripOf = (dir: string, c: CutFiles): string => (c.version ? (versionFile(dir, c.cut, '.strip.png') ?? join(dir, 'versions', c.cut, `${c.cut}.strip.png`)) : join(dir, 'out', `${c.name}.strip.png`))
132
+ export const stripOf = (dir: string, c: CutFiles): string => (c.version ? (versionFile(dir, c.cut, '.strip.png') ?? join(dir, 'versions', c.cut, `${c.cut}.strip.png`)) : join(dir, 'out', `${c.name}.strip.png`))
130
133
  export const montageOf = (dir: string, c: CutFiles): string => join(dir, 'out', `${c.name}.montage.md`)
131
134
 
132
135
  /** a cut's .trailer parsed: the film lines need the project CLI's words, which a timeline never does, so their errors
@@ -143,21 +146,32 @@ function parseCut(file: string): { trailer: Trailer; errors: string[] } {
143
146
  const SETTLE_MS = 2500
144
147
  const settled = (mtime: number, now: number): boolean => now - mtime > SETTLE_MS
145
148
 
146
- /** where each finished render is kept as the page plays it: an APFS clone, free, untouched by the next render */
149
+ /** where each finished render is recorded as the page plays it: its json, and an APFS clone of its video and strip
150
+ * (free, untouched by the next render) until the media store holds them (wiki build/trailer.md, Frame notes) */
147
151
  export const viewDir = (root: string): string => join(root, LAYOUT.cache, 'trailer-view')
148
- /** the versions kept per cut: the one on screen may be the one before the newest */
149
- const VIEWS_KEPT = 3
150
152
 
151
- /** a finished render of a cut: its clone, its length and rate, its size, the timeline it was rendered from (null: unknown) */
153
+ /** a render's files by their content, filled by the media store's scan (src/review/trailer-media.ts) */
154
+ export interface ViewMedia {
155
+ video?: MediaFact
156
+ strip?: MediaFact
157
+ /** the strip's width and height, so the timeline reads its grid once the clone is gone */
158
+ stripSize?: [number, number]
159
+ /** a kept version's own files with the same content, repo relative; set once checked */
160
+ from?: { video?: string; strip?: string }
161
+ }
162
+
163
+ /** a finished render of a cut: its length and rate, its size, the timeline it was rendered from (null: unknown), its
164
+ * files' content */
152
165
  export interface View {
153
166
  mtime: number
154
167
  duration: number
155
168
  fps: number
156
169
  size: [number, number]
157
170
  timeline: Timeline | null
171
+ media?: ViewMedia
158
172
  }
159
173
 
160
- const viewBase = (root: string, id: string, cut: string, mtime: number): string => join(viewDir(root), `${id}--${cut}--${Math.round(mtime)}`)
174
+ export const viewBase = (root: string, id: string, cut: string, mtime: number): string => join(viewDir(root), `${id}--${cut}--${Math.round(mtime)}`)
161
175
  export const viewVideo = (root: string, id: string, cut: string, mtime: number): string => `${viewBase(root, id, cut, mtime)}.mp4`
162
176
  export const viewStrip = (root: string, id: string, cut: string, mtime: number): string => `${viewBase(root, id, cut, mtime)}.strip.png`
163
177
 
@@ -169,10 +183,19 @@ function keepStrip(root: string, dir: string, id: string, c: CutFiles, mtime: nu
169
183
  copyFileSync(sf, kept, constants.COPYFILE_FICLONE)
170
184
  }
171
185
 
172
- /** a kept version by its mtime, null when it was pruned */
186
+ /** a render by its mtime, null when nothing holds its video: neither its clone nor the media store */
173
187
  export function readView(root: string, id: string, cut: string, mtime: number): View | null {
174
188
  const f = `${viewBase(root, id, cut, mtime)}.json`
175
- return existsSync(f) && existsSync(viewVideo(root, id, cut, mtime)) ? (JSON.parse(readFileSync(f, 'utf8')) as View) : null
189
+ if (!existsSync(f)) return null
190
+ const v = JSON.parse(readFileSync(f, 'utf8')) as View
191
+ return v.media?.video || existsSync(viewVideo(root, id, cut, mtime)) ? v : null
192
+ }
193
+
194
+ /** a render's record written whole, through a file beside it renamed */
195
+ export function writeView(root: string, id: string, cut: string, v: View): void {
196
+ const f = `${viewBase(root, id, cut, v.mtime)}.json`
197
+ writeFileSync(`${f}.${process.pid}.tmp`, JSON.stringify(v))
198
+ renameSync(`${f}.${process.pid}.tmp`, f)
176
199
  }
177
200
 
178
201
  function newestView(root: string, id: string, cut: string): View | null {
@@ -230,55 +253,63 @@ export function viewOf(root: string, dir: string, id: string, c: CutFiles, now =
230
253
  timeline = null
231
254
  }
232
255
  const view: View = { mtime, ...p, timeline }
233
- writeFileSync(`${viewBase(root, id, c.cut, mtime)}.json`, JSON.stringify(view))
256
+ writeView(root, id, c.cut, view)
234
257
  keepStrip(root, dir, id, c, mtime)
235
258
  views.set(key, view)
236
- pruneViews(root, id, c.cut)
237
259
  return { view, rendering: false }
238
260
  }
239
261
 
240
- function pruneViews(root: string, id: string, cut: string): void {
241
- const prefix = `${id}--${cut}--`
242
- for (const f of viewsToDrop(root)) if (f.slice(viewDir(root).length + 1).startsWith(prefix)) rmSync(f, { force: true })
243
- }
262
+ export const TRAILER_KIND = 'trailer'
244
263
 
245
- /** the kept renders that go: every one past the newest VIEWS_KEPT of a cut, and every one of a cut its folder no longer
246
- * has (a note keeps its own still) */
247
- export function viewsToDrop(root: string): string[] {
248
- const vd = viewDir(root)
249
- if (!existsSync(vd)) return []
250
- const live = new Set(trailerIds(root).flatMap((id) => cutsOf(join(trailersDir(root), id)).map((c) => `${id}--${c.cut}`)))
251
- const byCut = new Map<string, Set<number>>()
252
- const files = readdirSync(vd)
253
- for (const f of files) {
254
- const m = /^(.+)--(\d+)\./.exec(f)
255
- if (!m) continue
256
- const ms = byCut.get(m[1]!) ?? new Set<number>()
257
- byCut.set(m[1]!, ms.add(Number(m[2])))
264
+ /** where the Space keeps a render's file */
265
+ export const trailerKey = (f: MediaFact, part: 'video' | 'strip'): string => mediaKey(TRAILER_KIND, f, part === 'video' ? 'render.mp4' : 'strip.png')
266
+
267
+ /** the folder of the view clones, relative to the repo: the item of their rows in the media index */
268
+ export const VIEW_ITEM = join(LAYOUT.cache, 'trailer-view')
269
+
270
+ /** a render's video or strip as the page reads it: its clone, else the cut's own file while it is that render (a live
271
+ * cut's out/ file at the same mtime, a version's own file), else a URL the media store signs. `bytes` wants a file:
272
+ * the store's copy is fetched back into the clone's place. null when nothing holds it */
273
+ export async function viewMedia(root: string, id: string, cut: string, mtime: number, part: 'video' | 'strip', o: { bytes?: boolean } = {}): Promise<{ path: string } | { url: string } | null> {
274
+ const v = readView(root, id, cut, mtime)
275
+ if (!v) return null
276
+ const clone = part === 'video' ? viewVideo(root, id, cut, mtime) : viewStrip(root, id, cut, mtime)
277
+ if (existsSync(clone)) return { path: clone }
278
+ const dir = trailerDir(root, id)
279
+ const c = dir ? cutOf(dir, cut) : null
280
+ if (dir && c && part === 'video') {
281
+ const own = videoOf(dir, c)
282
+ if (existsSync(own) && Math.round(statSync(own).mtimeMs) === mtime) return { path: own }
258
283
  }
259
- const kept = new Set(
260
- [...byCut].flatMap(([cut, ms]) =>
261
- live.has(cut)
262
- ? [...ms]
263
- .sort((x, y) => y - x)
264
- .slice(0, VIEWS_KEPT)
265
- .map((m) => `${cut}--${m}`)
266
- : [],
267
- ),
268
- )
269
- return files.filter((f) => !kept.has(/^(.+--\d+)\./.exec(f)?.[1] ?? '')).map((f) => join(vd, f))
284
+ const fact = v.media?.[part]
285
+ const from = v.media?.from?.[part]
286
+ if (from && fact && existsSync(join(root, from)) && statSync(join(root, from)).size === fact.size) return { path: join(root, from) }
287
+ if (!fact) return null
288
+ const key = trailerKey(fact, part)
289
+ if (o.bytes) {
290
+ const back = await fetchBack(clone, key, fact, { store: root, item: VIEW_ITEM, name: clone.slice(viewDir(root).length + 1) })
291
+ return back ? { path: back } : null
292
+ }
293
+ const url = await signedUrl(key, fact.size)
294
+ return url ? { url } : null
270
295
  }
271
296
 
272
297
  /** the contact strip's grid as src/trailer/stitch.ts lays it: rows of six tiles THUMB_W wide, 6 px apart */
273
298
  const STRIP_COLS = 6
274
299
  const STRIP_PAD = 6
275
300
 
276
- /** the strip's grid, when the file's size fits this timeline's shots */
277
- function stripInfo(file: string, tl: Timeline): CutInfo['strip'] {
278
- if (!existsSync(file) || tl.shots.length === 0) return null
301
+ /** a png's width and height, read from its header */
302
+ export function pngSize(file: string): [number, number] {
279
303
  const head = readFileSync(file).subarray(0, 24)
280
- const w = head.readUInt32BE(16)
281
- const h = head.readUInt32BE(20)
304
+ return [head.readUInt32BE(16), head.readUInt32BE(20)]
305
+ }
306
+
307
+ /** the strip's grid, when its size fits this timeline's shots: read from the clone, else from the render's record */
308
+ function stripInfo(file: string, v: View, tl: Timeline): CutInfo['strip'] {
309
+ if (tl.shots.length === 0) return null
310
+ const wh = existsSync(file) ? pngSize(file) : v.media?.strip ? v.media.stripSize : undefined
311
+ if (!wh) return null
312
+ const [w, h] = wh
282
313
  const cols = Math.min(STRIP_COLS, tl.shots.length)
283
314
  const rows = Math.ceil(tl.shots.length / cols)
284
315
  const tileH = Math.round((THUMB_W * tl.size[1]) / tl.size[0] / 2) * 2
@@ -313,7 +344,7 @@ export function cutInfo(root: string, dir: string, id: string, c: CutFiles): Cut
313
344
  video: view ? { mtime: view.mtime, duration: view.duration, fps: view.fps } : null,
314
345
  rendering: !c.version && rendering,
315
346
  edited: !c.version && c.trailer !== null && view !== null && fileMtime > view.mtime,
316
- strip: timeline && view ? stripInfo(viewStrip(root, id, c.cut, view.mtime), timeline) : null,
347
+ strip: timeline && view ? stripInfo(viewStrip(root, id, c.cut, view.mtime), view, timeline) : null,
317
348
  fileMtime,
318
349
  version: c.version === true,
319
350
  }
@@ -362,7 +393,9 @@ export async function frameNote(root: string, trailer: string, input: NewNote, s
362
393
  const f = frameAt(input.time, v.fps, v.duration)
363
394
  const shot = shotAt(tl, f.time)
364
395
  if (!shot) throw new Error(`${input.cut} has no shot`)
365
- await stillAt(viewVideo(root, trailer, input.cut, v.mtime), (f.frame - 0.5) / v.fps, still)
396
+ const video = await viewMedia(root, trailer, input.cut, v.mtime, 'video', { bytes: true })
397
+ if (!video || !('path' in video)) throw new Error(`the render of ${input.cut} on screen is in neither the disk nor the media store`)
398
+ await stillAt(video.path, (f.frame - 0.5) / v.fps, still)
366
399
  return { kind: 'frame', trailer, cut: input.cut, version: String(v.mtime), time: round(f.time), frame: f.frame, shot: shot.name, shotTime: round(f.time - shot.start), section: shot.section }
367
400
  }
368
401
 
@@ -0,0 +1,163 @@
1
+ // the trailer renders as a kind of the media store (wiki build/trailer.md, Renders in the media store): each settled
2
+ // render's clone in the view folder and a kept version's own files, by the facts its view record keeps. Kept on the
3
+ // disk: the newest render of each live cut, the render an open frame note was written on, and any render seen in the
4
+ // window. A file goes only when its own bytes hash to the key. The takes and footage cache is never this kind's
5
+ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
6
+ import { basename, dirname, join, relative } from 'node:path'
7
+ import { factOf, shaOf, shaOfKey } from '../media-store/content.ts'
8
+ import type { MediaFact } from '../media-store/fact.ts'
9
+ import type { MediaKind, MediaRow } from '../media-store/kind.ts'
10
+ import { fetchBack } from '../media-store/remote.ts'
11
+ import { isFrame } from './model.ts'
12
+ import { readAllCached, storeDir } from './store.ts'
13
+ import { cutOf, cutsOf, pngSize, stripOf, TRAILER_KIND, trailerDir, trailerIds, trailerKey, trailerStamp, videoOf, VIEW_ITEM, viewDir, viewOf, writeView, type View } from './trailer-desk.ts'
14
+ import { noteOf } from './trailer-model.ts'
15
+
16
+ /** a view record's name, `<trailer>--<cut>--<mtime>` */
17
+ const BASE_RE = /^(.+?)--(.+)--(\d+)$/
18
+
19
+ interface ViewRecord {
20
+ base: string
21
+ id: string
22
+ cut: string
23
+ v: View
24
+ }
25
+
26
+ function records(root: string): ViewRecord[] {
27
+ const d = viewDir(root)
28
+ if (!existsSync(d)) return []
29
+ return readdirSync(d)
30
+ .filter((f) => f.endsWith('.json'))
31
+ .sort()
32
+ .flatMap((f) => {
33
+ const base = f.slice(0, -'.json'.length)
34
+ const m = BASE_RE.exec(base)
35
+ if (!m) return []
36
+ try {
37
+ return [{ base, id: m[1]!, cut: m[2]!, v: JSON.parse(readFileSync(join(d, f), 'utf8')) as View }]
38
+ } catch {
39
+ return []
40
+ }
41
+ })
42
+ }
43
+
44
+ const sizeOf = (p: string): number | undefined => statSync(p, { throwIfNoEntry: false })?.size
45
+
46
+ /** a version's own file, recorded only when its bytes are the clone's */
47
+ async function sameAs(root: string, file: string, f: MediaFact): Promise<string | undefined> {
48
+ return existsSync(file) && sizeOf(file) === f.size && (await shaOf(file)) === f.sha ? relative(root, file) : undefined
49
+ }
50
+
51
+ export const trailerMedia: MediaKind = {
52
+ kind: TRAILER_KIND,
53
+ storeOf: (root) => (existsSync(join(root, 'trailer')) ? root : null),
54
+ stamp: (root) => `${trailerStamp(root)}#${existsSync(viewDir(root)) ? readdirSync(viewDir(root)).length : 0}`,
55
+ async scan(root, o) {
56
+ // every settled render gets its record, whether or not the page was opened since
57
+ for (const id of trailerIds(root)) {
58
+ const dir = trailerDir(root, id)
59
+ if (dir) for (const c of cutsOf(dir)) viewOf(root, dir, id, c)
60
+ }
61
+ const rows: MediaRow[] = []
62
+ let budget = o.fill
63
+ let filled = 0
64
+ let left = 0
65
+ const take = (): boolean => {
66
+ if (budget <= 0) {
67
+ left++
68
+ return false
69
+ }
70
+ budget--
71
+ filled++
72
+ return true
73
+ }
74
+ for (const r of records(root)) {
75
+ const media = { ...r.v.media }
76
+ let moved = false
77
+ const video = join(viewDir(root), `${r.base}.mp4`)
78
+ const strip = join(viewDir(root), `${r.base}.strip.png`)
79
+ if (!media.video && existsSync(video) && take()) {
80
+ media.video = await factOf(video)
81
+ moved = true
82
+ }
83
+ if (!media.strip && existsSync(strip) && take()) {
84
+ media.strip = await factOf(strip)
85
+ media.stripSize = pngSize(strip)
86
+ moved = true
87
+ }
88
+ const dir = trailerDir(root, r.id)
89
+ const c = dir ? cutOf(dir, r.cut) : null
90
+ if (!media.from && c?.version && dir && media.video && (media.strip || !existsSync(strip)) && take()) {
91
+ const own = videoOf(dir, c)
92
+ const from = {
93
+ ...(Math.round(statSync(own, { throwIfNoEntry: false })?.mtimeMs ?? -1) === r.v.mtime ? { video: await sameAs(root, own, media.video) } : {}),
94
+ ...(media.strip ? { strip: await sameAs(root, stripOf(dir, c), media.strip) } : {}),
95
+ }
96
+ media.from = Object.fromEntries(Object.entries(from).filter(([, x]) => x !== undefined))
97
+ moved = true
98
+ }
99
+ if (moved) writeView(root, r.id, r.cut, { ...r.v, media })
100
+ const row = (path: string, f: MediaFact | undefined): void => {
101
+ const s = sizeOf(path)
102
+ if (!f) {
103
+ if (s === undefined) rows.push({ item: relative(root, dirname(path)), name: basename(path), fact: null, local: false })
104
+ return
105
+ }
106
+ // a file of another content at that place is never this record's
107
+ if (s !== undefined && s !== f.size) return
108
+ rows.push({ item: relative(root, dirname(path)), name: basename(path), fact: f, local: s === f.size })
109
+ }
110
+ row(video, media.video)
111
+ if (media.strip || existsSync(strip)) row(strip, media.strip)
112
+ if (media.from?.video) row(join(root, media.from.video), media.video)
113
+ if (media.from?.strip) row(join(root, media.from.strip), media.strip)
114
+ }
115
+ return { rows, filled, left }
116
+ },
117
+ async holds(root) {
118
+ const recs = records(root)
119
+ const owner = new Map<string, ViewRecord>()
120
+ for (const r of recs) {
121
+ owner.set(`${VIEW_ITEM}/${r.base}.mp4`, r)
122
+ owner.set(`${VIEW_ITEM}/${r.base}.strip.png`, r)
123
+ for (const p of Object.values(r.v.media?.from ?? {})) if (p) owner.set(`${dirname(p)}/${basename(p)}`, r)
124
+ }
125
+ // the newest render of each live cut: the one the page plays first, and the cut's out/ file is that render
126
+ const newest = new Map<string, number>()
127
+ const live = new Set(trailerIds(root).flatMap((id) => cutsOf(join(root, 'trailer', id)).filter((c) => !c.version).map((c) => `${id}--${c.cut}`)))
128
+ for (const r of recs) if (live.has(`${r.id}--${r.cut}`)) newest.set(`${r.id}--${r.cut}`, Math.max(newest.get(`${r.id}--${r.cut}`) ?? 0, r.v.mtime))
129
+ const open = new Set<string>()
130
+ const used = new Map<string, number>()
131
+ for (const x of readAllCached(storeDir(root)).items) {
132
+ const s = x.item.subject
133
+ if (!isFrame(s)) continue
134
+ const base = `${s.trailer}--${s.cut}--${s.version}`
135
+ if (noteOf(x, 0)?.state === 'open') open.add(base)
136
+ const at = Math.max(Date.parse(x.item.created) || 0, ...x.thread.map((m) => Date.parse(m.at) || 0))
137
+ used.set(base, Math.max(used.get(base) ?? 0, at))
138
+ }
139
+ return (row) => {
140
+ const r = owner.get(`${row.item}/${row.name}`)
141
+ if (!r) return { pinned: false, used: undefined }
142
+ const pinned = newest.get(`${r.id}--${r.cut}`) === r.v.mtime || open.has(r.base)
143
+ return { pinned, used: Math.max(r.v.mtime, used.get(r.base) ?? 0) }
144
+ }
145
+ },
146
+ async beforePurge(root, _space, r) {
147
+ const want = shaOfKey(r.key)
148
+ const path = join(root, r.item, r.name)
149
+ if (!want || (await shaOf(path)) !== want) throw new Error(`${path} does not hash to its key ${r.key}: kept`)
150
+ },
151
+ }
152
+
153
+ /** a kept version's video on the disk, fetched back from the media store when the disk let it go; null when neither */
154
+ export async function versionVideoBack(root: string, id: string, v: string): Promise<string | null> {
155
+ for (const r of records(root).filter((x) => x.id === id && x.cut === v)) {
156
+ const from = r.v.media?.from?.video
157
+ const f = r.v.media?.video
158
+ if (!from || !f) continue
159
+ const path = join(root, from)
160
+ return fetchBack(path, trailerKey(f, 'video'), f, { store: root, item: dirname(from), name: basename(from) })
161
+ }
162
+ return null
163
+ }
@@ -7,7 +7,7 @@ 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, viewStrip, viewVideo } from './trailer-desk.ts'
10
+ import { cutOf, frameNote, montagePage, trailerDir, trailerIds, trailerInfo, videoOf, viewMedia } from './trailer-desk.ts'
11
11
  import { CUT_RE, noteOf, TRAILER_ID_RE, type NotePin, type NoteState, type TrailerDesk } from './trailer-model.ts'
12
12
 
13
13
  const clamp = (v: number): number => Number(Math.min(1, Math.max(0, v)).toFixed(4))
@@ -54,7 +54,10 @@ export async function trailerRoutes(req: Request, path: string, root: string, di
54
54
  if (media && req.method === 'GET') {
55
55
  const [, kind, id = '', cut = '', version = ''] = media
56
56
  if (!TRAILER_ID_RE.test(id) || !CUT_RE.test(cut)) return bad(`${path}?`, 404)
57
- return ranged(req, kind === 'video' ? viewVideo(root, id, cut, Number(version)) : viewStrip(root, id, cut, Number(version)))
57
+ const at = await viewMedia(root, id, cut, Number(version), kind === 'video' ? 'video' : 'strip')
58
+ if (!at) return bad(`no render ${id}/${cut} at ${version}: neither the disk nor the media store holds it`, 404)
59
+ // a render the disk let go plays from the Space: the signed URL lives an hour, the browser keeps half of it
60
+ return 'path' in at ? ranged(req, at.path) : new Response(null, { status: 302, headers: { Location: at.url, 'Cache-Control': 'private, max-age=1800' } })
58
61
  }
59
62
  const mont = /^\/api\/trailer\/montage\/([^/]+)\/([^/]+)$/.exec(path)
60
63
  if (mont && req.method === 'GET') {
@@ -20,6 +20,7 @@ import { PaletteSt } from './palette-st.ts'
20
20
  import { PlannedSt } from './planned-st.ts'
21
21
  import { ActivitySt } from './activity-st.ts'
22
22
  import { InsightsSt } from './insights-st.ts'
23
+ import { InboxSt } from './inbox-st.ts'
23
24
  import { ProjectsSvc } from './projects-svc.ts'
24
25
  import { parseFilter, RepoSt } from './repo-st.ts'
25
26
  import { openSection, repoSections, sectionOfRepo } from './repo-sections.ts'
@@ -27,11 +28,11 @@ import { openSection, repoSections, sectionOfRepo } from './repo-sections.ts'
27
28
  /** the longest one repo's read ahead holds the next one back */
28
29
  export const PREFETCH_WAIT_MS = 10_000
29
30
 
30
- /** what the page shows: the machine overview, the plan, the activity, the insights, the archived repos, or one repo */
31
- export type Page = 'overview' | 'planned' | 'activity' | 'insights' | 'archived' | 'repo'
31
+ /** what the page shows: the machine overview, the inbox, the plan, the activity, the insights, the archived repos, or one repo */
32
+ export type Page = 'overview' | 'inbox' | 'planned' | 'activity' | 'insights' | 'archived' | 'repo'
32
33
 
33
34
  /** the address of each page of the home that is no repo's */
34
- export const PLACE_PATH = { overview: '/', planned: '/planned', activity: '/activity', insights: '/insights', archived: '/archived' } as const
35
+ export const PLACE_PATH = { overview: '/', inbox: '/inbox', planned: '/planned', activity: '/activity', insights: '/insights', archived: '/archived' } as const
35
36
 
36
37
  /** where a repo's hub answers on the home */
37
38
  export const repoBase = (name: string): string => `/r/${encodeURIComponent(name)}`
@@ -49,6 +50,7 @@ export const checkAddress = (repo: string, check: string): string =>
49
50
  export function routeOf(pathname: string): { page: Page; repo: string | null } {
50
51
  const m = /^\/r\/([^/]+)/.exec(pathname)
51
52
  if (m != null) return { page: 'repo', repo: decodeURIComponent(m[1]!) }
53
+ if (/^\/inbox\/?$/.test(pathname)) return { page: 'inbox', repo: null }
52
54
  if (/^\/planned\/?$/.test(pathname)) return { page: 'planned', repo: null }
53
55
  if (/^\/activity\/?$/.test(pathname)) return { page: 'activity', repo: null }
54
56
  if (/^\/insights\/?$/.test(pathname)) return { page: 'insights', repo: null }
@@ -78,6 +80,8 @@ export class HomeSt {
78
80
  /** what every repo committed and holds, polled while it is the page */
79
81
  activity: ActivitySt
80
82
  insights: InsightsSt
83
+ /** everything that waits on the owner in every repo, polled while it is the page */
84
+ inbox: InboxSt
81
85
  /** the one picker, cmd+j */
82
86
  palette: PaletteSt
83
87
  /** the widths of the project list and a repo's sidebar */
@@ -106,12 +110,13 @@ export class HomeSt {
106
110
  this.planned = new PlannedSt(this)
107
111
  this.activity = new ActivitySt(this)
108
112
  this.insights = new InsightsSt(this)
113
+ this.inbox = new InboxSt(this)
109
114
  this.palette = new PaletteSt(this)
110
115
  this.layout = new LayoutSt()
111
116
  this.dock = new DockSt(this)
112
117
  this.machine = o.home ? new MachineSt(this, o) : null
113
118
  this.page = o.home ? 'overview' : 'repo'
114
- makeAutoObservable<this, 'disposers' | 'onUrl' | 'prefetching' | 'base'>(this, { base: false, machine: false, projects: false, planned: false, activity: false, insights: false, palette: false, layout: false, theme: false, dock: false, repos: observableShallow, disposers: false, onUrl: false, prefetching: false })
119
+ makeAutoObservable<this, 'disposers' | 'onUrl' | 'prefetching' | 'base'>(this, { base: false, machine: false, projects: false, planned: false, activity: false, insights: false, inbox: false, palette: false, layout: false, theme: false, dock: false, repos: observableShallow, disposers: false, onUrl: false, prefetching: false })
115
120
  const m = this.machine
116
121
  if (m != null) {
117
122
  this.projects.onSelect = (name) => this.select(name)
@@ -147,6 +152,7 @@ export class HomeSt {
147
152
 
148
153
  get title(): string {
149
154
  if (this.page === 'overview') return 'home'
155
+ if (this.page === 'inbox') return this.inbox.count > 0 ? `inbox · ${this.inbox.count}` : 'inbox'
150
156
  if (this.page === 'planned') return 'planned'
151
157
  if (this.page === 'activity') return 'activity'
152
158
  if (this.page === 'insights') return 'insights'
@@ -193,6 +199,7 @@ export class HomeSt {
193
199
  this.machine?.stop()
194
200
  this.planned.stop()
195
201
  this.activity.stop()
202
+ this.inbox.stop()
196
203
  this.dock.dispose()
197
204
  for (const r of this.repos.values()) r.dispose()
198
205
  }
@@ -216,7 +223,12 @@ export class HomeSt {
216
223
  /** a check: its own page in its repo, in place. The selection is written
217
224
  * before the repo is shown, so the one history entry already names it */
218
225
  openCheck(repo: string, check: string): void {
219
- this.repo(repo).cols.select('checks', `check:${check}`)
226
+ this.openItem(repo, 'checks', `check:${check}`)
227
+ }
228
+
229
+ /** one row of a repo: its own page in its repo, in place, as one history entry */
230
+ openItem(repo: string, col: string, id: string): void {
231
+ this.repo(repo).cols.select(col, id)
220
232
  this.show('repo', repo, 'push')
221
233
  }
222
234
 
@@ -232,9 +244,20 @@ export class HomeSt {
232
244
  const u = new URL(path, 'http://home.invalid')
233
245
  const r = routeOf(u.pathname)
234
246
  if (r.page === 'planned') this.planned.query = u.searchParams.get('q') ?? ''
247
+ if (r.page === 'inbox') this.inbox.fromSearch(u.search)
235
248
  this.show(r.page, r.repo, 'push')
236
249
  }
237
250
 
251
+ /** the inbox on one item, or on its list: an item is a history entry of its own, so back returns to the list */
252
+ openInbox(item: { repo: string; id: string } | null): void {
253
+ const was = this.inbox.open
254
+ if (item != null) this.repo(item.repo)
255
+ this.inbox.open = item
256
+ const same = was?.repo === item?.repo && was?.id === item?.id
257
+ if (this.page === 'inbox' && same) return
258
+ this.show('inbox', null, item != null && this.page === 'inbox' ? 'push' : this.page === 'inbox' ? 'replace' : 'push')
259
+ }
260
+
238
261
  /** the url decides the page: the first load, back, forward and a hand
239
262
  * edited address all land here */
240
263
  fromUrl(): void {
@@ -246,6 +269,9 @@ export class HomeSt {
246
269
  // an address from before repo pages had their own path (`/#<repo>`)
247
270
  const legacy = r.page === 'overview' ? currentHash() : ''
248
271
  if (legacy !== '') return this.show('repo', legacy, 'replace')
272
+ // on a phone the home opens on the inbox
273
+ if (r.page === 'overview' && this.inbox.phone && location.search === '') return this.show('inbox', null, 'replace')
274
+ if (r.page === 'inbox') this.inbox.fromSearch(location.search)
249
275
  if (r.page === 'planned') this.planned.query = new URLSearchParams(location.search).get('q') ?? ''
250
276
  if (r.page === 'repo') this.repo(r.repo!).filter = parseFilter(location.search)
251
277
  this.show(r.page, r.repo, 'none')
@@ -259,7 +285,7 @@ export class HomeSt {
259
285
  const prevPage = this.page
260
286
  const next = page === 'repo' && repo != null ? this.repo(repo) : null
261
287
  // the page already shown is never a second history entry
262
- if (how === 'push' && page === this.page && next === prev && page !== 'planned') how = 'none'
288
+ if (how === 'push' && page === this.page && next === prev && page !== 'planned' && page !== 'inbox') how = 'none'
263
289
  if (prev != null && prev !== next) prev.pause()
264
290
  next?.markSeen()
265
291
  this.page = page
@@ -269,13 +295,17 @@ export class HomeSt {
269
295
  this.projects.away = next == null
270
296
  this.projects.place = page === 'repo' || page === 'archived' ? null : page
271
297
  if (how !== 'none') {
272
- const to = next != null ? `${repoPage(next.key)}${next.search}${next.hash}` : page === 'planned' ? this.planned.address : page === 'activity' || page === 'insights' || page === 'archived' ? PLACE_PATH[page] : '/'
273
- if (how === 'push') history.pushState(null, '', to)
274
- else history.replaceState(null, '', to)
298
+ const to = next != null ? `${repoPage(next.key)}${next.search}${next.hash}` : page === 'planned' ? this.planned.address : page === 'inbox' ? `${PLACE_PATH.inbox}${this.inbox.search}` : page === 'activity' || page === 'insights' || page === 'archived' ? PLACE_PATH[page] : '/'
299
+ // an inbox item marks its entry, so its back button goes back rather than forward to the list
300
+ const state = page === 'inbox' && this.inbox.open != null ? { inbox: 'item' } : null
301
+ if (how === 'push') history.pushState(state, '', to)
302
+ else history.replaceState(state, '', to)
275
303
  }
276
304
  if (page === 'planned') this.planned.start()
277
305
  else this.planned.stop()
278
306
  if (page === 'insights' && prevPage !== 'insights') this.insights.start()
307
+ if (page === 'inbox') this.inbox.start()
308
+ else this.inbox.stop()
279
309
  if (page === 'activity') this.activity.start()
280
310
  else this.activity.stop()
281
311
  if (next != null && next !== prev && this.machine?.data != null) void this.machine.hub(next.key, 'ensure')
@@ -2,7 +2,7 @@
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
6
6
  <title>home</title>
7
7
  <link rel="stylesheet" href="./hub.css" />
8
8
  <link rel="stylesheet" href="./project-list.css" />
@@ -15,6 +15,7 @@
15
15
  <link rel="stylesheet" href="./dock.css" />
16
16
  <link rel="stylesheet" href="./controls.css" />
17
17
  <link rel="stylesheet" href="./review.css" />
18
+ <link rel="stylesheet" href="./inbox.css" />
18
19
  </head>
19
20
  <body data-home>
20
21
  <div id="root"></div>
@@ -11,18 +11,16 @@ import { reaction, runInAction } from 'mobx'
11
11
  import { observer } from 'mobx-react-lite'
12
12
  import { StrictMode, useEffect, useLayoutEffect, useRef } from 'react'
13
13
  import { createRoot } from 'react-dom/client'
14
- import { ColCard, StatusCard } from './col-card.tsx'
14
+ import { StatusCard } from './col-card.tsx'
15
15
  import { AskTable, CheckTable, ItemTable, SecretTable } from './col-tables-view.tsx'
16
- import { WIKIS, WikisView } from './wikis-view.tsx'
17
- import { ComfyOverlay, ComfyView } from './comfy-view.tsx'
16
+ import { ComfyOverlay } from './comfy-view.tsx'
17
+ import { ItemView } from './item-view.tsx'
18
+ import { InboxView } from './inbox-view.tsx'
18
19
  import type { Filter, RepoSt } from './repo-st.ts'
19
20
  import { HomeSt, PLACE_PATH } from './home-st.ts'
20
21
  import { hashFor } from './hash-route.ts'
21
- import { TimelineView } from './timeline-view.tsx'
22
22
  import { HeaderBar, notUp } from './header-bar.tsx'
23
23
  import { FOLLOW_KEY } from './timeline-chart.tsx'
24
- import { CheckCard } from './check-view.tsx'
25
- import { TestCard } from './test-view.tsx'
26
24
  import { TestsPage } from './tests-view.tsx'
27
25
  import { AssetStage, CatGrid, InfoChips, MediaTopbar, ToolsBar, VariantsBar } from './media-view.tsx'
28
26
  import { Sidebar } from './sidebar.tsx'
@@ -81,22 +79,7 @@ const AssetRemarks = observer(({ app }: { app: RepoSt }) => {
81
79
  const Main = observer(({ app }: { app: RepoSt }) => {
82
80
  const m = app.media
83
81
  const errs = m.errors.length > 0 ? <div className="errs">{m.errors.join('\n')}</div> : null
84
- if (app.sel?.t === 'item') return (
85
- <main>
86
- {errs}
87
- {app.sel.col === WIKIS
88
- ? <WikisView app={app} id={app.sel.id} />
89
- : app.sel.col === 'comfy'
90
- ? <ComfyView app={app} id={app.sel.id} />
91
- : app.sel.col === 'checks'
92
- ? <div className="stagewrap"><CheckCard app={app} id={app.sel.id} /></div>
93
- : app.sel.col === 'tests'
94
- ? <div className="stagewrap"><TestCard app={app} id={app.sel.id} /></div>
95
- : app.sel.col === 'runs'
96
- ? <div className="stagewrap"><TimelineView app={app} /></div>
97
- : <div className="stagewrap"><ColCard app={app} col={app.sel.col} id={app.sel.id} /></div>}
98
- </main>
99
- )
82
+ if (app.sel?.t === 'item') return <main>{errs}<ItemView app={app} col={app.sel.col} id={app.sel.id} /></main>
100
83
  if (app.sel?.t === 'col') return (
101
84
  <main>
102
85
  {errs}
@@ -218,7 +201,7 @@ function onKey(e: KeyboardEvent): void {
218
201
  if (pk.t === 'picker') home.palette.toggle()
219
202
  else if (pk.t === 'dock') home.dock.cycle()
220
203
  else if (pk.t === 'rail') home.layout.toggleRail()
221
- else if (pk.t === 'home' || pk.t === 'planned' || pk.t === 'activity' || pk.t === 'insights') {
204
+ else if (pk.t === 'home' || pk.t === 'inbox' || pk.t === 'planned' || pk.t === 'activity' || pk.t === 'insights') {
222
205
  home.palette.close()
223
206
  if (home.machine != null) home.navigate(PLACE_PATH[pk.t === 'home' ? 'overview' : pk.t])
224
207
  } else if (pk.t === 'step') {
@@ -361,6 +344,7 @@ const App = observer(() => {
361
344
  <Panel id="page" minSize={320} className="appcol" style={PANEL}>
362
345
  {home.machine == null ? null : <HomeStrip app={home} />}
363
346
  {home.page === 'overview' ? <Overview app={home} /> : null}
347
+ {home.page === 'inbox' ? <InboxView app={home} /> : null}
364
348
  {home.page === 'planned' ? <PlannedView app={home} /> : null}
365
349
  {home.page === 'activity' ? <ActivityView app={home} /> : null}
366
350
  {home.page === 'insights' ? <InsightsView app={home} /> : null}
@@ -14,6 +14,8 @@ export const ICON = {
14
14
  archived: 'M2.5 4h15v3.5h-15zM4 7.5V16h12V7.5M8 10.5h4',
15
15
  insights: 'M3 16.5h14M5 16.5V11M9 16.5V5M13 16.5V8.5M17 16.5V12',
16
16
  home: 'M3 9.5 10 3.5l7 6M5 8v8.5h10V8M8.5 16.5v-4.5h3v4.5',
17
+ // a tray: what waits on the owner, every repo
18
+ inbox: 'M3 11.5 5.5 4h9l2.5 7.5V16H3zM3 11.5h4.5l1 2h3l1-2H17',
17
19
  planned: 'M5.5 3h9M5.5 17h9M6.5 3c0 4 7 4 7 7s-7 3-7 7M13.5 3c0 4-7 4-7 7s7 3 7 7',
18
20
  browser: 'M10 2.5a7.5 7.5 0 1 0 0 15a7.5 7.5 0 1 0 0-15M2.5 10h15M10 2.5c-3 3-3 12 0 15M10 2.5c3 3 3 12 0 15',
19
21
  window: 'M2.5 4h15v12h-15zM2.5 7.5h15M5 5.75h.01M7 5.75h.01',