rvlib-shipkit 2.11.0 → 2.13.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 (298) hide show
  1. package/CHANGELOG.md +56 -12
  2. package/README.md +1 -1
  3. package/package.json +4 -2
  4. package/src/agent-time/store.ts +2 -2
  5. package/src/check.ts +1 -1
  6. package/src/checks/SK001-package-json-shape.check.ts +4 -0
  7. package/src/checks/SK003-claude-md-shape.check.ts +1 -1
  8. package/src/checks/SK004-gitignore-policy.check.ts +27 -2
  9. package/src/checks/SK005-rvlib-versions.check.ts +1 -1
  10. package/src/checks/SK008-reviewer-agent.check.ts +2 -2
  11. package/src/checks/SK012-config-barrel-import.check.ts +1 -1
  12. package/src/checks/SK015-nested-repo.check.ts +1 -1
  13. package/src/checks/SK035-public-clean.check.ts +46 -0
  14. package/src/checks/SK036-draft-media-size.check.ts +28 -0
  15. package/src/cli/cmd_Backup.ts +152 -0
  16. package/src/cli/cmd_Ci.ts +8 -11
  17. package/src/cli/cmd_Drill.ts +145 -0
  18. package/src/cli/cmd_Home.ts +50 -3
  19. package/src/cli/cmd_Media.ts +96 -5
  20. package/src/cli/cmd_Review.ts +8 -2
  21. package/src/cli/cmd_Shot.ts +5 -2
  22. package/src/cli/cmd_Smoke.ts +4 -1
  23. package/src/cli/cmd_Social.ts +226 -0
  24. package/src/cli/cmd_Start.ts +1 -1
  25. package/src/cli/cmd_Time.ts +1 -1
  26. package/src/cli/cmd_Trailer.ts +9 -2
  27. package/src/cli/cmd_Veille.ts +173 -0
  28. package/src/cli/family-pages.ts +3 -0
  29. package/src/cli/registry.ts +13 -2
  30. package/src/cli.ts +5 -2
  31. package/src/collections/actions.ts +1 -49
  32. package/src/collections/checks.ts +2 -1
  33. package/src/collections/collection-types.ts +11 -2
  34. package/src/collections/providers.ts +4 -4
  35. package/src/collections/review.ts +2 -1
  36. package/src/collections/tests.ts +19 -8
  37. package/src/contracts/apply-contracts.ts +1 -3
  38. package/src/contracts/contract-manifests.ts +2 -3
  39. package/src/contracts/contract-types.ts +0 -1
  40. package/src/contracts/contracts-engine.ts +0 -3
  41. package/src/core/app-icon.ts +9 -3
  42. package/src/core/bun-builtins.ts +2 -2
  43. package/src/core/discover-checks.ts +37 -5
  44. package/src/core/fix-scope.ts +4 -2
  45. package/src/core/floor-resolve.ts +68 -48
  46. package/src/core/floor.ts +9 -0
  47. package/src/core/git-root.ts +24 -0
  48. package/src/core/last-good.ts +3 -1
  49. package/src/core/layout.ts +8 -0
  50. package/src/core/log-stamp.ts +36 -0
  51. package/src/core/loop-watch.ts +93 -0
  52. package/src/core/machine-link.ts +134 -0
  53. package/src/core/memory-watch.ts +41 -0
  54. package/src/core/one-way-in-policy.ts +27 -19
  55. package/src/core/run-ci.ts +6 -8
  56. package/src/core/run-fixers.ts +9 -9
  57. package/src/core/slots.ts +21 -0
  58. package/src/core/tree-rev.ts +60 -0
  59. package/src/core/unit-files.ts +42 -0
  60. package/src/drill/render.ts +140 -0
  61. package/src/drill/run.ts +269 -0
  62. package/src/fleet/scan-fleet.ts +6 -5
  63. package/src/home/daemon-jobs.ts +201 -0
  64. package/src/home/global-context.ts +34 -1
  65. package/src/home/home-routes.ts +22 -15
  66. package/src/home/hubs.ts +10 -3
  67. package/src/home/inbox-shape.ts +61 -6
  68. package/src/home/inbox.ts +75 -4
  69. package/src/home/lib-watch.ts +10 -3
  70. package/src/home/machine-stores.ts +15 -29
  71. package/src/home/run-daemon.ts +15 -18
  72. package/src/home/run-pm.ts +2 -0
  73. package/src/home/serve-daemon.ts +4 -3
  74. package/src/home/serve-web.ts +110 -1
  75. package/src/hooks/commit-message.ts +28 -19
  76. package/src/hooks/leak-guard.ts +10 -3
  77. package/src/hooks/run-hooks.ts +2 -6
  78. package/src/identities/identities.ts +334 -0
  79. package/src/identities/machine-route.ts +126 -0
  80. package/src/identities/machine.ts +62 -0
  81. package/src/init-repo.ts +1 -1
  82. package/src/ledger/check-stats.ts +10 -9
  83. package/src/ledger/gate-checks.ts +32 -1
  84. package/src/ledger/record-kept.ts +112 -0
  85. package/src/ledger/repo-view.ts +10 -0
  86. package/src/ledger/run-log.ts +17 -12
  87. package/src/ledger/run-timeline.ts +8 -4
  88. package/src/ledger/store.ts +7 -0
  89. package/src/ledger/suite-log.ts +17 -13
  90. package/src/media-kinds.ts +9 -1
  91. package/src/media-store/backup/daemon.ts +73 -0
  92. package/src/media-store/backup/keys.ts +25 -0
  93. package/src/media-store/backup/manifest.ts +193 -0
  94. package/src/media-store/backup/restore.ts +192 -0
  95. package/src/media-store/backup/run.ts +278 -0
  96. package/src/media-store/backup/secret.ts +86 -0
  97. package/src/media-store/backup/snapshot.ts +64 -0
  98. package/src/media-store/backup/sources.ts +199 -0
  99. package/src/media-store/content.ts +11 -1
  100. package/src/media-store/daemon.ts +56 -70
  101. package/src/media-store/hand.ts +58 -0
  102. package/src/media-store/put.ts +122 -0
  103. package/src/media-store/space.ts +73 -11
  104. package/src/pages/forward.ts +35 -0
  105. package/src/pages/frame-client.ts +118 -0
  106. package/src/pages/routes.ts +29 -0
  107. package/src/pages/unit.ts +92 -0
  108. package/src/plan/planner.ts +12 -0
  109. package/src/plan/repo-source.ts +19 -5
  110. package/src/reflect/transcript.ts +35 -10
  111. package/src/release/public-clean.ts +301 -0
  112. package/src/release/published-here.ts +22 -0
  113. package/src/release/run-bump.ts +2 -1
  114. package/src/release/run-release.ts +4 -1
  115. package/src/repo-config.ts +53 -2
  116. package/src/review/http.ts +16 -2
  117. package/src/review/media-kind.ts +3 -3
  118. package/src/review/media-read.ts +3 -3
  119. package/src/review/model.ts +24 -5
  120. package/src/review/notes.ts +77 -0
  121. package/src/review/project.ts +6 -38
  122. package/src/review/routes.ts +8 -13
  123. package/src/review/store.ts +46 -4
  124. package/src/review/trailer-media.ts +24 -3
  125. package/src/review/trailer-shots.ts +106 -0
  126. package/src/review/unit.ts +1 -1
  127. package/src/scaffold/files/agent-handoff.md +3 -0
  128. package/src/scaffold/files/agent-index.md +4 -12
  129. package/src/scaffold/project-scaffold.ts +5 -4
  130. package/src/serve/embed.ts +1 -1
  131. package/src/serve/hub-app/col-card.tsx +3 -17
  132. package/src/serve/hub-app/col-tables-view.tsx +2 -1
  133. package/src/serve/hub-app/cols-svc.ts +12 -14
  134. package/src/serve/hub-app/dock-st.ts +4 -2
  135. package/src/serve/hub-app/dock-view.tsx +2 -0
  136. package/src/serve/hub-app/frames-st.ts +35 -0
  137. package/src/serve/hub-app/hash-route.ts +64 -1
  138. package/src/serve/hub-app/home-st.ts +31 -7
  139. package/src/serve/hub-app/home-strip.css +9 -1
  140. package/src/serve/hub-app/home-strip.tsx +7 -6
  141. package/src/serve/hub-app/home.html +5 -0
  142. package/src/serve/hub-app/hub-app.tsx +49 -5
  143. package/src/serve/hub-app/hub.css +29 -11
  144. package/src/serve/hub-app/icons.tsx +16 -1
  145. package/src/serve/hub-app/identities-st.ts +210 -0
  146. package/src/serve/hub-app/identities-view.tsx +352 -0
  147. package/src/serve/hub-app/identities.css +48 -0
  148. package/src/serve/hub-app/identity-address.ts +52 -0
  149. package/src/serve/hub-app/inbox-st.ts +59 -6
  150. package/src/serve/hub-app/inbox-view.tsx +48 -6
  151. package/src/serve/hub-app/inbox.css +12 -1
  152. package/src/serve/hub-app/index.html +3 -0
  153. package/src/serve/hub-app/keys.ts +10 -2
  154. package/src/serve/hub-app/list-walk.ts +89 -0
  155. package/src/serve/hub-app/machine-st.ts +12 -0
  156. package/src/serve/hub-app/media-view.tsx +2 -1
  157. package/src/serve/hub-app/pages-frames.tsx +134 -0
  158. package/src/serve/hub-app/pages-svc.ts +111 -0
  159. package/src/serve/hub-app/palette-st.ts +18 -3
  160. package/src/serve/hub-app/palette-view.tsx +9 -2
  161. package/src/serve/hub-app/planned-view.tsx +2 -1
  162. package/src/serve/hub-app/project-list.css +18 -14
  163. package/src/serve/hub-app/project-list.tsx +88 -49
  164. package/src/serve/hub-app/projects-svc.ts +33 -3
  165. package/src/serve/hub-app/repo-sections.ts +19 -2
  166. package/src/serve/hub-app/repo-st.ts +75 -19
  167. package/src/serve/hub-app/review/review-cells.tsx +3 -3
  168. package/src/serve/hub-app/review/review-kit.ts +30 -7
  169. package/src/serve/hub-app/review/review-page.tsx +1 -1
  170. package/src/serve/hub-app/review/review-st.ts +33 -11
  171. package/src/serve/hub-app/review/review-thread.tsx +11 -9
  172. package/src/serve/hub-app/review/review-views.tsx +84 -19
  173. package/src/serve/hub-app/review/thread-st.ts +1 -10
  174. package/src/serve/hub-app/review/trailer-page.tsx +2 -1
  175. package/src/serve/hub-app/review.css +17 -8
  176. package/src/serve/hub-app/site/site-part.tsx +173 -0
  177. package/src/serve/hub-app/site/site-st.ts +157 -0
  178. package/src/serve/hub-app/site.css +35 -0
  179. package/src/serve/hub-app/social/calendar.tsx +182 -0
  180. package/src/serve/hub-app/social/comms-page.tsx +306 -0
  181. package/src/serve/hub-app/social/kit.tsx +244 -0
  182. package/src/serve/hub-app/social/post-card.tsx +456 -0
  183. package/src/serve/hub-app/social/problems.tsx +60 -0
  184. package/src/serve/hub-app/social/social-model.ts +154 -0
  185. package/src/serve/hub-app/social/social-page.tsx +674 -0
  186. package/src/serve/hub-app/social/social-st.ts +986 -0
  187. package/src/serve/hub-app/social.css +289 -0
  188. package/src/serve/hub-app/stores/stores-page.tsx +311 -0
  189. package/src/serve/hub-app/stores/stores-st.ts +286 -0
  190. package/src/serve/hub-app/stores.css +54 -0
  191. package/src/serve/hub-app/test-view.tsx +9 -2
  192. package/src/serve/hub-app/tests-svc.ts +16 -1
  193. package/src/serve/hub-app/timeline-geometry.ts +1 -1
  194. package/src/serve/hub-app/timeline-view.tsx +3 -2
  195. package/src/serve/hub-app/tree-build.ts +6 -0
  196. package/src/serve/hub-app/tree-row.tsx +27 -4
  197. package/src/serve/hub-app/tree-svc.ts +18 -49
  198. package/src/serve/hub-app/veille/veille-page.tsx +514 -0
  199. package/src/serve/hub-app/veille/veille-st.ts +443 -0
  200. package/src/serve/hub-app/veille.css +84 -0
  201. package/src/serve/hub-runtime.ts +14 -9
  202. package/src/serve/project-gutter-route.ts +44 -12
  203. package/src/serve/resources-wire.ts +48 -0
  204. package/src/serve/run-lanes.ts +7 -4
  205. package/src/serve/same-origin.ts +1 -1
  206. package/src/serve/serve-hub.ts +27 -18
  207. package/src/serve/tracked-watch.ts +24 -3
  208. package/src/serve/warm-cell.ts +5 -1
  209. package/src/shipkit-files.ts +15 -4
  210. package/src/shipkit.ts +0 -1
  211. package/src/shot/box.ts +162 -0
  212. package/src/shot/browser-slot.ts +62 -0
  213. package/src/shot/client.ts +43 -7
  214. package/src/shot/clip-encoder.ts +93 -12
  215. package/src/shot/film-box.ts +188 -0
  216. package/src/shot/shooter.ts +50 -15
  217. package/src/shot/shot-ask.ts +10 -2
  218. package/src/shot/stepped-clip.ts +5 -4
  219. package/src/site/desk.ts +242 -0
  220. package/src/site/routes.ts +66 -0
  221. package/src/site/unit.ts +62 -0
  222. package/src/social/brands.ts +22 -0
  223. package/src/social/compose.ts +97 -0
  224. package/src/social/desk-index.ts +123 -0
  225. package/src/social/desk-wire.ts +64 -0
  226. package/src/social/drafts.ts +183 -0
  227. package/src/social/house.ts +24 -0
  228. package/src/social/load.ts +319 -0
  229. package/src/social/md.ts +70 -0
  230. package/src/social/media-facts.ts +53 -0
  231. package/src/social/media-kind.ts +189 -0
  232. package/src/social/media-limit.ts +42 -0
  233. package/src/social/media-of.ts +30 -0
  234. package/src/social/migrate.ts +123 -0
  235. package/src/social/open.ts +17 -0
  236. package/src/social/post-url.ts +158 -0
  237. package/src/social/presence.ts +332 -0
  238. package/src/social/public-read.ts +53 -0
  239. package/src/social/publish/bluesky.ts +168 -0
  240. package/src/social/publish/discord.ts +76 -0
  241. package/src/social/publish/index.ts +24 -0
  242. package/src/social/publish/secret.ts +13 -0
  243. package/src/social/push.ts +31 -0
  244. package/src/social/richtext.ts +37 -0
  245. package/src/social/routes.ts +180 -0
  246. package/src/social/stats.ts +134 -0
  247. package/src/social/text.ts +267 -0
  248. package/src/social/tracker-route.ts +39 -0
  249. package/src/social/tracker.ts +255 -0
  250. package/src/social/unit.ts +53 -0
  251. package/src/social/writes.ts +130 -0
  252. package/src/start-repo.ts +14 -9
  253. package/src/stores/collection.ts +27 -0
  254. package/src/stores/desk.ts +336 -0
  255. package/src/stores/model.ts +187 -0
  256. package/src/stores/routes.ts +126 -0
  257. package/src/stores/unit.ts +57 -0
  258. package/src/suite/calibrate.ts +127 -0
  259. package/src/suite/core-counters.ts +91 -0
  260. package/src/suite/judge-suites.ts +94 -34
  261. package/src/suite/suite-cli.ts +44 -10
  262. package/src/suite/suite-cpu-preload.ts +34 -9
  263. package/src/trailer/adapter.ts +4 -0
  264. package/src/trailer/build.ts +42 -11
  265. package/src/trailer/ffmpeg.ts +11 -0
  266. package/src/trailer/footage.ts +30 -13
  267. package/src/trailer/grammar.ts +18 -2
  268. package/src/trailer/graph.ts +28 -6
  269. package/src/trailer/passage.ts +21 -6
  270. package/src/trailer/plan.ts +74 -3
  271. package/src/trailer/shelf.ts +16 -0
  272. package/src/trailer/stitch.ts +67 -26
  273. package/src/trailer/url.ts +1 -1
  274. package/src/trailer/versions.ts +24 -0
  275. package/src/ts/gate-typecheck.ts +32 -0
  276. package/src/ts/typecheck-cli.ts +9 -11
  277. package/src/tui/tui-app.tsx +0 -1
  278. package/src/veille/asks.ts +155 -0
  279. package/src/veille/auto.ts +31 -0
  280. package/src/veille/batch.ts +27 -0
  281. package/src/veille/chrome.ts +127 -0
  282. package/src/veille/collection.ts +28 -0
  283. package/src/veille/desk.ts +242 -0
  284. package/src/veille/identity.ts +80 -0
  285. package/src/veille/import.ts +68 -0
  286. package/src/veille/log.ts +183 -0
  287. package/src/veille/platforms.ts +118 -0
  288. package/src/veille/reads.ts +66 -0
  289. package/src/veille/replied.ts +110 -0
  290. package/src/veille/routes.ts +185 -0
  291. package/src/veille/service.ts +81 -0
  292. package/src/veille/watch.ts +116 -0
  293. package/src/veille/worth.ts +46 -0
  294. package/src/wiki/scan-md.ts +18 -0
  295. package/src/collections/posts.ts +0 -142
  296. package/src/contracts/manifests/social.contract.ts +0 -20
  297. package/src/scaffold/files/agent-coding.md +0 -35
  298. package/src/ts/typecheck-cache.ts +0 -11
