rvlib-shipkit 2.13.0 → 2.15.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 (270) hide show
  1. package/CHANGELOG.md +38 -13
  2. package/package.json +1 -1
  3. package/src/assets/run-assets.ts +2 -2
  4. package/src/assets/server/studio-server.ts +27 -23
  5. package/src/check.ts +3 -3
  6. package/src/checks/SK001-package-json-shape.check.ts +4 -4
  7. package/src/checks/SK002-contracts-fulfillness.check.ts +2 -2
  8. package/src/checks/SK003-claude-md-shape.check.ts +19 -12
  9. package/src/checks/SK004-gitignore-policy.check.ts +18 -4
  10. package/src/checks/SK005-rvlib-versions.check.ts +1 -1
  11. package/src/checks/SK006-npm-publish-safety.check.ts +3 -3
  12. package/src/checks/SK007-github-visibility.check.ts +2 -2
  13. package/src/checks/SK008-reviewer-agent.check.ts +1 -1
  14. package/src/checks/SK010-undeclared-unit.check.ts +2 -2
  15. package/src/checks/SK011-sibling-unit-ranges.check.ts +2 -2
  16. package/src/checks/SK012-config-barrel-import.check.ts +1 -1
  17. package/src/checks/SK013-one-way-in-policy.check.ts +2 -2
  18. package/src/checks/SK015-nested-repo.check.ts +2 -2
  19. package/src/checks/SK016-legacy-check-shapes.check.ts +2 -2
  20. package/src/checks/SK017-vscode-hub-task.check.ts +2 -2
  21. package/src/checks/SK018-test-files-run.check.ts +2 -2
  22. package/src/checks/SK019-tests-run-in-units.check.ts +2 -2
  23. package/src/checks/SK020-self-spawning-check.check.ts +2 -2
  24. package/src/checks/SK022-machine-runs-the-pin.check.ts +2 -2
  25. package/src/checks/SK024-identity-colors.check.ts +1 -1
  26. package/src/checks/SK025-release-drift.check.ts +2 -2
  27. package/src/checks/SK026-asks-autoclose.check.ts +2 -2
  28. package/src/checks/SK027-agent-wiki-links.check.ts +8 -2
  29. package/src/checks/SK028-readme.check.ts +2 -2
  30. package/src/checks/SK029-explicit-check-files.check.ts +3 -3
  31. package/src/checks/SK030-cache-audit.check.ts +7 -5
  32. package/src/checks/SK031-trace-audit.check.ts +7 -7
  33. package/src/checks/SK032-ignored-inputs.check.ts +3 -3
  34. package/src/checks/SK033-global-contribution.check.ts +11 -4
  35. package/src/checks/SK034-commit-gates-armed.check.ts +2 -2
  36. package/src/checks/SK035-public-clean.check.ts +4 -4
  37. package/src/checks/SK036-draft-media-size.check.ts +2 -2
  38. package/src/checks/SK037-keyword-additions.check.ts +43 -0
  39. package/src/cli/cmd_Backup.ts +2 -2
  40. package/src/cli/cmd_Commands.ts +4 -4
  41. package/src/cli/cmd_ConfigKeys.ts +2 -2
  42. package/src/cli/cmd_Drill.ts +30 -1
  43. package/src/cli/cmd_Home.ts +1 -1
  44. package/src/cli/cmd_Init.ts +1 -1
  45. package/src/cli/cmd_Media.ts +5 -5
  46. package/src/cli/cmd_Mv.ts +14 -7
  47. package/src/cli/cmd_Review.ts +2 -2
  48. package/src/cli/cmd_Smoke.ts +1 -1
  49. package/src/cli/cmd_Social.ts +3 -3
  50. package/src/cli/cmd_Sound.ts +1 -1
  51. package/src/cli/cmd_TraceAudit.ts +6 -6
  52. package/src/cli/cmd_Trailer.ts +2 -2
  53. package/src/cli/cmd_Veille.ts +2 -2
  54. package/src/cli/cmd_When.ts +2 -2
  55. package/src/cli/family-pages.ts +19 -19
  56. package/src/cli/registry.ts +2 -1
  57. package/src/collections/collection-types.ts +2 -2
  58. package/src/collections/review.ts +1 -1
  59. package/src/comfy/comfy-panel.ts +2 -2
  60. package/src/contracts/manifests/discord.contract.ts +1 -1
  61. package/src/contracts/manifests/identity.contract.ts +1 -1
  62. package/src/contracts/manifests/itch.contract.ts +1 -1
  63. package/src/contracts/manifests/steam.contract.ts +1 -1
  64. package/src/core/agent-dir-at.ts +12 -0
  65. package/src/core/agent-dir.ts +28 -0
  66. package/src/core/budget.ts +1 -1
  67. package/src/core/canonical-scripts.ts +2 -2
  68. package/src/core/discover-checks.ts +1 -1
  69. package/src/core/global-contribution.ts +4 -1
  70. package/src/core/ignored-block.ts +1 -1
  71. package/src/core/ignored-inputs.ts +3 -2
  72. package/src/core/layout.ts +3 -3
  73. package/src/core/loop-watch.ts +1 -1
  74. package/src/core/motherhome.ts +2 -2
  75. package/src/core/one-way-in-policy.ts +8 -8
  76. package/src/core/run-ci.ts +3 -3
  77. package/src/core/runs-matrix.ts +1 -1
  78. package/src/core/slots.ts +14 -5
  79. package/src/core/trace-audit.ts +50 -9
  80. package/src/core/tree-rev.ts +1 -1
  81. package/src/drill/clean.ts +54 -0
  82. package/src/drill/run.ts +1 -1
  83. package/src/home/daemon-jobs.ts +1 -1
  84. package/src/home/global-context.ts +11 -8
  85. package/src/home/gui-app/ShipkitGui.swift +91 -2
  86. package/src/home/inbox-shape.ts +1 -1
  87. package/src/home/inbox.ts +1 -1
  88. package/src/home/pm-config.ts +4 -1
  89. package/src/home/pm-inputs.ts +2 -0
  90. package/src/home/resources.ts +7 -2
  91. package/src/home/run-pm.ts +1 -1
  92. package/src/home/serve-web.ts +2 -2
  93. package/src/hooks/commit-message.ts +1 -1
  94. package/src/hooks/hook-gates.ts +1 -1
  95. package/src/hooks/leak-guard.ts +61 -8
  96. package/src/hooks/run-hooks.ts +18 -18
  97. package/src/identities/identities.ts +1 -1
  98. package/src/identities/machine-route.ts +1 -1
  99. package/src/identities/machine.ts +1 -1
  100. package/src/init-repo.ts +2 -2
  101. package/src/ledger/gate-checks.ts +1 -1
  102. package/src/ledger/record-kept.ts +1 -1
  103. package/src/media-kinds.ts +1 -1
  104. package/src/media-store/backup/daemon.ts +1 -1
  105. package/src/media-store/backup/keys.ts +1 -1
  106. package/src/media-store/backup/manifest.ts +1 -1
  107. package/src/media-store/backup/restore.ts +1 -1
  108. package/src/media-store/backup/run.ts +1 -1
  109. package/src/media-store/backup/secret.ts +1 -1
  110. package/src/media-store/backup/snapshot.ts +1 -1
  111. package/src/media-store/backup/sources.ts +1 -1
  112. package/src/media-store/content.ts +1 -1
  113. package/src/media-store/daemon.ts +1 -1
  114. package/src/media-store/db.ts +1 -1
  115. package/src/media-store/fact.ts +1 -1
  116. package/src/media-store/hand.ts +1 -1
  117. package/src/media-store/kind.ts +1 -1
  118. package/src/media-store/purge.ts +1 -1
  119. package/src/media-store/put.ts +1 -1
  120. package/src/media-store/remote.ts +1 -1
  121. package/src/media-store/space.ts +1 -1
  122. package/src/mv/mv-md.ts +63 -22
  123. package/src/pages/forward.ts +1 -1
  124. package/src/pages/frame-client.ts +1 -1
  125. package/src/pages/routes.ts +1 -1
  126. package/src/pages/unit.ts +1 -1
  127. package/src/plan/planner.ts +1 -1
  128. package/src/plan/repo-source.ts +1 -1
  129. package/src/release/public-clean.ts +25 -7
  130. package/src/release/run-bump.ts +1 -1
  131. package/src/release/run-release.ts +3 -3
  132. package/src/repo-config.ts +23 -16
  133. package/src/review/anim.ts +1 -1
  134. package/src/review/auto.ts +1 -1
  135. package/src/review/cells.ts +15 -1
  136. package/src/review/format.ts +2 -2
  137. package/src/review/marks.ts +1 -1
  138. package/src/review/media-kind.ts +1 -1
  139. package/src/review/media-read.ts +1 -1
  140. package/src/review/model.ts +14 -4
  141. package/src/review/notes.ts +52 -4
  142. package/src/review/previews.ts +1 -1
  143. package/src/review/project.ts +1 -1
  144. package/src/review/role.ts +1 -1
  145. package/src/review/routes.ts +14 -2
  146. package/src/review/store.ts +2 -2
  147. package/src/review/threads.ts +1 -1
  148. package/src/review/trailer-desk.ts +3 -3
  149. package/src/review/trailer-media.ts +1 -1
  150. package/src/review/trailer-model.ts +1 -1
  151. package/src/review/trailer-routes.ts +1 -1
  152. package/src/review/trailer-shots.ts +1 -1
  153. package/src/review/unit.ts +1 -1
  154. package/src/scaffold/files/tsconfig.json +1 -1
  155. package/src/scaffold/project-scaffold.ts +1 -1
  156. package/src/serve/embed.ts +1 -1
  157. package/src/serve/hub-app/check-words.ts +1 -1
  158. package/src/serve/hub-app/frames-st.ts +1 -1
  159. package/src/serve/hub-app/hash-route.ts +1 -1
  160. package/src/serve/hub-app/home-st.ts +1 -1
  161. package/src/serve/hub-app/home-strip.css +1 -1
  162. package/src/serve/hub-app/hub-app.tsx +2 -2
  163. package/src/serve/hub-app/identities-st.ts +1 -1
  164. package/src/serve/hub-app/identities-view.tsx +5 -4
  165. package/src/serve/hub-app/identity-address.ts +1 -1
  166. package/src/serve/hub-app/inbox-st.ts +1 -1
  167. package/src/serve/hub-app/inbox-view.tsx +1 -1
  168. package/src/serve/hub-app/kept-cols.tsx +30 -0
  169. package/src/serve/hub-app/keys.ts +1 -1
  170. package/src/serve/hub-app/media-svc.ts +1 -1
  171. package/src/serve/hub-app/pages-frames.tsx +1 -1
  172. package/src/serve/hub-app/pages-svc.ts +1 -1
  173. package/src/serve/hub-app/projects-svc.ts +1 -1
  174. package/src/serve/hub-app/repo-st.ts +1 -1
  175. package/src/serve/hub-app/review/review-board.tsx +1 -1
  176. package/src/serve/hub-app/review/review-cells.tsx +3 -2
  177. package/src/serve/hub-app/review/review-page.tsx +5 -4
  178. package/src/serve/hub-app/review/review-st.ts +15 -7
  179. package/src/serve/hub-app/review/review-thread.tsx +52 -5
  180. package/src/serve/hub-app/review/review-views.tsx +50 -33
  181. package/src/serve/hub-app/review/thread-st.ts +79 -27
  182. package/src/serve/hub-app/review/trailer-page.tsx +5 -4
  183. package/src/serve/hub-app/review/trailer-st.ts +1 -1
  184. package/src/serve/hub-app/review.css +9 -1
  185. package/src/serve/hub-app/site/site-part.tsx +1 -1
  186. package/src/serve/hub-app/site/site-st.ts +1 -1
  187. package/src/serve/hub-app/social/calendar.tsx +1 -1
  188. package/src/serve/hub-app/social/comms-page.tsx +29 -5
  189. package/src/serve/hub-app/social/kit.tsx +1 -1
  190. package/src/serve/hub-app/social/post-card.tsx +1 -1
  191. package/src/serve/hub-app/social/social-model.ts +1 -1
  192. package/src/serve/hub-app/social/social-page.tsx +12 -5
  193. package/src/serve/hub-app/social/social-st.ts +31 -3
  194. package/src/serve/hub-app/social.css +1 -1
  195. package/src/serve/hub-app/stores/stores-page.tsx +5 -4
  196. package/src/serve/hub-app/stores/stores-st.ts +1 -1
  197. package/src/serve/hub-app/stores.css +1 -1
  198. package/src/serve/hub-app/tree-row.tsx +1 -1
  199. package/src/serve/hub-app/veille/veille-page.tsx +5 -4
  200. package/src/serve/hub-app/veille/veille-st.ts +1 -1
  201. package/src/serve/hub-app/veille.css +1 -1
  202. package/src/serve/hub-runtime.ts +6 -2
  203. package/src/serve/project-gutter-route.ts +1 -1
  204. package/src/shot/box.ts +5 -7
  205. package/src/shot/browser-slot.ts +18 -6
  206. package/src/shot/client.ts +1 -2
  207. package/src/shot/clip-encoder.ts +16 -13
  208. package/src/shot/film-box.ts +132 -28
  209. package/src/shot/shooter.ts +21 -2
  210. package/src/shot/stepped-clip.ts +1 -1
  211. package/src/site/desk.ts +2 -2
  212. package/src/site/routes.ts +1 -1
  213. package/src/site/unit.ts +1 -1
  214. package/src/social/card-drafts.ts +24 -0
  215. package/src/social/compose.ts +2 -2
  216. package/src/social/desk-index.ts +1 -1
  217. package/src/social/desk-wire.ts +1 -1
  218. package/src/social/drafts.ts +3 -3
  219. package/src/social/load.ts +14 -1
  220. package/src/social/media-facts.ts +1 -1
  221. package/src/social/media-kind.ts +1 -1
  222. package/src/social/media-limit.ts +1 -1
  223. package/src/social/media-of.ts +1 -1
  224. package/src/social/migrate.ts +1 -1
  225. package/src/social/post-url.ts +1 -1
  226. package/src/social/presence.ts +2 -2
  227. package/src/social/public-read.ts +1 -1
  228. package/src/social/publish/bluesky.ts +1 -1
  229. package/src/social/publish/discord.ts +1 -1
  230. package/src/social/push.ts +10 -4
  231. package/src/social/richtext.ts +1 -1
  232. package/src/social/routes.ts +10 -4
  233. package/src/social/stats.ts +1 -1
  234. package/src/social/text.ts +1 -1
  235. package/src/social/tracker-route.ts +1 -1
  236. package/src/social/tracker.ts +1 -1
  237. package/src/social/unit.ts +1 -1
  238. package/src/social/writes.ts +1 -1
  239. package/src/stores/collection.ts +1 -1
  240. package/src/stores/desk.ts +1 -1
  241. package/src/stores/model.ts +1 -1
  242. package/src/stores/routes.ts +1 -1
  243. package/src/stores/unit.ts +1 -1
  244. package/src/suite/judge-suites.ts +1 -1
  245. package/src/trace/tracer.ts +12 -5
  246. package/src/trailer/adapter.ts +1 -1
  247. package/src/trailer/build.ts +6 -4
  248. package/src/trailer/holes.ts +1 -1
  249. package/src/trailer/passage.ts +1 -1
  250. package/src/trailer/prune.ts +1 -1
  251. package/src/trailer/states.ts +1 -1
  252. package/src/trailer/versions.ts +1 -1
  253. package/src/trailer/words.ts +1 -1
  254. package/src/tui/run-tui.ts +1 -1
  255. package/src/tui/tui-store.ts +1 -1
  256. package/src/veille/asks.ts +1 -1
  257. package/src/veille/auto.ts +1 -1
  258. package/src/veille/batch.ts +1 -1
  259. package/src/veille/chrome.ts +1 -1
  260. package/src/veille/collection.ts +1 -1
  261. package/src/veille/desk.ts +1 -1
  262. package/src/veille/identity.ts +1 -1
  263. package/src/veille/import.ts +1 -1
  264. package/src/veille/log.ts +1 -1
  265. package/src/veille/platforms.ts +1 -1
  266. package/src/veille/reads.ts +1 -1
  267. package/src/veille/replied.ts +1 -1
  268. package/src/veille/routes.ts +2 -2
  269. package/src/veille/watch.ts +1 -1
  270. package/src/veille/worth.ts +2 -2
