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,276 @@
1
+ // the vault's audit file kept bounded: renamed aside once a day or past a size, bao made to reopen its path (SIGHUP),
2
+ // the new file proved written before the old one is compressed. A file audit device that cannot write makes the vault
3
+ // refuse every request, so each step leaves bao writing somewhere, and a failure puts the old file back at its path
4
+ import { chmodSync, existsSync, linkSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from 'fs'
5
+ import { basename, dirname, isAbsolute, join } from 'path'
6
+ import { configFile, markerFile, type VaultPlace } from './vault-config.ts'
7
+
8
+ /** rotated between two days when it passes this size */
9
+ export const AUDIT_ROTATE_BYTES = 50_000_000
10
+ export const AUDIT_DAY_MS = 24 * 3600_000
11
+ /** a month of who read what is enough for a vault of one person: the snapshots are its backup, this file is a log */
12
+ export const AUDIT_KEEP_MS = 30 * AUDIT_DAY_MS
13
+ /** a cap on the count too, so a loop of size rotations cannot fill the disk */
14
+ export const AUDIT_KEEP_FILES = 40
15
+ /** a failed rotation is tried again after this long, never at every tick */
16
+ export const AUDIT_RETRY_MS = 3600_000
17
+ /** how often the vault's process looks at the file */
18
+ export const AUDIT_TICK_MS = 10 * 60_000
19
+
20
+ /** the bao that writes the file: `reopen` makes it reopen its audit path, `probe` makes one request it audits */
21
+ export type AuditBao = { reopen: () => void; probe: () => Promise<unknown> }
22
+ /** the last rotation tried, kept beside the vault: what the status says. Words, sizes and names only */
23
+ export type AuditRecord = { at: number; ok: boolean; tone: 'ok' | 'warn' | 'danger'; text: string; file?: string }
24
+ export type AuditShape = { bytes: number | null; rotatedAt: number | null; files: number; filesBytes: number; last: AuditRecord | null }
25
+
26
+ const stampOf = (at: number): string => new Date(at).toISOString().replace(/[-:]|\.\d{3}/g, '')
27
+ const stemOf = (live: string): string => basename(live).replace(/\.log$/, '')
28
+ /** `audit-20260131T120000Z.log` beside `audit.log`, sorted by its time; `-<n>` after the stamp for a second one in the same second */
29
+ export const rotatedName = (live: string, at: number, n = 0): string => join(dirname(live), `${stemOf(live)}-${stampOf(at)}${n > 0 ? `-${n}` : ''}.log`)
30
+
31
+ const escape = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
32
+ const rotatedRe = (live: string): RegExp => new RegExp(`^${escape(stemOf(live))}-(\\d{8}T\\d{6}Z)(?:-(\\d+))?\\.log(\\.gz)?(\\.tmp)?$`)
33
+ const atOfStamp = (s: string): number => Date.UTC(+s.slice(0, 4), +s.slice(4, 6) - 1, +s.slice(6, 8), +s.slice(9, 11), +s.slice(11, 13), +s.slice(13, 15))
34
+
35
+ /** the rotated files beside `live`, oldest first; the live file and any other name never among them */
36
+ export function rotatedFiles(live: string): { name: string; at: number; n: number; gz: boolean; tmp: boolean; bytes: number }[] {
37
+ const re = rotatedRe(live)
38
+ let names: string[] = []
39
+ try {
40
+ names = readdirSync(dirname(live))
41
+ } catch {
42
+ return []
43
+ }
44
+ return names
45
+ .flatMap((name) => {
46
+ const m = re.exec(name)
47
+ if (m == null || name === basename(live)) return []
48
+ let bytes = 0
49
+ try {
50
+ bytes = statSync(join(dirname(live), name)).size
51
+ } catch {
52
+ return []
53
+ }
54
+ return [{ name, at: atOfStamp(m[1]!), n: Number(m[2] ?? 0), gz: m[3] != null, tmp: m[4] != null, bytes }]
55
+ })
56
+ .sort((a, b) => a.at - b.at || a.n - b.n || a.name.localeCompare(b.name))
57
+ }
58
+
59
+ const sizeOf = (f: string): number | null => {
60
+ try {
61
+ return statSync(f).size
62
+ } catch {
63
+ return null
64
+ }
65
+ }
66
+ const codeOf = (e: unknown): string => (e as NodeJS.ErrnoException)?.code ?? (e as Error)?.message ?? String(e)
67
+
68
+ async function until(ok: () => boolean, ms: number): Promise<boolean> {
69
+ const end = Date.now() + ms
70
+ for (;;) {
71
+ if (ok()) return true
72
+ if (Date.now() >= end) return false
73
+ await Bun.sleep(20)
74
+ }
75
+ }
76
+
77
+ /** a request audited, then the file at `live` seen grown: proof bao writes there */
78
+ async function writesTo(live: string, bao: AuditBao, ms: number): Promise<boolean> {
79
+ const before = sizeOf(live)
80
+ if (before == null) return false
81
+ await bao.probe().catch(() => null)
82
+ return until(() => (sizeOf(live) ?? 0) > before, ms)
83
+ }
84
+
85
+ const REFUSES = 'the vault refuses requests while its audit file is not written: sk gp restart vault'
86
+
87
+ /** the old file back at its path through a hard link, which never replaces a file a late reload made there (EEXIST) */
88
+ export function putBackNoClobber(from: string, to: string): void {
89
+ linkSync(from, to)
90
+ rmSync(from)
91
+ }
92
+
93
+ /** the live file renamed to its dated name, bao made to reopen, the new file proved at 0600 and written. When bao
94
+ * makes no new file, the old one goes back to its path, where bao writes again; never a step that leaves it no file */
95
+ export async function rotateAudit(o: { live: string; bao: AuditBao; now: number; rename?: (a: string, b: string) => void; putBack?: (from: string, to: string) => void; appearMs?: number }): Promise<AuditRecord> {
96
+ const { live, bao, now } = o
97
+ const rename = o.rename ?? renameSync
98
+ const appearMs = o.appearMs ?? 500
99
+ const rec = (ok: boolean, tone: AuditRecord['tone'], text: string, file?: string): AuditRecord => ({ at: now, ok, tone, text, ...(file != null ? { file } : {}) })
100
+ if (!existsSync(live)) {
101
+ bao.reopen()
102
+ if ((await until(() => existsSync(live), appearMs)) && (await writesTo(live, bao, 2_000))) return rec(true, 'warn', 'the audit file was not there: the vault opened a new one and writes in it')
103
+ return rec(false, 'danger', `the audit file was not there and the vault made no new one: ${REFUSES}`)
104
+ }
105
+ const taken = (f: string): boolean => [f, `${f}.gz`, `${f}.gz.tmp`].some((x) => existsSync(x))
106
+ let n = 0
107
+ while (n < 100 && taken(rotatedName(live, now, n))) n++
108
+ const target = rotatedName(live, now, n)
109
+ if (taken(target)) return rec(false, 'warn', `the audit file was not rotated: ${basename(target)} is there already`)
110
+ try {
111
+ rename(live, target)
112
+ } catch (e) {
113
+ return rec(false, 'warn', `the audit file was not rotated, its rename failed (${codeOf(e)}): nothing changed`)
114
+ }
115
+ try {
116
+ bao.reopen()
117
+ } catch {
118
+ // no signal reached bao: the put back below
119
+ }
120
+ const proveNew = async (): Promise<AuditRecord> => {
121
+ let fixed = ''
122
+ if ((statSync(live).mode & 0o777) !== 0o600) {
123
+ chmodSync(live, 0o600)
124
+ fixed = ', its mode set to 0600'
125
+ }
126
+ if (await writesTo(live, bao, 2_000)) return rec(true, 'ok', `rotated to ${basename(target)}${fixed}`, target)
127
+ return rec(false, 'danger', `the vault reopened its audit file and writes nothing in it: ${REFUSES}`)
128
+ }
129
+ if (await until(() => existsSync(live), appearMs)) return proveNew()
130
+ const putBack = o.putBack ?? putBackNoClobber
131
+ try {
132
+ putBack(target, live)
133
+ } catch (e) {
134
+ if (codeOf(e) === 'EEXIST') return proveNew()
135
+ return rec(false, 'danger', `the vault did not reopen its audit file and the old one could not go back (${codeOf(e)}): ${REFUSES}`)
136
+ }
137
+ if (await writesTo(live, bao, 2_000)) return rec(false, 'warn', 'the vault did not reopen its audit file: the old one is put back at its path and the vault writes in it')
138
+ return rec(false, 'danger', `the vault did not reopen its audit file, the old one is put back and still nothing is written: ${REFUSES}`)
139
+ }
140
+
141
+ /** every rotated plain file gzipped beside itself at 0600, its bytes checked before the plain one goes. Run only after
142
+ * a proved rotation: bao then writes in none of them */
143
+ export async function compressRotated(live: string): Promise<{ done: string[]; failed: string | null }> {
144
+ const done: string[] = []
145
+ let failed: string | null = null
146
+ for (const f of rotatedFiles(live).filter((r) => !r.gz && !r.tmp)) {
147
+ const from = join(dirname(live), f.name)
148
+ const tmp = `${from}.gz.tmp`
149
+ try {
150
+ // streamed both ways, so a large file never sits in memory
151
+ const size = statSync(from).size
152
+ writeFileSync(tmp, '', { mode: 0o600 })
153
+ await Bun.write(tmp, new Response(Bun.file(from).stream().pipeThrough(new CompressionStream('gzip'))))
154
+ let back = 0
155
+ for await (const c of Bun.file(tmp).stream().pipeThrough(new DecompressionStream('gzip'))) back += c.byteLength
156
+ if (back !== size) throw new Error('the compressed copy reads back another size')
157
+ linkSync(tmp, `${from}.gz`)
158
+ rmSync(tmp)
159
+ rmSync(from)
160
+ done.push(f.name)
161
+ } catch (e) {
162
+ rmSync(tmp, { force: true })
163
+ failed = `${f.name} stays uncompressed (${codeOf(e)})`
164
+ }
165
+ }
166
+ return { done, failed }
167
+ }
168
+
169
+ /** rotated files past 30 days removed, then all but the newest 40, and any temp a killed compression left; the live
170
+ * file and every other name are never touched. The names removed */
171
+ export function pruneRotated(live: string, now: number): string[] {
172
+ const all = rotatedFiles(live)
173
+ const kept = all.filter((r) => !r.tmp && now - r.at <= AUDIT_KEEP_MS).slice(-AUDIT_KEEP_FILES)
174
+ const gone: string[] = []
175
+ for (const r of all) {
176
+ if (kept.includes(r)) continue
177
+ rmSync(join(dirname(live), r.name), { force: true })
178
+ gone.push(r.name)
179
+ }
180
+ return gone
181
+ }
182
+
183
+ /** why the file is due a rotation now, null when it is not: a day since it was born, past its size, or gone */
184
+ export function auditDue(o: { live: string; record: AuditRecord | null; now: number; bytes?: number }): 'day' | 'size' | 'missing' | null {
185
+ if (o.record != null && !o.record.ok && o.now - o.record.at < AUDIT_RETRY_MS) return null
186
+ let s: ReturnType<typeof statSync>
187
+ try {
188
+ s = statSync(o.live)
189
+ } catch {
190
+ return 'missing'
191
+ }
192
+ if ((o.bytes ?? s.size) >= AUDIT_ROTATE_BYTES) return 'size'
193
+ const born = s.birthtimeMs > 0 ? s.birthtimeMs : (o.record?.at ?? 0)
194
+ return s.size > 0 && o.now - born >= AUDIT_DAY_MS ? 'day' : null
195
+ }
196
+
197
+ export const auditRecordFile = (dir: string): string => join(dir, 'audit-rotation.json')
198
+ export function readAuditRecord(dir: string): AuditRecord | null {
199
+ try {
200
+ return JSON.parse(readFileSync(auditRecordFile(dir), 'utf8')) as AuditRecord
201
+ } catch {
202
+ return null
203
+ }
204
+ }
205
+ function writeAuditRecord(dir: string, r: AuditRecord): void {
206
+ const tmp = `${auditRecordFile(dir)}.tmp-${process.pid}`
207
+ writeFileSync(tmp, `${JSON.stringify(r)}\n`, { mode: 0o600 })
208
+ renameSync(tmp, auditRecordFile(dir))
209
+ }
210
+
211
+ const real = (p: string): string | null => {
212
+ try {
213
+ return realpathSync(p)
214
+ } catch {
215
+ return null
216
+ }
217
+ }
218
+
219
+ /** the file audit device the config on disk declares, its path as bao opens it (relative to the vault's folder) */
220
+ function declaredAudit(place: VaultPlace): string | null {
221
+ try {
222
+ const path = /audit "file" "[^"]+" \{[^}]*?file_path = "([^"]+)"/.exec(readFileSync(configFile(place), 'utf8'))?.[1]
223
+ return path == null ? null : isAbsolute(path) ? path : join(place.dir, path)
224
+ } catch {
225
+ return null
226
+ }
227
+ }
228
+
229
+ /** why the tick must touch nothing, null when it may. An audit file outside the vault's own folder (a stale marker) is
230
+ * never renamed, signalled for or pruned. A SIGHUP applies bao.hcl again, so a config that no longer declares this
231
+ * audit file would turn the device off: no signal then */
232
+ function refusal(place: VaultPlace, live: string): Pick<AuditRecord, 'tone' | 'text'> | null {
233
+ const dir = real(dirname(live))
234
+ if (dir == null || dir !== real(place.dir)) return { tone: 'warn', text: `the audit file ${live} is not in the vault's folder ${place.dir}: nothing is rotated, signalled or deleted while the marker's auditPath names another folder` }
235
+ const declared = declaredAudit(place)
236
+ if (declared == null || basename(declared) !== basename(live) || real(dirname(declared)) !== dir) return { tone: 'danger', text: `${configFile(place)} no longer declares the audit file ${live}: no rotation, as the reload it needs would turn the audit off. sk gp restart vault writes the config again` }
237
+ return null
238
+ }
239
+
240
+ /** the vault process's look at its audit file: rotated when due, compressed and pruned after a proved rotation, the
241
+ * outcome recorded and said. Null, with nothing said, where no vault is initialised or nothing is due */
242
+ export async function auditTick(o: { place: VaultPlace; live: string; bao: AuditBao; now?: number; say: (l: string) => void }): Promise<AuditRecord | null> {
243
+ if (!existsSync(markerFile(o.place))) return null
244
+ const now = o.now ?? Date.now()
245
+ const last = readAuditRecord(o.place.dir)
246
+ const held = refusal(o.place, o.live)
247
+ if (held != null) {
248
+ if (last?.text === held.text) return last
249
+ const r: AuditRecord = { at: now, ok: false, ...held }
250
+ writeAuditRecord(o.place.dir, r)
251
+ o.say(`${r.tone === 'danger' ? 'DANGER' : 'WARN'} vault audit file: ${r.text}`)
252
+ return r
253
+ }
254
+ const due = auditDue({ live: o.live, record: last, now })
255
+ if (due == null) return null
256
+ const r = await rotateAudit({ live: o.live, bao: o.bao, now })
257
+ if (r.ok) {
258
+ const c = await compressRotated(o.live)
259
+ const gone = pruneRotated(o.live, now)
260
+ if (c.failed != null) Object.assign(r, { tone: 'warn', text: `${r.text}; ${c.failed}` })
261
+ if (gone.length > 0) r.text += `; ${gone.length} old rotated file${gone.length === 1 ? '' : 's'} removed`
262
+ }
263
+ writeAuditRecord(o.place.dir, r)
264
+ o.say(`${r.tone === 'danger' ? 'DANGER' : r.tone === 'warn' ? 'WARN' : 'ok:'} vault audit file (${due}): ${r.text}`)
265
+ return r
266
+ }
267
+
268
+ /** what the status says of the audit file: its size, its last rotation, the rotated files kept. Sizes only, never a
269
+ * line read. Null where no vault is initialised */
270
+ export function auditShape(p: VaultPlace, live: string): AuditShape | null {
271
+ if (!existsSync(markerFile(p))) return null
272
+ const files = rotatedFiles(live).filter((r) => !r.tmp)
273
+ const last = readAuditRecord(p.dir)
274
+ const rotatedAt = [...files.map((f) => f.at), ...(last?.ok === true ? [last.at] : [])].reduce<number | null>((a, b) => (a == null || b > a ? b : a), null)
275
+ return { bytes: sizeOf(live), rotatedAt, files: files.length, filesBytes: files.reduce((n, f) => n + f.bytes, 0), last }
276
+ }
@@ -0,0 +1,40 @@
1
+ // a machine as the vault's client (wiki services/secrets, step 2): the vault is the store of secrets. A registry
2
+ // name has one path in it; a write goes to the vault only and is read back before it is called done. The login
3
+ // keychain is a read only legacy here: nothing in this module writes it
4
+ import type { Scope } from '../core/scope.ts'
5
+ import { KV_MOUNT, pathOf } from './layout.ts'
6
+ import type { VaultApi } from './vault-http.ts'
7
+
8
+ /** a path under the mount as the registry name it files: its scope's folder dropped, `rv/` put back. Null for a path
9
+ * no scope folder holds */
10
+ export function nameOfPath(path: string): string | null {
11
+ const parts = path.split('/')
12
+ const n = parts[0] === 'all' ? 1 : parts[0] === 'repo' || parts[0] === 'identity' || parts[0] === 'machine' ? 2 : 0
13
+ return n === 0 || parts.length <= n ? null : `rv/${parts.slice(n).join('/')}`
14
+ }
15
+
16
+ /** a registry row's path in the vault: a repo its row names by id is filed by that repo's key (host/path of its
17
+ * first remote), found from this machine's checkouts. A repo id no checkout here answers to has no path */
18
+ export async function vaultPathOf(name: string, scope: Scope | undefined, keyOf: (id: string) => Promise<string | null>): Promise<string> {
19
+ if (scope?.repos == null || scope.repos.length === 0) return pathOf(name, scope)
20
+ const repos: string[] = []
21
+ for (const r of scope.repos) {
22
+ if (r.includes('/')) repos.push(r)
23
+ else {
24
+ const key = await keyOf(r)
25
+ if (key == null) throw new Error(`repo:${r}: no checkout on this machine answers to that id, so its key (host/path of its first remote) is unknown`)
26
+ repos.push(key)
27
+ }
28
+ }
29
+ return pathOf(name, { ...scope, repos })
30
+ }
31
+
32
+ /** a value into the vault on top of the version it holds (check and set), then read back: its new version. A write
33
+ * the vault refuses, or a read back that differs by a byte, throws */
34
+ export async function setInVault(o: { vault: Pick<VaultApi, 'currentVersion' | 'writeKvCas' | 'readKv'>; path: string; account: string; value: string }): Promise<number> {
35
+ const cas = await o.vault.currentVersion(KV_MOUNT, o.path)
36
+ const version = await o.vault.writeKvCas(KV_MOUNT, o.path, { value: o.value, account: o.account }, cas)
37
+ const back = await o.vault.readKv(KV_MOUNT, o.path)
38
+ if (back?.['value'] !== o.value) throw new Error(`the vault read ${o.path} back as another value at v${version}`)
39
+ return version
40
+ }
@@ -0,0 +1,159 @@
1
+ // the vault's place on this machine (OpenBao beside the hq, wiki tools/shipkit/hq.md) and the config bao reads.
2
+ // The seal key is never in this text: bao reads it from its own environment (env://), where vault-serve.ts puts it
3
+ import { createHash, randomBytes } from 'crypto'
4
+ import { existsSync, realpathSync } from 'fs'
5
+ import { homedir } from 'os'
6
+ import { join, resolve } from 'path'
7
+ import { machinePath } from '../core/machine-layout.ts'
8
+ import { homeDir } from '../home/home-paths.ts'
9
+
10
+ /** the api, on loopback only. 4794 stays free for the vault's door to the tailnet */
11
+ export const DEFAULT_VAULT_PORT = 4793
12
+ /** raft's cluster listener: bao puts it on the api port + 1 unless told, which is the door's port */
13
+ export const DEFAULT_VAULT_CLUSTER_PORT = 4792
14
+
15
+ const envPort = (name: string, fallback: number): number => {
16
+ const n = Number(process.env[name])
17
+ return Number.isInteger(n) && n > 0 ? n : fallback
18
+ }
19
+
20
+ /** where the vault lives: its folder (mode 0700) and its two ports */
21
+ export type VaultPlace = { dir: string; port: number; clusterPort: number }
22
+
23
+ export const vaultPlace = (): VaultPlace => ({
24
+ dir: join(homeDir(), 'vault'),
25
+ port: envPort('SHIPKIT_VAULT_PORT', DEFAULT_VAULT_PORT),
26
+ clusterPort: envPort('SHIPKIT_VAULT_CLUSTER_PORT', DEFAULT_VAULT_CLUSTER_PORT),
27
+ })
28
+
29
+ export const vaultUrl = (p: VaultPlace): string => `http://127.0.0.1:${p.port}`
30
+ export const healthUrl = (p: VaultPlace): string => `${vaultUrl(p)}/v1/sys/health`
31
+
32
+ export const dataDir = (p: VaultPlace): string => join(p.dir, 'data')
33
+ export const auditLog = (p: VaultPlace): string => join(p.dir, 'audit.log')
34
+ export const configFile = (p: VaultPlace): string => join(p.dir, 'bao.hcl')
35
+ /** the token that mints the nodes' tokens (wiki services/secrets, step 2): 0600, never sent anywhere */
36
+ export const minterTokenFile = (p: VaultPlace): string => join(p.dir, 'minter-token')
37
+ /** written by `sk vault init` once the vault is initialised: no secret in it. Its presence is what starts the vault at login */
38
+ export const markerFile = (p: VaultPlace): string => join(p.dir, 'initialised.json')
39
+
40
+ export const vaultInitialised = (p: VaultPlace = vaultPlace()): boolean => existsSync(markerFile(p))
41
+
42
+ /** the login keychain item that holds the seal key: outside `rv/*`, so the secret manager, sk secret and the import never see it */
43
+ export const SEAL_SERVICE = 'shipkit-vault-seal'
44
+
45
+ /** the OS user's own home, from the user database: os.homedir() and os.userInfo() read $HOME, which a scratch run
46
+ * sets, and the real seal item must never follow it. Off macOS (no login keychain) the home as given */
47
+ let osHome: string | null = null
48
+ export function userHome(): string {
49
+ if (osHome != null) return osHome
50
+ osHome = homedir()
51
+ if (process.platform === 'darwin')
52
+ try {
53
+ const { dlopen, FFIType, CString, read } = require('bun:ffi') as typeof import('bun:ffi')
54
+ const { symbols, close } = dlopen('libc.dylib', { getpwuid: { args: [FFIType.u32], returns: FFIType.ptr }, getuid: { args: [], returns: FFIType.u32 } })
55
+ const pw = symbols.getpwuid(symbols.getuid())
56
+ // struct passwd on darwin: pw_dir after name, passwd, uid, gid, change, class, gecos
57
+ if (pw != null) osHome = new CString(read.ptr(pw, 48) as never).toString()
58
+ close()
59
+ } catch {
60
+ // no user database: the home as given
61
+ }
62
+ return osHome
63
+ }
64
+
65
+ /** the vault of this machine's real home (the OS user's own, userHome): the default of homeDir() under the machine's one root (layout.ts
66
+ * machinePath, the old root until the machine moved), whatever SHIPKIT_HOME_DIR says. A path that resolves to it
67
+ * through a link (the old root once moved) is it too */
68
+ export function isRealPlace(p: VaultPlace, home: string = userHome()): boolean {
69
+ const real = join(machinePath('home', home), 'vault')
70
+ if (resolve(p.dir) === real) return true
71
+ try {
72
+ return realpathSync(p.dir) === realpathSync(real)
73
+ } catch {
74
+ return false
75
+ }
76
+ }
77
+
78
+ /** the seal item of a place: the real one for the real home only. Any other home gets a name of its own, made from
79
+ * its folder, so no code run under a scratch home can name the real item */
80
+ export const sealServiceOf = (p: VaultPlace, home: string = userHome()): string => (isRealPlace(p, home) ? SEAL_SERVICE : `${SEAL_SERVICE}.scratch-${createHash('sha256').update(resolve(p.dir)).digest('hex').slice(0, 12)}`)
81
+ export const SEAL_ACCOUNT = 'vault'
82
+ /** the variable of bao's environment that carries the key */
83
+ export const SEAL_KEY_ENV = 'SHIPKIT_VAULT_SEAL_KEY'
84
+ /** the key's id in the seal stanza. A rotation adds the next id with the old key as `previous_key` */
85
+ export const SEAL_KEY_ID = 'shipkit-1'
86
+
87
+ /** 32 random bytes as 64 lowercase hex characters: the form bao decodes from env://, and one that needs no quoting
88
+ * on the keychain's stdin nor in a note */
89
+ export const newSealKey = (): string => randomBytes(32).toString('hex')
90
+ export const isSealKey = (s: string): boolean => /^[0-9a-f]{64}$/.test(s)
91
+
92
+ /** `bao` is the version init saw, `baoPath` the absolute binary it ran: the only one `sk vault serve` starts */
93
+ /** `auditPath`: the audit file the vault was initialised with. bao keeps that path inside its own data and answers
94
+ * 429 for good when the file is not there, so a vault served from a moved home declares it again */
95
+ export type MarkerData = { at: string; machine: string; keyId: string; bao: string; baoPath: string; auditPath?: string }
96
+
97
+ const q = (s: string): string => JSON.stringify(s)
98
+
99
+ /** the one audit device, declared in the config: OpenBao keeps a declared device in its own storage, so in every
100
+ * snapshot, and opens it at unseal before anything else; a device it cannot open leaves the node standby for good.
101
+ * Its path is RELATIVE, opened in bao's working folder (startBao runs bao in the vault's folder), so a snapshot
102
+ * restores on any machine and any path. A vault made with the older device `main` (an absolute path) drops it at
103
+ * its first start with this config: OpenBao disables a declared device the config no longer names */
104
+ export const AUDIT_DEVICE = 'local'
105
+ export const AUDIT_FILE = 'audit.log'
106
+
107
+ /** bao's config: raft on one node, loopback without tls, the static seal through env://, one file audit device
108
+ * (2.7 refuses one made through the api). No value in it is secret. `audit: false` is for a scratch vault that
109
+ * takes a snapshot: the snapshot carries the live device */
110
+ /** `unauthedRoot`: the listener takes the unauthenticated `sys/generate-root/*` calls (off by default since OpenBao
111
+ * 2.5.3), the one way to a root token from the recovery key in a vault no token opens: for a restore's run only */
112
+ /** the one road to a root token once the root token is revoked, said the same in every message: OpenBao (2.5.3 on)
113
+ * makes one from the recovery key only on a listener that takes the unauthenticated sys/generate-root calls */
114
+ export const ROOT_ROAD = 'a root token from the recovery key: OpenBao gives one only while its listener takes the unauthenticated sys/generate-root calls (disable_unauthed_generate_root_endpoints = false), which sk vault restore does for its run on an empty vault; on a live vault it is not built'
115
+
116
+ export function vaultHcl(p: VaultPlace, o: { audit?: boolean; unauthedRoot?: boolean } = {}): string {
117
+ const api = `127.0.0.1:${p.port}`
118
+ const cluster = `127.0.0.1:${p.clusterPort}`
119
+ return [
120
+ 'ui = false',
121
+ `api_addr = ${q(`http://${api}`)}`,
122
+ `cluster_addr = ${q(`http://${cluster}`)}`,
123
+ 'storage "raft" {',
124
+ ` path = ${q(dataDir(p))}`,
125
+ ' node_id = "shipkit"',
126
+ ' performance_multiplier = 1',
127
+ '}',
128
+ 'listener "tcp" {',
129
+ ` address = ${q(api)}`,
130
+ ` cluster_address = ${q(cluster)}`,
131
+ ' tls_disable = true',
132
+ ...(o.unauthedRoot === true ? [' disable_unauthed_generate_root_endpoints = false'] : []),
133
+ '}',
134
+ 'seal "static" {',
135
+ ` current_key_id = ${q(SEAL_KEY_ID)}`,
136
+ ` current_key = ${q(`env://${SEAL_KEY_ENV}`)}`,
137
+ '}',
138
+ ...(o.audit === false ? [] : [`audit "file" ${q(AUDIT_DEVICE)} {`, ' options {', ` file_path = ${q(AUDIT_FILE)}`, ' mode = "0600"', ' log_raw = "false"', ' hmac_accessor = "true"', ' }', '}']),
139
+ '',
140
+ ].join('\n')
141
+ }
142
+
143
+ /** bun test sets NODE_ENV=test in its process, and every child it starts inherits it: the gate's test checks run bun
144
+ * test, so a suite and every tool it spawns carry it */
145
+ export const underTest = (): boolean => process.env['NODE_ENV'] === 'test'
146
+
147
+ /** the guard of this machine's real vault: under a test, its place (isRealPlace) and its port (the default api port on
148
+ * loopback) are refused with a loud error before any file of it is read or any socket opened. A scratch vault on its
149
+ * own port and its own home passes; outside a test nothing is refused */
150
+ export function refuseRealVault(o: { place?: VaultPlace; url?: string }): void {
151
+ if (!underTest()) return
152
+ let hit: string | null = null
153
+ if (o.place != null && isRealPlace(o.place)) hit = o.place.dir
154
+ if (hit == null && o.url != null) {
155
+ const u = new URL(o.url)
156
+ if (['127.0.0.1', 'localhost', '0.0.0.0', '[::1]', '::1'].includes(u.hostname) && Number(u.port) === DEFAULT_VAULT_PORT) hit = o.url
157
+ }
158
+ if (hit != null) throw new Error(`a test reached for this machine's real vault (${hit}): give the suite a scratch SHIPKIT_HOME_DIR, and a scratch bao its own SHIPKIT_VAULT_PORT, as the vault's live suites do`)
159
+ }
@@ -0,0 +1,78 @@
1
+ // one secret destroyed for good, the owner's act alone: no token alive may destroy (a node never does, policy.ts), so a
2
+ // root token is made from the recovery key for this one act, in a window like the restore's. The served vault is
3
+ // stopped by the caller; bao runs on the vault's own data from a config in `<vault>.destroy` (the open root generation
4
+ // is never in the vault's bao.hcl), tethered to this process; every version and the metadata of the one path go, the
5
+ // root token is revoked, bao is stopped and the port checked free
6
+ import { existsSync, readFileSync, rmSync } from 'fs'
7
+ import { join } from 'path'
8
+ import { KV_MOUNT } from './layout.ts'
9
+ import { markerFile, vaultUrl, type VaultPlace } from './vault-config.ts'
10
+ import { VaultApi, waitHealth } from './vault-http.ts'
11
+ import { killRecorded, notePids, recordedGone } from './vault-restore.ts'
12
+ import { portHolders, startBao } from './vault-serve.ts'
13
+
14
+ export const destroyDirOf = (p: VaultPlace): string => `${p.dir}.destroy`
15
+
16
+ /** an act's root tokens no process holds any more, revoked by the minter (it may revoke by accessor): what a destroy
17
+ * or a restore killed after its root token leaves. Refused while an act runs (its work folder with a live bao): its
18
+ * token is held then. How many were revoked */
19
+ export async function revokeStrayRoots(place: VaultPlace, minter: Pick<VaultApi, 'accessors' | 'lookupAccessor' | 'revokeAccessor'>): Promise<{ revoked: number } | { refused: string }> {
20
+ for (const dir of [destroyDirOf(place), `${place.dir}.restore`]) {
21
+ if (!existsSync(join(dir, 'bao.pid'))) continue
22
+ const pids = readFileSync(join(dir, 'bao.pid'), 'utf8').split(/\s+/).map(Number).filter((n) => n > 0)
23
+ if (pids.some((pid) => Bun.spawnSync(['ps', '-o', 'command=', '-p', String(pid)]).stdout.toString().includes(`-config=${join(dir, 'bao.hcl')}`))) return { refused: `an act runs now (${dir}): its root token is held, nothing was revoked` }
24
+ }
25
+ let revoked = 0
26
+ for (const a of await minter.accessors()) {
27
+ if (!(await minter.lookupAccessor(a)).policies.includes('root')) continue
28
+ await minter.revokeAccessor(a)
29
+ revoked++
30
+ }
31
+ return { revoked }
32
+ }
33
+
34
+ /** the destroy, its exit code; each line through `say`, none with a key, a token or a value */
35
+ export async function destroyInVault(d: { place: VaultPlace; path: string; sealKey: string; recoveryKey: string; bin: string; say: (l: string) => void; step?: (s: 'root') => void | Promise<void> }): Promise<number> {
36
+ const fail = (l: string): number => (d.say(`FAIL: ${l}`), 1)
37
+ if (!existsSync(markerFile(d.place))) return fail(`no vault is initialised at ${d.place.dir}`)
38
+ if (portHolders(d.place).length > 0) return fail(`127.0.0.1:${d.place.port} is held: stop the vault first (sk gp stop vault)`)
39
+ const work = destroyDirOf(d.place)
40
+ if (existsSync(work)) {
41
+ const stopped = killRecorded(work)
42
+ rmSync(work, { recursive: true, force: true })
43
+ d.say(`ok: a destroy left half way was cleaned: ${work} removed${stopped > 0 ? ', its bao stopped' : ''}; sk vault status says if a root token of it is still alive`)
44
+ }
45
+ const bao = startBao({ place: d.place, key: d.sealKey, bin: d.bin, out: join(work, 'bao.log'), unauthedRoot: true, tethered: true, configDir: work })
46
+ notePids(work, bao)
47
+ const url = vaultUrl(d.place)
48
+ const held: { root: VaultApi | null } = { root: null }
49
+ const act = async (): Promise<number> => {
50
+ if ((await waitHealth(url, (h) => h?.code === 200, { ms: 60_000 }))?.code !== 200) return fail(`the vault did not open: see ${join(work, 'bao.log')}`)
51
+ notePids(work, bao)
52
+ const token = await new VaultApi(url).rootAfterRestore(d.recoveryKey.trim(), 30_000).catch((e: Error) => e)
53
+ if (token instanceof Error) return fail(`a root token from that recovery key: ${token.message}`)
54
+ const root = new VaultApi(url, token)
55
+ held.root = root
56
+ await d.step?.('root')
57
+ const had = await root.currentVersion(KV_MOUNT, d.path)
58
+ if (had === 0) return fail(`the vault holds nothing at ${d.path}: nothing was destroyed`)
59
+ await root.destroyAll(KV_MOUNT, d.path)
60
+ if ((await root.currentVersion(KV_MOUNT, d.path)) !== 0) return fail(`${d.path} still has metadata after the destroy`)
61
+ d.say(`ok: ${d.path} destroyed in the vault, its ${had} version${had === 1 ? '' : 's'} and its metadata, for good`)
62
+ return 0
63
+ }
64
+ let code: number
65
+ try {
66
+ code = await act()
67
+ } finally {
68
+ await held.root?.revokeSelf().catch(() => d.say('FAIL: the root token of this act could not be revoked: it dies with this bao, and sk vault status counts root tokens'))
69
+ await bao.stop()
70
+ killRecorded(work)
71
+ await recordedGone(work)
72
+ for (let i = 0; i < 50 && portHolders(d.place).length > 0; i++) await Bun.sleep(100)
73
+ rmSync(work, { recursive: true, force: true })
74
+ }
75
+ const left = portHolders(d.place)
76
+ if (left.length > 0) return fail(`a process still holds 127.0.0.1:${d.place.port}: ${left.map((h) => `pid ${h.pid}`).join(', ')}. Stop it (kill ${left.map((h) => h.pid).join(' ')}) before sk gp start vault`)
77
+ return code
78
+ }