rvlib-shipkit 2.19.0 → 2.21.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 (196) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/package.json +1 -1
  3. package/src/annex/annex.ts +227 -0
  4. package/src/annex/offload.ts +279 -0
  5. package/src/checks/SK004-gitignore-policy.check.ts +6 -3
  6. package/src/checks/SK040-release-words.check.ts +43 -0
  7. package/src/checks/SK041-annex-links.check.ts +28 -0
  8. package/src/checks/SK042-post-kinds.check.ts +73 -0
  9. package/src/cli/cmd_Annex.ts +179 -0
  10. package/src/cli/cmd_Commands.ts +4 -1
  11. package/src/cli/cmd_GlobalProcesses.ts +2 -107
  12. package/src/cli/cmd_Home.ts +4 -3
  13. package/src/cli/cmd_Messages.ts +155 -0
  14. package/src/cli/cmd_Overview.ts +2 -1
  15. package/src/cli/cmd_Releases.ts +84 -0
  16. package/src/cli/cmd_Review.ts +176 -12
  17. package/src/cli/cmd_Shot.ts +4 -4
  18. package/src/cli/cmd_Social.ts +151 -8
  19. package/src/cli/cmd_Sound.ts +17 -4
  20. package/src/cli/cmd_Trailer.ts +67 -1
  21. package/src/cli/family-pages.ts +2 -0
  22. package/src/cli/kit/index.ts +1 -1
  23. package/src/cli/kit/verb.ts +11 -3
  24. package/src/cli/registry.ts +7 -1
  25. package/src/collections/collection-types.ts +8 -1
  26. package/src/collections/providers.ts +4 -1
  27. package/src/collections/review.ts +23 -4
  28. package/src/commands/model.ts +36 -0
  29. package/src/commands/registry.ts +49 -0
  30. package/src/commands/routes.ts +59 -0
  31. package/src/commands/runner.ts +35 -0
  32. package/src/commands/runs.ts +112 -0
  33. package/src/core/app-icon.ts +4 -3
  34. package/src/core/icon-type.ts +8 -0
  35. package/src/core/jobs.ts +4 -3
  36. package/src/core/layout.ts +11 -2
  37. package/src/core/squircle.ts +95 -0
  38. package/src/home/daemon-jobs.ts +26 -2
  39. package/src/home/global-units.ts +3 -0
  40. package/src/home/gui-app/ShipkitGui.swift +337 -5
  41. package/src/home/gui-app.ts +64 -33
  42. package/src/home/hmr-keep.ts +134 -0
  43. package/src/home/home-start.ts +2 -2
  44. package/src/home/lib-watch.ts +21 -11
  45. package/src/home/pm-switch.ts +112 -0
  46. package/src/home/pm.ts +1 -1
  47. package/src/home/process-apps.ts +181 -0
  48. package/src/home/resources.ts +3 -3
  49. package/src/home/run-web.ts +7 -4
  50. package/src/home/serve-web.ts +64 -14
  51. package/src/identities/collection.ts +49 -0
  52. package/src/identities/identities.ts +121 -14
  53. package/src/identities/machine.ts +4 -3
  54. package/src/identities/rating.ts +33 -0
  55. package/src/identities/shown.ts +170 -0
  56. package/src/identities/steps.ts +5 -0
  57. package/src/media-store/purge.ts +15 -1
  58. package/src/media-store/remote.ts +22 -6
  59. package/src/messages/brief.ts +117 -0
  60. package/src/messages/collection.ts +40 -0
  61. package/src/messages/model.ts +171 -0
  62. package/src/messages/routes.ts +15 -0
  63. package/src/messages/score.ts +182 -0
  64. package/src/messages/tabs.ts +13 -0
  65. package/src/release/notes.ts +130 -0
  66. package/src/release/run-bump.ts +41 -18
  67. package/src/release/run-release.ts +22 -4
  68. package/src/release/run-releases.ts +17 -15
  69. package/src/release/unit-resolve.ts +9 -0
  70. package/src/releases/add.ts +94 -0
  71. package/src/releases/before.ts +31 -0
  72. package/src/releases/collection.ts +36 -0
  73. package/src/releases/from-card.ts +151 -0
  74. package/src/releases/model.ts +327 -0
  75. package/src/releases/pictures.ts +110 -0
  76. package/src/releases/routes.ts +36 -0
  77. package/src/releases/store.ts +71 -0
  78. package/src/repo-config.ts +5 -0
  79. package/src/review/cells.ts +0 -11
  80. package/src/review/format.ts +10 -6
  81. package/src/review/http.ts +1 -1
  82. package/src/review/model.ts +102 -3
  83. package/src/review/notes.ts +2 -48
  84. package/src/review/routes.ts +28 -10
  85. package/src/review/stage-card.ts +197 -0
  86. package/src/review/stage-routes.ts +123 -0
  87. package/src/review/store.ts +47 -1
  88. package/src/review/trailer-card.ts +99 -0
  89. package/src/review/trailer-desk.ts +76 -4
  90. package/src/review/trailer-model.ts +106 -7
  91. package/src/review/trailer-notes.ts +45 -0
  92. package/src/review/trailer-routes.ts +119 -13
  93. package/src/review/trailer-voices.ts +144 -0
  94. package/src/review/watchers.ts +58 -1
  95. package/src/serve/hub-app/app-bridge.ts +71 -0
  96. package/src/serve/hub-app/benign-errors.ts +22 -0
  97. package/src/serve/hub-app/commands/commands-page.tsx +122 -0
  98. package/src/serve/hub-app/commands/commands-st.ts +177 -0
  99. package/src/serve/hub-app/commands.css +24 -0
  100. package/src/serve/hub-app/hash-route.ts +59 -8
  101. package/src/serve/hub-app/home-st.ts +19 -2
  102. package/src/serve/hub-app/home.html +3 -0
  103. package/src/serve/hub-app/hub-app.tsx +8 -0
  104. package/src/serve/hub-app/icons.tsx +5 -0
  105. package/src/serve/hub-app/identities-view.tsx +4 -1
  106. package/src/serve/hub-app/identities.css +1 -0
  107. package/src/serve/hub-app/index.html +3 -0
  108. package/src/serve/hub-app/keys.ts +2 -2
  109. package/src/serve/hub-app/machine-st.ts +41 -10
  110. package/src/serve/hub-app/messages/messages-page.tsx +354 -0
  111. package/src/serve/hub-app/messages/messages-st.ts +74 -0
  112. package/src/serve/hub-app/messages.css +35 -0
  113. package/src/serve/hub-app/project-list.css +7 -2
  114. package/src/serve/hub-app/project-list.tsx +9 -0
  115. package/src/serve/hub-app/projects-svc.ts +16 -6
  116. package/src/serve/hub-app/releases/releases-page.tsx +187 -0
  117. package/src/serve/hub-app/releases/releases-st.ts +111 -0
  118. package/src/serve/hub-app/releases.css +52 -0
  119. package/src/serve/hub-app/repo-sections.ts +16 -2
  120. package/src/serve/hub-app/repo-st.ts +66 -10
  121. package/src/serve/hub-app/review/clip-st.ts +34 -4
  122. package/src/serve/hub-app/review/kit.tsx +3 -3
  123. package/src/serve/hub-app/review/note-place.ts +31 -0
  124. package/src/serve/hub-app/review/review-cells.tsx +27 -3
  125. package/src/serve/hub-app/review/review-st.ts +77 -2
  126. package/src/serve/hub-app/review/review-thread.tsx +9 -31
  127. package/src/serve/hub-app/review/review-views.tsx +164 -58
  128. package/src/serve/hub-app/review/thread-st.ts +108 -41
  129. package/src/serve/hub-app/review/trailer-card.tsx +187 -0
  130. package/src/serve/hub-app/review/trailer-page.tsx +92 -36
  131. package/src/serve/hub-app/review/trailer-st.ts +306 -34
  132. package/src/serve/hub-app/review/trailer-timeline.tsx +68 -23
  133. package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
  134. package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
  135. package/src/serve/hub-app/review.css +137 -6
  136. package/src/serve/hub-app/social/comms-page.tsx +65 -28
  137. package/src/serve/hub-app/social/identity-pictures.ts +46 -8
  138. package/src/serve/hub-app/social/kit.tsx +9 -6
  139. package/src/serve/hub-app/social/next-release.tsx +118 -0
  140. package/src/serve/hub-app/social/post-card.tsx +10 -2
  141. package/src/serve/hub-app/social/social-model.ts +39 -3
  142. package/src/serve/hub-app/social/social-page.tsx +179 -65
  143. package/src/serve/hub-app/social/social-st.ts +117 -27
  144. package/src/serve/hub-app/social/stage-popup.tsx +268 -0
  145. package/src/serve/hub-app/social/stage-st.ts +310 -0
  146. package/src/serve/hub-app/social/step-layout.ts +42 -0
  147. package/src/serve/hub-app/social.css +68 -1
  148. package/src/serve/hub-app/tree-build.ts +40 -1
  149. package/src/serve/hub-app/tree-svc.ts +10 -3
  150. package/src/serve/project-gutter-route.ts +12 -2
  151. package/src/serve/project-gutter.ts +4 -2
  152. package/src/serve/same-origin.ts +24 -1
  153. package/src/serve/serve-hub.ts +15 -1
  154. package/src/shipkit-files.ts +9 -7
  155. package/src/shot/box.ts +33 -12
  156. package/src/shot/client.ts +1 -1
  157. package/src/shot/shooter.ts +22 -12
  158. package/src/shot/shot-ask.ts +14 -3
  159. package/src/shot/shot.shipkit.ts +1 -1
  160. package/src/social/desk-index.ts +49 -8
  161. package/src/social/discord-layout.ts +54 -7
  162. package/src/social/drafts.ts +1 -1
  163. package/src/social/fit.ts +84 -0
  164. package/src/social/identity-words.ts +74 -0
  165. package/src/social/kind-pages.ts +41 -0
  166. package/src/social/kinds.ts +93 -0
  167. package/src/social/load.ts +125 -10
  168. package/src/social/media-limit.ts +63 -2
  169. package/src/social/presence.ts +1 -1
  170. package/src/social/publish/bluesky.ts +58 -19
  171. package/src/social/publish/index.ts +47 -6
  172. package/src/social/reach.ts +49 -0
  173. package/src/social/release-stage.ts +277 -0
  174. package/src/social/routes.ts +44 -8
  175. package/src/social/stage.ts +246 -0
  176. package/src/social/strip.ts +85 -0
  177. package/src/social/text.ts +6 -2
  178. package/src/social/unit.ts +57 -1
  179. package/src/social/writes.ts +11 -0
  180. package/src/trailer/bed.ts +111 -0
  181. package/src/trailer/build.ts +72 -40
  182. package/src/trailer/ffmpeg.ts +6 -0
  183. package/src/trailer/grammar.ts +37 -6
  184. package/src/trailer/graph.ts +12 -1
  185. package/src/trailer/public-words.ts +41 -0
  186. package/src/trailer/shot-plan.ts +75 -0
  187. package/src/trailer/shot-state.ts +191 -0
  188. package/src/trailer/sound/audio.ts +28 -0
  189. package/src/trailer/sound/brand.ts +53 -3
  190. package/src/trailer/sound/gen.ts +61 -2
  191. package/src/trailer/sound/index.ts +25 -11
  192. package/src/trailer/sound/presets.ts +86 -5
  193. package/src/trailer/sound/run.ts +1 -1
  194. package/src/trailer/sound/takes.ts +94 -0
  195. package/src/trailer/titles.ts +36 -0
  196. package/src/trailer/url.ts +1 -1
