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
@@ -0,0 +1,197 @@
1
+ // what a review card offers a post (wiki tools/shipkit/review-raised-items.md, A post staged from a card): each media of
2
+ // each version (an image, a clip, a pair's after, its before, its wipe, a gallery tile; never a sound alone), and the
3
+ // card's own words as chips: its title, its `what` cut into lines, its views' labels and notes, the line its agent
4
+ // wrote for a post, the owner's words and the agents' replies on the thread. A pick is a name the card names, never a path
5
+ import type { PostRating } from '../identities/rating.ts'
6
+ import { cutPassage } from '../social/fit.ts'
7
+ import type { StageInput } from '../social/stage.ts'
8
+ import { pairAnimation } from './anim.ts'
9
+ import { threadOfId } from './cells.ts'
10
+ import { ensureLocal } from './media-read.ts'
11
+ import { isApproved, isGallery, isPair, isReply, partyOf, viewLetter, viewName, wordsOf, type Item, type ReviewItem } from './model.ts'
12
+ import { readAll } from './store.ts'
13
+ import { threadsOf } from './threads.ts'
14
+
15
+ export type StageSide = 'before' | 'after' | 'wipe'
16
+
17
+ /** one media of a card a post may carry */
18
+ export type Stageable = {
19
+ /** `<item>#<view>[.<side>|/<tile>]`: the pick the popup sends back */
20
+ key: string
21
+ item: string
22
+ view: number
23
+ side?: StageSide
24
+ tile?: number
25
+ /** `2.A after`, `2.C vitality` */
26
+ label: string
27
+ kind: 'image' | 'clip'
28
+ /** the store's file the page shows for it (a wipe: the pair's after) */
29
+ file: string
30
+ /** its width over its height */
31
+ ratio: number
32
+ /** what it shows, for the alt: the view's note, its label */
33
+ note: string
34
+ }
35
+
36
+ /** a word of the card he may click into his text, and where it comes from */
37
+ export type Chip = { from: 'post' | 'card' | 'view' | 'his' | 'agent'; text: string }
38
+
39
+ const isClip = (f: string): boolean => /\.(mp4|webm)$/i.test(f)
40
+
41
+ /** every media of one version a post may carry, `n` its version number */
42
+ export function stageablesOf(i: Item, n: number): Stageable[] {
43
+ const out: Stageable[] = []
44
+ i.views.forEach((v, k) => {
45
+ const tag = `${n}.${viewLetter(k)}`
46
+ const name = viewName(v, k)
47
+ if (isGallery(v)) {
48
+ v.gallery.forEach((t, j) => out.push({ key: `${i.id}#${k}/${j}`, item: i.id, view: k, tile: j, label: `${tag} ${t.group ? `${t.group}/` : ''}${t.label}`, kind: 'image', file: t.file, ratio: t.size.w / Math.max(1, t.size.h), note: t.label }))
49
+ return
50
+ }
51
+ if (v.audio) return
52
+ const ratio = v.size.w / Math.max(1, v.size.h)
53
+ const note = v.note ?? (v.label || i.title)
54
+ const f = v.files
55
+ if (isPair(f)) {
56
+ const clip = isClip(f.after)
57
+ out.push({ key: `${i.id}#${k}.after`, item: i.id, view: k, side: 'after', label: `${tag} ${name} after`, kind: clip ? 'clip' : 'image', file: f.after, ratio, note })
58
+ out.push({ key: `${i.id}#${k}.before`, item: i.id, view: k, side: 'before', label: `${tag} ${name} before`, kind: clip ? 'clip' : 'image', file: f.before, ratio, note })
59
+ // a wipe is drawn from two images (the anim cache); two clips have none
60
+ if (!clip) out.push({ key: `${i.id}#${k}.wipe`, item: i.id, view: k, side: 'wipe', label: `${tag} ${name} wipe`, kind: 'clip', file: f.after, ratio, note })
61
+ return
62
+ }
63
+ const file = 'image' in f ? f.image : 'video' in f ? f.video : ''
64
+ if (file !== '') out.push({ key: `${i.id}#${k}`, item: i.id, view: k, label: `${tag} ${name}`, kind: isClip(file) ? 'clip' : 'image', file, ratio, note })
65
+ })
66
+ return out
67
+ }
68
+
69
+ /** every media of a thread's versions, the newest version first; the versions oldest first is `versions` reversed */
70
+ export const stageablesOfThread = (versions: readonly ReviewItem[]): Stageable[] => versions.flatMap((x, k) => stageablesOf(x.item, versions.length - k))
71
+
72
+ /** markdown read as plain words, one chip a line or a sentence */
73
+ function linesOf(md: string): string[] {
74
+ const plain = md
75
+ .replace(/```[\s\S]*?```/g, '')
76
+ .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
77
+ .replace(/[*_`]+/g, '')
78
+ .replace(/^#+\s*/gm, '')
79
+ return plain
80
+ .split('\n')
81
+ .map((l) => l.replace(/^\s*(?:[-+*]|\d+\.)\s+/, '').trim())
82
+ .flatMap((l) => l.split(/(?<=[.!?])\s+(?=[A-Z])/))
83
+ .map((l) => l.trim())
84
+ .filter((l) => l.length >= 3 && l.length <= 400)
85
+ }
86
+
87
+ /** the words of a thread he may pick from, each once, the card's own post line first */
88
+ export function chipsOf(versions: readonly ReviewItem[]): Chip[] {
89
+ const out: Chip[] = []
90
+ const seen = new Set<string>()
91
+ const add = (from: Chip['from'], text: string | undefined): void => {
92
+ const t = text?.trim() ?? ''
93
+ if (t === '' || seen.has(t)) return
94
+ seen.add(t)
95
+ out.push({ from, text: t })
96
+ }
97
+ for (const x of versions) add('post', x.item.post)
98
+ for (const x of versions) {
99
+ add('card', x.item.title)
100
+ for (const l of linesOf(x.item.what ?? '')) add('card', l)
101
+ x.item.views.forEach((v, k) => {
102
+ add('view', v.label || undefined)
103
+ if (!isGallery(v)) add('view', v.note)
104
+ void k
105
+ })
106
+ }
107
+ for (const x of versions)
108
+ for (const m of x.thread) {
109
+ if (m.op !== undefined && m.op !== 'ask' && m.op !== 'answer') continue
110
+ const owner = partyOf(m.who) === 'owner'
111
+ if (owner) {
112
+ if (m.verdict === undefined || isApproved(m.verdict)) add('his', m.text)
113
+ for (const r of m.reactions ?? []) add('his', r.comment)
114
+ for (const r of m.rects ?? []) add('his', r.comment)
115
+ } else if (isReply(m)) add('agent', m.text)
116
+ }
117
+ return out
118
+ }
119
+
120
+ /** what he asks of the stage: the pick (a key `stageablesOf` gives; unset, the newest version's first media), his
121
+ * text, the rating, and where else it goes */
122
+ export type StageAsk = {
123
+ pick?: string
124
+ text: string
125
+ rating: PostRating
126
+ /** what the post is for (wiki guides/post-kinds/index.md); unset, a card's `feature` */
127
+ kind?: string
128
+ /** a `custom` kind's one line on why no kind fits */
129
+ kindWhy?: string
130
+ alt?: string
131
+ slot?: string
132
+ tags?: string
133
+ /** a channel he picked on an account (Discord) over its default: that account gets its own heading */
134
+ place?: { account: string; place: string }
135
+ /** an agent rewrites it in the identity's voice: the draft note raised to the social topic */
136
+ polish?: boolean
137
+ /** a clip's passage, his in and out in seconds */
138
+ passage?: { from: number; to: number }
139
+ /** one copy within the tightest limits of the venues it reaches */
140
+ fit?: boolean
141
+ }
142
+
143
+ const slugWords = (s: string): string => wordsOf(s).join('-').slice(0, 40).replace(/-+$/, '') || 'post'
144
+
145
+ /** the thread a card id belongs to, its versions head first */
146
+ function versionsOf(dir: string, id: string): ReviewItem[] {
147
+ const t = threadOfId(id, threadsOf(readAll(dir).items))
148
+ if (t == null) throw new Error(`no card ${id}`)
149
+ if (t.head.item.origin.by !== 'agent') throw new Error(`${id} is no agent's card: only a card's media is staged`)
150
+ return t.versions
151
+ }
152
+
153
+ /** the stage of one card: its media, its words, the drafts already made from it */
154
+ export function stageOfCard(dir: string, id: string): { head: string; first: string; title: string; media: Stageable[]; words: Chip[] } {
155
+ const versions = versionsOf(dir, id)
156
+ const head = versions[0]!.item
157
+ return { head: head.id, first: versions.at(-1)!.item.id, title: head.title, media: stageablesOfThread(versions), words: chipsOf(versions) }
158
+ }
159
+
160
+ /** the owner's ask made a stage input: the pick resolved to a local file, its copy's name, the draft's angle and headings */
161
+ export async function stageInputOf(dir: string, id: string, ask: StageAsk, font?: string): Promise<{ input: StageInput; pick: Stageable | null }> {
162
+ const s = stageOfCard(dir, id)
163
+ const pick = ask.pick === undefined ? (s.media[0] ?? null) : (s.media.find((m) => m.key === ask.pick) ?? null)
164
+ if (ask.pick !== undefined && pick == null) throw new Error(`the card names no media ${ask.pick} (${s.media.map((m) => m.key).join(', ') || 'none'})`)
165
+ const whole = pick ? await stageFileOf(dir, pick, font) : null
166
+ if (ask.passage && pick?.kind !== 'clip') throw new Error('a passage is cut from a clip')
167
+ const file = whole && ask.passage ? cutPassage(whole, ask.passage.from, ask.passage.to) : whole
168
+ const tag = pick ? pick.label.split(' ')[0]!.replace('.', '').toLowerCase() : ''
169
+ const name = pick ? `${slugWords(s.title)}-${tag}${pick.side && pick.side !== 'after' ? `-${pick.side}` : pick.tile !== undefined ? `-${pick.tile + 1}` : ''}` : ''
170
+ const input: StageInput = {
171
+ source: { review: s.first },
172
+ title: s.title,
173
+ text: ask.text,
174
+ media: pick && file ? { file, name, vertical: pick.kind === 'clip' && pick.ratio < 0.6 } : null,
175
+ ...(ask.alt !== undefined ? { alt: ask.alt } : {}),
176
+ rating: ask.rating,
177
+ ...(ask.kind ? { kind: ask.kind } : {}),
178
+ ...(ask.kindWhy ? { kindWhy: ask.kindWhy } : {}),
179
+ ...(ask.slot ? { slot: ask.slot } : {}),
180
+ ...(ask.tags ? { tags: ask.tags } : {}),
181
+ angle: `Staged from the card « ${s.title} » (${s.head})${pick ? `, ${pick.label}` : ''}${ask.passage ? `, ${ask.passage.from.toFixed(2)} s to ${ask.passage.to.toFixed(2)} s` : ''}.`,
182
+ headings: [{ id: 'short' }, ...(ask.place ? [{ id: ask.place.account, place: ask.place.place }] : [])],
183
+ }
184
+ return { input, pick }
185
+ }
186
+
187
+ /** the local file a pick stands for: the store's own, fetched back from the Space when the disk let it go; a wipe
188
+ * drawn once into the anim cache */
189
+ export async function stageFileOf(dir: string, s: Stageable, font?: string): Promise<string> {
190
+ if (s.side === 'wipe') {
191
+ const a = await pairAnimation(dir, s.item, { view: s.view, mode: 'wipe', format: 'mp4', labels: 'none', ...(font ? { font } : {}) })
192
+ return a.file
193
+ }
194
+ const f = await ensureLocal(dir, s.item, s.file)
195
+ if (f == null) throw new Error(`${s.item}/${s.file}: neither the disk nor the Space holds it`)
196
+ return f
197
+ }
@@ -0,0 +1,123 @@
1
+ // the stage popup's two routes (wiki tools/shipkit/review-raised-items.md, A post staged from a card): GET what a card
2
+ // offers a post and where it may go, POST a dry run of his draft or the draft written. The page never names a path:
3
+ // a pick is a key the card names, resolved here through the store's own reads
4
+ import { dirname, join } from 'node:path'
5
+ import { POST_RATINGS, isPostRating } from '../identities/rating.ts'
6
+ import { MESSAGES_DIR, testedLines } from '../messages/model.ts'
7
+ import { draftsOfCard } from '../social/card-drafts.ts'
8
+ import { openDesk } from '../social/open.ts'
9
+ import { addDays, dayOf, slotDays } from '../social/presence.ts'
10
+ import { placesOf } from '../social/reach.ts'
11
+ import { askPolish, fitStage, stageDraft, stageDry, type Staged } from '../social/stage.ts'
12
+ import { NO_STORE } from './http.ts'
13
+ import { stageInputOf, stageOfCard, type StageAsk } from './stage-card.ts'
14
+ import type { ReviewUnit } from './unit.ts'
15
+
16
+ const str = (v: unknown): string | undefined => (typeof v === 'string' && v.trim() !== '' ? v : undefined)
17
+
18
+ /** what one account shows in the popup: where a message lands, its max, the places a picker lists */
19
+ export type StageAccount = { id: string; name: string; group: string; place: string; max: number | null; live: boolean; places: { id: string; ceiling: string; open: boolean }[] }
20
+
21
+ /** the popup's data for one card */
22
+ export async function stageGet(root: string, dir: string, id: string): Promise<Response> {
23
+ const card = stageOfCard(dir, id)
24
+ const voice = await voiceOf(root, { id: card.head, title: card.title })
25
+ return Response.json({ ...card, ...voice, drafts: draftsOfCard(root, new Set([card.head, card.first])) }, { headers: NO_STORE })
26
+ }
27
+
28
+ /** what the popup shows of the voice whatever the source (a card, a release): who speaks, its accounts and places, the
29
+ * next slots, the repo's tags, the repo's lines for this source */
30
+ export async function voiceOf(root: string, about: { id: string; title: string }): Promise<Record<string, unknown>> {
31
+ const { desk, unit } = await openDesk(root)
32
+ const card = about
33
+ const who = desk.identities.find((i) => i.id === desk.speaksAs) ?? null
34
+ const errors: string[] = []
35
+ const accounts: StageAccount[] = (who?.accounts ?? []).map((a) => ({
36
+ id: a.id,
37
+ name: a.name,
38
+ group: a.group,
39
+ place: a.place,
40
+ max: a.max,
41
+ live: a.automation === 'live',
42
+ places: placesOf(a, errors).map((p) => ({ id: p.id, ceiling: p.ceiling, open: p.open })),
43
+ }))
44
+ const today = dayOf(Date.now())
45
+ const slots = slotDays(desk.weekly, desk.drafts, today, addDays(today, 13)).map((s) => ({ value: `${s.day} ${s.slot.tag}`, what: s.slot.what, taken: s.drafts.length > 0 }))
46
+ const counts = new Map<string, number>()
47
+ for (const d of desk.drafts) for (const t of new Set(d.posts.flatMap((p) => p.tags))) counts.set(t, (counts.get(t) ?? 0) + 1)
48
+ const tags = [...counts].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, 10).map(([t]) => t)
49
+ let lines: { text: string; source: string }[] = []
50
+ try {
51
+ // the unit's own lines, else the tested phrasings of the repo's messages store (messages/model.ts)
52
+ lines = [...(unit?.lines?.({ id: card.id, title: card.title }) ?? testedLines(join(root, MESSAGES_DIR)))]
53
+ } catch (e) {
54
+ errors.push(`the repo's lines failed: ${(e as Error).message}`)
55
+ }
56
+ return {
57
+ identity: who == null ? null : { id: who.id, name: who.name, adult: who.adult },
58
+ ratings: POST_RATINGS,
59
+ rating: who?.adult ? null : 'safe',
60
+ // the kinds the repo takes, each with what it is for and its rules page: the popup's kind picker
61
+ kinds: desk.kinds,
62
+ accounts,
63
+ lines,
64
+ slots,
65
+ tags,
66
+ errors,
67
+ }
68
+ }
69
+
70
+ /** the owner's ask read from the page's body; a field of the wrong shape is refused by name */
71
+ export function askOf(b: Record<string, unknown>): StageAsk & { dry: boolean } {
72
+ const rating = typeof b.rating === 'string' ? b.rating : ''
73
+ if (!isPostRating(rating)) throw new Error(`rating: ${POST_RATINGS.join(', ')}`)
74
+ if (typeof b.text !== 'string') throw new Error('text: the post')
75
+ const place = typeof b.place === 'object' && b.place !== null ? (b.place as Record<string, unknown>) : null
76
+ const pick = str(b.pick)
77
+ const alt = typeof b.alt === 'string' ? b.alt : undefined
78
+ const slot = str(b.slot)
79
+ const tags = str(b.tags)
80
+ const kind = str(b.kind)
81
+ const kindWhy = str(b.kindWhy)
82
+ const p = typeof b.passage === 'object' && b.passage !== null ? (b.passage as Record<string, unknown>) : null
83
+ const passage = p && typeof p.from === 'number' && typeof p.to === 'number' ? { from: p.from, to: p.to } : null
84
+ return {
85
+ text: b.text,
86
+ rating,
87
+ ...(kind ? { kind } : {}),
88
+ ...(kindWhy ? { kindWhy } : {}),
89
+ ...(pick ? { pick } : {}),
90
+ ...(alt !== undefined ? { alt } : {}),
91
+ ...(slot ? { slot } : {}),
92
+ ...(tags ? { tags } : {}),
93
+ ...(place && typeof place.account === 'string' && typeof place.place === 'string' ? { place: { account: place.account, place: place.place } } : {}),
94
+ ...(b.polish === true ? { polish: true } : {}),
95
+ ...(b.fit === true ? { fit: true } : {}),
96
+ ...(passage ? { passage } : {}),
97
+ dry: b.dry === true,
98
+ }
99
+ }
100
+
101
+ /** what the popup reads of a stage: each message, each skip, every problem */
102
+ export const answerOf = (r: Staged, polish?: string): Record<string, unknown> => ({
103
+ slug: r.slug,
104
+ posts: (r.draft?.posts ?? []).map((p) => ({ key: p.key, platform: p.platform, place: p.place, length: p.length, refused: p.refused })),
105
+ skipped: r.draft?.skipped ?? [],
106
+ errors: r.errors,
107
+ ...(polish ? { polish } : {}),
108
+ })
109
+
110
+ /** a dry run of his draft (`dry: true`), or the draft written, its polish note raised when he ticked it */
111
+ export async function stagePost(root: string, dir: string, id: string, unit: ReviewUnit | null, body: Record<string, unknown>): Promise<Response> {
112
+ const ask = askOf(body)
113
+ const font = unit?.anim?.font ? join(dirname(dirname(dir)), unit.anim.font) : undefined
114
+ // a dry run reads the whole clip: the passage and the fit are cut once, at Enter
115
+ const { passage: _, fit: __, ...whole } = ask
116
+ const { input } = await stageInputOf(dir, id, ask.dry ? whole : ask, font)
117
+ const opened = await openDesk(root)
118
+ const ctx = { unit: opened.unit, speaksAs: opened.desk.speaksAs ?? undefined }
119
+ if (ask.dry) return Response.json(answerOf(await stageDry(root, input, ctx)), { headers: NO_STORE })
120
+ const r = await stageDraft(root, ask.fit ? await fitStage(root, input, ctx) : input, ctx)
121
+ const polish = ask.polish ? (await askPolish(root, r.slug, input.title, opened.unit)).id : undefined
122
+ return Response.json(answerOf(r, polish), { headers: NO_STORE })
123
+ }
@@ -35,8 +35,10 @@ import {
35
35
  toAcknowledge,
36
36
  verdictMessageOf,
37
37
  verdictOf,
38
+ viewIndexOf,
38
39
  withdrawnOf,
39
40
  type GalleryTile,
41
+ type CardChangelog,
40
42
  type Item,
41
43
  type Message,
42
44
  type Op,
@@ -48,6 +50,7 @@ import {
48
50
  type ReviewItem,
49
51
  type ReviewMark,
50
52
  type ReviewView,
53
+ type TrailerCard,
51
54
  type Spec,
52
55
  type Subject,
53
56
  viewFilesOf,
@@ -103,6 +106,10 @@ export interface ViewInput {
103
106
  export interface AddInput {
104
107
  title: string
105
108
  what: string
109
+ /** the public line for a post of it (`--post`); the caller runs the repo's guard on it first */
110
+ post?: string
111
+ /** the change its approval adds to next.md (`--changelog`); the caller runs the repo's guard on it first */
112
+ changelog?: CardChangelog
106
113
  /** what is judged; a plain shot by default */
107
114
  subject?: Subject
108
115
  topic?: string
@@ -133,6 +140,10 @@ export interface AddInput {
133
140
  wip?: { live: string }
134
141
  /** every view is an option he picks one of */
135
142
  choice?: boolean
143
+ /** on a choice: the option the agent suggests, by its label or its letter */
144
+ agentPick?: string
145
+ /** a trailer card: the cut the hub plays in its body; its one view is the cut's strip */
146
+ trailer?: TrailerCard
136
147
  now?: Date
137
148
  }
138
149
 
@@ -315,6 +326,8 @@ export async function addItem(dir: string, input: AddInput): Promise<Item> {
315
326
  if (given.length === 0) throw new Error('give --image, --video or --audio, or --before and --after, or --view "<label>" <image>')
316
327
  for (const [i, v] of given.entries()) if (i > 0 && !v.label.trim()) throw new Error('--view: every view after the first needs its label')
317
328
  if (input.choice && given.length < 2) throw new Error('--choice: a choice has two options or more, one --view each')
329
+ if (input.agentPick !== undefined && !input.choice) throw new Error('--pick: only on a --choice card')
330
+ const agentPick = input.agentPick === undefined ? undefined : pickIndex(given, input.agentPick)
318
331
  for (const v of given) if (v.note !== undefined && v.gallery) throw new Error(`--view "${v.label}": a note goes on an image, a clip or a sound, never a gallery`)
319
332
  const loaded = await Promise.all(given.map((v, i) => loadView(v, i === 0 ? 'the first view' : `--view "${v.label}"`)))
320
333
  if (input.supersedes !== undefined && !existsSync(join(dir, input.supersedes, 'item.json'))) throw new Error(`--supersedes ${input.supersedes}: no such card in ${dir}`)
@@ -366,6 +379,8 @@ export async function addItem(dir: string, input: AddInput): Promise<Item> {
366
379
  origin: { by: 'agent', ...(lane ? { lane } : {}), ...(session ? { session } : {}) },
367
380
  title: input.title.trim(),
368
381
  what: input.what.trim(),
382
+ ...(input.post?.trim() ? { post: input.post.trim() } : {}),
383
+ ...(input.changelog ? { changelog: { category: input.changelog.category.trim(), line: input.changelog.line.trim() } } : {}),
369
384
  ...(topic ? { topic } : {}),
370
385
  ...(input.commit ? { commit: input.commit } : {}),
371
386
  views: loaded.map((v, n) => viewOf(v, n, input.marks?.[n], given[n]?.note)),
@@ -376,6 +391,8 @@ export async function addItem(dir: string, input: AddInput): Promise<Item> {
376
391
  ...(input.light ? { light: input.light } : {}),
377
392
  ...(input.wip ? { wip: { live: input.wip.live, frame: 1 } } : {}),
378
393
  ...(input.choice ? { choice: true as const } : {}),
394
+ ...(agentPick !== undefined ? { agentPick } : {}),
395
+ ...(input.trailer ? { trailer: input.trailer } : {}),
379
396
  }
380
397
  const problems = itemProblems(item)
381
398
  if (problems.length > 0) throw new Error(problems.join('; '))
@@ -423,6 +440,25 @@ export async function addView(dir: string, id: string, v: ViewInput, o: { marks?
423
440
  })
424
441
  }
425
442
 
443
+ /** the option the agent suggests, by its label or its letter; throws naming every option */
444
+ function pickIndex(views: readonly { label: string }[], ref: string, flag = '--pick'): number {
445
+ try {
446
+ return viewIndexOf(views, ref)
447
+ } catch (e) {
448
+ throw new Error(`${flag}: ${(e as Error).message}`)
449
+ }
450
+ }
451
+
452
+ /** the agent's pick set on an open choice card, by the view's label or letter; refused once he answered */
453
+ export function setAgentPick(dir: string, id: string, ref: string): Item {
454
+ const x = readItem(dir, id)
455
+ if (!x) throw new Error(`no card ${id}`)
456
+ if (verdictOf(x)) throw new Error(`${id} has his answer already: the pick shows what was suggested, never rewritten after`)
457
+ if (x.item.choice !== true) throw new Error(`${id} is no choice card: a pick names one of its options`)
458
+ const n = pickIndex(x.item.views, ref, 'pick')
459
+ return updateHead(dir, id, (cur) => ({ ...cur, agentPick: n }))
460
+ }
461
+
426
462
  /** the head rewritten under the item's lock, from what the file says now: a write that raced this one is never lost */
427
463
  export function updateHead(dir: string, id: string, fn: (cur: Item) => Item): Item {
428
464
  return locked(dir, id, () => {
@@ -605,8 +641,8 @@ const CODE_KEEP_MS = 7 * 24 * 3600_000
605
641
  const READ_STEP = 250
606
642
 
607
643
  /** every item of the store, through the machine index (space/db.ts): an item whose stamp moved is read again */
608
- function readRaws(dir: string): ReadAll {
609
- const steps = readRawsSteps(dir)
644
+ function readRaws(dir: string, stamps?: Map<string, string>): ReadAll {
645
+ const steps = readRawsSteps(dir, stamps)
610
646
  for (;;) {
611
647
  const r = steps.next()
612
648
  if (r.done) return r.value
@@ -615,8 +651,8 @@ function readRaws(dir: string): ReadAll {
615
651
 
616
652
  /** the same read, the loop given back every READ_STEP items: a cold store of thousands of items is seconds of parsing
617
653
  * (wiki tools/shipkit/home.md, Nothing heavy on the daemon's loop) */
618
- async function readRawsAsync(dir: string): Promise<ReadAll> {
619
- const steps = readRawsSteps(dir)
654
+ async function readRawsAsync(dir: string, stamps?: Map<string, string>): Promise<ReadAll> {
655
+ const steps = readRawsSteps(dir, stamps)
620
656
  for (;;) {
621
657
  const r = steps.next()
622
658
  if (r.done) return r.value
@@ -624,8 +660,8 @@ async function readRawsAsync(dir: string): Promise<ReadAll> {
624
660
  }
625
661
  }
626
662
 
627
- /** the one read, in steps: it yields between two of them, and returns the store */
628
- function* readRawsSteps(dir: string): Generator<void, ReadAll, void> {
663
+ /** the one read, in steps: it yields between two of them, and returns the store. `stamps` hears each item's stamp */
664
+ function* readRawsSteps(dir: string, stamps?: Map<string, string>): Generator<void, ReadAll, void> {
629
665
  const out: ReadAll = { items: [], broken: [] }
630
666
  if (!existsSync(dir)) return out
631
667
  const store = resolve(dir)
@@ -650,6 +686,7 @@ function* readRawsSteps(dir: string): Generator<void, ReadAll, void> {
650
686
  if (++n % READ_STEP === 0) yield
651
687
  seen.add(id)
652
688
  const stamp = stampOf(join(dir, id))
689
+ stamps?.set(id, stamp)
653
690
  const held = was.get(id)
654
691
  let read: Read | null = null
655
692
  if (held && held.stamp === stamp)
@@ -1005,12 +1042,59 @@ export async function readyItem(dir: string, id: string, o: { image?: string; no
1005
1042
  }
1006
1043
 
1007
1044
  /** a store watched by this process: `moved` counts the writes under it, by any process; `dirty` names the items they
1008
- * touched since the last read, `held` every item as last read (null until a first whole read); null once the watch failed */
1045
+ * touched since the last read, `held` every item as last read (null until a first whole read); null once the watch
1046
+ * failed. `folder`, `stamps`, `swept` and `rev` are the disk check under the watch (verify) */
1009
1047
  interface Watched {
1010
1048
  moved: number
1011
1049
  dirty: Set<string>
1012
1050
  held: Map<string, Read> | null
1013
1051
  all: ReadAll | null
1052
+ folder: string
1053
+ stamps: Map<string, string>
1054
+ swept: number
1055
+ rev: number
1056
+ }
1057
+
1058
+ /** how often a read stats every item of a watched store, for a write inside an item its watch missed (17 ms on 3333) */
1059
+ export const SWEEP_MS = 10_000
1060
+
1061
+ const folderStamp = (key: string): string => {
1062
+ const s = statSync(key, { bigint: true, throwIfNoEntry: false })
1063
+ return s ? `${s.ctimeNs}.${s.ino}` : '-'
1064
+ }
1065
+
1066
+ /** the disk checked under the watch, which goes silent under load (FSEvents drops events) and must never freeze the
1067
+ * list: each call stats the store folder (1 µs), which a card's arrival or removal moves (a rename in it), and every
1068
+ * SWEEP_MS the stamp of each item. What moved unheard goes dirty and moves the ETag */
1069
+ function verify(key: string, w: Watched, now: number): void {
1070
+ if (!w.held) return
1071
+ let found = false
1072
+ const mark = (id: string): void => {
1073
+ if (w.dirty.has(id)) return
1074
+ w.dirty.add(id)
1075
+ found = true
1076
+ }
1077
+ const folder = folderStamp(key)
1078
+ if (folder !== w.folder) {
1079
+ w.folder = folder
1080
+ const ids = new Set(readdirSync(key).filter((n) => !n.startsWith('.')))
1081
+ for (const id of ids) if (!w.held.has(id)) mark(id)
1082
+ for (const id of w.held.keys()) if (!ids.has(id)) mark(id)
1083
+ }
1084
+ if (now - w.swept >= SWEEP_MS) {
1085
+ w.swept = now
1086
+ for (const [id, stamp] of w.stamps) if (stampOf(join(key, id)) !== stamp) mark(id)
1087
+ }
1088
+ if (found) w.rev++
1089
+ }
1090
+
1091
+ /** a whole read's result kept as the watch's view: its items, their stamps, the folder as it was before the read */
1092
+ function hold(w: Watched, all: ReadAll, folder: string, stamps: Map<string, string>, now: number): void {
1093
+ w.held = new Map<string, Read>([...all.items.map((x) => [x.item.id, { x }] as const), ...all.broken.map((b) => [b.id, { error: b.error }] as const)])
1094
+ w.all = all
1095
+ w.folder = folder
1096
+ w.stamps = stamps
1097
+ w.swept = now
1014
1098
  }
1015
1099
  const watched = new Map<string, Watched | null>()
1016
1100
  const BOOT = Date.now().toString(36)
@@ -1025,7 +1109,7 @@ function touched(path: string): void {
1025
1109
  function watchOf(dir: string): Watched | null {
1026
1110
  const key = resolve(dir)
1027
1111
  if (watched.has(key)) return watched.get(key) ?? null
1028
- const w: Watched = { moved: 0, dirty: new Set(), held: null, all: null }
1112
+ const w: Watched = { moved: 0, dirty: new Set(), held: null, all: null, folder: '', stamps: new Map(), swept: 0, rev: 0 }
1029
1113
  try {
1030
1114
  // an item's lock is no change of the list
1031
1115
  const watcher = watch(key, { recursive: true }, (_, name) => {
@@ -1052,17 +1136,21 @@ export async function warmStore(dir: string): Promise<void> {
1052
1136
  if (!w || (w.held && w.all)) return
1053
1137
  // what moved before the read is in it; what moves during it stays dirty, read again by the next reader
1054
1138
  w.dirty.clear()
1055
- const all = await readRawsAsync(dir)
1139
+ const folder = folderStamp(resolve(dir))
1140
+ const stamps = new Map<string, string>()
1141
+ const all = await readRawsAsync(dir, stamps)
1056
1142
  if (w.held && w.all) return
1057
- w.held = new Map<string, Read>([...all.items.map((x) => [x.item.id, { x }] as const), ...all.broken.map((b) => [b.id, { error: b.error }] as const)])
1058
- w.all = all
1143
+ hold(w, all, folder, stamps, Date.now())
1059
1144
  }
1060
1145
 
1061
- /** changes when anything the list is built from changes: watched, a count of writes; else a scan. The list's ETag */
1062
- export function storeStamp(dir: string): string {
1146
+ /** changes when anything the list is built from changes: watched, a count of writes and what the disk check found;
1147
+ * else a scan. The list's ETag */
1148
+ export function storeStamp(dir: string, now = Date.now()): string {
1063
1149
  if (!existsSync(dir)) return 'none'
1064
1150
  const w = watchOf(dir)
1065
- return w ? `${BOOT}.${w.moved}.${wrote}` : scanStamp(dir)
1151
+ if (!w) return scanStamp(dir)
1152
+ verify(resolve(dir), w, now)
1153
+ return `${BOOT}.${w.moved}.${w.rev}.${wrote}`
1066
1154
  }
1067
1155
 
1068
1156
  /** the store's stamp and who listens (the live watchers' pids), so a watch that starts or dies moves it too */
@@ -1097,18 +1185,28 @@ function readRawsCached(dir: string): ReadAll {
1097
1185
  if (cached?.dir !== dir || cached.tag !== tag) cached = { dir, tag, all: readRaws(dir) }
1098
1186
  return cached.all
1099
1187
  }
1188
+ const key = resolve(dir)
1189
+ const now = Date.now()
1100
1190
  if (!w.held || !w.all) {
1101
1191
  w.dirty.clear()
1102
- const all = readRaws(dir)
1103
- w.held = new Map<string, Read>([...all.items.map((x) => [x.item.id, { x }] as const), ...all.broken.map((b) => [b.id, { error: b.error }] as const)])
1104
- w.all = all
1192
+ const folder = folderStamp(key)
1193
+ const stamps = new Map<string, string>()
1194
+ const all = readRaws(dir, stamps)
1195
+ hold(w, all, folder, stamps, now)
1105
1196
  return all
1106
1197
  }
1198
+ verify(key, w, now)
1107
1199
  if (w.dirty.size === 0) return w.all
1108
1200
  for (const id of w.dirty) {
1109
1201
  if (id === '' || id.startsWith('.')) continue
1110
- if (existsSync(join(dir, id))) w.held.set(id, readOne(dir, id))
1111
- else w.held.delete(id)
1202
+ if (existsSync(join(dir, id))) {
1203
+ // stamped before the read: a write during it moves the stamp again
1204
+ w.stamps.set(id, stampOf(join(dir, id)))
1205
+ w.held.set(id, readOne(dir, id))
1206
+ } else {
1207
+ w.held.delete(id)
1208
+ w.stamps.delete(id)
1209
+ }
1112
1210
  }
1113
1211
  w.dirty.clear()
1114
1212
  const out: ReadAll = { items: [], broken: [] }