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.
Files changed (196) hide show
  1. package/CHANGELOG.md +32 -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/SK004-gitignore-policy.check.ts +6 -3
  6. package/src/checks/SK040-release-words.check.ts +43 -0
  7. package/src/checks/SK041-annex-links.check.ts +28 -0
  8. package/src/checks/SK042-post-kinds.check.ts +73 -0
  9. package/src/cli/cmd_Annex.ts +179 -0
  10. package/src/cli/cmd_Commands.ts +4 -1
  11. package/src/cli/cmd_GlobalProcesses.ts +2 -107
  12. package/src/cli/cmd_Home.ts +4 -3
  13. package/src/cli/cmd_Messages.ts +155 -0
  14. package/src/cli/cmd_Overview.ts +2 -1
  15. package/src/cli/cmd_Releases.ts +84 -0
  16. package/src/cli/cmd_Review.ts +176 -12
  17. package/src/cli/cmd_Shot.ts +4 -4
  18. package/src/cli/cmd_Social.ts +151 -8
  19. package/src/cli/cmd_Sound.ts +17 -4
  20. package/src/cli/cmd_Trailer.ts +67 -1
  21. package/src/cli/family-pages.ts +2 -0
  22. package/src/cli/kit/index.ts +1 -1
  23. package/src/cli/kit/verb.ts +11 -3
  24. package/src/cli/registry.ts +7 -1
  25. package/src/collections/collection-types.ts +8 -1
  26. package/src/collections/providers.ts +4 -1
  27. package/src/collections/review.ts +23 -4
  28. package/src/commands/model.ts +36 -0
  29. package/src/commands/registry.ts +49 -0
  30. package/src/commands/routes.ts +59 -0
  31. package/src/commands/runner.ts +35 -0
  32. package/src/commands/runs.ts +112 -0
  33. package/src/core/app-icon.ts +4 -3
  34. package/src/core/icon-type.ts +8 -0
  35. package/src/core/jobs.ts +4 -3
  36. package/src/core/layout.ts +11 -2
  37. package/src/core/squircle.ts +95 -0
  38. package/src/home/daemon-jobs.ts +26 -2
  39. package/src/home/global-units.ts +3 -0
  40. package/src/home/gui-app/ShipkitGui.swift +337 -5
  41. package/src/home/gui-app.ts +64 -33
  42. package/src/home/hmr-keep.ts +134 -0
  43. package/src/home/home-start.ts +2 -2
  44. package/src/home/lib-watch.ts +21 -11
  45. package/src/home/pm-switch.ts +112 -0
  46. package/src/home/pm.ts +1 -1
  47. package/src/home/process-apps.ts +181 -0
  48. package/src/home/resources.ts +3 -3
  49. package/src/home/run-web.ts +7 -4
  50. package/src/home/serve-web.ts +64 -14
  51. package/src/identities/collection.ts +49 -0
  52. package/src/identities/identities.ts +121 -14
  53. package/src/identities/machine.ts +4 -3
  54. package/src/identities/rating.ts +33 -0
  55. package/src/identities/shown.ts +170 -0
  56. package/src/identities/steps.ts +5 -0
  57. package/src/media-store/purge.ts +15 -1
  58. package/src/media-store/remote.ts +22 -6
  59. package/src/messages/brief.ts +117 -0
  60. package/src/messages/collection.ts +40 -0
  61. package/src/messages/model.ts +171 -0
  62. package/src/messages/routes.ts +15 -0
  63. package/src/messages/score.ts +182 -0
  64. package/src/messages/tabs.ts +13 -0
  65. package/src/release/notes.ts +130 -0
  66. package/src/release/run-bump.ts +41 -18
  67. package/src/release/run-release.ts +22 -4
  68. package/src/release/run-releases.ts +17 -15
  69. package/src/release/unit-resolve.ts +9 -0
  70. package/src/releases/add.ts +94 -0
  71. package/src/releases/before.ts +31 -0
  72. package/src/releases/collection.ts +36 -0
  73. package/src/releases/from-card.ts +151 -0
  74. package/src/releases/model.ts +327 -0
  75. package/src/releases/pictures.ts +110 -0
  76. package/src/releases/routes.ts +36 -0
  77. package/src/releases/store.ts +71 -0
  78. package/src/repo-config.ts +5 -0
  79. package/src/review/cells.ts +0 -11
  80. package/src/review/format.ts +10 -6
  81. package/src/review/http.ts +1 -1
  82. package/src/review/model.ts +102 -3
  83. package/src/review/notes.ts +2 -48
  84. package/src/review/routes.ts +28 -10
  85. package/src/review/stage-card.ts +197 -0
  86. package/src/review/stage-routes.ts +123 -0
  87. package/src/review/store.ts +47 -1
  88. package/src/review/trailer-card.ts +99 -0
  89. package/src/review/trailer-desk.ts +76 -4
  90. package/src/review/trailer-model.ts +106 -7
  91. package/src/review/trailer-notes.ts +45 -0
  92. package/src/review/trailer-routes.ts +119 -13
  93. package/src/review/trailer-voices.ts +144 -0
  94. package/src/review/watchers.ts +58 -1
  95. package/src/serve/hub-app/app-bridge.ts +71 -0
  96. package/src/serve/hub-app/benign-errors.ts +22 -0
  97. package/src/serve/hub-app/commands/commands-page.tsx +122 -0
  98. package/src/serve/hub-app/commands/commands-st.ts +177 -0
  99. package/src/serve/hub-app/commands.css +24 -0
  100. package/src/serve/hub-app/hash-route.ts +59 -8
  101. package/src/serve/hub-app/home-st.ts +19 -2
  102. package/src/serve/hub-app/home.html +3 -0
  103. package/src/serve/hub-app/hub-app.tsx +8 -0
  104. package/src/serve/hub-app/icons.tsx +5 -0
  105. package/src/serve/hub-app/identities-view.tsx +4 -1
  106. package/src/serve/hub-app/identities.css +1 -0
  107. package/src/serve/hub-app/index.html +3 -0
  108. package/src/serve/hub-app/keys.ts +2 -2
  109. package/src/serve/hub-app/machine-st.ts +41 -10
  110. package/src/serve/hub-app/messages/messages-page.tsx +354 -0
  111. package/src/serve/hub-app/messages/messages-st.ts +74 -0
  112. package/src/serve/hub-app/messages.css +35 -0
  113. package/src/serve/hub-app/project-list.css +7 -2
  114. package/src/serve/hub-app/project-list.tsx +9 -0
  115. package/src/serve/hub-app/projects-svc.ts +16 -6
  116. package/src/serve/hub-app/releases/releases-page.tsx +187 -0
  117. package/src/serve/hub-app/releases/releases-st.ts +111 -0
  118. package/src/serve/hub-app/releases.css +52 -0
  119. package/src/serve/hub-app/repo-sections.ts +16 -2
  120. package/src/serve/hub-app/repo-st.ts +66 -10
  121. package/src/serve/hub-app/review/clip-st.ts +34 -4
  122. package/src/serve/hub-app/review/kit.tsx +3 -3
  123. package/src/serve/hub-app/review/note-place.ts +31 -0
  124. package/src/serve/hub-app/review/review-cells.tsx +27 -3
  125. package/src/serve/hub-app/review/review-st.ts +77 -2
  126. package/src/serve/hub-app/review/review-thread.tsx +9 -31
  127. package/src/serve/hub-app/review/review-views.tsx +164 -58
  128. package/src/serve/hub-app/review/thread-st.ts +108 -41
  129. package/src/serve/hub-app/review/trailer-card.tsx +187 -0
  130. package/src/serve/hub-app/review/trailer-page.tsx +92 -36
  131. package/src/serve/hub-app/review/trailer-st.ts +306 -34
  132. package/src/serve/hub-app/review/trailer-timeline.tsx +68 -23
  133. package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
  134. package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
  135. package/src/serve/hub-app/review.css +137 -6
  136. package/src/serve/hub-app/social/comms-page.tsx +65 -28
  137. package/src/serve/hub-app/social/identity-pictures.ts +46 -8
  138. package/src/serve/hub-app/social/kit.tsx +9 -6
  139. package/src/serve/hub-app/social/next-release.tsx +118 -0
  140. package/src/serve/hub-app/social/post-card.tsx +10 -2
  141. package/src/serve/hub-app/social/social-model.ts +39 -3
  142. package/src/serve/hub-app/social/social-page.tsx +179 -65
  143. package/src/serve/hub-app/social/social-st.ts +117 -27
  144. package/src/serve/hub-app/social/stage-popup.tsx +268 -0
  145. package/src/serve/hub-app/social/stage-st.ts +310 -0
  146. package/src/serve/hub-app/social/step-layout.ts +42 -0
  147. package/src/serve/hub-app/social.css +68 -1
  148. package/src/serve/hub-app/tree-build.ts +40 -1
  149. package/src/serve/hub-app/tree-svc.ts +10 -3
  150. package/src/serve/project-gutter-route.ts +12 -2
  151. package/src/serve/project-gutter.ts +4 -2
  152. package/src/serve/same-origin.ts +24 -1
  153. package/src/serve/serve-hub.ts +15 -1
  154. package/src/shipkit-files.ts +9 -7
  155. package/src/shot/box.ts +33 -12
  156. package/src/shot/client.ts +1 -1
  157. package/src/shot/shooter.ts +22 -12
  158. package/src/shot/shot-ask.ts +14 -3
  159. package/src/shot/shot.shipkit.ts +1 -1
  160. package/src/social/desk-index.ts +49 -8
  161. package/src/social/discord-layout.ts +54 -7
  162. package/src/social/drafts.ts +1 -1
  163. package/src/social/fit.ts +84 -0
  164. package/src/social/identity-words.ts +74 -0
  165. package/src/social/kind-pages.ts +41 -0
  166. package/src/social/kinds.ts +93 -0
  167. package/src/social/load.ts +125 -10
  168. package/src/social/media-limit.ts +63 -2
  169. package/src/social/presence.ts +1 -1
  170. package/src/social/publish/bluesky.ts +58 -19
  171. package/src/social/publish/index.ts +47 -6
  172. package/src/social/reach.ts +49 -0
  173. package/src/social/release-stage.ts +277 -0
  174. package/src/social/routes.ts +44 -8
  175. package/src/social/stage.ts +246 -0
  176. package/src/social/strip.ts +85 -0
  177. package/src/social/text.ts +6 -2
  178. package/src/social/unit.ts +57 -1
  179. package/src/social/writes.ts +11 -0
  180. package/src/trailer/bed.ts +111 -0
  181. package/src/trailer/build.ts +72 -40
  182. package/src/trailer/ffmpeg.ts +6 -0
  183. package/src/trailer/grammar.ts +37 -6
  184. package/src/trailer/graph.ts +12 -1
  185. package/src/trailer/public-words.ts +41 -0
  186. package/src/trailer/shot-plan.ts +75 -0
  187. package/src/trailer/shot-state.ts +191 -0
  188. package/src/trailer/sound/audio.ts +28 -0
  189. package/src/trailer/sound/brand.ts +53 -3
  190. package/src/trailer/sound/gen.ts +61 -2
  191. package/src/trailer/sound/index.ts +25 -11
  192. package/src/trailer/sound/presets.ts +86 -5
  193. package/src/trailer/sound/run.ts +1 -1
  194. package/src/trailer/sound/takes.ts +94 -0
  195. package/src/trailer/titles.ts +36 -0
  196. package/src/trailer/url.ts +1 -1