@@ -23,7 +23,7 @@ export const HOOK_GATES = [
23
23
  export type HookGateId = (typeof HOOK_GATES)[number]['id']
24
24
 
25
25
  /** the page that owns every commit gate */
26
- export const HOOK_GATES_OWNER = 'build/shipkit/commit-gates.md'
26
+ export const HOOK_GATES_OWNER = 'tools/shipkit/commit-gates.md'
27
27
 
28
28
  /** the whole pre-commit hook, boot included, past which it warns */
29
29
  export const HOOK_BUDGET_MS = 1_000
@@ -21,7 +21,9 @@ import { basename, join } from 'path'
21
21
  import { gitBin } from '../core/git-bin.ts'
22
22
  import { KEYWORD_FILE, MACHINE_PRIVATE } from '../core/layout.ts'
23
23
 
24
- export type LeakHit = { where: string; pattern: string; file?: string }
24
+ /** `over`: an entry with a `count` named this pattern in this file, and the
25
+ * file now holds more, so every match blocks again until a person reviews it */
26
+ export type LeakHit = { where: string; pattern: string; file?: string; over?: { count: number; found: number; source: string } }
25
27
  export type LeakWaiver = LeakHit & { reason: string; source: string }
26
28
 
27
29
  /** what a hit REPORTS. The matched string is private by construction, and a
@@ -65,6 +67,12 @@ export type LeakAllowEntry = {
65
67
  * are arithmetic, not prose, so a keyword inside one is noise. The same
66
68
  * keyword on a normal line of the same file still blocks. */
67
69
  inHashes?: boolean
70
+ /** the most matches of the pattern the file may hold: one more and every
71
+ * match blocks again. Takes exactly one exact file in `paths` and one
72
+ * pattern, so the entry reads as « this word, this file, this many ».
73
+ * No readable label rides with it: a short keyword's label is the
74
+ * keyword, and the hit and waiver lines print it outside git. */
75
+ count?: number
68
76
  }
