rvlib-shipkit 2.25.0 → 2.27.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 (456) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/package.json +2 -2
  3. package/src/agent-time/diet.ts +77 -0
  4. package/src/agent-time/family.ts +72 -0
  5. package/src/agent-time/hooks.ts +331 -0
  6. package/src/agent-time/limits.ts +44 -0
  7. package/src/agent-time/live.ts +1 -3
  8. package/src/agent-time/mask.ts +96 -18
  9. package/src/agent-time/refused.ts +45 -0
  10. package/src/agent-time/render.ts +130 -17
  11. package/src/agent-time/report-cache.ts +57 -0
  12. package/src/agent-time/report.ts +349 -23
  13. package/src/agent-time/shape.ts +50 -3
  14. package/src/agent-time/store.ts +370 -95
  15. package/src/agent-time/timeline.ts +140 -21
  16. package/src/agent-time/turns.ts +18 -8
  17. package/src/annex/offload.ts +17 -6
  18. package/src/annex/tidy.ts +70 -10
  19. package/src/asks/ask-after.ts +40 -0
  20. package/src/asks/asks-queue.ts +205 -47
  21. package/src/assets/kit-config.ts +7 -3
  22. package/src/assets/kits/identity-kit.ts +289 -10
  23. package/src/check.ts +3 -1
  24. package/src/checks/SK004-gitignore-policy.check.ts +12 -5
  25. package/src/checks/SK013-one-way-in-policy.check.ts +8 -3
  26. package/src/checks/SK026-asks-autoclose.check.ts +5 -5
  27. package/src/checks/SK028-readme.check.ts +7 -66
  28. package/src/checks/SK030-cache-audit.check.ts +6 -1
  29. package/src/checks/SK031-trace-audit.check.ts +2 -0
  30. package/src/checks/SK033-global-contribution.check.ts +3 -1
  31. package/src/checks/SK035-public-clean.check.ts +2 -2
  32. package/src/checks/SK043-scratch-on-the-mac.check.ts +59 -4
  33. package/src/checks/SK045-slow-hooks.check.ts +47 -0
  34. package/src/checks/SK046-hook-records.check.ts +76 -0
  35. package/src/checks/SK047-login-in-description.check.ts +36 -0
  36. package/src/checks/SK048-one-local-file.check.ts +36 -0
  37. package/src/cli/cmd_Asks.ts +71 -5
  38. package/src/cli/cmd_Backup.ts +5 -3
  39. package/src/cli/cmd_Capacity.ts +2 -2
  40. package/src/cli/cmd_CrossRepoActivity.ts +5 -4
  41. package/src/cli/cmd_Db.ts +253 -0
  42. package/src/cli/cmd_History.ts +212 -0
  43. package/src/cli/cmd_Home.ts +31 -3
  44. package/src/cli/cmd_Hq.ts +516 -0
  45. package/src/cli/cmd_Machines.ts +36 -0
  46. package/src/cli/cmd_Media.ts +38 -6
  47. package/src/cli/cmd_Mv.ts +1 -1
  48. package/src/cli/cmd_Reflect.ts +23 -2
  49. package/src/cli/cmd_Releases.ts +30 -0
  50. package/src/cli/cmd_Review.ts +569 -118
  51. package/src/cli/cmd_Secret.ts +62 -12
  52. package/src/cli/cmd_Social.ts +83 -1
  53. package/src/cli/cmd_Space.ts +324 -0
  54. package/src/cli/cmd_Time.ts +82 -5
  55. package/src/cli/cmd_Tmp.ts +28 -4
  56. package/src/cli/cmd_Trailer.ts +14 -10
  57. package/src/cli/cmd_Urls.ts +56 -0
  58. package/src/cli/cmd_Vault.ts +583 -0
  59. package/src/cli/family-help.ts +4 -2
  60. package/src/cli/family-pages.ts +1 -1
  61. package/src/cli/registry.ts +26 -4
  62. package/src/collections/actions.ts +63 -13
  63. package/src/collections/collection-types.ts +23 -1
  64. package/src/collections/providers.ts +117 -23
  65. package/src/collections/review.ts +4 -4
  66. package/src/commands/runner.ts +5 -1
  67. package/src/contracts/contract-manifests.ts +6 -5
  68. package/src/contracts/contract-types.ts +6 -4
  69. package/src/contracts/contracts-engine.ts +11 -0
  70. package/src/contracts/manifests/chrome-web-store.contract.ts +31 -0
  71. package/src/core/budget.ts +12 -17
  72. package/src/core/capacity.ts +27 -18
  73. package/src/core/check-runner.ts +7 -4
  74. package/src/core/history-files.ts +9 -5
  75. package/src/core/layout.ts +3 -0
  76. package/src/core/machine-busy.ts +127 -0
  77. package/src/core/machine-commit.ts +6 -1
  78. package/src/core/machine-db.ts +368 -20
  79. package/src/core/machine-layout.ts +137 -0
  80. package/src/core/machine-read.ts +81 -0
  81. package/src/core/migrate-layout.ts +1 -1
  82. package/src/core/one-way-in-policy.ts +64 -7
  83. package/src/core/polling-policy.ts +27 -0
  84. package/src/core/retention.ts +16 -2
  85. package/src/core/scope.ts +107 -14
  86. package/src/core/signal-name.ts +6 -0
  87. package/src/core/slots.ts +5 -4
  88. package/src/core/trace-audit.ts +6 -1
  89. package/src/core/transient.ts +6 -0
  90. package/src/drill/clean.ts +25 -1
  91. package/src/drill/run.ts +2 -2
  92. package/src/drill/seal.ts +27 -4
  93. package/src/home/activity-shape.ts +2 -0
  94. package/src/home/activity.ts +66 -3
  95. package/src/home/app-sign.ts +15 -4
  96. package/src/home/daemon-jobs.ts +149 -7
  97. package/src/home/database-projects.ts +111 -0
  98. package/src/home/database-words.ts +203 -0
  99. package/src/home/databases.ts +460 -0
  100. package/src/home/global-units.ts +6 -0
  101. package/src/home/gui-app/ShipkitGui.swift +122 -1
  102. package/src/home/gui-app.ts +6 -3
  103. package/src/home/home-move.ts +514 -0
  104. package/src/home/home-paths.ts +12 -3
  105. package/src/home/home-routes.ts +68 -0
  106. package/src/home/inbox-shape.ts +24 -14
  107. package/src/home/machine-fold.ts +820 -0
  108. package/src/home/machine-host.ts +20 -5
  109. package/src/home/machine-repair.ts +503 -0
  110. package/src/home/machine-stores.ts +66 -15
  111. package/src/home/machine-temp.ts +547 -86
  112. package/src/home/resume.ts +79 -0
  113. package/src/home/run-daemon.ts +25 -4
  114. package/src/home/run-pm.ts +18 -5
  115. package/src/home/serve-daemon.ts +18 -3
  116. package/src/home/serve-web.ts +175 -7
  117. package/src/home/space-job.ts +115 -0
  118. package/src/home/space-page.ts +257 -0
  119. package/src/home/space-route.ts +167 -0
  120. package/src/home/space-words.ts +103 -0
  121. package/src/home/time-page-shape.ts +202 -0
  122. package/src/home/time-page.ts +64 -0
  123. package/src/home/vault-page.ts +482 -0
  124. package/src/home/vault-words.ts +132 -0
  125. package/src/hooks/leak-guard.ts +40 -13
  126. package/src/hooks/one-way-in-guard.ts +17 -4
  127. package/src/hq/cards.ts +581 -0
  128. package/src/hq/door-route.ts +43 -0
  129. package/src/hq/door.ts +163 -0
  130. package/src/hq/files-send.ts +348 -0
  131. package/src/hq/forgotten-log.ts +35 -0
  132. package/src/hq/history-check.ts +255 -0
  133. package/src/hq/history-place.ts +146 -0
  134. package/src/hq/history-send.ts +487 -0
  135. package/src/hq/hq-db.ts +99 -0
  136. package/src/hq/hq-local.ts +469 -0
  137. package/src/hq/hq-routes.ts +196 -0
  138. package/src/hq/hq-store.ts +599 -0
  139. package/src/hq/kinds/ask.ts +147 -0
  140. package/src/hq/kinds/card-gone.ts +83 -0
  141. package/src/hq/kinds/card-msg.ts +66 -0
  142. package/src/hq/kinds/card.ts +99 -0
  143. package/src/hq/kinds/index.ts +21 -0
  144. package/src/hq/kinds/kind.ts +126 -0
  145. package/src/hq/kinds/media.ts +125 -0
  146. package/src/hq/kinds/prompt.ts +219 -0
  147. package/src/hq/kinds/reflection.ts +128 -0
  148. package/src/hq/kinds/report.ts +55 -0
  149. package/src/hq/kinds/time-day.ts +236 -0
  150. package/src/hq/ledger.ts +473 -0
  151. package/src/hq/machine-key.ts +44 -0
  152. package/src/hq/machine-notes.ts +131 -0
  153. package/src/hq/outbox.ts +372 -0
  154. package/src/hq/replica.ts +168 -0
  155. package/src/hq/repo-id.ts +4 -0
  156. package/src/hq/report-facts.ts +117 -0
  157. package/src/hq/report.ts +274 -0
  158. package/src/hq/switch.ts +151 -0
  159. package/src/hq/vault-grant.ts +92 -0
  160. package/src/identities/identities.ts +15 -3
  161. package/src/identities/steps.ts +31 -0
  162. package/src/ledger/db.ts +73 -26
  163. package/src/ledger/gate-checks.ts +29 -4
  164. package/src/ledger/git-key.ts +3 -3
  165. package/src/ledger/git-scan.ts +49 -7
  166. package/src/ledger/run-log.ts +11 -3
  167. package/src/ledger/store.ts +26 -4
  168. package/src/media-store/backup/daemon.ts +36 -17
  169. package/src/media-store/backup/kept.ts +241 -0
  170. package/src/media-store/backup/restore.ts +14 -4
  171. package/src/media-store/backup/run.ts +11 -11
  172. package/src/media-store/backup/secret.ts +6 -4
  173. package/src/media-store/backup/snapshot.ts +4 -2
  174. package/src/media-store/backup/sources.ts +68 -20
  175. package/src/media-store/copy/config.ts +77 -0
  176. package/src/media-store/copy/copy.ts +194 -0
  177. package/src/media-store/copy/lifecycle.ts +43 -0
  178. package/src/media-store/copy/night.ts +90 -0
  179. package/src/media-store/copy/proof.ts +151 -0
  180. package/src/media-store/copy/snapshot.ts +152 -0
  181. package/src/media-store/copy/store.ts +62 -0
  182. package/src/media-store/copy/stream.ts +176 -0
  183. package/src/media-store/daemon.ts +66 -16
  184. package/src/media-store/db.ts +22 -11
  185. package/src/media-store/forget.ts +23 -3
  186. package/src/media-store/hand.ts +4 -3
  187. package/src/media-store/hq-find.ts +75 -0
  188. package/src/media-store/hq-send.ts +277 -0
  189. package/src/media-store/kind.ts +2 -0
  190. package/src/media-store/purge.ts +18 -15
  191. package/src/media-store/put.ts +24 -8
  192. package/src/media-store/remote.ts +16 -7
  193. package/src/media-store/space-listing.ts +240 -0
  194. package/src/media-store/space.ts +40 -21
  195. package/src/media-store/sync.ts +5 -5
  196. package/src/media-store/tidy.ts +98 -0
  197. package/src/media-store/upload.ts +3 -3
  198. package/src/media-store/webp.ts +66 -0
  199. package/src/messages/model.ts +16 -7
  200. package/src/messages/routes.ts +14 -4
  201. package/src/messages/score.ts +2 -2
  202. package/src/messages/suggest.ts +96 -0
  203. package/src/pages/frame-client.ts +10 -0
  204. package/src/plan/planner.ts +28 -17
  205. package/src/recordings/media-kind.ts +1 -0
  206. package/src/recordings/model.ts +1 -1
  207. package/src/recordings/recorder-app/Capture.swift +9 -7
  208. package/src/reflect/hq-corpus.ts +56 -0
  209. package/src/reflect/prompt-corpus.ts +3 -1
  210. package/src/reflect/transcript.ts +146 -36
  211. package/src/release/machine-words.ts +67 -0
  212. package/src/release/public-clean.ts +8 -3
  213. package/src/releases/from-card.ts +1 -1
  214. package/src/releases/model.ts +18 -0
  215. package/src/releases/routes.ts +10 -5
  216. package/src/releases/store.ts +23 -2
  217. package/src/repo-config.ts +42 -2
  218. package/src/review/anim.ts +2 -2
  219. package/src/review/auto.ts +2 -2
  220. package/src/review/card-db.ts +244 -0
  221. package/src/review/card-rows.ts +266 -0
  222. package/src/review/cells.ts +76 -5
  223. package/src/review/draft-card.ts +41 -0
  224. package/src/review/draft-model.ts +78 -0
  225. package/src/review/format.ts +29 -10
  226. package/src/review/gone.ts +98 -0
  227. package/src/review/inbox-hook.ts +35 -0
  228. package/src/review/marks.ts +1 -1
  229. package/src/review/media-kind.ts +7 -5
  230. package/src/review/media-read.ts +9 -7
  231. package/src/review/media.ts +32 -5
  232. package/src/review/model.ts +214 -45
  233. package/src/review/move.ts +491 -0
  234. package/src/review/notes.ts +12 -20
  235. package/src/review/previews.ts +15 -19
  236. package/src/review/project.ts +1 -1
  237. package/src/review/rev.ts +8 -0
  238. package/src/review/role.ts +1 -1
  239. package/src/review/routes.ts +64 -13
  240. package/src/review/stage-card.ts +8 -4
  241. package/src/review/stage-routes.ts +1 -1
  242. package/src/review/store.ts +529 -83
  243. package/src/review/thread-fold.ts +51 -0
  244. package/src/review/threads.ts +147 -9
  245. package/src/review/trailer-auto-mock.ts +63 -0
  246. package/src/review/trailer-card.ts +4 -4
  247. package/src/review/trailer-desk.ts +41 -7
  248. package/src/review/trailer-media.ts +1 -0
  249. package/src/review/trailer-model.ts +8 -0
  250. package/src/review/trailer-notes.ts +1 -1
  251. package/src/review/trailer-routes.ts +9 -1
  252. package/src/review/unit.ts +6 -6
  253. package/src/review/watchers.ts +1 -1
  254. package/src/rules/untrack-generated.ts +92 -8
  255. package/src/secrets/held.ts +16 -0
  256. package/src/secrets/keychain.ts +113 -0
  257. package/src/secrets/list.ts +16 -6
  258. package/src/secrets/manager.ts +24 -10
  259. package/src/secrets/read.ts +257 -0
  260. package/src/secrets/who-reads.ts +49 -0
  261. package/src/serve/door-forward.ts +268 -0
  262. package/src/serve/door-names.ts +47 -0
  263. package/src/serve/embed.ts +1 -1
  264. package/src/serve/hub-app/activity-view.tsx +56 -32
  265. package/src/serve/hub-app/activity.css +7 -1
  266. package/src/serve/hub-app/asks-page.tsx +48 -0
  267. package/src/serve/hub-app/asks-st.ts +25 -0
  268. package/src/serve/hub-app/clock-svc.ts +1 -2
  269. package/src/serve/hub-app/col-card.tsx +64 -13
  270. package/src/serve/hub-app/col-list-page.tsx +122 -0
  271. package/src/serve/hub-app/col-list-st.ts +103 -0
  272. package/src/serve/hub-app/col-tables-view.tsx +10 -41
  273. package/src/serve/hub-app/col-tables.ts +76 -8
  274. package/src/serve/hub-app/cols-svc.ts +70 -16
  275. package/src/serve/hub-app/database-st.ts +260 -0
  276. package/src/serve/hub-app/database-view.tsx +289 -0
  277. package/src/serve/hub-app/database.css +32 -0
  278. package/src/serve/hub-app/entry-bar.css +14 -0
  279. package/src/serve/hub-app/entry-bar.tsx +33 -0
  280. package/src/serve/hub-app/entry-pick.ts +31 -0
  281. package/src/serve/hub-app/floating.tsx +1 -0
  282. package/src/serve/hub-app/hash-route.ts +11 -1
  283. package/src/serve/hub-app/header-bar.tsx +14 -18
  284. package/src/serve/hub-app/home-st.ts +89 -9
  285. package/src/serve/hub-app/home-strip.css +5 -19
  286. package/src/serve/hub-app/home-strip.tsx +58 -92
  287. package/src/serve/hub-app/home.html +7 -0
  288. package/src/serve/hub-app/hub-app.tsx +31 -142
  289. package/src/serve/hub-app/hub-types.ts +3 -1
  290. package/src/serve/hub-app/hub.css +109 -23
  291. package/src/serve/hub-app/icons.tsx +18 -1
  292. package/src/serve/hub-app/identities-st.ts +56 -6
  293. package/src/serve/hub-app/identities-view.tsx +100 -58
  294. package/src/serve/hub-app/identities.css +17 -15
  295. package/src/serve/hub-app/identity-address.ts +5 -0
  296. package/src/serve/hub-app/inbox-st.ts +41 -24
  297. package/src/serve/hub-app/inbox-view.tsx +37 -41
  298. package/src/serve/hub-app/inbox.css +2 -5
  299. package/src/serve/hub-app/index.html +7 -0
  300. package/src/serve/hub-app/kept-cols.tsx +7 -0
  301. package/src/serve/hub-app/keys.ts +28 -15
  302. package/src/serve/hub-app/later.tsx +26 -0
  303. package/src/serve/hub-app/list-filter.tsx +14 -0
  304. package/src/serve/hub-app/list-walk.ts +72 -3
  305. package/src/serve/hub-app/machines-st.ts +251 -0
  306. package/src/serve/hub-app/machines-view.tsx +224 -0
  307. package/src/serve/hub-app/machines.css +76 -0
  308. package/src/serve/hub-app/md-copy.tsx +79 -0
  309. package/src/serve/hub-app/media-view.tsx +2 -0
  310. package/src/serve/hub-app/messages/messages-page.tsx +79 -7
  311. package/src/serve/hub-app/messages/messages-st.ts +99 -3
  312. package/src/serve/hub-app/messages.css +14 -0
  313. package/src/serve/hub-app/page-keys.ts +175 -0
  314. package/src/serve/hub-app/pages-frames.tsx +11 -3
  315. package/src/serve/hub-app/palette-st.ts +58 -11
  316. package/src/serve/hub-app/palette-view.tsx +3 -1
  317. package/src/serve/hub-app/project-list.css +54 -8
  318. package/src/serve/hub-app/project-list.tsx +128 -59
  319. package/src/serve/hub-app/projects-svc.ts +78 -7
  320. package/src/serve/hub-app/reader-chips.tsx +13 -0
  321. package/src/serve/hub-app/readme-view.tsx +2 -3
  322. package/src/serve/hub-app/readme.css +27 -5
  323. package/src/serve/hub-app/reflections-page.tsx +42 -0
  324. package/src/serve/hub-app/reflections-st.ts +17 -0
  325. package/src/serve/hub-app/releases/releases-page.tsx +25 -2
  326. package/src/serve/hub-app/releases/releases-st.ts +1 -1
  327. package/src/serve/hub-app/repo-sections.ts +9 -5
  328. package/src/serve/hub-app/repo-st.ts +35 -8
  329. package/src/serve/hub-app/review/draft-card.tsx +163 -0
  330. package/src/serve/hub-app/review/kit.tsx +50 -7
  331. package/src/serve/hub-app/review/note-place.ts +1 -1
  332. package/src/serve/hub-app/review/review-board.tsx +2 -2
  333. package/src/serve/hub-app/review/review-cells.tsx +145 -65
  334. package/src/serve/hub-app/review/review-kit.ts +27 -1
  335. package/src/serve/hub-app/review/review-list.tsx +68 -30
  336. package/src/serve/hub-app/review/review-page.tsx +7 -8
  337. package/src/serve/hub-app/review/review-st.ts +111 -24
  338. package/src/serve/hub-app/review/review-thread.tsx +49 -19
  339. package/src/serve/hub-app/review/review-views.tsx +475 -144
  340. package/src/serve/hub-app/review/thread-control-st.ts +115 -0
  341. package/src/serve/hub-app/review/thread-control.tsx +74 -0
  342. package/src/serve/hub-app/review/thread-st.ts +73 -26
  343. package/src/serve/hub-app/review/trailer-card.tsx +1 -1
  344. package/src/serve/hub-app/review/trailer-page.tsx +37 -16
  345. package/src/serve/hub-app/review/trailer-st.ts +41 -7
  346. package/src/serve/hub-app/review.css +267 -61
  347. package/src/serve/hub-app/side-lists.ts +72 -0
  348. package/src/serve/hub-app/sidebar.tsx +6 -3
  349. package/src/serve/hub-app/site/site-part.tsx +2 -8
  350. package/src/serve/hub-app/site/site-st.ts +4 -4
  351. package/src/serve/hub-app/social/comms-page.tsx +20 -5
  352. package/src/serve/hub-app/social/kit.tsx +30 -4
  353. package/src/serve/hub-app/social/post-card.tsx +139 -49
  354. package/src/serve/hub-app/social/serial-writes.ts +13 -0
  355. package/src/serve/hub-app/social/social-model.ts +11 -0
  356. package/src/serve/hub-app/social/social-page.tsx +94 -35
  357. package/src/serve/hub-app/social/social-st.ts +120 -36
  358. package/src/serve/hub-app/social/stage-popup.tsx +1 -1
  359. package/src/serve/hub-app/social/stage-st.ts +1 -1
  360. package/src/serve/hub-app/social/step-layout.ts +1 -1
  361. package/src/serve/hub-app/social.css +3 -0
  362. package/src/serve/hub-app/space-st.ts +209 -0
  363. package/src/serve/hub-app/space-view.tsx +196 -0
  364. package/src/serve/hub-app/space.css +27 -0
  365. package/src/serve/hub-app/stores/stores-page.tsx +91 -23
  366. package/src/serve/hub-app/stores/stores-st.ts +44 -19
  367. package/src/serve/hub-app/stores.css +6 -1
  368. package/src/serve/hub-app/theme-st.ts +22 -9
  369. package/src/serve/hub-app/time-charts.tsx +291 -0
  370. package/src/serve/hub-app/time-pages.tsx +749 -0
  371. package/src/serve/hub-app/time-st.ts +162 -0
  372. package/src/serve/hub-app/time-view.tsx +76 -0
  373. package/src/serve/hub-app/time.css +138 -0
  374. package/src/serve/hub-app/tree-build.ts +52 -42
  375. package/src/serve/hub-app/tree-row.tsx +4 -4
  376. package/src/serve/hub-app/tree-svc.ts +18 -9
  377. package/src/serve/hub-app/urls-svc.ts +154 -0
  378. package/src/serve/hub-app/urls-view.tsx +117 -0
  379. package/src/serve/hub-app/urls.css +30 -0
  380. package/src/serve/hub-app/vault-st.ts +127 -0
  381. package/src/serve/hub-app/vault-view.tsx +154 -0
  382. package/src/serve/hub-app/vault.css +38 -0
  383. package/src/serve/hub-app/veille/veille-st.ts +12 -10
  384. package/src/serve/hub-app/waiting-svc.ts +29 -0
  385. package/src/serve/hub-app/wikis-view.tsx +2 -2
  386. package/src/serve/hub-runtime.ts +15 -2
  387. package/src/serve/project-gutter-route.ts +27 -14
  388. package/src/serve/project-gutter.ts +25 -12
  389. package/src/serve/same-origin.ts +10 -0
  390. package/src/serve/serve-hub.ts +13 -4
  391. package/src/shipkit-files.ts +16 -2
  392. package/src/shipkit.ts +1 -1
  393. package/src/shot/shooter.ts +616 -420
  394. package/src/shot/shot-ask.ts +246 -155
  395. package/src/site/desk.ts +2 -2
  396. package/src/smoke/run-smoke.ts +3 -2
  397. package/src/social/cover.ts +202 -0
  398. package/src/social/discord-layout.ts +37 -13
  399. package/src/social/drafts.ts +3 -0
  400. package/src/social/load.ts +23 -2
  401. package/src/social/media-kind.ts +2 -1
  402. package/src/social/publish/discord.ts +5 -2
  403. package/src/social/publish/secret.ts +2 -2
  404. package/src/social/release-stage.ts +28 -13
  405. package/src/social/routes.ts +26 -1
  406. package/src/social/stage.ts +1 -1
  407. package/src/social/stats.ts +12 -9
  408. package/src/social/strip.ts +4 -1
  409. package/src/social/thumbnail.ts +255 -0
  410. package/src/stores/collection.ts +15 -11
  411. package/src/stores/desk.ts +236 -42
  412. package/src/stores/model.ts +72 -6
  413. package/src/stores/routes.ts +37 -12
  414. package/src/stores/unit.ts +14 -8
  415. package/src/suite/judge-suites.ts +113 -16
  416. package/src/suite/select.ts +45 -3
  417. package/src/suite/suite-cli.ts +81 -34
  418. package/src/trailer/bed.ts +1 -1
  419. package/src/trailer/build.ts +134 -21
  420. package/src/trailer/ffmpeg.ts +7 -0
  421. package/src/trailer/fonts.ts +3 -2
  422. package/src/trailer/grammar.ts +201 -2
  423. package/src/trailer/graph.ts +42 -5
  424. package/src/trailer/look.ts +21 -0
  425. package/src/trailer/mock.ts +154 -0
  426. package/src/trailer/passage.ts +65 -26
  427. package/src/trailer/score/heard.ts +89 -0
  428. package/src/trailer/score/sound.ts +14 -8
  429. package/src/trailer/sound/run.ts +16 -6
  430. package/src/trailer/stitch.ts +26 -5
  431. package/src/trailer/titles.ts +82 -19
  432. package/src/trailer/versions.ts +1 -3
  433. package/src/trailer/vertical.ts +3 -1
  434. package/src/urls/frame.ts +195 -0
  435. package/src/urls/routes.ts +43 -0
  436. package/src/urls/rows.ts +171 -0
  437. package/src/urls/unit.ts +73 -0
  438. package/src/vault/house-keys.ts +42 -0
  439. package/src/vault/layout.ts +50 -0
  440. package/src/vault/policy.ts +165 -0
  441. package/src/vault/vault-audit.ts +276 -0
  442. package/src/vault/vault-client.ts +40 -0
  443. package/src/vault/vault-config.ts +159 -0
  444. package/src/vault/vault-destroy.ts +78 -0
  445. package/src/vault/vault-handover.ts +305 -0
  446. package/src/vault/vault-http.ts +352 -0
  447. package/src/vault/vault-import.ts +208 -0
  448. package/src/vault/vault-init.ts +328 -0
  449. package/src/vault/vault-minter.ts +271 -0
  450. package/src/vault/vault-restore.ts +333 -0
  451. package/src/vault/vault-serve.ts +342 -0
  452. package/src/vault/vault-snapshot.ts +281 -0
  453. package/src/veille/asks.ts +1 -1
  454. package/src/veille/desk.ts +2 -2
  455. package/src/wiki/run-wiki.ts +2 -1
  456. package/src/wiki/scan-md.ts +42 -2
