rvlib-shipkit 2.19.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.
- package/CHANGELOG.md +16 -0
- package/package.json +1 -1
- package/src/annex/annex.ts +227 -0
- package/src/annex/offload.ts +279 -0
- package/src/checks/SK040-release-words.check.ts +43 -0
- package/src/checks/SK041-annex-links.check.ts +28 -0
- package/src/checks/SK042-post-kinds.check.ts +73 -0
- package/src/cli/cmd_Annex.ts +179 -0
- package/src/cli/cmd_Commands.ts +4 -1
- package/src/cli/cmd_Home.ts +3 -2
- package/src/cli/cmd_Messages.ts +155 -0
- package/src/cli/cmd_Releases.ts +48 -0
- package/src/cli/cmd_Review.ts +161 -6
- package/src/cli/cmd_Shot.ts +4 -4
- package/src/cli/cmd_Social.ts +143 -6
- package/src/cli/family-pages.ts +2 -0
- package/src/cli/kit/index.ts +1 -1
- package/src/cli/kit/verb.ts +11 -3
- package/src/cli/registry.ts +6 -1
- package/src/collections/collection-types.ts +8 -1
- package/src/collections/providers.ts +4 -1
- package/src/commands/model.ts +36 -0
- package/src/commands/registry.ts +49 -0
- package/src/commands/routes.ts +59 -0
- package/src/commands/runner.ts +35 -0
- package/src/commands/runs.ts +112 -0
- package/src/core/app-icon.ts +4 -3
- package/src/core/icon-type.ts +8 -0
- package/src/core/jobs.ts +4 -3
- package/src/core/layout.ts +5 -2
- package/src/core/squircle.ts +95 -0
- package/src/home/daemon-jobs.ts +26 -2
- package/src/home/global-units.ts +3 -0
- package/src/home/gui-app/ShipkitGui.swift +302 -5
- package/src/home/gui-app.ts +63 -33
- package/src/home/hmr-keep.ts +134 -0
- package/src/home/home-start.ts +2 -2
- package/src/home/lib-watch.ts +21 -11
- package/src/home/pm.ts +1 -1
- package/src/home/process-apps.ts +181 -0
- package/src/home/resources.ts +3 -3
- package/src/home/run-web.ts +7 -4
- package/src/home/serve-web.ts +64 -14
- package/src/identities/collection.ts +49 -0
- package/src/identities/identities.ts +110 -8
- package/src/identities/machine.ts +4 -3
- package/src/identities/rating.ts +33 -0
- package/src/identities/shown.ts +170 -0
- package/src/identities/steps.ts +5 -0
- package/src/media-store/purge.ts +15 -1
- package/src/media-store/remote.ts +22 -6
- package/src/messages/brief.ts +117 -0
- package/src/messages/collection.ts +40 -0
- package/src/messages/model.ts +171 -0
- package/src/messages/routes.ts +15 -0
- package/src/messages/score.ts +180 -0
- package/src/messages/tabs.ts +13 -0
- package/src/release/notes.ts +130 -0
- package/src/release/run-bump.ts +41 -18
- package/src/release/run-release.ts +22 -4
- package/src/release/run-releases.ts +17 -15
- package/src/release/unit-resolve.ts +9 -0
- package/src/releases/add.ts +66 -0
- package/src/releases/collection.ts +36 -0
- package/src/releases/from-card.ts +66 -0
- package/src/releases/model.ts +267 -0
- package/src/releases/pictures.ts +89 -0
- package/src/releases/routes.ts +36 -0
- package/src/releases/store.ts +71 -0
- package/src/repo-config.ts +5 -0
- package/src/review/cells.ts +0 -11
- package/src/review/format.ts +10 -6
- package/src/review/model.ts +92 -3
- package/src/review/notes.ts +2 -48
- package/src/review/routes.ts +28 -10
- package/src/review/stage-card.ts +197 -0
- package/src/review/stage-routes.ts +123 -0
- package/src/review/store.ts +36 -0
- package/src/review/trailer-card.ts +99 -0
- package/src/review/trailer-desk.ts +57 -4
- package/src/review/trailer-model.ts +41 -7
- package/src/review/trailer-notes.ts +45 -0
- package/src/review/trailer-routes.ts +22 -13
- package/src/serve/hub-app/app-bridge.ts +71 -0
- package/src/serve/hub-app/commands/commands-page.tsx +122 -0
- package/src/serve/hub-app/commands/commands-st.ts +177 -0
- package/src/serve/hub-app/commands.css +24 -0
- package/src/serve/hub-app/hash-route.ts +40 -1
- package/src/serve/hub-app/home-st.ts +11 -2
- package/src/serve/hub-app/home.html +3 -0
- package/src/serve/hub-app/hub-app.tsx +6 -0
- package/src/serve/hub-app/icons.tsx +5 -0
- package/src/serve/hub-app/identities-view.tsx +4 -1
- package/src/serve/hub-app/identities.css +1 -0
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/keys.ts +2 -2
- package/src/serve/hub-app/machine-st.ts +41 -10
- package/src/serve/hub-app/messages/messages-page.tsx +354 -0
- package/src/serve/hub-app/messages/messages-st.ts +74 -0
- package/src/serve/hub-app/messages.css +35 -0
- package/src/serve/hub-app/releases/releases-page.tsx +94 -0
- package/src/serve/hub-app/releases/releases-st.ts +69 -0
- package/src/serve/hub-app/releases.css +25 -0
- package/src/serve/hub-app/repo-sections.ts +15 -1
- package/src/serve/hub-app/repo-st.ts +56 -5
- package/src/serve/hub-app/review/clip-st.ts +31 -3
- package/src/serve/hub-app/review/note-place.ts +31 -0
- package/src/serve/hub-app/review/review-cells.tsx +27 -3
- package/src/serve/hub-app/review/review-st.ts +77 -2
- package/src/serve/hub-app/review/review-thread.tsx +9 -31
- package/src/serve/hub-app/review/review-views.tsx +164 -58
- package/src/serve/hub-app/review/thread-st.ts +108 -41
- package/src/serve/hub-app/review/trailer-card.tsx +187 -0
- package/src/serve/hub-app/review/trailer-page.tsx +62 -31
- package/src/serve/hub-app/review/trailer-st.ts +138 -26
- package/src/serve/hub-app/review/trailer-timeline.tsx +39 -26
- package/src/serve/hub-app/review.css +49 -6
- package/src/serve/hub-app/social/comms-page.tsx +55 -23
- package/src/serve/hub-app/social/identity-pictures.ts +46 -8
- package/src/serve/hub-app/social/kit.tsx +9 -6
- package/src/serve/hub-app/social/post-card.tsx +10 -2
- package/src/serve/hub-app/social/social-model.ts +37 -3
- package/src/serve/hub-app/social/social-page.tsx +179 -65
- package/src/serve/hub-app/social/social-st.ts +79 -26
- package/src/serve/hub-app/social/stage-popup.tsx +268 -0
- package/src/serve/hub-app/social/stage-st.ts +310 -0
- package/src/serve/hub-app/social/step-layout.ts +42 -0
- package/src/serve/hub-app/social.css +60 -1
- package/src/serve/hub-app/tree-build.ts +38 -1
- package/src/serve/hub-app/tree-svc.ts +10 -3
- package/src/serve/project-gutter-route.ts +4 -2
- package/src/serve/same-origin.ts +24 -1
- package/src/serve/serve-hub.ts +15 -1
- package/src/shipkit-files.ts +9 -7
- package/src/shot/shooter.ts +3 -3
- package/src/shot/shot-ask.ts +14 -3
- package/src/shot/shot.shipkit.ts +1 -1
- package/src/social/discord-layout.ts +48 -5
- package/src/social/fit.ts +84 -0
- package/src/social/identity-words.ts +74 -0
- package/src/social/kind-pages.ts +41 -0
- package/src/social/kinds.ts +92 -0
- package/src/social/load.ts +105 -9
- package/src/social/media-limit.ts +63 -2
- package/src/social/presence.ts +1 -1
- package/src/social/publish/bluesky.ts +58 -19
- package/src/social/publish/index.ts +31 -5
- package/src/social/reach.ts +49 -0
- package/src/social/release-stage.ts +173 -0
- package/src/social/routes.ts +42 -7
- package/src/social/stage.ts +227 -0
- package/src/social/strip.ts +85 -0
- package/src/social/text.ts +6 -2
- package/src/social/unit.ts +57 -1
- package/src/social/writes.ts +11 -0
- package/src/trailer/build.ts +15 -2
- package/src/trailer/grammar.ts +14 -4
- package/src/trailer/public-words.ts +41 -0
package/src/review/model.ts
CHANGED
|
@@ -74,7 +74,7 @@ export interface Spec {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
/** the kinds every repo has, whatever its unit declares */
|
|
77
|
-
export const BUILTIN_KINDS: Record<string, SpecKind> = { shot: { label: 'images' }, screen: { label: 'screens' }, frame: { label: 'trailer frames' }, store: { label: 'store pages', icon: '🏪' }, post: { label: 'post requests', icon: '📣' } }
|
|
77
|
+
export const BUILTIN_KINDS: Record<string, SpecKind> = { shot: { label: 'images' }, screen: { label: 'screens' }, frame: { label: 'trailer frames' }, trailer: { label: 'trailers', icon: '🎬' }, store: { label: 'store pages', icon: '🏪' }, post: { label: 'post requests', icon: '📣' } }
|
|
78
78
|
|
|
79
79
|
export const NO_SPEC: Spec = { kinds: {}, topics: {}, dispatcher: false }
|
|
80
80
|
|
|
@@ -175,6 +175,19 @@ export const isGallery = (v: ReviewView): v is GalleryView => 'gallery' in v
|
|
|
175
175
|
|
|
176
176
|
export const SHA_RE = /^[0-9a-f]{64}$/
|
|
177
177
|
|
|
178
|
+
/** a card's public change: the release category it goes under and its one line, the `### ` title */
|
|
179
|
+
export interface CardChangelog {
|
|
180
|
+
category: string
|
|
181
|
+
line: string
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** `--changelog "<category>: <line>"` read; a line with no category throws saying the shape */
|
|
185
|
+
export function changelogOfFlag(s: string): CardChangelog {
|
|
186
|
+
const m = /^([^:]+):\s*(.+)$/.exec(s.trim())
|
|
187
|
+
if (!m || m[1]!.trim() === '' || m[2]!.trim() === '') throw new Error(`--changelog "${s}": "<category>: <public line>", like "Studio: Move the body anywhere on the floor"`)
|
|
188
|
+
return { category: m[1]!.trim(), line: m[2]!.trim() }
|
|
189
|
+
}
|
|
190
|
+
|
|
178
191
|
/** `item.json`: the head, written at creation, changed by `add-view`, a draft's refresh and the media facts it lacks */
|
|
179
192
|
export interface Item {
|
|
180
193
|
id: string
|
|
@@ -185,6 +198,11 @@ export interface Item {
|
|
|
185
198
|
title: string
|
|
186
199
|
/** an agent card's markdown: what changed and why */
|
|
187
200
|
what?: string
|
|
201
|
+
/** the public line its agent wrote for a post of it (`--post`), checked by the repo's guard at add */
|
|
202
|
+
post?: string
|
|
203
|
+
/** the change its approval adds to the release being filled (`--changelog "<category>: <line>"`, releases/from-card.ts),
|
|
204
|
+
* checked by the repo's guard at add */
|
|
205
|
+
changelog?: CardChangelog
|
|
188
206
|
topic?: string
|
|
189
207
|
commit?: string
|
|
190
208
|
/** a media view (an image, a clip, a sound, a pair) or a gallery of images, any of them first */
|
|
@@ -202,10 +220,33 @@ export interface Item {
|
|
|
202
220
|
wip?: { live: string; frame: number }
|
|
203
221
|
/** a choice: every view is an option, he scores them and picks one */
|
|
204
222
|
choice?: true
|
|
223
|
+
/** on a choice: the option its agent suggests, the view's index (the hub's « my pick » pill); his own pick is the verdict's */
|
|
224
|
+
agentPick?: number
|
|
225
|
+
/** a trailer card: its body plays this cut in the trailer entry's player, never a compiled clip */
|
|
226
|
+
trailer?: TrailerCard
|
|
205
227
|
/** each media file the views name, by its name: what the Space keeps it under once the disk lets it go */
|
|
206
228
|
media?: Record<string, MediaFact>
|
|
207
229
|
}
|
|
208
230
|
|
|
231
|
+
/** one render a trailer card plays: the cut, and the render pinned by its mtime in ms */
|
|
232
|
+
export interface TrailerSide {
|
|
233
|
+
cut: string
|
|
234
|
+
render: number
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** what a trailer card plays (wiki tools/shipkit/review.md, A trailer): a cut of `trailer/<trailer>/`, the render it is
|
|
238
|
+
* compared with, the shots the change touched by name */
|
|
239
|
+
export interface TrailerCard {
|
|
240
|
+
trailer: string
|
|
241
|
+
after: TrailerSide
|
|
242
|
+
before?: TrailerSide
|
|
243
|
+
shots: string[]
|
|
244
|
+
/** the cut's frame in pixels: what his rectangles on it measure in */
|
|
245
|
+
size?: [number, number]
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export const isTrailerCard = (i: Item): i is Item & { trailer: TrailerCard } => i.trailer !== undefined
|
|
249
|
+
|
|
209
250
|
/** a choice card: he picks one of its views */
|
|
210
251
|
export const isChoice = (i: Item): boolean => i.choice === true
|
|
211
252
|
|
|
@@ -256,6 +297,16 @@ export const viewTag = (n: number, i: number): string => `${n}.${viewLetter(i)}`
|
|
|
256
297
|
/** a view's name as the page and the CLI show it: its label, or « view B » */
|
|
257
298
|
export const viewName = (v: ReviewView | undefined, i: number): string => v?.label || `view ${viewLetter(i)}`
|
|
258
299
|
|
|
300
|
+
/** a view named by its label, else by its letter (`B`); throws naming every view when none matches */
|
|
301
|
+
export function viewIndexOf(views: readonly { label: string }[], ref: string): number {
|
|
302
|
+
const r = ref.trim()
|
|
303
|
+
const byLabel = views.findIndex((v) => v.label === r)
|
|
304
|
+
if (r !== '' && byLabel >= 0) return byLabel
|
|
305
|
+
const byLetter = views.findIndex((_, i) => viewLetter(i) === r.toUpperCase())
|
|
306
|
+
if (r !== '' && byLetter >= 0) return byLetter
|
|
307
|
+
throw new Error(`« ${ref} » names no view: ${views.map((v, i) => `${viewLetter(i)}${v.label ? ` "${v.label}"` : ''}`).join(', ')}`)
|
|
308
|
+
}
|
|
309
|
+
|
|
259
310
|
/** every media file a card's views name: images, pairs, clips and their posters, sounds and their waveforms, tiles */
|
|
260
311
|
export function viewFilesOf(i: Item): string[] {
|
|
261
312
|
return i.views.flatMap((v) => {
|
|
@@ -282,7 +333,8 @@ export const onFrame = (t: number, time: number, fps: number): boolean => Math.f
|
|
|
282
333
|
export type Side = 'before' | 'after'
|
|
283
334
|
|
|
284
335
|
/** a rectangle on a view, normalized 0..1; w = h = 0 is a pin. `view` the index of its view, absent on the first;
|
|
285
|
-
* `side` only on a pair; `t` only on a clip
|
|
336
|
+
* `side` only on a pair (on a trailer card with a before, the render it is drawn on); `t` only on a clip or a trailer
|
|
337
|
+
* card's frame */
|
|
286
338
|
export interface Rect {
|
|
287
339
|
x: number
|
|
288
340
|
y: number
|
|
@@ -293,6 +345,8 @@ export interface Rect {
|
|
|
293
345
|
side?: Side
|
|
294
346
|
/** the clip time it was drawn at, in seconds */
|
|
295
347
|
t?: number
|
|
348
|
+
/** on a trailer card's frame: the shot it sits on and the seconds into it, so a new render places it */
|
|
349
|
+
shot?: { name: string; time: number }
|
|
296
350
|
/** the gallery tile it is drawn on, its coordinates the tile's image */
|
|
297
351
|
tile?: number
|
|
298
352
|
world?: { x0: number; y0: number; x1: number; y1: number }
|
|
@@ -783,6 +837,16 @@ function originProblems(o: unknown): string[] {
|
|
|
783
837
|
return ['origin.by: agent, owner, player or auto']
|
|
784
838
|
}
|
|
785
839
|
|
|
840
|
+
function trailerCardProblems(t: unknown): string[] {
|
|
841
|
+
const side = (v: unknown): boolean => obj(v) && typeof v.cut === 'string' && v.cut !== '' && typeof v.render === 'number' && Number.isFinite(v.render)
|
|
842
|
+
if (!obj(t) || typeof t.trailer !== 'string' || t.trailer === '' || !side(t.after)) return ['trailer: { trailer, after: { cut, render }, before?, shots }']
|
|
843
|
+
const out: string[] = []
|
|
844
|
+
if (t.before !== undefined && !side(t.before)) out.push('trailer.before: { cut, render }, or absent')
|
|
845
|
+
if (!Array.isArray(t.shots) || !t.shots.every((s) => typeof s === 'string' && s !== '')) out.push('trailer.shots: a list of shot names')
|
|
846
|
+
if (t.size !== undefined && !(Array.isArray(t.size) && t.size.length === 2 && t.size.every((n) => Number.isInteger(n) && (n as number) > 0))) out.push('trailer.size: [width, height] in pixels, or absent')
|
|
847
|
+
return out
|
|
848
|
+
}
|
|
849
|
+
|
|
786
850
|
/** every reason an item.json read back is not an item; empty: it is one */
|
|
787
851
|
export function itemProblems(v: unknown): string[] {
|
|
788
852
|
if (!obj(v)) return ['not an object']
|
|
@@ -801,10 +865,15 @@ export function itemProblems(v: unknown): string[] {
|
|
|
801
865
|
})
|
|
802
866
|
if (v.answers !== undefined && !(Array.isArray(v.answers) && v.answers.length > 0 && v.answers.every((a) => typeof a === 'string' && ID_RE.test(a))))
|
|
803
867
|
out.push('answers: a list of item ids')
|
|
804
|
-
for (const k of ['what', 'commit', 'supersedes', 'why', 'keeps']) if (v[k] !== undefined && typeof v[k] !== 'string') out.push(`${k}: a text`)
|
|
868
|
+
for (const k of ['what', 'post', 'commit', 'supersedes', 'why', 'keeps']) if (v[k] !== undefined && typeof v[k] !== 'string') out.push(`${k}: a text`)
|
|
869
|
+
if (v.changelog !== undefined && !(obj(v.changelog) && typeof v.changelog.category === 'string' && v.changelog.category.trim() !== '' && typeof v.changelog.line === 'string' && v.changelog.line.trim() !== ''))
|
|
870
|
+
out.push('changelog: { category, line }, or absent')
|
|
805
871
|
if (v.light !== undefined && v.light !== 'review') out.push('light: review, or absent')
|
|
806
872
|
if (v.wip !== undefined && !(obj(v.wip) && typeof v.wip.live === 'string' && v.wip.live !== '' && Number.isInteger(v.wip.frame))) out.push('wip: { live, frame }, or absent')
|
|
873
|
+
if (v.trailer !== undefined) out.push(...trailerCardProblems(v.trailer))
|
|
807
874
|
if (v.choice !== undefined && !(v.choice === true && Array.isArray(v.views) && v.views.length >= 2)) out.push('choice: true on a card of two views or more, or absent')
|
|
875
|
+
if (v.agentPick !== undefined && !(v.choice === true && Number.isInteger(v.agentPick) && Array.isArray(v.views) && (v.agentPick as number) >= 0 && (v.agentPick as number) < v.views.length))
|
|
876
|
+
out.push('agentPick: the index of one of its views, on a choice card, or absent')
|
|
808
877
|
if (v.media !== undefined) {
|
|
809
878
|
if (!obj(v.media)) out.push('media: { <file name>: { sha, size, type } }, or absent')
|
|
810
879
|
else
|
|
@@ -896,6 +965,21 @@ function viewProblems(v: Record<string, unknown>, at: string): string[] {
|
|
|
896
965
|
}
|
|
897
966
|
|
|
898
967
|
/** the verdict the page sends for an item, checked: every rectangle inside its view, a side exactly on a pair */
|
|
968
|
+
/** what a rectangle on a trailer card's frame carries beyond its box: the time on the cut it was drawn at, the shot and
|
|
969
|
+
* the seconds into it, and with a before the render it sits on; null with its errors pushed */
|
|
970
|
+
function trailerRect(r: Record<string, unknown>, t: TrailerCard, i: number, errors: string[]): Pick<Rect, 't' | 'shot' | 'side'> | null {
|
|
971
|
+
const at = r.t
|
|
972
|
+
const shot = r.shot as { name?: unknown; time?: unknown } | undefined
|
|
973
|
+
const bad: string[] = []
|
|
974
|
+
if (typeof at !== 'number' || !Number.isFinite(at) || at < 0) bad.push(`rects[${i}].t: the time on the cut it was drawn at`)
|
|
975
|
+
if (!obj(shot) || typeof shot.name !== 'string' || shot.name === '' || typeof shot.time !== 'number' || !Number.isFinite(shot.time) || shot.time < 0)
|
|
976
|
+
bad.push(`rects[${i}].shot: { name, time }, the shot it sits on and the seconds into it`)
|
|
977
|
+
if (t.before ? r.side !== 'before' && r.side !== 'after' : r.side !== undefined) bad.push(`rects[${i}].side: ${t.before ? 'before or after, the render it is drawn on' : 'none on a trailer card with no before'}`)
|
|
978
|
+
errors.push(...bad)
|
|
979
|
+
if (bad.length > 0 || !obj(shot)) return null
|
|
980
|
+
return { t: at as number, shot: { name: shot.name as string, time: shot.time as number }, ...(t.before ? { side: r.side as Side } : {}) }
|
|
981
|
+
}
|
|
982
|
+
|
|
899
983
|
export function verdictMessageOf(body: unknown, item: Item): { ok: true; message: Pick<Message, 'verdict' | 'text' | 'rects' | 'reactions' | 'pick'> } | { ok: false; errors: string[] } {
|
|
900
984
|
if (!obj(body)) return { ok: false, errors: ['not an object'] }
|
|
901
985
|
const errors: string[] = []
|
|
@@ -932,6 +1016,11 @@ export function verdictMessageOf(body: unknown, item: Item): { ok: true; message
|
|
|
932
1016
|
errors.push(`rects[${i}].view: no rectangle on a sound, react to the view instead`)
|
|
933
1017
|
continue
|
|
934
1018
|
}
|
|
1019
|
+
if (view === 0 && isTrailerCard(item)) {
|
|
1020
|
+
const r2 = trailerRect(r, item.trailer, i, errors)
|
|
1021
|
+
if (r2) out.push({ x: r.x, y: r.y, w: r.w, h: r.h, comment: typeof r.comment === 'string' ? r.comment : '', ...r2 })
|
|
1022
|
+
continue
|
|
1023
|
+
}
|
|
935
1024
|
const pair = isPair(on.files)
|
|
936
1025
|
if (pair && r.side !== 'before' && r.side !== 'after') errors.push(`rects[${i}].side: before or after, on a pair`)
|
|
937
1026
|
if (!pair && r.side !== undefined) errors.push(`rects[${i}].side: none on a single image`)
|
package/src/review/notes.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
// his notes on one thing a desk shows (a store page's picture or field, a draft): the first an item of the one store,
|
|
2
2
|
// its subject the thing, so the review page and `sk review inbox` hold it; the next ones, while that thread is open,
|
|
3
3
|
// his replies on it, never a second item. The one path for a note on a thing (wiki tools/shipkit/stores.md)
|
|
4
|
-
import {
|
|
5
|
-
import { isPostSubject, stateOf, subjectKey, type Origin, type PostSubject, type ReviewItem, type Subject } from './model.ts'
|
|
4
|
+
import { stateOf, subjectKey, type Origin, type ReviewItem, type Subject } from './model.ts'
|
|
6
5
|
import { addMessage, raiseItem, readAll, specOf } from './store.ts'
|
|
7
|
-
import {
|
|
6
|
+
import { membersOf, threadsOf, type Thread } from './threads.ts'
|
|
8
7
|
|
|
9
8
|
/** one note as a desk shows it: the owner's words, where it stands, the agent's last word once answered */
|
|
10
9
|
export type SubjectNote = { id: string; at: string; text: string; state: string; answer?: string }
|
|
@@ -78,48 +77,3 @@ export async function noteOn(
|
|
|
78
77
|
return { id: x.item.id }
|
|
79
78
|
}
|
|
80
79
|
|
|
81
|
-
/** a post the owner asked from a card and no draft answers yet: what Communications lists on top of its drafts */
|
|
82
|
-
export type AskedPost = { id: string; at: string; card: string; title: string; text: string; state: string }
|
|
83
|
-
|
|
84
|
-
/** every post request not closed, oldest first: the card's title as it is now, the owner's words joined */
|
|
85
|
-
export function askedPosts(items: readonly ReviewItem[]): AskedPost[] {
|
|
86
|
-
const threads = threadsOf(items)
|
|
87
|
-
const followed = followedIds(items)
|
|
88
|
-
return items
|
|
89
|
-
.filter((x) => isPostSubject(x.item.subject))
|
|
90
|
-
.map((x) => ({ x, st: stateOf(x, followed.has(x.item.id)) }))
|
|
91
|
-
.filter(({ st }) => st.state !== 'closed')
|
|
92
|
-
.sort((a, b) => a.x.item.created.localeCompare(b.x.item.created))
|
|
93
|
-
.map(({ x, st }) => {
|
|
94
|
-
const card = (x.item.subject as PostSubject).card
|
|
95
|
-
const t = threadOfId(card, threads)
|
|
96
|
-
const words = x.thread.filter((m) => m.who === 'owner' && m.op === undefined && m.verdict === undefined && m.text !== undefined).map((m) => m.text as string)
|
|
97
|
-
return { id: x.item.id, at: x.item.created, card: t?.head.item.id ?? card, title: t?.head.item.title ?? card, text: words.join('\n'), state: st.state }
|
|
98
|
-
})
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** « 📣 post » on a card: a request for its own public post, keyed on the card's first version so every version asks
|
|
102
|
-
* the same one; `topic` the social unit's notes topic, left out where the store's topics lack it */
|
|
103
|
-
export async function askPost(dir: string, o: { card: string; text?: string; topic?: string }): Promise<{ id: string }> {
|
|
104
|
-
const t = threadOfId(o.card, threadsOf(readAll(dir).items))
|
|
105
|
-
if (!t) throw new Error(`post: no card ${o.card}`)
|
|
106
|
-
const head = t.head.item
|
|
107
|
-
if (isPostSubject(head.subject)) throw new Error('post: this card is itself a post request')
|
|
108
|
-
const first = t.versions.at(-1)?.item.id ?? head.id
|
|
109
|
-
const spec = specOf(dir)
|
|
110
|
-
const topic = o.topic !== undefined && (Object.keys(spec.topics).length === 0 || spec.topics[o.topic]) ? o.topic : undefined
|
|
111
|
-
const subject: PostSubject = { kind: 'post', card: first }
|
|
112
|
-
return noteOn(dir, {
|
|
113
|
-
subject,
|
|
114
|
-
origin: { by: 'owner', from: 'review' },
|
|
115
|
-
name: `post « ${head.title} »`,
|
|
116
|
-
text: o.text?.trim() || 'this card deserves its own post',
|
|
117
|
-
...(topic ? { topic } : {}),
|
|
118
|
-
what: [
|
|
119
|
-
`A public post from the card « ${head.title} » (${head.id}).`,
|
|
120
|
-
`- read the card: \`sk review show ${head.id}\`; its views are the post's media`,
|
|
121
|
-
`- write the draft: \`.shipkit/social/drafts/<YYYYMMDD-HHMMSS>-<topic>/draft.md\`, \`review: ${head.id}\` in its front matter, the media in its \`media/\` (wiki tools/shipkit/social.md)`,
|
|
122
|
-
'- close this request: `sk review fixed <this id> --note "draft <slug>"`',
|
|
123
|
-
].join('\n'),
|
|
124
|
-
})
|
|
125
|
-
}
|
package/src/review/routes.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// the hub's review routes (wiki tools/shipkit/review.md, The hub): the store's list, an item's images and clips, the
|
|
2
2
|
// owner's verdicts, replies and read marks appended to its thread. The trailer view's routes: trailer-routes.ts. Paths are
|
|
3
3
|
// relative to the repo hub's base. null: not a path of these
|
|
4
|
-
import { existsSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
4
|
+
import { existsSync, mkdtempSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
5
5
|
import { tmpdir } from 'node:os'
|
|
6
6
|
import { dirname, extname, join } from 'node:path'
|
|
7
7
|
import { isAnimFormat, isAnimLabels, isAnimMode, pairAnimation } from './anim.ts'
|
|
8
8
|
import { startAuto } from './auto.ts'
|
|
9
9
|
import { bad, KEEP, NO_STORE, ranged, tagged, TYPES } from './http.ts'
|
|
10
10
|
import { viewFilesOf, type Rect, type ReviewItem, type Subject } from './model.ts'
|
|
11
|
-
import {
|
|
11
|
+
import { stageGet, stagePost } from './stage-routes.ts'
|
|
12
12
|
import { pasteHosts } from './paste.ts'
|
|
13
13
|
import { openReview, partFile, viewOfItem } from './project.ts'
|
|
14
14
|
import { isPreviewSize, previewOrRemote, warmPreviews } from './previews.ts'
|
|
@@ -23,8 +23,8 @@ import { trailerRoutes } from './trailer-routes.ts'
|
|
|
23
23
|
import { specData, type ReviewUnit } from './unit.ts'
|
|
24
24
|
import { liveWatchers } from './watchers.ts'
|
|
25
25
|
import { autoRulesOf } from '../veille/auto.ts'
|
|
26
|
-
import { loadSocialUnit } from '../social/unit.ts'
|
|
27
26
|
import { draftsOfCard } from '../social/card-drafts.ts'
|
|
27
|
+
import { draftsDir } from '../social/load.ts'
|
|
28
28
|
|
|
29
29
|
// ── each repo's review unit, read again at most every 5 s; its auto rules scheduled in this server while it serves ──
|
|
30
30
|
|
|
@@ -50,6 +50,19 @@ async function project(root: string): Promise<{ dir: string; unit: ReviewUnit |
|
|
|
50
50
|
return { dir, unit }
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/** an approved card's changelog line into next.md (releases/from-card.ts), after the verdict answered: a failure says so
|
|
54
|
+
* on the card's thread and in the hub's log, so the change is never lost in silence */
|
|
55
|
+
async function changeOnVerdict(dir: string, id: string): Promise<void> {
|
|
56
|
+
try {
|
|
57
|
+
const { onVerdict } = await import('../releases/from-card.ts')
|
|
58
|
+
await onVerdict(dirname(dirname(dir)), id)
|
|
59
|
+
} catch (e) {
|
|
60
|
+
const why = (e as Error).message
|
|
61
|
+
console.error(`FAIL: the release did not take the change of ${id}: ${why}`)
|
|
62
|
+
addMessage(dir, id, 'releases', `the release did not take this change: ${why}. Run sk releases add --card ${id}`)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
53
66
|
/** an image the page sent as a data url, written to a scratch file the caller removes */
|
|
54
67
|
function dataUrlFile(url: unknown): { file: string; done(): void } | null {
|
|
55
68
|
if (url === undefined || url === null) return null
|
|
@@ -148,7 +161,9 @@ async function reviewRoute(req: Request, path: string, dir: string, unit: Review
|
|
|
148
161
|
}
|
|
149
162
|
const t = threadOfId(id, x.threads)
|
|
150
163
|
if (!t) return bad(`no item ${ref}`, 404)
|
|
151
|
-
|
|
164
|
+
// a draft staged from the card moves the drafts folder, not the store: its time joins the tag
|
|
165
|
+
const staged = statSync(draftsDir(dirname(dirname(dir))), { throwIfNoEntry: false })?.mtimeMs ?? 0
|
|
166
|
+
return tagged(req, `${x.tag.slice(0, -1)}.${Math.round(staged)}"`, () => {
|
|
152
167
|
const members = membersOf(t)
|
|
153
168
|
return { ...threadView(t, readAllCached(dir).items, x.threads, id), missing: missingOf(dir, members), drafts: draftsOfCard(dirname(dirname(dir)), new Set(members.map((m) => m.item.id))) }
|
|
154
169
|
})
|
|
@@ -231,14 +246,10 @@ async function reviewRoute(req: Request, path: string, dir: string, unit: Review
|
|
|
231
246
|
try {
|
|
232
247
|
if (name === 'feedback') {
|
|
233
248
|
const r = writeVerdict(dir, id, await req.json())
|
|
249
|
+
if (r.ok) void changeOnVerdict(dir, id)
|
|
234
250
|
return r.ok ? Response.json(r.message, { headers: NO_STORE }) : Response.json({ error: r.errors.join('\n'), errors: r.errors }, { status: 400, headers: NO_STORE })
|
|
235
251
|
}
|
|
236
|
-
if (name === '
|
|
237
|
-
const b = (await req.json().catch(() => ({}))) as { text?: unknown }
|
|
238
|
-
const social = await loadSocialUnit(dirname(dirname(dir)))
|
|
239
|
-
const text = typeof b.text === 'string' ? b.text : undefined
|
|
240
|
-
return Response.json(await askPost(dir, { card: id, topic: social?.notes ?? 'social', ...(text ? { text } : {}) }), { headers: NO_STORE })
|
|
241
|
-
}
|
|
252
|
+
if (name === 'stage') return await stagePost(dirname(dirname(dir)), dir, id, unit, (await req.json().catch(() => ({}))) as Record<string, unknown>)
|
|
242
253
|
if (name === 'reply') return Response.json(addMessage(dir, id, 'owner', ((await req.json()) as { text?: unknown }).text), { headers: NO_STORE })
|
|
243
254
|
if (name === 'read') {
|
|
244
255
|
// the page names the words it drew: a word that came after them stays unread
|
|
@@ -268,6 +279,13 @@ async function reviewRoute(req: Request, path: string, dir: string, unit: Review
|
|
|
268
279
|
return bad(`POST ${path}?`, 404)
|
|
269
280
|
}
|
|
270
281
|
if (req.method !== 'GET') return null
|
|
282
|
+
if (name === 'stage') {
|
|
283
|
+
try {
|
|
284
|
+
return await stageGet(dirname(dirname(dir)), dir, id)
|
|
285
|
+
} catch (e) {
|
|
286
|
+
return bad(e)
|
|
287
|
+
}
|
|
288
|
+
}
|
|
271
289
|
// a kind's data view of one item, computed here: the page never runs the repo's code
|
|
272
290
|
if (name === 'view') {
|
|
273
291
|
try {
|
|
@@ -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
|
+
}
|