69
77
 
70
78
  export type LeakGuardResult =
@@ -84,8 +92,9 @@ const escapeRegex = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$
84
92
  * or `desk-lamp-...` is a word that ends in `sk`, never a key */
85
93
  export const SK_KEY_ROW = 're:(?<![A-Za-z0-9_-])sk-[A-Za-z0-9_-]{20,}'
86
94
 
87
- /** the generic secret shapes: a private key, an AWS key id, an sk- key, a GitHub token, a Slack token. The starter of
88
- * every keyword file, and the rows the backup refuses a file on (media-store/backup/secret.ts) */
95
+ /** the generic secret shapes: a private key, an AWS key id, an sk- key, a GitHub token, a Slack token. Built into
96
+ * every scan (`withBuiltinRows`), never copied into a keyword file, and the rows the backup refuses a file on
97
+ * (media-store/backup/secret.ts) */
89
98
  export const SECRET_ROWS: readonly string[] = ['re:-----BEGIN [A-Z ]*PRIVATE KEY-----', 're:AKIA[0-9A-Z]{16}', SK_KEY_ROW, 're:ghp_[A-Za-z0-9]{36}', 're:xox[baprs]-[A-Za-z0-9-]{10,}']
90
99
 
91
100
  /** rows the hooks seeded before their shape was fixed, read as the fixed
@@ -108,7 +117,10 @@ export function parsePatterns(text: string): ParsedPatterns {
108
117
  const row = raw.trim()
109
118
  if (row === '' || row.startsWith('#')) continue
110
119
  if (row.startsWith('re:')) {
111
- try { regexes.push({ row, re: new RegExp((SEEDED_ROW_FIXES[row] ?? row).slice(3), 'i') }) }
120
+ // a secret shape is exact, like the token it matches (a key is `sk-`, never `SK-`, which a public plugin
121
+ // name carries); every other regex row is case-insensitive
122
+ const source = SEEDED_ROW_FIXES[row] ?? row
123
+ try { regexes.push({ row, re: new RegExp(source.slice(3), SECRET_ROWS.includes(source) ? '' : 'i') }) }
112
124
  catch { /* a malformed row must not disable the whole guard */ }
113
125
  } else if (row.startsWith('w:')) {
114
126
  const word = row.slice(2).trim().toLowerCase()
@@ -120,6 +132,36 @@ export function parsePatterns(text: string): ParsedPatterns {
120
132
  return { substrings, words, regexes }
121
133
  }
122
134
 
135
+ /** the keyword text a scan reads: the built-in secret shapes, then the files' rows */
136
+ export const withBuiltinRows = (fileTexts: string[]): string => [...SECRET_ROWS, ...fileTexts].join('\n')
137
+
138
+ /** what makes two rows one row: a `w:` row and a substring row of the same word, in any case, or two `re:` rows of
139
+ * one regex (a seeded row and its fix included). null for a blank line or a comment */
140
+ function rowKey(raw: string): string | null {
141
+ const row = raw.trim()
142
+ if (row === '' || row.startsWith('#')) return null
143
+ if (row.startsWith('re:')) return SEEDED_ROW_FIXES[row] ?? row
144
+ return (row.startsWith('w:') ? row.slice(2).trim() : row).toLowerCase()
145
+ }
146
+
147
+ /** a repo's keyword file holds its ADDITIONS only: the official list is the machine's
148
+ * (~/.shipkit/private/banned-keywords.txt) and the secret shapes are built in. `copies` are the rows either already
149
+ * holds; `text` is the file without them, its comments and its own rows kept. The official row's shape wins: a
150
+ * repo's `foo` beside an official `w:foo` is a copy that stays stricter than the list decided */
151
+ export function repoAdditions(repoText: string, officialText: string): { text: string; copies: string[]; own: number } {
152
+ const held = new Set([...SECRET_ROWS, ...officialText.split('\n')].map(rowKey).filter((k): k is string => k != null))
153
+ const copies: string[] = []
154
+ let own = 0
155
+ const kept = repoText.split('\n').filter((line) => {
156
+ const k = rowKey(line)
157
+ if (k == null) return true
158
+ if (held.has(k)) { copies.push(line.trim()); return false }
159
+ own++
160
+ return true
161
+ })
162
+ return { text: kept.join('\n'), copies, own }
163
+ }
164
+
123
165
  type Span = [start: number, end: number]
124
166
 
125
167
  // a substring row is matched by a case-insensitive REGEX rather than by
@@ -194,23 +236,28 @@ export function evaluateLeak(targets: ScanTarget[], p: ParsedPatterns, allow: Lo
194
236
  if (seen.has(key)) continue
195
237
  seen.add(key)
196
238
  const fp = patternFingerprint(id)
239
+ let over: LeakHit['over']
197
240
  const entry = allow.find((a) => {
198
241
  if (a.paths != null && !pathCovered(t.file, a.paths)) return false
199
242
  if (a.patterns != null && !a.patterns.some((x) => x === fp || x.toLowerCase() === id)) return false
243
+ if (a.count != null && (a.paths?.[0] !== t.file || spans.length > a.count)) {
244
+ if (a.paths?.[0] === t.file) over = { count: a.count, found: spans.length, source: a.source }
245
+ return false
246
+ }
200
247
  if (a.inHashes === true) {
201
248
  hashes ??= hashSpans(t.content)
202
249
  if (!spans.every((s) => inside(s, hashes!))) return false
203
250
  }
204
251
  return true
205
252
  })
206
- if (entry == null) hits.push({ where: t.where, pattern: id, file: t.file })
253
+ if (entry == null) hits.push({ where: t.where, pattern: id, file: t.file, ...(over == null ? {} : { over }) })
207
254
  else waived.push({ where: t.where, pattern: id, file: t.file, reason: entry.reason, source: entry.source })
208
255
  }
209
256
  }