@@ -168,11 +168,10 @@ const read = (abs: string): string => readFileSync(abs, 'utf8')
168
168
  const home = (p: string): string => (p.startsWith('~/') ? join(homedir(), p.slice(2)) : p)
169
169
 
170
170
  /** the folder of every identity: `SHIPKIT_IDENTITIES_DIR`, else the house repo's; null when this machine has no house */
171
- export async function identitiesDir(cwd = process.cwd()): Promise<string | null> {
171
+ export async function identitiesDir(cwd = process.cwd(), known?: string | null): Promise<string | null> {
172
172
  const env = process.env['SHIPKIT_IDENTITIES_DIR']
173
173
  if (env) return env
174
- const { houseRootOf } = await import('../home/home-start.ts')
175
- const house = houseRootOf(cwd)
174
+ const house = known !== undefined ? known : (await import('../home/home-start.ts')).houseRootOf(cwd)
176
175
  return house == null ? null : join(house, LAYOUT.identities)
177
176
  }
178
177
 
@@ -524,6 +523,19 @@ export function speakerOf(speaksAs: string | undefined, ids: Identities): Identi
524
523
  return ids.identities.find((i) => i.default) ?? ids.identities[0] ?? null
525
524
  }
526
525
 
526
+ /** the id `speakerOf` answers, from the folder names and each `identity.md`'s head alone: a scope check asks it at
527
+ * every secret read, where the whole model costs 50 ms */
528
+ export function speakerIdIn(dir: string | null, speaksAs: string | undefined): string | null {
529
+ if (dir == null || !existsSync(dir)) return null
530
+ const has = (id: string): boolean => SLUG.test(id) && existsSync(join(dir, id, 'identity.md')) && statSync(join(dir, id)).isDirectory()
531
+ if (speaksAs != null) return has(speaksAs) ? speaksAs : null
532
+ const heads = readdirSync(dir)
533
+ .filter(has)
534
+ .map((id) => ({ id, meta: parseFrontmatter(read(join(dir, id, 'identity.md'))).meta }))
535
+ .sort((a, b) => Number(a.meta.order ?? 99) - Number(b.meta.order ?? 99) || a.id.localeCompare(b.id))
536
+ return (heads.find((h) => h.meta.default === 'true') ?? heads[0])?.id ?? null
537
+ }
538
+
527
539
  /** one identity by id, or a loud error naming the ones there are */
