rvlib-shipkit 2.18.0 → 2.20.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 (186) hide show
  1. package/CHANGELOG.md +31 -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/asks/asks-queue.ts +63 -10
  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_Asks.ts +3 -1
  11. package/src/cli/cmd_Commands.ts +4 -1
  12. package/src/cli/cmd_GlobalProcesses.ts +34 -11
  13. package/src/cli/cmd_Home.ts +41 -4
  14. package/src/cli/cmd_Messages.ts +155 -0
  15. package/src/cli/cmd_Releases.ts +48 -0
  16. package/src/cli/cmd_Review.ts +161 -6
  17. package/src/cli/cmd_Secret.ts +4 -30
  18. package/src/cli/cmd_Shot.ts +4 -4
  19. package/src/cli/cmd_Social.ts +179 -3
  20. package/src/cli/cmd_Trailer.ts +15 -3
  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 +8 -2
  25. package/src/collections/actions.ts +29 -1
  26. package/src/collections/collection-types.ts +10 -1
  27. package/src/collections/providers.ts +5 -2
  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 +5 -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 +302 -5
  41. package/src/home/gui-app.ts +63 -33
  42. package/src/home/hmr-keep.ts +134 -0
  43. package/src/home/home-paths.ts +5 -1
  44. package/src/home/home-start.ts +14 -14
  45. package/src/home/lib-watch.ts +21 -11
  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-daemon.ts +11 -2
  50. package/src/home/run-pm.ts +9 -1
  51. package/src/home/run-web.ts +7 -4
  52. package/src/home/serve-web.ts +64 -14
  53. package/src/home/supervise.ts +3 -1
  54. package/src/identities/collection.ts +49 -0
  55. package/src/identities/identities.ts +130 -11
  56. package/src/identities/machine.ts +4 -3
  57. package/src/identities/rating.ts +33 -0
  58. package/src/identities/shown.ts +170 -0
  59. package/src/identities/steps.ts +5 -0
  60. package/src/media-store/purge.ts +15 -1
  61. package/src/media-store/remote.ts +22 -6
  62. package/src/messages/brief.ts +117 -0
  63. package/src/messages/collection.ts +40 -0
  64. package/src/messages/model.ts +171 -0
  65. package/src/messages/routes.ts +15 -0
  66. package/src/messages/score.ts +180 -0
  67. package/src/messages/tabs.ts +13 -0
  68. package/src/release/notes.ts +130 -0
  69. package/src/release/run-bump.ts +41 -18
  70. package/src/release/run-release.ts +22 -4
  71. package/src/release/run-releases.ts +17 -15
  72. package/src/release/unit-resolve.ts +9 -0
  73. package/src/releases/add.ts +66 -0
  74. package/src/releases/collection.ts +36 -0
  75. package/src/releases/from-card.ts +66 -0
  76. package/src/releases/model.ts +267 -0
  77. package/src/releases/pictures.ts +89 -0
  78. package/src/releases/routes.ts +36 -0
  79. package/src/releases/store.ts +71 -0
  80. package/src/repo-config.ts +5 -0
  81. package/src/review/cells.ts +0 -11
  82. package/src/review/format.ts +10 -6
  83. package/src/review/http.ts +7 -2
  84. package/src/review/model.ts +92 -3
  85. package/src/review/notes.ts +2 -48
  86. package/src/review/routes.ts +28 -10
  87. package/src/review/stage-card.ts +197 -0
  88. package/src/review/stage-routes.ts +123 -0
  89. package/src/review/store.ts +117 -19
  90. package/src/review/trailer-card.ts +99 -0
  91. package/src/review/trailer-desk.ts +57 -4
  92. package/src/review/trailer-model.ts +41 -7
  93. package/src/review/trailer-notes.ts +45 -0
  94. package/src/review/trailer-routes.ts +22 -13
  95. package/src/secrets/manager.ts +59 -0
  96. package/src/secrets/name.ts +2 -0
  97. package/src/serve/hub-app/app-bridge.ts +71 -0
  98. package/src/serve/hub-app/col-card.tsx +10 -0
  99. package/src/serve/hub-app/cols-svc.ts +37 -6
  100. package/src/serve/hub-app/commands/commands-page.tsx +122 -0
  101. package/src/serve/hub-app/commands/commands-st.ts +177 -0
  102. package/src/serve/hub-app/commands.css +24 -0
  103. package/src/serve/hub-app/hash-route.ts +40 -1
  104. package/src/serve/hub-app/home-st.ts +11 -2
  105. package/src/serve/hub-app/home.html +3 -0
  106. package/src/serve/hub-app/hub-app.tsx +6 -0
  107. package/src/serve/hub-app/hub.css +1 -0
  108. package/src/serve/hub-app/icons.tsx +5 -0
  109. package/src/serve/hub-app/identities-view.tsx +4 -1
  110. package/src/serve/hub-app/identities.css +1 -0
  111. package/src/serve/hub-app/index.html +3 -0
  112. package/src/serve/hub-app/keys.ts +2 -2
  113. package/src/serve/hub-app/machine-st.ts +41 -10
  114. package/src/serve/hub-app/messages/messages-page.tsx +354 -0
  115. package/src/serve/hub-app/messages/messages-st.ts +74 -0
  116. package/src/serve/hub-app/messages.css +35 -0
  117. package/src/serve/hub-app/releases/releases-page.tsx +94 -0
  118. package/src/serve/hub-app/releases/releases-st.ts +69 -0
  119. package/src/serve/hub-app/releases.css +25 -0
  120. package/src/serve/hub-app/repo-sections.ts +15 -1
  121. package/src/serve/hub-app/repo-st.ts +56 -5
  122. package/src/serve/hub-app/review/clip-st.ts +31 -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 +62 -31
  131. package/src/serve/hub-app/review/trailer-st.ts +138 -26
  132. package/src/serve/hub-app/review/trailer-timeline.tsx +39 -26
  133. package/src/serve/hub-app/review.css +49 -6
  134. package/src/serve/hub-app/social/comms-page.tsx +55 -23
  135. package/src/serve/hub-app/social/identity-pictures.ts +112 -0
  136. package/src/serve/hub-app/social/kit.tsx +9 -6
  137. package/src/serve/hub-app/social/post-card.tsx +10 -2
  138. package/src/serve/hub-app/social/social-model.ts +37 -3
  139. package/src/serve/hub-app/social/social-page.tsx +236 -82
  140. package/src/serve/hub-app/social/social-st.ts +79 -26
  141. package/src/serve/hub-app/social/stage-popup.tsx +268 -0
  142. package/src/serve/hub-app/social/stage-st.ts +310 -0
  143. package/src/serve/hub-app/social/step-layout.ts +42 -0
  144. package/src/serve/hub-app/social.css +68 -4
  145. package/src/serve/hub-app/tree-build.ts +38 -1
  146. package/src/serve/hub-app/tree-svc.ts +10 -3
  147. package/src/serve/project-gutter-route.ts +4 -2
  148. package/src/serve/same-origin.ts +24 -1
  149. package/src/serve/serve-hub.ts +27 -3
  150. package/src/shipkit-files.ts +9 -7
  151. package/src/shot/shooter.ts +3 -3
  152. package/src/shot/shot-ask.ts +14 -3
  153. package/src/shot/shot.shipkit.ts +1 -1
  154. package/src/social/discord-layout.ts +282 -0
  155. package/src/social/fit.ts +84 -0
  156. package/src/social/identity-words.ts +74 -0
  157. package/src/social/kind-pages.ts +41 -0
  158. package/src/social/kinds.ts +92 -0
  159. package/src/social/load.ts +105 -9
  160. package/src/social/md.ts +14 -6
  161. package/src/social/media-limit.ts +63 -2
  162. package/src/social/presence.ts +1 -1
  163. package/src/social/publish/bluesky.ts +58 -19
  164. package/src/social/publish/discord.ts +3 -2
  165. package/src/social/publish/index.ts +31 -5
  166. package/src/social/reach.ts +49 -0
  167. package/src/social/release-stage.ts +173 -0
  168. package/src/social/routes.ts +44 -9
  169. package/src/social/stage.ts +227 -0
  170. package/src/social/strip.ts +85 -0
  171. package/src/social/text.ts +6 -2
  172. package/src/social/unit.ts +57 -1
  173. package/src/social/writes.ts +11 -0
  174. package/src/stores/routes.ts +2 -2
  175. package/src/suite/judge-suites.ts +1 -1
  176. package/src/suite/suite-cli.ts +5 -5
  177. package/src/trailer/build.ts +90 -52
  178. package/src/trailer/draft.ts +28 -0
  179. package/src/trailer/footage.ts +4 -2
  180. package/src/trailer/grammar.ts +25 -13
  181. package/src/trailer/graph.ts +32 -9
  182. package/src/trailer/profile.ts +35 -0
  183. package/src/trailer/prune.ts +15 -10
  184. package/src/trailer/public-words.ts +41 -0
  185. package/src/trailer/stitch.ts +22 -10
  186. package/src/trailer/titles.ts +47 -2
