rvlib-shipkit 2.19.0 → 2.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/package.json +1 -1
- package/src/annex/annex.ts +227 -0
- package/src/annex/offload.ts +279 -0
- package/src/checks/SK004-gitignore-policy.check.ts +6 -3
- 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_GlobalProcesses.ts +2 -107
- package/src/cli/cmd_Home.ts +4 -3
- package/src/cli/cmd_Messages.ts +155 -0
- package/src/cli/cmd_Overview.ts +2 -1
- package/src/cli/cmd_Releases.ts +84 -0
- package/src/cli/cmd_Review.ts +176 -12
- package/src/cli/cmd_Shot.ts +4 -4
- package/src/cli/cmd_Social.ts +151 -8
- package/src/cli/cmd_Sound.ts +17 -4
- package/src/cli/cmd_Trailer.ts +67 -1
- 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 +7 -1
- package/src/collections/collection-types.ts +8 -1
- package/src/collections/providers.ts +4 -1
- package/src/collections/review.ts +23 -4
- 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 +11 -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 +337 -5
- package/src/home/gui-app.ts +64 -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-switch.ts +112 -0
- 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 +121 -14
- 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 +182 -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 +94 -0
- package/src/releases/before.ts +31 -0
- package/src/releases/collection.ts +36 -0
- package/src/releases/from-card.ts +151 -0
- package/src/releases/model.ts +327 -0
- package/src/releases/pictures.ts +110 -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/http.ts +1 -1
- package/src/review/model.ts +102 -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 +47 -1
- package/src/review/trailer-card.ts +99 -0
- package/src/review/trailer-desk.ts +76 -4
- package/src/review/trailer-model.ts +106 -7
- package/src/review/trailer-notes.ts +45 -0
- package/src/review/trailer-routes.ts +119 -13
- package/src/review/trailer-voices.ts +144 -0
- package/src/review/watchers.ts +58 -1
- package/src/serve/hub-app/app-bridge.ts +71 -0
- package/src/serve/hub-app/benign-errors.ts +22 -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 +59 -8
- package/src/serve/hub-app/home-st.ts +19 -2
- package/src/serve/hub-app/home.html +3 -0
- package/src/serve/hub-app/hub-app.tsx +8 -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/project-list.css +7 -2
- package/src/serve/hub-app/project-list.tsx +9 -0
- package/src/serve/hub-app/projects-svc.ts +16 -6
- package/src/serve/hub-app/releases/releases-page.tsx +187 -0
- package/src/serve/hub-app/releases/releases-st.ts +111 -0
- package/src/serve/hub-app/releases.css +52 -0
- package/src/serve/hub-app/repo-sections.ts +16 -2
- package/src/serve/hub-app/repo-st.ts +66 -10
- package/src/serve/hub-app/review/clip-st.ts +34 -4
- package/src/serve/hub-app/review/kit.tsx +3 -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 +92 -36
- package/src/serve/hub-app/review/trailer-st.ts +306 -34
- package/src/serve/hub-app/review/trailer-timeline.tsx +68 -23
- package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
- package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
- package/src/serve/hub-app/review.css +137 -6
- package/src/serve/hub-app/social/comms-page.tsx +65 -28
- 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/next-release.tsx +118 -0
- package/src/serve/hub-app/social/post-card.tsx +10 -2
- package/src/serve/hub-app/social/social-model.ts +39 -3
- package/src/serve/hub-app/social/social-page.tsx +179 -65
- package/src/serve/hub-app/social/social-st.ts +117 -27
- 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 +68 -1
- package/src/serve/hub-app/tree-build.ts +40 -1
- package/src/serve/hub-app/tree-svc.ts +10 -3
- package/src/serve/project-gutter-route.ts +12 -2
- package/src/serve/project-gutter.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/box.ts +33 -12
- package/src/shot/client.ts +1 -1
- package/src/shot/shooter.ts +22 -12
- package/src/shot/shot-ask.ts +14 -3
- package/src/shot/shot.shipkit.ts +1 -1
- package/src/social/desk-index.ts +49 -8
- package/src/social/discord-layout.ts +54 -7
- package/src/social/drafts.ts +1 -1
- 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 +93 -0
- package/src/social/load.ts +125 -10
- 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 +47 -6
- package/src/social/reach.ts +49 -0
- package/src/social/release-stage.ts +277 -0
- package/src/social/routes.ts +44 -8
- package/src/social/stage.ts +246 -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/bed.ts +111 -0
- package/src/trailer/build.ts +72 -40
- package/src/trailer/ffmpeg.ts +6 -0
- package/src/trailer/grammar.ts +37 -6
- package/src/trailer/graph.ts +12 -1
- package/src/trailer/public-words.ts +41 -0
- package/src/trailer/shot-plan.ts +75 -0
- package/src/trailer/shot-state.ts +191 -0
- package/src/trailer/sound/audio.ts +28 -0
- package/src/trailer/sound/brand.ts +53 -3
- package/src/trailer/sound/gen.ts +61 -2
- package/src/trailer/sound/index.ts +25 -11
- package/src/trailer/sound/presets.ts +86 -5
- package/src/trailer/sound/run.ts +1 -1
- package/src/trailer/sound/takes.ts +94 -0
- package/src/trailer/titles.ts +36 -0
- package/src/trailer/url.ts +1 -1
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// what each account shows (wiki tools/shipkit/social-identities.md, What each account shows): `shown.md` beside its
|
|
2
|
+
// account.md records the sha of the picture each row was last given, or of the text he last pasted; a picture row
|
|
3
|
+
// whose files moved since, or that names none recorded, is stale; a text row only once recorded and moved. The one
|
|
4
|
+
// constraint: only a push or his « Done, uploaded » or « Done, pasted » writes a row, never a guess
|
|
5
|
+
import { existsSync, readFileSync, statSync, writeFileSync } from 'node:fs'
|
|
6
|
+
import { join } from 'node:path'
|
|
7
|
+
import { parseFrontmatter, table, type ProfileRow } from '../social/md.ts'
|
|
8
|
+
import { otherRating, ratingIn } from './rating.ts'
|
|
9
|
+
|
|
10
|
+
export const SHOWN_FILE = 'shown.md'
|
|
11
|
+
|
|
12
|
+
/** one recorded row: the short sha the account was given, that file (relative to the identity's `files`), the day */
|
|
13
|
+
export type ShownRow = { row: string; sha: string; file: string; on: string }
|
|
14
|
+
|
|
15
|
+
/** who sets a row: Discord's bot, Bluesky's api, or null, his hands */
|
|
16
|
+
export type Uploader = 'discord' | 'bluesky' | null
|
|
17
|
+
|
|
18
|
+
/** a picture row he uploads, or a text row he pastes */
|
|
19
|
+
export type ShownKind = 'picture' | 'text'
|
|
20
|
+
|
|
21
|
+
/** the file column of a text row: it names no file */
|
|
22
|
+
export const TEXT_FILE = 'text'
|
|
23
|
+
|
|
24
|
+
/** one picture or text row of an account and what the account shows of it */
|
|
25
|
+
export type Upload = {
|
|
26
|
+
field: string
|
|
27
|
+
kind: ShownKind
|
|
28
|
+
/** the row's files, relative to the identity's `files`; the first is what a push sends; none for a text */
|
|
29
|
+
files: string[]
|
|
30
|
+
/** the same files, absolute */
|
|
31
|
+
abs: string[]
|
|
32
|
+
/** each file's short sha now, in the same order; '' for one the disk cannot read; a text: its value's sha alone */
|
|
33
|
+
shas: string[]
|
|
34
|
+
/** the recorded row; null, nobody knows what the account shows */
|
|
35
|
+
shown: ShownRow | null
|
|
36
|
+
/** a picture: its recorded sha is none of its files' as they are now; a text: recorded, and its value moved since */
|
|
37
|
+
stale: boolean
|
|
38
|
+
by: Uploader
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** a server's picture rows the bot sets, by the field Discord's guild takes them in */
|
|
42
|
+
export const DISCORD_ROWS: Readonly<Record<string, string>> = { icon: 'icon', banner: 'banner', 'invite splash': 'splash' }
|
|
43
|
+
/** the profile rows Bluesky's api sets, by the field of app.bsky.actor.profile */
|
|
44
|
+
export const BLUESKY_ROWS: Readonly<Record<string, string>> = { avatar: 'avatar', banner: 'banner' }
|
|
45
|
+
|
|
46
|
+
const held = new Map<string, { stamp: string; sha: string }>()
|
|
47
|
+
|
|
48
|
+
/** a file's short sha (sha256, 12 hex), read again only when its size or mtime moves; '' when it cannot be read */
|
|
49
|
+
export function shaOf(abs: string): string {
|
|
50
|
+
const st = statSync(abs, { throwIfNoEntry: false })
|
|
51
|
+
if (st == null || !st.isFile()) return ''
|
|
52
|
+
const stamp = `${st.size}:${st.mtimeMs}`
|
|
53
|
+
const at = held.get(abs)
|
|
54
|
+
if (at?.stamp === stamp) return at.sha
|
|
55
|
+
const sha = new Bun.CryptoHasher('sha256').update(readFileSync(abs)).digest('hex').slice(0, 12)
|
|
56
|
+
held.set(abs, { stamp, sha })
|
|
57
|
+
return sha
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** a text's short sha (sha256, 12 hex): the value he pastes, its lines as they are */
|
|
61
|
+
export const textSha = (value: string): string => new Bun.CryptoHasher('sha256').update(value).digest('hex').slice(0, 12)
|
|
62
|
+
|
|
63
|
+
/** the rows of an account's `shown.md`; none when it has no file */
|
|
64
|
+
export function readShown(dir: string): ShownRow[] {
|
|
65
|
+
const abs = join(dir, SHOWN_FILE)
|
|
66
|
+
if (!existsSync(abs)) return []
|
|
67
|
+
return table(parseFrontmatter(readFileSync(abs, 'utf8')).body, 'Shown').map(([row = '', sha = '', file = '', on = '']) => ({ row, sha, file, on }))
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const page = (name: string, list: readonly ShownRow[]): string =>
|
|
71
|
+
[
|
|
72
|
+
`# What ${name} shows`,
|
|
73
|
+
'',
|
|
74
|
+
"The picture each profile row of this account was last given, or the text last pasted (file `text`), by its short sha (sha256, 12 hex). Written by a push (`sk identities push`, `sk social discord apply`) and by « Done, uploaded » or « Done, pasted » in the hub's identity view. A picture row not here is unknown, so it is to upload; a text row not here is unknown and quiet (wiki tools/shipkit/social-identities.md, What each account shows).",
|
|
75
|
+
'',
|
|
76
|
+
'## Shown',
|
|
77
|
+
'',
|
|
78
|
+
'| row | sha | file | on |',
|
|
79
|
+
'|---|---|---|---|',
|
|
80
|
+
...list.map((r) => `| ${r.row} | ${r.sha} | ${r.file} | ${r.on} |`),
|
|
81
|
+
'',
|
|
82
|
+
].join('\n')
|
|
83
|
+
|
|
84
|
+
/** one row recorded in the account's `shown.md`, the others kept in their order; the file's path, absolute */
|
|
85
|
+
export function writeShown(dir: string, name: string, row: ShownRow): string {
|
|
86
|
+
const list = readShown(dir)
|
|
87
|
+
const at = list.findIndex((r) => r.row === row.row)
|
|
88
|
+
if (at === -1) list.push(row)
|
|
89
|
+
else list[at] = row
|
|
90
|
+
const abs = join(dir, SHOWN_FILE)
|
|
91
|
+
writeFileSync(abs, page(name, list))
|
|
92
|
+
return abs
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
type Of = { id: string; guild: string; secret: string; automation: string }
|
|
96
|
+
|
|
97
|
+
/** who sets a row of this account */
|
|
98
|
+
export function uploaderOf(a: Of, field: string): Uploader {
|
|
99
|
+
if (a.id === 'discord' && a.guild !== '' && a.secret !== '' && field in DISCORD_ROWS) return 'discord'
|
|
100
|
+
if (a.id === 'bluesky' && a.automation === 'live' && a.secret !== '' && field in BLUESKY_ROWS) return 'bluesky'
|
|
101
|
+
return null
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** the picture rows an account shows, each with what it shows: its rating's, and a row of the other rating only when
|
|
105
|
+
* the account names it itself (`avatar sfw` on an nsfw venue that also takes an SFW variant), never one it inherits
|
|
106
|
+
* (`avatar nsfw` of the identity on an sfw venue); `files` the folder its paths are relative to. Then the text rows he
|
|
107
|
+
* pastes: the ones `pasted` names (its setup's refs), or with no setup (null) every text row but `rating`; each by the
|
|
108
|
+
* sha of its value as filled, stale only once recorded and moved since */
|
|
109
|
+
export function uploadsOf(a: Of, rows: readonly ProfileRow[], dir: string, files: string | null, own: ReadonlySet<string> = new Set(), pasted: ReadonlySet<string> | null = null): Upload[] {
|
|
110
|
+
const rating = ratingIn(rows)
|
|
111
|
+
const shown = readShown(dir)
|
|
112
|
+
const at = (field: string): ShownRow | null => shown.find((x) => x.row === field) ?? null
|
|
113
|
+
const pictures: Upload[] =
|
|
114
|
+
files == null
|
|
115
|
+
? []
|
|
116
|
+
: rows
|
|
117
|
+
.filter((r) => r.files.length > 0 && (!otherRating(r.field, rating) || own.has(r.field)))
|
|
118
|
+
.map((r) => {
|
|
119
|
+
const abs = r.files.map((f) => join(files, f))
|
|
120
|
+
const shas = abs.map(shaOf)
|
|
121
|
+
const s = at(r.field)
|
|
122
|
+
return { field: r.field, kind: 'picture', files: r.files, abs, shas, shown: s, stale: s == null || s.sha === '' || !shas.includes(s.sha), by: uploaderOf(a, r.field) }
|
|
123
|
+
})
|
|
124
|
+
const texts: Upload[] = rows
|
|
125
|
+
.filter((r) => (files == null || r.files.length === 0) && (pasted == null ? r.field !== 'rating' : pasted.has(r.field)))
|
|
126
|
+
.map((r) => {
|
|
127
|
+
const sha = textSha(r.value)
|
|
128
|
+
const s = at(r.field)
|
|
129
|
+
return { field: r.field, kind: 'text', files: [], abs: [], shas: [sha], shown: s, stale: s != null && s.sha !== sha, by: null }
|
|
130
|
+
})
|
|
131
|
+
return [...pictures, ...texts]
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** the day a row is recorded on, local time */
|
|
135
|
+
export const today = (): string => {
|
|
136
|
+
const d = new Date()
|
|
137
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** a row recorded as given its file now: `file` one of the row's own files (never a path from elsewhere), else its
|
|
141
|
+
* first; a text row as pasted with its value now. `sha`, the one the page showed: refused when the row moved since, so
|
|
142
|
+
* he never records what he did not copy. Throws on a row the account does not show */
|
|
143
|
+
export function recordShown(a: { name: string; dir: string; uploads: readonly Upload[] }, field: string, file?: string, sha?: string): { abs: string; row: ShownRow } {
|
|
144
|
+
const u = a.uploads.find((x) => x.field === field)
|
|
145
|
+
if (u == null) throw new Error(`${a.name} shows no picture or text row "${field}" (${a.uploads.map((x) => x.field).join(', ') || 'none'})`)
|
|
146
|
+
if (u.kind === 'text') {
|
|
147
|
+
if (file != null) throw new Error(`${a.name} ${field} is a text row: it names no file`)
|
|
148
|
+
if (sha != null && sha !== u.shas[0]) throw new Error(`${a.name} ${field} changed since the page showed it: copy it again, then press « Done, pasted »`)
|
|
149
|
+
const row = { row: field, sha: u.shas[0]!, file: TEXT_FILE, on: today() }
|
|
150
|
+
return { abs: writeShown(a.dir, a.name, row), row }
|
|
151
|
+
}
|
|
152
|
+
if (sha != null && !u.shas.includes(sha)) throw new Error(`${a.name} ${field} changed since the page showed it: download it again`)
|
|
153
|
+
const i = file == null ? 0 : u.files.indexOf(file)
|
|
154
|
+
if (i === -1) throw new Error(`${a.name} ${field}: "${file}" is none of its files (${u.files.join(', ')})`)
|
|
155
|
+
if (u.shas[i] === '') throw new Error(`${a.name} ${field}: ${u.files[i]} cannot be read`)
|
|
156
|
+
const row = { row: field, sha: u.shas[i]!, file: u.files[i]!, on: today() }
|
|
157
|
+
return { abs: writeShown(a.dir, a.name, row), row }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** what a picture push did, or would do dry: its lines, the rows it left and why, the `shown.md` files it wrote */
|
|
161
|
+
export type PushReport = { changes: string[]; left: string[]; recorded: string[] }
|
|
162
|
+
|
|
163
|
+
/** the rows an api of this kind sets and that are stale: a push sends each its first file */
|
|
164
|
+
export const toPush = (uploads: readonly Upload[], by: Exclude<Uploader, null>): Upload[] => uploads.filter((u) => u.by === by && u.stale && u.shas[0] !== '')
|
|
165
|
+
|
|
166
|
+
/** a pushed row recorded as given its first file */
|
|
167
|
+
export const recordPushed = (a: { name: string; dir: string }, u: Upload): string => writeShown(a.dir, a.name, { row: u.field, sha: u.shas[0]!, file: u.files[0]!, on: today() })
|
|
168
|
+
|
|
169
|
+
/** the stale rows of an account, as one line's words: « avatar, banner » */
|
|
170
|
+
export const staleWords = (uploads: readonly Upload[]): string => uploads.filter((u) => u.stale).map((u) => u.field).join(', ')
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// an account's setup steps (wiki tools/shipkit/social-identities.md, The accounts): `[[field]]` names a row of its
|
|
2
|
+
// form. Pure: the hub's bundle reads it too
|
|
3
|
+
|
|
4
|
+
/** the rows the steps name, `[[field]]`: the form he fills */
|
|
5
|
+
export const stepRefs = (list: readonly { text: string }[]): Set<string> => new Set(list.flatMap((s) => [...s.text.matchAll(/\[\[([^\]]+)\]\]/g)].map((m) => m[1]!)))
|
package/src/media-store/purge.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// form, `join(store, item, name)`, from the same index rows
|
|
5
5
|
import { existsSync, rmSync, statSync, statfsSync } from 'node:fs'
|
|
6
6
|
import { join, resolve } from 'node:path'
|
|
7
|
+
import { annexKeep, annexSweep, presentAnnexes } from '../annex/annex.ts'
|
|
7
8
|
import { mediaDb, tryWrite } from './db.ts'
|
|
8
9
|
import type { MediaKind } from './kind.ts'
|
|
9
10
|
import type { Space } from './space.ts'
|
|
@@ -66,13 +67,16 @@ export interface PurgeResult {
|
|
|
66
67
|
files: number
|
|
67
68
|
/** a file the HEAD or its kind did not confirm: left on the disk */
|
|
68
69
|
refused: { key: string; why: string }[]
|
|
70
|
+
/** of the files freed, those whose content an annex holds, and the bytes this pass copied there (one content at
|
|
71
|
+
* four paths is copied once) */
|
|
72
|
+
annexed: { files: number; bytes: number }
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
/** free the disk of the candidates, oldest first, until `enough` says stop, `jobs` files at a time: each file waits
|
|
72
76
|
* on its HEAD and its kind's check, so one at a time spends the purge on round trips. A file some process holds open
|
|
73
77
|
* stays */
|
|
74
78
|
export async function purge(kind: MediaKind, dir: string, space: Space, list: readonly Candidate[], o: { enough?: () => boolean; say?: (l: string) => void; jobs?: number } = {}): Promise<PurgeResult> {
|
|
75
|
-
const out: PurgeResult = { freed: 0, files: 0, refused: [] }
|
|
79
|
+
const out: PurgeResult = { freed: 0, files: 0, refused: [], annexed: { files: 0, bytes: 0 } }
|
|
76
80
|
const store = resolve(dir)
|
|
77
81
|
const open = openOf(list.map((c) => join(store, c.item, c.name)))
|
|
78
82
|
let said = Date.now()
|
|
@@ -96,6 +100,15 @@ export async function purge(kind: MediaKind, dir: string, space: Space, list: re
|
|
|
96
100
|
out.refused.push({ key: c.key, why: (e as Error).message })
|
|
97
101
|
return
|
|
98
102
|
}
|
|
103
|
+
try {
|
|
104
|
+
const kept = await annexKeep(path, c.key, c.size)
|
|
105
|
+
if (kept) {
|
|
106
|
+
out.annexed.files++
|
|
107
|
+
if (kept.copied) out.annexed.bytes += c.size
|
|
108
|
+
}
|
|
109
|
+
} catch (e) {
|
|
110
|
+
console.error(`WARN media store: ${(e as Error).message}; the Space holds it, the disk lets it go`)
|
|
111
|
+
}
|
|
99
112
|
rmSync(path, { force: true })
|
|
100
113
|
tryWrite(`${c.item}/${c.name} purged`, (db) => void db.query('update files set local = 0, purged = ? where store = ? and item = ? and name = ?').run(Date.now(), store, c.item, c.name))
|
|
101
114
|
out.freed += c.size
|
|
@@ -114,6 +127,7 @@ export async function purge(kind: MediaKind, dir: string, space: Space, list: re
|
|
|
114
127
|
}
|
|
115
128
|
}
|
|
116
129
|
await Promise.all(Array.from({ length: Math.max(1, o.jobs ?? PURGE_JOBS) }, work))
|
|
130
|
+
if (out.annexed.files > 0) for (const a of await presentAnnexes()) annexSweep(a)
|
|
117
131
|
return out
|
|
118
132
|
}
|
|
119
133
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// a media file from the disk or the Space (wiki tools/shipkit/media-store.md, Read): a URL signed for a file the disk
|
|
2
|
-
// let go, and the file fetched back into its place, checked by its sha, for a tool that needs its bytes
|
|
2
|
+
// let go, and the file fetched back into its place, checked by its sha, for a tool that needs its bytes: from the
|
|
3
|
+
// annex first (wiki tools/shipkit/annex.md), else from the Space
|
|
3
4
|
import { existsSync, renameSync, rmSync, statSync } from 'node:fs'
|
|
4
5
|
import { resolve } from 'node:path'
|
|
6
|
+
import { annexCopy, annexDrop } from '../annex/annex.ts'
|
|
5
7
|
import { shaOf } from './content.ts'
|
|
6
8
|
import { mediaDb, tryWrite } from './db.ts'
|
|
7
9
|
import type { MediaFact } from './fact.ts'
|
|
@@ -65,28 +67,42 @@ export async function signedIfUp(key: string): Promise<string | null> {
|
|
|
65
67
|
|
|
66
68
|
const fetching = new Map<string, Promise<string | null>>()
|
|
67
69
|
|
|
68
|
-
/** the file at `path`, fetched back
|
|
70
|
+
/** the file at `path`, fetched back first when the disk let it go, from an annex else the Space: checked by its sha before it lands,
|
|
69
71
|
* its index row marked local again (`row`: the store, item and name it is indexed under). null when neither holds it */
|
|
70
72
|
export function fetchBack(path: string, key: string, f: MediaFact, row?: { store: string; item: string; name: string }): Promise<string | null> {
|
|
71
73
|
if (existsSync(path)) return Promise.resolve(path)
|
|
72
74
|
const held = fetching.get(path)
|
|
73
75
|
if (held) return held
|
|
74
76
|
const job = (async (): Promise<string | null> => {
|
|
77
|
+
const tmp = `${path}.${process.pid}.back`
|
|
78
|
+
const done = (): string => {
|
|
79
|
+
renameSync(tmp, path)
|
|
80
|
+
if (row) tryWrite(`${row.item}/${row.name} back`, (db) => void db.query('update files set local = 1, purged = null where store = ? and item = ? and name = ?').run(resolve(row.store), row.item, row.name))
|
|
81
|
+
return path
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const at = await annexCopy(key, f.size, tmp)
|
|
85
|
+
if (at) {
|
|
86
|
+
const sha = await shaOf(tmp)
|
|
87
|
+
if (sha === f.sha) return done()
|
|
88
|
+
annexDrop(at, `it hashes to ${sha.slice(0, 12)}, the record of ${key} says ${f.sha.slice(0, 12)}`)
|
|
89
|
+
}
|
|
90
|
+
} catch (e) {
|
|
91
|
+
console.error(`WARN media store: ${path} not read from the annex: ${(e as Error).message}`)
|
|
92
|
+
}
|
|
93
|
+
rmSync(tmp, { force: true })
|
|
75
94
|
const space = (await machineSpace()).space
|
|
76
95
|
if (!space || !(await confirmedUp(key, f.size))) return null
|
|
77
|
-
const tmp = `${path}.${process.pid}.back`
|
|
78
96
|
try {
|
|
79
97
|
await space.get(key, tmp)
|
|
80
98
|
const sha = await shaOf(tmp)
|
|
81
99
|
if (sha !== f.sha || statSync(tmp).size !== f.size) throw new Error(`${key}: the bytes fetched back hash to ${sha.slice(0, 12)}, the record says ${f.sha.slice(0, 12)}`)
|
|
82
|
-
|
|
100
|
+
return done()
|
|
83
101
|
} catch (e) {
|
|
84
102
|
rmSync(tmp, { force: true })
|
|
85
103
|
console.error(`FAIL: media store: ${path} not fetched back: ${(e as Error).message}`)
|
|
86
104
|
return null
|
|
87
105
|
}
|
|
88
|
-
if (row) tryWrite(`${row.item}/${row.name} back`, (db) => void db.query('update files set local = 1, purged = null where store = ? and item = ? and name = ?').run(resolve(row.store), row.item, row.name))
|
|
89
|
-
return path
|
|
90
106
|
})().finally(() => fetching.delete(path))
|
|
91
107
|
fetching.set(path, job)
|
|
92
108
|
return job
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// the prompt a run's sub-agent follows word for word (wiki tools/shipkit/messages.md, The loop): a reader of one
|
|
2
|
+
// persona, the gatekeepers, a judge of some messages, a surface's reader or gatekeepers. Every run uses the same words,
|
|
3
|
+
// so two runs differ only by their phrasings; what the product is comes from the store's brief.md, never from here
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import type { Store } from './model.ts'
|
|
6
|
+
import { shuffled } from './score.ts'
|
|
7
|
+
|
|
8
|
+
const USAGE = 'messages: brief <run> reader <persona> | gatekeepers | judge <message,...> | surface <surface>:<persona> | surface-gatekeepers <surface>'
|
|
9
|
+
|
|
10
|
+
/** a paragraph and the blank line after it, or nothing when the store gives none */
|
|
11
|
+
const para = (text: string): string[] => (text ? [text, ''] : [])
|
|
12
|
+
|
|
13
|
+
export function briefOf(s: Store, kind: string, run: string, who: string): string {
|
|
14
|
+
const { personas, messages, brief: b } = s
|
|
15
|
+
const dir = join(s.dir, 'runs', run)
|
|
16
|
+
if (kind === 'reader') {
|
|
17
|
+
const p = personas.find((x) => x.id === who && x.kind === 'reader')
|
|
18
|
+
if (!p) throw new Error(`messages: no reader "${who}" in personas.md`)
|
|
19
|
+
return [
|
|
20
|
+
`You are a blind reader in a message test. Read ONLY ${join(dir, 'packets', `${p.id}.md`)} (sets of short lines; each set is one idea phrased several ways). Open no other file, search nothing, run no command except writing your two output files: your first reaction is the data.`,
|
|
21
|
+
'',
|
|
22
|
+
`You are **${p.id}**: ${p.who}`,
|
|
23
|
+
'',
|
|
24
|
+
`Each line is one line on the page of ${b.what} (a bullet, a title in a trailer, a post), seen with nothing else. Read the sets in the order given. Stay in character and honest.`,
|
|
25
|
+
'',
|
|
26
|
+
'For EVERY line, write one JSON object: "id" (the line\'s id), "said" (what the line tells you, 12 words or fewer), "gain" (what YOU would get from it, 10 words or fewer, or "nothing"), "believe" (0 no, 1 maybe, 2 yes), "appeal" (would it make you look further, 1 to 5), "friction" (the word that bothers or confuses you, or "").',
|
|
27
|
+
`Write the whole array as valid JSON to ${join(dir, 'readings', `${p.id}.json`)} with the Write tool.`,
|
|
28
|
+
`Then write ${join(dir, 'notes', `${p.id}.md`)}: per set, your favourite id and the line you would write instead (8 words or fewer)${b.readerNotes ? `; then: ${b.readerNotes}` : '.'}`,
|
|
29
|
+
'',
|
|
30
|
+
'Reply with two lines only: how many lines you read, and your favourite line of all.',
|
|
31
|
+
].join('\n')
|
|
32
|
+
}
|
|
33
|
+
if (kind === 'gatekeepers') {
|
|
34
|
+
const gs = personas.filter((p) => p.kind === 'gatekeeper')
|
|
35
|
+
if (!gs.length) throw new Error('messages: no gatekeeper in personas.md')
|
|
36
|
+
return [
|
|
37
|
+
`You play ${gs.length} gatekeepers in a message test, each judged on its own: ${gs.map((g) => g.id).join(', ')}. Read ONLY ${join(dir, 'packets', `${gs[0]!.id}.md`)}: that one sheet holds the lines every one of them judges. Open no other file.`,
|
|
38
|
+
'',
|
|
39
|
+
...para(b.gatekeepers),
|
|
40
|
+
...gs.map((g) => `- **${g.id}**: ${g.who}`),
|
|
41
|
+
'',
|
|
42
|
+
`For each one, judge EVERY line and write a JSON array of {"id", "verdict", "words": what drives it or ""} with the Write tool, one file a gatekeeper: ${gs.map((g) => join(dir, 'verdicts', `${g.id}.json`)).join(', ')}. Be realistic: reserve the harsh verdicts for what would truly trigger them.`,
|
|
43
|
+
'',
|
|
44
|
+
`Reply with ${gs.length} lines, one a gatekeeper: its id, the ids it refuses, then the ids it flags.`,
|
|
45
|
+
].join('\n')
|
|
46
|
+
}
|
|
47
|
+
if (kind === 'judge') {
|
|
48
|
+
const ids = who.split(',')
|
|
49
|
+
const missing = ids.filter((id) => !messages.some((m) => m.id === id))
|
|
50
|
+
if (missing.length) throw new Error(`messages: no message ${missing.join(', ')}`)
|
|
51
|
+
const readers = personas.filter((p) => p.kind === 'reader').map((p) => p.id)
|
|
52
|
+
return [
|
|
53
|
+
`You judge a message test. Read ${join(s.dir, 'messages.md')} and judge only the messages ${ids.join(', ')}: each has a meaning (what a reader must take away), a value (the gain we want them to see) and its lines.`,
|
|
54
|
+
`Then read ${readers.map((r) => join(dir, 'readings', `${r}.json`)).join(', ')}: per line, what each reader said and the gain they named.`,
|
|
55
|
+
'',
|
|
56
|
+
`For every line of your messages and every reader: "understood" 0 missed or wrong, 1 the gist with a key part missing, 2 got it; "value" 0 no gain or an unrelated one, 1 near ours, 2 the gain we meant in their own terms. Judge the reader's words, never whether you like the line.${b.judge ? ` ${b.judge}` : ''}`,
|
|
57
|
+
'Judge each reading one by one: never fill the scores from a rule, a table or a script.',
|
|
58
|
+
'',
|
|
59
|
+
`Write one JSON array of {"id", "persona", "understood", "value"} to ${join(dir, 'judged', `${ids[0]}.json`)} with the Write tool.`,
|
|
60
|
+
'',
|
|
61
|
+
'Reply with one line: how many entries you wrote.',
|
|
62
|
+
].join('\n')
|
|
63
|
+
}
|
|
64
|
+
if (kind === 'surface' || kind === 'surface-gatekeepers') {
|
|
65
|
+
const [sid, pid] = who.split(':')
|
|
66
|
+
const sf = s.surfaces.find((x) => x.id === sid)
|
|
67
|
+
if (!sf) throw new Error(`messages: no surface "${sid}" in surfaces.md`)
|
|
68
|
+
const two = sf.options.some((o) => o.second)
|
|
69
|
+
const sheet = sf.options.map((o) => (two ? `- ${o.id}: "${o.headline}" / "${o.second}"` : `- ${o.id}: "${o.headline}"`)).join('\n')
|
|
70
|
+
const said = two ? 'the first text is the title on screen, the second what the narrator says over the same shot' : 'the line is a title on screen or what the narrator says'
|
|
71
|
+
const shot = sf.shot ? [`Each option is one moment of a trailer for ${b.what}, a cut of 1 to 2 seconds over the shot below; ${said}.`, '', `> ${sf.shot}`, ''] : []
|
|
72
|
+
if (kind === 'surface-gatekeepers') {
|
|
73
|
+
const gs = personas.filter((p) => p.kind === 'gatekeeper')
|
|
74
|
+
return [
|
|
75
|
+
`You play ${gs.length} gatekeepers in a message test, each judged on its own. The options for one place (${sf.title}):`,
|
|
76
|
+
'',
|
|
77
|
+
...shot,
|
|
78
|
+
sheet,
|
|
79
|
+
'',
|
|
80
|
+
...para(b.surfaceGatekeepers),
|
|
81
|
+
...gs.map((g) => `- **${g.id}**: ${g.who}`),
|
|
82
|
+
'',
|
|
83
|
+
`For each one write a JSON array of {"id", "verdict", "words": what drives it or ""} to ${join(dir, 'verdicts', '<id>.json')} with the Write tool. Be realistic: reserve the harsh verdicts for what would truly trigger them.`,
|
|
84
|
+
'',
|
|
85
|
+
'Reply with one line a gatekeeper: anything not allowed or not neutral.',
|
|
86
|
+
].join('\n')
|
|
87
|
+
}
|
|
88
|
+
const p = personas.find((x) => x.id === pid && x.kind === 'reader')
|
|
89
|
+
if (!p) throw new Error(`messages: no reader "${pid}" in personas.md`)
|
|
90
|
+
const order = shuffled(sf.options, `${run}/${p.id}`).map((o) => o.id).join(', ')
|
|
91
|
+
const trailer = two
|
|
92
|
+
? 'For each, FIRST picture the title alone over the shot, THEN with the narrator\'s line. "alone_appeal": 1-5, the title alone over the shot; "appeal": 1-5, both together: would it make you want to try the app; "repeats": 1 if the narrator only says the title again, else 0.'
|
|
93
|
+
: '"alone_appeal": 1-5, the line read alone, with no picture; "appeal": 1-5, the line over the shot as you watch the trailer: would it make you want to try the app; "repeats": 0.'
|
|
94
|
+
const how = sf.shot
|
|
95
|
+
? trailer
|
|
96
|
+
: two
|
|
97
|
+
? 'For each, FIRST cover the second line and read the headline alone (as a link preview shows it), THEN read both. "alone_appeal": 1-5 click from the headline alone; "appeal": 1-5 click with both lines; "repeats": 1 if the two lines repeat each other, else 0.'
|
|
98
|
+
: 'Each option is the whole text of a profile, seen under a name and an avatar in a feed or a reply. "alone_appeal": 1-5, would you open the profile\'s link; "appeal": 1-5, would you follow; "repeats": 0.'
|
|
99
|
+
const took = b.takeaways.map((t) => `"${t.id}": 1 if you got ${t.text} else 0, `).join('')
|
|
100
|
+
return [
|
|
101
|
+
`You are a blind reader in a message test. Here are the options for one place (${sf.title}). Open no file, search nothing; your first reaction is the data.`,
|
|
102
|
+
'',
|
|
103
|
+
...shot,
|
|
104
|
+
sheet,
|
|
105
|
+
'',
|
|
106
|
+
`You are **${p.id}**: ${p.who}`,
|
|
107
|
+
'',
|
|
108
|
+
`Read the options in this order: ${order}. ${how}`,
|
|
109
|
+
'',
|
|
110
|
+
`Write a JSON array, one object per option, to ${join(dir, 'readings', `${p.id}.json`)} with the Write tool: {"option", "said": what it is, 12 words max, "alone_appeal", "appeal", ${took}"gain": what YOU would get, 10 words max, "repeats", "friction": the word that bothers you or ""}.`,
|
|
111
|
+
`Then write ${join(dir, 'notes', `${p.id}.md`)}: your top 2 and why in a line each, the one you would never pick, and the text you would write yourself within the same length.`,
|
|
112
|
+
'',
|
|
113
|
+
'Reply with two lines: your top 2, and the one you would never pick.',
|
|
114
|
+
].join('\n')
|
|
115
|
+
}
|
|
116
|
+
throw new Error(USAGE)
|
|
117
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// the messages page's tabs as tree rows (wiki tools/shipkit/messages.md, The page): the four after Messages, each
|
|
2
|
+
// opening its tab, its count in the slot. Only where the repo has a store, so the section of a repo with none is
|
|
3
|
+
// greyed. Counted from the files' headings alone: the tree recomputes often
|
|
4
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import { MESSAGES_COL, type Collection, type Instance } from '../collections/collection-types.ts'
|
|
7
|
+
import { MESSAGES_DIR } from './model.ts'
|
|
8
|
+
import { MESSAGES_TABS } from './tabs.ts'
|
|
9
|
+
|
|
10
|
+
const headings = (f: string, re: RegExp): number => (existsSync(f) ? (readFileSync(f, 'utf8').replace(/<!--[\s\S]*?-->/g, '').match(re)?.length ?? 0) : 0)
|
|
11
|
+
|
|
12
|
+
export function messagesCollection(root: string): Collection | null {
|
|
13
|
+
const dir = join(root, MESSAGES_DIR)
|
|
14
|
+
if (!existsSync(join(dir, 'messages.md'))) return null
|
|
15
|
+
return {
|
|
16
|
+
id: MESSAGES_COL,
|
|
17
|
+
title: 'messages',
|
|
18
|
+
kind: 'message',
|
|
19
|
+
media: 'text',
|
|
20
|
+
list: async () => {
|
|
21
|
+
// what each tab ranks: the messages, the personas, the page tops; the notes are a run's, so no count
|
|
22
|
+
const counts: Record<string, number> = {
|
|
23
|
+
value: headings(join(dir, 'messages.md'), /^## [\w-]+: /gm),
|
|
24
|
+
personas: headings(join(dir, 'personas.md'), /^## [\w-]+ \(/gm),
|
|
25
|
+
surfaces: headings(join(dir, 'surfaces.md'), /^## [\w-]+: /gm),
|
|
26
|
+
}
|
|
27
|
+
const file: Record<string, string> = { value: 'messages.md', personas: 'personas.md', surfaces: 'surfaces.md', notes: 'runs' }
|
|
28
|
+
return MESSAGES_TABS.slice(1).map(([tab, label], i): Instance => ({
|
|
29
|
+
id: `message:${tab}`,
|
|
30
|
+
text: `the messages page, ${label}`,
|
|
31
|
+
label,
|
|
32
|
+
order: i,
|
|
33
|
+
...(counts[tab] === undefined ? {} : { slot: String(counts[tab]) }),
|
|
34
|
+
type: 'message',
|
|
35
|
+
path: `${MESSAGES_DIR}/${file[tab]}`,
|
|
36
|
+
state: 'idle',
|
|
37
|
+
}))
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// the messages store (wiki tools/shipkit/messages.md): `.shipkit/messages/` read as text, every file parsed here. A
|
|
2
|
+
// message is a meaning, never its words; its phrasings are the candidates a run scores. The repo's own words (what its
|
|
3
|
+
// public lines may never say) are its social unit's guard, never a list here: the lint asks that guard
|
|
4
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
|
|
7
|
+
/** the store, from the repo root */
|
|
8
|
+
export const MESSAGES_DIR = '.shipkit/messages'
|
|
9
|
+
|
|
10
|
+
export type Candidate = { id: string; text: string; source: string; words: number; seconds: number }
|
|
11
|
+
export type Message = { id: string; title: string; fields: Record<string, string>; candidates: Candidate[] }
|
|
12
|
+
export type Persona = { id: string; kind: 'reader' | 'gatekeeper'; who: string }
|
|
13
|
+
/** `shot`: a trailer line's surface, the picture it sits over (a title or the narrator's line in a 1 to 2 s cut) */
|
|
14
|
+
export type Surface = { id: string; title: string; budget?: number; shot?: string; options: { id: string; headline: string; second: string }[] }
|
|
15
|
+
/** one thing a surface reader may get or miss (brief.md `takeaways`): its JSON key, its column, the words it asks */
|
|
16
|
+
export type Takeaway = { id: string; label: string; text: string }
|
|
17
|
+
/** the repo's words a run's briefs carry (brief.md), so the briefs themselves say nothing of any product */
|
|
18
|
+
export type Brief = { what: string; gatekeepers: string; surfaceGatekeepers: string; readerNotes: string; judge: string; takeaways: Takeaway[] }
|
|
19
|
+
|
|
20
|
+
/** spoken english runs about 2.5 words a second */
|
|
21
|
+
const WORDS_A_SECOND = 2.5
|
|
22
|
+
const wordsOf = (t: string): number => t.split(/\s+/).filter((w) => /[\p{L}\d]/u.test(w)).length
|
|
23
|
+
const dropComments = (md: string): string => md.replace(/<!--[\s\S]*?-->/g, '')
|
|
24
|
+
|
|
25
|
+
export function parseMessages(md: string): Message[] {
|
|
26
|
+
const out: Message[] = []
|
|
27
|
+
for (const line of dropComments(md).split('\n')) {
|
|
28
|
+
const head = /^## ([\w-]+): (.+)$/.exec(line)
|
|
29
|
+
if (head) out.push({ id: head[1]!, title: head[2]!, fields: {}, candidates: [] })
|
|
30
|
+
const cur = out.at(-1)
|
|
31
|
+
if (!cur || head) continue
|
|
32
|
+
const cand = /^- `([\w-]+)` "([^"]+)"\s*(.*)$/.exec(line)
|
|
33
|
+
if (cand) {
|
|
34
|
+
const words = wordsOf(cand[2]!)
|
|
35
|
+
cur.candidates.push({ id: cand[1]!, text: cand[2]!, source: cand[3]!, words, seconds: Math.round((words / WORDS_A_SECOND) * 10) / 10 })
|
|
36
|
+
continue
|
|
37
|
+
}
|
|
38
|
+
const field = /^- (\w+): (.+)$/.exec(line)
|
|
39
|
+
if (field) cur.fields[field[1]!] = field[2]!
|
|
40
|
+
}
|
|
41
|
+
return out
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function parsePersonas(md: string): Persona[] {
|
|
45
|
+
const out: Persona[] = []
|
|
46
|
+
for (const block of dropComments(md).split(/^## /m).slice(1)) {
|
|
47
|
+
const m = /^([\w-]+) \((reader|gatekeeper)\)\n([\s\S]*)$/.exec(block)
|
|
48
|
+
if (!m) throw new Error(`messages: a persona section reads "## <id> (reader|gatekeeper)": ${block.split('\n')[0]}`)
|
|
49
|
+
out.push({ id: m[1]!, kind: m[2] as Persona['kind'], who: m[3]!.trim() })
|
|
50
|
+
}
|
|
51
|
+
return out
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function parseSurfaces(md: string): Surface[] {
|
|
55
|
+
const out: Surface[] = []
|
|
56
|
+
for (const line of dropComments(md).split('\n')) {
|
|
57
|
+
const head = /^## ([\w-]+): (.+)$/.exec(line)
|
|
58
|
+
if (head) out.push({ id: head[1]!, title: head[2]!, options: [] })
|
|
59
|
+
const cur = out.at(-1)
|
|
60
|
+
const budget = /^- budget: (\d+) characters/.exec(line)
|
|
61
|
+
if (budget && cur) cur.budget = Number(budget[1])
|
|
62
|
+
const shot = /^- shot: (.+)$/.exec(line)
|
|
63
|
+
if (shot && cur) cur.shot = shot[1]!
|
|
64
|
+
const o = /^- `([\w-]+)` "([^"]+)"(?: \/ "([^"]+)")?/.exec(line)
|
|
65
|
+
if (o && cur) cur.options.push({ id: o[1]!, headline: o[2]!, second: o[3] ?? '' })
|
|
66
|
+
}
|
|
67
|
+
return out
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const BRIEF_KEYS = { what: 'what', gatekeepers: 'gatekeepers', 'surface gatekeepers': 'surfaceGatekeepers', 'reader notes': 'readerNotes', judge: 'judge', takeaways: 'takeaways' } as const
|
|
71
|
+
|
|
72
|
+
/** brief.md: one `## <key>` section a part, its text as written; an unknown key fails the read with the keys named */
|
|
73
|
+
export function parseBrief(md: string): Brief {
|
|
74
|
+
const out: Brief = { what: 'this product', gatekeepers: '', surfaceGatekeepers: '', readerNotes: '', judge: '', takeaways: [] }
|
|
75
|
+
for (const block of dropComments(md).split(/^## /m).slice(1)) {
|
|
76
|
+
const nl = block.indexOf('\n')
|
|
77
|
+
const head = (nl === -1 ? block : block.slice(0, nl)).trim()
|
|
78
|
+
const body = nl === -1 ? '' : block.slice(nl + 1).trim()
|
|
79
|
+
const key = BRIEF_KEYS[head as keyof typeof BRIEF_KEYS]
|
|
80
|
+
if (key === undefined) throw new Error(`messages: brief.md has no section "${head}": ${Object.keys(BRIEF_KEYS).join(', ')}`)
|
|
81
|
+
if (key !== 'takeaways') {
|
|
82
|
+
out[key] = body
|
|
83
|
+
continue
|
|
84
|
+
}
|
|
85
|
+
for (const l of body.split('\n')) {
|
|
86
|
+
const m = /^- `([\w-]+)` ([^:]+): (.+)$/.exec(l.trim())
|
|
87
|
+
if (m) out.takeaways.push({ id: m[1]!, label: m[2]!.trim(), text: m[3]!.trim() })
|
|
88
|
+
else if (l.trim() !== '') throw new Error(`messages: a takeaway reads "- \`<id>\` <label>: <what the reader got>": ${l.trim()}`)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return out
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** the texts a public surface may offer: a held phrasing (its source `held: <why>`), or every phrasing of a held message
|
|
95
|
+
* (a `- held: <why>` field), stays in the store for the runs and is never offered */
|
|
96
|
+
export function offerable(messages: Message[]): Set<string> {
|
|
97
|
+
return new Set(messages.filter((m) => !m.fields.held).flatMap((m) => m.candidates.filter((c) => !/^held:/.test(c.source)).map((c) => c.text)))
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** the repo's guard on one public text (social/unit.ts guardWith), one line a problem */
|
|
101
|
+
export type Guard = (input: { texts?: readonly string[]; shows?: readonly string[] }) => string[]
|
|
102
|
+
|
|
103
|
+
/** why each phrasing may not be tested or shown, one line each: a field missing, an id twice, the repo's guard */
|
|
104
|
+
export function lint(messages: Message[], guard: Guard): string[] {
|
|
105
|
+
const out: string[] = []
|
|
106
|
+
const seen = new Set<string>()
|
|
107
|
+
for (const m of messages) {
|
|
108
|
+
for (const k of ['meaning', 'value']) if (!m.fields[k]) out.push(`${m.id}: no ${k}`)
|
|
109
|
+
if (!m.candidates.length) out.push(`${m.id}: no candidate`)
|
|
110
|
+
for (const c of m.candidates) {
|
|
111
|
+
if (seen.has(c.id)) out.push(`${c.id}: the id is used twice`)
|
|
112
|
+
seen.add(c.id)
|
|
113
|
+
for (const why of guard({ texts: [c.text] })) out.push(`${c.id}: ${why}`)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return out
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** a surface option's problems: past its place's budget, or refused by the guard; a shot by what a picture may show */
|
|
120
|
+
export function lintSurfaces(surfaces: Surface[], guard: Guard): string[] {
|
|
121
|
+
const out: string[] = []
|
|
122
|
+
for (const s of surfaces) {
|
|
123
|
+
if (s.shot) for (const why of guard({ shows: [s.shot] })) out.push(`${s.id} shot: ${why}`)
|
|
124
|
+
for (const o of s.options) {
|
|
125
|
+
const text = o.second ? `${o.headline} ${o.second}` : o.headline
|
|
126
|
+
if (s.budget && text.length > s.budget) out.push(`${s.id} ${o.id}: ${text.length} characters, the budget is ${s.budget}`)
|
|
127
|
+
for (const why of guard({ texts: [text] })) out.push(`${s.id}/${o.id}: ${why}`)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return out
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** the store's files read whole; a store with no personas.md or surfaces.md reads as none */
|
|
134
|
+
export type Store = { dir: string; messages: Message[]; personas: Persona[]; surfaces: Surface[]; brief: Brief }
|
|
135
|
+
|
|
136
|
+
const readIf = (f: string): string => (existsSync(f) ? readFileSync(f, 'utf8') : '')
|
|
137
|
+
|
|
138
|
+
export function readStore(root: string): Store {
|
|
139
|
+
const dir = join(root, MESSAGES_DIR)
|
|
140
|
+
if (!existsSync(join(dir, 'messages.md'))) throw new Error(`messages: no store here: write ${MESSAGES_DIR}/messages.md (wiki tools/shipkit/messages.md)`)
|
|
141
|
+
return {
|
|
142
|
+
dir,
|
|
143
|
+
messages: parseMessages(readFileSync(join(dir, 'messages.md'), 'utf8')),
|
|
144
|
+
personas: parsePersonas(readIf(join(dir, 'personas.md'))),
|
|
145
|
+
surfaces: parseSurfaces(readIf(join(dir, 'surfaces.md'))),
|
|
146
|
+
brief: parseBrief(readIf(join(dir, 'brief.md'))),
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** the runs, newest first */
|
|
151
|
+
export const runsOf = (dir: string): string[] => (existsSync(join(dir, 'runs')) ? readdirSync(join(dir, 'runs')).sort().reverse() : [])
|
|
152
|
+
|
|
153
|
+
/** a line the stage popup offers (social/unit.ts SuggestedLine) */
|
|
154
|
+
export type TestedLine = { text: string; source: string }
|
|
155
|
+
|
|
156
|
+
/** the best phrasing of each message, best first, from the newest run with a matrix (its « Value for its cost » table),
|
|
157
|
+
* only where the store still offers that text: a held or reworded phrasing never reaches a public surface */
|
|
158
|
+
export function testedLines(dir: string, offer: Set<string> = offerable(parseMessages(readIf(join(dir, 'messages.md'))))): TestedLine[] {
|
|
159
|
+
const run = runsOf(dir).find((r) => existsSync(join(dir, 'runs', r, 'matrix.md')))
|
|
160
|
+
if (run == null) return []
|
|
161
|
+
const md = readFileSync(join(dir, 'runs', run, 'matrix.md'), 'utf8')
|
|
162
|
+
const at = md.indexOf('## Value for its cost')
|
|
163
|
+
if (at === -1) return []
|
|
164
|
+
const out: TestedLine[] = []
|
|
165
|
+
for (const l of md.slice(at).split('\n').slice(1)) {
|
|
166
|
+
if (l.startsWith('## ')) break
|
|
167
|
+
const m = /^\| ([\w-]+) \| "([^"]+)" \| (\d+) \|/.exec(l)
|
|
168
|
+
if (m && offer.has(m[2]!)) out.push({ text: m[2]!, source: `${m[1]}, scored ${m[3]} (${run})` })
|
|
169
|
+
}
|
|
170
|
+
return out
|
|
171
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// the messages page's one route (wiki tools/shipkit/messages.md, The page): the whole store read fresh on each load.
|
|
2
|
+
// Read only: the store is edited as text
|
|
3
|
+
import { bad, NO_STORE } from '../review/http.ts'
|
|
4
|
+
import { storeView } from './score.ts'
|
|
5
|
+
|
|
6
|
+
/** the messages route of the repo at `root`; null for any other path */
|
|
7
|
+
export function messagesRoutes(root: string, req: Request, path: string): Response | null {
|
|
8
|
+
if (path !== '/api/messages') return null
|
|
9
|
+
if (req.method !== 'GET') return bad(`messages: no route ${req.method} ${path}`, 404)
|
|
10
|
+
try {
|
|
11
|
+
return Response.json(storeView(root), { headers: NO_STORE })
|
|
12
|
+
} catch (e) {
|
|
13
|
+
return bad(e, 500)
|
|
14
|
+
}
|
|
15
|
+
}
|