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,482 @@
1
+ // the vault's one page: how it stands, where it lives and how it is copied, every secret name with who reads it and
2
+ // whether it is held. `vaultPage` is the one function the home's route and `sk vault status` print.
3
+ //
4
+ // The constraint a reader breaks first: an answer holds names, states, sizes and dates only. A value, a token, a key
5
+ // or a raw error of the vault never enters it: the list comes from the metadata calls and the keychain's attributes,
6
+ // and every failure is said in our own words (the status code at most)
7
+ import { existsSync, readdirSync, readFileSync, statSync } from 'fs'
8
+ import { homedir } from 'os'
9
+ import { join } from 'path'
10
+ import { scopeText, type Scope, type ScopeChip } from '../core/scope.ts'
11
+ import { ago } from '../hq/machine-notes.ts'
12
+ import { KV_MOUNT } from '../vault/layout.ts'
13
+ import { nameOfPath } from '../vault/vault-client.ts'
14
+ import { SECRET_NAME } from '../secrets/name.ts'
15
+ import { comparedFile } from '../hq/hq-local.ts'
16
+ import { configFile, dataDir, markerFile, vaultPlace, vaultUrl, type VaultPlace } from '../vault/vault-config.ts'
17
+ import { VaultError, type VaultApi } from '../vault/vault-http.ts'
18
+ import type { CompareSummary, RegistryRow } from '../vault/vault-import.ts'
19
+ import type { SealStore, VaultStatus } from '../vault/vault-serve.ts'
20
+ import type { AuditShape } from '../vault/vault-audit.ts'
21
+ import { CHANGED_KEY, DEAD_DISK_KEY, NAMES_KEY, PROVED_KEY, SENT_KEY, snapshotHealth, snapshotsDir, vaultStamp, type ProvedRecord, type Sent } from '../vault/vault-snapshot.ts'
22
+ import type { Fact, SecretRow, VaultPage } from './vault-words.ts'
23
+
24
+ export type Row = RegistryRow & { service?: string; level?: 'core' | 'used' | 'minor' }
25
+ export type AskOf = { repo: string; file: string; title: string; secrets: string[] }
26
+ export type VaultProcess = { status: string; since: number; want: string; repo: string } | null
27
+
28
+ /** what the page reads, each one a test replaces */
29
+ export type VaultPageDeps = {
30
+ place: VaultPlace
31
+ machine: string
32
+ status: () => Promise<VaultStatus>
33
+ /** the vault's names and their metadata (NameWalk), null with no minter on this machine */
34
+ names: (() => Promise<Map<string, Meta>>) | null
35
+ /** the `rv/` names this Mac's keychain held when sk vault compare last ran, null with no such record: the page
36
+ * itself never reads the keychain */
37
+ keychain: { names: string[]; at: number; stale: boolean } | null
38
+ /** what the read of the compare record says of itself (comparedOf), shown on top of the list */
39
+ notes?: Fact[]
40
+ /** who reads each name, in the words of an ask and of sk secret list: one call for every name */
41
+ who?: (names: string[]) => Promise<Record<string, { words: string; short: string; chips: ScopeChip[] }>>
42
+ /** the house registry's rows */
43
+ rows: Row[]
44
+ /** each registry name placed in the vault (vault-import.ts placeNames) */
45
+ placeOf: (rows: Row[], names: string[]) => Promise<{ name: string; path?: string; why?: string }[]>
46
+ asks: () => Promise<AskOf[]>
47
+ process: () => Promise<VaultProcess>
48
+ get: <T>(key: string) => T | null
49
+ /** the hq this machine joined on another machine, null when it carries its own */
50
+ joined: string | null
51
+ daemonToken: boolean
52
+ keychainOnly: boolean
53
+ pruneOn: boolean
54
+ compared: CompareSummary | null
55
+ copyConfigured: boolean
56
+ now: number
57
+ }
58
+
59
+ const PROCESS = { id: 'vault' }
60
+
61
+ /** what the page says of the seal key where it does not look it up: the daemon never runs `security` */
62
+ export const SEAL_NOT_LOOKED = 'not looked up by the page (sk vault status looks it up)'
63
+ const sealSkipped: SealStore = { has: () => { throw new Error(SEAL_NOT_LOOKED) }, read: () => null, write: () => undefined, remove: () => undefined }
64
+
65
+ /** a compare record past this age says what the keychain held, never that a name is missing */
66
+ export const STALE_MS = 7 * 86_400_000
67
+ const NAME_MAX = 200
68
+ const HELD_MAX = 10_000
69
+ const isName = (v: unknown): v is string => typeof v === 'string' && v.length <= NAME_MAX && v.startsWith('rv/') && SECRET_NAME.test(v)
70
+
71
+ /** the record of sk vault compare, read as data it may not be: its counts only when they are numbers, its names only
72
+ * when they are a list of secret names; another shape is the keychain column « not read » and one note naming the
73
+ * file. A record past STALE_MS keeps its names, said with their age */
74
+ export function comparedOf(raw: unknown, now: number): { keychain: VaultPageDeps['keychain']; compared: CompareSummary | null; note: Fact | null } {
75
+ if (raw == null) return { keychain: null, compared: null, note: null }
76
+ const bad: Fact = { text: `the keychain column is not read: ${shown(comparedFile())} has a shape this page does not know; sk vault compare writes it again`, tone: 'warn' }
77
+ const r = (typeof raw === 'object' && !Array.isArray(raw) ? raw : {}) as Record<string, unknown>
78
+ const n = (k: string): number | null => (typeof r[k] === 'number' && Number.isFinite(r[k]) ? (r[k] as number) : null)
79
+ const [at, same, differs, absent, refused, failed] = ['at', 'same', 'differs', 'absent', 'refused', 'failed'].map(n)
80
+ if (at == null || same == null || differs == null || absent == null || refused == null || failed == null) return { keychain: null, compared: null, note: bad }
81
+ const differing = Array.isArray(r['differing']) && r['differing'].length <= HELD_MAX && r['differing'].every(isName) ? (r['differing'] as string[]) : []
82
+ const compared: CompareSummary = { at, same, differs, absent, refused, failed, differing }
83
+ const held = r['held']
84
+ if (held === undefined) return { keychain: null, compared, note: null }
85
+ if (!Array.isArray(held) || held.length > HELD_MAX || !held.every(isName)) return { keychain: null, compared, note: bad }
86
+ const stale = now - at > STALE_MS
87
+ return { keychain: { names: held, at, stale }, compared, note: stale ? { text: `the keychain column is the compare of ${ago(now - at)} ago: run sk vault compare`, tone: 'warn' } : null }
88
+ }
89
+
90
+ /** a name's metadata as the vault keeps it: its current version and when it was written */
91
+ export type Meta = { version: number; at: number | null }
92
+
93
+ /** the list of names waits this long in all: the web gives the daemon 5 s for the whole answer */
94
+ export const LIST_MS = 3_000
95
+ /** what the page read of the vault is kept this long: each call is two lines of the vault's audit file, about half a
96
+ * megabyte a whole read at a hundred names. The refresh button reads everything again */
97
+ export const KEEP_MS = 60 * 60_000
98
+
99
+ /** the vault's names under the kv mount, walked through its metadata lists, and each name's metadata read once and
100
+ * kept KEEP_MS; a name the list no longer holds is dropped. A walk past its budget throws: a partial list is never
101
+ * answered as whole. `fresh` reads everything again */
102
+ export class NameWalk {
103
+ private list: { at: number; paths: string[] } | null = null
104
+ private meta = new Map<string, { m: Meta | null; at: number }>()
105
+ constructor(private api: Pick<VaultApi, 'listKeys' | 'writtenAt'>, private budgetMs: number = LIST_MS) {}
106
+
107
+ /** when the list it holds was read, null before its first read */
108
+ get listedAt(): number | null {
109
+ return this.list?.at ?? null
110
+ }
111
+
112
+ async read(fresh = false, now: number = Date.now()): Promise<Map<string, Meta>> {
113
+ const end = Date.now() + this.budgetMs
114
+ const late = (): void => {
115
+ if (Date.now() > end) throw Object.assign(new Error('late'), { name: 'TimeoutError' })
116
+ }
117
+ if (fresh || this.list == null || now - this.list.at > KEEP_MS) {
118
+ const paths: string[] = []
119
+ const walk = async (at: string): Promise<void> => {
120
+ late()
121
+ for (const k of await this.api.listKeys(`${KV_MOUNT}/metadata/${at}`)) {
122
+ if (k.endsWith('/')) await walk(`${at}${k}`)
123
+ else paths.push(`${at}${k}`)
124
+ }
125
+ }
126
+ await walk('')
127
+ this.list = { at: now, paths }
128
+ for (const p of [...this.meta.keys()]) if (!paths.includes(p)) this.meta.delete(p)
129
+ }
130
+ const out = new Map<string, Meta>()
131
+ for (const p of this.list.paths) {
132
+ let c = this.meta.get(p)
133
+ if (c == null || fresh || now - c.at > KEEP_MS) {
134
+ late()
135
+ c = { m: await this.api.writtenAt(KV_MOUNT, p), at: now }
136
+ this.meta.set(p, c)
137
+ }
138
+ if (c.m != null) out.set(p, c.m)
139
+ }
140
+ return out
141
+ }
142
+ }
143
+
144
+ /** a port intruder in words, its command line left out: a process's argv can hold a token */
145
+ export function intruderWords(text: string): string {
146
+ if (/makes a root token for anyone/.test(text)) return text
147
+ const port = /holds (127\.0\.0\.1:\d+)/.exec(text)?.[1] ?? 'the vault\'s port'
148
+ const pids = [...text.matchAll(/pid (\d+) \(/g)].map((m) => m[1])
149
+ return `a process this vault's config did not start holds ${port}${pids.length > 0 ? ` (pid ${pids.join(', ')})` : ''}: stop it, then sk gp start vault`
150
+ }
151
+
152
+ /** the audit file's last rotation and the rotated files kept, said after its size */
153
+ const rotationWords = (a: AuditShape | null | undefined, now: number): string => (a == null ? '' : `, rotated ${a.rotatedAt == null ? 'never yet' : `${ago(Math.max(0, now - a.rotatedAt))} ago`}, ${a.files} rotated file${a.files === 1 ? '' : 's'} kept (${sizeWords(a.filesBytes)}), 30 days at most`)
154
+ /** the last rotation's trouble, a WARN, or a DANGER when the vault refuses requests */
155
+ export const auditTrouble = (a: AuditShape | null | undefined, now: number = Date.now()): Fact[] => (a?.last == null || a.last.tone === 'ok' ? [] : [{ text: `the audit file's last rotation, ${ago(Math.max(0, now - a.last.at))} ago: ${a.last.text}`, tone: a.last.tone }])
156
+ /** its audit file, its size and its rotation: names and sizes only, never a line of it read */
157
+ const auditFact = (path: string, a: AuditShape | null | undefined, now: number = Date.now()): Fact => (existsSync(path) ? { text: `its audit file: ${shown(path)}, ${sizeWords(statSync(path).size)}${rotationWords(a, now)}`, tone: 'ok' } : { text: `its audit file: ${shown(path)}, not there${rotationWords(a, now)}`, tone: 'warn' })
158
+
159
+ /** how the vault stands, the words `sk vault status` prints, each with its tone */
160
+ export function standFacts(s: VaultStatus): Fact[] {
161
+ const state = !s.answers ? 'does not answer' : !s.initialised ? 'is not initialised' : s.sealed ? 'is SEALED' : 'is unsealed'
162
+ const out: Fact[] = [{ text: `the vault on 127.0.0.1:${s.port} ${state}${s.version === '' ? '' : ` (OpenBao ${s.version})`}`, tone: s.answers && s.initialised && !s.sealed ? 'ok' : s.marker == null ? 'dim' : 'danger' }]
163
+ if (s.intruder != null) out.push({ text: s.intruder, tone: 'danger' })
164
+ if (!s.answers && s.marker != null) out.push({ text: `the vault is initialised on this Mac and does not answer: every reader is on the keychain's old copy. Type: sk gp start vault${s.destroyLeft ? ' (a destroy was killed half way: its next run cleans its folder)' : ''}`, tone: 'danger' })
165
+ if (s.answers && s.initialised && s.sealed && s.marker != null) out.push({ text: 'the vault is sealed: every read on this Mac falls back to its keychain, which may be stale. Type: sk gp restart vault', tone: 'danger' })
166
+ if ((s.rootTokens ?? 0) > 0) out.push({ text: `${s.rootTokens} root token${s.rootTokens === 1 ? '' : 's'} alive, held by no act (a destroy or a restore killed after it made one): sk vault revoke-roots`, tone: 'danger' })
167
+ out.push(s.marker == null ? { text: 'sk vault init has not run on this machine', tone: 'dim' } : { text: `initialised ${s.marker.at.slice(0, 10)} on ${s.marker.machine}, seal key ${s.marker.keyId}`, tone: 'ok' })
168
+ if (s.marker != null) out.push(typeof s.marker.auditPath === 'string' ? auditFact(s.marker.auditPath, s.auditRotation) : { text: 'its audit file is not recorded in its marker: sk vault narrow records it (a move of the home waits on it)', tone: 'warn' })
169
+ out.push({ text: `seal key in the login keychain: ${s.sealKey === 'here' ? 'yes' : s.sealKey === 'absent' ? 'no' : s.sealKey}`, tone: s.sealKey === 'here' ? 'ok' : s.marker == null || s.sealKey === SEAL_NOT_LOOKED ? 'dim' : 'danger' })
170
+ if (s.audit != null) out.push({ text: `audit file: ${s.audit ? 'on' : 'OFF'}`, tone: s.audit ? 'ok' : 'danger' })
171
+ out.push(...auditTrouble(s.auditRotation))
172
+ if (s.rootTokens != null) out.push({ text: `root tokens alive: ${s.rootTokens}`, tone: s.rootTokens === 0 ? 'ok' : 'danger' })
173
+ if (s.minterNarrow != null) out.push(s.minterNarrow ? { text: 'the minter writes no policy; whoever reads its token file reads every secret', tone: 'ok' } : { text: 'the minter WRITES POLICIES: it is the vault\'s admin in all but name (sk vault narrow)', tone: 'warn' })
174
+ if (s.minterTtlS != null) out.push({ text: `the minter token: ${Math.floor(s.minterTtlS / 86_400)} days left, renewed by the vault's process`, tone: s.minterTtlS < 7 * 86_400 ? 'warn' : 'ok' })
175
+ else if (s.answers && !s.sealed && s.marker != null) out.push({ text: 'the minter token does not answer', tone: 'warn' })
176
+ return out
177
+ }
178
+
179
+ /** a failure of the vault said in words: its status code at most, never its body */
180
+ export function vaultTrouble(what: string, e: unknown): string {
181
+ if (e instanceof VaultError && e.status > 0) return `the vault refused ${what} (${e.status})`
182
+ if ((e as Error)?.name === 'TimeoutError') return `the vault did not answer ${what} in time`
183
+ return `the vault did not answer ${what}`
184
+ }
185
+
186
+ /** a folder's bytes, its files' sizes summed: names and sizes only, never a file read */
187
+ function folderBytes(dir: string): number | null {
188
+ try {
189
+ let n = 0
190
+ for (const e of readdirSync(dir, { withFileTypes: true })) n += e.isDirectory() ? (folderBytes(join(dir, e.name)) ?? 0) : e.isFile() ? statSync(join(dir, e.name)).size : 0
191
+ return n
192
+ } catch {
193
+ return null
194
+ }
195
+ }
196
+
197
+ export const sizeWords = (n: number): string => (n < 1e3 ? `${n} B` : n < 1e6 ? `${(n / 1e3).toFixed(0)} kB` : n < 1e9 ? `${(n / 1e6).toFixed(1)} MB` : `${(n / 1e9).toFixed(2)} GB`)
198
+
199
+ /** a scope's folder of a vault path as the scope it files: `all`, `repo/<key with ~>`, `identity/x`, `machine/x` */
200
+ export function scopeOfPath(path: string): Scope {
201
+ const [kind, part] = path.split('/')
202
+ if (kind === 'repo' && part != null) return { repos: [part.replaceAll('~', '/')] }
203
+ if (kind === 'identity' && part != null) return { identities: [part] }
204
+ if (kind === 'machine' && part != null) return { machines: [part] }
205
+ return {}
206
+ }
207
+
208
+ /** a path under the user's home as `~/…`: shorter to read, the same file */
209
+ export const shown = (path: string, home: string = homedir()): string => (path === home || path.startsWith(`${home}/`) ? `~${path.slice(home.length)}` : path)
210
+
211
+ const scopeLists = (s: Scope | undefined): SecretRow['scope'] => ({ repos: s?.repos ?? [], identities: s?.identities ?? [], machines: s?.machines ?? [] })
212
+ /** who reads a name where the house's words are not read (no house): the scope as the registry writes it */
213
+ const scopeCell = (s: Scope | undefined): string => scopeText(s)
214
+
215
+ /** where the vault lives on the disk, what keeps it up, where its keys are (in words only) */
216
+ function livesFacts(d: VaultPageDeps, s: VaultStatus, proc: VaultProcess): Fact[] {
217
+ const p = d.place
218
+ const out: Fact[] = [{ text: `its address: ${vaultUrl(p)}, this Mac's loopback only (raft on 127.0.0.1:${p.clusterPort})`, tone: 'ok' }]
219
+ const bytes = folderBytes(dataDir(p))
220
+ out.push({ text: `its data: ${shown(dataDir(p))}${bytes == null ? ', not on this disk' : `, ${sizeWords(bytes)}`}`, tone: bytes == null ? 'dim' : 'ok' })
221
+ try {
222
+ const mode = statSync(p.dir).mode & 0o777
223
+ out.push({ text: `its folder: ${shown(p.dir)}, mode ${mode.toString(8).padStart(4, '0')}`, tone: (mode & 0o077) === 0 ? 'ok' : 'danger' })
224
+ } catch {
225
+ out.push({ text: `its folder: ${shown(p.dir)}, not there`, tone: 'dim' })
226
+ }
227
+ out.push({ text: `its config: ${shown(configFile(p))}${existsSync(configFile(p)) ? '' : ', not written yet'}`, tone: 'ok' })
228
+ if (s.marker != null) out.push({ text: `its binary: OpenBao ${s.marker.bao} at ${s.marker.baoPath}, the one sk vault serve starts`, tone: s.version !== '' && s.version !== s.marker.bao ? 'warn' : 'ok' })
229
+ out.push(proc == null ? { text: 'kept up by pm as the global process vault: pm does not answer', tone: 'warn' } : { text: `kept up by pm as the global process vault (declared by ${proc.repo}): ${proc.status}${proc.since > 0 ? ` for ${ago(Math.max(0, d.now - proc.since))}` : ''}${proc.want === 'down' ? ', stopped by hand' : ''}`, tone: proc.status === 'up' ? 'ok' : s.marker == null ? 'dim' : 'danger', process: { repo: proc.repo, id: PROCESS.id } })
230
+ const seal = s.sealKey === 'here' ? ' (there)' : s.sealKey === SEAL_NOT_LOOKED ? '' : ' (not there)'
231
+ out.push({ text: `the seal key: the login keychain of this Mac${seal}, and your password manager`, tone: seal !== ' (not there)' || s.marker == null ? 'ok' : 'danger' })
232
+ out.push({ text: 'the recovery key: your password manager only, never on this Mac', tone: 'ok' })
233
+ out.push({ text: `the minter's token: a file in the vault's folder, mode 0600${s.minterTtlS == null ? '' : `, ${Math.floor(s.minterTtlS / 86_400)} days left`}`, tone: 'ok' })
234
+ out.push(d.daemonToken ? { text: 'this daemon holds a vault token of its own, which the hq renews', tone: 'ok' } : { text: 'this daemon holds no vault token: its reads (the hub\'s logins, the asks\' checks) fall back to the keychain: sk pm restart daemon', tone: s.marker == null ? 'dim' : 'warn' })
235
+ return out
236
+ }
237
+
238
+ /** the keychain against the vault, as sk vault compare last found it: how it stands, not where it lives */
239
+ const comparedFact = (d: VaultPageDeps): Fact | null => (d.compared == null ? null : { text: `the keychain against the vault, ${ago(Math.max(0, d.now - d.compared.at))} ago: ${d.compared.same} same, ${d.compared.differs} differ, ${d.compared.absent} absent from the vault (sk vault compare)`, tone: d.compared.differs > 0 ? 'warn' : 'ok' })
240
+
241
+ /** its copies: the sealed snapshots beside it and in the Space, their proofs, the prune, the second place */
242
+ function copiesFacts(d: VaultPageDeps, stamp: string | null): Fact[] {
243
+ const h = snapshotHealth({ sent: d.get<Sent>(SENT_KEY), proved: d.get<ProvedRecord>(PROVED_KEY), changed: d.get<{ stamp: string; at: number }>(CHANGED_KEY), stamp, now: d.now, deadDisk: d.get<ProvedRecord>(DEAD_DISK_KEY) })
244
+ const head = (t: string): string => t.toLowerCase().slice(0, 25)
245
+ const out: Fact[] = h.lines.map((text) => ({ text, tone: h.warn.some((w) => text.includes(w) || head(w) === head(text)) ? 'warn' : 'ok' }))
246
+ for (const w of h.warn) if (!h.lines.some((l) => l.includes(w) || head(w) === head(l))) out.push({ text: w, tone: 'warn' })
247
+ const sent = Object.keys(d.get<Record<string, number>>(NAMES_KEY) ?? {}).length
248
+ out.push({ text: `${sent} sealed snapshot${sent === 1 ? '' : 's'} sent to the Space and not pruned, as this machine recorded them`, tone: 'ok' })
249
+ let near: string[] = []
250
+ try {
251
+ near = readdirSync(snapshotsDir(d.place)).filter((f) => f.endsWith('.snap')).sort()
252
+ } catch {
253
+ // none taken yet
254
+ }
255
+ const newest = near.at(-1)
256
+ out.push({ text: newest == null ? 'no snapshot beside the vault yet' : `${near.length} beside the vault (${shown(snapshotsDir(d.place))}), the newest ${newest}, ${sizeWords(statSync(join(snapshotsDir(d.place), newest)).size)}`, tone: 'ok' })
257
+ out.push(d.pruneOn ? { text: 'the prune of old snapshots: ON, the daily tick deletes those older than 30 days from the Space for good (sk vault snapshot --prune off)', tone: 'warn' } : { text: 'the prune of old snapshots: off, nothing leaves the Space', tone: 'ok' })
258
+ out.push({ text: d.copyConfigured ? 'the second place: named in the house config, each snapshot goes there too' : 'the second place: none named in the house config', tone: d.copyConfigured ? 'ok' : 'dim' })
259
+ out.push({ text: 'to prove the dead disk way again, in your own Terminal: sk vault snapshot --prove --from-space --recovery', tone: 'dim' })
260
+ return out
261
+ }
262
+
263
+ /** every name the registry, the vault and this Mac's keychain know, one row each: names and metadata only */
264
+ async function secretRows(d: VaultPageDeps, versions: Map<string, Meta> | null, notes: Fact[], here: boolean): Promise<SecretRow[]> {
265
+ const kc = d.keychain == null ? null : new Set(d.keychain.names)
266
+ notes.push(...(d.notes ?? []))
267
+ if ((d.notes ?? []).length > 0) {
268
+ // the compare record said what it is
269
+ } else if (d.keychain == null) notes.push({ text: here ? 'the keychain column is not read: the page never reads this Mac\'s keychain; sk vault compare records the names it holds' : 'this Mac\'s keychain is not read by the page: sk secret list says what it holds', tone: 'dim' })
270
+ else notes.push({ text: `the keychain column: the names sk vault compare found ${ago(Math.max(0, d.now - d.keychain.at))} ago`, tone: 'dim' })
271
+ const byPath = new Map<string, string>()
272
+ for (const path of versions?.keys() ?? []) {
273
+ const name = nameOfPath(path)
274
+ if (name != null) byPath.set(path, name)
275
+ }
276
+ const exact = d.rows.filter((r) => !r.name.includes('<'))
277
+ const names = [...new Set([...exact.map((r) => r.name), ...byPath.values(), ...(kc ?? [])])].sort()
278
+ const placed = new Map((await d.placeOf(d.rows, names)).map((p) => [p.name, p]))
279
+ const words = d.who == null ? null : await d.who(names).catch(() => null)
280
+ const asks = new Map<string, AskOf>()
281
+ for (const a of await d.asks()) for (const n of a.secrets) if (!asks.has(n)) asks.set(n, a)
282
+ const rows = await Promise.all(names.map(async (name): Promise<SecretRow> => {
283
+ const row = exact.find((r) => r.name === name)
284
+ const at = placed.get(name)
285
+ const filed = [...byPath].filter(([, n]) => n === name).map(([p]) => p)
286
+ const path = at?.path != null && versions?.has(at.path) ? at.path : null
287
+ const read = path ?? filed[0] ?? null
288
+ const written = read == null ? null : (versions?.get(read) ?? null)
289
+ const scope = row?.for ?? (filed[0] == null ? undefined : scopeOfPath(filed[0]))
290
+ const elsewhere = row != null && path == null && filed.length > 0 ? `the vault files it under ${filed.map((p) => p.split('/').slice(0, p.startsWith('all/') ? 1 : 2).join('/')).join(', ')}, its row says ${words?.[name] ?? scopeCell(row.for)}` : null
291
+ const a = asks.get(name)
292
+ return {
293
+ name,
294
+ for: row?.service ?? '',
295
+ who: words?.[name]?.words ?? scopeCell(scope),
296
+ ...(words?.[name] == null ? {} : { short: words[name]!.short, chips: words[name]!.chips }),
297
+ scope: scopeLists(scope),
298
+ level: row?.level ?? (row == null ? null : 'used'),
299
+ registered: row != null,
300
+ inVault: versions == null ? null : path != null || filed.length > 0,
301
+ inKeychain: kc == null ? null : kc.has(name),
302
+ keychainAt: d.keychain?.at ?? null,
303
+ keychainStale: d.keychain?.stale === true,
304
+ written: written?.at ?? null,
305
+ version: written?.version ?? null,
306
+ note: elsewhere ?? (versions != null && at?.why != null && row != null ? at.why : null),
307
+ ask: a == null ? null : { repo: a.repo, file: a.file, title: a.title },
308
+ }
309
+ }))
310
+ return rows
311
+ }
312
+
313
+ /** the page's data: one read of the vault's state, its places, its copies and its names */
314
+ export async function vaultPage(d: VaultPageDeps): Promise<VaultPage> {
315
+ const notes: Fact[] = []
316
+ const here = existsSync(markerFile(d.place))
317
+ if (!here) {
318
+ const stands: Fact[] = [
319
+ { text: `this machine (${d.machine}) runs no vault`, tone: 'dim' },
320
+ { text: d.joined == null ? 'its secrets come from its login keychain, through the house\'s secret manager (credsReadCommand)' : `it reports to the hq at ${d.joined}, whose machine runs the vault; its own secrets come from its login keychain, through the house's secret manager`, tone: 'ok' },
321
+ { text: 'this page shows this machine only: never another machine\'s names', tone: 'dim' },
322
+ ]
323
+ const secrets = await secretRows(d, null, notes, here)
324
+ return { at: d.now, machine: d.machine, here, stands, lives: [{ text: 'its secrets: the login keychain of this Mac', tone: 'ok' }], copies: [{ text: 'no vault here, so no sealed snapshot of one', tone: 'dim' }], secrets, notes }
325
+ }
326
+ const status = await d.status()
327
+ const s: VaultStatus = { ...status, ...(status.intruder != null ? { intruder: intruderWords(status.intruder) } : {}) }
328
+ const proc = await d.process()
329
+ const stands = standFacts(s)
330
+ if (proc != null && proc.since > 0 && s.answers) stands.splice(1, 0, { text: `${proc.status} for ${ago(Math.max(0, d.now - proc.since))}, as pm counts it`, tone: proc.status === 'up' ? 'ok' : 'warn' })
331
+ if (d.keychainOnly) stands.push({ text: 'SHIPKIT_SECRET_KEYCHAIN_ONLY=1 in this daemon: its reads skip the vault for the keychain', tone: 'danger' })
332
+ let versions: Map<string, Meta> | null = null
333
+ let why: string | null = null
334
+ if (d.names == null) why = 'this machine holds no minter token'
335
+ else if (!s.answers) why = 'the vault does not answer'
336
+ else if (s.sealed) why = 'the vault is sealed'
337
+ else
338
+ try {
339
+ versions = await d.names()
340
+ } catch (e) {
341
+ why = vaultTrouble('the list of its names', e)
342
+ }
343
+ if (why != null) notes.push({ text: `the vault's list was not read: ${why}; the held column says not read`, tone: 'warn' })
344
+ const secrets = await secretRows(d, versions, notes, here)
345
+ const fallback = secrets.filter((r) => r.registered && r.inVault === false && r.inKeychain === true)
346
+ if (fallback.length > 0) stands.push({ text: `${fallback.length} name${fallback.length === 1 ? ' is' : 's are'} read from this Mac's keychain, not the vault, and may be stale: ${fallback.slice(0, 6).map((r) => r.name).join(', ')}${fallback.length > 6 ? ', …' : ''} (sk vault import --dry)`, tone: 'warn' })
347
+ const compared = comparedFact(d)
348
+ if (compared != null) stands.push(compared)
349
+ const stamp = versions == null ? null : (await vaultStamp({ versions: async () => new Map([...versions!].map(([p, m]) => [p, m.version])) })).stamp
350
+ return { at: d.now, machine: d.machine, here, stands, lives: livesFacts(d, s, proc), copies: copiesFacts(d, stamp), secrets, notes }
351
+ }
352
+
353
+ /** what this process read of the vault, kept KEEP_MS: the status (its health asked at each read, and read whole again
354
+ * when the health moved) and the walk of the names */
355
+ let keptStatus: { at: number; key: string; s: VaultStatus } | null = null
356
+ let keptWalk: { key: string; w: NameWalk } | null = null
357
+
358
+ async function statusKept(place: VaultPlace, read: () => Promise<VaultStatus>, fresh: boolean, now: number): Promise<VaultStatus> {
359
+ const { vaultHealth } = await import('../vault/vault-http.ts')
360
+ const h = await vaultHealth(vaultUrl(place))
361
+ const k = keptStatus
362
+ const key = `${place.dir}:${place.port}`
363
+ if (!fresh && k != null && k.key === key && now - k.at < KEEP_MS && k.s.answers === (h != null) && k.s.sealed === (h?.sealed ?? true) && k.s.initialised === (h?.initialized ?? false) && k.s.version === (h?.version ?? '')) return k.s
364
+ const s = await read()
365
+ keptStatus = { at: now, key, s }
366
+ return s
367
+ }
368
+
369
+ /** the page's reads on this machine, for the house at `root` (null: no registry, no asks). `seal: 'skip'` for the
370
+ * daemon, which never runs `security`; the console looks the seal item up by name, as it always did */
371
+ /** `names`: the vault's names from a read already made (the daemon's, kept an hour), so this read walks none */
372
+ export async function vaultDeps(root: string | null, o: { fresh?: boolean; seal?: 'lookup' | 'skip'; now?: number; names?: () => Promise<Map<string, Meta>> } = {}): Promise<VaultPageDeps> {
373
+ const now = o.now ?? Date.now()
374
+ const fresh = o.fresh === true
375
+ const [{ machineName }, { minterOf }, { loadRepoConfig }, { vaultStatus }, { machineGet }, hq, { vaultPruneOn }, { askPm }] = await Promise.all([
376
+ import('./machine-host.ts'),
377
+ import('../vault/vault-minter.ts'),
378
+ import('../repo-config.ts'),
379
+ import('../vault/vault-serve.ts'),
380
+ import('../core/machine-db.ts'),
381
+ import('../hq/hq-local.ts'),
382
+ import('../hq/switch.ts'),
383
+ import('./pm-switch.ts'),
384
+ ])
385
+ const place = vaultPlace()
386
+ const config = root == null ? null : await loadRepoConfig(root).catch(() => null)
387
+ const minter = minterOf(place, 2_000)
388
+ const key = `${place.dir}:${place.port}`
389
+ if (minter == null) keptWalk = null
390
+ else if (keptWalk?.key !== key) keptWalk = { key, w: new NameWalk(minter) }
391
+ const walk = keptWalk?.w
392
+ const c = comparedOf(hq.lastCompared(), now)
393
+ return {
394
+ place,
395
+ machine: machineName(),
396
+ status: () => statusKept(place, () => vaultStatus({ place, ...(o.seal === 'lookup' ? {} : { seal: sealSkipped }) }), fresh, now),
397
+ names: walk == null ? null : (o.names ?? (() => walk.read(fresh, now))),
398
+ keychain: c.keychain,
399
+ notes: c.note == null ? [] : [c.note],
400
+ rows: (config?.creds ?? []) as Row[],
401
+ placeOf: async (rows, names) => {
402
+ const [{ placeNames }, { houseKeys, keyOfFrom }] = await Promise.all([import('../vault/vault-import.ts'), import('../vault/house-keys.ts')])
403
+ return placeNames({ rows, held: names, keyOf: root == null ? async () => null : keyOfFrom(await keysOnce(root, houseKeys)) })
404
+ },
405
+ asks: async () => (root == null ? [] : houseAsks(root)),
406
+ ...(root == null ? {} : { who: async (names: string[]) => Object.fromEntries(Object.entries(await (await import('../secrets/who-reads.ts')).whoReads(names, root)).map(([n, w]) => [n, { words: w.words, short: w.short, chips: w.chips }])) }),
407
+ process: async () => {
408
+ const r = (await askPm())?.resources.find((x) => x.id === PROCESS.id)
409
+ return r == null ? null : { status: r.status, since: r.since, want: r.want, repo: r.repo }
410
+ },
411
+ get: machineGet,
412
+ joined: hq.carriesHq() ? null : new URL(hq.hqUrl()).host,
413
+ daemonToken: hq.readVaultToken() != null,
414
+ keychainOnly: process.env['SHIPKIT_SECRET_KEYCHAIN_ONLY'] === '1',
415
+ pruneOn: vaultPruneOn(),
416
+ compared: c.compared,
417
+ copyConfigured: config?.serve?.spaceCopy != null,
418
+ now,
419
+ }
420
+ }
421
+
422
+ /** the ids of the house's checkouts, kept a few minutes: each one is a config load and a git read */
423
+ let keys: { at: number; root: string; v: Promise<Map<string, import('../vault/house-keys.ts').KeyOf>> } | null = null
424
+ const KEYS_TTL_MS = 5 * 60_000
425
+ function keysOnce(root: string, read: (root: string) => Promise<Map<string, import('../vault/house-keys.ts').KeyOf>>): Promise<Map<string, import('../vault/house-keys.ts').KeyOf>> {
426
+ if (keys == null || keys.root !== root || Date.now() - keys.at > KEYS_TTL_MS) keys = { at: Date.now(), root, v: read(root) }
427
+ return keys.v
428
+ }
429
+
430
+ /** the open credential asks of every house repo, by the names they store; a repo with no queue is not made one */
431
+ async function houseAsks(root: string): Promise<AskOf[]> {
432
+ const [{ houseRepos, asksDirOf }, { openAsks }] = await Promise.all([import('../serve/project-gutter.ts'), import('../asks/asks-queue.ts')])
433
+ return houseRepos(root, homedir()).repos.flatMap((r) => {
434
+ let src = ''
435
+ try {
436
+ src = readFileSync(join(r.path, 'repo.config.ts'), 'utf8')
437
+ } catch {
438
+ return []
439
+ }
440
+ const dir = join(r.path, asksDirOf(src, r.path))
441
+ if (!existsSync(dir)) return []
442
+ try {
443
+ return openAsks(dir).filter((a) => a.kind === 'credential' && a.secrets.length > 0).map((a) => ({ repo: r.name, file: a.file, title: a.title, secrets: a.secrets }))
444
+ } catch {
445
+ return []
446
+ }
447
+ })
448
+ }
449
+
450
+ /** the walk's answer as json and back: the vault's paths with their version and date, and when they were listed */
451
+ export type NamesAnswer = { at: number; names: [path: string, meta: Meta][] }
452
+ export const namesAnswer = (names: Map<string, Meta>, at: number): NamesAnswer => ({ at, names: [...names] })
453
+ export const namesOfAnswer = (a: NamesAnswer): Map<string, Meta> => new Map(a.names)
454
+
455
+ /** `GET /api/home/vault/names`: the vault's paths as this process holds them (kept KEEP_MS; versions and dates, never a
456
+ * value), so the console twin takes them and walks no name itself. 503 where they were not read */
457
+ export async function vaultNamesRoute(root: string | null): Promise<Response> {
458
+ try {
459
+ const d = await vaultDeps(root, { seal: 'skip' })
460
+ if (d.names == null) return Response.json({ error: 'this machine holds no minter token' }, { status: 503 })
461
+ const names = await d.names()
462
+ return Response.json(namesAnswer(names, keptWalk?.w.listedAt ?? Date.now()), { headers: { 'cache-control': 'no-store' } })
463
+ } catch {
464
+ return Response.json({ error: 'the list of its names was not read' }, { status: 503 })
465
+ }
466
+ }
467
+
468
+ /** one answer at a time, kept a few seconds: two tabs polling make one read of the vault */
469
+ let last: { at: number; root: string; v: Promise<VaultPage> } | null = null
470
+ const TTL_MS = 5_000
471
+
472
+ /** `GET /api/home/vault`: the page's data. A failure answers our own words, never the error's */
473
+ export async function vaultRoute(root: string, o: { fresh?: boolean; deps?: (root: string, fresh: boolean) => Promise<VaultPageDeps> } = {}): Promise<Response> {
474
+ const deps = o.deps ?? ((r, fresh) => vaultDeps(r, { fresh, seal: 'skip' }))
475
+ if (o.fresh === true || last == null || last.root !== root || Date.now() - last.at > TTL_MS) last = { at: Date.now(), root, v: deps(root, o.fresh === true).then(vaultPage) }
476
+ try {
477
+ return Response.json(await last.v, { headers: { 'cache-control': 'no-store' } })
478
+ } catch {
479
+ last = null
480
+ return Response.json({ refused: 'the vault page could not be read on this machine: sk vault status says why' }, { status: 503 })
481
+ }
482
+ }
@@ -0,0 +1,132 @@
1
+ // the vault page's shape and its words, shared by the home page and `sk vault status`: pure and browser safe. The
2
+ // constraint a reader breaks first: nothing here holds or derives a value, only names, scopes, states and dates
3
+ import type { ScopeChip } from '../core/scope.ts'
4
+ import { ago } from '../hq/machine-notes.ts'
5
+
6
+ export type Tone = 'ok' | 'warn' | 'danger' | 'dim'
7
+ /** one line fact; `process` the global process it names, which the page links to */
8
+ export type Fact = { text: string; tone: Tone; process?: { repo: string; id: string } }
9
+
10
+ /** one name the house or the store knows. `inVault`/`inKeychain` null when that store was not read */
11
+ export type SecretRow = {
12
+ name: string
13
+ /** what it is for, as its registry row says (the account column) */
14
+ for: string
15
+ /** who reads it, in words */
16
+ who: string
17
+ /** the same readers as an ask's row draws them: a short cell and its chips. Absent where no house was read */
18
+ short?: string
19
+ chips?: ScopeChip[]
20
+ scope: { repos: string[]; identities: string[]; machines: string[] }
21
+ level: 'core' | 'used' | 'minor' | null
22
+ /** a registry row names it */
23
+ registered: boolean
24
+ inVault: boolean | null
25
+ inKeychain: boolean | null
26
+ /** when the keychain was read (the compare's date), and whether that is too old to say missing */
27
+ keychainAt: number | null
28
+ keychainStale: boolean
29
+ /** when its current version was written, the vault's own metadata */
30
+ written: number | null
31
+ version: number | null
32
+ /** why it has no place in the vault, or where the vault files it apart from its row */
33
+ note: string | null
34
+ /** the open credential ask that waits for it */
35
+ ask: { repo: string; file: string; title: string } | null
36
+ }
37
+
38
+ export type VaultPage = {
39
+ at: number
40
+ machine: string
41
+ /** this machine runs a vault */
42
+ here: boolean
43
+ stands: Fact[]
44
+ lives: Fact[]
45
+ copies: Fact[]
46
+ secrets: SecretRow[]
47
+ /** what the list could not read, in words */
48
+ notes: Fact[]
49
+ }
50
+
51
+ /** `absent`: the vault was read and lacks it, the keychain was not read */
52
+ export type HeldState = 'vault' | 'keychain' | 'absent' | 'missing' | 'unknown'
53
+
54
+ /** where a name is held, from what was read only: on the vault's machine the vault decides, and a vault not read
55
+ * says nothing of the name whatever the keychain says; on a machine with no vault the keychain is the store */
56
+ export function heldOf(r: SecretRow, here: boolean): HeldState {
57
+ if (here) {
58
+ if (r.inVault === true) return 'vault'
59
+ if (r.inVault === null) return 'unknown'
60
+ if (r.inKeychain === true) return 'keychain'
61
+ return r.inKeychain === null || r.keychainStale ? 'absent' : 'missing'
62
+ }
63
+ if (r.inKeychain === true) return 'keychain'
64
+ return r.inKeychain === null ? 'unknown' : 'missing'
65
+ }
66
+
67
+ /** `now`: the read's moment, for the age of a compare too old to trust */
68
+ export function heldWords(r: SecretRow, here: boolean, now: number = Date.now()): { text: string; tone: Tone } {
69
+ const h = heldOf(r, here)
70
+ if (h === 'vault') return { text: 'in the vault', tone: 'ok' }
71
+ const age = r.keychainStale && r.keychainAt != null ? `, ${ago(Math.max(0, now - r.keychainAt))} ago` : ''
72
+ if (h === 'keychain') return here ? { text: `only in the keychain${age}`, tone: 'warn' } : { text: `in the keychain${age}`, tone: age === '' ? 'ok' : 'warn' }
73
+ if (h === 'unknown') return { text: 'not read', tone: 'dim' }
74
+ if (h === 'absent') return { text: 'not in the vault', tone: 'warn' }
75
+ return { text: 'missing', tone: r.level === 'core' ? 'danger' : r.level === 'minor' ? 'dim' : 'warn' }
76
+ }
77
+
78
+ const day = (at: number): string => {
79
+ const d = new Date(at)
80
+ const p = (n: number): string => String(n).padStart(2, '0')
81
+ return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`
82
+ }
83
+
84
+ /** how long ago its current version was written, the table's cell: the day is its hover */
85
+ export const writtenShort = (r: SecretRow, now: number): string => (r.written == null ? '' : `${ago(Math.max(0, now - r.written))} ago${r.version != null && r.version > 1 ? `, v${r.version}` : ''}`)
86
+
87
+ /** when its current version was written, and how long ago */
88
+ export const writtenWords = (r: SecretRow, now: number): string => (r.written == null ? '' : `${day(r.written)}, ${writtenShort(r, now)}`)
89
+
90
+ export type RowFilter = { text: string; missing: boolean; repo: string; identity: string }
91
+ export const NO_FILTER: RowFilter = { text: '', missing: false, repo: '', identity: '' }
92
+
93
+ /** a row a filter keeps: every word of the text in its name, its use or its readers; « missing » keeps what is read
94
+ * as not held (never a row not read); a repo or an identity keeps the rows it reads (a row for every repo included) */
95
+ export function keeps(r: SecretRow, f: RowFilter, here: boolean): boolean {
96
+ const all = r.scope.repos.length + r.scope.identities.length + r.scope.machines.length === 0
97
+ const h = heldOf(r, here)
98
+ if (f.missing && h !== 'missing' && h !== 'absent') return false
99
+ if (f.repo !== '' && !all && !r.scope.repos.includes(f.repo)) return false
100
+ if (f.identity !== '' && !all && !r.scope.identities.includes(f.identity)) return false
101
+ const hay = `${r.name} ${r.for} ${r.who}`.toLowerCase()
102
+ return f.text.toLowerCase().split(/\s+/).every((w) => w === '' || hay.includes(w))
103
+ }
104
+
105
+ /** the repos and identities the rows name, for the filters */
106
+ export const scopesOf = (rows: readonly SecretRow[]): { repos: string[]; identities: string[] } => ({
107
+ repos: [...new Set(rows.flatMap((r) => r.scope.repos))].sort(),
108
+ identities: [...new Set(rows.flatMap((r) => r.scope.identities))].sort(),
109
+ })
110
+
111
+ /** the counts above the list */
112
+ export function countWords(rows: readonly SecretRow[], here: boolean): string {
113
+ const n = (h: HeldState): number => rows.filter((r) => heldOf(r, here) === h).length
114
+ const parts = [`${rows.length} names`, here && n('unknown') < rows.length ? `${n('vault')} in the vault` : '', n('keychain') > 0 ? `${n('keychain')} ${here ? 'only in the keychain' : 'in the keychain'}` : '', n('absent') > 0 ? `${n('absent')} not in the vault` : '', n('missing') > 0 ? `${n('missing')} missing` : '', n('unknown') > 0 ? `${n('unknown')} not read` : '', rows.some((r) => !r.registered) ? `${rows.filter((r) => !r.registered).length} with no registry row` : '']
115
+ return parts.filter((p) => p !== '').join(', ')
116
+ }
117
+
118
+ export const factLine = (f: Fact): string => (f.tone === 'danger' ? ` \x1b[31mDANGER: ${f.text}\x1b[0m` : f.tone === 'warn' ? ` WARN ${f.text}` : ` ${f.text}`)
119
+
120
+ /** the page as the console prints it: the three parts, and each row of the list with `rows` */
121
+ export function vaultLines(p: VaultPage, o: { rows?: boolean } = {}): string[] {
122
+ const [head, ...stands] = p.stands
123
+ const out = [head?.text ?? '', ...stands.map(factLine), 'where it lives', ...p.lives.map(factLine), 'its copies', ...p.copies.map(factLine)]
124
+ out.push(`the secrets: ${countWords(p.secrets, p.here)}${o.rows === true ? '' : ' (sk vault status --secrets lists them)'}`)
125
+ out.push(...p.notes.map(factLine))
126
+ if (o.rows === true)
127
+ for (const r of p.secrets) {
128
+ const h = heldWords(r, p.here, p.at)
129
+ out.push(` ${h.text.padEnd(20)} ${r.name.padEnd(44)} ${r.short ?? r.who}${r.registered ? '' : ' (no registry row)'}${r.written == null ? '' : ` written ${writtenWords(r, p.at)}`}${r.ask == null ? '' : ` ask ${r.ask.repo} ${r.ask.file}`}${r.note == null ? '' : ` (${r.note})`}`)
130
+ }
131
+ return out.filter((l) => l !== '')
132
+ }