rvlib-shipkit 2.26.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 (442) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/package.json +1 -1
  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 +6 -4
  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 +122 -21
  11. package/src/agent-time/report-cache.ts +57 -0
  12. package/src/agent-time/report.ts +314 -40
  13. package/src/agent-time/shape.ts +50 -3
  14. package/src/agent-time/store.ts +320 -99
  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/SK047-login-in-description.check.ts +36 -0
  34. package/src/checks/SK048-one-local-file.check.ts +36 -0
  35. package/src/cli/cmd_Asks.ts +71 -5
  36. package/src/cli/cmd_Backup.ts +2 -2
  37. package/src/cli/cmd_Capacity.ts +2 -2
  38. package/src/cli/cmd_CrossRepoActivity.ts +5 -4
  39. package/src/cli/cmd_Db.ts +253 -0
  40. package/src/cli/cmd_History.ts +212 -0
  41. package/src/cli/cmd_Home.ts +31 -3
  42. package/src/cli/cmd_Hq.ts +516 -0
  43. package/src/cli/cmd_Machines.ts +36 -0
  44. package/src/cli/cmd_Media.ts +38 -6
  45. package/src/cli/cmd_Reflect.ts +23 -2
  46. package/src/cli/cmd_Review.ts +548 -116
  47. package/src/cli/cmd_Secret.ts +62 -12
  48. package/src/cli/cmd_Social.ts +83 -1
  49. package/src/cli/cmd_Space.ts +324 -0
  50. package/src/cli/cmd_Time.ts +76 -5
  51. package/src/cli/cmd_Tmp.ts +28 -4
  52. package/src/cli/cmd_Trailer.ts +14 -10
  53. package/src/cli/cmd_Urls.ts +56 -0
  54. package/src/cli/cmd_Vault.ts +583 -0
  55. package/src/cli/family-help.ts +4 -2
  56. package/src/cli/family-pages.ts +1 -1
  57. package/src/cli/registry.ts +24 -3
  58. package/src/collections/actions.ts +63 -13
  59. package/src/collections/collection-types.ts +23 -1
  60. package/src/collections/providers.ts +117 -23
  61. package/src/collections/review.ts +4 -4
  62. package/src/contracts/contract-manifests.ts +6 -5
  63. package/src/contracts/contract-types.ts +6 -4
  64. package/src/contracts/contracts-engine.ts +11 -0
  65. package/src/contracts/manifests/chrome-web-store.contract.ts +31 -0
  66. package/src/core/budget.ts +12 -17
  67. package/src/core/capacity.ts +27 -18
  68. package/src/core/check-runner.ts +7 -4
  69. package/src/core/layout.ts +3 -0
  70. package/src/core/machine-busy.ts +127 -0
  71. package/src/core/machine-commit.ts +6 -1
  72. package/src/core/machine-db.ts +368 -20
  73. package/src/core/machine-layout.ts +137 -0
  74. package/src/core/machine-read.ts +81 -0
  75. package/src/core/migrate-layout.ts +1 -1
  76. package/src/core/one-way-in-policy.ts +64 -7
  77. package/src/core/polling-policy.ts +27 -0
  78. package/src/core/retention.ts +16 -2
  79. package/src/core/scope.ts +107 -14
  80. package/src/core/slots.ts +5 -4
  81. package/src/drill/clean.ts +25 -1
  82. package/src/drill/run.ts +1 -1
  83. package/src/drill/seal.ts +27 -4
  84. package/src/home/activity-shape.ts +2 -0
  85. package/src/home/activity.ts +66 -3
  86. package/src/home/app-sign.ts +15 -4
  87. package/src/home/daemon-jobs.ts +149 -7
  88. package/src/home/database-projects.ts +111 -0
  89. package/src/home/database-words.ts +203 -0
  90. package/src/home/databases.ts +460 -0
  91. package/src/home/global-units.ts +6 -0
  92. package/src/home/gui-app/ShipkitGui.swift +122 -1
  93. package/src/home/gui-app.ts +6 -3
  94. package/src/home/home-move.ts +514 -0
  95. package/src/home/home-paths.ts +12 -3
  96. package/src/home/home-routes.ts +68 -0
  97. package/src/home/inbox-shape.ts +24 -14
  98. package/src/home/machine-fold.ts +820 -0
  99. package/src/home/machine-host.ts +20 -5
  100. package/src/home/machine-repair.ts +503 -0
  101. package/src/home/machine-stores.ts +66 -15
  102. package/src/home/machine-temp.ts +547 -86
  103. package/src/home/resume.ts +79 -0
  104. package/src/home/run-daemon.ts +25 -4
  105. package/src/home/run-pm.ts +18 -5
  106. package/src/home/serve-daemon.ts +18 -3
  107. package/src/home/serve-web.ts +175 -7
  108. package/src/home/space-job.ts +115 -0
  109. package/src/home/space-page.ts +257 -0
  110. package/src/home/space-route.ts +167 -0
  111. package/src/home/space-words.ts +103 -0
  112. package/src/home/time-page-shape.ts +202 -0
  113. package/src/home/time-page.ts +64 -0
  114. package/src/home/vault-page.ts +482 -0
  115. package/src/home/vault-words.ts +132 -0
  116. package/src/hooks/leak-guard.ts +40 -13
  117. package/src/hooks/one-way-in-guard.ts +17 -4
  118. package/src/hq/cards.ts +581 -0
  119. package/src/hq/door-route.ts +43 -0
  120. package/src/hq/door.ts +163 -0
  121. package/src/hq/files-send.ts +348 -0
  122. package/src/hq/forgotten-log.ts +35 -0
  123. package/src/hq/history-check.ts +255 -0
  124. package/src/hq/history-place.ts +146 -0
  125. package/src/hq/history-send.ts +487 -0
  126. package/src/hq/hq-db.ts +99 -0
  127. package/src/hq/hq-local.ts +469 -0
  128. package/src/hq/hq-routes.ts +196 -0
  129. package/src/hq/hq-store.ts +599 -0
  130. package/src/hq/kinds/ask.ts +147 -0
  131. package/src/hq/kinds/card-gone.ts +83 -0
  132. package/src/hq/kinds/card-msg.ts +66 -0
  133. package/src/hq/kinds/card.ts +99 -0
  134. package/src/hq/kinds/index.ts +21 -0
  135. package/src/hq/kinds/kind.ts +126 -0
  136. package/src/hq/kinds/media.ts +125 -0
  137. package/src/hq/kinds/prompt.ts +219 -0
  138. package/src/hq/kinds/reflection.ts +128 -0
  139. package/src/hq/kinds/report.ts +55 -0
  140. package/src/hq/kinds/time-day.ts +236 -0
  141. package/src/hq/ledger.ts +473 -0
  142. package/src/hq/machine-key.ts +44 -0
  143. package/src/hq/machine-notes.ts +131 -0
  144. package/src/hq/outbox.ts +372 -0
  145. package/src/hq/replica.ts +168 -0
  146. package/src/hq/repo-id.ts +4 -0
  147. package/src/hq/report-facts.ts +117 -0
  148. package/src/hq/report.ts +274 -0
  149. package/src/hq/switch.ts +151 -0
  150. package/src/hq/vault-grant.ts +92 -0
  151. package/src/identities/identities.ts +15 -3
  152. package/src/identities/steps.ts +31 -0
  153. package/src/ledger/db.ts +73 -26
  154. package/src/ledger/gate-checks.ts +6 -2
  155. package/src/ledger/run-log.ts +11 -3
  156. package/src/ledger/store.ts +26 -4
  157. package/src/media-store/backup/daemon.ts +25 -17
  158. package/src/media-store/backup/kept.ts +241 -0
  159. package/src/media-store/backup/restore.ts +14 -4
  160. package/src/media-store/backup/run.ts +11 -11
  161. package/src/media-store/backup/secret.ts +6 -4
  162. package/src/media-store/backup/snapshot.ts +4 -2
  163. package/src/media-store/backup/sources.ts +67 -16
  164. package/src/media-store/copy/config.ts +77 -0
  165. package/src/media-store/copy/copy.ts +194 -0
  166. package/src/media-store/copy/lifecycle.ts +43 -0
  167. package/src/media-store/copy/night.ts +90 -0
  168. package/src/media-store/copy/proof.ts +151 -0
  169. package/src/media-store/copy/snapshot.ts +152 -0
  170. package/src/media-store/copy/store.ts +62 -0
  171. package/src/media-store/copy/stream.ts +176 -0
  172. package/src/media-store/daemon.ts +66 -16
  173. package/src/media-store/db.ts +22 -11
  174. package/src/media-store/forget.ts +23 -3
  175. package/src/media-store/hand.ts +4 -3
  176. package/src/media-store/hq-find.ts +75 -0
  177. package/src/media-store/hq-send.ts +277 -0
  178. package/src/media-store/kind.ts +2 -0
  179. package/src/media-store/purge.ts +18 -15
  180. package/src/media-store/put.ts +24 -8
  181. package/src/media-store/remote.ts +16 -7
  182. package/src/media-store/space-listing.ts +240 -0
  183. package/src/media-store/space.ts +40 -21
  184. package/src/media-store/sync.ts +5 -5
  185. package/src/media-store/tidy.ts +98 -0
  186. package/src/media-store/upload.ts +3 -3
  187. package/src/media-store/webp.ts +66 -0
  188. package/src/messages/model.ts +16 -7
  189. package/src/messages/routes.ts +14 -4
  190. package/src/messages/score.ts +2 -2
  191. package/src/messages/suggest.ts +96 -0
  192. package/src/pages/frame-client.ts +10 -0
  193. package/src/plan/planner.ts +28 -17
  194. package/src/recordings/media-kind.ts +1 -0
  195. package/src/recordings/model.ts +1 -1
  196. package/src/recordings/recorder-app/Capture.swift +9 -7
  197. package/src/reflect/hq-corpus.ts +56 -0
  198. package/src/reflect/prompt-corpus.ts +3 -1
  199. package/src/reflect/transcript.ts +129 -37
  200. package/src/release/machine-words.ts +67 -0
  201. package/src/release/public-clean.ts +8 -3
  202. package/src/releases/from-card.ts +1 -1
  203. package/src/releases/routes.ts +10 -5
  204. package/src/releases/store.ts +10 -1
  205. package/src/repo-config.ts +32 -2
  206. package/src/review/anim.ts +2 -2
  207. package/src/review/auto.ts +2 -2
  208. package/src/review/card-db.ts +244 -0
  209. package/src/review/card-rows.ts +266 -0
  210. package/src/review/cells.ts +76 -5
  211. package/src/review/draft-card.ts +41 -0
  212. package/src/review/draft-model.ts +78 -0
  213. package/src/review/format.ts +29 -10
  214. package/src/review/gone.ts +98 -0
  215. package/src/review/inbox-hook.ts +4 -4
  216. package/src/review/marks.ts +1 -1
  217. package/src/review/media-kind.ts +7 -5
  218. package/src/review/media-read.ts +9 -7
  219. package/src/review/media.ts +32 -5
  220. package/src/review/model.ts +202 -39
  221. package/src/review/move.ts +491 -0
  222. package/src/review/notes.ts +12 -20
  223. package/src/review/previews.ts +15 -19
  224. package/src/review/project.ts +1 -1
  225. package/src/review/rev.ts +8 -0
  226. package/src/review/role.ts +1 -1
  227. package/src/review/routes.ts +64 -13
  228. package/src/review/stage-card.ts +8 -4
  229. package/src/review/stage-routes.ts +1 -1
  230. package/src/review/store.ts +529 -83
  231. package/src/review/thread-fold.ts +51 -0
  232. package/src/review/threads.ts +147 -9
  233. package/src/review/trailer-auto-mock.ts +63 -0
  234. package/src/review/trailer-card.ts +4 -4
  235. package/src/review/trailer-desk.ts +41 -7
  236. package/src/review/trailer-media.ts +1 -0
  237. package/src/review/trailer-model.ts +8 -0
  238. package/src/review/trailer-notes.ts +1 -1
  239. package/src/review/trailer-routes.ts +9 -1
  240. package/src/review/unit.ts +6 -6
  241. package/src/review/watchers.ts +1 -1
  242. package/src/rules/untrack-generated.ts +92 -8
  243. package/src/secrets/held.ts +16 -0
  244. package/src/secrets/keychain.ts +113 -0
  245. package/src/secrets/list.ts +16 -6
  246. package/src/secrets/manager.ts +24 -10
  247. package/src/secrets/read.ts +257 -0
  248. package/src/secrets/who-reads.ts +49 -0
  249. package/src/serve/door-forward.ts +268 -0
  250. package/src/serve/door-names.ts +47 -0
  251. package/src/serve/embed.ts +1 -1
  252. package/src/serve/hub-app/activity-view.tsx +56 -32
  253. package/src/serve/hub-app/activity.css +7 -1
  254. package/src/serve/hub-app/asks-page.tsx +48 -0
  255. package/src/serve/hub-app/asks-st.ts +25 -0
  256. package/src/serve/hub-app/clock-svc.ts +1 -2
  257. package/src/serve/hub-app/col-card.tsx +64 -13
  258. package/src/serve/hub-app/col-list-page.tsx +122 -0
  259. package/src/serve/hub-app/col-list-st.ts +103 -0
  260. package/src/serve/hub-app/col-tables-view.tsx +10 -41
  261. package/src/serve/hub-app/col-tables.ts +76 -8
  262. package/src/serve/hub-app/cols-svc.ts +70 -16
  263. package/src/serve/hub-app/database-st.ts +260 -0
  264. package/src/serve/hub-app/database-view.tsx +289 -0
  265. package/src/serve/hub-app/database.css +32 -0
  266. package/src/serve/hub-app/entry-bar.css +14 -0
  267. package/src/serve/hub-app/entry-bar.tsx +33 -0
  268. package/src/serve/hub-app/entry-pick.ts +31 -0
  269. package/src/serve/hub-app/floating.tsx +1 -0
  270. package/src/serve/hub-app/hash-route.ts +11 -1
  271. package/src/serve/hub-app/header-bar.tsx +14 -18
  272. package/src/serve/hub-app/home-st.ts +89 -9
  273. package/src/serve/hub-app/home-strip.css +5 -19
  274. package/src/serve/hub-app/home-strip.tsx +58 -92
  275. package/src/serve/hub-app/home.html +7 -0
  276. package/src/serve/hub-app/hub-app.tsx +31 -142
  277. package/src/serve/hub-app/hub-types.ts +3 -1
  278. package/src/serve/hub-app/hub.css +109 -23
  279. package/src/serve/hub-app/icons.tsx +18 -1
  280. package/src/serve/hub-app/identities-st.ts +56 -6
  281. package/src/serve/hub-app/identities-view.tsx +100 -58
  282. package/src/serve/hub-app/identities.css +17 -15
  283. package/src/serve/hub-app/identity-address.ts +5 -0
  284. package/src/serve/hub-app/inbox-st.ts +41 -24
  285. package/src/serve/hub-app/inbox-view.tsx +37 -41
  286. package/src/serve/hub-app/inbox.css +2 -5
  287. package/src/serve/hub-app/index.html +7 -0
  288. package/src/serve/hub-app/kept-cols.tsx +7 -0
  289. package/src/serve/hub-app/keys.ts +28 -15
  290. package/src/serve/hub-app/later.tsx +26 -0
  291. package/src/serve/hub-app/list-filter.tsx +14 -0
  292. package/src/serve/hub-app/list-walk.ts +72 -3
  293. package/src/serve/hub-app/machines-st.ts +251 -0
  294. package/src/serve/hub-app/machines-view.tsx +224 -0
  295. package/src/serve/hub-app/machines.css +76 -0
  296. package/src/serve/hub-app/md-copy.tsx +79 -0
  297. package/src/serve/hub-app/media-view.tsx +2 -0
  298. package/src/serve/hub-app/messages/messages-page.tsx +79 -7
  299. package/src/serve/hub-app/messages/messages-st.ts +99 -3
  300. package/src/serve/hub-app/messages.css +14 -0
  301. package/src/serve/hub-app/page-keys.ts +175 -0
  302. package/src/serve/hub-app/pages-frames.tsx +11 -3
  303. package/src/serve/hub-app/palette-st.ts +58 -11
  304. package/src/serve/hub-app/palette-view.tsx +3 -1
  305. package/src/serve/hub-app/project-list.css +54 -8
  306. package/src/serve/hub-app/project-list.tsx +128 -59
  307. package/src/serve/hub-app/projects-svc.ts +78 -7
  308. package/src/serve/hub-app/reader-chips.tsx +13 -0
  309. package/src/serve/hub-app/readme-view.tsx +2 -3
  310. package/src/serve/hub-app/readme.css +27 -5
  311. package/src/serve/hub-app/reflections-page.tsx +42 -0
  312. package/src/serve/hub-app/reflections-st.ts +17 -0
  313. package/src/serve/hub-app/releases/releases-page.tsx +25 -2
  314. package/src/serve/hub-app/releases/releases-st.ts +1 -1
  315. package/src/serve/hub-app/repo-sections.ts +9 -5
  316. package/src/serve/hub-app/repo-st.ts +35 -8
  317. package/src/serve/hub-app/review/draft-card.tsx +163 -0
  318. package/src/serve/hub-app/review/kit.tsx +50 -7
  319. package/src/serve/hub-app/review/note-place.ts +1 -1
  320. package/src/serve/hub-app/review/review-board.tsx +2 -2
  321. package/src/serve/hub-app/review/review-cells.tsx +145 -65
  322. package/src/serve/hub-app/review/review-kit.ts +27 -1
  323. package/src/serve/hub-app/review/review-list.tsx +68 -30
  324. package/src/serve/hub-app/review/review-page.tsx +7 -8
  325. package/src/serve/hub-app/review/review-st.ts +111 -24
  326. package/src/serve/hub-app/review/review-thread.tsx +49 -19
  327. package/src/serve/hub-app/review/review-views.tsx +475 -144
  328. package/src/serve/hub-app/review/thread-control-st.ts +115 -0
  329. package/src/serve/hub-app/review/thread-control.tsx +74 -0
  330. package/src/serve/hub-app/review/thread-st.ts +73 -26
  331. package/src/serve/hub-app/review/trailer-card.tsx +1 -1
  332. package/src/serve/hub-app/review/trailer-page.tsx +37 -16
  333. package/src/serve/hub-app/review/trailer-st.ts +41 -7
  334. package/src/serve/hub-app/review.css +267 -61
  335. package/src/serve/hub-app/side-lists.ts +72 -0
  336. package/src/serve/hub-app/sidebar.tsx +6 -3
  337. package/src/serve/hub-app/site/site-part.tsx +2 -8
  338. package/src/serve/hub-app/site/site-st.ts +4 -4
  339. package/src/serve/hub-app/social/comms-page.tsx +20 -5
  340. package/src/serve/hub-app/social/kit.tsx +30 -4
  341. package/src/serve/hub-app/social/post-card.tsx +139 -49
  342. package/src/serve/hub-app/social/serial-writes.ts +13 -0
  343. package/src/serve/hub-app/social/social-model.ts +11 -0
  344. package/src/serve/hub-app/social/social-page.tsx +94 -35
  345. package/src/serve/hub-app/social/social-st.ts +120 -36
  346. package/src/serve/hub-app/social/stage-popup.tsx +1 -1
  347. package/src/serve/hub-app/social/stage-st.ts +1 -1
  348. package/src/serve/hub-app/social/step-layout.ts +1 -1
  349. package/src/serve/hub-app/social.css +3 -0
  350. package/src/serve/hub-app/space-st.ts +209 -0
  351. package/src/serve/hub-app/space-view.tsx +196 -0
  352. package/src/serve/hub-app/space.css +27 -0
  353. package/src/serve/hub-app/stores/stores-page.tsx +91 -23
  354. package/src/serve/hub-app/stores/stores-st.ts +44 -19
  355. package/src/serve/hub-app/stores.css +6 -1
  356. package/src/serve/hub-app/theme-st.ts +22 -9
  357. package/src/serve/hub-app/time-charts.tsx +291 -0
  358. package/src/serve/hub-app/time-pages.tsx +749 -0
  359. package/src/serve/hub-app/time-st.ts +162 -0
  360. package/src/serve/hub-app/time-view.tsx +76 -0
  361. package/src/serve/hub-app/time.css +138 -0
  362. package/src/serve/hub-app/tree-build.ts +52 -42
  363. package/src/serve/hub-app/tree-row.tsx +4 -4
  364. package/src/serve/hub-app/tree-svc.ts +18 -9
  365. package/src/serve/hub-app/urls-svc.ts +154 -0
  366. package/src/serve/hub-app/urls-view.tsx +117 -0
  367. package/src/serve/hub-app/urls.css +30 -0
  368. package/src/serve/hub-app/vault-st.ts +127 -0
  369. package/src/serve/hub-app/vault-view.tsx +154 -0
  370. package/src/serve/hub-app/vault.css +38 -0
  371. package/src/serve/hub-app/veille/veille-st.ts +12 -10
  372. package/src/serve/hub-app/waiting-svc.ts +29 -0
  373. package/src/serve/hub-app/wikis-view.tsx +2 -2
  374. package/src/serve/hub-runtime.ts +15 -2
  375. package/src/serve/project-gutter-route.ts +27 -14
  376. package/src/serve/project-gutter.ts +25 -12
  377. package/src/serve/same-origin.ts +10 -0
  378. package/src/serve/serve-hub.ts +13 -4
  379. package/src/shipkit-files.ts +16 -2
  380. package/src/shipkit.ts +1 -1
  381. package/src/shot/shooter.ts +616 -420
  382. package/src/shot/shot-ask.ts +246 -155
  383. package/src/site/desk.ts +2 -2
  384. package/src/smoke/run-smoke.ts +3 -2
  385. package/src/social/cover.ts +202 -0
  386. package/src/social/discord-layout.ts +37 -13
  387. package/src/social/drafts.ts +3 -0
  388. package/src/social/load.ts +23 -2
  389. package/src/social/media-kind.ts +2 -1
  390. package/src/social/publish/discord.ts +5 -2
  391. package/src/social/publish/secret.ts +2 -2
  392. package/src/social/release-stage.ts +28 -13
  393. package/src/social/routes.ts +26 -1
  394. package/src/social/stage.ts +1 -1
  395. package/src/social/stats.ts +12 -9
  396. package/src/social/strip.ts +4 -1
  397. package/src/social/thumbnail.ts +255 -0
  398. package/src/stores/collection.ts +15 -11
  399. package/src/stores/desk.ts +236 -42
  400. package/src/stores/model.ts +72 -6
  401. package/src/stores/routes.ts +37 -12
  402. package/src/stores/unit.ts +14 -8
  403. package/src/suite/judge-suites.ts +41 -11
  404. package/src/suite/select.ts +45 -3
  405. package/src/suite/suite-cli.ts +16 -10
  406. package/src/trailer/bed.ts +1 -1
  407. package/src/trailer/build.ts +134 -21
  408. package/src/trailer/ffmpeg.ts +7 -0
  409. package/src/trailer/fonts.ts +3 -2
  410. package/src/trailer/grammar.ts +201 -2
  411. package/src/trailer/graph.ts +42 -5
  412. package/src/trailer/look.ts +21 -0
  413. package/src/trailer/mock.ts +154 -0
  414. package/src/trailer/passage.ts +65 -26
  415. package/src/trailer/score/heard.ts +89 -0
  416. package/src/trailer/score/sound.ts +14 -8
  417. package/src/trailer/sound/run.ts +16 -6
  418. package/src/trailer/stitch.ts +26 -5
  419. package/src/trailer/titles.ts +82 -19
  420. package/src/trailer/versions.ts +1 -3
  421. package/src/trailer/vertical.ts +3 -1
  422. package/src/urls/frame.ts +195 -0
  423. package/src/urls/routes.ts +43 -0
  424. package/src/urls/rows.ts +171 -0
  425. package/src/urls/unit.ts +73 -0
  426. package/src/vault/house-keys.ts +42 -0
  427. package/src/vault/layout.ts +50 -0
  428. package/src/vault/policy.ts +165 -0
  429. package/src/vault/vault-audit.ts +276 -0
  430. package/src/vault/vault-client.ts +40 -0
  431. package/src/vault/vault-config.ts +159 -0
  432. package/src/vault/vault-destroy.ts +78 -0
  433. package/src/vault/vault-handover.ts +305 -0
  434. package/src/vault/vault-http.ts +352 -0
  435. package/src/vault/vault-import.ts +208 -0
  436. package/src/vault/vault-init.ts +328 -0
  437. package/src/vault/vault-minter.ts +271 -0
  438. package/src/vault/vault-restore.ts +333 -0
  439. package/src/vault/vault-serve.ts +342 -0
  440. package/src/vault/vault-snapshot.ts +281 -0
  441. package/src/veille/asks.ts +1 -1
  442. package/src/veille/desk.ts +2 -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