210
257
  return { hits, waived }
211
258
  }
212
259
 
213
- const ALLOW_KEYS = ['reason', 'paths', 'patterns', 'inHashes']
260
+ const ALLOW_KEYS = ['reason', 'paths', 'patterns', 'inHashes', 'count']
214
261
  const FINGERPRINT = /^fp:[0-9a-f]{12}$/
215
262
 
216
263
  /** why an entry cannot be used, or null. `tracked` = the source is committed
@@ -230,6 +277,13 @@ export function leakAllowProblem(entry: unknown, where: string, tracked: boolean
230
277
  return `${where}: '${k}' is a non-empty array of non-empty strings`
231
278
  }
232
279
  if (e['inHashes'] != null && typeof e['inHashes'] !== 'boolean') return `${where}: 'inHashes' is a boolean`
280
+ if (e['count'] != null) {
281
+ const n = e['count']
282
+ if (typeof n !== 'number' || !Number.isInteger(n) || n < 1) return `${where}: 'count' is a whole number of at least 1`
283
+ const paths = e['paths'] as string[] | undefined
284
+ if (paths?.length !== 1 || paths[0]!.endsWith('/')) return `${where}: 'count' takes exactly one file in 'paths', never a folder`
285
+ if ((e['patterns'] as string[] | undefined)?.length !== 1) return `${where}: 'count' takes exactly one entry in 'patterns'`
286
+ }
233
287
  if (tracked)
234
288
  for (const x of (e['patterns'] as string[] | undefined) ?? [])
235
289
  if (!FINGERPRINT.test(x))
@@ -358,9 +412,8 @@ export function runLeakGuard(root: string, o: LeakGuardOpts = {}): LeakGuardResu
358
412
  const file = join(root, rel)
359
413
  const sources = [existsSync(file) ? file : null, globalKeywordFile()].filter((f): f is string => f != null)
360
414
  if (sources.length === 0) return { status: 'skipped', reason: `${rel} not found and no machine-global banned-keywords.txt — no keyword list, no leak guard` }
361
- const patterns = parsePatterns(sources.map((f) => readFileSync(f, 'utf8')).join('\n'))
415
+ const patterns = parsePatterns(withBuiltinRows(sources.map((f) => readFileSync(f, 'utf8'))))
362
416
  const count = patterns.substrings.length + patterns.words.length + patterns.regexes.length
363
- if (count === 0) return { status: 'skipped', reason: `keyword file(s) have no patterns (${sources.join(', ')})` }
364
417
 
365
418
  const notes: string[] = []
366
419
  const allow: LoadedAllow[] = []
@@ -8,7 +8,7 @@ import { dirname, join, relative } from 'path'
8
8
  import { fileURLToPath } from 'url'
9
9
  import { KEYWORD_FILE, LAYOUT } from '../core/layout.ts'
10
10
  import { commitMessageOffenses } from './commit-message.ts'
11
- import { globalAllowFile, globalKeywordFile, maskPattern, patternFingerprint, runLeakGuard, SECRET_ROWS, type LeakAllowEntry, type LeakHit, type LeakWaiver } from './leak-guard.ts'
11
+ import { globalAllowFile, globalKeywordFile, maskPattern, patternFingerprint, runLeakGuard, type LeakAllowEntry, type LeakHit, type LeakWaiver } from './leak-guard.ts'
12
12
  import { runRootIdentity } from './root-identity.ts'
13
13
  import { readStaged } from './staged.ts'
14
14
  import { ALLOW_MASS_DELETE, runTreeShrink } from './tree-shrink.ts'
@@ -62,7 +62,7 @@ export type HooksConfig = {
62
62
  languageAllow?: string[]
63
63
  /** RETIRED, read as `off` while SK029 ports it there: a commit gate is
64
64
  * turned off like any check, `off: { <gate id>: '<why>' }`
65
- * (build/shipkit/runs.md). Dies once `shipkit fleet` shows no repo
65
+ * (tools/shipkit/runs.md). Dies once `shipkit fleet` shows no repo
66
66
  * carrying it */
67
67
  disable?: HookGateId[]
68
68
  }
@@ -152,27 +152,27 @@ export function installHooks(root: string, binInvocation: string, keywordFile?:
152
152
  }
153
153
  }
154
154
 
155
- // a starter so the leak guard bites from day one instead of skipping forever:
156
- // generic secret shapes only. private names live in the machine-global
157
- // ~/.shipkit/private/banned-keywords.txt, which the guard reads on every run
158
- // (never copied into a repo: a copy rots and a copy can leak)
159
- export const KEYWORD_STARTER = `# banned-keywords — the leak guard greps every commit (added lines, paths,
160
- # message) for these rows. one row = one case-insensitive substring, or
161
- # re:<regex>. add repo-specific names here; machine-wide private names go in
162
- # ~/.shipkit/private/banned-keywords.txt, read automatically alongside this file.
155
+ // a starter that names what belongs here: this repo's ADDITIONS. The official list is the machine's
156
+ // ~/.shipkit/private/banned-keywords.txt and the secret shapes are built into the guard, so neither is copied
157
+ // into a repo (a copy rots: SK037 strips one)
158
+ export const KEYWORD_STARTER = `# banned-keywords: THIS repo's additions to the leak guard, which greps every
159
+ # commit (added lines, paths, message) and every npm tarball for these rows.
160
+ # one row = one case-insensitive substring, w:<word> (whole words), or re:<regex>.
161
+ # the official list is ~/.shipkit/private/banned-keywords.txt and the generic
162
+ # secret shapes are built in: both are read with this file, never copied here.
163
+ # a word the list bans that this repo must say: repo.config.ts hooks.leakAllow.
163
164
  # this file is gitignored on purpose: the list itself is private.
