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,305 @@
1
+ // the one way the vault's keys leave a process: the owner's clipboard, as one note for his password manager, held
2
+ // until he proves his copy. The guard owns SIGINT, SIGHUP and SIGTERM while a key exists: whatever ends the run,
3
+ // the clipboard does not keep the note, the echo comes back, no root token outlives it and the bao it started stops
4
+ import { SEAL_SERVICE } from './vault-config.ts'
5
+ import type { VaultApi } from './vault-http.ts'
6
+ import type { Bao } from './vault-serve.ts'
7
+
8
+ export type Clipboard = { write(text: string): void; read(): string }
9
+
10
+ /** a pasteboard through AppKit, the text on stdin. A write is for this Mac only (no Universal Clipboard to his
11
+ * other devices) and marked concealed and transient (nspasteboard.org), what clipboard managers read as « keep
12
+ * no copy » */
13
+ const PASTEBOARD_JXA = `ObjC.import('AppKit')
14
+ function run(argv) {
15
+ const pb = argv[1] === 'general' ? $.NSPasteboard.generalPasteboard : $.NSPasteboard.pasteboardWithName(argv[1])
16
+ if (argv[0] === 'read') {
17
+ const s = pb.stringForType($.NSPasteboardTypeString)
18
+ return JSON.stringify({ text: s.isNil() ? '' : s.js, types: ObjC.deepUnwrap(pb.types) || [] })
19
+ }
20
+ if (argv[0] === 'release') { pb.releaseGlobally; return 'released' }
21
+ const text = $.NSString.alloc.initWithDataEncoding($.NSFileHandle.fileHandleWithStandardInput.readDataToEndOfFile, $.NSUTF8StringEncoding)
22
+ pb.prepareForNewContentsWithOptions($.NSPasteboardContentsCurrentHostOnly)
23
+ if (text.js === '') return 'cleared'
24
+ pb.declareTypesOwner($([$.NSPasteboardTypeString, 'org.nspasteboard.ConcealedType', 'org.nspasteboard.TransientType']), $())
25
+ pb.setStringForType(text, $.NSPasteboardTypeString)
26
+ pb.setStringForType($(''), 'org.nspasteboard.ConcealedType')
27
+ pb.setStringForType($(''), 'org.nspasteboard.TransientType')
28
+ return 'written'
29
+ }`
30
+
31
+ const jxa = (args: string[], stdin?: string): string => {
32
+ const p = Bun.spawnSync(['osascript', '-l', 'JavaScript', '-e', PASTEBOARD_JXA, ...args], { stdin: stdin == null ? 'ignore' : new TextEncoder().encode(stdin), stdout: 'pipe', stderr: 'pipe' })
33
+ if (p.exitCode !== 0) throw new Error(`the pasteboard refused (osascript exit ${p.exitCode})`)
34
+ return p.stdout.toString().trim()
35
+ }
36
+
37
+ /** the Mac's clipboard, or a private pasteboard of that name (what a test uses: his clipboard is never touched) */
38
+ export const pasteboard = (board = 'general'): Clipboard & { types: () => string[]; release: () => void } => ({
39
+ write: (text) => void jxa(['write', board], text),
40
+ read: () => (JSON.parse(jxa(['read', board])) as { text: string }).text,
41
+ types: () => (JSON.parse(jxa(['read', board])) as { types: string[] }).types,
42
+ release: () => void jxa(['release', board]),
43
+ })
44
+
45
+ export const macClipboard: Clipboard = pasteboard()
46
+
47
+ /** a round trip on a private pasteboard, before any key exists: why the pasteboard cannot hand a note, or null */
48
+ export function provePasteboard(): string | null {
49
+ const board = pasteboard(`shipkit-vault-proof-${process.pid}`)
50
+ const probe = `proof ${crypto.randomUUID()}`
51
+ try {
52
+ board.write(probe)
53
+ return board.read() === probe ? null : 'the pasteboard did not give back what was written to it'
54
+ } catch (e) {
55
+ return (e as Error).message
56
+ } finally {
57
+ try {
58
+ board.release()
59
+ } catch {
60
+ // a board that never opened has nothing to release
61
+ }
62
+ }
63
+ }
64
+
65
+ export const CLEAR_AFTER_MS = 90_000
66
+ /** a second ctrl c within this long drops the note */
67
+ export const SECOND_INT_MS = 5_000
68
+
69
+ const stamp = (d: Date): string => d.toISOString().slice(0, 16).replace('T', ' ')
70
+
71
+ /** the note for a secure note of his password manager: its title on the first line */
72
+ export function initNote(o: { machine: string; at: Date; sealKey: string; recoveryKey: string }): string {
73
+ return [
74
+ `shipkit vault (${o.machine})`,
75
+ `initialised ${stamp(o.at)} UTC on ${o.machine}`,
76
+ `seal key: ${o.sealKey}`,
77
+ `recovery key: ${o.recoveryKey}`,
78
+ `The seal key opens the vault and every snapshot of it; that Mac's login keychain holds it too (${SEAL_SERVICE}), and sk vault key --copy copies it again. The recovery key is kept nowhere else: after a dead disk, sk vault restore asks for it to make a new root token in the restored vault.`,
79
+ '',
80
+ ].join('\n')
81
+ }
82
+
83
+ export function sealNote(o: { machine: string; at: Date; sealKey: string }): string {
84
+ return [`shipkit vault (${o.machine}): seal key`, `copied ${stamp(o.at)} UTC from the login keychain of ${o.machine} (${SEAL_SERVICE})`, `seal key: ${o.sealKey}`, 'It opens the vault and every snapshot of it. The recovery key is in the note made at sk vault init.', ''].join('\n')
85
+ }
86
+
87
+ export type Signals = { on(sig: NodeJS.Signals, f: () => void): void; off(sig: NodeJS.Signals, f: () => void): void; exit(code: number): void }
88
+ export const processSignals: Signals = { on: (s, f) => void process.on(s, f), off: (s, f) => void process.off(s, f), exit: (c) => process.exit(c) }
89
+
90
+ /** the terminal's echo, off while he types the 4 characters: a paste there would print both keys in the scrollback */
91
+ export type Terminal = { echo(on: boolean): void }
92
+ export const ttyTerminal: Terminal = { echo: (on) => void Bun.spawnSync(['stty', on ? 'echo' : '-echo'], { stdin: 'inherit', stdout: 'ignore', stderr: 'ignore' }) }
93
+ const noTerminal: Terminal = { echo: () => {} }
94
+
95
+ const SIGNALS: NodeJS.Signals[] = ['SIGINT', 'SIGHUP', 'SIGTERM']
96
+ const EXIT_OF: Record<string, number> = { SIGINT: 130, SIGHUP: 129, SIGTERM: 143 }
97
+
98
+ /** what a run must undo whatever ends it, held from before the first key to the end */
99
+ export class KeyGuard {
100
+ /** the bao this run started, stopped on the way out */
101
+ bao: Bao | null = null
102
+ /** the root token while it lives: revoked on the way out */
103
+ root: VaultApi | null = null
104
+ /** undo what was made before the vault held anything */
105
+ rollback: (() => void) | null = null
106
+ /** the text on the clipboard while it is the note */
107
+ note: string | null = null
108
+ /** while he is asked: a first ctrl c asks again */
109
+ prompting = false
110
+ /** set once a signal ended the run: the hand over stops asking */
111
+ ended = false
112
+ private lastInt = 0
113
+ private readonly onSig = new Map<NodeJS.Signals, () => void>()
114
+
115
+ constructor(
116
+ private readonly d: { signals?: Signals; terminal?: Terminal; clipboard: Clipboard; say: (l: string) => void },
117
+ ) {}
118
+
119
+ private get signals(): Signals {
120
+ return this.d.signals ?? processSignals
121
+ }
122
+
123
+ install(): this {
124
+ for (const s of SIGNALS) {
125
+ const f = (): void => this.signal(s)
126
+ this.onSig.set(s, f)
127
+ this.signals.on(s, f)
128
+ }
129
+ return this
130
+ }
131
+
132
+ uninstall(): void {
133
+ for (const [s, f] of this.onSig) this.signals.off(s, f)
134
+ this.onSig.clear()
135
+ }
136
+
137
+ echo(on: boolean): void {
138
+ try {
139
+ ;(this.d.terminal ?? noTerminal).echo(on)
140
+ } catch {
141
+ // a terminal that is gone has no echo to set
142
+ }
143
+ }
144
+
145
+ /** the note off the clipboard, if it still holds it. Never throws */
146
+ clearNote(): boolean {
147
+ if (this.note == null) return false
148
+ try {
149
+ if (this.d.clipboard.read() !== this.note) return false
150
+ this.d.clipboard.write('')
151
+ return true
152
+ } catch {
153
+ return false
154
+ } finally {
155
+ this.note = null
156
+ }
157
+ }
158
+
159
+ async revokeRoot(): Promise<boolean> {
160
+ const root = this.root
161
+ if (root == null) return true
162
+ try {
163
+ await Promise.race([root.revokeSelf(), Bun.sleep(10_000).then(() => Promise.reject(new Error('no answer in 10 s')))])
164
+ } catch {
165
+ // proved below
166
+ }
167
+ const dead = await root.lookupSelf().then(
168
+ () => false,
169
+ () => true,
170
+ )
171
+ if (dead) this.root = null
172
+ return dead
173
+ }
174
+
175
+ /** everything undone, in the order that keeps it safe: the echo, the clipboard, the root token while bao still
176
+ * answers, bao, then what was made before the vault held anything */
177
+ async cleanup(): Promise<void> {
178
+ this.echo(true)
179
+ this.clearNote()
180
+ if (!(await this.revokeRoot())) this.d.say('FAIL: the root token still answers: it is held by no one once this process ends')
181
+ await this.bao?.stop()
182
+ this.bao = null
183
+ this.rollback?.()
184
+ this.rollback = null
185
+ }
186
+
187
+ private signal(s: NodeJS.Signals): void {
188
+ if (s === 'SIGINT' && this.prompting && Date.now() - this.lastInt > SECOND_INT_MS) {
189
+ this.lastInt = Date.now()
190
+ this.d.say(`ctrl c again within ${SECOND_INT_MS / 1000} s drops the recovery key for good. Type c to copy the note again, or the last 4 characters of the seal key once it is saved`)
191
+ return
192
+ }
193
+ if (this.ended) return
194
+ this.ended = true
195
+ const proved = !this.prompting
196
+ void this.cleanup().then(() => {
197
+ this.d.say(proved ? `stopped (${s}): undone` : `stopped (${s}) before your copy was proved: the clipboard is cleared, and the recovery key is gone if your password manager does not hold it. The seal key: sk vault key --copy`)
198
+ this.signals.exit(EXIT_OF[s] ?? 1)
199
+ })
200
+ }
201
+ }
202
+
203
+ export type HandOverDeps = {
204
+ clipboard: Clipboard
205
+ ask: (question: string) => Promise<string>
206
+ say: (line: string) => void
207
+ clearAfterMs?: number
208
+ signals?: Signals
209
+ terminal?: Terminal
210
+ /** the run's guard, when one holds more than the note */
211
+ guard?: KeyGuard
212
+ }
213
+
214
+ /** the note in the clipboard until he proves his copy (the last 4 characters of the seal key, typed with no echo),
215
+ * cleared once he did or after `clearAfterMs`. `c` copies it again, `show` prints it on the screen (his explicit
216
+ * choice, the one way to the screen), `give up` drops it. Never throws: a clipboard that refuses keeps the note in
217
+ * memory and asks again. True once his copy is proved */
218
+ export async function handOver(text: string, sealKey: string, d: HandOverDeps): Promise<boolean> {
219
+ const after = d.clearAfterMs ?? CLEAR_AFTER_MS
220
+ const g = d.guard ?? new KeyGuard(d).install()
221
+ let timer: ReturnType<typeof setTimeout> | null = null
222
+ const stopTimer = (): void => {
223
+ if (timer != null) clearTimeout(timer)
224
+ timer = null
225
+ }
226
+ // an invented end of a key, never the real one's
227
+ const example = sealKey.endsWith('9f3c') ? '4d1a' : '9f3c'
228
+ let copies = 0
229
+ const copy = (): void => {
230
+ stopTimer()
231
+ try {
232
+ d.clipboard.write(text)
233
+ } catch (e) {
234
+ d.say(`the clipboard refused the note (${(e as Error).message}): type c to try again, or show to print it on this screen (it then stays in the scrollback: clear it with cmd K once it is saved)`)
235
+ return
236
+ }
237
+ g.note = text
238
+ timer = setTimeout(() => {
239
+ if (g.clearNote()) d.say('the clipboard is cleared: type c to copy the note again')
240
+ }, after)
241
+ const clears = `the clipboard clears in ${Math.round(after / 1000)} s (c copies the note again)`
242
+ if (copies++ > 0) {
243
+ d.say(`copied again. It still waits for the 4 characters: paste the note in your password manager, then type here the last 4 characters of its « seal key: » line. ${clears}`)
244
+ return
245
+ }
246
+ d.say('the two keys of the vault are in your clipboard, as one note. Three steps:')
247
+ d.say(' 1. in your password manager: a new secure note, paste (cmd V), save')
248
+ d.say(' 2. in that saved note, find the line that starts with « seal key: »')
249
+ d.say(` 3. back here, type the LAST 4 CHARACTERS of that line, then Enter: for example, for « seal key: 71c0…e4b2${example} » you type ${example}. What you type is not shown`)
250
+ d.say(`the note goes in your password manager and nowhere else: never in a chat, a message or a file. ${clears}`)
251
+ }
252
+ g.prompting = true
253
+ copy()
254
+ try {
255
+ while (!g.ended) {
256
+ g.echo(false)
257
+ let a: string
258
+ try {
259
+ a = (await d.ask('the last 4 characters of the « seal key: » line (or c, show, give up): ')).trim()
260
+ } catch (e) {
261
+ d.say(`FAIL: the terminal gave no answer (${(e as Error).message})`)
262
+ return false
263
+ } finally {
264
+ g.echo(true)
265
+ }
266
+ if (g.ended) return false
267
+ if (a === 'c') copy()
268
+ else if (a === 'show') d.say(text)
269
+ else if (a === 'give up') {
270
+ d.say('the note is dropped: the recovery key is gone if your password manager does not hold it. The seal key: sk vault key --copy')
271
+ return false
272
+ } else if (a.length !== 4) d.say('that answer is not 4 characters, and nothing of it was shown: type the last 4 characters of the seal key')
273
+ else if (sealKey.endsWith(a.toLowerCase())) return true
274
+ else d.say('that is not the end of the seal key: check the note in your password manager, or type c to copy it again')
275
+ }
276
+ return false
277
+ } finally {
278
+ stopTimer()
279
+ g.prompting = false
280
+ if (g.clearNote()) d.say('the clipboard is cleared')
281
+ if (d.guard == null) g.uninstall()
282
+ }
283
+ }
284
+
285
+ /** `sk vault key --copy`'s way out: the seal note in the clipboard, cleared after `clearAfterMs` or on any signal */
286
+ export async function holdSealNote(text: string, d: { clipboard: Clipboard; say: (l: string) => void; clearAfterMs?: number; signals?: Signals; sleep?: (ms: number) => Promise<void> }): Promise<number> {
287
+ const after = d.clearAfterMs ?? CLEAR_AFTER_MS
288
+ const g = new KeyGuard(d).install()
289
+ try {
290
+ try {
291
+ d.clipboard.write(text)
292
+ } catch (e) {
293
+ d.say(`FAIL: the clipboard refused the note (${(e as Error).message})`)
294
+ return 1
295
+ }
296
+ g.note = text
297
+ d.say(`the seal key is in your clipboard: paste it in your password manager. It clears in ${Math.round(after / 1000)} s (ctrl c clears it now)`)
298
+ await (d.sleep ?? Bun.sleep)(after)
299
+ return 0
300
+ } finally {
301
+ g.clearNote()
302
+ g.uninstall()
303
+ d.say('the clipboard is cleared')
304
+ }
305
+ }
@@ -0,0 +1,352 @@
1
+ // the vault's http api on loopback, the few calls shipkit makes. An error carries the status and bao's own words,
2
+ // never a request body: a body may hold a token or a value
3
+ import { refuseRealVault } from './vault-config.ts'
4
+ export type VaultHealth = { code: number; initialized: boolean; sealed: boolean; version: string }
5
+
6
+ /** GET /v1/sys/health: 200 unsealed, 503 sealed, 501 not initialised. Null when nothing answers */
7
+ export async function vaultHealth(url: string, timeoutMs = 1_000): Promise<VaultHealth | null> {
8
+ refuseRealVault({ url })
9
+ try {
10
+ const r = await fetch(`${url}/v1/sys/health`, { signal: AbortSignal.timeout(timeoutMs) })
11
+ const j = (await r.json().catch(() => ({}))) as { initialized?: boolean; sealed?: boolean; version?: string }
12
+ return { code: r.status, initialized: j.initialized === true, sealed: j.sealed !== false, version: j.version ?? '' }
13
+ } catch {
14
+ return null
15
+ }
16
+ }
17
+
18
+ /** poll the health until `ok` holds, the last answer either way */
19
+ export async function waitHealth(url: string, ok: (h: VaultHealth | null) => boolean, o: { ms?: number; stepMs?: number; gone?: () => boolean } = {}): Promise<VaultHealth | null> {
20
+ const end = Date.now() + (o.ms ?? 15_000)
21
+ let h = await vaultHealth(url)
22
+ while (!ok(h) && Date.now() < end && o.gone?.() !== true) {
23
+ await Bun.sleep(o.stepMs ?? 150)
24
+ h = await vaultHealth(url)
25
+ }
26
+ return h
27
+ }
28
+
29
+ export class VaultError extends Error {
30
+ constructor(
31
+ readonly status: number,
32
+ what: string,
33
+ ) {
34
+ super(what)
35
+ }
36
+ }
37
+
38
+ type Json = Record<string, unknown>
39
+
40
+ export class VaultApi {
41
+ constructor(
42
+ readonly url: string,
43
+ private token: string | null = null,
44
+ /** how long one call may take; a read on a reader's path passes a short one */
45
+ private readonly timeoutMs: number = 30_000,
46
+ ) {}
47
+
48
+ private async call(method: string, path: string, body?: unknown, raw?: Uint8Array<ArrayBuffer>): Promise<{ status: number; json: Json; bytes: Uint8Array<ArrayBuffer> }> {
49
+ refuseRealVault({ url: this.url })
50
+ const headers: Record<string, string> = {}
51
+ if (this.token != null) headers['X-Vault-Token'] = this.token
52
+ if (body !== undefined) headers['content-type'] = 'application/json'
53
+ const r = await fetch(`${this.url}/v1/${path}`, { method, headers, body: raw ?? (body === undefined ? undefined : JSON.stringify(body)), signal: AbortSignal.timeout(this.timeoutMs) })
54
+ const bytes: Uint8Array<ArrayBuffer> = new Uint8Array(await r.arrayBuffer())
55
+ let json: Json = {}
56
+ if ((r.headers.get('content-type') ?? '').includes('json') && bytes.length > 0) {
57
+ try {
58
+ json = JSON.parse(new TextDecoder().decode(bytes)) as Json
59
+ } catch {
60
+ json = {}
61
+ }
62
+ }
63
+ if (r.status >= 400) {
64
+ const errs = Array.isArray(json['errors']) ? (json['errors'] as unknown[]).map(String).join('; ') : ''
65
+ throw new VaultError(r.status, `${method} /v1/${path}: ${r.status}${errs === '' ? '' : ` (${errs})`}`)
66
+ }
67
+ return { status: r.status, json, bytes }
68
+ }
69
+
70
+ /** the one init: one recovery share, threshold one. The root token and the recovery key, held by the caller only */
71
+ async init(): Promise<{ rootToken: string; recoveryKey: string }> {
72
+ const { json } = await this.call('PUT', 'sys/init', { recovery_shares: 1, recovery_threshold: 1 })
73
+ const rootToken = json['root_token']
74
+ const recovery = json['recovery_keys_base64']
75
+ if (typeof rootToken !== 'string' || !Array.isArray(recovery) || typeof recovery[0] !== 'string') throw new VaultError(0, 'sys/init answered without a root token or a recovery key')
76
+ return { rootToken, recoveryKey: recovery[0] }
77
+ }
78
+
79
+ /** a root token from the recovery key (one share): an attempt, the key, the encoded token decoded with the one
80
+ * time password the attempt gave. Any attempt left over is cancelled first. The token is the caller's alone */
81
+ /** a root token from the recovery key in a vault just restored: a restore seals it again while it swaps its keyring,
82
+ * and its node answers 500 until it is active again, so each such answer is tried again until `ms`. A 400 (a key
83
+ * that is not this vault's) ends at once */
84
+ async rootAfterRestore(recoveryKey: string, ms = 60_000): Promise<string> {
85
+ const end = Date.now() + ms
86
+ for (;;) {
87
+ await waitHealth(this.url, (h) => h?.code === 200, { ms: Math.max(1_000, end - Date.now()) })
88
+ try {
89
+ const token = await this.rootFromRecovery(recoveryKey)
90
+ await new VaultApi(this.url, token).lookupSelf()
91
+ return token
92
+ } catch (e) {
93
+ if (/recovery key|\b400\b/.test((e as Error).message) || Date.now() > end) throw e
94
+ await Bun.sleep(500)
95
+ }
96
+ }
97
+ }
98
+
99
+ async rootFromRecovery(recoveryKey: string): Promise<string> {
100
+ await this.call('DELETE', 'sys/generate-root/attempt').catch(() => undefined)
101
+ const { json: a } = await this.call('POST', 'sys/generate-root/attempt', {})
102
+ const nonce = a['nonce']
103
+ const otp = a['otp']
104
+ if (typeof nonce !== 'string' || typeof otp !== 'string' || otp === '') throw new VaultError(0, 'sys/generate-root/attempt gave no nonce or one time password')
105
+ const { json: u } = await this.call('POST', 'sys/generate-root/update', { key: recoveryKey, nonce })
106
+ const encoded = u['encoded_token'] ?? u['encoded_root_token']
107
+ if (u['complete'] !== true || typeof encoded !== 'string') throw new VaultError(0, 'the recovery key did not complete the root token: it is not this vault\'s')
108
+ const enc = Buffer.from(encoded, 'base64')
109
+ const pad = Buffer.from(otp, 'utf8')
110
+ if (enc.length !== pad.length) throw new VaultError(0, 'the encoded root token and its one time password differ in length')
111
+ return Buffer.from(enc.map((b, i) => b ^ pad[i]!)).toString('utf8')
112
+ }
113
+
114
+ mount(path: string, type: string, options?: Record<string, string>): Promise<unknown> {
115
+ return this.call('POST', `sys/mounts/${path}`, { type, ...(options == null ? {} : { options }) })
116
+ }
117
+
118
+ async mounts(): Promise<string[]> {
119
+ const { json } = await this.call('GET', 'sys/mounts')
120
+ const data = (json['data'] ?? json) as Json
121
+ return Object.keys(data).filter((k) => k.endsWith('/'))
122
+ }
123
+
124
+ writePolicy(name: string, hcl: string): Promise<unknown> {
125
+ return this.call('PUT', `sys/policies/acl/${name}`, { policy: hcl })
126
+ }
127
+
128
+ writeTokenRole(name: string, role: Json): Promise<unknown> {
129
+ return this.call('POST', `auth/token/roles/${name}`, role)
130
+ }
131
+
132
+ /** a token, created as an orphan from `role` when one is named, else from the caller's own token. `entityAlias`
133
+ * ties it to the entity of that alias (made at the first mint), whose metadata a templated policy reads */
134
+ async createToken(o: { role?: string; policies?: string[]; period?: string; orphan?: boolean; displayName?: string; entityAlias?: string; explicitMaxTtl?: string }): Promise<{ token: string; accessor: string; entityId: string; ttlS: number }> {
135
+ const path = o.role != null ? `auth/token/create/${o.role}` : o.orphan === true ? 'auth/token/create-orphan' : 'auth/token/create'
136
+ const { json } = await this.call('POST', path, {
137
+ ...(o.policies == null ? {} : { policies: o.policies }),
138
+ ...(o.period == null ? {} : { period: o.period }),
139
+ ...(o.displayName == null ? {} : { display_name: o.displayName }),
140
+ ...(o.entityAlias == null ? {} : { entity_alias: o.entityAlias }),
141
+ ...(o.explicitMaxTtl == null ? {} : { explicit_max_ttl: o.explicitMaxTtl }),
142
+ ...(o.role == null ? { renewable: true } : {}),
143
+ })
144
+ const auth = json['auth'] as { client_token?: string; accessor?: string; entity_id?: string; lease_duration?: number } | undefined
145
+ if (typeof auth?.client_token !== 'string' || typeof auth.accessor !== 'string') throw new VaultError(0, `${path} answered without a token`)
146
+ return { token: auth.client_token, accessor: auth.accessor, entityId: auth.entity_id ?? '', ttlS: auth.lease_duration ?? 0 }
147
+ }
148
+
149
+ /** what the caller's own token may do on each path (the default policy answers it) */
150
+ async capabilitiesSelf(paths: string[]): Promise<Record<string, string[]>> {
151
+ const { json } = await this.call('POST', 'sys/capabilities-self', { paths })
152
+ const out: Record<string, string[]> = {}
153
+ for (const p of paths) out[p] = ((json[p] ?? (paths.length === 1 ? json['capabilities'] : undefined)) as string[] | undefined) ?? []
154
+ return out
155
+ }
156
+
157
+ /** a policy's text, null when there is none */
158
+ async readPolicy(name: string): Promise<string | null> {
159
+ try {
160
+ const { json } = await this.call('GET', `sys/policies/acl/${name}`)
161
+ return ((json['data'] as { policy?: string } | undefined)?.policy ?? null) as string | null
162
+ } catch (e) {
163
+ if (e instanceof VaultError && e.status === 404) return null
164
+ throw e
165
+ }
166
+ }
167
+
168
+ listPolicies(): Promise<string[]> {
169
+ return this.listKeys('sys/policies/acl')
170
+ }
171
+
172
+ deletePolicy(name: string): Promise<unknown> {
173
+ return this.call('DELETE', `sys/policies/acl/${name}`)
174
+ }
175
+
176
+ async readTokenRole(name: string): Promise<Json | null> {
177
+ try {
178
+ return ((await this.call('GET', `auth/token/roles/${name}`)).json['data'] as Json | undefined) ?? null
179
+ } catch (e) {
180
+ if (e instanceof VaultError && e.status === 404) return null
181
+ throw e
182
+ }
183
+ }
184
+
185
+ /** end a token by its accessor. A token already ended, or past its time, is no error */
186
+ async revokeAccessor(accessor: string): Promise<void> {
187
+ try {
188
+ await this.call('POST', 'auth/token/revoke-accessor', { accessor })
189
+ } catch (e) {
190
+ if (e instanceof VaultError && e.status === 400 && /invalid accessor|token not found/i.test(e.message)) return
191
+ throw e
192
+ }
193
+ }
194
+
195
+ async readEntity(id: string): Promise<{ metadata: Record<string, string>; policies: string[]; disabled: boolean } | null> {
196
+ try {
197
+ const d = ((await this.call('GET', `identity/entity/id/${id}`)).json['data'] ?? {}) as { metadata?: Record<string, string> | null; policies?: string[] | null; disabled?: boolean }
198
+ return { metadata: d.metadata ?? {}, policies: d.policies ?? [], disabled: d.disabled === true }
199
+ } catch (e) {
200
+ if (e instanceof VaultError && e.status === 404) return null
201
+ throw e
202
+ }
203
+ }
204
+
205
+ /** an entity's metadata, replaced whole */
206
+ setEntityMetadata(id: string, metadata: Record<string, string>): Promise<unknown> {
207
+ return this.call('POST', `identity/entity/id/${id}`, { metadata })
208
+ }
209
+
210
+ async lookupSelf(): Promise<{ policies: string[]; ttl: number }> {
211
+ const { json } = await this.call('GET', 'auth/token/lookup-self')
212
+ const d = (json['data'] ?? {}) as { policies?: string[]; ttl?: number }
213
+ return { policies: d.policies ?? [], ttl: d.ttl ?? 0 }
214
+ }
215
+
216
+ renewSelf(): Promise<unknown> {
217
+ return this.call('POST', 'auth/token/renew-self', {})
218
+ }
219
+
220
+ revokeSelf(): Promise<unknown> {
221
+ return this.call('POST', 'auth/token/revoke-self', {})
222
+ }
223
+
224
+ /** every token's accessor (sudo on auth/token/accessors) */
225
+ async accessors(): Promise<string[]> {
226
+ const { json } = await this.call('GET', 'auth/token/accessors?list=true')
227
+ return ((json['data'] as { keys?: string[] } | undefined)?.keys ?? []).map(String)
228
+ }
229
+
230
+ async lookupAccessor(accessor: string): Promise<{ policies: string[]; displayName: string; entityId: string; ttl: number }> {
231
+ const { json } = await this.call('POST', 'auth/token/lookup-accessor', { accessor })
232
+ const d = (json['data'] ?? {}) as { policies?: string[]; display_name?: string; entity_id?: string; ttl?: number }
233
+ return { policies: d.policies ?? [], displayName: d.display_name ?? '', entityId: d.entity_id ?? '', ttl: d.ttl ?? 0 }
234
+ }
235
+
236
+ /** the audit devices by path (sudo on sys/audit) */
237
+ async audits(): Promise<string[]> {
238
+ const { json } = await this.call('GET', 'sys/audit')
239
+ const data = (json['data'] ?? json) as Json
240
+ return Object.keys(data).filter((k) => k.endsWith('/'))
241
+ }
242
+
243
+ /** the file path of each file audit device the vault's own data holds, by its name */
244
+ async auditFiles(): Promise<Record<string, string>> {
245
+ const { json } = await this.call('GET', 'sys/audit')
246
+ const data = (json['data'] ?? json) as Record<string, { type?: string; options?: { file_path?: string } }>
247
+ return Object.fromEntries(Object.entries(data).flatMap(([k, v]) => (k.endsWith('/') && v?.type === 'file' && typeof v.options?.file_path === 'string' ? [[k, v.options.file_path]] : [])))
248
+ }
249
+
250
+ async snapshot(): Promise<Uint8Array<ArrayBuffer>> {
251
+ return (await this.call('GET', 'sys/storage/raft/snapshot')).bytes
252
+ }
253
+
254
+ /** a snapshot into this vault. `force` is for one taken on another vault, whose keyring differs */
255
+ restore(snap: Uint8Array<ArrayBuffer>, o: { force: boolean }): Promise<unknown> {
256
+ return this.call('POST', `sys/storage/raft/${o.force ? 'snapshot-force' : 'snapshot'}`, undefined, snap)
257
+ }
258
+
259
+ /** the current version of one path, 0 when it holds none. Metadata only, never a value */
260
+ async currentVersion(mount: string, path: string): Promise<number> {
261
+ try {
262
+ const { json } = await this.call('GET', `${mount}/metadata/${path}`)
263
+ return Number((json['data'] as { current_version?: number } | undefined)?.current_version ?? 0)
264
+ } catch (e) {
265
+ if (e instanceof VaultError && e.status === 404) return 0
266
+ throw e
267
+ }
268
+ }
269
+
270
+ /** the current version of one path and when it was written, null when it holds none (no path, or its current
271
+ * version deleted). Metadata only, never a value */
272
+ async writtenAt(mount: string, path: string): Promise<{ version: number; at: number | null } | null> {
273
+ try {
274
+ const { json } = await this.call('GET', `${mount}/metadata/${path}`)
275
+ const d = (json['data'] ?? {}) as { current_version?: number; updated_time?: string; versions?: Record<string, { created_time?: string; deletion_time?: string; destroyed?: boolean }> }
276
+ const version = Number(d.current_version ?? 0)
277
+ const v = d.versions?.[String(version)]
278
+ if (version === 0 || (v?.deletion_time ?? '') !== '' || v?.destroyed === true) return null
279
+ const at = Date.parse(v?.created_time ?? d.updated_time ?? '')
280
+ return { version, at: Number.isNaN(at) ? null : at }
281
+ } catch (e) {
282
+ if (e instanceof VaultError && e.status === 404) return null
283
+ throw e
284
+ }
285
+ }
286
+
287
+ /** a write that takes only on top of version `cas` (0: a path that holds none): its new version. A write made
288
+ * meanwhile elsewhere refuses it */
289
+ async writeKvCas(mount: string, path: string, data: Json, cas: number): Promise<number> {
290
+ const { json } = await this.call('POST', `${mount}/data/${path}`, { options: { cas }, data })
291
+ return Number((json['data'] as { version?: number } | undefined)?.version ?? 0)
292
+ }
293
+
294
+ writeKv(mount: string, path: string, data: Json): Promise<unknown> {
295
+ return this.call('POST', `${mount}/data/${path}`, { data })
296
+ }
297
+
298
+ /** kv v2's metadata delete: every version and the key's metadata, for good. Only a root token may */
299
+ async destroyAll(mount: string, path: string): Promise<void> {
300
+ await this.call('DELETE', `${mount}/metadata/${path}`)
301
+ }
302
+
303
+ /** kv v2's soft delete of the newest version: a read finds nothing, `undelete` brings it back */
304
+ async deleteKv(mount: string, path: string): Promise<void> {
305
+ await this.call('DELETE', `${mount}/data/${path}`)
306
+ }
307
+
308
+ async readKv(mount: string, path: string): Promise<Json | null> {
309
+ try {
310
+ const { json } = await this.call('GET', `${mount}/data/${path}`)
311
+ return ((json['data'] as Json | undefined)?.['data'] as Json | undefined) ?? null
312
+ } catch (e) {
313
+ if (e instanceof VaultError && e.status === 404) return null
314
+ throw e
315
+ }
316
+ }
317
+
318
+ /** the names a LIST answers at `path`, none when it is absent */
319
+ async listKeys(path: string): Promise<string[]> {
320
+ try {
321
+ const { json } = await this.call('GET', `${path}?list=true`)
322
+ return ((json['data'] as { keys?: string[] } | undefined)?.keys ?? []).map(String)
323
+ } catch (e) {
324
+ if (e instanceof VaultError && e.status === 404) return []
325
+ throw e
326
+ }
327
+ }
328
+
329
+ /** the current version of each path under `prefix`, walked through the metadata: never a value */
330
+ async versions(mount: string, prefix = ''): Promise<Map<string, number>> {
331
+ const out = new Map<string, number>()
332
+ const walk = async (at: string): Promise<void> => {
333
+ let keys: string[] = []
334
+ try {
335
+ const { json } = await this.call('GET', `${mount}/metadata/${at}?list=true`)
336
+ keys = ((json['data'] as { keys?: string[] } | undefined)?.keys ?? []).map(String)
337
+ } catch (e) {
338
+ if (e instanceof VaultError && e.status === 404) return
339
+ throw e
340
+ }
341
+ for (const k of keys) {
342
+ if (k.endsWith('/')) await walk(`${at}${k}`)
343
+ else {
344
+ const { json } = await this.call('GET', `${mount}/metadata/${at}${k}`)
345
+ out.set(`${at}${k}`, Number((json['data'] as { current_version?: number } | undefined)?.current_version ?? 0))
346
+ }
347
+ }
348
+ }
349
+ await walk(prefix)
350
+ return out
351
+ }
352
+ }