@@ -77,6 +77,9 @@ export function rawAccessDecl(raw: string, toolkitCheckElsewhere: boolean): Pick
77
77
  }
78
78
 
79
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']))
80
83
 
81
84
  export type TestTier = 'quick' | 'full'
82
85
 
@@ -336,7 +339,8 @@ export async function composeChecks(root: string, c: RepoConfig, o: ComposeOpts
336
339
  const audit = readAuditReport(root)
337
340
  const extrasOf = (id: string): string[] => [...new Set([...ignoredFor(c.ignoredInputs, id), ...auditedExtras(audit, id)])].filter(onDisk).sort()
338
341
  for (const raw of [...floor.tasks, ...(c.tasks ?? []).filter((t) => foldedInto.get(t.id) !== t)]) {
339
- 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
340
344
  const own = t.id === 'test' && floor.tasks.includes(raw) ? rootTest : null
341
345
  const declared = own?.inputs ?? t.inputs
342
346
  // the declared extras join a declared list too: a list names what the
@@ -441,7 +445,7 @@ export async function composeChecks(root: string, c: RepoConfig, o: ComposeOpts
441
445
  ttl: cache.ttl,
442
446
  never: cache.never,
443
447
  argv: u.def.cmd,
444
- 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,
445
449
  writes: u.def.writes,
446
450
  ...(cache.reads === true && raw == null ? { reads: true } : {}),
447
451
  ...(raw != null ? rawAccessDecl(raw, toolkitCheckElsewhere(root, u)) : {}),
@@ -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 */
@@ -78,7 +77,9 @@ export function backupDue(now: number, heard: boolean): boolean {
78
77
  /** one look of the daemon's backup job, in its child process: the moved paths read again (or every source, on the
79
78
  * safety clock), then a run when it is due. What a look remembers lives in the machine db, so a daemon restart
80
79
  * never makes a run of its own */
81
- 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> {
82
83
  const now = o.now ?? Date.now
83
84
  const locals: Locals = machineGet<Locals>(LOCALS) ?? {}
84
85
  let walked = false
@@ -95,12 +96,13 @@ export async function backupTick(o: BackupTick): Promise<void> {
95
96
  const held: Stamps = machineGet<Stamps>(STAMPS) ?? { seen: '', ran: '' }
96
97
  const batch = machineGet<Batch>(BATCH)
97
98
  const moved = batch && !batch.done ? batch.paths : []
98
- 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
99
101
  const last = lastRun()
100
102
  const since = last ? started - Date.parse(last.at) : Infinity
101
103
  const sixHours = since >= EVERY_MS
102
104
  const all = batch?.done === false && batch.all
103
- const full = prev == null || all || started - (held.fullAt ?? 0) >= SAFETY_MS || sixHours
105
+ const full = !keptList || all || started - (held.fullAt ?? 0) >= SAFETY_MS || sixHours
104
106
  // a heard `*.local.*` path is read again in the kept git walk, alone
105
107
  for (const r of new Set(moved.map((p) => movesLocals(p, o.repos)).filter((r) => r != null))) {
106
108
  const kept = locals[r]
@@ -117,19 +119,25 @@ export async function backupTick(o: BackupTick): Promise<void> {
117
119
  return b
118
120
  }
119
121
  const c: Collect = { home: o.home, repos: o.repos, locals: cachedLocals, backupOf }
120
- // on a full walk, what the events told is read first: what the walk finds beyond it, no event told
121
- const told = full && prev != null && !all ? await refreshSources(prev, moved, c) : null
122
- const list = full ? await collect(c) : await refreshSources(prev, moved, c)
123
- if (told != null) {
124
- // said: a watch that went quiet is seen here, not after a lost file
125
- const missed = missedBy(told, list)
126
- 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 }))
127
137
  }
128
138
  if (walked) machineSet(LOCALS, locals)
129
139
  if (JSON.stringify(named) !== namedWas) machineSet(NAMED, named)
130
- machineSet(SOURCES, list)
131
140
  if (batch && !batch.done) machineSet(BATCH, { ...batch, done: true } satisfies Batch)
132
- const stamp = stampOfSources(list)
133
141
  const waitAt = stamp === held.ran ? undefined : (held.waitAt ?? started)
134
142
  const waited = waitAt != null && started - waitAt >= WAIT_MAX_MS
135
143
  const due = sixHours || (stamp !== held.ran && (stamp === held.seen || waited) && since >= FLOOR_MS)
@@ -144,7 +152,7 @@ export async function backupTick(o: BackupTick): Promise<void> {
144
152
  return
145
153
  }
146
154
  machineSet(NO_SPACE, '')
147
- 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()) })
148
156
  if (r.failed.length === 0) machineSet(STAMPS, { seen: stamp, ran: stamp, ...(fullAt != null ? { fullAt } : {}) } satisfies Stamps)
149
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}`)
150
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}`)