164
- ${SECRET_ROWS.join('\n')}
165
165
  `
166
166
 
167
- /** seed the configured keyword file with the generic starter so the guard is
168
- * ARMED, not a skip. an existing file is never touched. */
167
+ /** seed the configured keyword file with the starter: its presence ARMS the guard (the built-in secret shapes
168
+ * scan from then on), and it says what the repo adds. an existing file is never touched. */
169
169
  function seedKeywordFile(root: string, keywordFile?: string): string | null {
170
170
  const rel = keywordFile ?? KEYWORD_FILE
171
171
  const dest = join(root, rel)
172
172
  if (existsSync(dest)) return null
173
173
  mkdirSync(dirname(dest), { recursive: true })
174
174
  writeFileSync(dest, KEYWORD_STARTER)
175
- return `${rel} (starter shapes)`
175
+ return `${rel} (the repo's additions, empty)`
176
176
  }
177
177
 
178
178
  export type GateOutcome = { id: string; ok: boolean; lines: string[] }
@@ -182,7 +182,7 @@ export type GateOutcome = { id: string; ok: boolean; lines: string[] }
182
182
  * exempt it. The file rides along for a content hit; a staged-PATH hit adds
183
183
  * nothing, because there the path IS what matched. */
184
184
  const hitLine = (x: LeakHit): string =>
185
- ` ${x.where}${x.where === 'staged content' && x.file != null ? ` ${x.file}` : ''}: ${maskPattern(x.pattern)} [${patternFingerprint(x.pattern)}]`
185
+ ` ${x.where}${x.where === 'staged content' && x.file != null ? ` ${x.file}` : ''}: ${maskPattern(x.pattern)} [${patternFingerprint(x.pattern)}]${x.over == null ? '' : `, ${x.over.found} added where ${x.over.source} allows ${x.over.count}`}`
186
186
 
187
187
  /** what the allowlist let through, one line per waiver. An allowlist that
188
188
  * fires invisibly is a silent weakening, so a waived match is as loud as a
@@ -215,7 +215,7 @@ export function blockedStaged(staged: string[], config: RepoConfig): string[] {
215
215
  const draftsOpen = (c: RepoConfig): boolean => c.visibility === 'private'
216
216
 
217
217
  /** the pre-commit gate: built-in leak guard, then the repo's own commands.
218
- * A commit takes ~1s (build/shipkit/commit-gates.md): the gate times itself, and going
218
+ * A commit takes ~1s (tools/shipkit/commit-gates.md): the gate times itself, and going
219
219
  * over budget WARNs naming the fix, so drift back to slow commits is loud. */
220
220
  export async function runPreCommit(root: string, config: RepoConfig): Promise<GateOutcome[]> {
221
221
  const started = performance.now()
@@ -307,7 +307,7 @@ export async function runPreCommit(root: string, config: RepoConfig): Promise<Ga
307
307
  out.push({
308
308
  id: 'hook-budget',
309
309
  ok: true,
310
- lines: [`WARN pre-commit took ${(elapsed / 1000).toFixed(1)}s (budget ${HOOK_BUDGET_MS / 1000}s) — move slow preCommit commands to ci tasks, or a check off onPreCommit (build/shipkit/runs.md)`],
310
+ lines: [`WARN pre-commit took ${(elapsed / 1000).toFixed(1)}s (budget ${HOOK_BUDGET_MS / 1000}s) — move slow preCommit commands to ci tasks, or a check off onPreCommit (tools/shipkit/runs.md)`],
311
311
  })
312
312
  return out
313
313
  }
@@ -347,7 +347,7 @@ async function runPreCommitChecks(root: string, config: RepoConfig): Promise<Gat
347
347
  out.push({
348
348
  id: 'slow-import',
349
349
  ok: true,
350
- lines: [`WARN ${relative(root, s.path)} took ${Math.round(s.ms)}ms to import, over ${SLOW_IMPORT_MS}ms: every surface that lists the checks pays it, so move its heavy imports inside \`run\` (build/shipkit/writing-a-check.md)`],
350
+ lines: [`WARN ${relative(root, s.path)} took ${Math.round(s.ms)}ms to import, over ${SLOW_IMPORT_MS}ms: every surface that lists the checks pays it, so move its heavy imports inside \`run\` (tools/shipkit/writing-a-check.md)`],
351
351
  })
352
352
  const pass = new CheckPass(root, config, undefined, false)