@@ -10,9 +10,11 @@
10
10
  // port directly, and lets this door through. The host guard runs here too: Bun's dev server, which bundles the page
11
11
  // and drives its hot reload, answers only to a loopback Host, so it sits on a port of its own behind this one, and a
12
12
  // request reaches it only once its Host is a loopback name or the tailnet name the house declares (serve.publicHost)
13
- import { sameOrigin } from '../serve/same-origin.ts'
13
+ import { hostName, loopbackName, REACH_HEADER, reachOfHost, sameOrigin } from '../serve/same-origin.ts'
14
14
  import { hubBase } from './home-paths.ts'
15
15
  import { forwardPage, pagePath } from '../pages/forward.ts'
16
+ import { statSync } from 'fs'
17
+ import { HMR_BEAT_MS, HMR_KEEP_SCRIPT, HMR_WORDS } from './hmr-keep.ts'
16
18
 
17
19
  /** the page routes: ONE app for the overview, the plan, and the hub page of
18
20
  * each known repo, which moves between them in place (home-st.ts) */
@@ -62,20 +64,14 @@ export const readsGit = (path: string): boolean => path === '/api/home/activity.
62
64
  /** a run or a check run streams for minutes, and a silent one is never cut */
63
65
  export const streams = (path: string): boolean => /\/api\/(run|check\/run)$/.test(path)