@@ -0,0 +1,182 @@
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
+ const unjudged = verdicts.size ? personas.filter((p) => p.kind === 'gatekeeper' && !verdicts.has(p.id)).map((p) => p.id) : []
54
+ if (unjudged.length) throw new Error(`messages: no verdicts of ${unjudged.join(', ')} in ${join(dir, 'verdicts')}: the gatekeepers brief writes one file a gatekeeper`)
55
+
56
+ const cell = (c: Candidate, p: string): number | undefined => {
57
+ const r = readings.get(p)?.get(c.id)
58
+ const j = judged.get(`${c.id}/${p}`)
59
+ return r && j ? scoreOf(j, r) : undefined
60
+ }
61
+ const scored = (c: Candidate): number => mean(readers.map((p) => cell(c, p.id)).filter((x): x is number => x !== undefined))
62
+ const vetoesOf = (c: Candidate): string[] => [...verdicts].filter(([, v]) => VETO.test(v.get(c.id)?.verdict ?? '')).map(([g]) => g)
63
+ const best = (m: Message): number => Math.max(0, ...m.candidates.map(scored))
64
+
65
+ 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.`, '']
66
+ out.push('## Best phrasing per message, for each reader', '', `| message | ${readers.map((p) => p.id).join(' | ')} | all |`, `|---|${readers.map(() => '---|').join('')}---|`)
67
+ for (const m of messages) {
68
+ const row = readers.map((p) => {
69
+ const top = m.candidates.map((c) => ({ c, s: cell(c, p.id) ?? -1 })).sort((a, b) => b.s - a.s)[0]
70
+ return top && top.s >= 0 ? `${top.c.id} ${top.s}` : ''
71
+ })
72
+ const all = m.candidates.map((c) => ({ c, s: scored(c) })).sort((a, b) => b.s - a.s)[0]
73
+ out.push(`| ${m.id} | ${row.join(' | ')} | ${all ? `${all.c.id} ${all.s}` : ''} |`)
74
+ }
75
+ 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 |', '|---|---|---|---|---|---|')
76
+ const bests = messages
77
+ .map((m) => {
78
+ const b = m.candidates.map((c) => ({ c, s: scored(c) })).sort((x, y) => y.s - x.s)[0]
79
+ return b && { m, ...b, rate: Math.round(b.s / Math.max(b.c.seconds, 0.4)) }
80
+ })
81
+ .filter((x) => !!x)
82
+ .sort((a, b) => b.rate - a.rate)
83
+ for (const b of bests) out.push(`| ${b.m.id} | "${b.c.text}" | ${b.s} | ${b.c.words} | ${b.c.seconds} | ${b.rate} |`)
84
+ out.push('', '## Every phrasing, best first within its message', '')
85
+ for (const m of [...messages].sort((a, b) => best(b) - best(a))) {
86
+ out.push(`### ${m.id}: ${m.title}`, '', `meaning: ${m.fields.meaning} `, `value: ${m.fields.value}`, '', '| id | line | score | understood | value | appeal | words | s | friction | veto |', '|---|---|---|---|---|---|---|---|---|---|')
87
+ const rows = m.candidates.map((c) => {
88
+ const js = readers.map((p) => judged.get(`${c.id}/${p.id}`)).filter((x): x is Judged => !!x)
89
+ const rs = readers.map((p) => readings.get(p.id)?.get(c.id)).filter((x): x is Reading => !!x)
90
+ const s = scored(c)
91
+ 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('; ')
92
+ const avg = (xs: number[]): string => (xs.length ? (xs.reduce((a, b) => a + b, 0) / xs.length).toFixed(1) : '')
93
+ 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(' ')} |` }
94
+ })
95
+ out.push(...rows.sort((a, b) => b.s - a.s).map((r) => r.line), '')
96
+ }
97
+ return out.join('\n')
98
+ }
99
+
100
+ type TopReading = { option: string; alone_appeal: number; appeal: number; repeats: 0 | 1; friction?: string } & Record<string, unknown>
101
+
102
+ /** a surface run's option, 0 to 100: the headline alone 30 % (a link preview shows only it), the whole 30 %, the
103
+ * takeaways the other 40 % between them, minus 10 for each reader who saw a repeat; a gatekeeper's refusal vetoes it */
104
+ 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[] }
105
+
106
+ export function surfaceRows(dir: string, takeaways: readonly Takeaway[]): SurfaceRow[] {
107
+ const all = jsonsIn(join(dir, 'readings')).map((f) => readJson<TopReading[]>(join(dir, 'readings', f)))
108
+ const verdicts = jsonsIn(join(dir, 'verdicts')).map((f) => [f.slice(0, -5), readJson<Verdict[]>(join(dir, 'verdicts', f))] as const)
109
+ const options = [...new Set(all.flat().map((r) => r.option))].sort()
110
+ const avg = (xs: number[]): number => xs.reduce((a, b) => a + b, 0) / Math.max(xs.length, 1)
111
+ const [alone, whole] = takeaways.length ? [0.3, 0.3] : [0.5, 0.5]
112
+ const each = takeaways.length ? 0.4 / takeaways.length : 0
113
+ return options
114
+ .map((o) => {
115
+ const rs = all.map((a) => a.find((r) => r.option === o)).filter((r): r is TopReading => !!r)
116
+ const got = (id: string): number[] => rs.map((r) => Number(r[id] ?? 0))
117
+ 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)))
118
+ const verdictOf = (v: Verdict[]): string => v.find((x) => x.id === o)?.verdict ?? 'allow'
119
+ return {
120
+ option: o,
121
+ score,
122
+ veto: verdicts.some(([, v]) => VETO.test(verdictOf(v))),
123
+ alone: avg(rs.map((r) => r.alone_appeal)),
124
+ whole: avg(rs.map((r) => r.appeal)),
125
+ took: Object.fromEntries(takeaways.map((t) => [t.id, got(t.id).filter((x) => x > 0).length])),
126
+ repeats: rs.filter((r) => r.repeats).length,
127
+ n: rs.length,
128
+ gatekeepers: verdicts.filter(([, v]) => !PASS.test(verdictOf(v))).map(([g, v]) => `${g} ${verdictOf(v)}`),
129
+ friction: [...new Set(rs.map((r) => r.friction?.trim()).filter((x): x is string => !!x))].slice(0, 3),
130
+ }
131
+ })
132
+ .sort((a, b) => (b.veto ? -1 : b.score) - (a.veto ? -1 : a.score))
133
+ }
134
+
135
+ /** runs/<run>/surface.md's table */
136
+ export function surfaceTable(dir: string, takeaways: readonly Takeaway[]): string {
137
+ 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('; ')} |`)
138
+ return [`| option | score | headline alone | whole | ${takeaways.map((t) => `${t.label} got | `).join('')}repeats | gatekeepers | friction |`, `|---|---|---|---|${takeaways.map(() => '---|').join('')}---|---|---|`, ...rows].join('\n')
139
+ }
140
+
141
+ type Cell = { score: number; understood: number; value: number; appeal: number; believe: number; said: string; gain: string; friction: string }
142
+ export type RunView = {
143
+ id: string
144
+ kind: 'messages' | 'surface'
145
+ readers: string[]
146
+ gatekeepers: string[]
147
+ /** messages runs: phrasing id → reader → its cell */
148
+ cells: Record<string, Record<string, Cell>>
149
+ /** phrasing or option id → gatekeeper → its verdict */
150
+ verdicts: Record<string, Record<string, { verdict: string; words: string }>>
151
+ surface: SurfaceRow[]
152
+ /** each reader's notes: favourites, rewrites, what a line made them think */
153
+ notes: Record<string, string>
154
+ }
155
+
156
+ export type StoreView = Pick<Store, 'messages' | 'personas' | 'surfaces'> & { takeaways: Takeaway[]; runs: RunView[] }
157
+
158
+ function runView(dir: string, id: string, takeaways: readonly Takeaway[]): RunView {
159
+ const readings = jsonsIn(join(dir, 'readings')).map((f) => [f.slice(0, -5), readJson<unknown[]>(join(dir, 'readings', f))] as const)
160
+ const surface = readings.some(([, rs]) => rs.some((r) => typeof r === 'object' && r !== null && 'option' in r))
161
+ const verdicts: RunView['verdicts'] = {}
162
+ 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 ?? '' }
163
+ const judged = new Map<string, Judged>()
164
+ 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)
165
+ const cells: RunView['cells'] = {}
166
+ if (!surface)
167
+ for (const [p, rs] of readings)
168
+ for (const r of rs as Reading[]) {
169
+ const j = judged.get(`${r.id}/${p}`)
170
+ 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 ?? '' }
171
+ }
172
+ const notesDir = join(dir, 'notes')
173
+ const notes = Object.fromEntries((existsSync(notesDir) ? readdirSync(notesDir) : []).filter((f) => f.endsWith('.md')).map((f) => [f.slice(0, -3), readFileSync(join(notesDir, f), 'utf8')]))
174
+ 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 }
175
+ }
176
+
177
+ /** the whole store as one object, read fresh: what the hub's Messages page draws */
178
+ export function storeView(root: string): StoreView {
179
+ const s = readStore(root)
180
+ const runs = runsOf(s.dir).map((id) => runView(join(s.dir, 'runs', id), id, s.brief.takeaways))
181
+ return { messages: s.messages, personas: s.personas, surfaces: s.surfaces, takeaways: s.brief.takeaways, runs }
182
+ }
@@ -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)
@@ -0,0 +1,130 @@
1
+ // a unit's release notes, in one place, whatever holds them (wiki tools/shipkit/units.md): its CHANGELOG's sections,
2
+ // or, for a root unit with `.shipkit/releases/`, the release files, next.md being the Unreleased notes. Bump, release
3
+ // and `sk releases` read only this, so the two homes never drift into two pipelines
4
+ import { existsSync, readdirSync, readFileSync } from 'fs'
5
+ import { join, relative } from 'path'
6
+ import { NEXT, changelogOf, changesOf, fileOf, notesOf as releaseNotes, parseRelease, promoted, renderRelease, type Release } from '../releases/model.ts'
7
+ import { declaredKind, extractChangelogSection, hasUnreleasedHeading, hasVersionSection, promoteUnreleased, type ReleaseKind } from './changelog.ts'
8
+ import type { ReleaseUnit } from './unit-resolve.ts'
9
+
10
+ /** one file a bump writes: its new text, or null to remove it */
11
+ export type NotesWrite = { path: string; text: string | null }
12
+
13
+ export interface UnitNotes {
14
+ /** where they live, repo relative: a file or the release folder */
15
+ rel: string
16
+ /** the Unreleased heading, or next.md, is there */
17
+ hasUnreleased: boolean
18
+ /** and holds something to say */
19
+ hasUnreleasedNotes: boolean
20
+ /** the kind the Unreleased heading declares, or null */
21
+ kind: ReleaseKind | null
22
+ hasVersion(version: string): boolean
23
+ /** the notes of a released version, markdown; throws when it has none */
24
+ section(version: string): string
25
+ /** the files a bump writes to name the Unreleased notes `version`, or why it cannot */
26
+ promote(version: string, date: string): { writes: NotesWrite[] } | { error: string }
27
+ /** the file and the line pattern the commit that wrote a version's notes is found by */
28
+ anchor(version: string): { rel: string; pattern: string }
29
+ }
30
+
31
+ const esc = (v: string): string => v.replace(/\./g, '\\.')
32
+
33
+ function changelogNotes(root: string, u: ReleaseUnit): UnitNotes {
34
+ const rel = relative(root, u.changelog)
35
+ const text = existsSync(u.changelog) ? readFileSync(u.changelog, 'utf8') : null
36
+ const missing = `${rel} not found: a release states what changed`
37
+ return {
38
+ rel,
39
+ hasUnreleased: text != null && hasUnreleasedHeading(text),
40
+ hasUnreleasedNotes: text != null && !('error' in promoteUnreleased(text, '0.0.0')),
41
+ kind: text == null ? null : declaredKind(text),
42
+ hasVersion: (v) => text != null && hasVersionSection(text, v),
43
+ section: (v) => {
44
+ if (text == null) throw new Error(missing)
45
+ return extractChangelogSection({ changelog: text, version: v })
46
+ },
47
+ promote: (v) => {
48
+ if (text == null) return { error: missing }
49
+ const p = promoteUnreleased(text, v)
50
+ return 'error' in p ? p : { writes: [{ path: u.changelog, text: p.text }] }
51
+ },
52
+ anchor: (v) => ({ rel, pattern: `^## ${esc(v)}` }),
53
+ }
54
+ }
55
+
56
+ function folderNotes(root: string, u: ReleaseUnit, dir: string): UnitNotes {
57
+ const rel = relative(root, dir)
58
+ const read = (v: string): Release | null => {
59
+ const f = join(dir, fileOf(v))
60
+ return existsSync(f) ? parseRelease(readFileSync(f, 'utf8'), `${rel}/${fileOf(v)}`) : null
61
+ }
62
+ let next: Release | null = null
63
+ let nextError: string | null = null
64
+ try {
65
+ next = read(NEXT)
66
+ } catch (e) {
67
+ nextError = (e as Error).message
68
+ }
69
+ return {
70
+ rel,
71
+ hasUnreleased: next != null,
72
+ hasUnreleasedNotes: next != null && changesOf(next).length > 0,
73
+ kind: next?.kind ?? null,
74
+ hasVersion: (v) => existsSync(join(dir, fileOf(v))),
75
+ section: (v) => {
76
+ const r = read(v)
77
+ if (r == null) throw new Error(`${rel} has no ${fileOf(v)}: write the notes, then release`)
78
+ const notes = releaseNotes(r)
79
+ if (notes === '') throw new Error(`${rel}/${fileOf(v)} holds no change: write the notes, then release`)
80
+ return notes
81
+ },
82
+ promote: (v, date) => {
83
+ if (nextError != null) return { error: nextError }
84
+ if (next == null) return { error: `${rel} has no ${fileOf(NEXT)}: write the changes of this version in it, then bump` }
85
+ if (existsSync(join(dir, fileOf(v)))) return { error: `${rel}/${fileOf(v)} exists already: that version is written` }
86
+ let done: Release
87
+ try {
88
+ done = promoted(next, v, date)
89
+ } catch (e) {
90
+ return { error: (e as Error).message }
91
+ }
92
+ const writes: NotesWrite[] = [
93
+ { path: join(dir, fileOf(v)), text: renderRelease(done) },
94
+ { path: join(dir, fileOf(NEXT)), text: null },
95
+ ]
96
+ // a unit read on npm keeps a CHANGELOG.md, made from the files, its sections from before them kept: npm and
97
+ // GitHub show it. Notes still waiting under its Unreleased heading would be lost, so they refuse
98
+ if (u.targets.npm) {
99
+ const before = existsSync(u.changelog) ? readFileSync(u.changelog, 'utf8') : ''
100
+ if (!('error' in promoteUnreleased(before, '0.0.0')))
101
+ return { error: `${relative(root, u.changelog)} still holds "## Unreleased" notes: move them into ${rel}/${fileOf(NEXT)}, then bump` }
102
+ writes.push({ path: u.changelog, text: changelogOf([...releasedIn(dir, rel), done], before) })
103
+ }
104
+ return { writes }
105
+ },
106
+ anchor: (v) => ({ rel: `${rel}/${fileOf(v)}`, pattern: `^# ${esc(v)}` }),
107
+ }
108
+ }
109
+
110
+ /** every released version's file of the folder, parsed */
111
+ function releasedIn(dir: string, rel: string): Release[] {
112
+ return readdirSync(dir)
113
+ .filter((f) => /^\d+\.\d+\.\d+\.md$/.test(f))
114
+ .map((f) => parseRelease(readFileSync(join(dir, f), 'utf8'), `${rel}/${f}`))
115
+ }
116
+
117
+ /** next.md's private pictures made public, the file written with their URLs: how many went public */
118
+ export async function publishNext(root: string): Promise<number> {
119
+ const { readRelease, writeRelease } = await import('../releases/store.ts')
120
+ const { publishPictures } = await import('../releases/pictures.ts')
121
+ const { loadSocialUnit } = await import('../social/unit.ts')
122
+ const next = readRelease(root, NEXT)
123
+ if (next == null) return 0
124
+ const { release, published } = await publishPictures(root, next, await loadSocialUnit(root))
125
+ if (published > 0) writeRelease(root, release)
126
+ return published
127
+ }
128
+
129
+ /** the notes of one unit, from where it keeps them */
130
+ export const unitNotes = (root: string, u: ReleaseUnit): UnitNotes => (u.releases != null ? folderNotes(root, u, u.releases) : changelogNotes(root, u))
@@ -26,10 +26,10 @@
26
26
  // every selected unit's package.json and changelog. The publish part is
