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
@@ -0,0 +1,241 @@
1
+ // what the backup keeps between two looks and two runs, as rows of the machine db (core/machine-db.ts owns the
2
+ // tables): the list of sources the last look saw, and every file the last run held with its sha. A look writes only
3
+ // the rows under the paths it heard, and the list's stamp is kept beside them as the xor of each row's hash, so no
4
+ // look reads the list whole. The two json values a file of the older shape holds are imported at the first access,
5
+ // then their key goes; one an older process writes after that is newer than the rows and replaces them
6
+ import type { Database } from 'bun:sqlite'
7
+ import { join, relative, sep } from 'node:path'
8
+ import { machineDb } from '../../core/machine-db.ts'
9
+ import { stampOfSources, type Scope, type Source } from './sources.ts'
10
+
11
+ /** the older shape: the list and the seen files as two json values */
12
+ const OLD_SOURCES = 'backup-sources'
13
+ const OLD_SEEN = 'backup-seen'
14
+ /** the daemon's stamps (daemon.ts STAMPS): translated at the import, so a new formula never reads as a change */
15
+ const STAMPS = 'backup-stamps'
16
+ /** the list's stamp, `{ n, x }`: its rows that are files and the xor of their hashes. Its presence is "a list kept" */
17
+ const XOR = 'backup-sources-xor'
18
+
19
+ export type SeenRow = { size: number; mtime: number; sha: string; key: string }
20
+
21
+ type Row = { rel: string; refused: number; size: number; mtime: number; sqlite: string | null; whole: number; broken: string | null }
22
+
23
+ const rowOf = (s: Source): Row => ({ rel: s.rel, refused: s.broken != null ? 1 : 0, size: s.size, mtime: s.mtime, sqlite: s.sqlite ? JSON.stringify(s.sqlite) : null, whole: s.whole ? 1 : 0, broken: s.broken ?? null })
24
+
25
+ const sourceOf = (r: Row, home: string): Source => ({ abs: join(home, r.rel), rel: r.rel, size: r.size, mtime: r.mtime, ...(r.sqlite != null ? { sqlite: JSON.parse(r.sqlite) } : r.whole === 1 ? { whole: true as const } : {}), ...(r.broken != null ? { broken: r.broken } : {}) })
26
+
27
+ /** the same line stampOfSources hashes, as 64 bits: a sqlite moves by itself and is snapshotted on the clock */
28
+ const hashOf = (r: Pick<Row, 'rel' | 'size' | 'mtime' | 'broken' | 'sqlite'>): bigint => (r.sqlite != null ? 0n : BigInt.asUintN(64, BigInt(Bun.hash.wyhash(`${r.rel}\0${r.size}\0${r.mtime}\0${r.broken ?? ''}\n`))))
29
+
30
+ type Xor = { n: number; x: string }
31
+ const stampText = (n: number, x: bigint): string => `${n}:${x.toString(16).padStart(16, '0')}`
32
+
33
+ /** the stamp of a whole list, as the rows keep it */
34
+ export function stampOfRows(list: readonly Source[]): string {
35
+ let x = 0n
36
+ let n = 0
37
+ for (const s of list) {
38
+ const h = hashOf(rowOf(s))
39
+ if (h === 0n) continue
40
+ x ^= h
41
+ n++
42
+ }
43
+ return stampText(n, x)
44
+ }
45
+
46
+ const ROWS = 'select rel, refused, size, mtime, sqlite, whole, broken from backup_sources'
47
+ const INSERT = 'insert or replace into backup_sources (rel, refused, size, mtime, sqlite, whole, broken) values ($rel, $refused, $size, $mtime, $sqlite, $whole, $broken)'
48
+ const bind = (r: Row): Record<string, string | number | null> => ({ $rel: r.rel, $refused: r.refused, $size: r.size, $mtime: r.mtime, $sqlite: r.sqlite, $whole: r.whole, $broken: r.broken })
49
+
50
+ const readXor = (db: Database): Xor | null => {
51
+ const row = db.query('select value from state where name = ?').get(XOR) as { value: string } | null
52
+ return row == null ? null : (JSON.parse(row.value) as Xor)
53
+ }
54
+ const writeXor = (db: Database, n: number, x: bigint): string => {
55
+ db.query('insert or replace into state (name, value, at) values (?, ?, ?)').run(XOR, JSON.stringify({ n, x: x.toString(16) } satisfies Xor), Date.now())
56
+ return stampText(n, x)
57
+ }
58
+
59
+ /** a value of the older shape, null when absent; one that does not parse goes and is said (an older reader took it
60
+ * as none too) */
61
+ function oldValue<T>(db: Database, name: string): T | null {
62
+ const row = db.query('select value from state where name = ?').get(name) as { value: string } | null
63
+ if (row == null) return null
64
+ try {
65
+ return JSON.parse(row.value) as T
66
+ } catch {
67
+ console.error(`WARN backup: the machine db's ${name} does not parse: it goes, the next look walks every source`)
68
+ db.query('delete from state where name = ?').run(name)
69
+ return null
70
+ }
71
+ }
72
+
73
+ /** the list replaced whole by `list`: only the rows that moved are written. The new stamp */
74
+ function replaceAll(db: Database, list: readonly Source[]): string {
75
+ const held = new Map<string, Row>()
76
+ for (const r of db.query(ROWS).all() as Row[]) held.set(`${r.rel}\0${r.refused}`, r)
77
+ const put = db.query(INSERT)
78
+ const drop = db.query('delete from backup_sources where rel = ? and refused = ?')
79
+ let x = 0n
80
+ let n = 0
81
+ for (const s of list) {
82
+ const r = rowOf(s)
83
+ const k = `${r.rel}\0${r.refused}`
84
+ const was = held.get(k)
85
+ held.delete(k)
86
+ if (was == null || JSON.stringify(was) !== JSON.stringify(r)) put.run(bind(r))
87
+ const h = hashOf(r)
88
+ if (h !== 0n) {
89
+ x ^= h
90
+ n++
91
+ }
92
+ }
93
+ for (const r of held.values()) drop.run(r.rel, r.refused)
94
+ return writeXor(db, n, x)
95
+ }
96
+
97
+ /** the two values of the older shape become rows, once, under the write lock; then the file gives back the pages they
98
+ * held (megabytes: a delete never shrinks a file) when no other process holds it open */
99
+ function importOld(db: Database): void {
100
+ if (db.query('select 1 from state where name in (?, ?) limit 1').get(OLD_SOURCES, OLD_SEEN) == null) return
101
+ importRows(db)
102
+ try {
103
+ db.exec('vacuum')
104
+ } catch { /* another process reads it now: the pages are reused by the next rows */ }
105
+ }
106
+
107
+ function importRows(db: Database): void {
108
+ db.transaction(() => {
109
+ const list = oldValue<Source[]>(db, OLD_SOURCES)
110
+ if (list != null) {
111
+ const stamp = replaceAll(db, list)
112
+ const old = stampOfSources(list)
113
+ const s = oldValue<Record<string, unknown>>(db, STAMPS)
114
+ if (s != null && (s.seen === old || s.ran === old)) {
115
+ const next = { ...s, ...(s.seen === old ? { seen: stamp } : {}), ...(s.ran === old ? { ran: stamp } : {}) }
116
+ db.query('update state set value = ? where name = ?').run(JSON.stringify(next), STAMPS)
117
+ }
118
+ db.query('delete from state where name = ?').run(OLD_SOURCES)
119
+ }
120
+ const seen = oldValue<Record<string, SeenRow>>(db, OLD_SEEN)
121
+ if (seen != null) {
122
+ writeSeen(db, new Map(Object.entries(seen)))
123
+ db.query('delete from state where name = ?').run(OLD_SEEN)
124
+ }
125
+ }).immediate()
126
+ }
127
+
128
+ /** the kept rows, imported first from a value of the older shape */
129
+ const kept = <R>(body: (db: Database) => R): R =>
130
+ machineDb((db) => {
131
+ importOld(db)
132
+ return body(db)
133
+ })
134
+
135
+ /** the list the last look kept, sorted as collect sorts it, under `home` (a source is always the home's join of its
136
+ * path: collect.ts keeps nothing outside it); null when no look kept one */
137
+ export function keptSources(home: string): Source[] | null {
138
+ return kept((db) => {
139
+ if (readXor(db) == null) return null
140
+ const rows = db.query(ROWS).all() as Row[]
141
+ return rows.map((r) => sourceOf(r, home)).sort((a, b) => (a.rel < b.rel ? -1 : a.rel > b.rel ? 1 : a.broken === b.broken ? 0 : a.broken ? 1 : -1))
142
+ })
143
+ }
144
+
145
+ /** the stamp of the kept list, null when none: what a look compares, with no read of the list */
146
+ export function keptStamp(): string | null {
147
+ return kept((db) => {
148
+ const x = readXor(db)
149
+ return x == null ? null : stampText(x.n, BigInt(`0x${x.x}`))
150
+ })
151
+ }
152
+
153
+ /** a full walk's list kept in place of the last: its stamp */
154
+ export function keepSources(list: readonly Source[]): string {
155
+ return kept((db) => db.transaction(() => replaceAll(db, list)).immediate())
156
+ }
157
+
158
+ /** the `rel` ranges a scope covers under `home`: every row (a path at or above the home), none (a path beside it), or
159
+ * each path and what is under it */
160
+ function rangesOf(home: string, scope: Scope): 'all' | string[] {
161
+ const out: string[] = []
162
+ for (const p of scope.paths) {
163
+ const r = relative(home, p)
164
+ if (r === '' || (r.startsWith('..') && !relative(p, home).startsWith('..'))) return 'all'
165
+ if (r.startsWith('..')) continue
166
+ out.push(r)
167
+ }
168
+ return out
169
+ }
170
+
171
+ /** the rows under the scope's paths replaced by `fresh` (a scoped collect of them), in one transaction: the new stamp */
172
+ export function patchSources(home: string, scope: Scope, fresh: readonly Source[]): string {
173
+ return kept((db) =>
174
+ db.transaction(() => {
175
+ const ranges = rangesOf(home, scope)
176
+ const was = readXor(db)
177
+ if (ranges === 'all' || was == null) return replaceAll(db, fresh)
178
+ let x = BigInt(`0x${was.x}`)
179
+ let n = was.n
180
+ const under = db.query(`${ROWS} where rel = ?1 or (rel > ?1 || '${sep}' and rel < ?1 || '${String.fromCharCode(sep.charCodeAt(0) + 1)}')`)
181
+ const drop = db.query(`delete from backup_sources where rel = ?1 or (rel > ?1 || '${sep}' and rel < ?1 || '${String.fromCharCode(sep.charCodeAt(0) + 1)}')`)
182
+ for (const r of ranges) {
183
+ for (const row of under.all(r) as Row[]) {
184
+ const h = hashOf(row)
185
+ if (h === 0n) continue
186
+ x ^= h
187
+ n--
188
+ }
189
+ drop.run(r)
190
+ }
191
+ const put = db.query(INSERT)
192
+ const one = db.query('select rel, size, mtime, broken, sqlite from backup_sources where rel = ? and refused = ?')
193
+ for (const s of fresh) {
194
+ const row = rowOf(s)
195
+ // a fresh source the scope does not cover would be counted twice
196
+ const k = one.get(row.rel, row.refused) as Row | null
197
+ if (k != null) {
198
+ const h = hashOf(k)
199
+ if (h !== 0n) {
200
+ x ^= h
201
+ n--
202
+ }
203
+ }
204
+ put.run(bind(row))
205
+ const h = hashOf(row)
206
+ if (h !== 0n) {
207
+ x ^= h
208
+ n++
209
+ }
210
+ }
211
+ return writeXor(db, n, x)
212
+ }).immediate(),
213
+ )
214
+ }
215
+
216
+ function writeSeen(db: Database, next: ReadonlyMap<string, SeenRow>): void {
217
+ const held = new Map<string, SeenRow>()
218
+ for (const r of db.query('select path, size, mtime, sha, key from backup_seen').all() as (SeenRow & { path: string })[]) held.set(r.path, { size: r.size, mtime: r.mtime, sha: r.sha, key: r.key })
219
+ const put = db.query('insert or replace into backup_seen (path, size, mtime, sha, key) values (?, ?, ?, ?, ?)')
220
+ const drop = db.query('delete from backup_seen where path = ?')
221
+ for (const [path, r] of next) {
222
+ const was = held.get(path)
223
+ held.delete(path)
224
+ if (was == null || was.size !== r.size || was.mtime !== r.mtime || was.sha !== r.sha || was.key !== r.key) put.run(path, r.size, r.mtime, r.sha, r.key)
225
+ }
226
+ for (const path of held.keys()) drop.run(path)
227
+ }
228
+
229
+ /** every file the last run held, by its path under the home */
230
+ export function keptSeen(): Map<string, SeenRow> {
231
+ return kept((db) => {
232
+ const out = new Map<string, SeenRow>()
233
+ for (const r of db.query('select path, size, mtime, sha, key from backup_seen order by path').all() as (SeenRow & { path: string })[]) out.set(r.path, { size: r.size, mtime: r.mtime, sha: r.sha, key: r.key })
234
+ return out
235
+ })
236
+ }
237
+
238
+ /** the files this run held, in place of the last run's: only the rows that moved are written */
239
+ export function keepSeen(next: ReadonlyMap<string, SeenRow>): void {
240
+ kept((db) => db.transaction(() => writeSeen(db, next)).immediate())
241
+ }
@@ -12,7 +12,9 @@ import type { Space } from '../space.ts'
12
12
  import { sameMachine, stampOf } from './keys.ts'
