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.
Files changed (158) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +1 -1
  3. package/src/annex/annex.ts +227 -0
  4. package/src/annex/offload.ts +279 -0
  5. package/src/checks/SK040-release-words.check.ts +43 -0
  6. package/src/checks/SK041-annex-links.check.ts +28 -0
  7. package/src/checks/SK042-post-kinds.check.ts +73 -0
  8. package/src/cli/cmd_Annex.ts +179 -0
  9. package/src/cli/cmd_Commands.ts +4 -1
  10. package/src/cli/cmd_Home.ts +3 -2
  11. package/src/cli/cmd_Messages.ts +155 -0
  12. package/src/cli/cmd_Releases.ts +48 -0
  13. package/src/cli/cmd_Review.ts +161 -6
  14. package/src/cli/cmd_Shot.ts +4 -4
  15. package/src/cli/cmd_Social.ts +143 -6
  16. package/src/cli/family-pages.ts +2 -0
  17. package/src/cli/kit/index.ts +1 -1
  18. package/src/cli/kit/verb.ts +11 -3
  19. package/src/cli/registry.ts +6 -1
  20. package/src/collections/collection-types.ts +8 -1
  21. package/src/collections/providers.ts +4 -1
  22. package/src/commands/model.ts +36 -0
  23. package/src/commands/registry.ts +49 -0
  24. package/src/commands/routes.ts +59 -0
  25. package/src/commands/runner.ts +35 -0
  26. package/src/commands/runs.ts +112 -0
  27. package/src/core/app-icon.ts +4 -3
  28. package/src/core/icon-type.ts +8 -0
  29. package/src/core/jobs.ts +4 -3
  30. package/src/core/layout.ts +5 -2
  31. package/src/core/squircle.ts +95 -0
  32. package/src/home/daemon-jobs.ts +26 -2
  33. package/src/home/global-units.ts +3 -0
  34. package/src/home/gui-app/ShipkitGui.swift +302 -5
  35. package/src/home/gui-app.ts +63 -33
  36. package/src/home/hmr-keep.ts +134 -0
  37. package/src/home/home-start.ts +2 -2
  38. package/src/home/lib-watch.ts +21 -11
  39. package/src/home/pm.ts +1 -1
  40. package/src/home/process-apps.ts +181 -0
  41. package/src/home/resources.ts +3 -3
  42. package/src/home/run-web.ts +7 -4
  43. package/src/home/serve-web.ts +64 -14
  44. package/src/identities/collection.ts +49 -0
  45. package/src/identities/identities.ts +110 -8
  46. package/src/identities/machine.ts +4 -3
  47. package/src/identities/rating.ts +33 -0
  48. package/src/identities/shown.ts +170 -0
  49. package/src/identities/steps.ts +5 -0
  50. package/src/media-store/purge.ts +15 -1
  51. package/src/media-store/remote.ts +22 -6
  52. package/src/messages/brief.ts +117 -0
  53. package/src/messages/collection.ts +40 -0
  54. package/src/messages/model.ts +171 -0
  55. package/src/messages/routes.ts +15 -0
  56. package/src/messages/score.ts +180 -0
  57. package/src/messages/tabs.ts +13 -0
  58. package/src/release/notes.ts +130 -0
  59. package/src/release/run-bump.ts +41 -18
  60. package/src/release/run-release.ts +22 -4
  61. package/src/release/run-releases.ts +17 -15
  62. package/src/release/unit-resolve.ts +9 -0
  63. package/src/releases/add.ts +66 -0
  64. package/src/releases/collection.ts +36 -0
  65. package/src/releases/from-card.ts +66 -0
  66. package/src/releases/model.ts +267 -0
  67. package/src/releases/pictures.ts +89 -0
  68. package/src/releases/routes.ts +36 -0
  69. package/src/releases/store.ts +71 -0
  70. package/src/repo-config.ts +5 -0
  71. package/src/review/cells.ts +0 -11
  72. package/src/review/format.ts +10 -6
  73. package/src/review/model.ts +92 -3
  74. package/src/review/notes.ts +2 -48
  75. package/src/review/routes.ts +28 -10
  76. package/src/review/stage-card.ts +197 -0
  77. package/src/review/stage-routes.ts +123 -0
  78. package/src/review/store.ts +36 -0
  79. package/src/review/trailer-card.ts +99 -0
  80. package/src/review/trailer-desk.ts +57 -4
  81. package/src/review/trailer-model.ts +41 -7
  82. package/src/review/trailer-notes.ts +45 -0
  83. package/src/review/trailer-routes.ts +22 -13
  84. package/src/serve/hub-app/app-bridge.ts +71 -0
  85. package/src/serve/hub-app/commands/commands-page.tsx +122 -0
  86. package/src/serve/hub-app/commands/commands-st.ts +177 -0
  87. package/src/serve/hub-app/commands.css +24 -0
  88. package/src/serve/hub-app/hash-route.ts +40 -1
  89. package/src/serve/hub-app/home-st.ts +11 -2
  90. package/src/serve/hub-app/home.html +3 -0
  91. package/src/serve/hub-app/hub-app.tsx +6 -0
  92. package/src/serve/hub-app/icons.tsx +5 -0
  93. package/src/serve/hub-app/identities-view.tsx +4 -1
  94. package/src/serve/hub-app/identities.css +1 -0
  95. package/src/serve/hub-app/index.html +3 -0
  96. package/src/serve/hub-app/keys.ts +2 -2
  97. package/src/serve/hub-app/machine-st.ts +41 -10
  98. package/src/serve/hub-app/messages/messages-page.tsx +354 -0
  99. package/src/serve/hub-app/messages/messages-st.ts +74 -0
  100. package/src/serve/hub-app/messages.css +35 -0
  101. package/src/serve/hub-app/releases/releases-page.tsx +94 -0
  102. package/src/serve/hub-app/releases/releases-st.ts +69 -0
  103. package/src/serve/hub-app/releases.css +25 -0
  104. package/src/serve/hub-app/repo-sections.ts +15 -1
  105. package/src/serve/hub-app/repo-st.ts +56 -5
  106. package/src/serve/hub-app/review/clip-st.ts +31 -3
  107. package/src/serve/hub-app/review/note-place.ts +31 -0
  108. package/src/serve/hub-app/review/review-cells.tsx +27 -3
  109. package/src/serve/hub-app/review/review-st.ts +77 -2
  110. package/src/serve/hub-app/review/review-thread.tsx +9 -31
  111. package/src/serve/hub-app/review/review-views.tsx +164 -58
  112. package/src/serve/hub-app/review/thread-st.ts +108 -41
  113. package/src/serve/hub-app/review/trailer-card.tsx +187 -0
  114. package/src/serve/hub-app/review/trailer-page.tsx +62 -31
  115. package/src/serve/hub-app/review/trailer-st.ts +138 -26
  116. package/src/serve/hub-app/review/trailer-timeline.tsx +39 -26
  117. package/src/serve/hub-app/review.css +49 -6
  118. package/src/serve/hub-app/social/comms-page.tsx +55 -23
  119. package/src/serve/hub-app/social/identity-pictures.ts +46 -8
  120. package/src/serve/hub-app/social/kit.tsx +9 -6
  121. package/src/serve/hub-app/social/post-card.tsx +10 -2
  122. package/src/serve/hub-app/social/social-model.ts +37 -3
  123. package/src/serve/hub-app/social/social-page.tsx +179 -65
  124. package/src/serve/hub-app/social/social-st.ts +79 -26
  125. package/src/serve/hub-app/social/stage-popup.tsx +268 -0
  126. package/src/serve/hub-app/social/stage-st.ts +310 -0
  127. package/src/serve/hub-app/social/step-layout.ts +42 -0
  128. package/src/serve/hub-app/social.css +60 -1
  129. package/src/serve/hub-app/tree-build.ts +38 -1
  130. package/src/serve/hub-app/tree-svc.ts +10 -3
  131. package/src/serve/project-gutter-route.ts +4 -2
  132. package/src/serve/same-origin.ts +24 -1
  133. package/src/serve/serve-hub.ts +15 -1
  134. package/src/shipkit-files.ts +9 -7
  135. package/src/shot/shooter.ts +3 -3
  136. package/src/shot/shot-ask.ts +14 -3
  137. package/src/shot/shot.shipkit.ts +1 -1
  138. package/src/social/discord-layout.ts +48 -5
  139. package/src/social/fit.ts +84 -0
  140. package/src/social/identity-words.ts +74 -0
  141. package/src/social/kind-pages.ts +41 -0
  142. package/src/social/kinds.ts +92 -0
  143. package/src/social/load.ts +105 -9
  144. package/src/social/media-limit.ts +63 -2
  145. package/src/social/presence.ts +1 -1
  146. package/src/social/publish/bluesky.ts +58 -19
  147. package/src/social/publish/index.ts +31 -5
  148. package/src/social/reach.ts +49 -0
  149. package/src/social/release-stage.ts +173 -0
  150. package/src/social/routes.ts +42 -7
  151. package/src/social/stage.ts +227 -0
  152. package/src/social/strip.ts +85 -0
  153. package/src/social/text.ts +6 -2
  154. package/src/social/unit.ts +57 -1
  155. package/src/social/writes.ts +11 -0
  156. package/src/trailer/build.ts +15 -2
  157. package/src/trailer/grammar.ts +14 -4
  158. package/src/trailer/public-words.ts +41 -0
