rvlib-shipkit 2.18.0 → 2.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/package.json +1 -1
  3. package/src/annex/annex.ts +227 -0
  4. package/src/annex/offload.ts +279 -0
  5. package/src/asks/asks-queue.ts +63 -10
  6. package/src/checks/SK040-release-words.check.ts +43 -0
  7. package/src/checks/SK041-annex-links.check.ts +28 -0
  8. package/src/checks/SK042-post-kinds.check.ts +73 -0
  9. package/src/cli/cmd_Annex.ts +179 -0
  10. package/src/cli/cmd_Asks.ts +3 -1
  11. package/src/cli/cmd_Commands.ts +4 -1
  12. package/src/cli/cmd_GlobalProcesses.ts +34 -11
  13. package/src/cli/cmd_Home.ts +41 -4
  14. package/src/cli/cmd_Messages.ts +155 -0
  15. package/src/cli/cmd_Releases.ts +48 -0
  16. package/src/cli/cmd_Review.ts +161 -6
  17. package/src/cli/cmd_Secret.ts +4 -30
  18. package/src/cli/cmd_Shot.ts +4 -4
  19. package/src/cli/cmd_Social.ts +179 -3
  20. package/src/cli/cmd_Trailer.ts +15 -3
  21. package/src/cli/family-pages.ts +2 -0
  22. package/src/cli/kit/index.ts +1 -1
  23. package/src/cli/kit/verb.ts +11 -3
  24. package/src/cli/registry.ts +8 -2
  25. package/src/collections/actions.ts +29 -1
  26. package/src/collections/collection-types.ts +10 -1
  27. package/src/collections/providers.ts +5 -2
  28. package/src/commands/model.ts +36 -0
  29. package/src/commands/registry.ts +49 -0
  30. package/src/commands/routes.ts +59 -0
  31. package/src/commands/runner.ts +35 -0
  32. package/src/commands/runs.ts +112 -0
  33. package/src/core/app-icon.ts +4 -3
  34. package/src/core/icon-type.ts +8 -0
  35. package/src/core/jobs.ts +4 -3
  36. package/src/core/layout.ts +5 -2
  37. package/src/core/squircle.ts +95 -0
  38. package/src/home/daemon-jobs.ts +26 -2
  39. package/src/home/global-units.ts +3 -0
  40. package/src/home/gui-app/ShipkitGui.swift +302 -5
  41. package/src/home/gui-app.ts +63 -33
  42. package/src/home/hmr-keep.ts +134 -0
  43. package/src/home/home-paths.ts +5 -1
  44. package/src/home/home-start.ts +14 -14
  45. package/src/home/lib-watch.ts +21 -11
  46. package/src/home/pm.ts +1 -1
  47. package/src/home/process-apps.ts +181 -0
  48. package/src/home/resources.ts +3 -3
  49. package/src/home/run-daemon.ts +11 -2
  50. package/src/home/run-pm.ts +9 -1
  51. package/src/home/run-web.ts +7 -4
  52. package/src/home/serve-web.ts +64 -14
  53. package/src/home/supervise.ts +3 -1
  54. package/src/identities/collection.ts +49 -0
  55. package/src/identities/identities.ts +130 -11
  56. package/src/identities/machine.ts +4 -3
  57. package/src/identities/rating.ts +33 -0
  58. package/src/identities/shown.ts +170 -0
  59. package/src/identities/steps.ts +5 -0
  60. package/src/media-store/purge.ts +15 -1
  61. package/src/media-store/remote.ts +22 -6
  62. package/src/messages/brief.ts +117 -0
  63. package/src/messages/collection.ts +40 -0
  64. package/src/messages/model.ts +171 -0
  65. package/src/messages/routes.ts +15 -0
  66. package/src/messages/score.ts +180 -0
  67. package/src/messages/tabs.ts +13 -0
  68. package/src/release/notes.ts +130 -0
  69. package/src/release/run-bump.ts +41 -18
  70. package/src/release/run-release.ts +22 -4
  71. package/src/release/run-releases.ts +17 -15
  72. package/src/release/unit-resolve.ts +9 -0
  73. package/src/releases/add.ts +66 -0
  74. package/src/releases/collection.ts +36 -0
  75. package/src/releases/from-card.ts +66 -0
  76. package/src/releases/model.ts +267 -0
  77. package/src/releases/pictures.ts +89 -0
  78. package/src/releases/routes.ts +36 -0
  79. package/src/releases/store.ts +71 -0
  80. package/src/repo-config.ts +5 -0
  81. package/src/review/cells.ts +0 -11
  82. package/src/review/format.ts +10 -6
  83. package/src/review/http.ts +7 -2
  84. package/src/review/model.ts +92 -3
  85. package/src/review/notes.ts +2 -48
  86. package/src/review/routes.ts +28 -10
  87. package/src/review/stage-card.ts +197 -0
  88. package/src/review/stage-routes.ts +123 -0
  89. package/src/review/store.ts +117 -19
  90. package/src/review/trailer-card.ts +99 -0
  91. package/src/review/trailer-desk.ts +57 -4
  92. package/src/review/trailer-model.ts +41 -7
  93. package/src/review/trailer-notes.ts +45 -0
  94. package/src/review/trailer-routes.ts +22 -13
  95. package/src/secrets/manager.ts +59 -0
  96. package/src/secrets/name.ts +2 -0
  97. package/src/serve/hub-app/app-bridge.ts +71 -0
  98. package/src/serve/hub-app/col-card.tsx +10 -0
  99. package/src/serve/hub-app/cols-svc.ts +37 -6
  100. package/src/serve/hub-app/commands/commands-page.tsx +122 -0
  101. package/src/serve/hub-app/commands/commands-st.ts +177 -0
  102. package/src/serve/hub-app/commands.css +24 -0
  103. package/src/serve/hub-app/hash-route.ts +40 -1
  104. package/src/serve/hub-app/home-st.ts +11 -2
  105. package/src/serve/hub-app/home.html +3 -0
  106. package/src/serve/hub-app/hub-app.tsx +6 -0
  107. package/src/serve/hub-app/hub.css +1 -0
  108. package/src/serve/hub-app/icons.tsx +5 -0
  109. package/src/serve/hub-app/identities-view.tsx +4 -1
  110. package/src/serve/hub-app/identities.css +1 -0
  111. package/src/serve/hub-app/index.html +3 -0
  112. package/src/serve/hub-app/keys.ts +2 -2
  113. package/src/serve/hub-app/machine-st.ts +41 -10
  114. package/src/serve/hub-app/messages/messages-page.tsx +354 -0
  115. package/src/serve/hub-app/messages/messages-st.ts +74 -0
  116. package/src/serve/hub-app/messages.css +35 -0
  117. package/src/serve/hub-app/releases/releases-page.tsx +94 -0
  118. package/src/serve/hub-app/releases/releases-st.ts +69 -0
  119. package/src/serve/hub-app/releases.css +25 -0
  120. package/src/serve/hub-app/repo-sections.ts +15 -1
  121. package/src/serve/hub-app/repo-st.ts +56 -5
  122. package/src/serve/hub-app/review/clip-st.ts +31 -3
  123. package/src/serve/hub-app/review/note-place.ts +31 -0
  124. package/src/serve/hub-app/review/review-cells.tsx +27 -3
  125. package/src/serve/hub-app/review/review-st.ts +77 -2
  126. package/src/serve/hub-app/review/review-thread.tsx +9 -31
  127. package/src/serve/hub-app/review/review-views.tsx +164 -58
  128. package/src/serve/hub-app/review/thread-st.ts +108 -41
  129. package/src/serve/hub-app/review/trailer-card.tsx +187 -0
  130. package/src/serve/hub-app/review/trailer-page.tsx +62 -31
  131. package/src/serve/hub-app/review/trailer-st.ts +138 -26
  132. package/src/serve/hub-app/review/trailer-timeline.tsx +39 -26
  133. package/src/serve/hub-app/review.css +49 -6
  134. package/src/serve/hub-app/social/comms-page.tsx +55 -23
  135. package/src/serve/hub-app/social/identity-pictures.ts +112 -0
  136. package/src/serve/hub-app/social/kit.tsx +9 -6
  137. package/src/serve/hub-app/social/post-card.tsx +10 -2
  138. package/src/serve/hub-app/social/social-model.ts +37 -3
  139. package/src/serve/hub-app/social/social-page.tsx +236 -82
  140. package/src/serve/hub-app/social/social-st.ts +79 -26
  141. package/src/serve/hub-app/social/stage-popup.tsx +268 -0
  142. package/src/serve/hub-app/social/stage-st.ts +310 -0
  143. package/src/serve/hub-app/social/step-layout.ts +42 -0
  144. package/src/serve/hub-app/social.css +68 -4
  145. package/src/serve/hub-app/tree-build.ts +38 -1
  146. package/src/serve/hub-app/tree-svc.ts +10 -3
  147. package/src/serve/project-gutter-route.ts +4 -2
  148. package/src/serve/same-origin.ts +24 -1
  149. package/src/serve/serve-hub.ts +27 -3
  150. package/src/shipkit-files.ts +9 -7
  151. package/src/shot/shooter.ts +3 -3
  152. package/src/shot/shot-ask.ts +14 -3
  153. package/src/shot/shot.shipkit.ts +1 -1
  154. package/src/social/discord-layout.ts +282 -0
  155. package/src/social/fit.ts +84 -0
  156. package/src/social/identity-words.ts +74 -0
  157. package/src/social/kind-pages.ts +41 -0
  158. package/src/social/kinds.ts +92 -0
  159. package/src/social/load.ts +105 -9
  160. package/src/social/md.ts +14 -6
  161. package/src/social/media-limit.ts +63 -2
  162. package/src/social/presence.ts +1 -1
  163. package/src/social/publish/bluesky.ts +58 -19
  164. package/src/social/publish/discord.ts +3 -2
  165. package/src/social/publish/index.ts +31 -5
  166. package/src/social/reach.ts +49 -0
  167. package/src/social/release-stage.ts +173 -0
  168. package/src/social/routes.ts +44 -9
  169. package/src/social/stage.ts +227 -0
  170. package/src/social/strip.ts +85 -0
  171. package/src/social/text.ts +6 -2
  172. package/src/social/unit.ts +57 -1
  173. package/src/social/writes.ts +11 -0
  174. package/src/stores/routes.ts +2 -2
  175. package/src/suite/judge-suites.ts +1 -1
  176. package/src/suite/suite-cli.ts +5 -5
  177. package/src/trailer/build.ts +90 -52
  178. package/src/trailer/draft.ts +28 -0
  179. package/src/trailer/footage.ts +4 -2
  180. package/src/trailer/grammar.ts +25 -13
  181. package/src/trailer/graph.ts +32 -9
  182. package/src/trailer/profile.ts +35 -0
  183. package/src/trailer/prune.ts +15 -10
  184. package/src/trailer/public-words.ts +41 -0
  185. package/src/trailer/stitch.ts +22 -10
  186. package/src/trailer/titles.ts +47 -2