353
353
  for (const k of found.checks) {
@@ -1,4 +1,4 @@
1
- // the identities, who speaks (wiki build/shipkit/social.md, Identities): one folder an identity in the house repo,
1
+ // the identities, who speaks (wiki tools/shipkit/social.md, Identities): one folder an identity in the house repo,
2
2
  // `.shipkit/identities/<id>/`, its profile, brand, accounts and their places, and a company's legal rows. Read from
3
3
  // the disk as it is on every call; the one constraint: never in the npm package, a project names its identity
4
4
  import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
@@ -1,4 +1,4 @@
1
- // the home's identities page (wiki build/shipkit/home.md, Identities): every identity, its accounts, the repos that
1
+ // the home's identities page (wiki tools/shipkit/home.md, Identities): every identity, its accounts, the repos that
2
2
  // speak as it, and where its data lives on disk. `POST /api/home/identities/open` opens one of those places in VS Code
3
3
  // or the Finder; it names an identity, a place and a repo, never a path
4
4
  import { existsSync, readdirSync } from 'node:fs'
@@ -1,4 +1,4 @@
1
- // the identities as the machine's surfaces show them (wiki build/shipkit/social.md, Identities): the project list's
1
+ // the identities as the machine's surfaces show them (wiki tools/shipkit/social.md, Identities): the project list's
2
2
  // headers (`railIdentities`: a name, a colour, a mark) and the repo each row speaks as. Read again only when an
3
3
  // `identity.md` of the folder moves, so the list's 5 s poll costs a few stats
4
4
  import { existsSync, readdirSync, statSync } from 'node:fs'
package/src/init-repo.ts CHANGED
@@ -118,7 +118,7 @@ export async function initRepo(root: string, opts: InitOpts = {}): Promise<numbe
118
118
  let added = 0
119
119
  // canonical script bodies — ONE source (core/canonical-scripts.ts),
120
120
  // shared with rule SK001's autofix; vocabulary owned by
121
- // meta/rv-conventions/package-json.md
121
+ // patterns/rv-conventions/package-json.md
122
122
  // `test` is scaffolded only once the repo has tests: `bun test` exits
123
123
  // non-zero with none, and a scaffold that reds the gate is a bad scaffold
124
124
  for (const [k, v] of Object.entries(canonicalBodies({ bin: opts.bin }))) {
@@ -166,7 +166,7 @@ export async function initRepo(root: string, opts: InitOpts = {}): Promise<numbe
166
166
  }
167
167
 
168
168
  /** ONE WAY IN, both halves, through the SAME fixers `shipkit check --fix` runs
169
- * (build/shipkit/one-way-in.md). Nothing here is a second implementation: rule SK001
169
+ * (tools/shipkit/one-way-in.md). Nothing here is a second implementation: rule SK001
170
170
  * routes the package.json scripts, rule SK013 writes the harness policy, and
171
171
  * init just calls them so a wired repo is born enforced and a re-run repairs
172
172
  * one that was not. The deny is a RESTRICTION, which is why it lands
@@ -301,7 +301,7 @@ export async function composeChecks(root: string, c: RepoConfig, o: ComposeOpts
301
301
  // what it likes, and a gate that guesses which one is the tests will miss
302
302
  // one.
303
303
  // a compose is seconds of sync work on a large repo: the loop goes back to the pages between its parts (wiki
304
- // build/shipkit/home.md, Nothing heavy on the daemon's loop)
304
+ // tools/shipkit/home.md, Nothing heavy on the daemon's loop)
305
305
  await yieldLoop()
306
306
  const rootTest = rootTestKey(root, c, floor)
307
307
  await yieldLoop()
@@ -3,7 +3,7 @@
3
3
  // db file's and its WAL's time and size: any write moves one of them. A table that only grows at its end and loses its
4
4
  // oldest rows (runs, suites: every write sweeps what is past the keep window) is read whole once, then by the rows
5
5
  // written since, the swept ones dropped from its front; what does not add up reads it whole again. `warmTable` is the
6
- // same whole read in pages, the loop given back between two (wiki build/shipkit/home.md, Nothing heavy on the
6
+ // same whole read in pages, the loop given back between two (wiki tools/shipkit/home.md, Nothing heavy on the
7
7
  // daemon's loop)
8
8
  import { statSync } from 'fs'
9
9
  import type { Database } from 'bun:sqlite'
@@ -1,4 +1,4 @@
1
- // every kind the machine's media store holds (wiki build/shipkit/media-store.md, A kind): the daemon and `sk media` read
1
+ // every kind the machine's media store holds (wiki tools/shipkit/media-store.md, A kind): the daemon and `sk media` read
2
2
  // this list. A new caller writes its kind beside its own code and adds its line here
3
3
  import type { MediaKind } from './media-store/kind.ts'
4
4
  import { handKind, labelsInIndex } from './media-store/hand.ts'
@@ -1,4 +1,4 @@
1
- // the daemon's backup job (wiki build/shipkit/media-store.md, Backup, The daemon): one look, in a child process the
1
+ // the daemon's backup job (wiki tools/shipkit/media-store.md, Backup, The daemon): one look, in a child process the
2
2
  // daemon starts every 2 min (home/daemon-jobs.ts), never on its loop. A cheap stamp of the sources (paths, sizes,
3
3
  // times, no hashing); once it moved and then held still for one look, a run, at most one each 10 min; a run every 6 h
4
4
  // whatever moved, which takes the sqlite snapshots. Each failure is one line in the log
@@ -1,4 +1,4 @@
1
- // where the backup keeps its objects in the private Space (wiki build/shipkit/media-store.md, Backup): a file's bytes
1
+ // where the backup keeps its objects in the private Space (wiki tools/shipkit/media-store.md, Backup): a file's bytes
2
2
  // under `backup/<sha256>.<ext>`, a sqlite snapshot gzipped under `backup/<sha256 of the gz>.gz`, one manifest a run
3
3
  // under `backup/runs/<time>-<digest>.json.gz`. Nothing under the prefix is ever deleted
4
4
  export const BACKUP_LABEL = 'backup'
@@ -1,4 +1,4 @@
1
- // one backup run as a record (wiki build/shipkit/media-store.md, Backup, In the Space): every file the machine held,
1
+ // one backup run as a record (wiki tools/shipkit/media-store.md, Backup, In the Space): every file the machine held,
2
2
  // its sha, size, time and the key its bytes are under, and every file refused with the reason. A run of version 2 keeps
3
3
  // its files in PARTS, one a group (the home, the memories, a house repo; a big group cut in buckets by folder), each
4
4
  // part content addressed: a run that changes one file writes that file's part and the run's list of parts. A run of
@@ -1,4 +1,4 @@
1
- // A RESTORE (wiki build/shipkit/media-store.md, Backup, Restore): a run's files written back from the Space, each one
1
+ // A RESTORE (wiki tools/shipkit/media-store.md, Backup, Restore): a run's files written back from the Space, each one
2
2
  // checked by its sha before it lands. Into a folder that is empty or new, by default. In place only when asked, and
3
3
  // then a live file that differs is copied aside first, and a sqlite lands beside its live file (`.restored`): a live
4
4
  // db is never swapped under the process that writes it. The DRILL restores into a scratch folder and compares every
@@ -1,4 +1,4 @@
1
- // A BACKUP RUN (wiki build/shipkit/media-store.md, Backup): every source read once, refused or hashed (a sqlite
1
+ // A BACKUP RUN (wiki tools/shipkit/media-store.md, Backup): every source read once, refused or hashed (a sqlite
2
2
  // snapshotted first), each object the Space lacks sent from the bytes that were hashed (never
3
3
  // the live file again: it may have moved), then the run's parts the Space lacks, then the run itself, last, so a run
4
4
  // never names an object the Space lacks. A run whose state equals the last one writes nothing. The objects are never
@@ -1,4 +1,4 @@
1
- // what the backup never sends (wiki build/shipkit/media-store.md, Backup): a secret's home is the keychain, never the
1
+ // what the backup never sends (wiki tools/shipkit/media-store.md, Backup): a secret's home is the keychain, never the
2
2
  // Space. A file is refused by its name (an env file, a key file, a name that says secret, token, password, api key), by
3
3
  // the leak guard's secret shapes in its bytes, by a credential line whose value is no keychain pointer, or by its
4
4
  // size (over 50 MB is a question for the owner first, unless his repo names the path whole: `backup.paths`). The
@@ -1,4 +1,4 @@
1
- // a live sqlite copied consistently (wiki build/shipkit/media-store.md, Backup): the live file attached read only into
1
+ // a live sqlite copied consistently (wiki tools/shipkit/media-store.md, Backup): the live file attached read only into
2
2
  // a fresh database, the tables kept copied inside ONE transaction (one read snapshot of the WAL), then vacuumed. Never a
3
3
  // copy of the file while a process writes it. The same rows give the same bytes, so an unchanged db is one object.
4
4
  // A cut leaves out the rows that move by themselves (a pid, the backup's own records): else every run differs
@@ -1,4 +1,4 @@
1
- // WHAT THE BACKUP HOLDS (wiki build/shipkit/media-store.md, Backup, The inventory): every file of the machine that no
1
+ // WHAT THE BACKUP HOLDS (wiki tools/shipkit/media-store.md, Backup, The inventory): every file of the machine that no
2
2
  // git and no Space keeps, its authored or irreplaceable state. The home's veille logs, the rail order, the media index
3
3
  // and the machine db (consistent sqlite snapshots), the machine's private folder, the agents' memories of each house
4
4
  // repo; in each house repo, every untracked file of `.shipkit/` and the hand tuned `.comfy-ts/` files, and its
@@ -1,4 +1,4 @@
1
- // a media file by its content (wiki build/shipkit/media-store.md): its sha256, size and type, and the one key the Space
1
+ // a media file by its content (wiki tools/shipkit/media-store.md): its sha256, size and type, and the one key the Space
2
2
  // keeps it under, `<kind>/<sha256>.<ext>`, the same for every caller and repo that names it
3
3
  import { existsSync, statSync } from 'node:fs'
4
4
  import { extname, join } from 'node:path'
@@ -1,4 +1,4 @@
1
- // the daemon's media job (wiki build/shipkit/media-store.md, The daemon): one pass, in a child process the daemon
1
+ // the daemon's media job (wiki tools/shipkit/media-store.md, The daemon): one pass, in a child process the daemon
2
2
  // starts every 30 s (home/daemon-jobs.ts), never on its loop. Every kind of every house repo scanned into the machine
3
3
  // index once its store moved, what waits sent up, and (when the owner turned it on) the disk purged under 40 GB free.
4
4
  // Each failure is one line in the daemon's log
@@ -1,4 +1,4 @@
1
- // THE MACHINE'S MEDIA INDEX (wiki build/shipkit/media-store.md, The index): one sqlite file in the home's state folder,
1
+ // THE MACHINE'S MEDIA INDEX (wiki tools/shipkit/media-store.md, The index): one sqlite file in the home's state folder,
2
2
  // never in a repo, for every media file of this machine, whatever kind holds it. It is DERIVED: each kind's files stay
3
3
  // the truth, and a deleted index builds again from them (a file's place in the Space is found again by a HEAD). It holds
4
4
  // each file a kind names (local or not), each Space object (up or waiting, its retries), and the review store's item
@@ -1,4 +1,4 @@
1
- // a media file known by its content (wiki build/shipkit/media-store.md): the shape every caller records beside its file
1
+ // a media file known by its content (wiki tools/shipkit/media-store.md): the shape every caller records beside its file
2
2
  // name. Pure, so a page's types read it too
3
3
  export interface MediaFact {
4
4
  /** sha256, hex */
@@ -1,4 +1,4 @@
1
- // the generic kind (wiki build/shipkit/media-store.md, Put a file from any repo): a label no `MediaKind` of the code
1
+ // the generic kind (wiki tools/shipkit/media-store.md, Put a file from any repo): a label no `MediaKind` of the code
2
2
  // owns, its files named by hand through `sk media put`. The index is its only record, so its scan reads the index's
3
3
  // own rows back and asks the disk whether each file still holds the bytes of its key; nothing else names them
4
4
  import { statSync } from 'node:fs'
@@ -1,4 +1,4 @@
1
- // what a caller of the media store plugs in (wiki build/shipkit/media-store.md, A kind): where its files live in a repo,
1
+ // what a caller of the media store plugs in (wiki tools/shipkit/media-store.md, A kind): where its files live in a repo,
2
2
  // what they are, and what must stay on the disk. The store does the rest: the index, the upload, the signed URL, the
3
3
  // fetch back, the purge. A row's path is always `join(store, item, name)`, the one form every scan, pin and delete uses
4
4
  import type { MediaFact } from './fact.ts'
@@ -1,4 +1,4 @@
1
- // the disk lets go of media the Space holds (wiki build/shipkit/media-store.md, The purge). A file goes only when the
1
+ // the disk lets go of media the Space holds (wiki tools/shipkit/media-store.md, The purge). A file goes only when the
2
2
  // index says up AND a HEAD answers its size AND its kind's `beforePurge` passed. Kept: every row its kind pins, every
3
3
  // row used in the last `older` days, every row nothing names. Oldest first. The candidates and the delete read one path
4
4
  // form, `join(store, item, name)`, from the same index rows
@@ -1,4 +1,4 @@
1
- // a file put in the store by hand, and a fresh link to anything it holds (wiki build/shipkit/media-store.md, Put a file
1
+ // a file put in the store by hand, and a fresh link to anything it holds (wiki tools/shipkit/media-store.md, Put a file
2
2
  // from any repo): the one way a repo's agent keeps a file in the private Space. The index row is written before the
3
3
  // upload, so a failed upload waits for the daemon like any other; a link lasts at most 7 days, the object for good
4
4
  import { realpathSync, statSync } from 'node:fs'
@@ -1,4 +1,4 @@
1
- // a media file from the disk or the Space (wiki build/shipkit/media-store.md, Read): a URL signed for a file the disk
1
+ // a media file from the disk or the Space (wiki tools/shipkit/media-store.md, Read): a URL signed for a file the disk
2
2
  // let go, and the file fetched back into its place, checked by its sha, for a tool that needs its bytes
3
3
  import { existsSync, renameSync, rmSync, statSync } from 'node:fs'
4
4
  import { resolve } from 'node:path'
@@ -1,4 +1,4 @@
1
- // the private S3 bucket that keeps every media file of the machine's store (wiki build/shipkit/media-store.md), named by
1
+ // the private S3 bucket that keeps every media file of the machine's store (wiki tools/shipkit/media-store.md), named by
2
2
  // the house config's `serve.mediaSpace`. Every object is PRIVATE: never a public-read ACL, never a bucket policy. A page
3
3
  // reads one through a URL signed for one hour, on the CDN edge. The key pair (`KEY:SECRET`) is read through the house's
4
4
  // `credsReadCommand`, held in memory only: never written to a file, never printed
package/src/mv/mv-md.ts CHANGED
@@ -1,4 +1,4 @@
1
- // shipkit mv — rename an md page the AGILE way: one command moves the .md,
1
+ // shipkit mv — rename an md page the AGILE way: one command moves the .md (or makes it a `<topic>/index.md`),
2
2
  // its sibling asset dir and <name>.check.ts, then sweeps EVERY tracked text
3
3
  // file for refs (full path, docs-root-relative id, check filename). Dry by
4
4
  // default; --write applies; --commit adds one conventional commit (the
@@ -6,19 +6,20 @@
6
6
  // script it runs after the moves (repo-specific re-stamps). TS module moves
7
7
  // are a different concern (a TS-aware renamer owns import graphs).
8
8
  import { execSync } from 'child_process'
9
- import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'fs'
9
+ import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'fs'
10
10
  import { basename, dirname, join, relative } from 'path'
11
11
  import { isVendored } from '../core/vendored.ts'
12
12
  import { vendoredAround } from '../core/vendored-read.ts'
13
13
 
14
14
  export type MvIo = { print: (l: string) => void; printErr: (l: string) => void }
15
- export type MvOpts = { write?: boolean; commit?: boolean }
15
+ export type MvOpts = { write?: boolean; commit?: boolean; /** run the repo's `mv:after` script (a batch runs it once, at the end) */ after?: boolean }
16
16
 
17
17
  const sh = (cmd: string, cwd: string): string => execSync(cmd, { cwd }).toString()
18
18
 
19
- /** a page's own probe, named after the page: a check file, or a legacy
20
- * check script, which shares the suffix. */
21
- const SIBLING_SUFFIXES = ['.check.ts'] as const
19
+ /** a page's own files, named after the page: its check file (either suffix)
20
+ * and its unit file (a global process or a widget). Longest first, so the
21
+ * unit suffix never claims a check file. */
22
+ const SIBLING_SUFFIXES = ['.check.shipkit.ts', '.check.ts', '.shipkit.ts'] as const
22
23
 
23
24
  const posix = (p: string): string => p.replace(/\\/g, '/')
24
25
  /** a link points at a file. A directory that happens to share a prose word's
@@ -99,25 +100,31 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
99
100
  // refusing, so the probe lands one level too deep and the run still says
100
101
  // ok. Unreachable while every move was a same-dir rename, likely the
101
102
  // moment a move crosses directories
102
- const oldSiblingDir = oldRel.slice(0, -3)
103
- if (existsSync(join(root, oldSiblingDir)) && existsSync(join(root, newRel.slice(0, -3))))
104
- return die(`${newRel.slice(0, -3)}/ already exists, and ${oldSiblingDir}/ would be nested inside it rather than become it — move or merge it by hand first`)
103
+ // the index form: `<topic>/index.md` names a topic folder, so the page's
104
+ // asset dir BECOMES that folder instead of sitting beside the page
105
+ const indexForm = basename(newRel) === 'index.md' && basename(oldRel) !== 'index.md'
106
+ const oldBase = oldRel.slice(0, -3) // full path sans .md, the sibling dir
107
+ const newBase = indexForm ? dirOf(newRel) : newRel.slice(0, -3)
108
+ // in place: the page moves into its own asset dir, which already is the topic folder
109
+ const inPlace = indexForm && newBase === oldBase
110
+ if (indexForm && !inPlace && existsSync(join(root, newBase))) return die(`${newBase}/ already exists: a topic folder is created by its move, never merged into`)
111
+ if (!indexForm && existsSync(join(root, oldBase)) && existsSync(join(root, newBase)))
112
+ return die(`${newBase}/ already exists, and ${oldBase}/ would be nested inside it rather than become it: move or merge it by hand first`)
105
113
 
106
114
  const write = o.write === true || o.commit === true
107
115
  const oldName = basename(oldRel, '.md')
108
- const newName = basename(newRel, '.md')
109
- const oldBase = oldRel.slice(0, -3) // full path sans .md — the sibling dir
110
- const newBase = newRel.slice(0, -3)
116
+ const newName = basename(newBase)
111
117
  // docs-root-relative id: refs inside a wiki usually omit the top dir
112
118
  // (`build/state`, not `wiki/build/state`) — sweep both forms
113
119
  const tail = (p: string): string | null => { const seg = p.split('/'); return seg.length >= 3 ? seg.slice(1).join('/') : null }
114
120
  const oldId = tail(oldBase)
115
121
  const newId = tail(newBase)
122
+ const newPageId = tail(newRel.slice(0, -3))
116
123
 
117
124
  // longest-first so `wiki/x/state.md` beats `x/state` beats bare tokens
118
125
  const pairs: [string, string][] = [
119
- [`${oldBase}.md`, `${newBase}.md`],
120
- ...(oldId != null ? [[`${oldId}.md`, `${newId}.md`] as [string, string]] : []),
126
+ [`${oldBase}.md`, newRel],
127
+ ...(oldId != null ? [[`${oldId}.md`, `${newPageId}.md`] as [string, string]] : []),
121
128
  // probe file is named after its page; DIR-qualified so another
122
129
  // page's same-named check.ts in a different dir never gets rewritten
123
130
  ...SIBLING_SUFFIXES.flatMap((sfx): [string, string][] => [
@@ -142,7 +149,9 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
142
149
  // whole subtree, and the probe is renamed after the page, so its own entry
143
150
  // is written LAST and wins over the subtree rule.
144
151
  const moves = new Map<string, string>([[oldRel, newRel]])
145
- if (existsSync(join(root, oldBase))) {
152
+ // an asset dir is one git tracks: an empty leftover dir is not, and git mv refuses it
153
+ const hasDir = tracked.some((f) => f.startsWith(`${oldBase}/`))
154
+ if (hasDir) {
146
155
  moves.set(oldBase, newBase)
147
156
  for (const f of tracked) if (f.startsWith(`${oldBase}/`)) moves.set(f, `${newBase}${f.slice(oldBase.length)}`)
148
157
  for (const sfx of SIBLING_SUFFIXES) {
@@ -171,10 +180,15 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
171
180
  // moves AFTER the sweep (the sweep rewrote files at their old paths).
172
181
  // git mv refuses into a directory that is not there yet, and a move
173
182
  // between directories is the case where it usually is not
183
+ // the index form moves the asset dir FIRST, so it becomes the topic
184
+ // folder; created first, git mv would nest it one level down
185
+ if (!hasDir && existsSync(join(root, oldBase)) && readdirSync(join(root, oldBase)).every((e) => e === '.DS_Store')) rmSync(join(root, oldBase), { recursive: true })
186
+ mkdirSync(join(root, dirOf(hasDir ? newBase : newRel)), { recursive: true })
187
+ if (indexForm && hasDir && !inPlace) sh(`git mv ${JSON.stringify(oldBase)} ${JSON.stringify(newBase)}`, root)
174
188
  mkdirSync(join(root, dirOf(newRel)), { recursive: true })
175
189
  sh(`git mv ${JSON.stringify(oldRel)} ${JSON.stringify(newRel)}`, root)
176
- if (existsSync(join(root, oldBase))) {
177
- sh(`git mv ${JSON.stringify(oldBase)} ${JSON.stringify(newBase)}`, root)
190
+ if (hasDir) {
191
+ if (!indexForm) sh(`git mv ${JSON.stringify(oldBase)} ${JSON.stringify(newBase)}`, root)
178
192
  // the probe is named after its page, so it only moves when the NAME
179
193
  // changed. A move that keeps the name and changes the directory takes
180
194
  // the probe along inside the dir, and `git mv X X` is a fatal
@@ -184,11 +198,7 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
184
198
  }
185
199
  }
186
200
 
187
- // repo-specific re-stamps (e.g. wiki depth frontmatter) — loud on failure
188
- const pkg = existsSync(join(root, 'package.json')) ? (JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as { scripts?: Record<string, string> }) : {}
189
- if (pkg.scripts?.['mv:after'] != null) {
190
- try { execSync('bun run mv:after', { cwd: root, stdio: 'inherit' }) } catch { return die('mv:after failed, fix before committing') }
191
- }
201
+ if (o.after !== false && !runAfter(root)) return die('mv:after failed, fix before committing')
192
202
  if (o.commit === true) {
193
203
  sh('git add -A', root)
194
204
  try {
@@ -198,3 +208,34 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
198
208
  io.print(`ok: ${oldBase} → ${newBase}${o.commit === true ? ' (committed)' : ''}`)
199
209
  return 0
200
210
  }
211
+
212
+ /** the repo's own follow up to a move (`mv:after` in package.json), loud on failure */
213
+ function runAfter(root: string): boolean {
214
+ const pkg = existsSync(join(root, 'package.json')) ? (JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as { scripts?: Record<string, string> }) : {}
215
+ if (pkg.scripts?.['mv:after'] == null) return true
216
+ try { execSync('bun run mv:after', { cwd: root, stdio: 'inherit' }); return true } catch { return false }
217
+ }
218
+
219
+ /** a move map: one `<old> <new>` pair per line, `#` comments and blank lines skipped */
220
+ export function parseMoveMap(text: string): [string, string][] {
221
+ return text.split('\n').map((l) => l.replace(/#.*/, '').trim()).filter(Boolean).map((l, i) => {
222
+ const parts = l.split(/\s+/)
223
+ if (parts.length !== 2) throw new Error(`move map line ${i + 1}: want "<old> <new>", got "${l}"`)
224
+ return [parts[0]!, parts[1]!]
225
+ })
226
+ }
227
+
228
+ /** many pages in one run, in map order: each move sweeps the tree the previous
229
+ * one left, and `mv:after` runs once at the end. A dry run shows each move
230
+ * against the CURRENT tree, so a later pair that depends on an earlier one
231
+ * only reports true once applied. Stops at the first failure. */
232
+ export function movePages(root: string, pairs: [string, string][], io: MvIo, o: MvOpts = {}): number {
233
+ if (o.commit === true) { io.printErr('FAIL: a move map applies with --write, then you commit what you own'); return 1 }
234
+ for (const [from, to] of pairs) {
235
+ const code = movePage(root, from, to, io, { ...o, after: false })
236
+ if (code !== 0) return code
237
+ }
238
+ if (o.write === true && !runAfter(root)) { io.printErr('FAIL: mv:after failed, fix before committing'); return 1 }
239
+ io.print(`ok: ${pairs.length} move(s)${o.write === true ? '' : ' (dry run)'}`)
240
+ return 0
241
+ }
@@ -1,4 +1,4 @@
1
- // a repo page's request sent on to the repo's process and streamed back (wiki build/shipkit/project-pages.md, The
1
+ // a repo page's request sent on to the repo's process and streamed back (wiki tools/shipkit/project-pages.md, The
2
2
  // proxy): the daemon's hub route and the web's direct path both go through here. Light on purpose: the web imports it
3
3
  /** what names the browser or this hop: the page's process sees a plain local client */
4
4
  const DROP = new Set(['host', 'origin', 'referer', 'sec-fetch-site', 'sec-fetch-mode', 'sec-fetch-dest', 'connection', 'keep-alive', 'content-length'])