@@ -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. Read ONLY ${join(dir, 'packets', `${gs[0]!.id}.md`)}. 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 ""} to ${join(dir, 'verdicts', '<id>.json')} with the Write tool. Be realistic: reserve the harsh verdicts for what would truly trigger them.`,
43
+ '',
44
+ 'Reply with one line a gatekeeper: 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
+ }
@@ -0,0 +1,180 @@
1
+ // a run of the messages store (wiki tools/shipkit/messages.md, The loop): the blind sheets it hands each persona, the
2
+ // readings it gets back scored into a matrix, a surface run's options ranked, and the whole store as the hub's page
3
+ // draws it. A run is a folder of JSON the sub-agents wrote: runs/<run>/{packets,readings,verdicts,judged,notes}
4
+ import { existsSync, readdirSync, readFileSync } from 'node:fs'
5
+ import { join } from 'node:path'
6
+ import { readStore, runsOf, type Candidate, type Message, type Persona, type Store, type Takeaway } from './model.ts'
7
+
8
+ /** a stable shuffle: the same run and persona always give the same order */
9
+ export function shuffled<T>(xs: readonly T[], seed: string): T[] {
10
+ let h = 2166136261
11
+ for (const ch of seed) h = Math.imul(h ^ ch.charCodeAt(0), 16777619)
12
+ const rand = (): number => {
13
+ h = Math.imul(h ^ (h >>> 15), 2246822507) ^ Math.imul(h ^ (h >>> 13), 3266489909)
14
+ return ((h ^= h >>> 16) >>> 0) / 4294967296
15
+ }
16
+ const a = [...xs]
17
+ for (let i = a.length - 1; i > 0; i--) {
18
+ const j = Math.floor(rand() * (i + 1))
19
+ ;[a[i], a[j]] = [a[j]!, a[i]!]
20
+ }
21
+ return a
22
+ }
23
+
24
+ /** a persona's sheet: its sets (one a message, unnamed) and their lines, in an order of its own */
25
+ export function packetOf(p: Persona, messages: Message[], run: string): string {
26
+ const sets = shuffled(messages, `${run}/${p.id}`)
27
+ const body = sets.map((m, i) => [`Set ${i + 1}`, ...shuffled(m.candidates, `${run}/${p.id}/${m.id}`).map((c) => `- ${c.id}: "${c.text}"`)].join('\n'))
28
+ return [`# Lines to read (${p.id})`, '', ...body.flatMap((b) => [b, ''])].join('\n')
29
+ }
30
+
31
+ type Reading = { id: string; said: string; gain: string; believe: 0 | 1 | 2; appeal: number; friction?: string }
32
+ type Verdict = { id: string; verdict: string; words?: string }
33
+ type Judged = { id: string; persona: string; understood: 0 | 1 | 2; value: 0 | 1 | 2 }
34
+
35
+ /** a gatekeeper's verdict that refuses, and one that lets a line pass */
36
+ export const VETO = /^(remove|decline|object)/i
37
+ export const PASS = /^(allow|approve|ignore|link|partner)/i
38
+ const readJson = <T>(f: string): T => JSON.parse(readFileSync(f, 'utf8')) as T
39
+ const jsonsIn = (dir: string): string[] => (existsSync(dir) ? readdirSync(dir).filter((f) => f.endsWith('.json')) : [])
40
+ const mean = (xs: number[]): number => (xs.length ? Math.round(xs.reduce((a, b) => a + b, 0) / xs.length) : 0)
41
+
42
+ /** a cell's score, 0 to 100: understood weighs most, then the value landed, then appeal, then belief */
43
+ const scoreOf = (j: Judged, r: Reading): number => Math.round(100 * (0.4 * (j.understood / 2) + 0.3 * (j.value / 2) + 0.2 * ((r.appeal - 1) / 4) + 0.1 * (r.believe / 2)))
44
+
45
+ /** runs/<run>/matrix.md: the best phrasing per reader, the value for its cost, every phrasing with its parts */
46
+ export function matrix(messages: Message[], personas: Persona[], dir: string): string {
47
+ const readers = personas.filter((p) => p.kind === 'reader' && existsSync(join(dir, 'readings', `${p.id}.json`)))
48
+ const readings = new Map(readers.map((p) => [p.id, new Map(readJson<Reading[]>(join(dir, 'readings', `${p.id}.json`)).map((r) => [r.id, r]))]))
49
+ const judged = new Map<string, Judged>()
50
+ for (const f of jsonsIn(join(dir, 'judged'))) for (const j of readJson<Judged[]>(join(dir, 'judged', f))) judged.set(`${j.id}/${j.persona}`, j)
51
+ const verdicts = new Map<string, Map<string, Verdict>>()
52
+ for (const f of jsonsIn(join(dir, 'verdicts'))) verdicts.set(f.slice(0, -5), new Map(readJson<Verdict[]>(join(dir, 'verdicts', f)).map((v) => [v.id, v])))
53
+
54
+ const cell = (c: Candidate, p: string): number | undefined => {
55
+ const r = readings.get(p)?.get(c.id)
56
+ const j = judged.get(`${c.id}/${p}`)
57
+ return r && j ? scoreOf(j, r) : undefined
58
+ }
59
+ const scored = (c: Candidate): number => mean(readers.map((p) => cell(c, p.id)).filter((x): x is number => x !== undefined))
60
+ const vetoesOf = (c: Candidate): string[] => [...verdicts].filter(([, v]) => VETO.test(v.get(c.id)?.verdict ?? '')).map(([g]) => g)
61
+ const best = (m: Message): number => Math.max(0, ...m.candidates.map(scored))
62
+
63
+ const out = [`# Messages matrix: ${dir.split('/').at(-1)}`, '', `${readers.length} readers, ${verdicts.size} gatekeepers. A cell is 0 to 100: understood 40 %, value landed 30 %, appeal 20 %, belief 10 %. ⛔ is a gatekeeper's veto.`, '']
64
+ out.push('## Best phrasing per message, for each reader', '', `| message | ${readers.map((p) => p.id).join(' | ')} | all |`, `|---|${readers.map(() => '---|').join('')}---|`)
65
+ for (const m of messages) {
66
+ const row = readers.map((p) => {
67
+ const top = m.candidates.map((c) => ({ c, s: cell(c, p.id) ?? -1 })).sort((a, b) => b.s - a.s)[0]
68
+ return top && top.s >= 0 ? `${top.c.id} ${top.s}` : ''
69
+ })
70
+ const all = m.candidates.map((c) => ({ c, s: scored(c) })).sort((a, b) => b.s - a.s)[0]
71
+ out.push(`| ${m.id} | ${row.join(' | ')} | ${all ? `${all.c.id} ${all.s}` : ''} |`)
72
+ }
73
+ out.push('', '## Value for its cost', '', "Each message's best phrasing: its score for each second spoken. A small gain said in a second can beat a big one that needs a sentence.", '', '| message | best | score | words | s | score a second |', '|---|---|---|---|---|---|')
74
+ const bests = messages
75
+ .map((m) => {
76
+ const b = m.candidates.map((c) => ({ c, s: scored(c) })).sort((x, y) => y.s - x.s)[0]
77
+ return b && { m, ...b, rate: Math.round(b.s / Math.max(b.c.seconds, 0.4)) }
78
+ })
79
+ .filter((x) => !!x)
80
+ .sort((a, b) => b.rate - a.rate)
81
+ for (const b of bests) out.push(`| ${b.m.id} | "${b.c.text}" | ${b.s} | ${b.c.words} | ${b.c.seconds} | ${b.rate} |`)
82
+ out.push('', '## Every phrasing, best first within its message', '')
83
+ for (const m of [...messages].sort((a, b) => best(b) - best(a))) {
84
+ out.push(`### ${m.id}: ${m.title}`, '', `meaning: ${m.fields.meaning} `, `value: ${m.fields.value}`, '', '| id | line | score | understood | value | appeal | words | s | friction | veto |', '|---|---|---|---|---|---|---|---|---|---|')
85
+ const rows = m.candidates.map((c) => {
86
+ const js = readers.map((p) => judged.get(`${c.id}/${p.id}`)).filter((x): x is Judged => !!x)
87
+ const rs = readers.map((p) => readings.get(p.id)?.get(c.id)).filter((x): x is Reading => !!x)
88
+ const s = scored(c)
89
+ const fr = [...new Set(rs.map((r) => r.friction?.trim()).filter((x): x is string => !!x && x !== '-' && !/^none/i.test(x)))].slice(0, 3).join('; ')
90
+ const avg = (xs: number[]): string => (xs.length ? (xs.reduce((a, b) => a + b, 0) / xs.length).toFixed(1) : '')
91
+ return { s, line: `| ${c.id} | "${c.text}" | ${s} | ${avg(js.map((j) => j.understood))} | ${avg(js.map((j) => j.value))} | ${avg(rs.map((r) => r.appeal))} | ${c.words} | ${c.seconds} | ${fr} | ${vetoesOf(c).join(' ')} |` }
92
+ })
93
+ out.push(...rows.sort((a, b) => b.s - a.s).map((r) => r.line), '')
94
+ }
95
+ return out.join('\n')
96
+ }
97
+
98
+ type TopReading = { option: string; alone_appeal: number; appeal: number; repeats: 0 | 1; friction?: string } & Record<string, unknown>
99
+
100
+ /** a surface run's option, 0 to 100: the headline alone 30 % (a link preview shows only it), the whole 30 %, the
101
+ * takeaways the other 40 % between them, minus 10 for each reader who saw a repeat; a gatekeeper's refusal vetoes it */
102
+ export type SurfaceRow = { option: string; score: number; veto: boolean; alone: number; whole: number; took: Record<string, number>; repeats: number; n: number; gatekeepers: string[]; friction: string[] }
103
+
104
+ export function surfaceRows(dir: string, takeaways: readonly Takeaway[]): SurfaceRow[] {
105
+ const all = jsonsIn(join(dir, 'readings')).map((f) => readJson<TopReading[]>(join(dir, 'readings', f)))
106
+ const verdicts = jsonsIn(join(dir, 'verdicts')).map((f) => [f.slice(0, -5), readJson<Verdict[]>(join(dir, 'verdicts', f))] as const)
107
+ const options = [...new Set(all.flat().map((r) => r.option))].sort()
108
+ const avg = (xs: number[]): number => xs.reduce((a, b) => a + b, 0) / Math.max(xs.length, 1)
109
+ const [alone, whole] = takeaways.length ? [0.3, 0.3] : [0.5, 0.5]
110
+ const each = takeaways.length ? 0.4 / takeaways.length : 0
111
+ return options
112
+ .map((o) => {
113
+ const rs = all.map((a) => a.find((r) => r.option === o)).filter((r): r is TopReading => !!r)
114
+ const got = (id: string): number[] => rs.map((r) => Number(r[id] ?? 0))
115
+ const score = Math.round(100 * takeaways.reduce((s, t) => s + each * avg(got(t.id)), alone * ((avg(rs.map((r) => r.alone_appeal)) - 1) / 4) + whole * ((avg(rs.map((r) => r.appeal)) - 1) / 4)) - 10 * avg(rs.map((r) => r.repeats)))
116
+ const verdictOf = (v: Verdict[]): string => v.find((x) => x.id === o)?.verdict ?? 'allow'
117
+ return {
118
+ option: o,
119
+ score,
120
+ veto: verdicts.some(([, v]) => VETO.test(verdictOf(v))),
121
+ alone: avg(rs.map((r) => r.alone_appeal)),
122
+ whole: avg(rs.map((r) => r.appeal)),
123
+ took: Object.fromEntries(takeaways.map((t) => [t.id, got(t.id).filter((x) => x > 0).length])),
124
+ repeats: rs.filter((r) => r.repeats).length,
125
+ n: rs.length,
126
+ gatekeepers: verdicts.filter(([, v]) => !PASS.test(verdictOf(v))).map(([g, v]) => `${g} ${verdictOf(v)}`),
127
+ friction: [...new Set(rs.map((r) => r.friction?.trim()).filter((x): x is string => !!x))].slice(0, 3),
128
+ }
129
+ })
130
+ .sort((a, b) => (b.veto ? -1 : b.score) - (a.veto ? -1 : a.score))
131
+ }
132
+
133
+ /** runs/<run>/surface.md's table */
134
+ export function surfaceTable(dir: string, takeaways: readonly Takeaway[]): string {
135
+ const rows = surfaceRows(dir, takeaways).map((r) => `| ${r.option} | ${r.veto ? '⛔' : r.score} | ${r.alone.toFixed(1)} | ${r.whole.toFixed(1)} | ${takeaways.map((t) => `${r.took[t.id]}/${r.n} | `).join('')}${r.repeats} | ${r.gatekeepers.join(', ')} | ${r.friction.join('; ')} |`)
136
+ return [`| option | score | headline alone | whole | ${takeaways.map((t) => `${t.label} got | `).join('')}repeats | gatekeepers | friction |`, `|---|---|---|---|${takeaways.map(() => '---|').join('')}---|---|---|`, ...rows].join('\n')
137
+ }
138
+
139
+ type Cell = { score: number; understood: number; value: number; appeal: number; believe: number; said: string; gain: string; friction: string }
140
+ export type RunView = {
141
+ id: string
142
+ kind: 'messages' | 'surface'
143
+ readers: string[]
144
+ gatekeepers: string[]
145
+ /** messages runs: phrasing id → reader → its cell */
146
+ cells: Record<string, Record<string, Cell>>
147
+ /** phrasing or option id → gatekeeper → its verdict */
148
+ verdicts: Record<string, Record<string, { verdict: string; words: string }>>
149
+ surface: SurfaceRow[]
150
+ /** each reader's notes: favourites, rewrites, what a line made them think */
151
+ notes: Record<string, string>
152
+ }
153
+
154
+ export type StoreView = Pick<Store, 'messages' | 'personas' | 'surfaces'> & { takeaways: Takeaway[]; runs: RunView[] }
155
+
156
+ function runView(dir: string, id: string, takeaways: readonly Takeaway[]): RunView {
157
+ const readings = jsonsIn(join(dir, 'readings')).map((f) => [f.slice(0, -5), readJson<unknown[]>(join(dir, 'readings', f))] as const)
158
+ const surface = readings.some(([, rs]) => rs.some((r) => typeof r === 'object' && r !== null && 'option' in r))
159
+ const verdicts: RunView['verdicts'] = {}
160
+ for (const f of jsonsIn(join(dir, 'verdicts'))) for (const v of readJson<Verdict[]>(join(dir, 'verdicts', f))) (verdicts[v.id] ??= {})[f.slice(0, -5)] = { verdict: v.verdict, words: v.words ?? '' }
161
+ const judged = new Map<string, Judged>()
162
+ for (const f of jsonsIn(join(dir, 'judged'))) for (const j of readJson<Judged[]>(join(dir, 'judged', f))) judged.set(`${j.id}/${j.persona}`, j)
163
+ const cells: RunView['cells'] = {}
164
+ if (!surface)
165
+ for (const [p, rs] of readings)
166
+ for (const r of rs as Reading[]) {
167
+ const j = judged.get(`${r.id}/${p}`)
168
+ if (j) (cells[r.id] ??= {})[p] = { score: scoreOf(j, r), understood: j.understood, value: j.value, appeal: r.appeal, believe: r.believe, said: r.said, gain: r.gain, friction: r.friction ?? '' }
169
+ }
170
+ const notesDir = join(dir, 'notes')
171
+ const notes = Object.fromEntries((existsSync(notesDir) ? readdirSync(notesDir) : []).filter((f) => f.endsWith('.md')).map((f) => [f.slice(0, -3), readFileSync(join(notesDir, f), 'utf8')]))
172
+ return { id, kind: surface ? 'surface' : 'messages', readers: readings.map(([p]) => p), gatekeepers: jsonsIn(join(dir, 'verdicts')).map((f) => f.slice(0, -5)), cells, verdicts, surface: surface ? surfaceRows(dir, takeaways) : [], notes }
173
+ }
174
+
175
+ /** the whole store as one object, read fresh: what the hub's Messages page draws */
176
+ export function storeView(root: string): StoreView {
177
+ const s = readStore(root)
178
+ const runs = runsOf(s.dir).map((id) => runView(join(s.dir, 'runs', id), id, s.brief.takeaways))
179
+ return { messages: s.messages, personas: s.personas, surfaces: s.surfaces, takeaways: s.brief.takeaways, runs }
180
+ }
@@ -0,0 +1,13 @@
1
+ // the messages page's tabs, in its order: the page's top tabs, and the four after the first the rows under the hub's
2
+ // messages section (wiki tools/shipkit/messages.md, The page). Light: the hub bundles it
3
+ export const MESSAGES_TABS = [
4
+ ['messages', 'Messages'],
5
+ ['value', 'Value for its cost'],
6
+ ['personas', 'Personas'],
7
+ ['surfaces', 'Page tops'],
8
+ ['notes', "Readers' notes"],
9
+ ] as const
10
+
11
+ export type MessagesTab = (typeof MESSAGES_TABS)[number][0]
12
+
13
+ export const isMessagesTab = (s: unknown): s is MessagesTab => MESSAGES_TABS.some(([t]) => t === s)