27
27
  // RESUMABLE instead, because an npm publish cannot be undone and a rollback
28
28
  // that cannot roll back is a lie.
29
- import { existsSync, readFileSync, realpathSync, writeFileSync } from 'fs'
29
+ import { existsSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'fs'
30
30
  import { homedir } from 'os'
31
31
  import { join, relative } from 'path'
32
- import { declaredKind, hasUnreleasedNotes, promoteUnreleased } from './changelog.ts'
32
+ import { publishNext, unitNotes } from './notes.ts'
33
33
  import { deriveRemote, dirtyPathList, dirtyPaths, git as gitAt, mergeProbe, remoteTags, tagExistsLocally } from './git-facts.ts'
34
34
  import { unitBlockers } from './unit-gate.ts'
35
35
  import { publicCleanBlockers } from './public-clean.ts'
@@ -216,7 +216,13 @@ function probeMergeIntoReleaseBranch(
216
216
  * another worktree cannot stop it */
217
217
  const rehearsalOnly = (o: BumpOpts): boolean => o.dryRun === true
218
218
 
219
- type Selected = { unit: ReleaseUnit; version: string; changelogRel: string; kind: BumpKind }
219
+ type Selected = { unit: ReleaseUnit; version: string; notesRel: string; kind: BumpKind }
220
+
221
+ /** the local date a version is written on, YYYY-MM-DD */
222
+ const today = (): string => {
223
+ const d = new Date()
224
+ return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
225
+ }
220
226
 
221
227
  export async function runBump(root: string, config: RepoConfig, kind: BumpKind | null, o: BumpOpts = {}): Promise<number> {
222
228
  const print = o.print ?? ((l: string) => console.log(l))
@@ -366,9 +372,10 @@ export async function runBump(root: string, config: RepoConfig, kind: BumpKind |
366
372
  if (o.all === true) {
367
373
  picked = []
368
374
  for (const u of all) {
369
- if (!existsSync(u.changelog)) { print(`skip: ${u.id} — no changelog at ${relative(root, u.changelog)}`); continue }
370
- if (hasUnreleasedNotes(readFileSync(u.changelog, 'utf8'))) picked.push(u)
371
- else print(`skip: ${u.id} — no Unreleased notes`)
375
+ const notes = unitNotes(root, u)
376
+ if (u.releases == null && !existsSync(u.changelog)) { print(`skip: ${u.id}: no changelog at ${notes.rel}`); continue }
377
+ if (notes.hasUnreleasedNotes) picked.push(u)
378
+ else print(`skip: ${u.id}: no Unreleased notes in ${notes.rel}`)
372
379
  }
373
380
  if (picked.length === 0) return fail('no unit has non-empty Unreleased notes — write what changed, then bump')
374
381
  } else {
@@ -387,22 +394,22 @@ export async function runBump(root: string, config: RepoConfig, kind: BumpKind |
387
394
  const blockers: string[] = []
388
395
  const selected: Selected[] = []
389
396
  for (const unit of picked) {
390
- const changelogRel = relative(root, unit.changelog)
391
- if (!existsSync(unit.changelog)) { blockers.push(`unit '${unit.id}': ${changelogRel} not found — a release states what changed`); continue }
392
- const source = readFileSync(unit.changelog, 'utf8')
397
+ const notes = unitNotes(root, unit)
398
+ const notesRel = notes.rel
393
399
  // an explicit kind on the command line wins for the whole selection.
394
400
  // Without one, each unit answers for itself from its own heading, and
395
401
  // a unit that never said is a refusal: guessing a version number
396
402
  // publishes it, and a published number cannot be recalled.
397
- const unitKind = kind ?? declaredKind(source)
403
+ const unitKind = kind ?? notes.kind
398
404
  if (unitKind == null) {
399
- blockers.push(`unit '${unit.id}': ${changelogRel} does not say what kind of release this is — write "## Unreleased (minor)", or pass a kind that applies to every selected unit`)
405
+ const write = unit.releases != null ? '"# next (minor)" in next.md' : '"## Unreleased (minor)"'
406
+ blockers.push(`unit '${unit.id}': ${notesRel} does not say what kind of release this is: write ${write}, or pass a kind that applies to every selected unit`)
400
407
  continue
401
408
  }
402
409
  let version: string
403
410
  try { version = nextVersion(unit.version, unitKind) }
404
411
  catch (e) { blockers.push(`unit '${unit.id}': ${e instanceof Error ? e.message : String(e)}`); continue }
405
- const promoted = promoteUnreleased(source, version)
412
+ const promoted = notes.promote(version, today())
406
413
  if ('error' in promoted) { blockers.push(`unit '${unit.id}': ${promoted.error}`); continue }
407
414
  const tag = renderTag(unit, version)
408
415
  if (tagExistsLocally(root, tag)) {
@@ -414,7 +421,7 @@ export async function runBump(root: string, config: RepoConfig, kind: BumpKind |
414
421
  continue
415
422
  }
416
423
  blockers.push(...unitBlockers(root, config, unit), ...(await publicCleanBlockers(root, config, unit)))
417
- selected.push({ unit, version, changelogRel, kind: unitKind })
424
+ selected.push({ unit, version, notesRel, kind: unitKind })
418
425
  }
419
426
  // everything the release needs that does not depend on the new version.
420
427
  // HEAD is the release branch by now, so the branch check applies — except
@@ -465,6 +472,7 @@ export async function runBump(root: string, config: RepoConfig, kind: BumpKind |
465
472
  // real bump that aborts mid-merge
466
473
  if (mergeUnknown) print(`WARN dry run inconclusive — would write ${what}, but the merge into '${branch}' could not be checked (git 2.38+ answers it)`)
467
474
  else print(`ok: dry run clean — would write ${what}, commit, then ${o.noRelease === true ? 'stop' : 'release'}`)
475
+ for (const s of selected.filter((x) => x.unit.releases != null)) print(` it did NOT make the pictures of ${s.notesRel}/next.md public: the real bump does, after the repo's guard reads them`)
468
476
  // what the rehearsal did NOT cover, said out loud: a merge that never
469
477
  // happened cannot have been gated, and a number computed on the
470
478
  // feature branch can differ from the one the real bump writes
@@ -484,20 +492,35 @@ export async function runBump(root: string, config: RepoConfig, kind: BumpKind |
484
492
  closeMergeWindow()
485
493
  const failKeep = (msg: string, fixLine: string): number => { print(`FAIL: ${msg}`); print(` fix: ${fixLine}`); return 1 }
486
494
  const files: string[] = []
495
+ for (const s of selected) {
496
+ // a release file's pictures go public now, never before: the version ships, the guard read their bytes
497
+ if (s.unit.releases != null) {
498
+ try {
499
+ const n = await publishNext(root)
500
+ if (n > 0) print(`ok: ${n} picture${n === 1 ? '' : 's'} of ${s.notesRel}/next.md made public`)
501
+ } catch (e) {
502
+ return failKeep(`${s.unit.id}: ${(e as Error).message}`, `fix the change in ${s.notesRel}/next.md, then run bump again`)
503
+ }
504
+ }
505
+ }
487
506
  for (const s of selected) {
488
507
  const pkgRel = s.unit.rel === '' ? 'package.json' : `${s.unit.rel}/package.json`
489
508
  // re-read: a merge can have changed both files under us
490
509
  const pkgNow = readFileSync(`${root}/${pkgRel}`, 'utf8')
491
- const promoted = promoteUnreleased(readFileSync(s.unit.changelog, 'utf8'), s.version)
492
- if ('error' in promoted) return failKeep(`${s.unit.id}: ${promoted.error}`, `check ${s.changelogRel}, then run bump again`)
510
+ const promoted = unitNotes(root, s.unit).promote(s.version, today())
511
+ if ('error' in promoted) return failKeep(`${s.unit.id}: ${promoted.error}`, `check ${s.notesRel}, then run bump again`)
493
512
  // indentation is preserved by rewriting only the version VALUE, so a bump
494
513
  // never reformats a file the repo cares about
495
514
  const bumped = pkgNow.replace(/("version"\s*:\s*")[^"]*(")/, `$1${s.version}$2`)
496
515
  if (bumped === pkgNow) return failKeep(`${s.unit.id}: could not rewrite the version field in ${pkgRel}`, `git status, then set the version by hand`)
497
516
  writeFileSync(`${root}/${pkgRel}`, bumped)
498
- writeFileSync(s.unit.changelog, promoted.text)
499
- files.push(pkgRel, s.changelogRel)
500
- print(`ok: ${pkgRel} ${s.version}, ${s.changelogRel} section promoted`)
517
+ for (const w of promoted.writes) {
518
+ if (w.text == null) rmSync(w.path, { force: true })
519
+ else writeFileSync(w.path, w.text)
520
+ files.push(relative(root, w.path))
521
+ }
522
+ files.push(pkgRel)
523
+ print(`ok: ${pkgRel} ${s.version}, ${s.notesRel} notes named ${s.version}`)
501
524
  }
502
525
 
503
526
  // every OTHER unit that depends on a bumped one moves its range forward, in
@@ -5,11 +5,11 @@
5
5
  //
6
6
  // every step is idempotent and the pipeline resumes: a run that died after
7
7
  // publishing completes only what is missing. preflight touches nothing.
8
- import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs'
8
+ import { mkdtempSync, rmSync, writeFileSync } from 'fs'
9
9
  import { tmpdir } from 'os'
10
10
  import { join } from 'path'
11
11
  import { runCi } from '../core/run-ci.ts'
12
- import { extractChangelogSection } from './changelog.ts'
12
+ import { unitNotes } from './notes.ts'
13
13
  import { deriveRemote, dirtyPaths, git, remoteTagState, tagExistsLocally, type RemoteTagState } from './git-facts.ts'
14
14
  import { releaseScope } from './release-scope.ts'
15
15
  import { publishCommand, unitBlockers, type Publisher } from './unit-gate.ts'
@@ -29,6 +29,11 @@ export type ReleaseConfig = {
29
29
  tag?: string
30
30
  /** the ROOT unit's versioned changelog (default 'CHANGELOG.md') */
31
31
  changelog?: string
32
+ /** the ROOT unit's notes are the release files of `.shipkit/releases/` (next.md, one md a version), filled from
33
+ * approved review cards; an npm root's CHANGELOG.md is then made from them, its older sections kept. Declared,
34
+ * never inferred from the folder: an approval writes next.md only where this is true. Default false.
35
+ * wiki/tools/shipkit/units.md, The release files */
36
+ releases?: boolean
32
37
  /** publish the ROOT unit to npm, declared and never inferred: a root whose
33
38
  * package.json is not private refuses to release until this says true or
34
39
  * false. A private package NEVER publishes, whatever this says. True makes
@@ -197,8 +202,7 @@ export async function releaseUnit(root: string, config: RepoConfig, unit: Releas
197
202
 
198
203
  const blockers: string[] = []
199
204
  const notesResult = ((): { notes: string } | { error: string } => {
200
- if (!existsSync(unit.changelog)) return { error: `unit '${unit.id}': CHANGELOG not found at ${unit.changelog} — a release states what changed` }
201
- try { return { notes: extractChangelogSection({ changelog: readFileSync(unit.changelog, 'utf8'), version }) } }
205
+ try { return { notes: unitNotes(root, unit).section(version) } }
202
206
  catch (e) { return { error: `unit '${unit.id}': ${e instanceof Error ? e.message : String(e)}` } }
203
207
  })()
204
208
  if ('error' in notesResult) blockers.push(notesResult.error)
@@ -344,6 +348,20 @@ export async function releaseUnit(root: string, config: RepoConfig, unit: Releas
344
348
  print(`ok: GitHub release ${tag} live`)
345
349
  }
346
350
  print(`ok: ${name}@${version} released${wantNpm ? ' (npm + tag' : ' (tag'}${wantGh ? ' + github release)' : ')'}`)
351
+ // the root unit's post, staged where the repo's social unit declares release headings: a draft that waits for
352
+ // his submit, never a post; a failure warns and names the command to run again
353
+ if (unit.rel === '') {
354
+ try {
355
+ const { loadSocialUnit } = await import('../social/unit.ts')
356
+ const { stageRelease } = await import('../social/release-stage.ts')
357
+ const before = git(root, ['describe', '--tags', '--abbrev=0', `${tag}^`])
358
+ const r = await stageRelease(root, await loadSocialUnit(root), { unit: unit.id, version, notes, tag, ...(before.code === 0 && before.out !== '' ? { since: before.out } : {}) }, config.speaksAs ? { speaksAs: config.speaksAs } : {})
359
+ if (r != null) print(`ok: ${r.created ? 'staged its post' : 'its post already staged'}: ${r.slug}, waiting in Communications`)
360
+ } catch (e) {
361
+ print(`WARN the release's post was not staged: ${(e as Error).message}`)
362
+ print(` fix: shipkit social release ${version} --unit ${unit.id} --notes <the ## ${version} section> --tag ${tag}`)
363
+ }
364
+ }
347
365
  // LAST, and root-unit only: everything above is already published, so
348
366
  // a failed deploy is reported without unwinding any of it
349
367
  const after = unit.rel === '' ? config.release?.after : undefined
@@ -6,9 +6,7 @@
6
6
  // the table stays one line per unit and carries only facts that fit in a
7
7
  // column. Anything that needs a sentence (drift, stale notes, an unreachable
8
8
  // remote) prints BELOW the table, so the noise is proportional to the problem.
9
- import { existsSync, readFileSync } from 'fs'
10
- import { relative } from 'path'
11
- import { hasUnreleasedHeading, hasVersionSection } from './changelog.ts'
9
+ import { unitNotes } from './notes.ts'
12
10
  import { deriveRemote, git, remoteTags } from './git-facts.ts'
13
11
  import { formatUnitError, resolveUnits, type ReleaseUnit } from './units.ts'
14
12
  import type { RepoConfig } from '../repo-config.ts'
@@ -45,6 +43,8 @@ export type UnitReport = {
45
43
  * describe none of it */
46
44
  commitsAfterNotes: number | null
47
45
  hasUnreleased: boolean
46
+ /** where the Unreleased notes are written, as a line says it: `"## Unreleased"`, or the release folder's next.md */
47
+ unreleasedAt: string
48
48
  }
49
49
 
50
50
  const pathspec = (u: ReleaseUnit): string[] => (u.rel === '' ? [] : ['--', u.rel])
@@ -53,8 +53,8 @@ const pathspec = (u: ReleaseUnit): string[] => (u.rel === '' ? [] : ['--', u.rel
53
53
  * purpose: a substring pickaxe also matches prose that MENTIONS `## 1.2.3`,
54
54
  * so a sentence in the Unreleased section moves the anchor to itself and
55
55
  * silences the stale-notes warning it was talking about. */
56
- export function notesAnchor(root: string, changelogRel: string, version: string): string | null {
57
- const h = git(root, ['log', '-1', '--format=%H', '-G', `^## ${version.replace(/\./g, '\\.')}`, '--', changelogRel])
56
+ export function notesAnchor(root: string, at: { rel: string; pattern: string }): string | null {
57
+ const h = git(root, ['log', '-1', '--format=%H', '-G', at.pattern, '--', at.rel])
58
58
  return h.code === 0 && h.out !== '' ? h.out : null
59
59
  }
60
60
 
@@ -110,15 +110,14 @@ async function surveyUnits(root: string, config: RepoConfig, o: { offline?: bool
110
110
  // whole run. Order is preserved by mapping rather than pushing.
111
111
  const reports: UnitReport[] = await Promise.all(units.map(async (u): Promise<UnitReport> => {
112
112
  const tagLocal = git(root, ['rev-parse', '--quiet', '--verify', `refs/tags/${u.tag}`]).code === 0
113
- const changelog = existsSync(u.changelog) ? readFileSync(u.changelog, 'utf8') : ''
114
- const hasSection = hasVersionSection(changelog, u.version)
115
- const changelogRel = relative(root, u.changelog)
113
+ const notes = unitNotes(root, u)
114
+ const hasSection = notes.hasVersion(u.version)
116
115
  // the commit that introduced this version's heading, then everything
117
- // that touched the unit afterwards but is not the changelog itself
116
+ // that touched the unit afterwards but is not the notes themselves
118
117
  let commitsAfterNotes: number | null = null
119
- const anchor = hasSection ? notesAnchor(root, changelogRel, u.version) : null
118
+ const anchor = hasSection ? notesAnchor(root, notes.anchor(u.version)) : null
120
119
  if (anchor != null) {
121
- const c = git(root, ['rev-list', '--count', `${anchor}..HEAD`, ...(u.rel === '' ? ['--'] : ['--', u.rel]), `:(exclude)${changelogRel}`])
120
+ const c = git(root, ['rev-list', '--count', `${anchor}..HEAD`, ...(u.rel === '' ? ['--'] : ['--', u.rel]), `:(exclude)${notes.rel}`])
122
121
  if (c.code === 0) commitsAfterNotes = Number(c.out)
123
122
  }
124
123
  const since = tagLocal ? git(root, ['rev-list', '--count', `${u.tag}..HEAD`, ...pathspec(u)]) : null
@@ -158,7 +157,8 @@ async function surveyUnits(root: string, config: RepoConfig, o: { offline?: bool
158
157
  contentDiffers: tagTree != null && headTree != null ? tagTree !== headTree : null,
159
158
  hasSection,
160
159
  commitsAfterNotes,
161
- hasUnreleased: hasUnreleasedHeading(changelog),
160
+ hasUnreleased: notes.hasUnreleased,
161
+ unreleasedAt: u.releases != null ? `${notes.rel}/next.md` : '"## Unreleased"',
162
162
  }
163
163
  }))
164
164
  return { reports, errors: errors.map(formatUnitError), remote, remoteError }
@@ -198,7 +198,7 @@ export function attentionLines(r: UnitReport): string[] {
198
198
  const out: string[] = []
199
199
  const behindNpm = r.npmTarget && r.npmLatest != null && r.npmLatest !== 'unpublished' && r.npmLatest !== r.version
200
200
  const npmClause = behindNpm ? `, and npm still has ${r.npmLatest ?? ''}` : ''
201
- const notesClause = r.hasUnreleased ? '' : 'write the notes under "## Unreleased", then '
201
+ const notesClause = r.hasUnreleased ? '' : `write the notes in ${r.unreleasedAt}, then `
202
202
  // the tool knows the unit and its state, never whether the change is a fix,
203
203
  // a feature or a break — stating a kind it cannot know is a guess in the
204
204
  // shape of a command
@@ -222,7 +222,7 @@ export function attentionLines(r: UnitReport): string[] {
222
222
  } else if (r.hasUnreleased) {
223
223
  // written notes with no release behind them are a DECISION waiting on
224
224
  // a human, not a defect: a note, so the row still reads as healthy
225
- out.push(`note: ${r.id}: "## Unreleased" notes are waiting — shipkit bump ${KIND} ${r.id}`)
225
+ out.push(`note: ${r.id}: ${r.unreleasedAt} notes are waiting — shipkit bump ${KIND} ${r.id}`)
226
226
  }
227
227
 
228
228
  if (r.commitsSinceTag === 0 && r.contentDiffers === true)
@@ -232,7 +232,9 @@ export function attentionLines(r: UnitReport): string[] {
232
232
  if (r.tagLocal && r.tagRemote === false)
233
233
  out.push(`WARN ${r.id}: ${r.tag} exists here and nowhere else — invisible on GitHub until it is pushed`)
234
234
  if (!r.hasSection && !r.hasUnreleased)
235
- out.push(`WARN ${r.id}: no "## ${r.version}" section and no "## Unreleased" in ${r.id === 'root' ? 'the root changelog' : 'its changelog'} — nothing to release from`)
235
+ out.push(r.unreleasedAt.endsWith('next.md')
236
+ ? `WARN ${r.id}: no ${r.version}.md and no ${r.unreleasedAt}: nothing to release from`
237
+ : `WARN ${r.id}: no "## ${r.version}" section and no "## Unreleased" in ${r.id === 'root' ? 'the root changelog' : 'its changelog'} — nothing to release from`)
236
238
  return out
237
239
  }
238
240