13
13
  import { machinesOf, readManifest, runAt, type Entry, type Manifest } from './manifest.ts'
14
14
  import { machineName } from '../../home/machine-host.ts'
15
+ import { livePath, machinePath, oneRootRel } from '../../core/machine-layout.ts'
15
16
  import { rowsOf } from './snapshot.ts'
17
+ import { machineGet, machineSet } from '../../core/machine-db.ts'
16
18
 
17
19
  export interface RestoreResult {
18
20
  run: string
@@ -94,10 +96,12 @@ export async function restore(space: Space, o: RestoreOptions): Promise<RestoreR
94
96
  const run = await runFor(space, o.at, o.machine ?? machineName())
95
97
  const scratch = mkdtempSync(join(tmpdir(), 'shipkit-restore-'))
96
98
  const stamp = stampOf(new Date())
97
- const aside = join(o.home, '.shipkit', 'backup-replaced', stamp)
99
+ const aside = join(machinePath('backup-replaced', o.home), stamp)
98
100
  try {
99
101
  const m = await readManifest(space, run.key, join(scratch, 'run'))
100
- const files = m.files.filter((f) => !o.only || f.path === o.only || f.path.startsWith(o.only.endsWith('/') ? o.only : `${o.only}/`))
102
+ // a run names the machine's state under the root it had: `--path` matches either form
103
+ const only = o.only ? oneRootRel(o.only.replace(/\/+$/, '')) : null
104
+ const files = m.files.filter((f) => only == null || oneRootRel(f.path) === only || oneRootRel(f.path).startsWith(`${only}/`))
101
105
  const out: RestoreResult & { manifest: Manifest } = { run: run.key, at: m.at, files: files.length, bytes: 0, written: 0, same: 0, aside: { n: 0, dir: null }, beside: [], failed: [], manifest: m }
102
106
  let next = 0
103
107
  const one = async (e: Entry): Promise<void> => {
@@ -108,7 +112,7 @@ export async function restore(space: Space, o: RestoreOptions): Promise<RestoreR
108
112
  out.bytes += e.size
109
113
  return
110
114
  }
111
- const live = join(o.home, e.path)
115
+ const live = livePath(o.home, e.path)
112
116
  if (e.sqlite) {
113
117
  land(`${live}.restored`, await fetchEntry(space, e, scratch))
114
118
  out.beside.push(`${live}.restored`)
@@ -163,6 +167,11 @@ export interface DrillResult {
163
167
  dir: string
164
168
  }
165
169
 
170
+ /** the last drill of this machine's own last run, counts only: what the resume check reads */
171
+ export const BACKUP_DRILL = 'backup-drill'
172
+ export type BackupDrill = { at: number; run: string; files: number; restored: number; failed: number }
173
+ export const lastBackupDrill = (): BackupDrill | null => machineGet<BackupDrill>(BACKUP_DRILL)
174
+
166
175
  /** a run (the last, or the last at or before `at`) restored into a scratch folder (or `to`), every sha read again and
167
176
  * compared to the live files */
168
177
  export async function drill(space: Space, o: { home: string; to?: string; keep?: boolean; at?: Date; machine?: string }): Promise<DrillResult & { v: number }> {
@@ -180,7 +189,7 @@ export async function drill(space: Space, o: { home: string; to?: string; keep?:
180
189
  continue
181
190
  }
182
191
  out.restored++
183
- const live = join(o.home, e.path)
192
+ const live = livePath(o.home, e.path)
184
193
  if (!existsSync(live)) {
185
194
  out.liveGone.push(e.path)
186
195
  continue
@@ -192,6 +201,7 @@ export async function drill(space: Space, o: { home: string; to?: string; keep?:
192
201
  if ((await shaOf(live)) === e.sha) out.sameAsLive++
193
202
  else out.liveMoved.push(e.path)
194
203
  }
204
+ if (o.at == null && o.machine == null) machineSet(BACKUP_DRILL, { at: Date.now(), run: out.run, files: out.files, restored: out.restored, failed: out.failed.length } satisfies BackupDrill)
195
205
  return out
196
206
  } finally {
197
207
  if (!o.to && !o.keep) rmSync(dir, { recursive: true, force: true })
@@ -9,6 +9,7 @@ import { basename, dirname, join, relative } from 'node:path'
9
9
  import { homeDir } from '../../home/home-paths.ts'
10
10
  import { gzipSync } from 'node:zlib'
11
11
  import { machineGet, machineSet } from '../../core/machine-db.ts'
12
+ import { keepSeen, keptSeen, type SeenRow } from './kept.ts'
12
13
  import { mediaKey } from '../content.ts'
13
14
  import { isUp } from '../remote.ts'
14
15
  import type { Space } from '../space.ts'
@@ -21,9 +22,6 @@ import { collect, type Collect, type Source } from './sources.ts'
21
22
  import { machineName } from '../../home/machine-host.ts'
22
23
 
23
24
  const LAST = 'backup-last'
24
- /** every file a run held, by path: its size, time, sha and key, so a file whose size and time held is never read
25
- * again (the 6 h run reads every byte again) */
26
- const SEEN = 'backup-seen'
27
25
 
28
26
  export interface Last {
29
27
  key: string
@@ -31,7 +29,9 @@ export interface Last {
31
29
  at: string
32
30
  }
33
31
 
34
- type Seen = Record<string, { size: number; mtime: number; sha: string; key: string }>
32
+ /** every file a run held, by path: its size, time, sha and key, so a file whose size and time held is never read
33
+ * again (the 6 h run reads every byte again). Rows of the machine db (kept.ts) */
34
+ type Seen = ReadonlyMap<string, SeenRow>
35
35
 
36
36
  export const lastRun = (): Last | null => machineGet<Last>(LAST)
37
37
 
@@ -53,7 +53,7 @@ export interface Ready {
53
53
 
54
54
  /** every source read: hashed, snapshotted, or refused. A file whose size and time equal the last run's, its object
55
55
  * up, keeps that run's sha unread (`seen`; empty reads every byte) */
56
- export async function prepare(sources: readonly Source[], scratch: string, seen: Seen = machineGet<Seen>(SEEN) ?? {}): Promise<{ ready: Ready[]; refused: Refused[] }> {
56
+ export async function prepare(sources: readonly Source[], scratch: string, seen: Seen = keptSeen()): Promise<{ ready: Ready[]; refused: Refused[] }> {
57
57
  const ready: Ready[] = []
58
58
  const refused: Refused[] = []
59
59
  for (const s of sources) {
@@ -67,7 +67,7 @@ export async function prepare(sources: readonly Source[], scratch: string, seen:
67
67
  const snap = snapshotSqlite(s.abs, to, s.sqlite)
68
68
  const raw = new Uint8Array(await Bun.file(to).arrayBuffer())
69
69
  rmSync(to, { force: true })
70
- const why = refusal(basename(s.rel), raw)
70
+ const why = refusal(basename(s.rel), raw, true)
71
71
  if (why) {
72
72
  refused.push({ path: s.rel, why })
73
73
  continue
@@ -78,7 +78,7 @@ export async function prepare(sources: readonly Source[], scratch: string, seen:
78
78
  ready.push({ entry, bytes: gz, size: gz.length, read: true })
79
79
  continue
80
80
  }
81
- const was = seen[s.rel]
81
+ const was = seen.get(s.rel)
82
82
  if (was && was.size === s.size && was.mtime === s.mtime && isUp(was.key)) {
83
83
  ready.push({ entry: { path: s.rel, sha: was.sha, size: was.size, mtime: s.mtime, key: was.key }, size: was.size, ...(s.whole ? { whole: true as const } : {}) })
84
84
  continue
@@ -219,16 +219,16 @@ export async function backupRun(space: Space, o: Collect & { now?: Date; jobs?:
219
219
  const scratch = mkdtempSync(join(tmpdir(), 'shipkit-backup-'))
220
220
  try {
221
221
  const now = o.now ?? new Date()
222
- const { ready, refused } = await prepare(o.sources ?? (await collect(o)), scratch, o.rehash ? {} : undefined)
222
+ const { ready, refused } = await prepare(o.sources ?? (await collect(o)), scratch, o.rehash ? new Map() : undefined)
223
223
  const files = ready.map((r) => r.entry)
224
224
  const digest = digestOf(files, refused)
225
225
  const last = await lastOf(space, scratch)
226
226
  const out: RunResult = { files: files.length, bytes: ready.reduce((n, r) => n + r.entry.size, 0), sent: 0, sentBytes: 0, there: 0, refused, failed: [], read: ready.filter((r) => r.read).length, manifest: null, record: { parts: 0, partsSent: 0, partsBytes: 0, runBytes: 0 }, last, digest }
227
227
  await sendAll(space, ready, scratch, o.jobs ?? 8, out)
228
228
  if (out.failed.length > 0) return out
229
- const seen: Seen = {}
230
- for (const r of ready) if (!r.entry.sqlite) seen[r.entry.path] = { size: r.entry.size, mtime: r.entry.mtime, sha: r.entry.sha, key: r.entry.key }
231
- machineSet(SEEN, seen)
229
+ const seen = new Map<string, SeenRow>()
230
+ for (const r of ready) if (!r.entry.sqlite) seen.set(r.entry.path, { size: r.entry.size, mtime: r.entry.mtime, sha: r.entry.sha, key: r.entry.key })
231
+ keepSeen(seen)
232
232
  if (last?.digest === digest) return out
233
233
  const enc = encodeRun({ at: now.toISOString(), host: hostname(), home: o.home, digest, files, refused }, o.repos.map((r) => relative(o.home, r)))
234
234
  out.record.parts = enc.parts.length
@@ -1,7 +1,8 @@
1
1
  // what the backup never sends (wiki tools/shipkit/media-store.md, Backup): a secret's home is the keychain, never the
2
2
  // Space. A file is refused by its name (an env file, a key file, a name that says secret, token, password, api key), by
3
3
  // the leak guard's secret shapes in its bytes, by a credential line whose value is no keychain pointer, or by its
4
- // size (over 50 MB is a question for the owner first, unless his repo names the path whole: `backup.paths`). The
4
+ // size (over 50 MB is a question for the owner first, unless his repo names the path whole, `backup.paths`, or it is a
5
+ // sqlite cut, whose tables are named). The
5
6
  // reason is printed, the content never
6
7
  import { parsePatterns, SECRET_ROWS } from '../../hooks/leak-guard.ts'
7
8
 
@@ -29,9 +30,10 @@ function textRefusal(bytes: Uint8Array): string | null {
29
30
 
30
31
  const nameRefusal = (name: string): string | null => (SECRET_NAME.test(name) ? 'its name says it holds a secret: the keychain keeps those' : null)
31
32
 
32
- /** why the file never goes up, null when it may */
33
- export function refusal(name: string, bytes: Uint8Array): string | null {
34
- if (bytes.length > MAX_BYTES) return `over 50 MB (${(bytes.length / 1e6).toFixed(0)} MB): asked before it goes`
33
+ /** why the file never goes up, null when it may. `named`: its content was named (a sqlite cut's tables), so its size
34
+ * is no question */
35
+ export function refusal(name: string, bytes: Uint8Array, named = false): string | null {
36
+ if (!named && bytes.length > MAX_BYTES) return `over 50 MB (${(bytes.length / 1e6).toFixed(0)} MB): asked before it goes`
35
37
  return nameRefusal(name) ?? textRefusal(bytes)
36
38
  }
37
39
 
@@ -7,6 +7,8 @@ import { Database } from 'bun:sqlite'
7
7
  export interface SqliteCut {
8
8
  /** the tables kept, null: every table */
9
9
  tables: string[] | null
10
+ /** tables kept too when the file holds them (a store whose tables come once it is first opened) */
11
+ maybe?: string[]
10
12
  /** per table, a where clause of the rows left out */
11
13
  except?: Record<string, string>
12
14
  }
@@ -27,7 +29,7 @@ export function snapshotSqlite(live: string, to: string, cut: SqliteCut): Snapsh
27
29
  db.query('attach database ? as live').run(`file:${encodeURI(live)}?mode=ro`)
28
30
  db.exec('begin')
29
31
  const all = db.query(`select name, sql from live.sqlite_schema where type = 'table' and name not like 'sqlite_%' order by name`).all() as { name: string; sql: string }[]
30
- const keep = cut.tables === null ? all : all.filter((t) => cut.tables!.includes(t.name))
32
+ const keep = cut.tables === null ? all : all.filter((t) => cut.tables!.includes(t.name) || (cut.maybe ?? []).includes(t.name))
31
33
  const missing = (cut.tables ?? []).filter((t) => !all.some((a) => a.name === t))
32
34
  if (missing.length > 0) throw new Error(`${live}: no table ${missing.join(', ')}`)
33
35
  const rows: Record<string, number> = {}
@@ -53,7 +55,7 @@ export function rowsOf(file: string, cut: SqliteCut): Record<string, number> {
53
55
  const db = new Database(file, { readonly: true })
54
56
  try {
55
57
  db.exec('begin')
56
- const names = (db.query(`select name from sqlite_schema where type = 'table' and name not like 'sqlite_%' order by name`).all() as { name: string }[]).map((r) => r.name).filter((n) => cut.tables === null || cut.tables.includes(n))
58
+ const names = (db.query(`select name from sqlite_schema where type = 'table' and name not like 'sqlite_%' order by name`).all() as { name: string }[]).map((r) => r.name).filter((n) => cut.tables === null || cut.tables.includes(n) || (cut.maybe ?? []).includes(n))
57
59
  const out: Record<string, number> = {}
58
60
  for (const n of names) out[n] = (db.query(`select count(*) as n from ${quote(n)}${kept(cut, n)}`).get() as { n: number }).n
59
61
  db.exec('commit')
@@ -1,7 +1,7 @@
1
1
  // WHAT THE BACKUP HOLDS (wiki tools/shipkit/media-store.md, Backup, The inventory): every file of the machine that no
2
- // git and no Space keeps, its authored or irreplaceable state. The home's veille logs, the rail order, the media index
3
- // and the machine db (consistent sqlite snapshots), the machine's private folder, the agents' memories of each house
4
- // repo; in each house repo, every untracked file of `.shipkit/` and the hand tuned `.comfy-ts/` files, and its
2
+ // git and no Space keeps, its authored or irreplaceable state. The home's veille logs, the rail order, the media index,
3
+ // the machine db and the review cards of the daemon's file (consistent sqlite snapshots), the machine's private
4
+ // folder, the agents' memories of each house repo; in each house repo, every untracked file of `.shipkit/` and the hand tuned `.comfy-ts/` files, and its
5
5
  // gitignored `*.local.*` files; and what the repo's config adds (`backup`: paths kept whole, sqlite files). Never a cache, a log, a scratch folder, a lock, a dev database it did not name or a media file a kind of
6
6
  // the store holds. Walked with sync fs (half the CPU of an async walk): it runs in the job's child or the cli, never on
7
7
  // the daemon's loop. A look of the daemon reads again only the paths its watch heard (a Scope)
@@ -10,10 +10,13 @@ import { lstat, readdir } from 'node:fs/promises'
10
10
  import { existsSync, lstatSync, readdirSync, statSync } from 'node:fs'
11
11
  import { basename, dirname, extname, join, relative, sep } from 'node:path'
12
12
  import { homeDir } from '../../home/home-paths.ts'
13
- import { machineDbPath } from '../../core/machine-db.ts'
14
- import { MACHINE_PRIVATE } from '../../core/layout.ts'
15
- import { ORDER_FILE } from '../../serve/project-gutter-route.ts'
13
+ import { isTombstone, machineDbPath, oldStorePath } from '../../core/machine-db.ts'
14
+ import { machinePath } from '../../core/machine-layout.ts'
15
+ import { orderFile } from '../../serve/project-gutter-route.ts'
16
16
  import { mediaDbPath } from '../db.ts'
17
+ import { forgottenLogPath } from '../../hq/forgotten-log.ts'
18
+ import { hqDbPath } from '../../hq/hq-db.ts'
19
+ import { daemonDbPath } from '../../hq/outbox.ts'
17
20
  import { loadRepoConfig, type RepoBackup } from '../../repo-config.ts'
18
21
  import type { SqliteCut } from './snapshot.ts'
19
22
 
@@ -58,6 +61,10 @@ export class Scope {
58
61
  get size(): number {
59
62
  return this.at.size
60
63
  }
64
+ /** the paths themselves, each one with everything under it */
65
+ get paths(): readonly string[] {
66
+ return [...this.at]
67
+ }
61
68
  /** at or under a path of the scope */
62
69
  covers(abs: string): boolean {
63
70
  for (let p = abs; ; p = dirname(p)) {
@@ -167,6 +174,39 @@ export async function backupOfRepo(repo: string): Promise<RepoBackup | null> {
167
174
  return backup
168
175
  }
169
176
 
177
+ /** the review cards' tables: in the daemon's file, or in the machine db once it is folded */
178
+ const CARD_TABLES = ['review_cards', 'review_msgs', 'review_gone', 'review_replaced', 'review_repos']
179
+
180
+ /** the machine db as a run holds it. The Mac's own names stay out: a run restored on another Mac must not make it
181
+ * take this one's name, nor its place in an hq (the hq it joined, the switch that opens its own, its key:
182
+ * hq/hq-local.ts). The backup's own records stay out too (kept.ts): else every run differs. Its tables are named:
183
+ * the media index's files and objects come along, never its reads nor the agent time index (caches, the second
184
+ * one hundreds of MB) */
185
+ export const machineCut: SqliteCut = {
186
+ tables: ['state', 'backup_sources', 'backup_seen'],
187
+ maybe: ['media_files', 'media_objects', ...CARD_TABLES],
188
+ except: { state: "name like 'pid:%' or name like 'backup-%' or name like 'db-fold-%' or name like 'hq-%' or name in ('machine-name', 'tailnet-name')", backup_sources: '1', backup_seen: '1', media_objects: "key like 'backup/%'" },
189
+ }
190
+
191
+ /** the media index in a file of its own (moved for one process): its files and objects */
192
+ export const mediaCut: SqliteCut = { tables: [], maybe: ['media_files', 'media_objects'], except: { media_objects: "key like 'backup/%'" } }
193
+
194
+ /** the daemon's own file: the review cards a machine keeps as rows (the switch cards-in-db) and their threads, the one
195
+ * copy of a card made here until the hq took it. Its outbox, ledger and queues stay out: they are what is sent, and a
196
+ * restored queue would send again */
197
+ export const cardsCut: SqliteCut = { tables: [], maybe: CARD_TABLES }
198
+
199
+ /** the media index still in its file of before the fold (`sk db fold`), its tables of no prefix: until the fold, the
200
+ * backup holds it there */
201
+ export const unfoldedMediaCut: SqliteCut = { tables: [], maybe: ['files', 'objects'], except: { objects: "key like 'backup/%'" } }
202
+ const unfoldedMedia = (): string | null => {
203
+ const old = oldStorePath('media index')
204
+ return old !== mediaDbPath() && existsSync(old) && !isTombstone(old) ? old : null
205
+ }
206
+
207
+ /** the files that hold a token, or the names a compare found differing: never a source of the backup */
208
+ const TOKEN_FILE = /^(?:hq-token|vault-token|minter-token|vault-compared\.json|hq-door-secret|door-key)(?:\.tmp-\d+)?$/
209
+
170
210
  /** a live db's own side files and the locks of a folder named whole: never part of it */
171
211
  const WHOLE_DENY = /^(?:\.DS_Store)$|\.(?:pid|lock)$|-(?:wal|shm|journal)$/
172
212
 
@@ -177,13 +217,18 @@ export async function collect(o: Collect): Promise<Source[]> {
177
217
  const add = (abs: string): void => void files.push(abs)
178
218
  // the backup's own objects and records, and the pids, move by themselves: left out, else every run differs
179
219
  const sqlite = new Map<string, SqliteCut>([
180
- [mediaDbPath(), { tables: ['files', 'objects'], except: { objects: "key like 'backup/%'" } }],
181
- // the Mac's own names stay out: a run restored on another Mac must not make it take this one's name
182
- [machineDbPath(), { tables: null, except: { state: "name like 'pid:%' or name like 'backup-%' or name in ('machine-name', 'tailnet-name')" } }],
220
+ [mediaDbPath(), mediaCut],
221
+ [machineDbPath(), machineCut],
183
222
  ])
223
+ // the daemon's file until it is folded: then its cards are tables of the machine db, in its cut
224
+ if (daemonDbPath() !== machineDbPath()) sqlite.set(daemonDbPath(), cardsCut)
225
+ const unfolded = unfoldedMedia()
226
+ if (unfolded != null) sqlite.set(unfolded, unfoldedMediaCut)
184
227
  await walk(join(homeDir(), 'veille'), () => true, files, undefined, scope)
185
- add(join(o.home, ORDER_FILE))
186
- await walk(join(o.home, MACHINE_PRIVATE), () => true, files, undefined, scope)
228
+ add(orderFile(o.home))
229
+ // the rows forgotten at the hq, ids only: neither the hq's replica nor a restore of it carries them
230
+ add(forgottenLogPath(hqDbPath()))
231
+ await walk(machinePath('private', o.home), () => true, files, undefined, scope)
187
232
  for (const root of await agentRoots(o.home)) for (const repo of o.repos) await walk(join(root, sessionName(repo), 'memory'), () => true, files, undefined, scope)
188
233
  const repos = scope ? o.repos.filter((r) => scope.reaches(r)) : o.repos
189
234
  // the git walks of ignored trees take seconds each: all at once
@@ -230,8 +275,11 @@ export async function collect(o: Collect): Promise<Source[]> {
230
275
  for (const f of mine) if (!tracked.has(f)) files.push(f)
231
276
  }
232
277
  const out = new Map<string, Source>()
278
+ // the vault's folder never: its sealed copy travels through sk vault snapshot only (vault/vault-snapshot.ts); and
279
+ // a token file by its name wherever a backup key reaches it, its half written copy included
280
+ const vault = `${join(homeDir(), 'vault')}${sep}`
233
281
  for (const abs of [...files, ...sqlite.keys()]) {
234
- if (out.has(abs) || (scope && !scope.covers(abs))) continue
282
+ if (out.has(abs) || (scope && !scope.covers(abs)) || abs.startsWith(vault) || TOKEN_FILE.test(basename(abs))) continue
235
283
  const st = lstatSync(abs, { throwIfNoEntry: false })
236
284
  if (!st?.isFile()) continue
237
285
  const rel = relative(o.home, abs)
@@ -253,11 +301,14 @@ export function scopeOf(moved: readonly string[], repos: readonly string[]): Sco
253
301
  return new Scope(all)
254
302
  }
255
303
 
304
+ /** what a look reads again: the moved paths, and the home's databases at each look (two stats, and one that appears
305
+ * is held from its first run) */
306
+ export const lookScope = (moved: readonly string[], repos: readonly string[]): Scope => scopeOf([...moved, ...new Set([mediaDbPath(), machineDbPath(), daemonDbPath()]), ...[unfoldedMedia()].filter((p): p is string => p != null)], repos)
307
+
256
308
  /** the last list with the moved paths read again: the list a full collect gives, at the cost of what moved (a
257
309
  * repo's own sqlite keeps the size and time of the last full walk: snapshotted live at each run, out of the stamp) */
258
310
  export async function refreshSources(prev: readonly Source[], moved: readonly string[], o: Collect): Promise<Source[]> {
259
- // the home's databases are read at each look: two stats, and one that appears is held from its first run
260
- const scope = scopeOf([...moved, mediaDbPath(), machineDbPath()], o.repos)
311
+ const scope = lookScope(moved, o.repos)
261
312
  const fresh = await collect({ ...o, scope })
262
313
  return sortSources([...prev.filter((s) => !scope.covers(s.abs)), ...fresh])
263
314
  }
@@ -321,11 +372,11 @@ export interface WatchRoot {
321
372
 
322
373
  /** `named` gives a repo's `backup.paths` as the last look read them: asked at each event, so a new name counts at once */
323
374
  export async function watchRoots(home: string, repos: readonly string[], named: (repo: string) => readonly string[] = () => []): Promise<WatchRoot[]> {
324
- const order = join(home, ORDER_FILE)
375
+ const order = orderFile(home)
325
376
  const memory = new Set(repos.map(sessionName))
326
377
  return [
327
378
  { dir: join(homeDir(), 'veille'), recursive: true, heard: () => 'due' },
328
- { dir: join(home, MACHINE_PRIVATE), recursive: true, heard: () => 'due' },
379
+ { dir: machinePath('private', home), recursive: true, heard: () => 'due' },
329
380
  { dir: dirname(order), recursive: false, heard: (rel) => due(rel === basename(order)) },
330
381
  ...(await agentRoots(home)).map((dir): WatchRoot => ({ dir, recursive: true, heard: (rel) => { const [repo, folder] = rel.split(sep); return due(memory.has(repo ?? '') && (folder === undefined || folder === 'memory')) } })),
331
382
  ...repos.map((r): WatchRoot => ({ dir: r, recursive: true, heard: (rel) => repoPathHeard(rel, named(r)) })),