@@ -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
  },
@@ -52,6 +52,8 @@ export type ProcView = {
52
52
  note: string | null
53
53
  /** up, and started by something else: not ours to stop */
54
54
  external: boolean
55
+ /** what the owner last asked for */
56
+ want: 'up' | 'down'
55
57
  }
56
58
 
57
59
  export type SuperviseDeps = {
@@ -361,7 +363,7 @@ export class Proc {
361
363
  }
362
364
 
363
365
  view(): ProcView {
364
- return { id: this.spec.id, status: this.status, pid: this.pid, since: this.since, restarts: this.crashes.length, note: this.note, external: this.external }
366
+ return { id: this.spec.id, status: this.status, pid: this.pid, since: this.since, restarts: this.crashes.length, note: this.note, external: this.external, want: this.want }
365
367
  }
366
368
  }
367
369
 
@@ -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,9 +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
- export type Picture = { file: string; w: number | null; h: number | null }
111
+ /** one picture: the file shown, its size, and the same picture in its other formats (an svg beside its png) */
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
+ }
75
127
 
76
128
  /** a company as the forms ask it: `legal.md`, and the private rows of the gitignored `legal.local.md` */
77
129
  export type Legal = {
@@ -86,6 +138,8 @@ export type Identity = {
86
138
  order: number
87
139
  /** it speaks for a repo that names none */
88
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
89
143
  site: string
90
144
  siteRepo: string
91
145
  /** the folder its picture paths are relative to, absolute: its `files`, else its own folder */
@@ -134,6 +188,26 @@ function merged(shared: ProfileRow[], own: ProfileRow[]): ProfileRow[] {
134
188
  return [...shared.map((r) => mine.get(r.field) ?? r), ...own.filter((r) => !shared.some((s) => s.field === r.field))]
135
189
  }
136
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
+
137
211
  function places(dir: string, errors: string[]): Place[] {
138
212
  const at = join(dir, 'places')
139
213
  if (!existsSync(at)) return []
@@ -157,6 +231,7 @@ function places(dir: string, errors: string[]): Place[] {
157
231
  write: meta.write ?? '',
158
232
  when: meta.when ?? '',
159
233
  flair: meta.flair ?? '',
234
+ ceiling: ceilingOf(meta.posts, abs, errors),
160
235
  file: abs,
161
236
  rules: section(body, 'Rules') ?? '',
162
237
  notes: section(body, 'Notes') ?? '',
@@ -199,19 +274,36 @@ function imageSize(abs: string): { w: number | null; h: number | null } {
199
274
  return { w: null, h: null }
200
275
  }
201
276
 
202
- /** the pictures of each `pictures` folder, each folder the largest first: a folder under `files`, or a `~/…` or
203
- * absolute one elsewhere on the disk (a repo's own files the identity names), its pictures named by that path */
277
+ /** the formats a picture is shown by, the first one its folder holds; the others are its `also` */
278
+ const SHOWN = ['jpg', 'png', 'webp', 'mp4', 'svg']
279
+ /** the identity's own folder of pictures, listed first whether `pictures` names it or not */
280
+ const OWN = 'pictures'
281
+
282
+ /** the pictures of its own folder then of each `pictures` folder, each folder the largest first, one picture per name
283
+ * with its other formats: a folder under `files`, or a `~/…` or absolute one elsewhere on the disk (a repo's own files
284
+ * the identity names), its pictures named by that path */
204
285
  function pictures(files: string | null, dirs: string, file: string, errors: string[]): Picture[] {
205
286
  if (files == null) return []
287
+ const named = dirs.split(',').map((d) => d.trim().replace(/\/+$/, '')).filter(Boolean)
206
288
  const out: Picture[] = []
207
- for (const dir of dirs.split(',').map((d) => d.trim()).filter(Boolean)) {
289
+ for (const dir of [...(named.includes(OWN) || !existsSync(join(files, OWN)) ? [] : [OWN]), ...named]) {
208
290
  const abs = dir.startsWith('~/') || isAbsolute(dir) ? home(dir) : join(files, dir)
209
291
  if (!existsSync(abs)) {
210
292
  errors.push(`${file}: pictures "${dir}" is no folder on this disk`)
211
293
  continue
212
294
  }
295
+ const byName = new Map<string, string[]>()
296
+ for (const f of readdirSync(abs).sort()) {
297
+ const m = /^(.+)\.(\w+)$/.exec(f)
298
+ if (m == null || !SHOWN.includes(m[2]!)) continue
299
+ byName.set(m[1]!, [...(byName.get(m[1]!) ?? []), m[2]!])
300
+ }
213
301
  const here: Picture[] = []
214
- for (const f of readdirSync(abs).sort()) if (/\.(png|jpg|webp|mp4)$/.test(f)) here.push({ file: `${dir}/${f}`, ...imageSize(join(abs, f)) })
302
+ for (const [name, exts] of byName) {
303
+ const [shown, ...rest] = [...exts].sort((x, y) => SHOWN.indexOf(x) - SHOWN.indexOf(y))
304
+ const v = Object.fromEntries([shown!, ...rest].map((e) => [`${dir}/${name}.${e}`, pictureVersion(join(abs, `${name}.${e}`))]))
305
+ here.push({ file: `${dir}/${name}.${shown}`, ...imageSize(join(abs, `${name}.${shown}`)), also: rest.map((e) => `${dir}/${name}.${e}`), v })
306
+ }
215
307
  out.push(...here.sort((x, y) => (y.w ?? 0) * (y.h ?? 0) - (x.w ?? 0) * (x.h ?? 0)))
216
308
  }
217
309
  return out
@@ -232,6 +324,13 @@ function account(identity: string, id: string, dir: string, shared: ProfileRow[]
232
324
  const file = join(dir, 'account.md')
233
325
  const { meta, body } = parseFrontmatter(read(file))
234
326
  linkErrors(file, meta, ['profile', 'live', 'write', 'inbox', 'stats'], errors)
327
+ const own = rows(body, 'Profile', files)
328
+ errors.push(...copiedRows(own, shared, file))
329
+ const merge = filledRows(merged(shared, own), file, errors)
330
+ const automation = meta.automation ?? 'none'
331
+ const secret = meta.secret ?? ''
332
+ const guild = meta.guild ?? ''
333
+ const setup = steps(body)
235
334
  return {
236
335
  id,
237
336
  identity,
@@ -243,30 +342,49 @@ function account(identity: string, id: string, dir: string, shared: ProfileRow[]
243
342
  write: meta.write ?? '',
244
343
  inbox: meta.inbox ?? '',
245
344
  stats: meta.stats ?? '',
345
+ settings: meta.settings ?? '',
246
346
  max: meta.max ? Number(meta.max) : null,
247
347
  text: meta.text ?? '',
248
348
  group: meta.group ?? '',
249
349
  place: meta.place ?? '',
250
350
  footer: meta.footer ?? '',
251
- automation: meta.automation ?? 'none',
252
- secret: meta.secret ?? '',
253
- guild: meta.guild ?? '',
351
+ automation,
352
+ secret,
353
+ guild,
354
+ ceiling: ceilingOf(meta.posts, file, errors),
355
+ sensitive: meta.sensitive ?? '',
356
+ limits: limitsOf(meta.limits, file, errors),
254
357
  file,
255
358
  dir,
256
- rows: merged(shared, rows(body, 'Profile', files)),
359
+ rows: merge,
360
+ uploads: uploadsOf({ id, guild, secret, automation }, merge, dir, files, new Set(own.map((r) => r.field)), setup.length === 0 ? null : stepRefs(setup)),
257
361
  automationText: section(body, 'Automation') ?? '',
258
- steps: steps(body),
362
+ steps: setup,
259
363
  notes: section(body, 'Notes') ?? '',
260
364
  places: places(dir, errors),
261
365
  }
262
366
  }
263
367
 
368
+ /** the identity's texts an account's own text row copies verbatim (over 12 characters): one error line each, so a text
369
+ * lives in one place and every venue follows it (`[[field]]`, or no row at all to inherit it) */
370
+ export function copiedRows(own: readonly ProfileRow[], shared: readonly ProfileRow[], file: string): string[] {
371
+ const out: string[] = []
372
+ for (const r of own) {
373
+ if (r.files.length > 0) continue
374
+ for (const s of shared)
375
+ if (s.files.length === 0 && s.value.length > 12 && !s.value.includes('[[') && r.value.includes(s.value))
376
+ out.push(`${file}: row ${r.field} holds the identity's ${s.field} verbatim: write [[${s.field}]] there, or drop the row to inherit it`)
377
+ }
378
+ return out
379
+ }
380
+
264
381
  function identity(id: string, dir: string, errors: string[]): Identity {
265
382
  const file = join(dir, 'identity.md')
266
383
  const { meta, body } = parseFrontmatter(read(file))
267
384
  const files = meta.files ? home(meta.files) : dir
268
385
  if (!isAbsolute(files) || !existsSync(files)) errors.push(`${file}: files "${meta.files}" is no folder on this disk`)
269
- const shared = rows(body, 'Profile', files)
386
+ // filled once here, so the profile shows and copies a shared text (a tier's lines) as an account does
387
+ const shared = filledRows(rows(body, 'Profile', files), file, errors)
270
388
  const at = join(dir, 'accounts')
271
389
  const accounts: Account[] = []
272
390
  if (existsSync(at))
@@ -284,6 +402,7 @@ function identity(id: string, dir: string, errors: string[]): Identity {
284
402
  name: meta.name ?? id,
285
403
  order: Number(meta.order ?? 99),
286
404
  default: meta.default === 'true',
405
+ adult: meta.adult === 'true',
287
406
  site: meta.site ?? '',
288
407
  siteRepo: meta.siteRepo ?? '',
289
408
  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
+ }