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
@@ -12,7 +12,7 @@ import { graphRoutes } from 'rvlib-shipkit/src/wiki/serve-graph.ts'
12
12
  import type { StudioRoutes } from '../assets/server/studio-server.ts'
13
13
  import { comfyBoxUp, type ComfyBox, type ComfyPanelUp } from '../comfy/comfy-panel.ts'
14
14
  import { appendAskRemark, appendAssetNote, appendPostFeedback, askDone, askProof, markPosted, pickPostVariant } from '../collections/actions.ts'
15
- import { brokenRow, projectResources, type Collection, type Instance, type NeedItem } from '../collections/collection-types.ts'
15
+ import { brokenRow, projectResources, type Collection, type Instance, type NeedItem, type Resource } from '../collections/collection-types.ts'
16
16
  import type { CheckEvent } from '../core/run-check.ts'
17
17
  import { configDirty, readGateBlock, writeGateBlock, type GateEdit } from '../core/when-block.ts'
18
18
  import type { InvokedBy } from '../ledger/run-log.ts'
@@ -131,6 +131,8 @@ export type HubHandler = {
131
131
  invalidate: () => void
132
132
  /** compute the warm answers now, the rows first: the hub's load */
133
133
  warm: () => Promise<void>
134
+ /** every row that needs someone, from the warm rows as memory holds them: the home's inbox polls it */
135
+ needs: () => Promise<Resource[]>
134
136
  stop: () => void
135
137
  }
136
138
 
@@ -200,6 +202,7 @@ export function hubHandler(d: HubDeps, o: { base?: string; projects?: Gutter } =
200
202
  await timeline?.warm()
201
203
  for (const g of graphs.values()) await g.warm()
202
204
  },
205
+ needs: async () => (await rows.get({ held: true })).resources.filter((r) => r.severity != null),
203
206
  stop: () => { d.comfy?.stop() },
