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
@@ -8,9 +8,11 @@
8
8
  import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFileSync } from 'fs'
9
9
  import { atomicWrite, mutateLease, withMutateLease } from '../core/locked-write.ts'
10
10
  import { join } from 'path'
11
+ import { SECRET_NAME } from '../secrets/name.ts'
11
12
 
12
- export type Ask = { file: string; status: string; kind: string; created: string; closed: string | null; blocks: string; check: string | null; title: string }
13
- export type CreateOpts = { kind?: string; blocks?: string; check?: string; why?: string }
13
+ /** `secrets`: the names a credential ask stores, from its `secret:` line (space or comma separated), [] for none */
14
+ export type Ask = { file: string; status: string; kind: string; created: string; closed: string | null; blocks: string; check: string | null; secrets: string[]; title: string }
15
+ export type CreateOpts = { kind?: string; blocks?: string; check?: string; why?: string; secrets?: string[] }
14
16
 
15
17
  /** filename slug: kebab, truncated at a WORD boundary (never mid-word — a
16
18
  * `…-rvlib-` stub reads as broken). Falls back to a hard cut only when the
@@ -34,6 +36,7 @@ const parse = (dir: string, file: string): Ask => {
34
36
  closed: fm('closed'),
35
37
  blocks: fm('blocks') ?? '-',
36
38
  check: fm('check'),
39
+ secrets: (fm('secret') ?? '').split(/[\s,]+/).filter((n) => n !== ''),
37
40
  title: md.match(/^# (.+)$/m)?.[1] ?? file,
38
41
  }
39
42
  }
@@ -74,12 +77,7 @@ function checkAsksBody(dir: string, print: (line: string) => void): { closed: nu
74
77
  for (const a of listAsks(dir)) {
75
78
  if (a.status === 'done') { renameSync(join(dir, a.file), join(done, a.file)); print(`archived ${a.file} → done/`); continue }
76
79
  if (a.check == null) { print(`still ${a.status.padEnd(8)} ${a.file} (manual — no probe)`); continue }
77
- // env named: bun's default is the env the process started with, blind to a later process.env write
78
- const p = Bun.spawnSync(['bash', '-lc', a.check], { env: process.env })
79
- if (p.exitCode === 0) {
80
- const md = readFileSync(join(dir, a.file), 'utf8').replace(/^status:.*$/m, `status: done\nclosed: ${new Date().toISOString().slice(0, 10)}`)
81
- atomicWrite(join(dir, a.file), md)
82
- renameSync(join(dir, a.file), join(done, a.file))
80
+ if (probeAsk(dir, a, a.check).passed) {
83
81
  print(`closed + archived ${a.file}`)
84
82
  closed++
85
83
  } else {
@@ -90,6 +88,37 @@ function checkAsksBody(dir: string, print: (line: string) => void): { closed: nu
90
88
  return { closed }
91
89
  }
92
90
 
91
+ /** one ask's probe: when it exits 0 the ask is stamped done and archived; else
92
+ * the probe's last stderr line says why */
93
+ function probeAsk(dir: string, a: Ask, check: string): { passed: true } | { passed: false; why: string } {
94
+ // env named: bun's default is the env the process started with, blind to a later process.env write
95
+ const p = Bun.spawnSync(['bash', '-lc', check], { env: process.env, stdout: 'ignore', stderr: 'pipe' })
96
+ if (p.exitCode !== 0) {
97
+ const tail = p.stderr.toString().trim().split('\n').at(-1) ?? ''
98
+ return { passed: false, why: `exit ${p.exitCode}${tail !== '' ? `: ${tail}` : ''}` }
99
+ }
100
+ const done = join(dir, 'done')
101
+ mkdirSync(done, { recursive: true })
102
+ const md = readFileSync(join(dir, a.file), 'utf8').replace(/^status:.*$/m, `status: done\nclosed: ${new Date().toISOString().slice(0, 10)}`)
103
+ atomicWrite(join(dir, a.file), md)
104
+ renameSync(join(dir, a.file), join(done, a.file))
105
+ return { passed: true }
106
+ }
107
+
108
+ export type OneCheck = { check: 'none' } | { check: 'passed' } | { check: 'failed'; why: string }
109
+
110
+ /** `checkAsks` for one open ask: its probe alone, under the same lease */
111
+ export async function checkAsk(root: string, dir: string, file: string): Promise<OneCheck> {
112
+ const leased = await withMutateLease(mutateLease(root, 'asks'), { label: 'asks archive', print: () => {}, maxWaitMs: 45_000 }, (): OneCheck => {
113
+ const a = openAsks(dir).find((x) => x.file === file)
114
+ if (a == null) return { check: 'failed', why: `${file} is no longer an open ask` }
115
+ if (a.check == null) return { check: 'none' }
116
+ const r = probeAsk(dir, a, a.check)
117
+ return r.passed ? { check: 'passed' } : { check: 'failed', why: r.why }
118
+ })
119
+ return leased.ok ? leased.value : { check: 'failed', why: `the check did not run: ${leased.warn}` }
120
+ }
121
+
93
122
  // the hub renders ask markdown, so a new ask starts as the page the human