528
540
  export function identityOf(id: string, ids: Identities): Identity {
529
541
  const i = ids.identities.find((x) => x.id === id)
@@ -3,3 +3,34 @@
3
3
 
4
4
  /** the rows the steps name, `[[field]]`: the form he fills */
5
5
  export const stepRefs = (list: readonly { text: string }[]): Set<string> => new Set(list.flatMap((s) => [...s.text.matchAll(/\[\[([^\]]+)\]\]/g)].map((m) => m[1]!)))
6
+
7
+ /** a step's secret: `[[secret:<name>]]` draws the field that stores that name, in the step itself */
8
+ const SECRET_REF = /^secret:([a-z0-9][a-z0-9/_-]*)$/
9
+
10
+ /** the secret a ref names; null for a row's ref */
11
+ export const secretOfRef = (ref: string): string | null => SECRET_REF.exec(ref)?.[1] ?? null
12
+
13
+ /** every secret the steps take, in their order */
14
+ export const stepSecrets = (list: readonly { text: string }[]): string[] => [...stepRefs(list)].flatMap((r) => secretOfRef(r) ?? [])
15
+
16
+ /** a step that tells a story in place of an act: what was set for him, or a state of his screen to check */
17
+ const STORY = /\bonly a look\b|\bcheck that [^.;]* reads\b|\bset (?:it|them) through\b/i
18
+
19
+ /** the rows a Discord bot's steps name: each field of the developer portal that holds words or a picture of ours */
20
+ export const BOT_ROWS = ['bot name', 'bot description', 'bot tags', 'bot banner'] as const
21
+
22
+ /** what is wrong in an account's setup steps, one line each:
23
+ * - a step still to do that sends him elsewhere to store a secret (an ask's page, a command to type): the step holds
24
+ * the field. A done step is history and stays as written
25
+ * - a Discord account's bot token taken with no profile for the bot: its name and its description are rows the steps name */
26
+ export function setupProblems(a: { id: string; secret: string; steps: readonly { text: string; done?: boolean }[] }): string[] {
27
+ const out: string[] = []
28
+ for (const [i, s] of a.steps.entries())
29
+ if (!s.done && /#item:asks:|\b[\w-]*secret set\b/.test(s.text)) out.push(`step ${i + 1} sends him elsewhere to store a secret: write [[secret:<name>]] in the step, which draws the field there`)
30
+ for (const [i, s] of a.steps.entries())
31
+ if (!s.done && STORY.test(s.text)) out.push(`step ${i + 1} tells what was done or what the screen should read: name the control and the value he sets it to`)
32
+ const refs = stepRefs(a.steps)
33
+ if (a.id === 'discord' && a.secret !== '' && stepSecrets(a.steps).includes(a.secret))
34
+ for (const row of BOT_ROWS) if (!refs.has(row)) out.push(`the steps take the bot's token and never name [[${row}]]: a bot he creates needs its name, its description, its tags and its banner in the steps, page by page of the platform's form`)
35
+ return out
36
+ }
package/src/ledger/db.ts CHANGED
@@ -24,10 +24,11 @@
24
24
  // of the repo shares it, which is safe for answers because no key component
25
25
  // is a path (ledger/toolchain-identity.ts).
26
26
  import { Database } from 'bun:sqlite'
27
- import { existsSync, mkdirSync } from 'fs'
28
- import { dirname, join } from 'path'
27
+ import { chmodSync, existsSync, mkdirSync, readdirSync, rmSync, statSync } from 'fs'
28
+ import { basename, dirname, join } from 'path'
29
29
 
30
30
  import { shipkitRoot } from '../core/git-root.ts'
31
+ import { createRefusal } from '../core/machine-layout.ts'
31
32
  export { shipkitRoot }
32
33
 
33
34
  export const DB_FILE = 'shipkit.sqlite'
@@ -195,9 +196,16 @@ export type Opened = { db: Database }
195
196
  * a handle the caller CLOSES. Null for every failure there is: no path, no
196
197
  * db and `create: false`, a corrupt file, a locked one, a read only disk. */
197
198
  export function openDb(path: string, o: { create?: boolean; busyMs?: number } = {}): Opened | null {
199
+ return openWith(path, o, migrate)
200
+ }
201
+
202
+ /** the same open for another database of shipkit's (the hq's): its own `schema` runs where the record's migration
203
+ * does, and every failure is null the same way */
204
+ export function openWith(path: string, o: { create?: boolean; busyMs?: number }, schema: (db: Database) => void): Opened | null {
198
205
  if (path === '') return null
199
206
  const create = o.create !== false
200
207
  if (!create && !existsSync(path)) return null
208
+ if (create && createRefusal(path) != null) return null
201
209
  let db: Database | null = null
202
210
  try {
203
211
  if (create) mkdirSync(dirname(path), { recursive: true })
@@ -208,10 +216,11 @@ export function openDb(path: string, o: { create?: boolean; busyMs?: number } =
208
216
  db.exec(`pragma busy_timeout = ${busyMs}`)
209
217
  ensureWal(db, busyMs)
210
218
  db.exec('pragma synchronous = NORMAL')
211
- migrate(db)
219
+ schema(db)
212
220
  return { db }
213
- } catch {
221
+ } catch (e) {
214
222
  try { db?.close() } catch { /* never opened, or already gone */ }
223
+ if (e instanceof NoCopy) console.error(`WARN ${e.message}`)
215
224
  return null
216
225
  }
217
226
  }
@@ -240,31 +249,48 @@ export function ensureWal(db: Database, busyMs: number): void {
240
249
 
241
250
  const userVersion = (db: Database): number => Number((db.query('pragma user_version').get() as { user_version?: number } | null)?.user_version ?? 0)
242
251
 
243
- /** create the schema, once. The version is read a SECOND time inside the
244
- * write lock: two processes can open a fresh db at the same moment, and the
245
- * loser must find the schema already there rather than drop it. */
246
- function migrate(db: Database): void {
247
- if (userVersion(db) >= SCHEMA_VERSION) return
252
+ /** a migration held for want of its copy: every open says it, the file stays as it was */
253
+ class NoCopy extends Error {
254
+ override readonly name = 'NoCopy'
255
+ }
256
+
257
+ /** where a file keeps itself from before its schema went to `version` */
258
+ export const beforeCopy = (path: string, version: number): string => `${path}.before-v${version}`
259
+
260
+ /** a file that held something keeps one whole copy of itself before its shape changes, mode 0600:
261
+ * the roles of a machine run the source as it is saved, so a migration that is wrong runs on a live file, and the
262
+ * copy is the way back. One copy a file: the next change of shape replaces it. No copy, no migration: a copy that
263
+ * cannot be made (a full disk) holds the file at its version and throws why */
264
+ function keepBefore(db: Database, was: number, version: number): void {
265
+ const path = db.filename
266
+ if (was <= 0 || path === '' || path === ':memory:') return
267
+ const to = beforeCopy(path, version)
268
+ try {
269
+ rmSync(to, { force: true })
270
+ db.exec(`vacuum into '${to.replace(/'/g, "''")}'`)
271
+ // the copy holds what the file held, whatever its own mode: the owner's only
272
+ chmodSync(to, 0o600)
273
+ for (const f of readdirSync(dirname(path))) if (f.startsWith(`${basename(path)}.before-v`) && f !== basename(to)) rmSync(join(dirname(path), f), { force: true })
274
+ } catch (e) {
275
+ try { rmSync(to, { force: true }) } catch { /* what is in the way stays: the next open says it again */ }
276
+ let mb = 0
277
+ try { mb = Math.ceil(statSync(path).size / 1e6) } catch { /* the size is unknown */ }
278
+ throw new NoCopy(`${path} stays at version ${was}: no copy of it could be made before it goes to version ${version} (${(e as Error).message}); free room on the disk (about ${mb} MB), then open it again`)
279
+ }
280
+ }
281
+
282
+ /** bring a file to `version`, once: `apply(was)` runs under the write lock, where the version is read a SECOND time,
283
+ * since two processes can open a fresh db at the same moment and the loser must find the schema already there */
284
+ export function migrateTo(db: Database, version: number, apply: (was: number) => void): void {
285
+ const seen = userVersion(db)
286
+ if (seen >= version) return
287
+ keepBefore(db, seen, version)
248
288
  db.exec('begin immediate')
249
289
  try {
250
290
  const was = userVersion(db)
251
- if (was < SCHEMA_VERSION) {
252
- // the pre-v2 tables carry a `kind` column and keys of the form
253
- // `<kind>:<id>`, which no reader speaks any more. v2 to v3 only
254
- // adds tables, v3 to v4 renames one, v4 to v5 adds one and v5 to
255
- // v6 and every step to v9 add columns (v8 a table too), and v10
256
- // adds a table, so their rows stay
257
- if (was < 2) db.exec('drop table if exists runs; drop table if exists unit_last;')
258
- else if (was < 4 && db.query("select 1 from sqlite_master where type = 'table' and name = 'unit_last'").get() != null) db.exec('alter table unit_last rename to check_last; alter table check_last rename column unit to id; drop index if exists runs_unit;')
259
- const suites = db.query("select name from pragma_table_info('suites')").all() as { name: string }[]
260
- if (suites.length > 0 && !suites.some((c) => c.name === 'check_id')) db.exec("alter table suites add column check_id text not null default ''")
261
- if (suites.length > 0 && !suites.some((c) => c.name === 'unit')) db.exec("alter table suites add column unit text not null default ''")
262
- if (suites.length > 0 && !suites.some((c) => c.name === 'cpu_ms')) db.exec('alter table suites add column cpu_ms integer default null')
263
- if (suites.length > 0 && !suites.some((c) => c.name === 'phase')) db.exec("alter table suites add column phase text not null default ''")
264
- if (suites.length > 0 && !suites.some((c) => c.name === 'phase_ms')) db.exec('alter table suites add column phase_ms integer default null')
265
- if (suites.length > 0 && !suites.some((c) => c.name === 'fail_line')) db.exec("alter table suites add column fail_line text not null default ''")
266
- db.exec(SCHEMA)
267
- db.exec(`pragma user_version = ${SCHEMA_VERSION}`)
291
+ if (was < version) {
292
+ apply(was)
293
+ db.exec(`pragma user_version = ${version}`)
268
294
  }
269
295
  db.exec('commit')
270
296
  } catch (e) {
@@ -273,6 +299,27 @@ function migrate(db: Database): void {
273
299
  }
274
300
  }
275
301
 
302
+ /** the record's own schema, once */
303
+ function migrate(db: Database): void {
304
+ migrateTo(db, SCHEMA_VERSION, (was) => {
305
+ // the pre-v2 tables carry a `kind` column and keys of the form
306
+ // `<kind>:<id>`, which no reader speaks any more. v2 to v3 only
307
+ // adds tables, v3 to v4 renames one, v4 to v5 adds one and v5 to
308
+ // v6 and every step to v9 add columns (v8 a table too), and v10
309
+ // adds a table, so their rows stay
310
+ if (was < 2) db.exec('drop table if exists runs; drop table if exists unit_last;')
311
+ else if (was < 4 && db.query("select 1 from sqlite_master where type = 'table' and name = 'unit_last'").get() != null) db.exec('alter table unit_last rename to check_last; alter table check_last rename column unit to id; drop index if exists runs_unit;')
312
+ const suites = db.query("select name from pragma_table_info('suites')").all() as { name: string }[]
313
+ if (suites.length > 0 && !suites.some((c) => c.name === 'check_id')) db.exec("alter table suites add column check_id text not null default ''")
314
+ if (suites.length > 0 && !suites.some((c) => c.name === 'unit')) db.exec("alter table suites add column unit text not null default ''")
315
+ if (suites.length > 0 && !suites.some((c) => c.name === 'cpu_ms')) db.exec('alter table suites add column cpu_ms integer default null')
316
+ if (suites.length > 0 && !suites.some((c) => c.name === 'phase')) db.exec("alter table suites add column phase text not null default ''")
317
+ if (suites.length > 0 && !suites.some((c) => c.name === 'phase_ms')) db.exec('alter table suites add column phase_ms integer default null')
318
+ if (suites.length > 0 && !suites.some((c) => c.name === 'fail_line')) db.exec("alter table suites add column fail_line text not null default ''")
319
+ db.exec(SCHEMA)
320
+ })
321
+ }
322
+
276
323
  /** give the file back its free pages once more than half of it is free and
277
324
  * that is worth it: a DELETE frees pages for reuse but never shrinks the
278
325
  * file. VACUUM holds the write lock while it runs: a gate that asks then
@@ -11,7 +11,7 @@
11
11
  // check script, a `*.check.ts` with no check object). The declaration always lives WITH the check, never in a table
12
12
  // over here: a table beside the registry is a second source of truth that
13
13
  // drifts the first time somebody adds one.
14
- import { existsSync } from 'fs'
14
+ import { existsSync, realpathSync } from 'fs'
15
15
  import { join, relative, resolve } from 'path'
16
16
  import type { CheckCtx } from '../core/check-ctx.ts'
17
17
  import { type RepoConfig } from '../repo-config.ts'
@@ -55,7 +55,31 @@ function rawAccessOf(root: string, u: DiscoveredCheck, configs: Map<string, RvtC
55
55
  * asked for the quick tier and one that asked for the full tier are different
56
56
  * questions, and a surface that renders keys without applying it renders a
57
57
  * tier nobody ran. */
58
+ /** true when `file` is this repo's own source: under its root, and no install. By real paths, so a root or a file
59
+ * reached through a link is judged where it is */
60
+ export const hostsFile = (root: string, file: string): boolean => {
61
+ const real = (p: string): string => { try { return realpathSync(p) } catch { return p } }
62
+ const rel = relative(real(root), real(file))
63
+ return !rel.startsWith('..') && !rel.split(/[\\/]/).includes('node_modules')
64
+ }
65
+
66
+ /** a check of the toolkit (it has no path of its own in the repo) whose source lives outside this repo */
67
+ export const toolkitCheckElsewhere = (root: string, u: { rel?: string | null; path: string }): boolean => u.rel == null && !hostsFile(root, u.path)
68
+
69
+ /** what a check that declares cache reads becomes when a module its body reaches touches the disk around `c`.
70
+ * In the repo that holds the check's source it is a refusal: the declaration is wrong, and the gate fails until it
71
+ * is right. A toolkit check seen from another repo is the toolkit's defect, never that repo's: it runs there with
72
+ * no cache and says why, so a red gate still means « this repo is broken » */
73
+ export function rawAccessDecl(raw: string, toolkitCheckElsewhere: boolean): Pick<CheckDecl, 'declError' | 'uncacheable'> {
74
+ return toolkitCheckElsewhere
75
+ ? { uncacheable: `a defect of the toolkit, not of this repo: its check declares cache reads, but ${raw}. It runs here with no cache` }
76
+ : { declError: `declares cache reads, but ${raw}` }
77
+ }
78
+
58
79
  export const FULL_TESTS_ENV = 'SHIPKIT_TEST_FULL'
80
+ /** a suite that runs only with SHIPKIT_<NAME>_LIVE=1 (it starts real servers on scratch): each such switch set joins
81
+ * every task's env, so its key, and a green of a run without it never answers for a run with it */
82
+ export const liveEnv = (env: Record<string, string | undefined> = process.env): Record<string, string> => Object.fromEntries(Object.keys(env).filter((k) => /^SHIPKIT_[A-Z0-9_]+_LIVE$/.test(k) && env[k] === '1').sort().map((k) => [k, '1']))
59
83
 
60
84
  export type TestTier = 'quick' | 'full'
61
85
 
@@ -315,7 +339,8 @@ export async function composeChecks(root: string, c: RepoConfig, o: ComposeOpts
315
339
  const audit = readAuditReport(root)
316
340
  const extrasOf = (id: string): string[] => [...new Set([...ignoredFor(c.ignoredInputs, id), ...auditedExtras(audit, id)])].filter(onDisk).sort()
317
341
  for (const raw of [...floor.tasks, ...(c.tasks ?? []).filter((t) => foldedInto.get(t.id) !== t)]) {
318
- const t: TaskDef = full ? { ...raw, env: { ...raw.env, [FULL_TESTS_ENV]: '1' } } : raw
342
+ const added = { ...(full ? { [FULL_TESTS_ENV]: '1' } : {}), ...liveEnv() }
343
+ const t: TaskDef = Object.keys(added).length > 0 ? { ...raw, env: { ...raw.env, ...added } } : raw
319
344
  const own = t.id === 'test' && floor.tasks.includes(raw) ? rootTest : null
320
345
  const declared = own?.inputs ?? t.inputs
321
346
  // the declared extras join a declared list too: a list names what the
@@ -420,10 +445,10 @@ export async function composeChecks(root: string, c: RepoConfig, o: ComposeOpts
420
445
  ttl: cache.ttl,
421
446
  never: cache.never,
422
447
  argv: u.def.cmd,
423
- extra: cache.reads === true ? `${extra ?? ''}|tier=${full ? 'full' : 'quick'}` : extra,
448
+ extra: cache.reads === true ? `${extra ?? ''}|tier=${full ? 'full' : 'quick'}${Object.keys(liveEnv()).map((k) => `|${k}=1`).join('')}` : extra,
424
449
  writes: u.def.writes,
425
450
  ...(cache.reads === true && raw == null ? { reads: true } : {}),
426
- ...(raw != null ? { declError: `declares cache reads, but ${raw}` } : {}),
451
+ ...(raw != null ? rawAccessDecl(raw, toolkitCheckElsewhere(root, u)) : {}),
427
452
  },
428
453
  title: u.title,
429
454
  description: u.description,
@@ -367,14 +367,14 @@ export class KeyLayer {
367
367
  } catch (e) {
368
368
  return { ...base, reason: e instanceof Error ? e.message : String(e) }
369
369
  }
370
- // absent means not on disk at all: a path git cannot name while it
371
- // exists (a submodule, an empty folder) keys nothing, optional or not
370
+ // absent means not on disk at all: a path git cannot name while it exists (a submodule
371
+ // with a change of its own, an empty folder) keys nothing, optional or not
372
372
  const notOnDisk = (p: string): boolean => !existsSync(join(this.root, p))
373
373
  const absent = new Set(inputs.filter((p) => optional.has(p) && scan.missing.includes(p) && notOnDisk(p)))
374
374
  const stale = inputs.filter((p) => scan.missing.includes(p) && !absent.has(p))
375
375
  const gone = stale.filter(notOnDisk)
376
376
  if (gone.length > 0) return { ...base, reason: `declared input(s) not on disk: ${gone.join(', ')}` }
377
- if (stale.length > 0) return { ...base, reason: `declared input(s) on disk that git could not name (a submodule, an empty folder): ${stale.join(', ')}` }
377
+ if (stale.length > 0) return { ...base, reason: `declared input(s) on disk that git could not name (a submodule with uncommitted changes, an empty folder): ${stale.join(', ')}` }
378
378
  const hidden = inputs.flatMap((p) => scan.excluded.get(p) ?? [])
379
379
  const inputOids: [string, string][] = inputs.map((p) => [p, absent.has(p) ? ABSENT : scan.oidByPath.get(p) ?? ''])
380
380
  if (inputOids.some(([, oid]) => oid === '')) return { ...base, reason: 'git could not name one of the declared inputs' }
@@ -55,6 +55,10 @@ export type ScanResult = {
55
55
  oidByPath: Map<string, string>
56
56
  /** declared paths that are not on disk — the caller must not cache them */
57
57
  missing: string[]
58
+ /** declared paths that are a submodule, keyed (by the commit it stands at) or not. Whether one holds a change
59
+ * is read from its own repo, not from this index, so a result that looked at one is never kept from one scan
60
+ * to the next, in either direction */
61
+ submodules?: string[]
58
62
  /** repo-relative path → ignored content under it that is NOT in the key
59
63
  * (node_modules only, by policy: toolchain-identity.ts owns installs) */
60
64
  excluded: Map<string, string[]>
@@ -349,14 +353,17 @@ function stage(root: string, wanted: string[], prior: ScanResult | undefined, o:
349
353
  // an earlier scan's object dir held and dropped: their ids are right, and
350
354
  // `--missing-ok` lets the tree be written from the ids alone
351
355
  const ignoredTreeOid = forceAdd.length > 0 ? gitOrThrow(root, ['write-tree', '--missing-ok'], on(ignoredIndex)).trim() : null
356
+ const submodules: string[] = []
357
+ /** the declared paths the tree holds as a submodule, with the commit each stands at */
358
+ const gitlinks = new Map<string, string>()
352
359
  const done = (oidByPath: Map<string, string>, files?: readonly string[]): ScanResult => {
353
- const r: ScanResult = { treeOid, oidByPath, missing: [...new Set(missing)].sort(), excluded, ignored, ignoredTreeOid, ...(files == null ? {} : { files }), ms: performance.now() - started }
354
- if (memoKey != null) remember(memoKey, { ...r, oidByPath: new Map(oidByPath), missing: [...r.missing] })
360
+ const r: ScanResult = { treeOid, oidByPath, missing: [...new Set(missing)].sort(), excluded, ignored, ignoredTreeOid, ...(submodules.length > 0 ? { submodules: [...submodules] } : {}), ...(files == null ? {} : { files }), ms: performance.now() - started }
361
+ if (memoKey != null && submodules.length === 0) remember(memoKey, { ...r, oidByPath: new Map(oidByPath), missing: [...r.missing] })
355
362
  return r
356
363
  }
357
364
  // both root trees unchanged and the same paths on disk: every path under
358
365
  // them names the same object, so the per path answer is the prior one
359
- if (prior != null && prior.treeOid === treeOid && prior.ignoredTreeOid === ignoredTreeOid && prior.missing.join('\n') === [...new Set(missing)].sort().join('\n') && (o.treeOnly !== true || prior.files != null))
366
+ if (prior != null && !(prior.submodules?.length) && prior.treeOid === treeOid && prior.ignoredTreeOid === ignoredTreeOid && prior.missing.join('\n') === [...new Set(missing)].sort().join('\n') && (o.treeOnly !== true || prior.files != null))
360
367
  return done(new Map(prior.oidByPath), prior.files)
361
368
  const oidByPath = new Map<string, string>()
362
369
  // a declared path is relative to root, and `<tree>:<path>` reads from the
@@ -386,19 +393,54 @@ function stage(root: string, wanted: string[], prior: ScanResult | undefined, o:
386
393
  throw new GitScanError(`git cat-file --batch-check answered ${lines.length} of ${paths.length} paths`)
387
394
  paths.forEach((path, i) => {
388
395
  const oid = lines[i]!.split(' ')[0] ?? ''
389
- // 'missing' / 'ambiguous' come back in place of an id — a path git
390
- // cannot name is a path we cannot key on
391
- if (/^[0-9a-f]{40}$/.test(oid)) oidByPath.set(path, oid)
392
- else if (!missing.includes(path)) missing.push(path)
396
+ if (/^[0-9a-f]{40}$/.test(oid)) return void oidByPath.set(path, oid)
397
+ // `missing` is also git's word for an entry whose OBJECT is gone: the warm index keeps a file's entry
398
+ // from scan to scan, git writes no blob for an entry that did not move, and the objects of the scan
399
+ // that wrote it were dropped with that scan. The tree still names the file, and that id is its content
400
+ const entry = entryOf(root, root_, underRoot(path), on(index))
401
+ if (entry?.mode === GITLINK) gitlinks.set(path, entry.oid)
402
+ else if (entry != null) return void oidByPath.set(path, entry.oid)
403
+ // a path git cannot name is a path we cannot key on
404
+ if (!missing.includes(path)) missing.push(path)
393
405
  })
394
406
  }
395
407
 
408
+ // a submodule is a commit of another repo, so no object here names it. While it holds no change of its own, the
409
+ // commit it stands at is its content; with one, it stays a path git cannot name, and nothing is keyed on it
410
+ for (const path of [...missing]) {
411
+ if (path === WHOLE_TREE || !existsSync(join(root, path))) continue
412
+ const link = gitlinks.get(path)
413
+ if (link == null) continue
414
+ submodules.push(path)
415
+ if (!submoduleClean(join(root, path))) continue
416
+ oidByPath.set(path, link)
417
+ missing.splice(missing.indexOf(path), 1)
418
+ }
396
419
  if (o.treeOnly !== true) return done(oidByPath)
397
420
  const whole = oidByPath.get(WHOLE_TREE)
398
421
  if (whole == null) throw new GitScanError('git could not name the work tree')
399
422
  return done(oidByPath, filesOf(root, whole, on(indexFile)))
400
423
  }
401
424
 
425
+ /** the mode of a tree entry that is a submodule: its id is a commit of another repo */
426
+ const GITLINK = '160000'
427
+
428
+ /** what a tree holds at `path`, read from the tree itself: its mode and its id, whether the object is at hand or not */
429
+ function entryOf(root: string, tree: string, path: string, env: Record<string, string>): { mode: string; oid: string } | null {
430
+ const p = Bun.spawnSync([gitBin(), 'ls-tree', tree, '--', path], { cwd: root, stdout: 'pipe', stderr: 'ignore', env: { ...process.env, ...env } })
431
+ const m = /^(\d{6}) \w+ ([0-9a-f]{40})\t/.exec(p.stdout.toString())
432
+ return p.exitCode === 0 && m ? { mode: m[1]!, oid: m[2]! } : null
433
+ }
434
+
435
+ /** a submodule's work tree is there and holds no change of its own: nothing modified, nothing untracked, in it or
436
+ * in a submodule of its own. A folder with no `.git` is a submodule nobody filled (a new worktree has them so): git
437
+ * would answer there for the repo around it, so it is never clean. The two flags hold whatever its config says */
438
+ function submoduleClean(dir: string): boolean {
439
+ if (!existsSync(join(dir, '.git'))) return false
440
+ const p = Bun.spawnSync([gitBin(), 'status', '--porcelain', '--untracked-files=all', '--ignore-submodules=none'], { cwd: dir, stdout: 'pipe', stderr: 'ignore' })
441
+ return p.exitCode === 0 && p.stdout.toString().trim() === ''
442
+ }
443
+
402
444
  /** a tree id names its content, so its file list is a pure function of the
403
445
  * id and one listing serves every scan of that tree. `--full-tree` keeps it
404
446
  * so: without it git filters the listing by the cwd's path under the work
@@ -34,6 +34,9 @@ export const KEEP_MS = 30 * 24 * 60 * 60 * 1000
34
34
  * tens of thousands of run rows a day, so age alone is no cap */
35
35
  export const MAX_ROWS = 200_000
36
36
 
37
+ /** the most rows the suites table keeps: it gains one row a test file a run, the fastest of the record */
38
+ export const SUITES_MAX_ROWS = 50_000
39
+
37
40
  /** one check, one run. `ms` is what it MEASURED: a replay measured nothing and
38
41
  * says 0, so the two can never be averaged together by accident. */
39
42
  export type RunRow = {
@@ -240,7 +243,7 @@ const sweepAll = (db: Database, now: number, cutoff: number, max?: number): void
240
243
  db.query('delete from suites where at < ?').run(cutoff)
241
244
  db.query('delete from suite_runs where at < ?').run(cutoff)
242
245
  if (max == null) return
243
- for (const [table, col] of RECORD_TABLES) db.query(`delete from ${table} where rowid in (select rowid from ${table} order by ${col} desc limit -1 offset ?)`).run(max)
246
+ for (const [table, col] of RECORD_TABLES) db.query(`delete from ${table} where rowid in (select rowid from ${table} order by ${col} desc limit -1 offset ?)`).run(table === 'suites' ? Math.min(max, SUITES_MAX_ROWS) : max)
244
247
  }
245
248
 
246
249
  /** every record table and the column its age is read from */
@@ -362,8 +365,9 @@ export function readLastStatusReadonly(path: string, o: { lines?: boolean } = {}
362
365
  }
363
366
 
364
367
  /** every check's last result and how many runs in a row ended on that same
365
- * status: what the planner hands a check's `every` lambda. `{}` when the
366
- * record cannot be read, so a plan look never crashes on it */
368
+ * status: what the planner hands a check's `every` lambda. A check with no
369
+ * row left in the history answers from its last outcome on record, streak 1.
370
+ * `{}` when the record cannot be read, so a plan look never crashes on it */
367
371
  export function readLastResults(path: string): Record<string, { status: RunStatus; at: number; streak: number }> {
368
372
  const opened = openDb(path, { create: false })
369
373
  if (opened == null) return {}
@@ -376,6 +380,10 @@ export function readLastResults(path: string): Record<string, { status: RunStatu
376
380
  from (select d.id as id, (select r3.rowid from runs r3 where r3.id = d.id order by r3.at desc, r3.rowid desc limit 1) as rid from (select distinct id from runs) d) x
377
381
  join runs l on l.rowid = x.rid`).all() as { id: string; status: string; at: number; streak: number }[]
378
382
  for (const r of rows) out[r.id] = { status: r.status as RunStatus, at: Number(r.at), streak: Math.max(1, Number(r.streak)) }
383
+ // the history is capped (MAX_ROWS, KEEP_MS) and check_last is not: a check whose rows left the history still
384
+ // has the last outcome every page shows, and the plan must read that same answer
385
+ for (const r of opened.db.query('select id, status, at from check_last').all() as { id: string; status: string; at: number }[])
386
+ out[r.id] ??= { status: r.status as RunStatus, at: Number(r.at), streak: 1 }
379
387
  } catch {
380
388
  return {}
381
389
  } finally {
@@ -52,6 +52,15 @@ export const KEEP_MS = 14 * 24 * 60 * 60 * 1000
52
52
  * dozens of distinct trees; past it the least recently used go first. */
53
53
  export const MAX_ANSWERS = 5_000
54
54
 
55
+ /** the most answers ONE check keeps, the most recently used: each is one state of the tree, and a state older than
56
+ * that many gates is asked again once when it comes back */
57
+ export const MAX_A_CHECK = 40
58
+
59
+ /** a row whose payload holds the key parts it was stored under */
60
+ const HOLDS_PARTS = `instr(payload, '"components":[') > 0 and json_type(payload, '$.components') is not null`
61
+ /** the newest row of each check, as latest() reads it */
62
+ const NEWEST_OF_EACH = 'select rowid from (select rowid, row_number() over (partition by ns, name order by at desc, rowid desc) as n from answers) where n = 1'
63
+
55
64
  /** the import takes json answers this young only: every edit of shipkit moves
56
65
  * every key, so an older answer is one no gate asks for again */
57
66
  export const IMPORT_MAX_AGE_MS = 24 * 60 * 60 * 1000
@@ -140,8 +149,11 @@ export class Answers {
140
149
  // the import never overwrites a row a gate already wrote
141
150
  const put = h.query(`insert or ${o.keepNewer === true ? 'ignore' : 'replace'} into answers (ns, name, key, v, at, keeps, used, payload) values (?, ?, ?, ?, ?, ?, ?, ?)`)
142
151
  const use = h.query('update answers set used = max(used, ?) where ns = ? and name = ? and key = ?')
152
+ const cut = h.query(`update answers set payload = json_remove(payload, '$.components') where ns = ? and name = ? and ${HOLDS_PARTS} and rowid = (select rowid from answers where ns = ? and name = ? order by at desc, rowid desc limit 1 offset 1)`)
143
153
  h.transaction(() => {
144
154
  for (const r of rows) put.run(r.ns, r.name, r.key, STORE_VERSION, r.at, r.keeps ?? null, Math.max(r.at, now), JSON.stringify(r.payload))
155
+ // one row a check, the one the write just made second: every older one was cut when it became second
156
+ for (const k of new Set(rows.map((r) => `${r.ns}\0${r.name}`))) cut.run(...(k.split('\0') as [string, string]), ...(k.split('\0') as [string, string]))
145
157
  for (const t of o.touched ?? []) use.run(now, t.ns, t.name, t.key)
146
158
  }).immediate()
147
159
  return true
@@ -167,7 +179,7 @@ export class Answers {
167
179
  /** the newest answer of one check under ANY key: what a miss diffs its
168
180
  * own key against, to say what moved */
169
181
  latest<T>(ns: string, name: string): Stored<T> | null {
170
- const row = this.with(READ_BUSY_MS, (h) => h.query('select v, key, at, keeps, payload from answers where ns = ? and name = ? order by at desc limit 1').get(ns, name) as (Row & { key: string }) | null)
182
+ const row = this.with(READ_BUSY_MS, (h) => h.query('select v, key, at, keeps, payload from answers where ns = ? and name = ? order by at desc, rowid desc limit 1').get(ns, name) as (Row & { key: string }) | null)
171
183
  if (row == null) return null
172
184
  try {
173
185
  const payload = JSON.parse(row.payload) as T
@@ -211,14 +223,23 @@ export class Answers {
211
223
  return r == null ? null : { count: Number(r.n), oldestUsed: r.oldest }
212
224
  }
213
225
 
226
+ /** the key parts cut from every answer that is not the newest of its check: a miss reads them from the newest
227
+ * alone (latest), and one list of them is tens of kB. How many rows it cut, null when the db could not be opened.
228
+ * The text test is the cheap half, json_type the exact one (a line of a check can hold the same words) */
229
+ slim(): number | null {
230
+ return this.with(BUSY_MS, (h) => h.query(`update answers set payload = json_remove(payload, '$.components') where ${HOLDS_PARTS} and rowid not in (${NEWEST_OF_EACH})`).run().changes)
231
+ }
232
+
214
233
  /** the cap, enforced: rows not written nor replayed for `keepMs` go, then
215
- * the least recently used past `max`. A DELETE, so a row written while it
234
+ * the least recently used past `max`, then past `maxACheck` of one check. A DELETE, so a row written while it
216
235
  * runs is kept. How many went, null when the db could not be opened. */
217
- sweep(now: number, o: { keepMs?: number; max?: number } = {}): number | null {
236
+ sweep(now: number, o: { keepMs?: number; max?: number; maxACheck?: number } = {}): number | null {
218
237
  return this.with(BUSY_MS, (h) => {
219
238
  // a forever answer is a decided fact: dropping it re-asks the world
220
239
  let n = h.query('delete from answers where used < ? and coalesce(keeps, 0) < ?').run(now - (o.keepMs ?? KEEP_MS), FOREVER_MS).changes
221
240
  n += h.query('delete from answers where rowid in (select rowid from answers where coalesce(keeps, 0) < ? order by used desc limit -1 offset ?)').run(FOREVER_MS, o.max ?? MAX_ANSWERS).changes
241
+ // one check, its most recently used answers: a forever answer is neither counted nor dropped
242
+ n += h.query('delete from answers where rowid in (select rowid from (select rowid, row_number() over (partition by ns, name order by used desc, rowid desc) as n from answers where coalesce(keeps, 0) < ?) where n > ?)').run(FOREVER_MS, o.maxACheck ?? MAX_A_CHECK).changes
222
243
  return n
223
244
  })
224
245
  }
@@ -244,7 +265,8 @@ export const listAnswers = (db: string, ns: string): { name: string; at: number;
244
265
  export const answersStamp = (db: string, ns: string): string => withAnswers(db, (a) => a.stamp(ns))
245
266
  export const answerMeasures = (db: string, ns: string): { name: string; at: number; ms: unknown; status: unknown }[] => withAnswers(db, (a) => a.measures(ns))
246
267
  export const answersUse = (db: string): AnswersUse | null => withAnswers(db, (a) => a.use())
247
- export const sweepAnswers = (db: string, now: number, o?: { keepMs?: number; max?: number }): number | null => withAnswers(db, (a) => a.sweep(now, o))
268
+ export const slimAnswers = (db: string): number | null => withAnswers(db, (a) => a.slim())
269
+ export const sweepAnswers = (db: string, now: number, o?: { keepMs?: number; max?: number; maxACheck?: number }): number | null => withAnswers(db, (a) => a.sweep(now, o))
248
270
 
249
271
  /** the migration: the json answers of the pre-db store read into the table
250
272
  * once, then the dir deleted. An answer older than IMPORT_MAX_AGE_MS is not
@@ -4,11 +4,12 @@
4
4
  // the last look kept; a full walk every SAFETY_MS catches what no event told. Once the stamp moved and then held
5
5
  // still for one look (or waited WAIT_MAX_MS while sources kept moving), a run, at most one each 10 min; a run every
6
6
  // 6 h whatever moved, which reads every byte again
7
- import { machineGet, machineSet } from '../../core/machine-db.ts'
7
+ import { machineGet, machineHeld, machineSet } from '../../core/machine-db.ts'
8
8
  import type { RepoBackup } from '../../repo-config.ts'
9
9
  import type { Space } from '../space.ts'
10
10
  import { backupRun, lastRun } from './run.ts'
11
- import { backupOfRepo, collect, localFiles, missedBy, movesLocals, patchLocals, refreshSources, stampOfSources, type Collect, type Source } from './sources.ts'
11
+ import { keepSources, keptSources, keptStamp, patchSources } from './kept.ts'
12
+ import { backupOfRepo, collect, localFiles, lookScope, missedBy, movesLocals, patchLocals, refreshSources, type Collect, type Source } from './sources.ts'
12
13
 
13
14
  /** the daemon looks this often: a look starts the child only when `backupDue` says so */
14
15
  export const BACKUP_EVERY_MS = 120_000
@@ -27,8 +28,6 @@ const LOCALS_MS = 30 * 60_000
27
28
  export const STAMPS = 'backup-stamps'
28
29
  const LOCALS = 'backup-locals'
29
30
  const NO_SPACE = 'backup-no-space'
30
- /** the list the last look kept, so the next one reads only what moved */
31
- const SOURCES = 'backup-sources'
32
31
  /** the paths the daemon heard, handed to the look it starts: kept undone until a look took them */
33
32
  export const BATCH = 'backup-moved'
34
33
  /** each repo's `backup.paths`, for the daemon's watch: a look writes them, the watch reads them */
@@ -39,6 +38,17 @@ export type Stamps = { seen: string; ran: string; fullAt?: number; waitAt?: numb
39
38
  export type Batch = { paths: string[]; all: boolean; done: boolean }
40
39
  type Locals = Record<string, { at: number; files: string[] }>
41
40
 
41
+ /** each repo's `*.local.*` files as the daemon's looks keep them, for a reader that only looks (`sk backup --check`):
42
+ * the kept list while it is fresh, else the repo's own git walk, which takes seconds in a repo with a large ignored
43
+ * folder. Nothing is written */
44
+ export function keptLocals(now: () => number = Date.now): (repo: string) => Promise<string[]> {
45
+ const locals: Locals = machineGet<Locals>(LOCALS) ?? {}
46
+ return async (repo) => {
47
+ const held = locals[repo]
48
+ return held && now() - held.at < LOCALS_MS ? held.files : localFiles(repo)
49
+ }
50
+ }
51
+
42
52
  export interface BackupTick {
43
53
  home: string
44
54
  repos: string[]
@@ -67,7 +77,9 @@ export function backupDue(now: number, heard: boolean): boolean {
67
77
  /** one look of the daemon's backup job, in its child process: the moved paths read again (or every source, on the
68
78
  * safety clock), then a run when it is due. What a look remembers lives in the machine db, so a daemon restart
69
79
  * never makes a run of its own */
70
- export async function backupTick(o: BackupTick): Promise<void> {
80
+ export const backupTick = (o: BackupTick): Promise<void> => machineHeld(() => tick(o))
81
+
82
+ async function tick(o: BackupTick): Promise<void> {
71
83
  const now = o.now ?? Date.now
72
84
  const locals: Locals = machineGet<Locals>(LOCALS) ?? {}
73
85
  let walked = false
@@ -84,12 +96,13 @@ export async function backupTick(o: BackupTick): Promise<void> {
84
96
  const held: Stamps = machineGet<Stamps>(STAMPS) ?? { seen: '', ran: '' }
85
97
  const batch = machineGet<Batch>(BATCH)
86
98
  const moved = batch && !batch.done ? batch.paths : []
87
- const prev = machineGet<Source[]>(SOURCES)
99
+ // the list the last look kept, as rows (kept.ts): a look reads and writes only those under what moved
100
+ const keptList = keptStamp() != null
88
101
  const last = lastRun()
89
102
  const since = last ? started - Date.parse(last.at) : Infinity
90
103
  const sixHours = since >= EVERY_MS
91
104
  const all = batch?.done === false && batch.all
92
- const full = prev == null || all || started - (held.fullAt ?? 0) >= SAFETY_MS || sixHours
105
+ const full = !keptList || all || started - (held.fullAt ?? 0) >= SAFETY_MS || sixHours
93
106
  // a heard `*.local.*` path is read again in the kept git walk, alone
94
107
  for (const r of new Set(moved.map((p) => movesLocals(p, o.repos)).filter((r) => r != null))) {
95
108
  const kept = locals[r]
@@ -106,19 +119,25 @@ export async function backupTick(o: BackupTick): Promise<void> {
106
119
  return b
107
120
  }
108
121
  const c: Collect = { home: o.home, repos: o.repos, locals: cachedLocals, backupOf }
109
- // on a full walk, what the events told is read first: what the walk finds beyond it, no event told
110
- const told = full && prev != null && !all ? await refreshSources(prev, moved, c) : null
111
- const list = full ? await collect(c) : await refreshSources(prev, moved, c)
112
- if (told != null) {
113
- // said: a watch that went quiet is seen here, not after a lost file
114
- const missed = missedBy(told, list)
115
- if (missed.length > 0) o.printErr(`note: backup: the safety walk found ${missed.length} changes no file event told, first ${missed[0]}`)
122
+ let list: Source[] | null = null
123
+ let stamp: string
124
+ if (full) {
125
+ // on a full walk, what the events told is read first: what the walk finds beyond it, no event told
126
+ const told = keptList && !all ? await refreshSources(keptSources(o.home) ?? [], moved, c) : null
127
+ list = await collect(c)
128
+ if (told != null) {
129
+ // said: a watch that went quiet is seen here, not after a lost file
130
+ const missed = missedBy(told, list)
131
+ if (missed.length > 0) o.printErr(`note: backup: the safety walk found ${missed.length} changes no file event told, first ${missed[0]}`)
132
+ }
133
+ stamp = keepSources(list)
134
+ } else {
135
+ const scope = lookScope(moved, o.repos)
136
+ stamp = patchSources(o.home, scope, await collect({ ...c, scope }))
116
137
  }
117
138
  if (walked) machineSet(LOCALS, locals)
118
139
  if (JSON.stringify(named) !== namedWas) machineSet(NAMED, named)
119
- machineSet(SOURCES, list)
120
140
  if (batch && !batch.done) machineSet(BATCH, { ...batch, done: true } satisfies Batch)
121
- const stamp = stampOfSources(list)
122
141
  const waitAt = stamp === held.ran ? undefined : (held.waitAt ?? started)
123
142
  const waited = waitAt != null && started - waitAt >= WAIT_MAX_MS
124
143
  const due = sixHours || (stamp !== held.ran && (stamp === held.seen || waited) && since >= FLOOR_MS)
@@ -133,7 +152,7 @@ export async function backupTick(o: BackupTick): Promise<void> {
133
152
  return
134
153
  }
135
154
  machineSet(NO_SPACE, '')
136
- const r = await backupRun(space, { ...c, sources: list, rehash: sixHours, now: new Date(now()) })
155
+ const r = await backupRun(space, { ...c, sources: list ?? keptSources(o.home) ?? [], rehash: sixHours, now: new Date(now()) })
137
156
  if (r.failed.length === 0) machineSet(STAMPS, { seen: stamp, ran: stamp, ...(fullAt != null ? { fullAt } : {}) } satisfies Stamps)
138
157
  if (r.failed.length > 0) o.printErr(`WARN backup: ${r.failed.length} objects did not go up, no manifest written; first: ${r.failed[0]?.key}: ${r.failed[0]?.error}`)
139
158
  else if (r.manifest) o.print(`ok: backup: ${r.files} files, ${r.sent} objects up (${(r.sentBytes / 1e6).toFixed(1)} MB), ${r.read} read again, ${r.refused.length} refused, manifest ${r.manifest}`)