204
207
  async handle(req, path, srv): Promise<Response> {
205
208
  if (!sameOrigin(req)) return new Response('refused: a request that changes something must come from the hub page', { status: 403 })
@@ -91,7 +91,7 @@ export class WarmCell<T> {
91
91
 
92
92
  /** the answer in memory, a stale one kicking a recompute behind it. With
93
93
  * nothing in memory yet, or `fresh`, it waits on a compute */
94
- async get(o: { fresh?: boolean } = {}): Promise<T> {
94
+ async get(o: { fresh?: boolean; held?: boolean } = {}): Promise<T> {
95
95
  const watched = this.watched
96
96
  this.readAt = this.now()
97
97
  if (o.fresh === true) return this.fresh()
@@ -99,6 +99,11 @@ export class WarmCell<T> {
99
99
  // nothing in memory, a failed compute included: wait on a new one
100
100
  if (v == null) return this.run()
101
101
  const moved = this.stale || this.gen !== this.runGen
102
+ // `held`: a reader that polls (the home's inbox) takes what is in memory now, a compute behind it
103
+ if (o.held === true) {
104
+ if (moved && this.running == null) this.kick()
105
+ return v.v
106
+ }
102
107
  // the first reader in a while: what is in memory may be hours old,
103
108
  // and no save recomputed it meanwhile
104
109
  if (moved && !watched) return this.running != null && this.runGen === this.gen ? this.running : this.fresh()
@@ -5,6 +5,7 @@ import { copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync,
5
5
  import { tmpdir } from 'node:os'
6
6
  import { isAbsolute, join } from 'node:path'
7
7
  import type { TrailerFilmLine, TrailerUnit } from './adapter.ts'
8
+ import { scratchObjects } from '../core/scratch-objects.ts'
8
9
  import { duration } from './ffmpeg.ts'
9
10
  import type { Shot, Trailer } from './grammar.ts'
10
11
  import { cliArgv, isTake, recipeText, recipeWords, runCommand, type Stamp, specOf, type Take, type TakeFilm, type TakeSpec, takeIsStill, takeName, takeSeconds } from './plan.ts'
@@ -71,7 +72,8 @@ const git = (root: string, args: string[], env?: Record<string, string>): string
71
72
  * the world the takes show: every file of the repo as it stands, by its content (`trailer/` and `.shipkit/` left out),
72
73
  * or only the `paths` the trailer unit's `stamp` names; a repo with no git: `no-git`. Content addressed: the working
73
74
  * tree is staged into a throwaway copy of the index and the staged entries hashed, so the same content dirty or
74
- * committed is one world, and an edit of the cut alone moves nothing
75
+ * committed is one world, and an edit of the cut alone moves nothing. The blobs the add hashes go to a throwaway
76
+ * object dir too (core/scratch-objects.ts), never into the repo's store
75
77
  */
76
78
  export function worldStamp(root: string, paths?: readonly string[]): string {
77
79
  const real = git(root, ['rev-parse', '--git-path', 'index'])
@@ -79,17 +81,19 @@ export function worldStamp(root: string, paths?: readonly string[]): string {
79
81
  const spec = paths ? ['--', ...paths] : ['--', '.', ':(exclude)trailer', ':(exclude).shipkit']
80
82
  if (paths) for (const p of paths) if (!existsSync(join(root, p))) throw new Error(`the trailer unit's stamp names a path the repo does not hold: ${p}`)
81
83
  const index = join(tmpdir(), `sk-world-${process.pid}-${Math.random().toString(36).slice(2)}`)
84
+ const objects = scratchObjects(root, tmpdir())
82
85
  try {
83
86
  // a copy of the real index keeps git's stat cache: only the files that changed are read again
84
87
  const from = isAbsolute(real.trim()) ? real.trim() : join(root, real.trim())
85
88
  if (existsSync(from)) copyFileSync(from, index)
86
- const env = { GIT_INDEX_FILE: index }
89
+ const env = { ...objects.env, GIT_INDEX_FILE: index }
87
90
  if (git(root, ['add', '-A', ...spec], env) === null) throw new Error('git add into the world\'s throwaway index failed')
88
91
  const staged = git(root, ['ls-files', '-s', ...spec], env)
89
92
  if (staged === null) throw new Error('git ls-files of the world\'s throwaway index failed')
90
93
  return new Bun.CryptoHasher('sha1').update(staged).digest('hex').slice(0, 12)
91
94
  } finally {
92
95
  rmSync(index, { force: true })
96
+ objects.drop()
93
97
  }
94
98
  }
95
99
 
@@ -66,8 +66,10 @@ async function versionCut(l: Loaded, v: string, cwd: string): Promise<{ t: Trail
66
66
  if (!existsSync(text)) throw new Refused(`no ${relative(cwd, text)}`)
67
67
  const kept = await load(text, l.root, { dir: l.dir, check: false })
68
68
  if (kept.errors.length > 0) throw new Refused(`${v} does not read with today's tool (an older version builds only in a worktree at its tag): ${kept.errors[0]!.message}`)
69
- const video = versionVideo(l.dir, v) ?? join(l.dir, 'versions', v, `${basename(l.dir)}-${v}.mp4`)
70
- if (!existsSync(video)) throw new Refused(`no ${relative(cwd, video)}`)
69
+ let video = versionVideo(l.dir, v) ?? join(l.dir, 'versions', v, `${basename(l.dir)}-${v}.mp4`)
70
+ // a version the disk let go comes back from the media store
71
+ if (!existsSync(video)) video = (await (await import('../review/trailer-media.ts')).versionVideoBack(l.root, basename(l.dir), v)) ?? video
72
+ if (!existsSync(video)) throw new Refused(`no ${relative(cwd, video)}, on the disk or in the media store`)
71
73
  return { t: kept.t, video }
72
74
  }
73
75
 
@@ -163,7 +163,7 @@ function filesUnder(dir: string): string[] {
163
163
  const cacheOf = async (root: string): Promise<string> => join((await import('./footage.ts')).trailerCache(root, 'footage'), '..')
164
164
 
165
165
  /** each folder's files that go, as of `now`; `now` Infinity names the files only their age keeps too */
166
- function planOf(cache: string, live: Live, views: readonly string[], now: number): [string, Doomed[]][] {
166
+ function planOf(cache: string, live: Live, now: number): [string, Doomed[]][] {
167
167
  const whole = live.broken.length === 0
168
168
  // titles/ holds the vertical's drawings too: only a title's and a card's files are the prune's
169
169
  const ownTitle = (n: string): boolean => /^(title|card)-[0-9a-f]{16}\./.test(n)
@@ -176,7 +176,6 @@ function planOf(cache: string, live: Live, views: readonly string[], now: number
176
176
  ]
177
177
  const dead = existsSync(cache) ? readdirSync(cache, { withFileTypes: true }).filter((e) => e.isDirectory() && !FOLDERS.includes(e.name)) : []
178
178
  for (const d of dead) plan.push([`${d.name}/ (dead)`, filesUnder(join(cache, d.name)).map(doomed)])
179
- plan.push(['trailer-view/', views.filter((f) => existsSync(f) && now - statSync(f).mtimeMs > RENDER_GRACE_MS).map(doomed)])
180
179
  return plan
181
180
  }
182
181
 
@@ -188,15 +187,14 @@ interface Stamp {
188
187
 
189
188
  const stampFile = (cache: string): string => join(cache, 'prune.json')
190
189
 
191
- /** what the prune reads that a build can change: every cut's text, every file name in the cache's folders, the views
192
- * to drop. The same key and no spared file of age: the prune would find what it found */
190
+ /** what the prune reads that a build can change: every cut's text, every file name in the cache's folders. The same
191
+ * key and no spared file of age: the prune would find what it found */
193
192
  async function pruneKey(root: string, cache: string): Promise<string> {
194
- const [{ cutFiles }, { viewsToDrop }] = await Promise.all([import('./build.ts'), import('../review/trailer-desk.ts')])
193
+ const { cutFiles } = await import('./build.ts')
195
194
  const h = new Bun.CryptoHasher('sha1')
196
195
  for (const f of cutFiles(root)) h.update(`${f}\0`).update(readFileSync(f)).update('\0')
197
196
  const folders = existsSync(cache) ? readdirSync(cache, { withFileTypes: true }).filter((e) => e.isDirectory()) : []
198
197
  for (const d of folders.map((e) => e.name).sort()) h.update(`${d}/\0${filesUnder(join(cache, d)).sort().join('\0')}\0`)
199
- h.update(viewsToDrop(root).sort().join('\0'))
200
198
  return h.digest('hex')
201
199
  }
202
200
 
@@ -214,17 +212,15 @@ export async function pruneIfMoved(root: string, now = Date.now()): Promise<Prun
214
212
  /** plans every folder's prune, then deletes unless `dry`; a whole prune writes its stamp */
215
213
  export async function prune(root: string, o: { dry: boolean; now?: number }): Promise<Pruned> {
216
214
  const now = o.now ?? Date.now()
217
- const { viewsToDrop } = await import('../review/trailer-desk.ts')
218
215
  const cache = await cacheOf(root)
219
216
  const live = await liveSet(root)
220
- const views = viewsToDrop(root)
221
- const plan = planOf(cache, live, views, now)
217
+ const plan = planOf(cache, live, now)
222
218
  if (!o.dry && existsSync(cache)) {
223
219
  for (const [, ds] of plan) for (const d of ds) rmSync(d.file, { force: true })
224
220
  for (const d of readdirSync(cache, { withFileTypes: true }).filter((e) => e.isDirectory() && !FOLDERS.includes(e.name))) rmSync(join(cache, d.name), { recursive: true, force: true })
225
221
  rmSync(stampFile(cache), { force: true })
226
222
  if (live.broken.length === 0) {
227
- const spared = planOf(cache, live, views, Number.POSITIVE_INFINITY).flatMap(([, ds]) => ds.filter((d) => existsSync(d.file)))
223
+ const spared = planOf(cache, live, Number.POSITIVE_INFINITY).flatMap(([, ds]) => ds.filter((d) => existsSync(d.file)))
228
224
  const until = Math.min(Number.MAX_SAFE_INTEGER, ...spared.map((d) => statSync(d.file).mtimeMs + RENDER_GRACE_MS))
229
225
  writeFileSync(stampFile(cache), JSON.stringify({ key: await pruneKey(root, cache), until } satisfies Stamp))
230
226
  }