64
66
 
65
- /** a Host header's name: its port, brackets and trailing dot gone, lowercase */
66
- export function hostName(host: string): string {
67
- const h = host.trim().toLowerCase()
68
- const name = h.startsWith('[') ? h.slice(1, h.indexOf(']') < 0 ? undefined : h.indexOf(']')) : h.replace(/:\d+$/, '')
69
- return name.replace(/\.$/, '')
70
- }
67
+ export { hostName }
71
68
 
72
69
  /** the names a browser may reach the home by: this machine's loopback names, and the tailnet names the house
73
70
  * declares. Any other name is a page of another site resolved to this machine (DNS rebinding), and is refused */
74
71
  export function hostAllowed(host: string | null, names: ReadonlySet<string>): boolean {
75
72
  if (host == null || host === '') return false
76
73
  const n = hostName(host)
77
- if (n === 'localhost' || n.endsWith('.localhost') || n === '::1' || /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(n)) return true
78
- return names.has(n)
74
+ return loopbackName(n) || names.has(n)
79
75
  }
80
76
 
81
77
  export const hostRefusedText = (host: string | null): string =>
@@ -101,6 +97,7 @@ export const MANIFEST = {
101
97
  * page's file as a file to bundle, and these name routes of this server */
102
98
  export const APP_HEAD = [
103
99
  '<link rel="manifest" href="/manifest.webmanifest">',
100
+ '<link rel="icon" type="image/png" sizes="192x192" href="/api/home/icon/192.png">',
104
101
  '<link rel="apple-touch-icon" href="/api/home/icon/180.png">',
105
102
  '<meta name="apple-mobile-web-app-capable" content="yes">',
106
103
  '<meta name="mobile-web-app-capable" content="yes">',
@@ -108,8 +105,29 @@ export const APP_HEAD = [
108
105
  '<meta name="apple-mobile-web-app-title" content="shipkit">',
109
106
  `<meta name="theme-color" media="(prefers-color-scheme: dark)" content="${THEME.dark}">`,
110
107
  `<meta name="theme-color" media="(prefers-color-scheme: light)" content="${THEME.light}">`,
108
+ HMR_KEEP_SCRIPT,
111
109
  ].join('')
112
110
 
111
+ /** the head this web serves, as a page that came back compares it: the head is this file's code, not a page file */
112
+ export const HEAD_STAMP = Bun.hash(APP_HEAD).toString(36)
113
+
114
+ /** a write this close before the stamp may not have reached the page yet (the dev server rebuilds, then pushes): it
115
+ * counts as moved, a rare reload that means nothing rather than a page left stale */
116
+ export const MOVED_MARGIN_MS = 1_000
117
+
118
+ /** whether a file of the page moved after `since` (this machine's clock), a file gone included: a page back on the
119
+ * hot reload socket after a gap is current only when none did (hmr-keep.ts) */
120
+ export function pageMovedSince(files: Iterable<string>, since: number, mtimeOf: (f: string) => number = (f) => statSync(f).mtimeMs): boolean {
121
+ for (const f of files) {
122
+ try {
123
+ if (mtimeOf(f) > since - MOVED_MARGIN_MS) return true
124
+ } catch {
125
+ return true
126
+ }
127
+ }
128
+ return false
129
+ }
130
+
113
131
  /** a page file the web gzips for a browser that takes it: the dev bundle is megabytes of text */
114
132
  const ZIPS = /^(text\/|application\/(javascript|json)|image\/svg)/
115
133
  /** the gzipped bodies kept, by path and etag: the bundle changes on an edit, not on a request */
@@ -181,10 +199,14 @@ export type WebDeps<T> = {
181
199
  hosts?: string[]
182
200
  /** in place of STALE_AFTER_MS (a test) */
183
201
  staleAfterMs?: number
202
+ /** the files of the page's bundle: a page back on the hot reload socket after a gap reloads only when one moved.
203
+ * Without them it always reloads */
204
+ pageFiles?: () => Iterable<string>
184
205
  }
185
206
 
186
- /** one browser socket to the page server's hot reload, piped to the same path there */
187
- type Pipe = { path: string; up: WebSocket | null; queue: (string | Uint8Array<ArrayBuffer>)[] }
207
+ /** one browser socket to the page server's hot reload, piped to the same path there. `since`: the last time a socket
208
+ * that came back heard this web, null on a page's first socket */
209
+ type Pipe = { path: string; up: WebSocket | null; queue: (string | Uint8Array<ArrayBuffer>)[]; since: number | null }
188
210
 
189
211
  export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
190
212
  let known = ''
@@ -229,6 +251,8 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
229
251
  async function forward(req: Request, url: URL, srv: Bun.Server<Pipe>, key: string | null): Promise<Response> {
230
252
  const headers = new Headers()
231
253
  req.headers.forEach((v, k) => { if (!DROP.has(k)) headers.set(k, v) })
254
+ // set after the copy, so a value the browser sent never passes
255
+ headers.set(REACH_HEADER, reachOfHost(req.headers.get('host')))
232
256
  // a run or a live stream can stay silent for minutes
233
257
  srv.timeout(req, 0)
234
258
  const body = req.method === 'GET' || req.method === 'HEAD' ? undefined : await req.arrayBuffer()
@@ -291,6 +315,15 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
291
315
  const notFound = (): Response => new Response('not found: the home page is at /', { status: 404 })
292
316
  const inner = Bun.serve({ port: 0, hostname: '127.0.0.1', routes: pageRoutes([], d.page), fetch: notFound })
293
317
  const innerAt = `127.0.0.1:${inner.port}`
318
+ // a dev server pushes an edit only once it bundled the page: asked here, a page that came back to a restarted web
319
+ // without reloading gets the next edit
320
+ void fetch(`http://${innerAt}/`).then((r) => r.body?.cancel()).catch(() => {})
321
+ /** the browsers' hot reload sockets, each stamped with this web's time every HMR_BEAT_MS */
322
+ const hmrSockets = new Set<Bun.ServerWebSocket<Pipe>>()
323
+ const beats = setInterval(() => {
324
+ const beat = `${HMR_WORDS.beat}${Date.now()}`
325
+ for (const ws of hmrSockets) ws.send(beat)
326
+ }, HMR_BEAT_MS)
294
327
 
295
328
  /** a page request handed to the page server as a loopback request, its answer gzipped for a browser that takes
296
329
  * it, the page itself given the app's head */
@@ -334,9 +367,14 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
334
367
  if (!hostAllowed(host, hosts)) return new Response(hostRefusedText(host), { status: 403, headers: { 'content-type': 'text/plain; charset=utf-8' } })
335
368
  const url = new URL(req.url)
336
369
  const path = url.pathname
337
- if (path === '/_bun/hmr' && req.headers.get('upgrade')?.toLowerCase() === 'websocket')
338
- return srv.upgrade(req, { data: { path: `${path}${url.search}`, up: null, queue: [] } }) ? undefined : new Response('the hot reload socket did not open', { status: 400 })
370
+ if (path === '/_bun/hmr' && req.headers.get('upgrade')?.toLowerCase() === 'websocket') {
371
+ const since = url.searchParams.get('since')
372
+ url.searchParams.delete('since')
373
+ return srv.upgrade(req, { data: { path: `${path}${url.search}`, up: null, queue: [], since: since == null ? null : Number(since) } }) ? undefined : new Response('the hot reload socket did not open', { status: 400 })
374
+ }
339
375
  if (path === '/manifest.webmanifest') return Response.json(MANIFEST, { headers: { 'content-type': 'application/manifest+json', 'cache-control': 'no-cache' } })
376
+ // a browser asks it before it reads the head, and so does a page the head never reached (an error page)
377
+ if (path === '/favicon.ico') return new Response(null, { status: 302, headers: { location: '/api/home/icon/192.png', 'cache-control': 'max-age=86400' } })
340
378
  const page = /^\/r\/([^/]+)(\/page\/.+)$/.exec(path)
341
379
  if (page != null) {
342
380
  const direct = await toPageProcess(req, decodeURIComponent(page[1]!), page[2]!, srv)
@@ -367,13 +405,23 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
367
405
  fetch: fetchFn,
368
406
  websocket: {
369
407
  open(ws) {
408
+ hmrSockets.add(ws)
409
+ ws.send(`${HMR_WORDS.beat}${Date.now()}`)
410
+ ws.send(`${HMR_WORDS.head}${HEAD_STAMP}`)
411
+ // said before the page server's version message, which the page's script holds back on fresh
412
+ const since = ws.data.since
413
+ if (since != null) ws.send(Number.isFinite(since) && d.pageFiles != null && !pageMovedSince(d.pageFiles(), since) ? HMR_WORDS.fresh : HMR_WORDS.moved)
370
414
  const up = new WebSocket(`ws://${innerAt}${ws.data.path}`)
371
415
  up.binaryType = 'arraybuffer'
372
416
  ws.data.up = up
373
417
  up.onopen = () => {
374
418
  for (const m of ws.data.queue.splice(0)) up.send(m)
375
419
  }
376
- up.onmessage = (e) => ws.send(e.data as string | ArrayBuffer)
420
+ // stamped after each message too: an edit the page got as a hot swap a while ago never reads as missed
421
+ up.onmessage = (e) => {
422
+ ws.send(e.data as string | ArrayBuffer)
423
+ ws.send(`${HMR_WORDS.beat}${Date.now()}`)
424
+ }
377
425
  up.onclose = () => ws.close()
378
426
  up.onerror = () => ws.close()
379
427
  },
@@ -384,6 +432,7 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
384
432
  else ws.data.queue.push(msg)
385
433
  },
386
434
  close(ws) {
435
+ hmrSockets.delete(ws)
387
436
  ws.data.up?.close()
388
437
  },
389
438
  },
@@ -416,6 +465,7 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
416
465
  stop: () => {
417
466
  stopped = true
418
467
  if (listTimer != null) clearTimeout(listTimer)
468
+ clearInterval(beats)
419
469
  server.stop(true)
420
470
  inner.stop(true)
421
471
  },
@@ -0,0 +1,49 @@
1
+ // the pictures his hands still have to upload and the texts to paste again, as needs (wiki
2
+ // tools/shipkit/social-identities.md, What each account shows): one row an online account whose rows no api sets and
3
+ // that do not show what the folder holds now. Listed in the house repo alone, where the identities live, so no repo
4
+ // says it twice
5
+ import { existsSync } from 'node:fs'
6
+ import { join } from 'node:path'
7
+ import { type Collection, type Instance } from '../collections/collection-types.ts'
8
+ import { LAYOUT } from '../core/layout.ts'
9
+ import { DEFAULT_HOME_PORT } from '../home/home-paths.ts'
10
+ import { identityAddress } from '../serve/hub-app/identity-address.ts'
11
+ import { readIdentities, type Identities } from './identities.ts'
12
+
13
+ export const PICTURES_COL = 'pictures'
14
+
15
+ /** one row an online account with a stale row for his hands */
16
+ export function pictureNeeds(ids: Identities, home = `http://127.0.0.1:${DEFAULT_HOME_PORT}`): Instance[] {
17
+ const out: Instance[] = []
18
+ for (const i of ids.identities)
19
+ for (const a of i.accounts) {
20
+ const stale = a.uploads.filter((u) => u.stale && u.by == null)
21
+ if (a.live === '' || stale.length === 0) continue
22
+ const where = `${home}${identityAddress({ id: i.id, part: a.id, place: null })}`
23
+ const lines = stale.map((u) =>
24
+ u.kind === 'text'
25
+ ? `- **${u.field}**: its text changed since it was pasted on ${u.shown?.on ?? '?'}: paste it again`
26
+ : `- **${u.field}**: ${u.files[0]}${u.shown == null ? ', what it shows is unknown' : `, it shows ${u.shown.file} as of ${u.shown.on} (sha ${u.shown.sha})`}`,
27
+ )
28
+ out.push({
29
+ id: `pictures:${i.id}/${a.id}`,
30
+ text: `update ${i.name}'s ${stale.map((u) => u.field).join(', ')} on ${a.name}`,
31
+ label: `${i.name} on ${a.name}: ${stale.map((u) => u.field).join(', ')}`,
32
+ slot: 'pictures',
33
+ type: 'ask',
34
+ path: `${PICTURES_COL}/${i.id}/${a.id}`,
35
+ virtual: true,
36
+ severity: 'red',
37
+ href: where,
38
+ md: [`${a.name} (${a.live}) does not show these rows of ${i.name} as the folder holds them now:`, '', ...lines, '', `Upload or paste each one, then click « Done, uploaded » or « Done, pasted » beside it: ${where}`].join('\n'),
39
+ })
40
+ }
41
+ return out
42
+ }
43
+
44
+ /** only in the repo that holds the identities folder, the house repo */
45
+ export function picturesCollection(root: string): Collection | null {
46
+ const dir = join(root, LAYOUT.identities)
47
+ if (!existsSync(dir)) return null
48
+ return { id: PICTURES_COL, title: 'pictures', kind: 'ask', media: 'text', list: async () => pictureNeeds(readIdentities(dir)) }
49
+ }
@@ -6,6 +6,9 @@ import { homedir } from 'node:os'
6
6
  import { isAbsolute, join } from 'node:path'
7
7
  import { LAYOUT } from '../core/layout.ts'
8
8
  import { parseFrontmatter, rows, section, table, type ProfileRow } from '../social/md.ts'
9
+ import { ceilingOf, type PostRating } from './rating.ts'
10
+ import { uploadsOf, type Upload } from './shown.ts'
11
+ import { stepRefs } from './steps.ts'
9
12
 
10
13
  const SLUG = /^[a-z0-9-]+$/
11
14
 
@@ -23,12 +26,36 @@ export type Place = {
23
26
  when: string
24
27
  /** the label a post there must carry */
25
28
  flair: string
29
+ /** the most a post there may show (`posts:`); unset, `safe` */
30
+ ceiling: PostRating
26
31
  /** absolute */
27
32
  file: string
28
33
  rules: string
29
34
  notes: string
30
35
  }
31
36
 
37
+ /** a venue's media limits, `limits: image 5 MB, video 512 MB 140 s`: bytes and seconds, each unset when unknown */
38
+ export type MediaLimits = { imageBytes?: number; videoBytes?: number; videoSeconds?: number }
39
+
40
+ /** `limits:` read; a part it cannot read is an error at its file */
41
+ export function limitsOf(v: string | undefined, file: string, errors: string[]): MediaLimits {
42
+ const out: MediaLimits = {}
43
+ for (const part of (v ?? '').split(',').map((x) => x.trim()).filter(Boolean)) {
44
+ const m = /^(image|video) (\d+(?:\.\d+)?) MB(?: (\d+) s)?$/.exec(part)
45
+ if (m == null || (m[1] === 'image' && m[3] != null)) {
46
+ errors.push(`${file}: limits "${part}" is not "image <n> MB" or "video <n> MB [<n> s]"`)
47
+ continue
48
+ }
49
+ const bytes = Math.round(Number(m[2]) * 1e6)
50
+ if (m[1] === 'image') out.imageBytes = bytes
51
+ else {
52
+ out.videoBytes = bytes
53
+ if (m[3] != null) out.videoSeconds = Number(m[3])
54
+ }
55
+ }
56
+ return out
57
+ }
58
+
32
59
  /** a `## Setup` step: one bullet of the checklist */
33
60
  export type Step = { text: string; done: boolean }
34
61
 
@@ -45,6 +72,8 @@ export type Account = {
45
72
  write: string
46
73
  inbox: string
47
74
  stats: string
75
+ /** the page where its profile is edited (the name, the bio, the avatar) */
76
+ settings: string
48
77
  max: number | null
49
78
  /** the field a message's text goes in: description, comment; empty, the post's own text */
50
79
  text: string
@@ -60,6 +89,12 @@ export type Account = {
60
89
  secret: string
61
90
  /** Discord: the server's id, its messages' links and the bot's posts */
62
91
  guild: string
92
+ /** the most a post on its own profile (the place `me`) may show (`posts:`); unset, `safe` */
93
+ ceiling: PostRating
94
+ /** the venue's own switch a rated post needs, said on its card (X: « mark the media sensitive »); empty, none */
95
+ sensitive: string
96
+ /** the media a post there may carry (`limits:`); empty, none known */
97
+ limits: MediaLimits
63
98
  /** absolute */
64
99
  file: string
65
100
  dir: string
@@ -69,10 +104,26 @@ export type Account = {
69
104
  steps: Step[]
70
105
  notes: string
71
106
  places: Place[]
107
+ /** its picture rows and what it shows of each (shown.md) */
108
+ uploads: Upload[]
72
109
  }
73
110
 
74
111
  /** one picture: the file shown, its size, and the same picture in its other formats (an svg beside its png) */
75
- export type Picture = { file: string; w: number | null; h: number | null; also: string[] }
112
+ export type Picture = {
113
+ file: string
114
+ w: number | null
115
+ h: number | null
116
+ also: string[]
117
+ /** each of its files (shown and also) by its version, which moves when its bytes do: a url carries it, so a page
118
+ * never keeps an old picture under a url that stayed the same */
119
+ v: Record<string, string>
120
+ }
121
+
122
+ /** a file's version: its size and mtime, '' when it is gone; cheap, so every answer computes it fresh */
123
+ export function pictureVersion(abs: string): string {
124
+ const st = statSync(abs, { throwIfNoEntry: false })
125
+ return st == null ? '' : `${st.size.toString(36)}-${Math.round(st.mtimeMs).toString(36)}`
126
+ }
76
127
 
77
128
  /** a company as the forms ask it: `legal.md`, and the private rows of the gitignored `legal.local.md` */
78
129
  export type Legal = {
@@ -87,6 +138,8 @@ export type Identity = {
87
138
  order: number
88
139
  /** it speaks for a repo that names none */
89
140
  default: boolean
141
+ /** an adult (18+) voice (`adult: true`): every draft names its rating, and the stage popup picks none for him */
142
+ adult: boolean
90
143
  site: string
91
144
  siteRepo: string
92
145
  /** the folder its picture paths are relative to, absolute: its `files`, else its own folder */
@@ -135,6 +188,26 @@ function merged(shared: ProfileRow[], own: ProfileRow[]): ProfileRow[] {
135
188
  return [...shared.map((r) => mine.get(r.field) ?? r), ...own.filter((r) => !shared.some((s) => s.field === r.field))]
136
189
  }
137
190
 
191
+ /** a text row's value as he pastes it: `[[field]]` the other row's value, `<br>` a new line (a table cell holds none),
192
+ * so a venue's text says the bio once, never « the bio » in words */
193
+ export function filledRows(list: ProfileRow[], file: string, errors: string[]): ProfileRow[] {
194
+ const by = new Map(list.map((r) => [r.field, r]))
195
+ return list.map((r) => {
196
+ if (r.files.length > 0 || !/\[\[|<br>/.test(r.value)) return r
197
+ const value = r.value
198
+ .replace(/\[\[([^\]]+)\]\]/g, (all, f: string) => {
199
+ const at = by.get(f)
200
+ if (at == null || at === r || /\[\[/.test(at.value)) {
201
+ errors.push(`${file}: row ${r.field} names [[${f}]], ${at == null ? 'no row' : 'a row that names another'}`)
202
+ return all
203
+ }
204
+ return at.value
205
+ })
206
+ .replace(/\s*<br>\s*/g, '\n')
207
+ return { ...r, value }
208
+ })
209
+ }
210
+
138
211
  function places(dir: string, errors: string[]): Place[] {
139
212
  const at = join(dir, 'places')
140
213
  if (!existsSync(at)) return []
@@ -158,6 +231,7 @@ function places(dir: string, errors: string[]): Place[] {
158
231
  write: meta.write ?? '',
159
232
  when: meta.when ?? '',
160
233
  flair: meta.flair ?? '',
234
+ ceiling: ceilingOf(meta.posts, abs, errors),
161
235
  file: abs,
162
236
  rules: section(body, 'Rules') ?? '',
163
237
  notes: section(body, 'Notes') ?? '',
@@ -204,8 +278,10 @@ function imageSize(abs: string): { w: number | null; h: number | null } {
204
278
  const SHOWN = ['jpg', 'png', 'webp', 'mp4', 'svg']
205
279
  /** the identity's own folder of pictures, listed first whether `pictures` names it or not */
206
280
  const OWN = 'pictures'
281
+ /** its folders by kind; its other folders (src, art, fonts, candidates) are how they are made, never listed */
282
+ const KINDS = ['avatars', 'banners', 'tiers']
207
283
 
208
- /** the pictures of its own folder then of each `pictures` folder, each folder the largest first, one picture per name
284
+ /** the pictures of its own folder (and its kind folders) then of each `pictures` folder, each folder the largest first, one picture per name
209
285
  * with its other formats: a folder under `files`, or a `~/…` or absolute one elsewhere on the disk (a repo's own files
210
286
  * the identity names), its pictures named by that path */
211
287
  function pictures(files: string | null, dirs: string, file: string, errors: string[]): Picture[] {
@@ -219,15 +295,19 @@ function pictures(files: string | null, dirs: string, file: string, errors: stri
219
295
  continue
220
296
  }
221
297
  const byName = new Map<string, string[]>()
222
- for (const f of readdirSync(abs).sort()) {
223
- const m = /^(.+)\.(\w+)$/.exec(f)
224
- if (m == null || !SHOWN.includes(m[2]!)) continue
225
- byName.set(m[1]!, [...(byName.get(m[1]!) ?? []), m[2]!])
226
- }
298
+ const subs = dir === OWN ? KINDS.filter((k) => existsSync(join(abs, k))) : []
299
+ for (const sub of ['', ...subs])
300
+ for (const f of readdirSync(join(abs, sub)).sort()) {
301
+ const m = /^(.+)\.(\w+)$/.exec(f)
302
+ if (m == null || !SHOWN.includes(m[2]!)) continue
303
+ const name = sub === '' ? m[1]! : `${sub}/${m[1]!}`
304
+ byName.set(name, [...(byName.get(name) ?? []), m[2]!])
305
+ }
227
306
  const here: Picture[] = []
228
307
  for (const [name, exts] of byName) {
229
308
  const [shown, ...rest] = [...exts].sort((x, y) => SHOWN.indexOf(x) - SHOWN.indexOf(y))
230
- here.push({ file: `${dir}/${name}.${shown}`, ...imageSize(join(abs, `${name}.${shown}`)), also: rest.map((e) => `${dir}/${name}.${e}`) })
309
+ const v = Object.fromEntries([shown!, ...rest].map((e) => [`${dir}/${name}.${e}`, pictureVersion(join(abs, `${name}.${e}`))]))
310
+ here.push({ file: `${dir}/${name}.${shown}`, ...imageSize(join(abs, `${name}.${shown}`)), also: rest.map((e) => `${dir}/${name}.${e}`), v })
231
311
  }
232
312
  out.push(...here.sort((x, y) => (y.w ?? 0) * (y.h ?? 0) - (x.w ?? 0) * (x.h ?? 0)))
233
313
  }
@@ -249,6 +329,13 @@ function account(identity: string, id: string, dir: string, shared: ProfileRow[]
249
329
  const file = join(dir, 'account.md')
250
330
  const { meta, body } = parseFrontmatter(read(file))
251
331
  linkErrors(file, meta, ['profile', 'live', 'write', 'inbox', 'stats'], errors)
332
+ const own = rows(body, 'Profile', files)
333
+ errors.push(...copiedRows(own, shared, file))
334
+ const merge = filledRows(merged(shared, own), file, errors)
335
+ const automation = meta.automation ?? 'none'
336
+ const secret = meta.secret ?? ''
337
+ const guild = meta.guild ?? ''
338
+ const setup = steps(body)
252
339
  return {
253
340
  id,
254
341
  identity,
@@ -260,30 +347,49 @@ function account(identity: string, id: string, dir: string, shared: ProfileRow[]
260
347
  write: meta.write ?? '',
261
348
  inbox: meta.inbox ?? '',
262
349
  stats: meta.stats ?? '',
350
+ settings: meta.settings ?? '',
263
351
  max: meta.max ? Number(meta.max) : null,
264
352
  text: meta.text ?? '',
265
353
  group: meta.group ?? '',
266
354
  place: meta.place ?? '',
267
355
  footer: meta.footer ?? '',
268
- automation: meta.automation ?? 'none',
269
- secret: meta.secret ?? '',
270
- guild: meta.guild ?? '',
356
+ automation,
357
+ secret,
358
+ guild,
359
+ ceiling: ceilingOf(meta.posts, file, errors),
360
+ sensitive: meta.sensitive ?? '',
361
+ limits: limitsOf(meta.limits, file, errors),
271
362
  file,
272
363
  dir,
273
- rows: merged(shared, rows(body, 'Profile', files)),
364
+ rows: merge,
365
+ uploads: uploadsOf({ id, guild, secret, automation }, merge, dir, files, new Set(own.map((r) => r.field)), setup.length === 0 ? null : stepRefs(setup)),
274
366
  automationText: section(body, 'Automation') ?? '',
275
- steps: steps(body),
367
+ steps: setup,
276
368
  notes: section(body, 'Notes') ?? '',
277
369
  places: places(dir, errors),
278
370
  }
279
371
  }
280
372
 
373
+ /** the identity's texts an account's own text row copies verbatim (over 12 characters): one error line each, so a text
374
+ * lives in one place and every venue follows it (`[[field]]`, or no row at all to inherit it) */
375
+ export function copiedRows(own: readonly ProfileRow[], shared: readonly ProfileRow[], file: string): string[] {
376
+ const out: string[] = []
377
+ for (const r of own) {
378
+ if (r.files.length > 0) continue
379
+ for (const s of shared)
380
+ if (s.files.length === 0 && s.value.length > 12 && !s.value.includes('[[') && r.value.includes(s.value))
381
+ out.push(`${file}: row ${r.field} holds the identity's ${s.field} verbatim: write [[${s.field}]] there, or drop the row to inherit it`)
382
+ }
383
+ return out
384
+ }
385
+
281
386
  function identity(id: string, dir: string, errors: string[]): Identity {
282
387
  const file = join(dir, 'identity.md')
283
388
  const { meta, body } = parseFrontmatter(read(file))
284
389
  const files = meta.files ? home(meta.files) : dir
285
390
  if (!isAbsolute(files) || !existsSync(files)) errors.push(`${file}: files "${meta.files}" is no folder on this disk`)
286
- const shared = rows(body, 'Profile', files)
391
+ // filled once here, so the profile shows and copies a shared text (a tier's lines) as an account does
392
+ const shared = filledRows(rows(body, 'Profile', files), file, errors)
287
393
  const at = join(dir, 'accounts')
288
394
  const accounts: Account[] = []
289
395
  if (existsSync(at))
@@ -301,6 +407,7 @@ function identity(id: string, dir: string, errors: string[]): Identity {
301
407
  name: meta.name ?? id,
302
408
  order: Number(meta.order ?? 99),
303
409
  default: meta.default === 'true',
410
+ adult: meta.adult === 'true',
304
411
  site: meta.site ?? '',
305
412
  siteRepo: meta.siteRepo ?? '',
306
413
  files,
@@ -3,7 +3,7 @@
3
3
  // `identity.md` of the folder moves, so the list's 5 s poll costs a few stats
4
4
  import { existsSync, readdirSync, statSync } from 'node:fs'
5
5
  import { join } from 'node:path'
6
- import { readIdentities, speakerOf, type Identities, type Identity } from './identities.ts'
6
+ import { pictureVersion, readIdentities, speakerOf, type Identities, type Identity } from './identities.ts'
7
7
 
8
8
  /** one identity as a header of the project list draws it */
9
9
  export type RailIdentity = {
@@ -40,10 +40,11 @@ function folderStamp(dir: string | null): string {
40
40
  return readdirSync(dir).sort().map((id) => `${id}:${stampOf(join(dir, id, 'identity.md'))}`).join('|')
41
41
  }
42
42
 
43
- /** the url the gutter serves an identity's mark at (project-gutter-route.ts), its stamp in it */
43
+ /** the url the gutter serves an identity's mark at (project-gutter-route.ts), its version in it: read on every call,
44
+ * so a redrawn avatar moves the url even while the identity's cache holds */
44
45
  export const markUrl = (i: Identity): string | null => {
45
46
  const f = markFile(i)
46
- return f == null ? null : `/api/projects/identity-mark/${encodeURIComponent(i.id)}?v=${stampOf(f)}`
47
+ return f == null ? null : `/api/projects/identity-mark/${encodeURIComponent(i.id)}?v=${pictureVersion(f)}`
47
48
  }
48
49
 
49
50
  export const railOf = (i: Identity): RailIdentity => ({ id: i.id, name: i.name, default: i.default, colour: colourOf(i), mark: markUrl(i) })
@@ -0,0 +1,33 @@
1
+ // an account's rating (wiki tools/shipkit/social-identities.md): its `rating` row names the pictures it shows, `sfw` or
2
+ // `nsfw`, and a row for the other one (`avatar nsfw` on an sfw account) is not its. Pure: the hub's bundle reads it too
3
+
4
+ export const RATINGS: readonly string[] = ['sfw', 'nsfw']
5
+
6
+ /** the `rating` row's first word: `sfw`, `nsfw`, or '' when it names none */
7
+ export const ratingIn = (rows: readonly { field: string; value: string }[]): string => (rows.find((r) => r.field === 'rating')?.value.trim().split(/\s/)[0] ?? '').toLowerCase()
8
+
9
+ /** a row for the other rating, `avatar nsfw` on an sfw account: not this venue's */
10
+ export function otherRating(field: string, rating: string): boolean {
11
+ const last = field.trim().split(/\s+/).pop() ?? ''
12
+ return rating !== '' && RATINGS.includes(last) && last !== rating
13
+ }
14
+
15
+ /** what a post shows, and what a place takes (wiki tools/shipkit/social-identities.md, The accounts): `safe` no nudity,
16
+ * `mild` nudity never explicit, `explicit` the rest. A place takes a post rated at most its own */
17
+ export const POST_RATINGS = ['safe', 'mild', 'explicit'] as const
18
+ export type PostRating = (typeof POST_RATINGS)[number]
19
+
20
+ export const isPostRating = (v: string): v is PostRating => (POST_RATINGS as readonly string[]).includes(v)
21
+
22
+ /** a place whose ceiling is `ceiling` takes a post rated `r` */
23
+ export const takes = (ceiling: PostRating, r: PostRating): boolean => POST_RATINGS.indexOf(r) <= POST_RATINGS.indexOf(ceiling)
24
+
25
+ /** a `posts:` value read: absent is `safe`, so a place nobody rated takes nothing rated (fail closed); a bad word is an
26
+ * error at its file and reads `safe` too */
27
+ export function ceilingOf(v: string | undefined, file: string, errors: string[]): PostRating {
28
+ const w = (v ?? '').trim()
29
+ if (w === '') return 'safe'
30
+ if (isPostRating(w)) return w
31
+ errors.push(`${file}: posts "${w}" is not ${POST_RATINGS.join(', ')}`)
32
+ return 'safe'
33
+ }