94
123
  // follows: one section per step, a link that opens the exact page, values
95
124
  // to copy. Every {{placeholder}} is the author's to fill (braces, since markdown hides an unknown <tag>) before the ask ships
@@ -116,7 +145,31 @@ const DECISION_BODY = `<!-- a decision: numbered options, the recommended one fi
116
145
  Reply with the number.
117
146
  `
118
147
 
148
+ // a credential ask: the human mints the value, then pastes it into the field
149
+ // the hub draws under the ask, or into the store command's silent prompt
150
+ const credentialBody = (names: string[]): string => `<!-- a credential: the steps that mint the value, then the store step as written. Values in the table, buttons in bold. -->
151
+
152
+ ## 1. {{verb}} {{thing}}
153
+
154
+ Open **[{{page name}}]({{url, ids filled in}})**, then click **{{button}}**, and copy the value it shows.
155
+
156
+ ## 2. Store it
157
+
158
+ Paste it in the field below and click **store**. Or type ${names.length > 1 ? 'these lines' : 'this line'} in Claude Code and paste it at the silent prompt:
159
+
160
+ \`\`\`
161
+ ${names.map((n) => `! sk secret set ${n}`).join('\n')}
162
+ \`\`\`
163
+
164
+ The check below then closes this ask.
165
+ `
166
+
119
167
  export function createAsk(dir: string, title: string, opts?: CreateOpts): string {
168
+ const secrets = opts?.secrets ?? []
169
+ const bad = secrets.find((s) => !SECRET_NAME.test(s))
170
+ if (bad != null) throw new Error(`refusing secret name '${bad}': letters, digits and . _ @ / - only, never a leading dash`)
171
+ if (secrets.length > 0 && (opts?.kind ?? 'credential') !== 'credential') throw new Error(`a secret is stored by a credential ask, not a ${opts?.kind} one`)
172
+ opts = secrets.length > 0 ? { ...opts, kind: 'credential', check: opts?.check ?? secrets.map((s) => `sk secret get ${s} >/dev/null`).join(' && ') } : opts
120
173
  mkdirSync(dir, { recursive: true })
121
174
  // max numeric prefix across BOTH live and archived asks — numbers are never reused
122
175
  const done = join(dir, 'done')
@@ -135,12 +188,12 @@ export function createAsk(dir: string, title: string, opts?: CreateOpts): string
135
188
  status: open
136
189
  kind: ${opts?.kind ?? 'action'}
137
190
  created: ${new Date().toISOString().slice(0, 10)}
138
- blocks: ${opts?.blocks ?? '-'}${check != null ? `\ncheck: ${check}` : ''}
191
+ blocks: ${opts?.blocks ?? '-'}${check != null ? `\ncheck: ${check}` : ''}${secrets.length > 0 ? `\nsecret: ${secrets.join(' ')}` : ''}
139
192
  ---
140
193
 
141
194
  # ${title}
142
195
 
143
- ${whyBlock}${opts?.kind === 'decision' ? DECISION_BODY : STEPS_BODY}
196
+ ${whyBlock}${opts?.kind === 'decision' ? DECISION_BODY : secrets.length > 0 ? credentialBody(secrets) : STEPS_BODY}
144
197
  **Answer**: _(fill in / check off, or just do it — the check probe auto-closes when it passes)_
145
198
 
146
199
  **Done when**: ${doneWhen}
@@ -0,0 +1,43 @@
1
+ // SK040 release words (tools/shipkit/built-in-checks-contracts-and-visibility.md): every file of `.shipkit/releases/`
2
+ // reads as a release, and every public word in it (a title, a category, a change, its description, its picture's alt,
3
+ // its bullets) passes the repo's guard, the social unit's `guard` hook, the one every staged post passes. A release is
4
+ // read by strangers, so a word the guard refuses fails here before a bump can publish it. Keyed on the release files,
5
+ // the messages store and the unit file's text: a guard that moves only in a module the unit imports keeps a stale green
6
+ // until one of those moves
7
+ import { readFileSync } from 'node:fs'
8
+ import { check } from '../check.ts'
9
+ import { LAYOUT } from '../core/layout.ts'
10
+ import { unitFilesDeclaring } from '../core/unit-files.ts'
11
+ import { fileOf, publicTexts } from '../releases/model.ts'
12
+ import { hasReleases, readReleases } from '../releases/store.ts'
13
+ import { publicProblems } from '../social/unit.ts'
14
+
15
+ export const releaseWords = check({
16
+ id: 'SK040',
17
+ blocking: true,
18
+ title: 'release words',
19
+ description: 'every release file parses, and its public words pass the repo guard',
20
+ owner: 'tools/shipkit/units.md',
21
+ runs: { onPreCommit: false, onCi: true, onFull: true, onRelease: true, onHealth: true, onSave: 'moved', onClock: false },
22
+ // the release files and the messages store the guard reads, and the text of the social unit files that declare it
23
+ cache: { by: 'files', inputs: [LAYOUT.releases, '.shipkit/messages'], key: (env) => unitFilesDeclaring(env.root, 'social').map((f) => `${f}:${Bun.hash(readFileSync(f, 'utf8'))}`).join('\n') },
24
+ fix: 'none',
25
+ applies: 'always',
26
+ run: async (c) => {
27
+ if (!hasReleases(c.root)) return c.ok(`no ${LAYOUT.releases}/: no release files to read`)
28
+ const { releases, errors } = readReleases(c.root)
29
+ for (const e of errors) c.lines.push({ kind: 'fail', text: e })
30
+ let words = 0
31
+ for (const r of releases) {
32
+ const texts = publicTexts(r, { fileIsPublic: c.config.visibility === 'public' })
33
+ words += texts.length
34
+ for (const p of await publicProblems(c.root, { title: r.title, texts })) c.lines.push({ kind: 'fail', text: `${LAYOUT.releases}/${fileOf(r.version)}: ${p}` })
35
+ }
36
+ const failed = c.lines.filter((l) => l.kind === 'fail').length
37
+ if (failed === 0) return c.ok(`${releases.length} release file${releases.length === 1 ? '' : 's'}, ${words} public text${words === 1 ? '' : 's'}, the guard refuses none`)
38
+ c.fail(`${failed} problem${failed === 1 ? '' : 's'} in ${LAYOUT.releases}/: a release is public, so the guard reads it first`)
39
+ c.lines.push({ kind: 'fix-fail', text: `reword the change in its file (or sk releases add again), then sk ci --only SK040` })
40
+ },
41
+ })
42
+
43
+ export default releaseWords
@@ -0,0 +1,28 @@
1
+ // SK041 annex links (tools/shipkit/annex.md): each folder of this repo that
2
+ // `sk annex offload` moved to an external drive still reaches its copy there.
3
+ // It warns, never fails: an unplugged drive is the world, not the repo. A link
4
+ // that reaches nothing, a recorded folder that is no longer a link (a reset made
5
+ // a real folder on the Mac), and a folder on the annex no link reaches are each
6
+ // named with the command that settles them
7
+ import { check } from '../check.ts'
8
+
9
+ export const annexLinks = check({
10
+ id: 'SK041',
11
+ blocking: false,
12
+ title: 'annex links',
13
+ description: "every folder this repo offloaded to an annex still reaches its copy there",
14
+ owner: 'tools/shipkit/annex.md',
15
+ runs: { onPreCommit: false, onCi: false, onFull: true, onRelease: false, onHealth: true, onSave: false, onClock: false },
16
+ cache: { by: 'never', why: 'it reads the machine db and the external drives, outside the repo, in a few milliseconds' },
17
+ fix: 'none',
18
+ applies: 'always',
19
+ run: async (c) => {
20
+ const { drift, offloads } = await import('../annex/offload.ts')
21
+ const mine = offloads().filter((x) => x.repo === c.root)
22
+ const bad = await drift(c.root)
23
+ if (bad.length === 0) return c.ok(mine.length === 0 ? 'nothing offloaded' : `${mine.length} offloaded folders, every link holds`)
24
+ for (const d of bad) c.warn(`${d.kind}: ${d.path}: ${d.why}. ${d.fix}`)
25
+ },
26
+ })
27
+
28
+ export default annexLinks
@@ -0,0 +1,73 @@
1
+ // SK042 post kinds (tools/shipkit/built-in-checks-contracts-and-visibility.md): every draft of `.shipkit/social/drafts/`
2
+ // names what it is for, a kind of the closed set or of the social unit's own `kinds` (wiki guides/post-kinds/index.md),
3
+ // through the load's one check, kinds.ts kindProblem. A word of the old words table only warns: each repo moves its own
4
+ // drafts. Keyed on the social folder, the unit file's text and whether each page its text names is a file: kinds a
5
+ // module the unit imports declares keep a stale green until one of those moves
6
+ import { existsSync, readdirSync, readFileSync } from 'node:fs'
7
+ import { join } from 'node:path'
8
+ import { check } from '../check.ts'
9
+ import { LAYOUT } from '../core/layout.ts'
10
+ import { unitFilesDeclaring } from '../core/unit-files.ts'
11
+ import { ownPageMissing } from '../social/kind-pages.ts'
12
+ import { kindOfMeta, kindProblem } from '../social/kinds.ts'
13
+ import { parseFrontmatter } from '../social/md.ts'
14
+ import { loadSocialUnit, type SocialUnit } from '../social/unit.ts'
15
+
16
+ /** a unit file's text, and whether each `.md` path it names is a file: a kind's page deleted asks the question again */
17
+ export function unitKey(root: string, file: string): string {
18
+ const text = readFileSync(file, 'utf8')
19
+ const pages = [...new Set([...text.matchAll(/['"`]([^'"`\s]+\.md)['"`]/g)].map((m) => m[1]!))].map((p) => `${p}:${existsSync(join(root, p))}`)
20
+ return `${file}:${Bun.hash(text)}:${pages.join(',')}`
21
+ }
22
+
23
+ const FIX ='set the kind to one of wiki guides/post-kinds/index.md (a custom one with its kindWhy), or declare the project kind in its social unit, then sk ci --only SK042'
24
+ const FIX_OLD = "move each draft to the kind its intent reads as (wiki guides/post-kinds/index.md, The old words): the repo's own step, never a blind replace"
25
+
26
+ export const postKinds = check({
27
+ id: 'SK042',
28
+ blocking: true,
29
+ title: 'post kinds',
30
+ description: 'every social draft names its kind: one of the closed set or of the social unit',
31
+ owner: 'tools/shipkit/built-in-checks-contracts-and-visibility.md',
32
+ runs: { onPreCommit: false, onCi: true, onFull: true, onRelease: true, onHealth: true, onSave: 'moved', onClock: false },
33
+ // the social folder, the text of the social unit files that declare its own kinds, and each page they name
34
+ cache: { by: 'files', inputs: [LAYOUT.social], key: (env) => unitFilesDeclaring(env.root, 'social').map((f) => unitKey(env.root, f)).join('\n') },
35
+ fix: 'none',
36
+ applies: 'always',
37
+ run: async (c) => {
38
+ const dir = join(c.root, LAYOUT.social, 'drafts')
39
+ const slugs = existsSync(dir) ? readdirSync(dir, { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith('.')).map((e) => e.name).sort() : []
40
+ if (slugs.length === 0) return c.ok(`no draft in ${LAYOUT.social}/drafts/: no kind to read`)
41
+ let unit: SocialUnit | null
42
+ try {
43
+ unit = await loadSocialUnit(c.root)
44
+ } catch (e) {
45
+ return c.fail(`the social unit does not load: ${(e as Error).message}`, 'fix the unit file it names, then sk ci --only SK042')
46
+ }
47
+ const own = unit?.kinds ?? []
48
+ for (const k of own) if (!existsSync(join(c.root, k.page))) c.fail(ownPageMissing(k), `write its rules page, in the shape of a page of wiki guides/post-kinds/`)
49
+ let bad = 0
50
+ let old = 0
51
+ for (const slug of slugs) {
52
+ const rel = `${LAYOUT.social}/drafts/${slug}/draft.md`
53
+ const raw = c.read(rel)
54
+ if (raw == null) continue
55
+ const { meta } = parseFrontmatter(raw)
56
+ const { kind, why } = kindOfMeta(meta)
57
+ const p = kindProblem(kind, why, own)
58
+ if (p == null) continue
59
+ if (p.old) {
60
+ old++
61
+ c.lines.push({ kind: 'warn', text: `${rel}: ${p.text}` })
62
+ } else {
63
+ bad++
64
+ c.lines.push({ kind: 'fail', text: `${rel}: ${p.text}` })
65
+ }
66
+ }
67
+ if (bad > 0) c.fail(`${bad} draft${bad === 1 ? '' : 's'} with no kind of the set`, FIX)
68
+ if (old > 0) c.warn(`${old} draft${old === 1 ? '' : 's'} on an old kind word`, FIX_OLD)
69
+ if (bad === 0 && old === 0 && !c.failed) c.ok(`${slugs.length} draft${slugs.length === 1 ? '' : 's'}, each names its kind`)
70
+ },
71
+ })
72
+
73
+ export default postKinds
@@ -0,0 +1,179 @@
1
+ // sk annex: the machine's external drives for heavy files, never a db (annex/, wiki tools/shipkit/annex.md): where
2
+ // each annex stands, its marker written once, a repo's scratch offloaded behind a symlink and back, the media trimmed
3
+ // to the cap. Every module loads inside execute: the cli registers this file on every `sk` call
4
+ import { Command, Option } from 'clipanion'
5
+
6
+ const DETAILS = `an annex is a folder on an external drive the house config lists (serve.annexes in the house repo config), present only while its root holds the marker sk annex init wrote. A media purge moves each file there before the Mac lets it go, a fetch back reads it before the Space, and sk annex offload moves a repo's .shipkit/cache or .shipkit/tmp folders there behind a symlink. No db, lock, worktree or backed up file ever goes. Page: wiki tools/shipkit/annex.md`
7
+
8
+ type Ctx = { stdout: NodeJS.WritableStream; stderr: NodeJS.WritableStream }
9
+
10
+ async function run(context: Ctx, body: (out: (l: string) => void) => Promise<number>): Promise<number> {
11
+ const out = (l: string): void => void context.stdout.write(`${l}\n`)
12
+ try {
13
+ return await body(out)
14
+ } catch (e) {
15
+ context.stderr.write(`FAIL: annex: ${e instanceof Error ? e.message : String(e)}\n`)
16
+ return 1
17
+ }
18
+ }
19
+
20
+ const gb = (n: number): string => `${(n / 1e9).toFixed(1)} GB`
21
+
22
+ async function repoAndRel(arg: string): Promise<{ root: string; rel: string }> {
23
+ const { findRepoRoot } = await import('../ts/config.ts')
24
+ const { relative, resolve } = await import('node:path')
25
+ const abs = resolve(process.cwd(), arg).replace(/\/+$/, '')
26
+ const root = findRepoRoot(process.cwd())
27
+ return { root, rel: relative(root, abs) }
28
+ }
29
+
30
+ export class AnnexCommand extends Command {
31
+ static override paths = [['annex']]
32
+ static override usage = Command.Usage({
33
+ category: 'Annex',
34
+ description: 'each annex: present or not, free space, its media, every offloaded folder and its link',
35
+ details: `${DETAILS}\n\nA folder with no marker where an annex should be is named: the drive is unplugged, or a phantom folder took its place.`,
36
+ examples: [['where the annexes stand', 'sk annex']],
37
+ })
38
+ async execute(): Promise<number> {
39
+ return run(this.context, async (out) => {
40
+ const { annexSpecs, driveFree, isPresent, mediaFiles } = await import('../annex/annex.ts')
41
+ const { drift, offloads } = await import('../annex/offload.ts')
42
+ const { existsSync } = await import('node:fs')
43
+ const specs = await annexSpecs()
44
+ if (specs.length === 0) out('no annex: the house config lists none (serve.annexes)')
45
+ for (const a of specs) {
46
+ if (!isPresent(a)) {
47
+ out(`${a.path} ABSENT${existsSync(a.path) ? ': the folder is there with no marker (a phantom, or sk annex init never ran)' : ': the drive is unplugged'}`)
48
+ continue
49
+ }
50
+ const m = mediaFiles(a)
51
+ const bytes = m.reduce((s, f) => s + f.size, 0)
52
+ out(`${a.path} present free ${gb(driveFree(a.path))} media ${m.length} files ${gb(bytes)}${a.maxGb !== undefined ? ` of ${a.maxGb} GB` : ''}`)
53
+ }
54
+ const list = offloads()
55
+ for (const repo of [...new Set(list.map((x) => x.repo))]) {
56
+ const bad = new Map((await drift(repo)).map((d) => [d.path, d] as const))
57
+ for (const x of list.filter((y) => y.repo === repo)) {
58
+ const d = bad.get(`${x.repo}/${x.rel}`)
59
+ out(` ${repo}/${x.rel} ${gb(x.bytes)} ${d ? `${d.kind.toUpperCase()}: ${d.why}` : 'link holds'}`)
60
+ }
61
+ for (const d of bad.values()) if (d.kind === 'orphan') out(` ORPHAN ${d.path}: ${d.why}`)
62
+ for (const d of bad.values()) out(` → ${d.fix}`)
63
+ }
64
+ return 0
65
+ })
66
+ }
67
+ }
68
+
69
+ export class AnnexInitCommand extends Command {
70
+ static override paths = [['annex', 'init']]
71
+ static override usage = Command.Usage({
72
+ category: 'Annex',
73
+ description: 'mark a folder of an external drive as an annex: its parent mounted, never the home disk',
74
+ details: `${DETAILS}\n\nThe folder is made only when its parent exists, never with its parents, and is refused on the home disk or a Time Machine volume. List it in serve.annexes of the house config.`,
75
+ examples: [['the T7', 'sk annex init /Volumes/T7/shipkit']],
76
+ })
77
+ root = Option.String({ required: true })
78
+ async execute(): Promise<number> {
79
+ return run(this.context, async (out) => {
80
+ const { initAnnex } = await import('../annex/annex.ts')
81
+ out(`annex marked: ${initAnnex(this.root)}`)
82
+ return 0
83
+ })
84
+ }
85
+ }
86
+
87
+ export class AnnexOffloadCommand extends Command {
88
+ static override paths = [['annex', 'offload']]
89
+ static override usage = Command.Usage({
90
+ category: 'Annex',
91
+ description: "a repo's .shipkit/cache or .shipkit/tmp folders to the annex, a symlink in their place",
92
+ details: `${DETAILS}\n\nEach path is checked first: inside .shipkit/cache or .shipkit/tmp, ignored by git, no db, lock or git worktree inside, nothing the backup holds or the media store indexes, nothing a process holds open. The copy is checked by its file count and bytes before the swap.`,
93
+ examples: [['two scratch folders', 'sk annex offload .shipkit/tmp/anatomy-data .shipkit/cache'], ['what would move', 'sk annex offload --dry .shipkit/tmp/*']],
94
+ })
95
+ dry = Option.Boolean('--dry', false, { description: 'check and print, move nothing' })
96
+ folders = Option.Rest({ required: 1 })
97
+ async execute(): Promise<number> {
98
+ return run(this.context, async (out) => {
99
+ const { offload } = await import('../annex/offload.ts')
100
+ let failed = 0
101
+ let total = 0
102
+ for (const p of this.folders) {
103
+ const { root, rel } = await repoAndRel(p)
104
+ try {
105
+ const m = await offload(root, rel, { dry: this.dry })
106
+ total += m.bytes
107
+ out(`${this.dry ? 'would move' : 'moved'} ${rel} ${m.files} files ${gb(m.bytes)} → ${m.target}`)
108
+ } catch (e) {
109
+ failed++
110
+ out(`refused ${rel}: ${(e as Error).message}`)
111
+ }
112
+ }
113
+ out(`${this.dry ? 'would free' : 'freed'} ${gb(total)}${failed > 0 ? `, ${failed} refused` : ''}`)
114
+ return failed > 0 ? 1 : 0
115
+ })
116
+ }
117
+ }
118
+
119
+ export class AnnexBackCommand extends Command {
120
+ static override paths = [['annex', 'back']]
121
+ static override usage = Command.Usage({
122
+ category: 'Annex',
123
+ description: "an offloaded folder back on the Mac's disk, its link replaced, when the disk has room",
124
+ details: `${DETAILS}\n\nThe disk must keep 10 GB free beyond the folder. The copy is checked by its file count and bytes before the link goes.`,
125
+ examples: [['bring one back', 'sk annex back .shipkit/tmp/anatomy-data']],
126
+ })
127
+ folder = Option.String({ required: true })
128
+ async execute(): Promise<number> {
129
+ return run(this.context, async (out) => {
130
+ const { back } = await import('../annex/offload.ts')
131
+ const { root, rel } = await repoAndRel(this.folder)
132
+ const m = back(root, rel)
133
+ out(`back ${rel} ${m.files} files ${gb(m.bytes)}`)
134
+ return 0
135
+ })
136
+ }
137
+ }
138
+
139
+ export class AnnexForgetCommand extends Command {
140
+ static override paths = [['annex', 'forget']]
141
+ static override usage = Command.Usage({
142
+ category: 'Annex',
143
+ description: 'drop an offload record the Mac no longer needs: a split, a dead link, or nothing left',
144
+ details: `${DETAILS}\n\nA split (a real folder where the link was, after a cache reset) keeps the Mac folder and deletes the stale annex copy. A dangling link (the drive gone for good) loses the link and its record. Refused while the link holds (sk annex back brings a folder home), and when the link is gone while the annex copy is there (relink it).`,
145
+ examples: [['settle a split', 'sk annex forget .shipkit/cache']],
146
+ })
147
+ folder = Option.String({ required: true })
148
+ async execute(): Promise<number> {
149
+ return run(this.context, async (out) => {
150
+ const { forget } = await import('../annex/offload.ts')
151
+ const { root, rel } = await repoAndRel(this.folder)
152
+ out(`forgot ${rel}: ${forget(root, rel).did}`)
153
+ return 0
154
+ })
155
+ }
156
+ }
157
+
158
+ export class AnnexSweepCommand extends Command {
159
+ static override paths = [['annex', 'sweep']]
160
+ static override usage = Command.Usage({
161
+ category: 'Annex',
162
+ description: "trim each annex's media to its cap, used longest ago first: the Space holds every one",
163
+ details: `${DETAILS}\n\nThe purge runs it after each pass that kept a file on an annex. Offloaded folders never count and never leave.`,
164
+ examples: [['what would go', 'sk annex sweep --dry']],
165
+ })
166
+ dry = Option.Boolean('--dry', false, { description: 'print what would go, delete nothing' })
167
+ async execute(): Promise<number> {
168
+ return run(this.context, async (out) => {
169
+ const { annexSweep, presentAnnexes } = await import('../annex/annex.ts')
170
+ for (const a of await presentAnnexes()) {
171
+ const s = annexSweep(a, { dry: this.dry })
172
+ out(`${a.path} ${s.files} files ${gb(s.bytes)} ${this.dry ? 'would free' : 'freed'} ${s.freed.files} files ${gb(s.freed.bytes)}`)
173
+ }
174
+ return 0
175
+ })
176
+ }
177
+ }
178
+
179
+ export const ANNEX_COMMANDS = [AnnexCommand, AnnexInitCommand, AnnexOffloadCommand, AnnexBackCommand, AnnexForgetCommand, AnnexSweepCommand]
@@ -62,6 +62,7 @@ export class AskNewCommand extends Command {
62
62
  ['minimal', 'sk ask "rotate the API token"'],
63
63
  ['with a reason', 'sk ask "buy the domain" --why "landing page is blocked on it"'],
64
64
  ['with metadata', 'sk ask "buy the domain" --kind action --blocks deploy --check "dig +short example.com"'],
65
+ ['a token he pastes in the hub', 'sk ask "mint the npm token" --secret rv/npm/token'],
65
66
  ],
66
67
  })
67
68
 
@@ -70,11 +71,12 @@ export class AskNewCommand extends Command {
70
71
  blocks = Option.String('--blocks', { required: false, description: 'what this ask blocks (task id, page, plain words)' })
71
72
  check = Option.String('--check', { required: false, description: 'shell probe that exits 0 once the ask is done (enables auto-close)' })
72
73
  why = Option.String('--why', { required: false, description: 'one line of context: why this is worth a human interrupt' })
74
+ secret = Option.Array('--secret', { required: false, description: 'a secret name the human stores (repeat for more): a credential ask whose page takes the pasted value' })
73
75
 
74
76
  async execute(): Promise<number> {
75
77
  try {
76
78
  const dir = await asksDir(process.cwd())
77
- const file = createAsk(dir, this.title, { kind: this.kind, blocks: this.blocks, check: this.check, why: this.why })
79
+ const file = createAsk(dir, this.title, { kind: this.kind, blocks: this.blocks, check: this.check, why: this.why, secrets: this.secret ?? [] })
78
80
  this.context.stdout.write(`created ${dir}/${file}\nfill every {{placeholder}} in it: the hub shows the body as written\n`)
79
81
  return 0
80
82
  } catch (e) {
@@ -6,7 +6,7 @@
6
6
  import { Command, Option } from 'clipanion'
7
7
  import { spliceMarkedBlock } from '../core/doc-block.ts'
8
8
  import { FAMILY_PAGES } from './family-pages.ts'
9
- import { type Essential, type Film, marksOf, ROW_OF, runText } from './kit/verb.ts'
9
+ import { type Effect, type Essential, type Film, marksOf, ROW_OF, runText } from './kit/verb.ts'
10
10
 
11
11
  export type CommandOption = { definition: string; description: string }
12
12
  export type CommandRow = {
@@ -25,6 +25,8 @@ export type CommandRow = {
25
25
  stamp?: string[]
26
26
  /** listed on the essentials page */
27
27
  essential?: Essential
28
+ /** acts beyond this machine or spends money: the hub asks before it runs (cli/kit/verb.ts) */
29
+ effect?: Effect
28
30
  /** what a kit row runs */
29
31
  runs?: string
30
32
  }
@@ -87,6 +89,7 @@ export function commandRows(plain: Definition[], detailed: Definition[] = [], bi
87
89
  if (m.words != null) row.words = m.words
88
90
  if (m.stamp != null) row.stamp = m.stamp
89
91
  if (m.essential != null) row.essential = m.essential
92
+ if (m.effect != null) row.effect = m.effect
90
93
  const v = ROW_OF.get(c)
91
94
  if (v != null) row.runs = runText(v.run)
92
95
  }
@@ -8,7 +8,7 @@ import { homedir } from 'os'
8
8
  import { Command, Option } from 'clipanion'
9
9
  import { daemonPort, daemonUrl, homePort, pmPort, pmUrl } from '../home/home-paths.ts'
10
10
  import { houseRootOf } from '../home/home-start.ts'
11
- import type { PmAnswer } from '../home/pm.ts'
11
+ import { ROLES, type PmAnswer, type Role } from '../home/pm.ts'
12
12
  import type { ResourceView } from '../home/resources.ts'
13
13
  import { coreGroup, declaredRow, groupRows, processGroups, stateWords, type ProcessGroup } from '../home/process-rows.ts'
14
14
  import type { PmConfig } from '../home/pm-config.ts'
@@ -159,11 +159,14 @@ export class GlobalProcessesCommand extends Command {
159
159
 
160
160
  export type SwitchAct = 'start' | 'stop' | 'restart'
161
161
 
162
+ /** what a switch follows, the same on a global process and on one of pm's own roles (the daemon, the web) */
163
+ export type SwitchView = Pick<ResourceView, 'status' | 'pid' | 'want' | 'note' | 'tail'>
164
+
162
165
  export type SwitchDeps = {
163
166
  /** pm's answer to the switch: null when it took it, else why not */
164
167
  post: (id: string, act: SwitchAct | 'open' | 'chrome' | 'app') => Promise<string | null>
165
168
  /** the process as pm sees it now, null when pm does not answer */
166
- view: (id: string) => Promise<ResourceView | null>
169
+ view: (id: string) => Promise<SwitchView | null>
167
170
  sleep: (ms: number) => Promise<void>
168
171
  now: () => number
169
172
  log: (line: string) => void
@@ -175,10 +178,13 @@ const SWITCH_POLL_MS = 1_000
175
178
  /** how long the state the switch left counts as pm not having acted yet */
176
179
  export const SWITCH_GRACE_MS = 30_000
177
180
 
178
- /** flip a global process through pm, then follow pm's state until its probe
179
- * settles it: 0 once it is up (or down for stop), 1 otherwise. The launcher's
180
- * exit code proves nothing, pm's probe does */
181
+ /** flip a global process, or one of pm's own roles, through pm, then follow
182
+ * pm's state until its probe settles it: 0 once it is up (or down for stop),
183
+ * 1 otherwise. A restart is up only on a new pid: the old one still answers
184
+ * until pm stops it (pm stops the web after its answer is out). The
185
+ * launcher's exit code proves nothing, pm's probe does */
181
186
  export async function switchProcess(id: string, act: SwitchAct, d: SwitchDeps, waitMs = SWITCH_WAIT_MS): Promise<number> {
187
+ const before = act === 'restart' ? ((await d.view(id))?.pid ?? null) : null
182
188
  const refused = await d.post(id, act)
183
189
  if (refused != null) {
184
190
  d.log(`FAIL ${act} ${id}: ${refused}`)
@@ -199,9 +205,15 @@ export async function switchProcess(id: string, act: SwitchAct, d: SwitchDeps, w
199
205
  d.log(`${id}: ${v.status}`)
200
206
  }
201
207
  // the state it is leaving, read just after the switch, is pm not there yet
202
- const leaving = v.status === (want === 'up' ? 'down' : 'up') && d.now() - start < SWITCH_GRACE_MS
203
- const moving = v.status === 'starting' || v.status === 'stopping' || v.want !== want || leaving
208
+ const graced = d.now() - start < SWITCH_GRACE_MS
209
+ const leaving = v.status === (want === 'up' ? 'down' : 'up') && graced
210
+ const old = before != null && v.pid === before
211
+ const moving = v.status === 'starting' || v.status === 'stopping' || v.want !== want || leaving || (old && graced)
204
212
  if (!moving) {
213
+ if (old && v.status === 'up') {
214
+ d.log(`FAIL ${id} still runs pid ${before} ${Math.round(SWITCH_GRACE_MS / 1000)}s after the restart: pm did not restart it`)
215
+ return 1
216
+ }
205
217
  if (v.status === want) return 0
206
218
  d.log(`FAIL ${id} is ${v.status}, not ${want}${v.note == null ? '' : `: ${v.note}`}`)
207
219
  for (const l of v.tail.slice(-10)) d.log(` log: ${l}`)
@@ -215,17 +227,24 @@ export async function switchProcess(id: string, act: SwitchAct, d: SwitchDeps, w
215
227
  }
216
228
  }
217
229
 
218
- /** the switch against the running pm */
230
+ const isRole = (id: string): id is Role => (ROLES as string[]).includes(id)
231
+
232
+ /** the switch against the running pm: pm's own roles (the daemon, the web) through its child api, every other id a
233
+ * global process */
219
234
  export const pmSwitchDeps = (log: (line: string) => void, url = pmUrl()): SwitchDeps => ({
220
235
  post: async (id, act) => {
221
236
  try {
222
- const r = await fetch(`${url}/api/pm/resource`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ id, act }), signal: AbortSignal.timeout(5_000) })
237
+ const r = await fetch(`${url}/api/pm/${isRole(id) ? 'child' : 'resource'}`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ id, act }), signal: AbortSignal.timeout(5_000) })
223
238
  return r.ok ? null : await r.text()
224
239
  } catch (e) {
225
240
  return `pm does not answer on ${url} (${(e as Error).message}): shipkit pm install`
226
241
  }
227
242
  },
228
- view: async (id) => (await askPm(url))?.resources.find((r) => r.id === id) ?? null,
243
+ view: async (id) => {
244
+ const a = await askPm(url)
245
+ if (a == null) return null
246
+ return (isRole(id) ? a.children.find((c) => c.id === id) : a.resources.find((r) => r.id === id)) ?? null
247
+ },
229
248
  sleep: (ms) => Bun.sleep(ms),
230
249
  now: () => Date.now(),
231
250
  log,
@@ -268,7 +287,11 @@ export class GlobalProcessRestartCommand extends SwitchCommand {
268
287
  static override usage = Command.Usage({
269
288
  category: 'Home',
270
289
  description: 'restart a global process through pm and wait until its probe answers again. Exit 0 once it is up',
271
- examples: [['restart ComfyUI, so it rescans its models', 'sk gp restart comfyui']],
290
+ details: 'restart a global process, or one of pm\'s own roles (`daemon`, `web`: the same as `sk pm restart <role>`), through pm, and wait until its probe answers again. A process pm holds a pid for is up only on a new pid. Exit 0 once it is up, 1 when it crashed, kept its old pid or pm refused',
291
+ examples: [
292
+ ['restart ComfyUI, so it rescans its models', 'sk gp restart comfyui'],
293
+ ['restart the home daemon in place', 'sk gp restart daemon'],
294
+ ],
272
295
  })
273
296
  }
274
297