@@ -26,6 +26,13 @@ async function guarded(c: Ctx, body: () => Promise<number>): Promise<number> {
26
26
  }
27
27
  }
28
28
 
29
+ /** the shown.md files a push wrote, committed by their paths alone */
30
+ async function recorded(files: string[], message: string): Promise<void> {
31
+ if (files.length === 0) return
32
+ const { commitPaths } = await import('../social/writes.ts')
33
+ commitPaths(files, message)
34
+ }
35
+
29
36
  const asOpt = (): string | undefined => Option.String('--as', { description: "the identity, by id (default: the one this repo speaks as)" })
30
37
 
31
38
  class SocialCommand extends Command {
@@ -98,19 +105,90 @@ class SocialPostCommand extends Command {
98
105
  static override usage = Command.Usage({
99
106
  category: 'Social',
100
107
  description: 'one draft across every account of its headings: posted with its date and link, or waiting',
108
+ details:
109
+ "--publish posts the waiting messages of its accounts whose automation is live (Discord, Bluesky), each link recorded in its ## Posted; --only <account> keeps that account's alone. A message the repo's guard or a place refuses never posts. Every other account waits for his paste: nothing posts without an order. Page: wiki tools/shipkit/social.md, A post staged",
101
110
  examples: [
102
111
  ['by its topic', 'sk social post arena-face-lift'],
103
112
  ['by its whole name', 'sk social post 20261025-131139-arena-face-lift'],
113
+ ["a release's #announcements line, at release", 'sk social post 20261108-120000-app-1-2-0 --only discord --publish'],
104
114
  ],
105
115
  })
106
116
  draft = Option.String({ required: true })
117
+ only = Option.String('--only', { description: 'one account: its messages alone' })
118
+ publish = Option.Boolean('--publish', false, { description: 'post the waiting messages of its live accounts now' })
107
119
  override async execute(): Promise<number> {
108
120
  return guarded(this.context, async () => {
109
121
  const { desk } = await model(undefined)
110
122
  const d = desk.drafts.find((x) => x.slug === this.draft || x.slug.replace(/^\d{8}-\d{6}-/, '') === this.draft)
111
123
  if (d == null) throw new Error(`no draft "${this.draft}" in .shipkit/social/drafts/: give its folder's name or its topic`)
124
+ const only = this.only
125
+ if (only != null && !d.posts.some((p) => p.platform === only)) throw new Error(`${d.slug} has no message to ${only} (${[...new Set(d.posts.map((p) => p.platform))].join(', ') || 'none'})`)
126
+ if (this.publish) {
127
+ const { publishDraft } = await import('../social/publish/index.ts')
128
+ const { socialMediaBack } = await import('../social/media-kind.ts')
129
+ const before = async (p: { media: { path: string } | null }): Promise<void> => void (p.media ? await socialMediaBack(desk.root, p.media.path) : undefined)
130
+ for (const r of await publishDraft(desk, d.slug, { ...(only != null ? { only } : {}), before })) say(this.context)(`${r.key}: ${r.line}`)
131
+ return 0
132
+ }
112
133
  const { socialModel, postText } = await import('../social/text.ts')
113
- for (const l of postText(socialModel(desk, d.identity), d.slug)) say(this.context)(l)
134
+ const lines = postText(socialModel(desk, d.identity), d.slug)
135
+ for (const l of only == null ? lines : lines.filter((l) => !/^[a-z0-9-]+(?:\/[a-z0-9-]+)?\s{2}/.test(l) || l.startsWith(`${only} `) || l.startsWith(`${only}/`))) say(this.context)(l)
136
+ return 0
137
+ })
138
+ }
139
+ }
140
+
141
+ class SocialReleaseCommand extends Command {
142
+ static override paths = [['social', 'release']]
143
+ static override usage = Command.Usage({
144
+ category: 'Social',
145
+ description: "a release staged as one post draft: a heading per venue the social unit declares, never posted",
146
+ details:
147
+ "The draft waits in Communications with its polish note: the release message (else the notes' lines) under each heading of the social unit's release.headings, the notes in its angle, the range --since..--tag whose approved cards lend it their media. A second call for the same release writes nothing. A repo whose social unit declares no release headings stages nothing. Page: wiki tools/shipkit/social.md, A post staged",
148
+ examples: [
149
+ ["an app's release, its notes on stdin, its message from a file", 'sk social release 1.2.0 --unit app --notes - --message msg.md --tag app-v1.2.0 --since app-v1.1.0'],
150
+ ],
151
+ })
152
+ version = Option.String({ required: true })
153
+ unit = Option.String('--unit', { description: "the unit released (default: the repo's folder name)" })
154
+ notes = Option.String('--notes', { required: true, description: "the release's notes: a file, or - for stdin" })
155
+ message = Option.String('--message', { description: 'the short message for users: a file, or - for stdin' })
156
+ tag = Option.String('--tag', { description: "the release's tag" })
157
+ since = Option.String('--since', { description: 'the tag before it' })
158
+ title = Option.String('--title', { description: "the draft's title (default <unit> <version>)" })
159
+ override async execute(): Promise<number> {
160
+ return guarded(this.context, async () => {
161
+ const { readFileSync } = await import('node:fs')
162
+ const { basename } = await import('node:path')
163
+ const { findRepoRoot } = await import('../ts/config.ts')
164
+ const { loadRepoConfig } = await import('../repo-config.ts')
165
+ const { loadSocialUnit } = await import('../social/unit.ts')
166
+ const { stageRelease } = await import('../social/release-stage.ts')
167
+ if (this.notes === '-' && this.message === '-') throw new Error('one of --notes and --message reads stdin, never both')
168
+ const text = async (v: string): Promise<string> => (v === '-' ? await new Response(Bun.stdin.stream()).text() : readFileSync(v, 'utf8'))
169
+ const root = findRepoRoot(process.cwd())
170
+ const unit = await loadSocialUnit(root)
171
+ const speaksAs = (await loadRepoConfig(root).catch(() => null))?.speaksAs
172
+ const r = await stageRelease(
173
+ root,
174
+ unit,
175
+ {
176
+ unit: this.unit ?? basename(root),
177
+ version: this.version,
178
+ notes: await text(this.notes),
179
+ ...(this.message ? { message: await text(this.message) } : {}),
180
+ ...(this.tag ? { tag: this.tag } : {}),
181
+ ...(this.since ? { since: this.since } : {}),
182
+ ...(this.title ? { title: this.title } : {}),
183
+ },
184
+ speaksAs ? { speaksAs } : {},
185
+ )
186
+ if (r == null) say(this.context)("ok: the repo's social unit declares no release headings: nothing staged")
187
+ else if (!r.created) say(this.context)(`ok: already staged: ${r.slug}`)
188
+ else {
189
+ say(this.context)(`staged ${r.slug}: waiting in Communications, its polish note raised`)
190
+ for (const e of r.errors) say(this.context)(`WARN ${e}`)
191
+ }
114
192
  return 0
115
193
  })
116
194
  }
@@ -187,6 +265,48 @@ class SocialMigrateCommand extends Command {
187
265
  }
188
266
  }
189
267
 
268
+ class SocialDiscordApplyCommand extends Command {
269
+ static override paths = [['social', 'discord', 'apply']]
270
+ static override usage = Command.Usage({
271
+ category: 'Social',
272
+ description: "an identity's Discord server made to match its layout.md through its bot: roles, channels",
273
+ details:
274
+ "The layout is `layout.md` beside the identity's discord `account.md`, which names the server (`guild`) and the bot's token (`secret`). It creates, renames, moves, sets topics, read only, age restricted and role only channels; a server that matches gets no write. It never deletes but with --prune, and then only an empty text channel the layout lacks. With no guild yet, it names the servers the bot is in. Nothing is sent while the guard of a repo speaking as the identity refuses one of its words or pictures. Page: wiki tools/shipkit/social-identities.md, The server's layout",
275
+ examples: [
276
+ ['what would change', 'sk social discord apply studio --dry'],
277
+ ['as this repo speaks', 'sk social discord apply'],
278
+ ['and delete the empty channels it lacks', 'sk social discord apply studio --prune'],
279
+ ],
280
+ })
281
+ identity = Option.String({ required: false })
282
+ dry = Option.Boolean('--dry', false, { description: 'print what would change, write nothing' })
283
+ prune = Option.Boolean('--prune', false, { description: 'delete an empty text channel the layout lacks' })
284
+ override async execute(): Promise<number> {
285
+ return guarded(this.context, async () => {
286
+ const { loadIdentities, identityOf, speakerOf } = await import('../identities/identities.ts')
287
+ const { applyLayout } = await import('../social/discord-layout.ts')
288
+ const ids = await loadIdentities()
289
+ let id = this.identity
290
+ if (id == null) {
291
+ const { findRepoRoot } = await import('../ts/config.ts')
292
+ const { loadRepoConfig } = await import('../repo-config.ts')
293
+ id = speakerOf((await loadRepoConfig(findRepoRoot(process.cwd()))).speaksAs, ids)?.id
294
+ if (id == null) throw new Error('no identity named and none this repo speaks as')
295
+ }
296
+ const i = identityOf(id, ids)
297
+ const a = i.accounts.find((x) => x.id === 'discord')
298
+ if (a == null) throw new Error(`${id} has no discord account (accounts/discord/account.md)`)
299
+ await (await import('../social/identity-words.ts')).refuseUnguarded(i)
300
+ const r = await applyLayout(a, { dry: this.dry, prune: this.prune })
301
+ await recorded(r.recorded, `identities: ${id} discord server pictures set by the bot`)
302
+ for (const l of r.changes) say(this.context)(l)
303
+ if (r.changes.length === 0) say(this.context)(`ok: the server of ${id} matches its layout and its pictures`)
304
+ for (const l of r.left) say(this.context)(`left alone: ${l}`)
305
+ return 0
306
+ })
307
+ }
308
+ }
309
+
190
310
  class IdentitiesCommand extends Command {
191
311
  static override paths = [['identities']]
192
312
  static override usage = Command.Usage({
@@ -215,7 +335,7 @@ class IdentitiesCommand extends Command {
215
335
  into.set(id, [...(into.get(id) ?? []), r.name])
216
336
  }
217
337
  if (this.json) {
218
- say(this.context)(JSON.stringify({ dir: ids.dir, identities: ids.identities.map((i) => ({ id: i.id, name: i.name, default: i.default, site: i.site, accounts: i.accounts.map((a) => ({ id: a.id, handle: a.handle, live: a.live })), repos: by.get(i.id) ?? [], archived: old.get(i.id) ?? [] })), unnamed, seen: all.length, errors: ids.errors }))
338
+ say(this.context)(JSON.stringify({ dir: ids.dir, identities: ids.identities.map((i) => ({ id: i.id, name: i.name, default: i.default, site: i.site, accounts: i.accounts.map((a) => ({ id: a.id, handle: a.handle, live: a.live, stale: a.uploads.filter((u) => u.stale).map((u) => ({ row: u.field, kind: u.kind, by: u.by, file: u.files[0] ?? null, shown: u.shown?.sha ?? null })) })), repos: by.get(i.id) ?? [], archived: old.get(i.id) ?? [] })), unnamed, seen: all.length, errors: ids.errors }))
219
339
  return ids.errors.length || unnamed.length ? 1 : 0
220
340
  }
221
341
  for (const i of ids.identities) {
@@ -224,6 +344,16 @@ class IdentitiesCommand extends Command {
224
344
  say(this.context)(` online: ${online.map((a) => `${a.id} ${a.handle}`).join(', ') || 'none'}`)
225
345
  const archived = old.get(i.id) ?? []
226
346
  say(this.context)(` repos: ${(by.get(i.id) ?? []).join(', ') || 'none'}${archived.length > 0 ? `; archived: ${archived.join(', ')}` : ''}`)
347
+ for (const a of i.accounts) {
348
+ const stale = a.uploads.filter((u) => u.stale && u.kind === 'picture')
349
+ const texts = a.uploads.filter((u) => u.stale && u.kind === 'text').map((u) => u.field)
350
+ if (texts.length > 0) say(this.context)(` to paste again on ${a.name}: ${texts.join(', ')}`)
351
+ if (stale.length === 0) continue
352
+ const hands = stale.filter((u) => u.by == null).map((u) => u.field)
353
+ const api = stale.filter((u) => u.by != null).map((u) => u.field)
354
+ const parts = [...(hands.length > 0 ? [hands.join(', ')] : []), ...(api.length > 0 ? [`the api sets ${api.join(', ')}: sk identities push ${i.id}`] : [])]
355
+ say(this.context)(` to upload on ${a.name}${a.live === '' ? ' (still to create)' : ''}: ${parts.join('; ')}`)
356
+ }
227
357
  }
228
358
  if (all.length === 0) say(this.context)(`note: no house repo seen from ${process.cwd()}, so every identity lists none: run it from a repo beside the house`)
229
359
  if (unnamed.length > 0) say(this.context)(`FAIL: ${unnamed.length} repo(s) name no speaksAs (SK038): ${unnamed.join(', ')}`)
@@ -233,4 +363,50 @@ class IdentitiesCommand extends Command {
233
363
  }
234
364
  }
235
365
 
236
- export const SOCIAL_COMMANDS = [SocialCommand, SocialTimelineCommand, SocialCoverageCommand, SocialPostCommand, SocialPlanCommand, SocialStateCommand, SocialMigrateCommand, IdentitiesCommand]
366
+ class IdentitiesPushCommand extends Command {
367
+ static override paths = [['identities', 'push']]
368
+ static override usage = Command.Usage({
369
+ category: 'Social',
370
+ description: "an identity's stale pictures set where an api reaches: Discord's bot, Bluesky",
371
+ details:
372
+ "Each account records in shown.md the sha of the picture each row was last given; a row whose picture changed since, or that records none, is stale. This sets the stale rows an api reaches (Discord: icon, banner and invite splash through the bot; Bluesky with automation live: avatar and banner) and records each one. X, Reddit and the rest stay his hands: the hub's identity view and sk needs list them. Nothing is set while the guard of a repo speaking as the identity refuses one of its words or pictures. Page: wiki tools/shipkit/social-identities.md, What each account shows",
373
+ examples: [
374
+ ['what would be set', 'sk identities push studio --dry'],
375
+ ['as this repo speaks', 'sk identities push'],
376
+ ],
377
+ })
378
+ identity = Option.String({ required: false })
379
+ dry = Option.Boolean('--dry', false, { description: 'print what would be set, write nothing' })
380
+ override async execute(): Promise<number> {
381
+ return guarded(this.context, async () => {
382
+ const { loadIdentities, identityOf, speakerOf } = await import('../identities/identities.ts')
383
+ const { pushServerPictures } = await import('../social/discord-layout.ts')
384
+ const { pushProfilePictures } = await import('../social/publish/bluesky.ts')
385
+ const ids = await loadIdentities()
386
+ let id = this.identity
387
+ if (id == null) {
388
+ const { findRepoRoot } = await import('../ts/config.ts')
389
+ const { loadRepoConfig } = await import('../repo-config.ts')
390
+ id = speakerOf((await loadRepoConfig(findRepoRoot(process.cwd()))).speaksAs, ids)?.id
391
+ if (id == null) throw new Error('no identity named and none this repo speaks as')
392
+ }
393
+ const i = identityOf(id, ids)
394
+ await (await import('../social/identity-words.ts')).refuseUnguarded(i)
395
+ let set = 0
396
+ for (const a of i.accounts) {
397
+ const r = a.id === 'discord' ? await pushServerPictures(a, { dry: this.dry }) : a.id === 'bluesky' ? await pushProfilePictures(a, { dry: this.dry }) : null
398
+ if (r == null) continue
399
+ await recorded(r.recorded, `identities: ${id} ${a.id} pictures set through its api`)
400
+ set += r.changes.length
401
+ for (const l of r.changes) say(this.context)(`${a.name}: ${l}`)
402
+ for (const l of r.left) say(this.context)(`${a.name}: left alone: ${l}`)
403
+ }
404
+ if (set === 0) say(this.context)(`ok: no stale picture of ${id} an api reaches`)
405
+ const hands = i.accounts.filter((a) => a.uploads.some((u) => u.stale && u.by == null))
406
+ if (hands.length > 0) say(this.context)(`his hands: ${hands.map((a) => `${a.name} ${a.uploads.filter((u) => u.stale && u.by == null).map((u) => u.field).join(', ')}`).join('; ')}`)
407
+ return 0
408
+ })
409
+ }
410
+ }
411
+
412
+ export const SOCIAL_COMMANDS = [SocialCommand, SocialTimelineCommand, SocialCoverageCommand, SocialPostCommand, SocialReleaseCommand, SocialPlanCommand, SocialStateCommand, SocialMigrateCommand, SocialDiscordApplyCommand, IdentitiesCommand, IdentitiesPushCommand]
@@ -36,6 +36,8 @@ export class TrailerCommand extends Command {
36
36
  ['film again the takes of two shots', 'sk trailer --refilm intro,menu'],
37
37
  ['encoded by x264 for a release', 'sk trailer --final'],
38
38
  ['the music variant b on the same picture', 'sk trailer --variant b'],
39
+ ['a quick draft to judge the beats', 'sk trailer --draft'],
40
+ ['where the build spends its time', 'sk trailer --profile'],
39
41
  ],
40
42
  })
41
43
 
@@ -43,13 +45,23 @@ export class TrailerCommand extends Command {
43
45
  refilm = Option.String('--refilm', { tolerateBoolean: true, description: 'film again: every stale take, or the named shots (a,b)' })
44
46
  final = Option.Boolean('--final', false, { description: 'encode with x264 for a release (default: the fast draft encoder)' })
45
47
  variant = Option.String('--variant', { description: 'a music variant the cut names (music … variant <name>): out/<name>-<variant>.mp4' })
48
+ draft = Option.Boolean('--draft', false, { description: 'a quick draft at half the size: out/<name>-draft.mp4, the cut\'s takes read as they are, a missing one filmed small, no strip' })
49
+ strip = Option.Boolean('--strip', false, { description: 'with --draft: its strip too' })
50
+ profile = Option.Boolean('--profile', false, { description: 'print every phase of the build with its start, seconds and share' })
46
51
 
47
52
  async execute(): Promise<number> {
48
53
  return run(this.context, async (say, root, cwd) => {
49
- const b = await import('../trailer/build.ts')
50
- const l = await b.load(b.trailerFile(this.file, root, cwd), root, this.variant !== undefined ? { variant: this.variant } : {})
54
+ const { span, timed, profileLines } = await import('../trailer/profile.ts')
55
+ span('start: bun, sk, the cli', 0, performance.now())
56
+ const b = await timed('load: build modules', () => import('../trailer/build.ts'))
57
+ const l = await timed('load: parse and check', () => b.load(b.trailerFile(this.file, root, cwd), root, this.variant !== undefined ? { variant: this.variant } : {}))
51
58
  if (!b.sayErrors(l, say, cwd)) return 1
52
- await b.build(l, { refilm: refilmOf(this.refilm), final: this.final, say, cwd })
59
+ try {
60
+ const draft = this.draft ? { draft: (await import('../trailer/draft.ts')).DRAFT, strip: this.strip } : {}
61
+ await b.build(l, { refilm: refilmOf(this.refilm), final: this.final, say, cwd, ...draft })
62
+ } finally {
63
+ if (this.profile) for (const line of profileLines()) say(line)
64
+ }
53
65
  return 0
54
66
  })
55
67
  }
@@ -5,6 +5,7 @@ import { homedir } from 'os'
5
5
  import { join } from 'path'
6
6
 
7
7
  export const FAMILY_PAGES: Readonly<Record<string, string>> = {
8
+ Annex: 'tools/shipkit/annex.md',
8
9
  Asks: 'preferences/human-loop/index.md',
9
10
  Assets: 'tools/generate-assets/index.md',
10
11
  Drill: 'meta/speed-up-agents/index.md',
@@ -12,6 +13,7 @@ export const FAMILY_PAGES: Readonly<Record<string, string>> = {
12
13
  Health: 'tools/shipkit/index.md',
13
14
  Home: 'tools/shipkit/home.md',
14
15
  Media: 'tools/shipkit/media-store.md',
16
+ Messages: 'tools/shipkit/messages.md',
15
17
  Refactor: 'patterns/typescript/index.md',
16
18
  Review: 'tools/shipkit/review.md',
17
19
  Scaffold: 'patterns/pocketbase/index.md',
@@ -5,4 +5,4 @@ export { Command, Option } from 'clipanion'
5
5
  export { type Family, familiesFor, listing, listingOf } from './families.ts'
6
6
  export { callsFile, logCall } from './calls.ts'
7
7
  export { type ProjectCliSpec, projectCli, runProjectCli } from './project-cli.ts'
8
- export { argvOf, type AskTool, type CommandClass, type Essential, type Film, filmCall, type KitContext, type Run, type Verb, verbs } from './verb.ts'
8
+ export { argvOf, type AskTool, type CommandClass, type Effect, type Essential, type Film, filmCall, type KitContext, type Run, type Verb, verbs } from './verb.ts'
@@ -36,6 +36,9 @@ export type Run =
36
36
  /** a row that shoots a state: `still` writes one image at `--out`, `clip` a video, its length `--seconds` */
37
37
  export type Film = 'still' | 'clip'
38
38
 
39
+ /** `outward`: acts beyond this machine or spends money (a push, a deploy, a paid api); the hub asks before it runs */
40
+ export type Effect = 'outward'
41
+
39
42
  /** an everyday command, listed on the essentials page every session loads */
40
43
  export type Essential = {
41
44
  /** its arguments as an agent types them: '<x> <y>' */
@@ -59,6 +62,7 @@ export type Verb = {
59
62
  /** 'own': `--help` also runs the tool with `--help`, which prints its flags and exits 0 */
60
63
  help?: 'own'
61
64
  essential?: Essential
65
+ effect?: Effect
62
66
  /** filmable: takes `--out <path>`, a clip also `--seconds <n>` (a trailer `film` line calls it) */
63
67
  film?: Film
64
68
  /** with film: the row's take version, a bump films every trailer take of the row again */
@@ -127,6 +131,7 @@ export function verbs(rows: Verb[]): CommandClass[] {
127
131
  static override paths = [v.path.split(' ')]
128
132
  static override usage = Command.Usage({ category: v.category, description: v.description, details: v.details, examples: v.examples })
129
133
  static essential = v.essential
134
+ static effect = v.effect
130
135
  static film = v.film
131
136
  static filmVersion = v.version
132
137
  static filmLength = v.length
@@ -160,10 +165,13 @@ export function verbs(rows: Verb[]): CommandClass[] {
160
165
 
161
166
  /** the marks a command class carries: set by `verbs()` from its row, or
162
167
  * declared as statics on a hand written class */
163
- export function marksOf(c: object): { essential?: Essential; film?: Film; version?: number | string; length?: 'own'; words?: Record<string, unknown>; stamp?: string[] } {
164
- const o = c as { essential?: unknown; film?: unknown; filmVersion?: unknown; filmLength?: unknown; filmWords?: unknown; filmStamp?: unknown }
165
- const out: { essential?: Essential; film?: Film; version?: number | string; length?: 'own'; words?: Record<string, unknown>; stamp?: string[] } = {}
168
+ export type Marks = { essential?: Essential; effect?: Effect; film?: Film; version?: number | string; length?: 'own'; words?: Record<string, unknown>; stamp?: string[] }
169
+
170
+ export function marksOf(c: object): Marks {
171
+ const o = c as { essential?: unknown; effect?: unknown; film?: unknown; filmVersion?: unknown; filmLength?: unknown; filmWords?: unknown; filmStamp?: unknown }
172
+ const out: Marks = {}
166
173
  if (typeof o.essential === 'object' && o.essential !== null) out.essential = o.essential as Essential
174
+ if (o.effect === 'outward') out.effect = 'outward'
167
175
  if (o.film === 'still' || o.film === 'clip') {
168
176
  out.film = o.film
169
177
  if (typeof o.filmVersion === 'number' || typeof o.filmVersion === 'string') out.version = o.filmVersion
@@ -24,7 +24,7 @@ import { CiCommand } from './cmd_Ci.ts'
24
24
  import { ContractsCommand } from './cmd_Contracts.ts'
25
25
  import { FleetCommand } from './cmd_Fleet.ts'
26
26
  import { FleetPushCommand } from './cmd_FleetPush.ts'
27
- import { DaemonCommand, DaemonJobCommand, GuiCommand, PmCommand, PmInstallCommand, PmUninstallCommand, WebCommand } from './cmd_Home.ts'
27
+ import { DaemonCommand, DaemonJobCommand, GuiCommand, PmCommand, PmInstallCommand, PmRestartCommand, PmUninstallCommand, WebCommand } from './cmd_Home.ts'
28
28
  import { HooksCommitMsgCommand, HooksInstallCommand, HooksListCommand, HooksPreCommitCommand } from './cmd_Hooks.ts'
29
29
  import { InitCommand } from './cmd_Init.ts'
30
30
  import { KeysCommand } from './cmd_Keys.ts'
@@ -33,7 +33,7 @@ import { NeedsCommand } from './cmd_Needs.ts'
33
33
  import { PbCollectionCommand } from './cmd_Pb.ts'
34
34
  import { ReflectCommand } from './cmd_Reflect.ts'
35
35
  import { ReleaseCommand } from './cmd_Release.ts'
36
- import { ReleasesCommand } from './cmd_Releases.ts'
36
+ import { ReleasesAddCommand, ReleasesCommand } from './cmd_Releases.ts'
37
37
  import { ChecksCommand, UnitsAliasCommand } from './cmd_Checks.ts'
38
38
  import { WhenCommand } from './cmd_When.ts'
39
39
  import { CacheAuditCommand } from './cmd_CacheAudit.ts'
@@ -48,8 +48,10 @@ import { SOUND_COMMANDS } from './cmd_Sound.ts'
48
48
  import { REVIEW_COMMANDS } from './cmd_Review.ts'
49
49
  import { SOCIAL_COMMANDS } from './cmd_Social.ts'
50
50
  import { MEDIA_COMMANDS } from './cmd_Media.ts'
51
+ import { ANNEX_COMMANDS } from './cmd_Annex.ts'
51
52
  import { BACKUP_COMMANDS } from './cmd_Backup.ts'
52
53
  import { VEILLE_COMMANDS } from './cmd_Veille.ts'
54
+ import { MESSAGES_COMMANDS } from './cmd_Messages.ts'
53
55
  import { TuiCommand } from './cmd_Tui.ts'
54
56
  import { SecretListCommand, SecretReadCommand, SecretSetCommand } from './cmd_Secret.ts'
55
57
  import { WikiLintCommand, WikiServeCommand } from './cmd_Wiki.ts'
@@ -81,6 +83,7 @@ export function buildCli(): Cli {
81
83
  cli.register(BumpCommand)
82
84
  cli.register(ReleaseCommand)
83
85
  cli.register(ReleasesCommand)
86
+ cli.register(ReleasesAddCommand)
84
87
  cli.register(HooksInstallCommand)
85
88
  cli.register(HooksPreCommitCommand)
86
89
  cli.register(HooksCommitMsgCommand)
@@ -93,8 +96,10 @@ export function buildCli(): Cli {
93
96
  for (const c of REVIEW_COMMANDS) cli.register(c)
94
97
  for (const c of SOCIAL_COMMANDS) cli.register(c)
95
98
  for (const c of MEDIA_COMMANDS) cli.register(c)
99
+ for (const c of ANNEX_COMMANDS) cli.register(c)
96
100
  for (const c of BACKUP_COMMANDS) cli.register(c)
97
101
  for (const c of VEILLE_COMMANDS) cli.register(c)
102
+ for (const c of MESSAGES_COMMANDS) cli.register(c)
98
103
  cli.register(ServeCommand)
99
104
  cli.register(PmCommand)
100
105
  cli.register(DaemonCommand)
@@ -102,6 +107,7 @@ export function buildCli(): Cli {
102
107
  cli.register(WebCommand)
103
108
  cli.register(PmInstallCommand)
104
109
  cli.register(PmUninstallCommand)
110
+ cli.register(PmRestartCommand)
105
111
  cli.register(GuiCommand)
106
112
  cli.register(ContractsCommand)
107
113
  cli.register(AsksCommand)
@@ -3,7 +3,9 @@
3
3
  // repo's diff shows it; Feedback appends are append-only, never destructive).
4
4
  import { existsSync, readFileSync, writeFileSync } from 'fs'
5
5
  import { join } from 'path'
6
- import { archiveAsk, proofAsk } from '../asks/asks-queue.ts'
6
+ import { archiveAsk, checkAsk, openAsks, proofAsk, type OneCheck } from '../asks/asks-queue.ts'
7
+ import { redact, type SecretStore } from '../secrets/manager.ts'
8
+ import { SECRET_NAME } from '../secrets/name.ts'
7
9
 
8
10
  const today = (): string => new Date().toISOString().slice(0, 10)
9
11
 
@@ -35,3 +37,29 @@ export function askProof(root: string, asksDir: string, file: string, url: strin
35
37
  if (file.includes('/') || file.includes('..')) throw new Error('bad path')
36
38
  proofAsk(join(root, asksDir), file, url)
37
39
  }
40
+
41
+ export type SecretAnswer = { stored: string } & OneCheck
42
+
43
+ /** a value pasted under a credential ask: stored under a name that open ask
44
+ * declares, then that ask's check alone. Its truth is the keychain, never a
45
+ * file: the value is not written, logged or answered, and a failure line has
46
+ * it replaced by ‹value› */
47
+ export async function askSecret(o: { root: string; asksDir: string; file: string; name: string; value: string; store: SecretStore }): Promise<SecretAnswer> {
48
+ if (!/^[A-Za-z0-9][A-Za-z0-9._-]*\.md$/.test(o.file)) throw new Error('bad path')
49
+ const dir = join(o.root, o.asksDir)
50
+ const ask = openAsks(dir).find((a) => a.file === o.file)
51
+ if (ask == null) throw new Error(`no open ask ${o.file}`)
52
+ if (ask.kind !== 'credential') throw new Error(`${o.file} is a ${ask.kind} ask: only a credential ask stores a secret`)
53
+ if (!SECRET_NAME.test(o.name) || !ask.secrets.includes(o.name)) throw new Error(`${o.file} declares no secret named ${o.name}`)
54
+ const value = o.value.trim()
55
+ if (value === '') throw new Error('empty value: nothing stored')
56
+ let c: OneCheck
57
+ try {
58
+ const r = await o.store(o.name, value)
59
+ if (!r.ok) throw new Error(`${o.name} not stored: ${r.why}`)
60
+ c = await checkAsk(o.root, dir, o.file)
61
+ } catch (e) {
62
+ throw new Error(redact((e as Error).message, value))
63
+ }
64
+ return c.check === 'failed' ? { stored: o.name, check: 'failed', why: redact(c.why, value) } : { stored: o.name, ...c }
65
+ }
@@ -32,7 +32,7 @@ export const NO_CHECK = 'in no check'
32
32
  * section a row lives under (hub-app/tree-build.ts KIND_SECTION). There is no
33
33
  * catch all kind: a row belongs to an owner, and what belongs to the hub
34
34
  * itself is its status (serve/hub-problems.ts), never a row */
35
- export const RESOURCE_TYPES = ['ask', 'secret', 'asset', 'post', 'workflow', 'wiki', 'contract', 'check', 'test', 'reflection', 'process', 'card', 'cut', 'store', 'veille'] as const
35
+ export const RESOURCE_TYPES = ['ask', 'secret', 'asset', 'post', 'workflow', 'wiki', 'contract', 'check', 'test', 'reflection', 'process', 'command', 'card', 'cut', 'store', 'release', 'veille', 'message'] as const
36
36
 
37
37
  /** the collection of the review cards that wait on him (collections/review.ts) */
38
38
  export const REVIEW_COL = 'review'
@@ -40,8 +40,12 @@ export const REVIEW_COL = 'review'
40
40
  export const TRAILER_COL = 'trailers'
41
41
  /** the collection of the store pages, one row a store (stores/collection.ts) */
42
42
  export const STORES_COL = 'stores'
43
+ /** the collection of the release files, one row a version, next first (releases/collection.ts) */
44
+ export const RELEASES_COL = 'releases'
43
45
  /** the collection of the Veille, one row for the identity whose posts it ranks (veille/collection.ts) */
44
46
  export const VEILLE_COL = 'veille'
47
+ /** the collection of the messages page's tabs, one row each under its section (messages/collection.ts) */
48
+ export const MESSAGES_COL = 'messages'
45
49
 
46
50
  export type ResourceType = (typeof RESOURCE_TYPES)[number]
47
51
 
@@ -187,6 +191,8 @@ export type AskFacts = {
187
191
  blocks: string
188
192
  /** the shell probe that closes it once it exits 0, null for a manual ask */
189
193
  probe: string | null
194
+ /** the secret names a credential ask stores: its page takes each pasted value */
195
+ secrets: string[]
190
196
  }
191
197
 
192
198
  /** one test file, as its row and its page read it */
@@ -241,6 +247,9 @@ export type Instance = {
241
247
  /** the group it sits in on the tree, under its section: an asset's kit
242
248
  * category. Absent = directly under the section */
243
249
  group?: string
250
+ /** its place among its siblings on the tree, where the labels' alphabet is the wrong order (a page's tabs, in the
251
+ * page's order). Absent = after the ordered ones, by label */
252
+ order?: number
244
253
  type: ResourceType
245
254
  /** a slash path. Where a truth file exists this IS its repo-relative
246
255
  * path; otherwise a VIRTUAL path under a root named for the type, and
@@ -28,7 +28,10 @@ import { assetState, secretState, type SecretLevel, type SecretProbe } from './s
28
28
  import { reflectionsCollection } from './reflections.ts'
29
29
  import { reviewCollection, trailersCollection } from './review.ts'
30
30
  import { storesCollection } from '../stores/collection.ts'
31
+ import { messagesCollection } from '../messages/collection.ts'
32
+ import { releasesCollection } from '../releases/collection.ts'
31
33
  import { veilleCollection } from '../veille/collection.ts'
34
+ import { picturesCollection } from '../identities/collection.ts'
32
35
  import { testsCollection } from './tests.ts'
33
36
  import { checksCollection } from './checks.ts'
34
37
  import { LAYOUT } from '../core/layout.ts'
@@ -121,7 +124,7 @@ const slug = (t: string): string => t.toLowerCase().replace(/[^a-z0-9]+/g, '-').
121
124
  /** wire lines re-rendered as a fenced block for an instance's md */
122
125
  const wireMd = (lines: string[]): string => `\`\`\`\n${lines.join('\n')}\n\`\`\``
123
126
 
124
- const askFacts = (a: Ask): AskFacts => ({ kind: a.kind, created: a.created, closed: a.closed, blocks: a.blocks, probe: a.check })
127
+ const askFacts = (a: Ask): AskFacts => ({ kind: a.kind, created: a.created, closed: a.closed, blocks: a.blocks, probe: a.check, secrets: a.kind === 'credential' ? a.secrets : [] })
125
128
 
126
129
  export function asksCollection(root: string, c: RepoConfig): Collection {
127
130
  return {
@@ -419,6 +422,6 @@ export function buildCollections(root: string, c: RepoConfig, kit: ResolvedKit |
419
422
  reflectionsCollection(root),
420
423
  testsCollection(root, c),
421
424
  // only where the repo has a review store, a trailer folder or a store folder: the section of a repo with none is greyed
422
- ...[reviewCollection(root), trailersCollection(root), storesCollection(root), veilleCollection(root)].filter((x): x is Collection => x !== null),
425
+ ...[reviewCollection(root), trailersCollection(root), storesCollection(root), releasesCollection(root), messagesCollection(root), veilleCollection(root), picturesCollection(root)].filter((x): x is Collection => x !== null),
423
426
  ]
424
427
  }
@@ -0,0 +1,36 @@
1
+ // what the commands page and its routes share: the view it reads, and when a run waits for a confirm. Pure, so the
2
+ // page bundles it
3
+ import type { CommandRow } from '../cli/cmd_Commands.ts'
4
+ import type { Reach } from '../serve/same-origin.ts'
5
+ import type { RunView } from './runs.ts'
6
+
7
+ export type { RunView }
8
+
9
+ /** what `GET /api/commands` answers */
10
+ export type CommandsView = {
11
+ bin: string
12
+ rows: CommandRow[]
13
+ runs: RunView[]
14
+ /** where the page reaches the hub from: a run from his phone confirms first */
15
+ reach: Reach
16
+ /** why the repo shows no command: no CLI, or one that failed to list */
17
+ error: string | null
18
+ }
19
+
20
+ /** what `GET /api/commands/runs/<id>` answers */
21
+ export type LogView = { run: RunView; text: string; next: number; size: number }
22
+
23
+ /** why a run of this row waits for a confirm click, null when it runs at once */
24
+ export function confirmWhy(row: Pick<CommandRow, 'effect'>, reach: Reach): string | null {
25
+ if (row.effect === 'outward') return 'it acts beyond this machine or spends money'
26
+ if (reach === 'tailnet') return 'it starts on the Mac from another device'
27
+ return null
28
+ }
29
+
30
+ /** the args an example line gives its command: what follows the binary and the command's words; null for a line
31
+ * of another command, which the page shows without a run button */
32
+ export function exampleArgs(bin: string, path: string, line: string): string | null {
33
+ const head = `${bin} ${path}`
34
+ if (line === head) return ''
35
+ return line.startsWith(`${head} `) ? line.slice(head.length + 1) : null
36
+ }
@@ -0,0 +1,49 @@
1
+ // a repo's project CLI as the hub's commands page reads it (wiki tools/shipkit/hub.md, The commands page): the `cli`
2
+ // script of its package.json, asked for its own registry (`commands --json`, guides/cli-tool). Read fresh each time,
3
+ // about 0.1 s, so the page never shows a command the CLI no longer has
4
+ import { existsSync, readFileSync } from 'node:fs'
5
+ import { join } from 'node:path'
6
+ import type { CommandRow } from '../cli/cmd_Commands.ts'
7
+
8
+ export type Registry = {
9
+ /** the binary's name, as its examples type it */
10
+ bin: string
11
+ rows: CommandRow[]
12
+ }
13
+
14
+ /** how long the registry may take before the page says so */
15
+ const READ_MS = 15_000
16
+
17
+ /** the argv that runs the repo's CLI with `words`: bun's own `run`, never a shell */
18
+ export const cliArgv = (words: readonly string[]): string[] => [process.execPath, 'run', '--silent', 'cli', ...words]
19
+
20
+ /** null when the repo has a CLI, else why it has none */
21
+ export function noCli(root: string): string | null {
22
+ const file = join(root, 'package.json')
23
+ if (!existsSync(file)) return 'no package.json, so no project CLI'
24
+ const pkg = JSON.parse(readFileSync(file, 'utf8')) as { scripts?: Record<string, unknown> }
25
+ return typeof pkg.scripts?.cli === 'string' ? null : 'no project CLI: package.json has no `cli` script (guides/cli-tool, `sk start` writes one)'
26
+ }
27
+
28
+ /** the binary's name: the first word of its usage lines */
29
+ export function binOf(rows: readonly CommandRow[]): string {
30
+ for (const r of rows) {
31
+ const w = r.usage.split(' ')[0]
32
+ if (w != null && w !== '' && w !== '$0') return w
33
+ }
34
+ return 'cli'
35
+ }
36
+
37
+ /** the CLI's registry; throws with the words the page shows */
38
+ export async function readRegistry(root: string): Promise<Registry> {
39
+ const why = noCli(root)
40
+ if (why != null) throw new Error(why)
41
+ const p = Bun.spawn(cliArgv(['commands', '--json']), { cwd: root, stdin: 'ignore', stdout: 'pipe', stderr: 'pipe', env: { ...process.env, NO_COLOR: '1' } })
42
+ const timer = setTimeout(() => p.kill(), READ_MS)
43
+ const [out, err, code] = await Promise.all([new Response(p.stdout).text(), new Response(p.stderr).text(), p.exited])
44
+ clearTimeout(timer)
45
+ if (code !== 0) throw new Error(`\`bun run cli commands --json\` exited ${code}: ${(err.trim() || out.trim()).split('\n').slice(-3).join(' ')}`)
46
+ let rows: CommandRow[]
47
+ try { rows = JSON.parse(out) as CommandRow[] } catch { throw new Error('`bun run cli commands --json` printed no json: the CLI is not a kit CLI (guides/cli-tool)') }
48
+ return { bin: binOf(rows), rows }
49
+ }