@@ -12,6 +12,7 @@ import { existsSync, readFileSync, realpathSync, statSync, watch, type FSWatcher
12
12
  import { dirname, extname, join, relative, resolve } from 'path'
13
13
  import { copyStamp, heldNow, homeLib, LAST_GOOD_ENV, lastGood, OWN_LIB, setHeld, takeLastGood } from '../core/last-good.ts'
14
14
  import { LIB_VERSION } from '../core/lib-version.ts'
15
+ import { loopWatch } from '../core/loop-watch.ts'
15
16
  import { bootEntries, probeLoad, TreeProbe } from '../core/load-probe.ts'
16
17
  import { reexecBlocker, reexecSelf } from '../core/reexec.ts'
17
18
  import { StaleRestart } from '../serve/stale-restart.ts'
@@ -57,6 +58,10 @@ export function libGraph(entry: string, o: { bundles?: boolean } = {}): Set<stri
57
58
  return out
58
59
  }
59
60
 
61
+ /** a burst of saves is one change once no write came for this long: an agent saves file after file, and each
62
+ * restart rescans every house repo */
63
+ export const SETTLE_MS = 5_000
64
+
60
65
  export class LibWatch {
61
66
  private w: FSWatcher | null = null
62
67
  private last: { file: string; at: number } | null = null
@@ -68,9 +73,9 @@ export class LibWatch {
68
73
  private settleMs: number
69
74
 
70
75
  /** `only`: absolute paths; an edit of any other file is not a change */
71
- constructor(private root: string, o: { settleMs?: number; now?: () => number; only?: Set<string> } = {}) {
76
+ constructor(root: string, o: { settleMs?: number; now?: () => number; only?: Set<string> } = {}) {
72
77
  this.now = o.now ?? Date.now
73
- this.settleMs = o.settleMs ?? 1_000
78
+ this.settleMs = o.settleMs ?? SETTLE_MS
74
79
  // an APFS clone of the tree (the last good copy, a scratch checkout)
75
80
  // fires a change on every source file it reads: only a moved mtime,
76
81
  // or a file gone, is a write
@@ -207,13 +212,15 @@ export function reloadOnOwnCode(o: {
207
212
  const keeper = o.keep === true && !onCopy
208
213
  ? setInterval(() => {
209
214
  if (lib.seq === kept || !lib.settled() || Date.now() - Math.max(lastGood(tree)?.at ?? 0, triedAt) < KEEP_EVERY_MS) return
215
+ const probed = loopWatch.span('load probe')
210
216
  const v = probe.loads()
217
+ probed()
211
218
  if (v === 'pending') return
212
219
  if (v !== 'ok') return hold(v)
213
220
  hold(null)
214
221
  kept = lib.seq
215
222
  triedAt = Date.now()
216
- void takeLastGood(tree).catch((e: Error) => o.io.printErr(`WARN the last good copy of the shipkit source could not be kept: ${e.message}`))
223
+ void loopWatch.spanned('last good copy', () => takeLastGood(tree)).catch((e: Error) => o.io.printErr(`WARN the last good copy of the shipkit source could not be kept: ${e.message}`))
217
224
  }, 2_000)
218
225
  : null
219
226
  function stop(): void {
@@ -1,10 +1,12 @@
1
1
  // the machine's own stores and their caps (core/retention.ts owns the model):
2
2
  // every log under the home dir, and the gui window's Chrome profile. And the
3
- // daemon's timer that sweeps every store, the repos' and these.
3
+ // daemon's retention job that sweeps every store, the repos' and these, in a
4
+ // child process (daemon-jobs.ts).
4
5
  import { existsSync, lstatSync, readdirSync, rmSync, statSync } from 'fs'
5
6
  import { join } from 'path'
6
7
  import { repoStores, sweepStores, walkUse, type Store } from '../core/retention.ts'
7
8
  import { capLog, LOG_MAX_BYTES } from './supervise.ts'
9
+ import { machineSet } from '../core/machine-db.ts'
8
10
 
9
11
  /** a log nothing wrote for this long belongs to a process that is gone (a
10
12
  * repo removed, a resource dropped) */
@@ -85,33 +87,17 @@ export function machineStores(dir: string): Store[] {
85
87
 
86
88
  /** how often the daemon sweeps, after the one on boot */
87
89
  export const SWEEP_EVERY_MS = 60 * 60 * 1000
88
- /** the boot sweep waits this long, so loading the repos goes first */
89
- export const BOOT_SWEEP_DELAY_MS = 10_000
90
-
91
- export type Sweeper = { stop: () => void; once: () => Promise<void> }
92
-
93
- /** the daemon's one retention sweep: every repo it loads, then the machine,
94
- * then `also` (the machine's batched writes), on boot and every hour. A
95
- * store whose sweep throws is one printed line */
96
- export function startSweeps(o: { roots: () => string[]; dir: string; printErr: (l: string) => void; everyMs?: number; bootDelayMs?: number; now?: () => number; also?: (now: number) => void }): Sweeper {
97
- let running = false
98
- const once = async (): Promise<void> => {
99
- if (running) return
100
- running = true
101
- try {
102
- const now = (o.now ?? Date.now)()
103
- for (const root of o.roots()) {
104
- for (const r of await sweepStores(repoStores(root), now)) if (r.error != null) o.printErr(`WARN retention sweep of ${r.id} in ${root} failed: ${r.error}`)
105
- }
106
- for (const r of await sweepStores(machineStores(o.dir), now)) if (r.error != null) o.printErr(`WARN retention sweep of ${r.id} failed: ${r.error}`)
107
- o.also?.(now)
108
- } finally {
109
- running = false
110
- }
90
+ /** when the last sweep ended, in the machine db: the daemon's job sweeps once SWEEP_EVERY_MS passed, a restart
91
+ * included */
92
+ export const SWEPT_AT = 'retention-swept-at'
93
+ /** one sweep of the daemon's retention job, in its child process: every repo, then the machine, then `also`; its
94
+ * end time kept, so the daemon's next look waits SWEEP_EVERY_MS whatever restarts in between */
95
+ export async function sweepTick(o: { roots: string[]; dir: string; printErr: (l: string) => void; now?: () => number; also?: (now: number) => void }): Promise<void> {
96
+ const now = (o.now ?? Date.now)()
97
+ for (const root of o.roots) {
98
+ for (const r of await sweepStores(repoStores(root), now)) if (r.error != null) o.printErr(`WARN retention sweep of ${r.id} in ${root} failed: ${r.error}`)
111
99
  }
112
- const boot = setTimeout(() => void once(), o.bootDelayMs ?? BOOT_SWEEP_DELAY_MS)
113
- const every = setInterval(() => void once(), o.everyMs ?? SWEEP_EVERY_MS)
114
- boot.unref()
115
- every.unref()
116
- return { stop: () => { clearTimeout(boot); clearInterval(every) }, once }
100
+ for (const r of await sweepStores(machineStores(o.dir), now)) if (r.error != null) o.printErr(`WARN retention sweep of ${r.id} failed: ${r.error}`)
101
+ o.also?.(now)
102
+ machineSet(SWEPT_AT, (o.now ?? Date.now)())
117
103
  }
@@ -6,6 +6,8 @@
6
6
  // it runs with no bun watch and an edit of its own code restarts it in place
7
7
  // at once (lib-watch.ts): the new image follows the jobs still running. The
8
8
  // machine resources are pm's.
9
+ import { loopWatch } from '../core/loop-watch.ts'
10
+ import { MemoryWatch } from '../core/memory-watch.ts'
9
11
  import { fileURLToPath } from 'url'
10
12
  import { installOneLib } from '../core/one-lib.ts'
11
13
  import { reclaimPreviousImage } from '../core/instance.ts'
@@ -16,17 +18,15 @@ import { projectGutter } from '../serve/project-gutter-route.ts'
16
18
  import { loadRepoConfig } from '../repo-config.ts'
17
19
  import { ensureIdentity } from '../core/identity.ts'
18
20
  import { homedir } from 'os'
19
- import { daemonPort, homeDir, homePort, homeUp, hubBase, publicHome, WORKER_ENV } from './home-paths.ts'
21
+ import { join } from 'path'
22
+ import { childLog, daemonPort, homeDir, homePort, homeUp, hubBase, publicHome, WORKER_ENV } from './home-paths.ts'
20
23
  import { inboxAddress } from './inbox-shape.ts'
21
24
  import { HomeState } from './home-state.ts'
22
25
  import { Hubs } from './hubs.ts'
23
26
  import { Planner } from '../plan/planner.ts'
24
27
  import { machineCatchUp } from '../plan/catch-up.ts'
25
28
  import { serveDaemon } from './serve-daemon.ts'
26
- import { startSweeps } from './machine-stores.ts'
27
- import { startMediaStore } from '../media-store/daemon.ts'
28
- import { MEDIA_KINDS } from '../media-kinds.ts'
29
- import { landMotherhome } from '../core/motherhome.ts'
29
+ import { startJobs } from './daemon-jobs.ts'
30
30
  import { Widgets } from './widgets.ts'
31
31
 
32
32
  const CLI = fileURLToPath(new URL('../cli.ts', import.meta.url))
@@ -114,25 +114,22 @@ export async function runDaemon(root: string, io: HomeIo, o: { port?: number } =
114
114
  publicHost,
115
115
  })
116
116
  io.print(`daemon → http://127.0.0.1:${home.server.port} (the page: http://localhost:${port})`)
117
- // nothing grows unbound: every store of every repo it loads, and the
118
- // machine's, swept on boot and hourly (core/retention.ts)
119
- const only = onlyRepos()
120
- const sweeps = startSweeps({
121
- roots: () => house.repos.filter((r) => only == null || only.has(r.name)).map((r) => r.path), dir, printErr: io.printErr,
122
- // the rows every gate filed land here, one commit a day at most
123
- also: (now) => { for (const n of landMotherhome({ now })) io.printErr(n) },
124
- })
125
- // every kind's media into the machine index, up to the Space, purged when the owner turned it on
126
- const media = startMediaStore({ roots: () => house.repos.filter((r) => only == null || only.has(r.name)).map((r) => r.path), kinds: MEDIA_KINDS, print: io.print, printErr: io.printErr })
127
- const code = reloadOnOwnCode({ role: 'daemon', entry: fileURLToPath(import.meta.url), busy: () => hubs.busy(), before: () => { sweeps.stop(); media.stop(); home.stop() }, keep: true, io })
117
+ // the retention sweep (nothing grows unbound, core/retention.ts), the media store and the backup of the
118
+ // machine-only state, each a niced child process: never a job's body on this loop (daemon-jobs.ts). A daemon
119
+ // limited to some repos (SHIPKIT_DAEMON_ONLY) is a trial and runs none
120
+ const jobs = onlyRepos() == null ? startJobs({ cli: CLI, cwd: root, dir: join(dir, 'jobs'), log: childLog(dir, 'daemon'), printErr: io.printErr }) : null
121
+ // a job that holds the loop holds every page: each stall is said with the work that overlapped it
122
+ const stalls = loopWatch.start(io.printErr)
123
+ // its memory as a trend: a line only when it moved by a tenth, at most every 10 minutes
124
+ const memory = new MemoryWatch().start(io.print)
125
+ const code = reloadOnOwnCode({ role: 'daemon', entry: fileURLToPath(import.meta.url), busy: () => hubs.busy(), before: () => { stalls(); memory(); jobs?.stop(); home.stop() }, keep: true, io })
128
126
  io.print(` ${house.repos.length} repos, state in ${dir}, reloads on ${code.files} lib files`)
129
127
  for (const sig of ['SIGINT', 'SIGTERM'] as const)
130
128
  process.on(sig, () => {
131
129
  // the repo processes it started keep running: they are their
132
130
  // own process groups, and the next daemon adopts them
133
131
  code.stop()
134
- sweeps.stop()
135
- media.stop()
132
+ jobs?.stop()
136
133
  home.stop()
137
134
  process.exit(0)
138
135
  })
@@ -5,6 +5,7 @@
5
5
  // It never loads the repo config itself (pm-config.ts), and it runs from this
6
6
  // file, never from cli.ts (execPm): cli.ts loads every command, about 170 MB
7
7
  // against pm's own 20.
8
+ import { stampConsole } from '../core/log-stamp.ts'
8
9
  import { fileURLToPath } from 'url'
9
10
  import { daemonPort, homeDir, homePort, homeUp, homeUrl, pmPort, pmUp, WORKER_ENV } from './home-paths.ts'
10
11
  import { reloadOnOwnCode } from './lib-watch.ts'
@@ -171,5 +172,6 @@ export async function runPm(root: string, io: HomeIo, o: { port?: number } = {})
171
172
  if (import.meta.main) {
172
173
  const i = process.argv.indexOf('--port')
173
174
  const port = i < 0 ? undefined : Number(process.argv[i + 1])
175
+ stampConsole()
174
176
  process.exitCode = await runPm(process.cwd(), { print: (l) => console.log(l), printErr: (l) => console.error(l) }, { port })
175
177
  }
@@ -3,19 +3,20 @@
3
3
  // (serve-web.ts) serves the page and proxies here, so a browser only ever
4
4
  // sees the web origin. A terminal client (via-hub.ts, attach.ts) talks here
5
5
  // directly, so a gate never depends on the web.
6
+ import { loopWatch } from '../core/loop-watch.ts'
6
7
  import { homeRoutes, TICK_MS, type HomeDeps } from './home-routes.ts'
7
8
 
8
9
  export function serveDaemon(d: HomeDeps & { daemonPort: number }) {
9
10
  const routes = homeRoutes(d)
10
- const fetch = async (req: Request, srv: Bun.Server<unknown>): Promise<Response> =>
11
- (await routes.handle(req, srv)) ?? new Response('not found', { status: 404 })
11
+ const fetch = (req: Request, srv: Bun.Server<unknown>): Promise<Response> =>
12
+ loopWatch.spanned(`${req.method} ${new URL(req.url).pathname}`, async () => (await routes.handle(req, srv)) ?? new Response('not found', { status: 404 }))
12
13
  const server = Bun.serve({ port: d.daemonPort, hostname: '127.0.0.1', fetch })
13
14
  let stopped = false
14
15
  let running = false
15
16
  const timer = setInterval(() => {
16
17
  if (running || stopped) return
17
18
  running = true
18
- void routes.tick().catch((e) => console.error(`WARN the daemon tick broke: ${(e as Error).message}`)).finally(() => { running = false })
19
+ void loopWatch.spanned('daemon tick', () => routes.tick()).catch((e) => console.error(`WARN the daemon tick broke: ${(e as Error).message}`)).finally(() => { running = false })
19
20
  }, TICK_MS)
20
21
  void routes.tick().catch(() => {})
21
22
  return {
@@ -12,11 +12,12 @@
12
12
  // request reaches it only once its Host is a loopback name or the tailnet name the house declares (serve.publicHost)
13
13
  import { sameOrigin } from '../serve/same-origin.ts'
14
14
  import { hubBase } from './home-paths.ts'
15
+ import { forwardPage, pagePath } from '../pages/forward.ts'
15
16
 
16
17
  /** the page routes: ONE app for the overview, the plan, and the hub page of
17
18
  * each known repo, which moves between them in place (home-st.ts) */
18
19
  export function pageRoutes<T>(names: string[], page: T): Record<string, T> {
19
- const out: Record<string, T> = { '/': page, '/inbox': page, '/planned': page, '/activity': page, '/archived': page, '/insights': page }
20
+ const out: Record<string, T> = { '/': page, '/inbox': page, '/planned': page, '/activity': page, '/archived': page, '/insights': page, '/identities': page }
20
21
  for (const n of names) out[`${hubBase(n)}/`] = page
21
22
  return out
22
23
  }
@@ -52,6 +53,8 @@ export const REPO_ANSWER_MS = 30_000
52
53
  /** how often the web asks the daemon's repo list once it has one, and while it has none */
53
54
  export const LIST_EVERY_MS = 30_000
54
55
  export const LIST_RETRY_MS = 1_000
56
+ /** how long the web keeps a repo's page urls before it asks the daemon again */
57
+ export const PAGE_URLS_MS = 10_000
55
58
 
56
59
  /** the home answers that can wait on git: the activity page's first read of a window, a repo's git page, and the insights page's read of every manifest */
57
60
  export const readsGit = (path: string): boolean => path === '/api/home/activity.json' || path === '/api/home/git.json' || path === '/api/home/insights.json'
@@ -112,6 +115,56 @@ const ZIPS = /^(text\/|application\/(javascript|json)|image\/svg)/
112
115
  /** the gzipped bodies kept, by path and etag: the bundle changes on an edit, not on a request */
113
116
  const ZIP_KEEP = 64
114
117
 
118
+ /** past this wait on the daemon, a GET the web holds a copy of answers that copy, the request still running */
119
+ export const STALE_AFTER_MS = 1_500
120
+ /** the copies kept: by count, and a copy past this size is never kept */
121
+ const LAST_GOOD_MAX = 400
122
+ const LAST_GOOD_BYTES = 2 * 1024 * 1024
123
+
124
+ /** why the web answered its copy: the daemon did not answer at all (a restart), or not yet (a held loop) */
125
+ export type StaleWhy = 'restarting' | 'slow'
126
+
127
+ /** the last good answer of each GET the page reads from the daemon: a JSON answer of status 200, by path, query and
128
+ * encoding, its body as the daemon sent it. A restart of the daemon or a held loop then answers the page from here
129
+ * (wiki build/shipkit/home.md, How it stays up: a restart never blanks the page) */
130
+ export class LastGood {
131
+ private held = new Map<string, { body: Uint8Array<ArrayBuffer>; headers: [string, string][]; at: number }>()
132
+
133
+ /** the key of a request whose answer may be kept, null for any other */
134
+ key(req: Request, url: URL): string | null {
135
+ if (req.method !== 'GET' || streams(url.pathname) || toPm(url.pathname)) return null
136
+ return `${url.pathname}${url.search}|${/\bgzip\b/.test(req.headers.get('accept-encoding') ?? '') ? 'gz' : ''}`
137
+ }
138
+
139
+ has(key: string): boolean {
140
+ return this.held.has(key)
141
+ }
142
+
143
+ /** the daemon's answer, kept when it is a JSON 200 small enough: what the browser gets is the same bytes */
144
+ async keep(key: string, r: Response, headers: Headers): Promise<Response> {
145
+ if (r.status !== 200 || !/^application\/json\b/.test(headers.get('content-type') ?? '')) return new Response(r.body, { status: r.status, statusText: r.statusText, headers })
146
+ const body = new Uint8Array(await r.arrayBuffer())
147
+ if (body.length <= LAST_GOOD_BYTES) {
148
+ this.held.delete(key)
149
+ this.held.set(key, { body, headers: [...headers], at: Date.now() })
150
+ if (this.held.size > LAST_GOOD_MAX) this.held.delete(this.held.keys().next().value!)
151
+ }
152
+ return new Response(body, { status: 200, headers })
153
+ }
154
+
155
+ /** the copy, tagged with why it is served; a 304 when the browser holds it already */
156
+ answer(key: string, req: Request, why: StaleWhy): Response | null {
157
+ const h = this.held.get(key)
158
+ if (h == null) return null
159
+ const headers = new Headers(h.headers)
160
+ headers.set('x-shipkit-daemon', why)
161
+ headers.set('x-shipkit-daemon-at', String(h.at))
162
+ const tag = headers.get('etag')
163
+ if (tag != null && req.headers.get('if-none-match') === tag) return new Response(null, { status: 304, headers })
164
+ return new Response(h.body, { status: 200, headers })
165
+ }
166
+ }
167
+
115
168
  export type WebDeps<T> = {
116
169
  port: number
117
170
  /** the daemon's url, e.g. http://127.0.0.1:4798 */
@@ -126,6 +179,8 @@ export type WebDeps<T> = {
126
179
  listEveryMs?: number
127
180
  /** tailnet names allowed before the daemon names any (a test) */
128
181
  hosts?: string[]
182
+ /** in place of STALE_AFTER_MS (a test) */
183
+ staleAfterMs?: number
129
184
  }
130
185
 
131
186
  /** one browser socket to the page server's hot reload, piped to the same path there */
@@ -141,6 +196,8 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
141
196
  /** every page route, as the page server holds them */
142
197
  let pages = new Set(Object.keys(pageRoutes([], d.page)))
143
198
  const zips = new Map<string, Uint8Array<ArrayBuffer>>()
199
+ const lastGood = new LastGood()
200
+ const inflight = new Map<string, Promise<Response>>()
144
201
  /** the repo names the daemon knows and the tailnet names, or the reason it did not answer */
145
202
  async function names(): Promise<{ repos: string[]; hosts: string[] } | Error> {
146
203
  try {
@@ -153,8 +210,23 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
153
210
  }
154
211
  }
155
212
 
213
+ /** a GET with a copy never waits past STALE_AFTER_MS: past it, or with the daemon down, the copy answers and the
214
+ * request runs on, its answer the next copy */
156
215
  async function proxy(req: Request, url: URL, srv: Bun.Server<Pipe>): Promise<Response> {
157
216
  if (!sameOrigin(req)) return new Response('refused: a request that changes something must come from the home page', { status: 403 })
217
+ const key = lastGood.key(req, url)
218
+ if (key == null || !lastGood.has(key)) return forward(req, url, srv, key)
219
+ // one request a key at a time while the daemon is slow: a poll never piles up behind a held loop
220
+ if (inflight.has(key)) return lastGood.answer(key, req, 'slow') ?? forward(req, url, srv, key)
221
+ const live = forward(req, url, srv, key).finally(() => inflight.delete(key))
222
+ inflight.set(key, live)
223
+ const first = await Promise.race([live, Bun.sleep(d.staleAfterMs ?? STALE_AFTER_MS).then(() => null)])
224
+ if (first != null && first.headers.get('x-shipkit-daemon') !== 'down') return first
225
+ if (first == null) void live.then((r) => r.body?.cancel()).catch(() => {})
226
+ return lastGood.answer(key, req, first == null ? 'slow' : 'restarting') ?? (first ?? live)
227
+ }
228
+
229
+ async function forward(req: Request, url: URL, srv: Bun.Server<Pipe>, key: string | null): Promise<Response> {
158
230
  const headers = new Headers()
159
231
  req.headers.forEach((v, k) => { if (!DROP.has(k)) headers.set(k, v) })
160
232
  // a run or a live stream can stay silent for minutes
@@ -178,6 +250,7 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
178
250
  out.delete('content-length')
179
251
  out.delete('transfer-encoding')
180
252
  out.delete('connection')
253
+ if (key != null) return await lastGood.keep(key, r, out)
181
254
  return new Response(r.body, { status: r.status, statusText: r.statusText, headers: out })
182
255
  } catch (e) {
183
256
  if (timer != null) clearTimeout(timer)
@@ -188,6 +261,31 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
188
261
  }
189
262
  }
190
263
 
264
+ /** each repo's pages, by id: where its process serves it, asked of the daemon and kept a while */
265
+ const pageUrls = new Map<string, { at: number; pages: Map<string, { url: string; process?: string }> }>()
266
+ /** a repo page's request straight to the repo's process, the daemon left out of the path: a busy daemon held a page's
267
+ * html 2.5 s (wiki build/shipkit/project-pages.md, The proxy). null: the daemon answers it (a redirect, an unknown page) */
268
+ async function toPageProcess(req: Request, repo: string, rest: string, srv: Bun.Server<Pipe>): Promise<Response | null> {
269
+ const at = pagePath(rest)
270
+ if (at == null || at.rest === null) return null
271
+ let known = pageUrls.get(repo)
272
+ if (known == null || Date.now() - known.at > PAGE_URLS_MS) {
273
+ try {
274
+ const r = await fetch(`${d.daemon}${hubBase(repo)}/api/pages.json`, { signal: AbortSignal.timeout(3_000) })
275
+ const j = (await r.json()) as { pages: { id: string; url: string; process?: string }[] }
276
+ known = { at: Date.now(), pages: new Map(j.pages.map((p) => [p.id, { url: p.url, ...(p.process ? { process: p.process } : {}) }])) }
277
+ pageUrls.set(repo, known)
278
+ } catch {
279
+ // the daemon restarts: the list it gave last still says where the page process serves
280
+ if (known == null) return null
281
+ }
282
+ }
283
+ const p = known.pages.get(at.id)
284
+ if (p == null) return null
285
+ if (!sameOrigin(req)) return new Response('refused: a request that changes something must come from the home page', { status: 403 })
286
+ return forwardPage(req, `${p.url}${at.rest}`, at.id, p.process, srv)
287
+ }
288
+
191
289
  // the page and its bundle, served by Bun's dev server on a loopback port of its own: it bundles the page, serves
192
290
  // its files under /_bun/ and drives the page's hot reload over /_bun/hmr
193
291
  const notFound = (): Response => new Response('not found: the home page is at /', { status: 404 })
@@ -212,6 +310,12 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
212
310
  return new HTMLRewriter().on('head', { element: (e) => { e.append(APP_HEAD, { html: true }) } }).transform(page)
213
311
  }
214
312
  const etag = out.get('etag')
313
+ // the page server answers 200 to a tag the browser holds: the bundle (3 MB) is then a 304 here
314
+ if (r.status === 200 && etag != null && req.headers.get('if-none-match') === etag) {
315
+ await r.body?.cancel()
316
+ return new Response(null, { status: 304, headers: { etag, 'cache-control': 'no-cache' } })
317
+ }
318
+ if (etag != null) out.set('cache-control', 'no-cache')
215
319
  if (r.status !== 200 || etag == null || !ZIPS.test(type) || !/\bgzip\b/.test(req.headers.get('accept-encoding') ?? '')) return new Response(r.body, { status: r.status, headers: out })
216
320
  const key = `${url.pathname}${url.search}|${etag}`
217
321
  let zipped = zips.get(key)
@@ -233,6 +337,11 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
233
337
  if (path === '/_bun/hmr' && req.headers.get('upgrade')?.toLowerCase() === 'websocket')
234
338
  return srv.upgrade(req, { data: { path: `${path}${url.search}`, up: null, queue: [] } }) ? undefined : new Response('the hot reload socket did not open', { status: 400 })
235
339
  if (path === '/manifest.webmanifest') return Response.json(MANIFEST, { headers: { 'content-type': 'application/manifest+json', 'cache-control': 'no-cache' } })
340
+ const page = /^\/r\/([^/]+)(\/page\/.+)$/.exec(path)
341
+ if (page != null) {
342
+ const direct = await toPageProcess(req, decodeURIComponent(page[1]!), page[2]!, srv)
343
+ if (direct != null) return direct
344
+ }
236
345
  if (proxied(path)) return proxy(req, url, srv)
237
346
  if (pages.has(path) || path.startsWith('/_bun/')) return toPage(req, url)
238
347
  const bare = /^\/r\/([^/]+)$/.exec(path)
@@ -1,35 +1,44 @@
1
1
  // the commit-message predicate of the commit-msg hook, which blocks at write
2
2
  // time. mechanical text rules only, so this stays publishable.
3
+ //
4
+ // an inline " - " in a commit body is math or a key name ((1 - s), "+ and -")
5
+ // far more often than a separator, so a body blocks only the em dash (the
6
+ // tell) and an en dash outside a number range, and the subject " - " too.
7
+ // an accented proper noun is a name, not a language choice, so French needs
8
+ // two signals on one line.
3
9
 
4
10
  export type OffenseKind = 'dash' | 'language'
5
11
  export type Offense = { line: number; text: string; kind: OffenseKind; why: string }
6
12
 
7
- /** git surfaces are English, always (identity/writing-voice.md). cheap French
8
- * detector: an accented letter, or two distinct French function words on one
9
- * line. quoted spans are exempt: they carry product copy under discussion
10
- * ("Modification refusée"), not the message's own voice. single quotes stay
11
- * in (they are French apostrophes: stripping l'écran would hide the French).
12
- * `languageAllow` (repo.config hooks) exempts listed words, for proper nouns
13
- * that carry accents without being a language choice. */
13
+ /** quoted spans carry product copy or code under discussion ("Modification
14
+ * refusée", `a - b`), not the message's own voice. single quotes stay in
15
+ * (they are French apostrophes: stripping l'écran would hide the French). */
14
16
  const QUOTED_SPANS = /`[^`\n]*`|"[^"\n]*"|“[^”\n]*”|«[^»\n]*»/g
15
- const FRENCH_ACCENTS = /[àâçéèêëîïôùûœÀÂÇÉÈÊËÎÏÔÙÛŒ]/
17
+ const EM_DASH = /—/
18
+ /** an en dash between digits is a range (⌥1–6, 2026–2027), not punctuation */
19
+ const EN_DASH_PUNCT = /(?<!\d\s?)–|–(?!\s?\d)/
20
+ const ACCENTED_WORDS = /[\p{L}'’]*[àâçéèêëîïôùûœÀÂÇÉÈÊËÎÏÔÙÛŒ][\p{L}'’]*/gu
21
+ // unicode boundaries: with \b an accent is a boundary, so Hélène would hide "ne"
16
22
  const FRENCH_STOPWORDS =
17
- /\b(?:le|la|les|un|une|des|du|au|aux|et|est|sont|avec|pour|dans|sur|pas|que|qui|ne|se|ce|cette|ces|chaque|tout|toute|tous|toutes|jamais|toujours|mais|donc|sans|sous|vers|chez|depuis|encore|aussi|devient|deviennent|nouvelle|ancienne)\b/gi
23
+ /(?<!\p{L})(?:le|la|les|un|une|des|du|au|aux|et|est|sont|avec|pour|dans|sur|pas|que|qui|ne|se|ce|cette|ces|chaque|tout|toute|tous|toutes|jamais|toujours|mais|donc|sans|sous|vers|chez|depuis|encore|aussi|devient|deviennent|nouvelle|ancienne)(?!\p{L})/giu
18
24
 
19
25
  const escapeRe = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
20
26
 
27
+ /** French = two distinct signals on one line: French function words and
28
+ * accented words. one accented name (Zoé, Hélène) or one stray "et" is not a
29
+ * language. `languageAllow` (repo.config hooks) drops listed words first. */
21
30
  export function frenchHits(line: string, languageAllow: string[] = []): boolean {
22
31
  let prose = line.replace(QUOTED_SPANS, ' ')
23
32
  for (const word of languageAllow) prose = prose.replace(new RegExp(`(?:^|(?<=[^\\p{L}]))${escapeRe(word)}(?:'s)?(?=$|[^\\p{L}])`, 'giu'), ' ')
24
- if (FRENCH_ACCENTS.test(prose)) return true
25
- const words = new Set<string>()
33
+ const signals = new Set<string>()
34
+ for (const m of prose.matchAll(ACCENTED_WORDS)) signals.add(m[0].toLowerCase().replace(/['’]s$/, ''))
26
35
  // an ALL-CAPS token is an acronym (UN, EST, CE), not a French word
27
36
  for (const m of prose.matchAll(FRENCH_STOPWORDS)) {
28
37
  const w = m[0]
29
38
  if (w.length > 1 && w === w.toUpperCase()) continue
30
- words.add(w.toLowerCase())
39
+ signals.add(w.toLowerCase())
31
40
  }
32
- return words.size >= 2
41
+ return signals.size >= 2
33
42
  }
34
43
 
35
44
  /** everything below git's scissors line is the verbose-mode diff, which git
@@ -41,18 +50,18 @@ export function stripNonMessage(message: string): string {
41
50
 
42
51
  /** offenses in ONE commit message (or one commit body from `git log`).
43
52
  * `#` comment lines never land in the message and are ignored; a `Revert "…"`
44
- * title quotes the reverted subject verbatim and is exempt; a line-start
45
- * `- ` bullet is a list marker, not punctuation. */
53
+ * title quotes the reverted subject verbatim and is exempt. */
46
54
  export function commitMessageOffenses(message: string, opts?: { languageAllow?: string[] }): Offense[] {
47
55
  const offenses: Offense[] = []
48
56
  stripNonMessage(message).split('\n').forEach((raw, i) => {
49
57
  if (raw.startsWith('#')) return
50
58
  if (i === 0 && /^Revert "/.test(raw)) return
51
- if (/[—–]/.test(raw))
59
+ const prose = raw.replace(QUOTED_SPANS, ' ')
60
+ if (EM_DASH.test(prose) || EN_DASH_PUNCT.test(prose))
52
61
  offenses.push({ line: i + 1, text: raw, kind: 'dash', why: 'em/en dash: use a comma, a period, parentheses, or a new sentence' })
53
- const body = raw.replace(/^\s*[-*] /, '')
54
- if (body.includes(' - '))
55
- offenses.push({ line: i + 1, text: raw, kind: 'dash', why: 'inline " - " separator: same fix' })
62
+ // the subject is a title, where " - " is a separator and never math
63
+ else if (i === 0 && prose.includes(' - '))
64
+ offenses.push({ line: i + 1, text: raw, kind: 'dash', why: 'inline " - " separator in the subject: use a comma or a colon' })
56
65
  if (frenchHits(raw, opts?.languageAllow))
57
66
  offenses.push({ line: i + 1, text: raw, kind: 'language', why: 'French: git surfaces are English, always (identity/writing-voice.md); quote product copy in "…" or `…` to exempt it' })
58
67
  })
@@ -84,6 +84,10 @@ const escapeRegex = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$
84
84
  * or `desk-lamp-...` is a word that ends in `sk`, never a key */
85
85
  export const SK_KEY_ROW = 're:(?<![A-Za-z0-9_-])sk-[A-Za-z0-9_-]{20,}'
86
86
 
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) */
89
+ 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
+
87
91
  /** rows the hooks seeded before their shape was fixed, read as the fixed
88
92
  * shape. Their id stays the seeded row, so a waiver written against its
89
93
  * fingerprint keeps working */
@@ -132,15 +136,18 @@ const substringRegex = (s: string): RegExp => {
132
136
  }
133
137
 
134
138
  /** every occurrence of every pattern, keyed by the id a hit reports. */
135
- function occurrences(haystack: string, p: ParsedPatterns): Map<string, Span[]> {
139
+ export function occurrences(haystack: string, p: ParsedPatterns): Map<string, Span[]> {
136
140
  const found = new Map<string, Span[]>()
137
141
  const push = (id: string, span: Span): void => {
138
142
  const prev = found.get(id)
139
143
  if (prev == null) found.set(id, [span])
140
144
  else prev.push(span)
141
145
  }
142
- for (const s of p.substrings) for (const m of haystack.matchAll(substringRegex(s))) push(s, [m.index, m.index + m[0].length])
143
- for (const w of p.words) for (const m of haystack.matchAll(w.re)) push(w.word, [m.index, m.index + m[0].length])
146
+ // a cheap prefilter before each regex: a row whose lowercase text the lowercased haystack lacks cannot match, so a
147
+ // scan over a whole tarball pays one regex per row that is there, not one per row
148
+ const lower = haystack.toLowerCase()
149
+ for (const s of p.substrings) if (lower.includes(s)) for (const m of haystack.matchAll(substringRegex(s))) push(s, [m.index, m.index + m[0].length])
150
+ for (const w of p.words) if (lower.includes(w.word)) for (const m of haystack.matchAll(w.re)) push(w.word, [m.index, m.index + m[0].length])
144
151
  for (const r of p.regexes) {
145
152
  const g = new RegExp(r.re.source, r.re.flags.includes('g') ? r.re.flags : r.re.flags + 'g')
146
153
  for (const m of haystack.matchAll(g)) push(r.row, [m.index, m.index + m[0].length])
@@ -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, SK_KEY_ROW, type LeakAllowEntry, type LeakHit, type LeakWaiver } from './leak-guard.ts'
11
+ import { globalAllowFile, globalKeywordFile, maskPattern, patternFingerprint, runLeakGuard, SECRET_ROWS, 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'
@@ -161,11 +161,7 @@ export const KEYWORD_STARTER = `# banned-keywords — the leak guard greps every
161
161
  # re:<regex>. add repo-specific names here; machine-wide private names go in
162
162
  # ~/.shipkit/private/banned-keywords.txt, read automatically alongside this file.
163
163
  # this file is gitignored on purpose: the list itself is private.
164
- re:-----BEGIN [A-Z ]*PRIVATE KEY-----
165
- re:AKIA[0-9A-Z]{16}
166
- ${SK_KEY_ROW}
167
- re:ghp_[A-Za-z0-9]{36}
168
- re:xox[baprs]-[A-Za-z0-9-]{10,}
164
+ ${SECRET_ROWS.join('\n')}
169
165
  `
170
166
 
171
167
  /** seed the configured keyword file with the generic starter so the guard is