rvlib-shipkit 2.25.0 → 2.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (456) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/package.json +2 -2
  3. package/src/agent-time/diet.ts +77 -0
  4. package/src/agent-time/family.ts +72 -0
  5. package/src/agent-time/hooks.ts +331 -0
  6. package/src/agent-time/limits.ts +44 -0
  7. package/src/agent-time/live.ts +1 -3
  8. package/src/agent-time/mask.ts +96 -18
  9. package/src/agent-time/refused.ts +45 -0
  10. package/src/agent-time/render.ts +130 -17
  11. package/src/agent-time/report-cache.ts +57 -0
  12. package/src/agent-time/report.ts +349 -23
  13. package/src/agent-time/shape.ts +50 -3
  14. package/src/agent-time/store.ts +370 -95
  15. package/src/agent-time/timeline.ts +140 -21
  16. package/src/agent-time/turns.ts +18 -8
  17. package/src/annex/offload.ts +17 -6
  18. package/src/annex/tidy.ts +70 -10
  19. package/src/asks/ask-after.ts +40 -0
  20. package/src/asks/asks-queue.ts +205 -47
  21. package/src/assets/kit-config.ts +7 -3
  22. package/src/assets/kits/identity-kit.ts +289 -10
  23. package/src/check.ts +3 -1
  24. package/src/checks/SK004-gitignore-policy.check.ts +12 -5
  25. package/src/checks/SK013-one-way-in-policy.check.ts +8 -3
  26. package/src/checks/SK026-asks-autoclose.check.ts +5 -5
  27. package/src/checks/SK028-readme.check.ts +7 -66
  28. package/src/checks/SK030-cache-audit.check.ts +6 -1
  29. package/src/checks/SK031-trace-audit.check.ts +2 -0
  30. package/src/checks/SK033-global-contribution.check.ts +3 -1
  31. package/src/checks/SK035-public-clean.check.ts +2 -2
  32. package/src/checks/SK043-scratch-on-the-mac.check.ts +59 -4
  33. package/src/checks/SK045-slow-hooks.check.ts +47 -0
  34. package/src/checks/SK046-hook-records.check.ts +76 -0
  35. package/src/checks/SK047-login-in-description.check.ts +36 -0
  36. package/src/checks/SK048-one-local-file.check.ts +36 -0
  37. package/src/cli/cmd_Asks.ts +71 -5
  38. package/src/cli/cmd_Backup.ts +5 -3
  39. package/src/cli/cmd_Capacity.ts +2 -2
  40. package/src/cli/cmd_CrossRepoActivity.ts +5 -4
  41. package/src/cli/cmd_Db.ts +253 -0
  42. package/src/cli/cmd_History.ts +212 -0
  43. package/src/cli/cmd_Home.ts +31 -3
  44. package/src/cli/cmd_Hq.ts +516 -0
  45. package/src/cli/cmd_Machines.ts +36 -0
  46. package/src/cli/cmd_Media.ts +38 -6
  47. package/src/cli/cmd_Mv.ts +1 -1
  48. package/src/cli/cmd_Reflect.ts +23 -2
  49. package/src/cli/cmd_Releases.ts +30 -0
  50. package/src/cli/cmd_Review.ts +569 -118
  51. package/src/cli/cmd_Secret.ts +62 -12
  52. package/src/cli/cmd_Social.ts +83 -1
  53. package/src/cli/cmd_Space.ts +324 -0
  54. package/src/cli/cmd_Time.ts +82 -5
  55. package/src/cli/cmd_Tmp.ts +28 -4
  56. package/src/cli/cmd_Trailer.ts +14 -10
  57. package/src/cli/cmd_Urls.ts +56 -0
  58. package/src/cli/cmd_Vault.ts +583 -0
  59. package/src/cli/family-help.ts +4 -2
  60. package/src/cli/family-pages.ts +1 -1
  61. package/src/cli/registry.ts +26 -4
  62. package/src/collections/actions.ts +63 -13
  63. package/src/collections/collection-types.ts +23 -1
  64. package/src/collections/providers.ts +117 -23
  65. package/src/collections/review.ts +4 -4
  66. package/src/commands/runner.ts +5 -1
  67. package/src/contracts/contract-manifests.ts +6 -5
  68. package/src/contracts/contract-types.ts +6 -4
  69. package/src/contracts/contracts-engine.ts +11 -0
  70. package/src/contracts/manifests/chrome-web-store.contract.ts +31 -0
  71. package/src/core/budget.ts +12 -17
  72. package/src/core/capacity.ts +27 -18
  73. package/src/core/check-runner.ts +7 -4
  74. package/src/core/history-files.ts +9 -5
  75. package/src/core/layout.ts +3 -0
  76. package/src/core/machine-busy.ts +127 -0
  77. package/src/core/machine-commit.ts +6 -1
  78. package/src/core/machine-db.ts +368 -20
  79. package/src/core/machine-layout.ts +137 -0
  80. package/src/core/machine-read.ts +81 -0
  81. package/src/core/migrate-layout.ts +1 -1
  82. package/src/core/one-way-in-policy.ts +64 -7
  83. package/src/core/polling-policy.ts +27 -0
  84. package/src/core/retention.ts +16 -2
  85. package/src/core/scope.ts +107 -14
  86. package/src/core/signal-name.ts +6 -0
  87. package/src/core/slots.ts +5 -4
  88. package/src/core/trace-audit.ts +6 -1
  89. package/src/core/transient.ts +6 -0
  90. package/src/drill/clean.ts +25 -1
  91. package/src/drill/run.ts +2 -2
  92. package/src/drill/seal.ts +27 -4
  93. package/src/home/activity-shape.ts +2 -0
  94. package/src/home/activity.ts +66 -3
  95. package/src/home/app-sign.ts +15 -4
  96. package/src/home/daemon-jobs.ts +149 -7
  97. package/src/home/database-projects.ts +111 -0
  98. package/src/home/database-words.ts +203 -0
  99. package/src/home/databases.ts +460 -0
  100. package/src/home/global-units.ts +6 -0
  101. package/src/home/gui-app/ShipkitGui.swift +122 -1
  102. package/src/home/gui-app.ts +6 -3
  103. package/src/home/home-move.ts +514 -0
  104. package/src/home/home-paths.ts +12 -3
  105. package/src/home/home-routes.ts +68 -0
  106. package/src/home/inbox-shape.ts +24 -14
  107. package/src/home/machine-fold.ts +820 -0
  108. package/src/home/machine-host.ts +20 -5
  109. package/src/home/machine-repair.ts +503 -0
  110. package/src/home/machine-stores.ts +66 -15
  111. package/src/home/machine-temp.ts +547 -86
  112. package/src/home/resume.ts +79 -0
  113. package/src/home/run-daemon.ts +25 -4
  114. package/src/home/run-pm.ts +18 -5
  115. package/src/home/serve-daemon.ts +18 -3
  116. package/src/home/serve-web.ts +175 -7
  117. package/src/home/space-job.ts +115 -0
  118. package/src/home/space-page.ts +257 -0
  119. package/src/home/space-route.ts +167 -0
  120. package/src/home/space-words.ts +103 -0
  121. package/src/home/time-page-shape.ts +202 -0
  122. package/src/home/time-page.ts +64 -0
  123. package/src/home/vault-page.ts +482 -0
  124. package/src/home/vault-words.ts +132 -0
  125. package/src/hooks/leak-guard.ts +40 -13
  126. package/src/hooks/one-way-in-guard.ts +17 -4
  127. package/src/hq/cards.ts +581 -0
  128. package/src/hq/door-route.ts +43 -0
  129. package/src/hq/door.ts +163 -0
  130. package/src/hq/files-send.ts +348 -0
  131. package/src/hq/forgotten-log.ts +35 -0
  132. package/src/hq/history-check.ts +255 -0
  133. package/src/hq/history-place.ts +146 -0
  134. package/src/hq/history-send.ts +487 -0
  135. package/src/hq/hq-db.ts +99 -0
  136. package/src/hq/hq-local.ts +469 -0
  137. package/src/hq/hq-routes.ts +196 -0
  138. package/src/hq/hq-store.ts +599 -0
  139. package/src/hq/kinds/ask.ts +147 -0
  140. package/src/hq/kinds/card-gone.ts +83 -0
  141. package/src/hq/kinds/card-msg.ts +66 -0
  142. package/src/hq/kinds/card.ts +99 -0
  143. package/src/hq/kinds/index.ts +21 -0
  144. package/src/hq/kinds/kind.ts +126 -0
  145. package/src/hq/kinds/media.ts +125 -0
  146. package/src/hq/kinds/prompt.ts +219 -0
  147. package/src/hq/kinds/reflection.ts +128 -0
  148. package/src/hq/kinds/report.ts +55 -0
  149. package/src/hq/kinds/time-day.ts +236 -0
  150. package/src/hq/ledger.ts +473 -0
  151. package/src/hq/machine-key.ts +44 -0
  152. package/src/hq/machine-notes.ts +131 -0
  153. package/src/hq/outbox.ts +372 -0
  154. package/src/hq/replica.ts +168 -0
  155. package/src/hq/repo-id.ts +4 -0
  156. package/src/hq/report-facts.ts +117 -0
  157. package/src/hq/report.ts +274 -0
  158. package/src/hq/switch.ts +151 -0
  159. package/src/hq/vault-grant.ts +92 -0
  160. package/src/identities/identities.ts +15 -3
  161. package/src/identities/steps.ts +31 -0
  162. package/src/ledger/db.ts +73 -26
  163. package/src/ledger/gate-checks.ts +29 -4
  164. package/src/ledger/git-key.ts +3 -3
  165. package/src/ledger/git-scan.ts +49 -7
  166. package/src/ledger/run-log.ts +11 -3
  167. package/src/ledger/store.ts +26 -4
  168. package/src/media-store/backup/daemon.ts +36 -17
  169. package/src/media-store/backup/kept.ts +241 -0
  170. package/src/media-store/backup/restore.ts +14 -4
  171. package/src/media-store/backup/run.ts +11 -11
  172. package/src/media-store/backup/secret.ts +6 -4
  173. package/src/media-store/backup/snapshot.ts +4 -2
  174. package/src/media-store/backup/sources.ts +68 -20
  175. package/src/media-store/copy/config.ts +77 -0
  176. package/src/media-store/copy/copy.ts +194 -0
  177. package/src/media-store/copy/lifecycle.ts +43 -0
  178. package/src/media-store/copy/night.ts +90 -0
  179. package/src/media-store/copy/proof.ts +151 -0
  180. package/src/media-store/copy/snapshot.ts +152 -0
  181. package/src/media-store/copy/store.ts +62 -0
  182. package/src/media-store/copy/stream.ts +176 -0
  183. package/src/media-store/daemon.ts +66 -16
  184. package/src/media-store/db.ts +22 -11
  185. package/src/media-store/forget.ts +23 -3
  186. package/src/media-store/hand.ts +4 -3
  187. package/src/media-store/hq-find.ts +75 -0
  188. package/src/media-store/hq-send.ts +277 -0
  189. package/src/media-store/kind.ts +2 -0
  190. package/src/media-store/purge.ts +18 -15
  191. package/src/media-store/put.ts +24 -8
  192. package/src/media-store/remote.ts +16 -7
  193. package/src/media-store/space-listing.ts +240 -0
  194. package/src/media-store/space.ts +40 -21
  195. package/src/media-store/sync.ts +5 -5
  196. package/src/media-store/tidy.ts +98 -0
  197. package/src/media-store/upload.ts +3 -3
  198. package/src/media-store/webp.ts +66 -0
  199. package/src/messages/model.ts +16 -7
  200. package/src/messages/routes.ts +14 -4
  201. package/src/messages/score.ts +2 -2
  202. package/src/messages/suggest.ts +96 -0
  203. package/src/pages/frame-client.ts +10 -0
  204. package/src/plan/planner.ts +28 -17
  205. package/src/recordings/media-kind.ts +1 -0
  206. package/src/recordings/model.ts +1 -1
  207. package/src/recordings/recorder-app/Capture.swift +9 -7
  208. package/src/reflect/hq-corpus.ts +56 -0
  209. package/src/reflect/prompt-corpus.ts +3 -1
  210. package/src/reflect/transcript.ts +146 -36
  211. package/src/release/machine-words.ts +67 -0
  212. package/src/release/public-clean.ts +8 -3
  213. package/src/releases/from-card.ts +1 -1
  214. package/src/releases/model.ts +18 -0
  215. package/src/releases/routes.ts +10 -5
  216. package/src/releases/store.ts +23 -2
  217. package/src/repo-config.ts +42 -2
  218. package/src/review/anim.ts +2 -2
  219. package/src/review/auto.ts +2 -2
  220. package/src/review/card-db.ts +244 -0
  221. package/src/review/card-rows.ts +266 -0
  222. package/src/review/cells.ts +76 -5
  223. package/src/review/draft-card.ts +41 -0
  224. package/src/review/draft-model.ts +78 -0
  225. package/src/review/format.ts +29 -10
  226. package/src/review/gone.ts +98 -0
  227. package/src/review/inbox-hook.ts +35 -0
  228. package/src/review/marks.ts +1 -1
  229. package/src/review/media-kind.ts +7 -5
  230. package/src/review/media-read.ts +9 -7
  231. package/src/review/media.ts +32 -5
  232. package/src/review/model.ts +214 -45
  233. package/src/review/move.ts +491 -0
  234. package/src/review/notes.ts +12 -20
  235. package/src/review/previews.ts +15 -19
  236. package/src/review/project.ts +1 -1
  237. package/src/review/rev.ts +8 -0
  238. package/src/review/role.ts +1 -1
  239. package/src/review/routes.ts +64 -13
  240. package/src/review/stage-card.ts +8 -4
  241. package/src/review/stage-routes.ts +1 -1
  242. package/src/review/store.ts +529 -83
  243. package/src/review/thread-fold.ts +51 -0
  244. package/src/review/threads.ts +147 -9
  245. package/src/review/trailer-auto-mock.ts +63 -0
  246. package/src/review/trailer-card.ts +4 -4
  247. package/src/review/trailer-desk.ts +41 -7
  248. package/src/review/trailer-media.ts +1 -0
  249. package/src/review/trailer-model.ts +8 -0
  250. package/src/review/trailer-notes.ts +1 -1
  251. package/src/review/trailer-routes.ts +9 -1
  252. package/src/review/unit.ts +6 -6
  253. package/src/review/watchers.ts +1 -1
  254. package/src/rules/untrack-generated.ts +92 -8
  255. package/src/secrets/held.ts +16 -0
  256. package/src/secrets/keychain.ts +113 -0
  257. package/src/secrets/list.ts +16 -6
  258. package/src/secrets/manager.ts +24 -10
  259. package/src/secrets/read.ts +257 -0
  260. package/src/secrets/who-reads.ts +49 -0
  261. package/src/serve/door-forward.ts +268 -0
  262. package/src/serve/door-names.ts +47 -0
  263. package/src/serve/embed.ts +1 -1
  264. package/src/serve/hub-app/activity-view.tsx +56 -32
  265. package/src/serve/hub-app/activity.css +7 -1
  266. package/src/serve/hub-app/asks-page.tsx +48 -0
  267. package/src/serve/hub-app/asks-st.ts +25 -0
  268. package/src/serve/hub-app/clock-svc.ts +1 -2
  269. package/src/serve/hub-app/col-card.tsx +64 -13
  270. package/src/serve/hub-app/col-list-page.tsx +122 -0
  271. package/src/serve/hub-app/col-list-st.ts +103 -0
  272. package/src/serve/hub-app/col-tables-view.tsx +10 -41
  273. package/src/serve/hub-app/col-tables.ts +76 -8
  274. package/src/serve/hub-app/cols-svc.ts +70 -16
  275. package/src/serve/hub-app/database-st.ts +260 -0
  276. package/src/serve/hub-app/database-view.tsx +289 -0
  277. package/src/serve/hub-app/database.css +32 -0
  278. package/src/serve/hub-app/entry-bar.css +14 -0
  279. package/src/serve/hub-app/entry-bar.tsx +33 -0
  280. package/src/serve/hub-app/entry-pick.ts +31 -0
  281. package/src/serve/hub-app/floating.tsx +1 -0
  282. package/src/serve/hub-app/hash-route.ts +11 -1
  283. package/src/serve/hub-app/header-bar.tsx +14 -18
  284. package/src/serve/hub-app/home-st.ts +89 -9
  285. package/src/serve/hub-app/home-strip.css +5 -19
  286. package/src/serve/hub-app/home-strip.tsx +58 -92
  287. package/src/serve/hub-app/home.html +7 -0
  288. package/src/serve/hub-app/hub-app.tsx +31 -142
  289. package/src/serve/hub-app/hub-types.ts +3 -1
  290. package/src/serve/hub-app/hub.css +109 -23
  291. package/src/serve/hub-app/icons.tsx +18 -1
  292. package/src/serve/hub-app/identities-st.ts +56 -6
  293. package/src/serve/hub-app/identities-view.tsx +100 -58
  294. package/src/serve/hub-app/identities.css +17 -15
  295. package/src/serve/hub-app/identity-address.ts +5 -0
  296. package/src/serve/hub-app/inbox-st.ts +41 -24
  297. package/src/serve/hub-app/inbox-view.tsx +37 -41
  298. package/src/serve/hub-app/inbox.css +2 -5
  299. package/src/serve/hub-app/index.html +7 -0
  300. package/src/serve/hub-app/kept-cols.tsx +7 -0
  301. package/src/serve/hub-app/keys.ts +28 -15
  302. package/src/serve/hub-app/later.tsx +26 -0
  303. package/src/serve/hub-app/list-filter.tsx +14 -0
  304. package/src/serve/hub-app/list-walk.ts +72 -3
  305. package/src/serve/hub-app/machines-st.ts +251 -0
  306. package/src/serve/hub-app/machines-view.tsx +224 -0
  307. package/src/serve/hub-app/machines.css +76 -0
  308. package/src/serve/hub-app/md-copy.tsx +79 -0
  309. package/src/serve/hub-app/media-view.tsx +2 -0
  310. package/src/serve/hub-app/messages/messages-page.tsx +79 -7
  311. package/src/serve/hub-app/messages/messages-st.ts +99 -3
  312. package/src/serve/hub-app/messages.css +14 -0
  313. package/src/serve/hub-app/page-keys.ts +175 -0
  314. package/src/serve/hub-app/pages-frames.tsx +11 -3
  315. package/src/serve/hub-app/palette-st.ts +58 -11
  316. package/src/serve/hub-app/palette-view.tsx +3 -1
  317. package/src/serve/hub-app/project-list.css +54 -8
  318. package/src/serve/hub-app/project-list.tsx +128 -59
  319. package/src/serve/hub-app/projects-svc.ts +78 -7
  320. package/src/serve/hub-app/reader-chips.tsx +13 -0
  321. package/src/serve/hub-app/readme-view.tsx +2 -3
  322. package/src/serve/hub-app/readme.css +27 -5
  323. package/src/serve/hub-app/reflections-page.tsx +42 -0
  324. package/src/serve/hub-app/reflections-st.ts +17 -0
  325. package/src/serve/hub-app/releases/releases-page.tsx +25 -2
  326. package/src/serve/hub-app/releases/releases-st.ts +1 -1
  327. package/src/serve/hub-app/repo-sections.ts +9 -5
  328. package/src/serve/hub-app/repo-st.ts +35 -8
  329. package/src/serve/hub-app/review/draft-card.tsx +163 -0
  330. package/src/serve/hub-app/review/kit.tsx +50 -7
  331. package/src/serve/hub-app/review/note-place.ts +1 -1
  332. package/src/serve/hub-app/review/review-board.tsx +2 -2
  333. package/src/serve/hub-app/review/review-cells.tsx +145 -65
  334. package/src/serve/hub-app/review/review-kit.ts +27 -1
  335. package/src/serve/hub-app/review/review-list.tsx +68 -30
  336. package/src/serve/hub-app/review/review-page.tsx +7 -8
  337. package/src/serve/hub-app/review/review-st.ts +111 -24
  338. package/src/serve/hub-app/review/review-thread.tsx +49 -19
  339. package/src/serve/hub-app/review/review-views.tsx +475 -144
  340. package/src/serve/hub-app/review/thread-control-st.ts +115 -0
  341. package/src/serve/hub-app/review/thread-control.tsx +74 -0
  342. package/src/serve/hub-app/review/thread-st.ts +73 -26
  343. package/src/serve/hub-app/review/trailer-card.tsx +1 -1
  344. package/src/serve/hub-app/review/trailer-page.tsx +37 -16
  345. package/src/serve/hub-app/review/trailer-st.ts +41 -7
  346. package/src/serve/hub-app/review.css +267 -61
  347. package/src/serve/hub-app/side-lists.ts +72 -0
  348. package/src/serve/hub-app/sidebar.tsx +6 -3
  349. package/src/serve/hub-app/site/site-part.tsx +2 -8
  350. package/src/serve/hub-app/site/site-st.ts +4 -4
  351. package/src/serve/hub-app/social/comms-page.tsx +20 -5
  352. package/src/serve/hub-app/social/kit.tsx +30 -4
  353. package/src/serve/hub-app/social/post-card.tsx +139 -49
  354. package/src/serve/hub-app/social/serial-writes.ts +13 -0
  355. package/src/serve/hub-app/social/social-model.ts +11 -0
  356. package/src/serve/hub-app/social/social-page.tsx +94 -35
  357. package/src/serve/hub-app/social/social-st.ts +120 -36
  358. package/src/serve/hub-app/social/stage-popup.tsx +1 -1
  359. package/src/serve/hub-app/social/stage-st.ts +1 -1
  360. package/src/serve/hub-app/social/step-layout.ts +1 -1
  361. package/src/serve/hub-app/social.css +3 -0
  362. package/src/serve/hub-app/space-st.ts +209 -0
  363. package/src/serve/hub-app/space-view.tsx +196 -0
  364. package/src/serve/hub-app/space.css +27 -0
  365. package/src/serve/hub-app/stores/stores-page.tsx +91 -23
  366. package/src/serve/hub-app/stores/stores-st.ts +44 -19
  367. package/src/serve/hub-app/stores.css +6 -1
  368. package/src/serve/hub-app/theme-st.ts +22 -9
  369. package/src/serve/hub-app/time-charts.tsx +291 -0
  370. package/src/serve/hub-app/time-pages.tsx +749 -0
  371. package/src/serve/hub-app/time-st.ts +162 -0
  372. package/src/serve/hub-app/time-view.tsx +76 -0
  373. package/src/serve/hub-app/time.css +138 -0
  374. package/src/serve/hub-app/tree-build.ts +52 -42
  375. package/src/serve/hub-app/tree-row.tsx +4 -4
  376. package/src/serve/hub-app/tree-svc.ts +18 -9
  377. package/src/serve/hub-app/urls-svc.ts +154 -0
  378. package/src/serve/hub-app/urls-view.tsx +117 -0
  379. package/src/serve/hub-app/urls.css +30 -0
  380. package/src/serve/hub-app/vault-st.ts +127 -0
  381. package/src/serve/hub-app/vault-view.tsx +154 -0
  382. package/src/serve/hub-app/vault.css +38 -0
  383. package/src/serve/hub-app/veille/veille-st.ts +12 -10
  384. package/src/serve/hub-app/waiting-svc.ts +29 -0
  385. package/src/serve/hub-app/wikis-view.tsx +2 -2
  386. package/src/serve/hub-runtime.ts +15 -2
  387. package/src/serve/project-gutter-route.ts +27 -14
  388. package/src/serve/project-gutter.ts +25 -12
  389. package/src/serve/same-origin.ts +10 -0
  390. package/src/serve/serve-hub.ts +13 -4
  391. package/src/shipkit-files.ts +16 -2
  392. package/src/shipkit.ts +1 -1
  393. package/src/shot/shooter.ts +616 -420
  394. package/src/shot/shot-ask.ts +246 -155
  395. package/src/site/desk.ts +2 -2
  396. package/src/smoke/run-smoke.ts +3 -2
  397. package/src/social/cover.ts +202 -0
  398. package/src/social/discord-layout.ts +37 -13
  399. package/src/social/drafts.ts +3 -0
  400. package/src/social/load.ts +23 -2
  401. package/src/social/media-kind.ts +2 -1
  402. package/src/social/publish/discord.ts +5 -2
  403. package/src/social/publish/secret.ts +2 -2
  404. package/src/social/release-stage.ts +28 -13
  405. package/src/social/routes.ts +26 -1
  406. package/src/social/stage.ts +1 -1
  407. package/src/social/stats.ts +12 -9
  408. package/src/social/strip.ts +4 -1
  409. package/src/social/thumbnail.ts +255 -0
  410. package/src/stores/collection.ts +15 -11
  411. package/src/stores/desk.ts +236 -42
  412. package/src/stores/model.ts +72 -6
  413. package/src/stores/routes.ts +37 -12
  414. package/src/stores/unit.ts +14 -8
  415. package/src/suite/judge-suites.ts +113 -16
  416. package/src/suite/select.ts +45 -3
  417. package/src/suite/suite-cli.ts +81 -34
  418. package/src/trailer/bed.ts +1 -1
  419. package/src/trailer/build.ts +134 -21
  420. package/src/trailer/ffmpeg.ts +7 -0
  421. package/src/trailer/fonts.ts +3 -2
  422. package/src/trailer/grammar.ts +201 -2
  423. package/src/trailer/graph.ts +42 -5
  424. package/src/trailer/look.ts +21 -0
  425. package/src/trailer/mock.ts +154 -0
  426. package/src/trailer/passage.ts +65 -26
  427. package/src/trailer/score/heard.ts +89 -0
  428. package/src/trailer/score/sound.ts +14 -8
  429. package/src/trailer/sound/run.ts +16 -6
  430. package/src/trailer/stitch.ts +26 -5
  431. package/src/trailer/titles.ts +82 -19
  432. package/src/trailer/versions.ts +1 -3
  433. package/src/trailer/vertical.ts +3 -1
  434. package/src/urls/frame.ts +195 -0
  435. package/src/urls/routes.ts +43 -0
  436. package/src/urls/rows.ts +171 -0
  437. package/src/urls/unit.ts +73 -0
  438. package/src/vault/house-keys.ts +42 -0
  439. package/src/vault/layout.ts +50 -0
  440. package/src/vault/policy.ts +165 -0
  441. package/src/vault/vault-audit.ts +276 -0
  442. package/src/vault/vault-client.ts +40 -0
  443. package/src/vault/vault-config.ts +159 -0
  444. package/src/vault/vault-destroy.ts +78 -0
  445. package/src/vault/vault-handover.ts +305 -0
  446. package/src/vault/vault-http.ts +352 -0
  447. package/src/vault/vault-import.ts +208 -0
  448. package/src/vault/vault-init.ts +328 -0
  449. package/src/vault/vault-minter.ts +271 -0
  450. package/src/vault/vault-restore.ts +333 -0
  451. package/src/vault/vault-serve.ts +342 -0
  452. package/src/vault/vault-snapshot.ts +281 -0
  453. package/src/veille/asks.ts +1 -1
  454. package/src/veille/desk.ts +2 -2
  455. package/src/wiki/run-wiki.ts +2 -1
  456. package/src/wiki/scan-md.ts +42 -2
@@ -0,0 +1,208 @@
1
+ // the import of this machine's keychain values into the vault, and the compare of the two (wiki services/secrets,
2
+ // step 2, section 9). The keychain is only READ: a value goes from it into this process, exact or refused with its
3
+ // reason, then on http to the vault, and is read back and compared there by its bytes. No line, file or error holds a
4
+ // value, a part of one or a hash of one. A name with no registry row is never imported, a value the vault already
5
+ // holds differently is never overwritten, and a read back that differs stops the import and removes nothing
6
+ import { closeSync, openSync, readFileSync, rmSync, writeSync } from 'fs'
7
+ import { join } from 'path'
8
+ import { NAME_PART, scopeText, type Scope } from '../core/scope.ts'
9
+ import type { Keychain } from '../secrets/keychain.ts'
10
+ import { KV_MOUNT, scopeRefs } from './layout.ts'
11
+ import { SLOTS, type VaultGrant } from './policy.ts'
12
+ import { vaultPathOf } from './vault-client.ts'
13
+ import { VaultApi } from './vault-http.ts'
14
+ import { mintNode, setNodeSlots } from './vault-minter.ts'
15
+
16
+ export type RegistryRow = { name: string; for?: Scope }
17
+
18
+ /** where one name of this machine's keychain goes: its path, or why it has none */
19
+ export type Placed = { name: string; scope: string; path?: string; why?: string }
20
+
21
+ /** a template row (`rv/realm/<word>/thing`) as the names it stands for: each `<word>` one part of a name */
22
+ const templateOf = (name: string): RegExp | null =>
23
+ name.includes('<') ? new RegExp(`^${name.split(/<[a-z-]+>/).map((p) => p.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join(NAME_PART.source.slice(1, -1))}$`) : null
24
+
25
+ /** each registry name this machine's keychain holds, and each `rv/` name it holds with no row, placed. A template row
26
+ * places every name it stands for. A row of several scopes is refused: the node template carries no exact line,
27
+ * and bao refuses a slot value of two parts (vault/policy.ts) */
28
+ export async function placeNames(o: { rows: RegistryRow[]; held: string[]; keyOf: (id: string) => Promise<string | null> }): Promise<Placed[]> {
29
+ const out: Placed[] = []
30
+ const exact = new Map(o.rows.filter((r) => templateOf(r.name) == null).map((r) => [r.name, r]))
31
+ const templates = o.rows.flatMap((r) => {
32
+ const t = templateOf(r.name)
33
+ return t == null ? [] : [{ t, row: r }]
34
+ })
35
+ for (const name of o.held) {
36
+ const row = exact.get(name) ?? templates.find((x) => x.t.test(name))?.row
37
+ if (row == null) {
38
+ out.push({ name, scope: '', why: 'no row in the registry: not imported' })
39
+ continue
40
+ }
41
+ const scope = scopeText(row.for)
42
+ if (scopeRefs(row.for).length > 1) {
43
+ out.push({ name, scope, why: 'filed under several scopes: the vault carries one scope a secret' })
44
+ continue
45
+ }
46
+ try {
47
+ out.push({ name, scope, path: await vaultPathOf(name, row.for, o.keyOf) })
48
+ } catch (e) {
49
+ out.push({ name, scope, why: (e as Error).message })
50
+ }
51
+ }
52
+ return out
53
+ }
54
+
55
+ /** how a value came out of the keychain: as `security` printed it, decoded from its hex form, or not at all */
56
+ export type Form = 'plain' | 'hex' | 'refused'
57
+
58
+ export type Imported = { name: string; did: 'would' | 'ok' | 'same' | 'differs' | 'refused' | 'failed'; form: Form; bytes: number; path?: string; why?: string; version?: number }
59
+
60
+ /** the vault's value against the keychain's, by their bytes, and the count of bytes the keychain gave */
61
+ const sameBytes = (held: string, read: string, bytes: number): boolean => {
62
+ const h = Buffer.from(held, 'utf8')
63
+ return h.length === bytes && h.equals(Buffer.from(read, 'utf8'))
64
+ }
65
+
66
+ /** every item under a name past the first a read gives: named, never copied */
67
+ function seconds(keychain: Keychain, name: string): (Imported & Compared)[] {
68
+ return keychain.accounts(name).slice(1).map((account) => ({ name, did: 'refused' as const, form: 'refused' as const, bytes: 0, why: `a second item under this name (account ${account}): not copied` }))
69
+ }
70
+
71
+ /** a read back that differs from what went: the import stops there, the name said, nothing removed */
72
+ export class ImportStopped extends Error {}
73
+
74
+ /** each placed name into the vault. The keychain is read, never written. `go` false: what it would do, the vault
75
+ * read and nothing written. A name the vault holds already is compared by its bytes: the same is left, another is
76
+ * left and said. A new one is written with check and set 0, then read back: a byte off stops the import */
77
+ export async function importNames(o: { placed: Placed[]; keychain: Keychain; vault: Pick<VaultApi, 'currentVersion' | 'writeKvCas' | 'readKv'>; go: boolean }): Promise<Imported[]> {
78
+ const out: Imported[] = []
79
+ for (const p of o.placed) {
80
+ out.push(...seconds(o.keychain, p.name))
81
+ const read = o.keychain.read(p.name)
82
+ if (read == null) {
83
+ out.push({ name: p.name, did: 'failed', form: 'refused', bytes: 0, why: 'the keychain no longer holds it' })
84
+ continue
85
+ }
86
+ if (!read.ok) {
87
+ out.push({ name: p.name, did: 'refused', form: 'refused', bytes: 0, why: read.why })
88
+ continue
89
+ }
90
+ const row = { name: p.name, form: read.form, bytes: read.bytes }
91
+ if (p.path == null) {
92
+ out.push({ ...row, did: 'refused', why: p.why })
93
+ continue
94
+ }
95
+ try {
96
+ const v = await o.vault.currentVersion(KV_MOUNT, p.path)
97
+ if (v > 0) {
98
+ const held = await o.vault.readKv(KV_MOUNT, p.path)
99
+ const same = typeof held?.['value'] === 'string' && sameBytes(held['value'], read.value, read.bytes)
100
+ out.push({ ...row, did: same ? 'same' : 'differs', path: p.path, version: v, ...(same ? {} : { why: 'the vault holds another value: neither is changed, the owner decides' }) })
101
+ continue
102
+ }
103
+ if (!o.go) {
104
+ out.push({ ...row, did: 'would', path: p.path })
105
+ continue
106
+ }
107
+ const version = await o.vault.writeKvCas(KV_MOUNT, p.path, { value: read.value, account: read.account }, 0)
108
+ const back = await o.vault.readKv(KV_MOUNT, p.path)
109
+ if (typeof back?.['value'] !== 'string' || !sameBytes(back['value'], read.value, read.bytes) || back['account'] !== read.account) throw new ImportStopped(`${p.name}: the vault read it back as another value at v${version}: the import stops here, nothing is removed`)
110
+ out.push({ ...row, did: 'ok', path: p.path, version })
111
+ } catch (e) {
112
+ if (e instanceof ImportStopped) throw e
113
+ out.push({ ...row, did: 'failed', path: p.path, why: (e as Error).message })
114
+ }
115
+ }
116
+ return out
117
+ }
118
+
119
+ export type Compared = { name: string; did: 'same' | 'differs' | 'absent' | 'refused' | 'failed'; form: Form; bytes: number; path?: string; why?: string }
120
+
121
+ /** each placed name, the keychain's value against the vault's, read by the same decoder as the import and compared
122
+ * in memory: same, differs, or absent from the vault. Nothing is written on either side */
123
+ export async function compareNames(o: { placed: Placed[]; keychain: Keychain; vault: Pick<VaultApi, 'readKv'> }): Promise<Compared[]> {
124
+ const out: Compared[] = []
125
+ for (const p of o.placed) {
126
+ out.push(...seconds(o.keychain, p.name))
127
+ const read = o.keychain.read(p.name)
128
+ if (read == null || !read.ok) {
129
+ out.push({ name: p.name, did: read == null ? 'failed' : 'refused', form: 'refused', bytes: 0, why: read == null ? 'the keychain no longer holds it' : read.why })
130
+ continue
131
+ }
132
+ const row = { name: p.name, form: read.form, bytes: read.bytes }
133
+ if (p.path == null) {
134
+ out.push({ ...row, did: 'refused', why: p.why })
135
+ continue
136
+ }
137
+ try {
138
+ const held = await o.vault.readKv(KV_MOUNT, p.path)
139
+ if (typeof held?.['value'] !== 'string') out.push({ ...row, did: 'absent', path: p.path })
140
+ else out.push({ ...row, did: sameBytes(held['value'], read.value, read.bytes) ? 'same' : 'differs', path: p.path })
141
+ } catch (e) {
142
+ out.push({ ...row, did: 'failed', path: p.path, why: (e as Error).message })
143
+ }
144
+ }
145
+ return out
146
+ }
147
+
148
+ /** one import or compare at a time on this machine: a file made with O_EXCL beside the vault, its pid inside; one
149
+ * left by a process that is gone is taken over */
150
+ export async function withImportLock<T>(dir: string, run: () => Promise<T>): Promise<T> {
151
+ const file = join(dir, 'import.lock')
152
+ let fd: number
153
+ try {
154
+ fd = openSync(file, 'wx', 0o600)
155
+ } catch {
156
+ let pid = NaN
157
+ try {
158
+ pid = Number(readFileSync(file, 'utf8').trim())
159
+ } catch {
160
+ pid = NaN
161
+ }
162
+ let alive = false
163
+ try {
164
+ if (!Number.isInteger(pid) || pid <= 0) throw new Error('no pid')
165
+ process.kill(pid, 0)
166
+ alive = true
167
+ } catch {
168
+ alive = false
169
+ }
170
+ if (alive) throw new Error(`another import or compare runs on this machine (pid ${pid}): wait for it`)
171
+ rmSync(file, { force: true })
172
+ fd = openSync(file, 'wx', 0o600)
173
+ }
174
+ writeSync(fd, String(process.pid))
175
+ closeSync(fd)
176
+ try {
177
+ return await run()
178
+ } finally {
179
+ rmSync(file, { force: true })
180
+ }
181
+ }
182
+
183
+ /** the grants that write every placed path: all (all, repo and identity whole) and each machine named, four at most */
184
+ export function importGrants(placed: Placed[]): VaultGrant[] {
185
+ const machines = [...new Set(placed.flatMap((p) => (p.path?.startsWith('machine/') === true ? [p.path.split('/')[1]!] : [])))].sort()
186
+ if (machines.length > SLOTS.machine) throw new Error(`the import writes for ${machines.length} machines, and one token carries ${SLOTS.machine}: run it again with fewer names`)
187
+ return [{ kind: 'all' }, ...machines.map((name) => ({ kind: 'machine' as const, name }))]
188
+ }
189
+
190
+ /** a run with a node token of its own, minted by the minter for this one run and revoked after it, its entity
191
+ * emptied: the import never needs a root token, and nothing it held outlives it */
192
+ export async function withImportToken<T>(minter: VaultApi, url: string, machine: string, placed: Placed[], run: (vault: VaultApi) => Promise<T>): Promise<T> {
193
+ const t = await mintNode(minter, `import-${machine}`, importGrants(placed))
194
+ try {
195
+ return await run(new VaultApi(url, t.token))
196
+ } finally {
197
+ await minter.revokeAccessor(t.accessor).catch(() => undefined)
198
+ await setNodeSlots(minter, t.entity, null).catch(() => undefined)
199
+ }
200
+ }
201
+
202
+ /** the counts of the last compare, names only, so the house check says them with no read of a value */
203
+ /** `held`: the `rv/` names the keychain held at the compare, names only (the vault page's keychain column) */
204
+ export type CompareSummary = { at: number; same: number; differs: number; absent: number; refused: number; failed: number; differing: string[]; held?: string[] }
205
+ export const summaryOf = (rows: Compared[], at: number): CompareSummary => {
206
+ const n = (d: Compared['did']): number => rows.filter((r) => r.did === d).length
207
+ return { at, same: n('same'), differs: n('differs'), absent: n('absent'), refused: n('refused'), failed: n('failed'), differing: rows.filter((r) => r.did === 'differs').map((r) => r.name) }
208
+ }
@@ -0,0 +1,328 @@
1
+ // `sk vault init`, typed by the owner in his own terminal: it makes the seal key, keeps it in the login keychain,
2
+ // initialises the vault, sets up what the hq needs (the mounts, the token role `node`, the minter), revokes the root
3
+ // token, hands him the keys (vault-handover.ts), and only then hands the vault to pm. `--reset` undoes an init
4
+ // while the vault holds no secret. No line, file or returned value holds a key
5
+ import { existsSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'fs'
6
+ import { isAbsolute, resolve } from 'path'
7
+ import { AUDIT_DEVICE, auditLog, configFile, dataDir, isSealKey, markerFile, sealServiceOf, minterTokenFile, newSealKey, ROOT_ROAD, SEAL_KEY_ID, SEAL_SERVICE, vaultUrl, type MarkerData, type VaultPlace } from './vault-config.ts'
8
+ import { handOver, holdSealNote, initNote, KeyGuard, sealNote, type Clipboard, type Signals, type Terminal } from './vault-handover.ts'
9
+ import { VaultApi, vaultHealth, waitHealth } from './vault-http.ts'
10
+ import { MINTER_PERIOD, MINTER_POLICY, MINTER_POLICY_NAME, writeNodeSetup } from './vault-minter.ts'
11
+ import { auditPathOf, baoVersion, markerBaoProblem, readMarker, startBao, type SealStore } from './vault-serve.ts'
12
+
13
+ /** variables a coding agent's session sets in the shell it runs commands in. CLAUDE_CONFIG_DIR is not one: an
14
+ * owner's own terminal may set it to pick an account */
15
+ export const AGENT_ENV = ['CLAUDECODE', 'CLAUDE_CODE_ENTRYPOINT', 'CLAUDE_CODE_SESSION_ID', 'CLAUDE_PID', 'AI_AGENT', 'CODEX_SANDBOX', 'CODEX_THREAD_ID', 'GEMINI_CLI', 'CURSOR_AGENT']
16
+ const SSH_ENV = ['SSH_TTY', 'SSH_CONNECTION', 'SSH_CLIENT']
17
+
18
+ /** why this run is not the owner typing at the Mac's own desktop, null when it is. A guard against a mistake, not
19
+ * a wall: any process of his user reads the seal key, since `sk vault serve` reads it with no prompt */
20
+ export function notTypedByOwner(o: { env: Record<string, string | undefined>; stdinTTY: boolean; stdoutTTY: boolean }): string | null {
21
+ const set = (keys: string[]): string[] => keys.filter((k) => (o.env[k] ?? '') !== '')
22
+ const agent = set(AGENT_ENV)
23
+ if (agent.length > 0) return `this shell belongs to an agent's session (${agent.join(', ')}): no agent may hold a key of the vault. Run it in Terminal.app`
24
+ const ssh = set(SSH_ENV)
25
+ if (ssh.length > 0) return `this is an ssh session (${ssh.join(', ')}): the clipboard is not yours and the keychain may be locked. Run it in Terminal.app at the vault Mac's own desktop`
26
+ if ((o.env['RV_KEYCHAIN_BIN'] ?? '') !== '') return 'RV_KEYCHAIN_BIN is set: the seal key would go to that binary, not the login keychain. Unset it, then run it again'
27
+ if (!o.stdinTTY || !o.stdoutTTY) return 'no terminal on stdin and stdout: it is typed by the owner only. Run it in Terminal.app'
28
+ return null
29
+ }
30
+
31
+ export type InitDeps = {
32
+ place: VaultPlace
33
+ seal: SealStore
34
+ clipboard: Clipboard
35
+ /** a round trip on a pasteboard before any key exists: why it cannot hand a note, or null */
36
+ proveClipboard?: () => string | null
37
+ /** one line typed by the owner */
38
+ ask: (question: string) => Promise<string>
39
+ say: (line: string) => void
40
+ machine: string
41
+ /** the absolute path of the bao to run: recorded in the marker, the only one serve starts */
42
+ bin: string
43
+ now?: () => Date
44
+ /** hand the vault to pm and wait until it answers unsealed: true when it did */
45
+ startUnderPm: () => Promise<boolean>
46
+ /** pins openbao so an upgrade is a deliberate act; absent under test */
47
+ pin?: () => string
48
+ clearAfterMs?: number
49
+ /** where bao writes while init holds it */
50
+ baoLog?: string
51
+ signals?: Signals
52
+ terminal?: Terminal
53
+ }
54
+
55
+ const RESET = 'if the vault holds no secret yet (a crash during init), sk vault init --reset undoes it'
56
+
57
+ /** why init cannot run on this place, null when it can */
58
+ export async function initRefusal(d: Pick<InitDeps, 'place' | 'seal'>): Promise<string | null> {
59
+ if (existsSync(markerFile(d.place))) return `the vault of this machine is initialised already (${markerFile(d.place)}): init runs once. ${RESET}`
60
+ if (existsSync(dataDir(d.place)) && readdirSync(dataDir(d.place)).length > 0) return `a vault's data is there already (${dataDir(d.place)}): init never writes over it. ${RESET}`
61
+ try {
62
+ if (d.seal.has()) return `the keychain holds a seal key already (${sealServiceOf(d.place)}): init would orphan the data it opens. ${RESET}`
63
+ } catch (e) {
64
+ return (e as Error).message
65
+ }
66
+ const h = await vaultHealth(vaultUrl(d.place), 500)
67
+ if (h != null) return `something answers on 127.0.0.1:${d.place.port} already (health ${h.code}): stop it first: sk gp stop vault, or for a bao left by a killed init, pkill -f ${configFile(d.place)}`
68
+ return null
69
+ }
70
+
71
+ /** what the hq needs and only the root token may write: the node policy, the role, the narrow minter. Its token */
72
+ export async function setupMinter(root: VaultApi): Promise<string> {
73
+ await writeNodeSetup(root)
74
+ await root.writePolicy(MINTER_POLICY_NAME, MINTER_POLICY)
75
+ return (await root.createToken({ policies: [MINTER_POLICY_NAME], period: MINTER_PERIOD, orphan: true, displayName: 'shipkit-minter' })).token
76
+ }
77
+
78
+ /** the mounts, the role, the minter, its token to a file: everything the root token is needed for */
79
+ async function configure(root: VaultApi, d: InitDeps): Promise<void> {
80
+ await root.mount('rv', 'kv', { version: '2' })
81
+ await root.mount('totp', 'totp')
82
+ if (!(await root.audits()).includes(`${AUDIT_DEVICE}/`)) throw new Error('the audit file of the config is not enabled')
83
+ writeFileSync(minterTokenFile(d.place), `${await setupMinter(root)}\n`, { mode: 0o600 })
84
+ }
85
+
86
+ /** the whole init, its exit code. Every line goes through `say`, and none holds a key. The guard is installed
87
+ * before the first key exists, and the keys are handed right after the root token is revoked: the slow steps
88
+ * (bao stopped, the marker, pm) come after he holds them */
89
+ export async function initVault(d: InitDeps): Promise<number> {
90
+ const now = d.now ?? (() => new Date())
91
+ const refused = await initRefusal(d)
92
+ if (refused != null) {
93
+ d.say(`FAIL: ${refused}`)
94
+ return 1
95
+ }
96
+ const board = d.proveClipboard?.() ?? null
97
+ if (board != null) {
98
+ d.say(`FAIL: the pasteboard cannot hand the keys over (${board}): nothing was made. Run it in Terminal.app at the vault Mac's own desktop`)
99
+ return 1
100
+ }
101
+ const version = isAbsolute(d.bin) ? baoVersion(d.bin) : null
102
+ if (version == null) {
103
+ d.say(`FAIL: ${d.bin} is no OpenBao (an absolute path to bao, brew install openbao): nothing was made`)
104
+ return 1
105
+ }
106
+ if (d.pin != null) d.say(d.pin())
107
+ const g = new KeyGuard(d).install()
108
+ try {
109
+ const sealKey = newSealKey()
110
+ g.rollback = () => {
111
+ d.seal.remove()
112
+ rmSync(dataDir(d.place), { recursive: true, force: true })
113
+ rmSync(configFile(d.place), { force: true })
114
+ }
115
+ try {
116
+ d.seal.write(sealKey)
117
+ } catch (e) {
118
+ d.say(`FAIL: ${(e as Error).message}: nothing else was done`)
119
+ return 1
120
+ }
121
+ if (d.seal.read() !== sealKey) {
122
+ d.say(`FAIL: the keychain did not keep the seal key (${sealServiceOf(d.place)}): nothing else was done`)
123
+ return 1
124
+ }
125
+ d.say(`ok: a new seal key is in this Mac's login keychain (${sealServiceOf(d.place)})`)
126
+ const url = vaultUrl(d.place)
127
+ g.bao = startBao({ place: d.place, key: sealKey, bin: d.bin, out: d.baoLog, detached: true })
128
+ const fresh = await waitHealth(url, (h) => h?.code === 501, { ms: 30_000, gone: g.bao.gone })
129
+ if (fresh?.code !== 501) {
130
+ d.say(`FAIL: bao did not start on 127.0.0.1:${d.place.port} (${fresh == null ? 'no answer' : `health ${fresh.code}`}): the key and the data are removed, nothing was initialised${d.baoLog == null ? '' : `. Its log: ${d.baoLog}`}`)
131
+ return 1
132
+ }
133
+ let keys: { rootToken: string; recoveryKey: string }
134
+ try {
135
+ keys = await new VaultApi(url).init()
136
+ } catch (e) {
137
+ const h = await vaultHealth(url)
138
+ if (h?.initialized === true) g.rollback = null
139
+ d.say(`FAIL: the init was refused: ${(e as Error).message}${h?.initialized === true ? `. The vault says it is initialised: the key stays in the keychain (${sealServiceOf(d.place)}). ${RESET}` : ': the key and the data are removed'}`)
140
+ return 1
141
+ }
142
+ g.rollback = null
143
+ g.root = new VaultApi(url, keys.rootToken)
144
+ let ok = true
145
+ const up = await waitHealth(url, (h) => h?.code === 200, { ms: 30_000, gone: g.bao.gone })
146
+ if (up?.code !== 200) {
147
+ ok = false
148
+ d.say(`FAIL: the vault did not open after its init (${up == null ? 'no answer' : `health ${up.code}`})`)
149
+ } else
150
+ try {
151
+ await configure(g.root, d)
152
+ d.say('ok: the vault is initialised: kv at rv/, totp at totp/, the audit file, the token role node, the minter')
153
+ } catch (e) {
154
+ ok = false
155
+ d.say(`FAIL: the vault is initialised but its setup broke: ${(e as Error).message}. ${RESET}`)
156
+ }
157
+ if (await g.revokeRoot()) d.say('ok: the root token is revoked: no root token is alive')
158
+ else {
159
+ ok = false
160
+ d.say('FAIL: the root token still answers. It is held in this process only, and dies with no copy')
161
+ }
162
+ const proved = await handOver(initNote({ machine: d.machine, at: now(), sealKey, recoveryKey: keys.recoveryKey }), sealKey, { ...d, guard: g })
163
+ if (g.ended) return 1
164
+ if (proved) d.say('ok: your copy matches the seal key')
165
+ else ok = false
166
+ await g.bao.stop()
167
+ g.bao = null
168
+ if (!ok) {
169
+ d.say(`WARN the vault is not handed to pm. ${RESET}`)
170
+ return 1
171
+ }
172
+ const marker: MarkerData = { at: now().toISOString(), machine: d.machine, keyId: SEAL_KEY_ID, bao: version, baoPath: d.bin, auditPath: resolve(auditLog(d.place)) }
173
+ writeFileSync(markerFile(d.place), `${JSON.stringify(marker, null, 2)}\n`, { mode: 0o600 })
174
+ if (await d.startUnderPm()) d.say('ok: pm runs the vault, unsealed with nobody typing, and starts it at each login')
175
+ else {
176
+ d.say('WARN the vault is initialised, but pm did not bring it up unsealed: sk gp start vault, then sk vault status')
177
+ return 1
178
+ }
179
+ return 0
180
+ } finally {
181
+ if (!g.ended) await g.cleanup()
182
+ g.uninstall()
183
+ }
184
+ }
185
+
186
+ /** the mounts init makes, beside the ones every vault has */
187
+ const INIT_MOUNTS = ['cubbyhole/', 'identity/', 'sys/', 'rv/', 'totp/']
188
+
189
+ /** the secrets a vault holds, counted with its minter: every mount is read first, and one init never made may hold
190
+ * anything, so it is a refusal; then the kv paths and the totp keys, never a value. Why, when they cannot be counted */
191
+ export async function heldSecrets(url: string, minterToken: string): Promise<{ n: number } | { why: string }> {
192
+ const minter = new VaultApi(url, minterToken)
193
+ try {
194
+ const other = (await minter.mounts()).filter((m) => !INIT_MOUNTS.includes(m))
195
+ if (other.length > 0) return { why: `the vault holds mounts init never made (${other.join(', ')}): each may hold secrets` }
196
+ } catch (e) {
197
+ return { why: `the minter cannot read the vault's mounts (${(e as Error).message}): a vault made before the narrow needs sk vault narrow first` }
198
+ }
199
+ try {
200
+ const kv = (await minter.versions('rv')).size
201
+ const totp = await minter.listKeys('totp/keys')
202
+ return { n: kv + totp.length }
203
+ } catch (e) {
204
+ return { why: `the minter cannot count them: ${(e as Error).message}` }
205
+ }
206
+ }
207
+
208
+ /** what init's root token asks, in its order (configure, then setupMinter): the audit file of an init that stopped
209
+ * holds a beginning of it. The live tier of the init proves the order against a real audit file */
210
+ export const INIT_REQUESTS = ['sys/mounts/rv', 'sys/mounts/totp', 'sys/audit', 'sys/policies/acl/shipkit-node', 'auth/token/roles/node', 'sys/policies/acl/shipkit-minter', 'auth/token/create-orphan']
211
+ /** the line the audit device writes as it starts, before any request: the file of a vault begins with it */
212
+ const AUDIT_START = 'sys/audit/test'
213
+
214
+ /** why the audit file shows more than init at work, null when it shows init alone: it begins as a vault's start
215
+ * does, its root token's requests are a beginning of init's own in their order (the revoke of the root token may
216
+ * end them), and no token other than root made one. An empty file, a file cut at its start, or a line that does not
217
+ * read proves nothing. A file cut at its end is a crash at that line: it cannot be told apart, so it is taken */
218
+ export function auditBeyondInit(file: string): string | null {
219
+ if (!existsSync(file)) return `its audit file is not there (${file})`
220
+ let next = 0
221
+ let first = true
222
+ let revoked = false
223
+ for (const line of readFileSync(file, 'utf8').split('\n')) {
224
+ if (line.trim() === '') continue
225
+ let e: { type?: string; auth?: { policies?: string[] | null }; request?: { path?: string } }
226
+ try {
227
+ e = JSON.parse(line) as typeof e
228
+ } catch {
229
+ return 'a line of its audit file does not read'
230
+ }
231
+ if (e.type !== 'request') continue
232
+ const path = e.request?.path ?? ''
233
+ if (first && path !== AUDIT_START) return `its audit file does not begin as a vault's start does (${path}): it was cut at its start`
234
+ first = false
235
+ const policies = e.auth?.policies
236
+ if (policies == null || policies.length === 0) continue
237
+ if (!policies.includes('root')) return `its audit file shows a token of ${policies.join(', ')} at work (${path})`
238
+ if (revoked) return `its audit file shows the root token at work after its revoke (${path})`
239
+ if (path === 'auth/token/revoke-self') revoked = true
240
+ else if (path === INIT_REQUESTS[next]) next++
241
+ else return `its audit file shows the root token out of init's order (${path})`
242
+ }
243
+ return first ? 'its audit file is empty: an audit file that does not hold a vault\'s start proves nothing' : null
244
+ }
245
+
246
+ /** `sk vault init --reset`: undo an init while the vault holds no secret, so init can run again. It proves the vault
247
+ * empty first: never initialised (501), or counted with its minter (zero kv paths, zero totp keys), or, with no
248
+ * minter and no marker, by construction: the root token never left init, and init writes no secret */
249
+ export async function resetVault(d: Pick<InitDeps, 'place' | 'seal' | 'say' | 'bin' | 'baoLog'>): Promise<number> {
250
+ const fail = (why: string): number => (d.say(`FAIL: ${why}`), 1)
251
+ const h0 = await vaultHealth(vaultUrl(d.place), 500)
252
+ if (h0 != null) return fail(`something answers on 127.0.0.1:${d.place.port} (health ${h0.code}): stop it first: sk gp stop vault, or for a bao left by a killed init, pkill -f ${configFile(d.place)}`)
253
+ let key: string | null
254
+ try {
255
+ key = d.seal.read()
256
+ } catch (e) {
257
+ return fail((e as Error).message)
258
+ }
259
+ const data = existsSync(dataDir(d.place)) && readdirSync(dataDir(d.place)).length > 0
260
+ const marker = readMarker(d.place)
261
+ if (!data && key == null && marker == null) return fail('there is nothing to reset: no data, no marker, no seal key')
262
+ // the key is removed only once the vault of this place opened with it: a key no data proves its own may open
263
+ // another vault's data or its snapshots
264
+ let opened = false
265
+ if (data) {
266
+ if (key == null) return fail(`the vault's data is there but its seal key is not in the keychain (${sealServiceOf(d.place)}): nothing can prove it empty. Put the key back from your password manager, then run it again`)
267
+ const wrong = marker == null ? null : markerBaoProblem(d.place, marker)
268
+ if (wrong != null) return fail(`${wrong}: nothing was removed`)
269
+ const bao = startBao({ place: d.place, key, bin: marker?.baoPath ?? d.bin, out: d.baoLog, detached: true })
270
+ try {
271
+ const h = await waitHealth(vaultUrl(d.place), (x) => x?.code === 200 || x?.code === 501, { ms: 30_000, gone: bao.gone })
272
+ if (h?.code === 501) d.say('the vault was never initialised: it holds nothing')
273
+ else if (h?.code !== 200) return fail(`the vault does not open with the keychain's key (${h == null ? 'no answer' : `health ${h.code}`}): nothing was removed`)
274
+ else if (existsSync(minterTokenFile(d.place))) {
275
+ const held = await heldSecrets(vaultUrl(d.place), (await Bun.file(minterTokenFile(d.place)).text()).trim())
276
+ if ('why' in held) return fail(`${held.why}: nothing was removed. The way is ${ROOT_ROAD}`)
277
+ if (held.n > 0) return fail(`the vault holds ${held.n} secret${held.n === 1 ? '' : 's'}: a reset would lose them, nothing was removed. The way is ${ROOT_ROAD}`)
278
+ d.say('the vault holds no secret: no kv path, no totp key (counted with the minter)')
279
+ } else if (marker != null) return fail(`${markerFile(d.place)} says init finished, but its minter token is gone: nothing can prove the vault empty. The way is ${ROOT_ROAD}`)
280
+ else {
281
+ const why = auditBeyondInit(auditPathOf(d.place))
282
+ if (why != null) return fail(`there is no minter token and no marker, but ${why}: nothing can prove the vault empty, nothing was removed. The way is ${ROOT_ROAD}`)
283
+ d.say("the vault holds no secret: there is no minter token, and the audit file shows init's root token alone at work, on sys and auth only")
284
+ }
285
+ opened = true
286
+ } finally {
287
+ await bao.stop()
288
+ }
289
+ }
290
+ const removed: string[] = []
291
+ for (const [what, path] of [
292
+ ['the data', dataDir(d.place)],
293
+ ['the config', configFile(d.place)],
294
+ ['the marker', markerFile(d.place)],
295
+ ['the minter token', minterTokenFile(d.place)],
296
+ ] as const)
297
+ if (existsSync(path)) {
298
+ rmSync(path, { recursive: true, force: true })
299
+ removed.push(`${what} (${path})`)
300
+ }
301
+ if (key != null && opened) {
302
+ d.seal.remove()
303
+ removed.push(`the seal key in the login keychain (${sealServiceOf(d.place)})`)
304
+ }
305
+ for (const r of removed) d.say(`removed ${r}`)
306
+ if (key != null && !opened) {
307
+ d.say(`FAIL: the seal key (${sealServiceOf(d.place)}) is kept: no vault data here opened with it, so it may be the one key of data or snapshots elsewhere. If it is the key of an init killed before its vault started, and your password manager holds no note of it: security delete-generic-password -s ${sealServiceOf(d.place)} -a vault`)
308
+ return 1
309
+ }
310
+ d.say('ok: the vault is reset; the audit file is kept. Run sk vault init again')
311
+ return 0
312
+ }
313
+
314
+ /** `sk vault key --copy`: the seal key from the keychain into the clipboard, as a short note, cleared after 90 s */
315
+ export async function copySealKey(d: Pick<InitDeps, 'seal' | 'clipboard' | 'say' | 'machine' | 'now' | 'clearAfterMs' | 'signals'> & { sleep?: (ms: number) => Promise<void> }): Promise<number> {
316
+ let key: string | null
317
+ try {
318
+ key = d.seal.read()
319
+ } catch (e) {
320
+ d.say(`FAIL: ${(e as Error).message}`)
321
+ return 1
322
+ }
323
+ if (key == null || !isSealKey(key)) {
324
+ d.say(`FAIL: no seal key in this Mac's login keychain (${SEAL_SERVICE}): the vault was not initialised here`)
325
+ return 1
326
+ }
327
+ return await holdSealNote(sealNote({ machine: d.machine, at: (d.now ?? (() => new Date()))(), sealKey: key }), d)
328
+ }