rvlib-shipkit 2.25.0 → 2.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (456) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/package.json +2 -2
  3. package/src/agent-time/diet.ts +77 -0
  4. package/src/agent-time/family.ts +72 -0
  5. package/src/agent-time/hooks.ts +331 -0
  6. package/src/agent-time/limits.ts +44 -0
  7. package/src/agent-time/live.ts +1 -3
  8. package/src/agent-time/mask.ts +96 -18
  9. package/src/agent-time/refused.ts +45 -0
  10. package/src/agent-time/render.ts +130 -17
  11. package/src/agent-time/report-cache.ts +57 -0
  12. package/src/agent-time/report.ts +349 -23
  13. package/src/agent-time/shape.ts +50 -3
  14. package/src/agent-time/store.ts +370 -95
  15. package/src/agent-time/timeline.ts +140 -21
  16. package/src/agent-time/turns.ts +18 -8
  17. package/src/annex/offload.ts +17 -6
  18. package/src/annex/tidy.ts +70 -10
  19. package/src/asks/ask-after.ts +40 -0
  20. package/src/asks/asks-queue.ts +205 -47
  21. package/src/assets/kit-config.ts +7 -3
  22. package/src/assets/kits/identity-kit.ts +289 -10
  23. package/src/check.ts +3 -1
  24. package/src/checks/SK004-gitignore-policy.check.ts +12 -5
  25. package/src/checks/SK013-one-way-in-policy.check.ts +8 -3
  26. package/src/checks/SK026-asks-autoclose.check.ts +5 -5
  27. package/src/checks/SK028-readme.check.ts +7 -66
  28. package/src/checks/SK030-cache-audit.check.ts +6 -1
  29. package/src/checks/SK031-trace-audit.check.ts +2 -0
  30. package/src/checks/SK033-global-contribution.check.ts +3 -1
  31. package/src/checks/SK035-public-clean.check.ts +2 -2
  32. package/src/checks/SK043-scratch-on-the-mac.check.ts +59 -4
  33. package/src/checks/SK045-slow-hooks.check.ts +47 -0
  34. package/src/checks/SK046-hook-records.check.ts +76 -0
  35. package/src/checks/SK047-login-in-description.check.ts +36 -0
  36. package/src/checks/SK048-one-local-file.check.ts +36 -0
  37. package/src/cli/cmd_Asks.ts +71 -5
  38. package/src/cli/cmd_Backup.ts +5 -3
  39. package/src/cli/cmd_Capacity.ts +2 -2
  40. package/src/cli/cmd_CrossRepoActivity.ts +5 -4
  41. package/src/cli/cmd_Db.ts +253 -0
  42. package/src/cli/cmd_History.ts +212 -0
  43. package/src/cli/cmd_Home.ts +31 -3
  44. package/src/cli/cmd_Hq.ts +516 -0
  45. package/src/cli/cmd_Machines.ts +36 -0
  46. package/src/cli/cmd_Media.ts +38 -6
  47. package/src/cli/cmd_Mv.ts +1 -1
  48. package/src/cli/cmd_Reflect.ts +23 -2
  49. package/src/cli/cmd_Releases.ts +30 -0
  50. package/src/cli/cmd_Review.ts +569 -118
  51. package/src/cli/cmd_Secret.ts +62 -12
  52. package/src/cli/cmd_Social.ts +83 -1
  53. package/src/cli/cmd_Space.ts +324 -0
  54. package/src/cli/cmd_Time.ts +82 -5
  55. package/src/cli/cmd_Tmp.ts +28 -4
  56. package/src/cli/cmd_Trailer.ts +14 -10
  57. package/src/cli/cmd_Urls.ts +56 -0
  58. package/src/cli/cmd_Vault.ts +583 -0
  59. package/src/cli/family-help.ts +4 -2
  60. package/src/cli/family-pages.ts +1 -1
  61. package/src/cli/registry.ts +26 -4
  62. package/src/collections/actions.ts +63 -13
  63. package/src/collections/collection-types.ts +23 -1
  64. package/src/collections/providers.ts +117 -23
  65. package/src/collections/review.ts +4 -4
  66. package/src/commands/runner.ts +5 -1
  67. package/src/contracts/contract-manifests.ts +6 -5
  68. package/src/contracts/contract-types.ts +6 -4
  69. package/src/contracts/contracts-engine.ts +11 -0
  70. package/src/contracts/manifests/chrome-web-store.contract.ts +31 -0
  71. package/src/core/budget.ts +12 -17
  72. package/src/core/capacity.ts +27 -18
  73. package/src/core/check-runner.ts +7 -4
  74. package/src/core/history-files.ts +9 -5
  75. package/src/core/layout.ts +3 -0
  76. package/src/core/machine-busy.ts +127 -0
  77. package/src/core/machine-commit.ts +6 -1
  78. package/src/core/machine-db.ts +368 -20
  79. package/src/core/machine-layout.ts +137 -0
  80. package/src/core/machine-read.ts +81 -0
  81. package/src/core/migrate-layout.ts +1 -1
  82. package/src/core/one-way-in-policy.ts +64 -7
  83. package/src/core/polling-policy.ts +27 -0
  84. package/src/core/retention.ts +16 -2
  85. package/src/core/scope.ts +107 -14
  86. package/src/core/signal-name.ts +6 -0
  87. package/src/core/slots.ts +5 -4
  88. package/src/core/trace-audit.ts +6 -1
  89. package/src/core/transient.ts +6 -0
  90. package/src/drill/clean.ts +25 -1
  91. package/src/drill/run.ts +2 -2
  92. package/src/drill/seal.ts +27 -4
  93. package/src/home/activity-shape.ts +2 -0
  94. package/src/home/activity.ts +66 -3
  95. package/src/home/app-sign.ts +15 -4
  96. package/src/home/daemon-jobs.ts +149 -7
  97. package/src/home/database-projects.ts +111 -0
  98. package/src/home/database-words.ts +203 -0
  99. package/src/home/databases.ts +460 -0
  100. package/src/home/global-units.ts +6 -0
  101. package/src/home/gui-app/ShipkitGui.swift +122 -1
  102. package/src/home/gui-app.ts +6 -3
  103. package/src/home/home-move.ts +514 -0
  104. package/src/home/home-paths.ts +12 -3
  105. package/src/home/home-routes.ts +68 -0
  106. package/src/home/inbox-shape.ts +24 -14
  107. package/src/home/machine-fold.ts +820 -0
  108. package/src/home/machine-host.ts +20 -5
  109. package/src/home/machine-repair.ts +503 -0
  110. package/src/home/machine-stores.ts +66 -15
  111. package/src/home/machine-temp.ts +547 -86
  112. package/src/home/resume.ts +79 -0
  113. package/src/home/run-daemon.ts +25 -4
  114. package/src/home/run-pm.ts +18 -5
  115. package/src/home/serve-daemon.ts +18 -3
  116. package/src/home/serve-web.ts +175 -7
  117. package/src/home/space-job.ts +115 -0
  118. package/src/home/space-page.ts +257 -0
  119. package/src/home/space-route.ts +167 -0
  120. package/src/home/space-words.ts +103 -0
  121. package/src/home/time-page-shape.ts +202 -0
  122. package/src/home/time-page.ts +64 -0
  123. package/src/home/vault-page.ts +482 -0
  124. package/src/home/vault-words.ts +132 -0
  125. package/src/hooks/leak-guard.ts +40 -13
  126. package/src/hooks/one-way-in-guard.ts +17 -4
  127. package/src/hq/cards.ts +581 -0
  128. package/src/hq/door-route.ts +43 -0
  129. package/src/hq/door.ts +163 -0
  130. package/src/hq/files-send.ts +348 -0
  131. package/src/hq/forgotten-log.ts +35 -0
  132. package/src/hq/history-check.ts +255 -0
  133. package/src/hq/history-place.ts +146 -0
  134. package/src/hq/history-send.ts +487 -0
  135. package/src/hq/hq-db.ts +99 -0
  136. package/src/hq/hq-local.ts +469 -0
  137. package/src/hq/hq-routes.ts +196 -0
  138. package/src/hq/hq-store.ts +599 -0
  139. package/src/hq/kinds/ask.ts +147 -0
  140. package/src/hq/kinds/card-gone.ts +83 -0
  141. package/src/hq/kinds/card-msg.ts +66 -0
  142. package/src/hq/kinds/card.ts +99 -0
  143. package/src/hq/kinds/index.ts +21 -0
  144. package/src/hq/kinds/kind.ts +126 -0
  145. package/src/hq/kinds/media.ts +125 -0
  146. package/src/hq/kinds/prompt.ts +219 -0
  147. package/src/hq/kinds/reflection.ts +128 -0
  148. package/src/hq/kinds/report.ts +55 -0
  149. package/src/hq/kinds/time-day.ts +236 -0
  150. package/src/hq/ledger.ts +473 -0
  151. package/src/hq/machine-key.ts +44 -0
  152. package/src/hq/machine-notes.ts +131 -0
  153. package/src/hq/outbox.ts +372 -0
  154. package/src/hq/replica.ts +168 -0
  155. package/src/hq/repo-id.ts +4 -0
  156. package/src/hq/report-facts.ts +117 -0
  157. package/src/hq/report.ts +274 -0
  158. package/src/hq/switch.ts +151 -0
  159. package/src/hq/vault-grant.ts +92 -0
  160. package/src/identities/identities.ts +15 -3
  161. package/src/identities/steps.ts +31 -0
  162. package/src/ledger/db.ts +73 -26
  163. package/src/ledger/gate-checks.ts +29 -4
  164. package/src/ledger/git-key.ts +3 -3
  165. package/src/ledger/git-scan.ts +49 -7
  166. package/src/ledger/run-log.ts +11 -3
  167. package/src/ledger/store.ts +26 -4
  168. package/src/media-store/backup/daemon.ts +36 -17
  169. package/src/media-store/backup/kept.ts +241 -0
  170. package/src/media-store/backup/restore.ts +14 -4
  171. package/src/media-store/backup/run.ts +11 -11
  172. package/src/media-store/backup/secret.ts +6 -4
  173. package/src/media-store/backup/snapshot.ts +4 -2
  174. package/src/media-store/backup/sources.ts +68 -20
  175. package/src/media-store/copy/config.ts +77 -0
  176. package/src/media-store/copy/copy.ts +194 -0
  177. package/src/media-store/copy/lifecycle.ts +43 -0
  178. package/src/media-store/copy/night.ts +90 -0
  179. package/src/media-store/copy/proof.ts +151 -0
  180. package/src/media-store/copy/snapshot.ts +152 -0
  181. package/src/media-store/copy/store.ts +62 -0
  182. package/src/media-store/copy/stream.ts +176 -0
  183. package/src/media-store/daemon.ts +66 -16
  184. package/src/media-store/db.ts +22 -11
  185. package/src/media-store/forget.ts +23 -3
  186. package/src/media-store/hand.ts +4 -3
  187. package/src/media-store/hq-find.ts +75 -0
  188. package/src/media-store/hq-send.ts +277 -0
  189. package/src/media-store/kind.ts +2 -0
  190. package/src/media-store/purge.ts +18 -15
  191. package/src/media-store/put.ts +24 -8
  192. package/src/media-store/remote.ts +16 -7
  193. package/src/media-store/space-listing.ts +240 -0
  194. package/src/media-store/space.ts +40 -21
  195. package/src/media-store/sync.ts +5 -5
  196. package/src/media-store/tidy.ts +98 -0
  197. package/src/media-store/upload.ts +3 -3
  198. package/src/media-store/webp.ts +66 -0
  199. package/src/messages/model.ts +16 -7
  200. package/src/messages/routes.ts +14 -4
  201. package/src/messages/score.ts +2 -2
  202. package/src/messages/suggest.ts +96 -0
  203. package/src/pages/frame-client.ts +10 -0
  204. package/src/plan/planner.ts +28 -17
  205. package/src/recordings/media-kind.ts +1 -0
  206. package/src/recordings/model.ts +1 -1
  207. package/src/recordings/recorder-app/Capture.swift +9 -7
  208. package/src/reflect/hq-corpus.ts +56 -0
  209. package/src/reflect/prompt-corpus.ts +3 -1
  210. package/src/reflect/transcript.ts +146 -36
  211. package/src/release/machine-words.ts +67 -0
  212. package/src/release/public-clean.ts +8 -3
  213. package/src/releases/from-card.ts +1 -1
  214. package/src/releases/model.ts +18 -0
  215. package/src/releases/routes.ts +10 -5
  216. package/src/releases/store.ts +23 -2
  217. package/src/repo-config.ts +42 -2
  218. package/src/review/anim.ts +2 -2
  219. package/src/review/auto.ts +2 -2
  220. package/src/review/card-db.ts +244 -0
  221. package/src/review/card-rows.ts +266 -0
  222. package/src/review/cells.ts +76 -5
  223. package/src/review/draft-card.ts +41 -0
  224. package/src/review/draft-model.ts +78 -0
  225. package/src/review/format.ts +29 -10
  226. package/src/review/gone.ts +98 -0
  227. package/src/review/inbox-hook.ts +35 -0
  228. package/src/review/marks.ts +1 -1
  229. package/src/review/media-kind.ts +7 -5
  230. package/src/review/media-read.ts +9 -7
  231. package/src/review/media.ts +32 -5
  232. package/src/review/model.ts +214 -45
  233. package/src/review/move.ts +491 -0
  234. package/src/review/notes.ts +12 -20
  235. package/src/review/previews.ts +15 -19
  236. package/src/review/project.ts +1 -1
  237. package/src/review/rev.ts +8 -0
  238. package/src/review/role.ts +1 -1
  239. package/src/review/routes.ts +64 -13
  240. package/src/review/stage-card.ts +8 -4
  241. package/src/review/stage-routes.ts +1 -1
  242. package/src/review/store.ts +529 -83
  243. package/src/review/thread-fold.ts +51 -0
  244. package/src/review/threads.ts +147 -9
  245. package/src/review/trailer-auto-mock.ts +63 -0
  246. package/src/review/trailer-card.ts +4 -4
  247. package/src/review/trailer-desk.ts +41 -7
  248. package/src/review/trailer-media.ts +1 -0
  249. package/src/review/trailer-model.ts +8 -0
  250. package/src/review/trailer-notes.ts +1 -1
  251. package/src/review/trailer-routes.ts +9 -1
  252. package/src/review/unit.ts +6 -6
  253. package/src/review/watchers.ts +1 -1
  254. package/src/rules/untrack-generated.ts +92 -8
  255. package/src/secrets/held.ts +16 -0
  256. package/src/secrets/keychain.ts +113 -0
  257. package/src/secrets/list.ts +16 -6
  258. package/src/secrets/manager.ts +24 -10
  259. package/src/secrets/read.ts +257 -0
  260. package/src/secrets/who-reads.ts +49 -0
  261. package/src/serve/door-forward.ts +268 -0
  262. package/src/serve/door-names.ts +47 -0
  263. package/src/serve/embed.ts +1 -1
  264. package/src/serve/hub-app/activity-view.tsx +56 -32
  265. package/src/serve/hub-app/activity.css +7 -1
  266. package/src/serve/hub-app/asks-page.tsx +48 -0
  267. package/src/serve/hub-app/asks-st.ts +25 -0
  268. package/src/serve/hub-app/clock-svc.ts +1 -2
  269. package/src/serve/hub-app/col-card.tsx +64 -13
  270. package/src/serve/hub-app/col-list-page.tsx +122 -0
  271. package/src/serve/hub-app/col-list-st.ts +103 -0
  272. package/src/serve/hub-app/col-tables-view.tsx +10 -41
  273. package/src/serve/hub-app/col-tables.ts +76 -8
  274. package/src/serve/hub-app/cols-svc.ts +70 -16
  275. package/src/serve/hub-app/database-st.ts +260 -0
  276. package/src/serve/hub-app/database-view.tsx +289 -0
  277. package/src/serve/hub-app/database.css +32 -0
  278. package/src/serve/hub-app/entry-bar.css +14 -0
  279. package/src/serve/hub-app/entry-bar.tsx +33 -0
  280. package/src/serve/hub-app/entry-pick.ts +31 -0
  281. package/src/serve/hub-app/floating.tsx +1 -0
  282. package/src/serve/hub-app/hash-route.ts +11 -1
  283. package/src/serve/hub-app/header-bar.tsx +14 -18
  284. package/src/serve/hub-app/home-st.ts +89 -9
  285. package/src/serve/hub-app/home-strip.css +5 -19
  286. package/src/serve/hub-app/home-strip.tsx +58 -92
  287. package/src/serve/hub-app/home.html +7 -0
  288. package/src/serve/hub-app/hub-app.tsx +31 -142
  289. package/src/serve/hub-app/hub-types.ts +3 -1
  290. package/src/serve/hub-app/hub.css +109 -23
  291. package/src/serve/hub-app/icons.tsx +18 -1
  292. package/src/serve/hub-app/identities-st.ts +56 -6
  293. package/src/serve/hub-app/identities-view.tsx +100 -58
  294. package/src/serve/hub-app/identities.css +17 -15
  295. package/src/serve/hub-app/identity-address.ts +5 -0
  296. package/src/serve/hub-app/inbox-st.ts +41 -24
  297. package/src/serve/hub-app/inbox-view.tsx +37 -41
  298. package/src/serve/hub-app/inbox.css +2 -5
  299. package/src/serve/hub-app/index.html +7 -0
  300. package/src/serve/hub-app/kept-cols.tsx +7 -0
  301. package/src/serve/hub-app/keys.ts +28 -15
  302. package/src/serve/hub-app/later.tsx +26 -0
  303. package/src/serve/hub-app/list-filter.tsx +14 -0
  304. package/src/serve/hub-app/list-walk.ts +72 -3
  305. package/src/serve/hub-app/machines-st.ts +251 -0
  306. package/src/serve/hub-app/machines-view.tsx +224 -0
  307. package/src/serve/hub-app/machines.css +76 -0
  308. package/src/serve/hub-app/md-copy.tsx +79 -0
  309. package/src/serve/hub-app/media-view.tsx +2 -0
  310. package/src/serve/hub-app/messages/messages-page.tsx +79 -7
  311. package/src/serve/hub-app/messages/messages-st.ts +99 -3
  312. package/src/serve/hub-app/messages.css +14 -0
  313. package/src/serve/hub-app/page-keys.ts +175 -0
  314. package/src/serve/hub-app/pages-frames.tsx +11 -3
  315. package/src/serve/hub-app/palette-st.ts +58 -11
  316. package/src/serve/hub-app/palette-view.tsx +3 -1
  317. package/src/serve/hub-app/project-list.css +54 -8
  318. package/src/serve/hub-app/project-list.tsx +128 -59
  319. package/src/serve/hub-app/projects-svc.ts +78 -7
  320. package/src/serve/hub-app/reader-chips.tsx +13 -0
  321. package/src/serve/hub-app/readme-view.tsx +2 -3
  322. package/src/serve/hub-app/readme.css +27 -5
  323. package/src/serve/hub-app/reflections-page.tsx +42 -0
  324. package/src/serve/hub-app/reflections-st.ts +17 -0
  325. package/src/serve/hub-app/releases/releases-page.tsx +25 -2
  326. package/src/serve/hub-app/releases/releases-st.ts +1 -1
  327. package/src/serve/hub-app/repo-sections.ts +9 -5
  328. package/src/serve/hub-app/repo-st.ts +35 -8
  329. package/src/serve/hub-app/review/draft-card.tsx +163 -0
  330. package/src/serve/hub-app/review/kit.tsx +50 -7
  331. package/src/serve/hub-app/review/note-place.ts +1 -1
  332. package/src/serve/hub-app/review/review-board.tsx +2 -2
  333. package/src/serve/hub-app/review/review-cells.tsx +145 -65
  334. package/src/serve/hub-app/review/review-kit.ts +27 -1
  335. package/src/serve/hub-app/review/review-list.tsx +68 -30
  336. package/src/serve/hub-app/review/review-page.tsx +7 -8
  337. package/src/serve/hub-app/review/review-st.ts +111 -24
  338. package/src/serve/hub-app/review/review-thread.tsx +49 -19
  339. package/src/serve/hub-app/review/review-views.tsx +475 -144
  340. package/src/serve/hub-app/review/thread-control-st.ts +115 -0
  341. package/src/serve/hub-app/review/thread-control.tsx +74 -0
  342. package/src/serve/hub-app/review/thread-st.ts +73 -26
  343. package/src/serve/hub-app/review/trailer-card.tsx +1 -1
  344. package/src/serve/hub-app/review/trailer-page.tsx +37 -16
  345. package/src/serve/hub-app/review/trailer-st.ts +41 -7
  346. package/src/serve/hub-app/review.css +267 -61
  347. package/src/serve/hub-app/side-lists.ts +72 -0
  348. package/src/serve/hub-app/sidebar.tsx +6 -3
  349. package/src/serve/hub-app/site/site-part.tsx +2 -8
  350. package/src/serve/hub-app/site/site-st.ts +4 -4
  351. package/src/serve/hub-app/social/comms-page.tsx +20 -5
  352. package/src/serve/hub-app/social/kit.tsx +30 -4
  353. package/src/serve/hub-app/social/post-card.tsx +139 -49
  354. package/src/serve/hub-app/social/serial-writes.ts +13 -0
  355. package/src/serve/hub-app/social/social-model.ts +11 -0
  356. package/src/serve/hub-app/social/social-page.tsx +94 -35
  357. package/src/serve/hub-app/social/social-st.ts +120 -36
  358. package/src/serve/hub-app/social/stage-popup.tsx +1 -1
  359. package/src/serve/hub-app/social/stage-st.ts +1 -1
  360. package/src/serve/hub-app/social/step-layout.ts +1 -1
  361. package/src/serve/hub-app/social.css +3 -0
  362. package/src/serve/hub-app/space-st.ts +209 -0
  363. package/src/serve/hub-app/space-view.tsx +196 -0
  364. package/src/serve/hub-app/space.css +27 -0
  365. package/src/serve/hub-app/stores/stores-page.tsx +91 -23
  366. package/src/serve/hub-app/stores/stores-st.ts +44 -19
  367. package/src/serve/hub-app/stores.css +6 -1
  368. package/src/serve/hub-app/theme-st.ts +22 -9
  369. package/src/serve/hub-app/time-charts.tsx +291 -0
  370. package/src/serve/hub-app/time-pages.tsx +749 -0
  371. package/src/serve/hub-app/time-st.ts +162 -0
  372. package/src/serve/hub-app/time-view.tsx +76 -0
  373. package/src/serve/hub-app/time.css +138 -0
  374. package/src/serve/hub-app/tree-build.ts +52 -42
  375. package/src/serve/hub-app/tree-row.tsx +4 -4
  376. package/src/serve/hub-app/tree-svc.ts +18 -9
  377. package/src/serve/hub-app/urls-svc.ts +154 -0
  378. package/src/serve/hub-app/urls-view.tsx +117 -0
  379. package/src/serve/hub-app/urls.css +30 -0
  380. package/src/serve/hub-app/vault-st.ts +127 -0
  381. package/src/serve/hub-app/vault-view.tsx +154 -0
  382. package/src/serve/hub-app/vault.css +38 -0
  383. package/src/serve/hub-app/veille/veille-st.ts +12 -10
  384. package/src/serve/hub-app/waiting-svc.ts +29 -0
  385. package/src/serve/hub-app/wikis-view.tsx +2 -2
  386. package/src/serve/hub-runtime.ts +15 -2
  387. package/src/serve/project-gutter-route.ts +27 -14
  388. package/src/serve/project-gutter.ts +25 -12
  389. package/src/serve/same-origin.ts +10 -0
  390. package/src/serve/serve-hub.ts +13 -4
  391. package/src/shipkit-files.ts +16 -2
  392. package/src/shipkit.ts +1 -1
  393. package/src/shot/shooter.ts +616 -420
  394. package/src/shot/shot-ask.ts +246 -155
  395. package/src/site/desk.ts +2 -2
  396. package/src/smoke/run-smoke.ts +3 -2
  397. package/src/social/cover.ts +202 -0
  398. package/src/social/discord-layout.ts +37 -13
  399. package/src/social/drafts.ts +3 -0
  400. package/src/social/load.ts +23 -2
  401. package/src/social/media-kind.ts +2 -1
  402. package/src/social/publish/discord.ts +5 -2
  403. package/src/social/publish/secret.ts +2 -2
  404. package/src/social/release-stage.ts +28 -13
  405. package/src/social/routes.ts +26 -1
  406. package/src/social/stage.ts +1 -1
  407. package/src/social/stats.ts +12 -9
  408. package/src/social/strip.ts +4 -1
  409. package/src/social/thumbnail.ts +255 -0
  410. package/src/stores/collection.ts +15 -11
  411. package/src/stores/desk.ts +236 -42
  412. package/src/stores/model.ts +72 -6
  413. package/src/stores/routes.ts +37 -12
  414. package/src/stores/unit.ts +14 -8
  415. package/src/suite/judge-suites.ts +113 -16
  416. package/src/suite/select.ts +45 -3
  417. package/src/suite/suite-cli.ts +81 -34
  418. package/src/trailer/bed.ts +1 -1
  419. package/src/trailer/build.ts +134 -21
  420. package/src/trailer/ffmpeg.ts +7 -0
  421. package/src/trailer/fonts.ts +3 -2
  422. package/src/trailer/grammar.ts +201 -2
  423. package/src/trailer/graph.ts +42 -5
  424. package/src/trailer/look.ts +21 -0
  425. package/src/trailer/mock.ts +154 -0
  426. package/src/trailer/passage.ts +65 -26
  427. package/src/trailer/score/heard.ts +89 -0
  428. package/src/trailer/score/sound.ts +14 -8
  429. package/src/trailer/sound/run.ts +16 -6
  430. package/src/trailer/stitch.ts +26 -5
  431. package/src/trailer/titles.ts +82 -19
  432. package/src/trailer/versions.ts +1 -3
  433. package/src/trailer/vertical.ts +3 -1
  434. package/src/urls/frame.ts +195 -0
  435. package/src/urls/routes.ts +43 -0
  436. package/src/urls/rows.ts +171 -0
  437. package/src/urls/unit.ts +73 -0
  438. package/src/vault/house-keys.ts +42 -0
  439. package/src/vault/layout.ts +50 -0
  440. package/src/vault/policy.ts +165 -0
  441. package/src/vault/vault-audit.ts +276 -0
  442. package/src/vault/vault-client.ts +40 -0
  443. package/src/vault/vault-config.ts +159 -0
  444. package/src/vault/vault-destroy.ts +78 -0
  445. package/src/vault/vault-handover.ts +305 -0
  446. package/src/vault/vault-http.ts +352 -0
  447. package/src/vault/vault-import.ts +208 -0
  448. package/src/vault/vault-init.ts +328 -0
  449. package/src/vault/vault-minter.ts +271 -0
  450. package/src/vault/vault-restore.ts +333 -0
  451. package/src/vault/vault-serve.ts +342 -0
  452. package/src/vault/vault-snapshot.ts +281 -0
  453. package/src/veille/asks.ts +1 -1
  454. package/src/veille/desk.ts +2 -2
  455. package/src/wiki/run-wiki.ts +2 -1
  456. package/src/wiki/scan-md.ts +42 -2
@@ -0,0 +1,257 @@
1
+ // the Space's one page: what each Space of the house holds and where the room goes, a folder opened down to a file,
2
+ // what it is and how it stands. `spacePage` is the one function the home's route and `sk space` print; the truth is
3
+ // the bucket's own listing, kept in the machine db by the daemon's job `space listing` (media-store/space-listing.ts),
4
+ // joined here with the media index for each file's name and who put it.
5
+ //
6
+ // The constraint a reader breaks first: a request never lists a bucket and never reads a secret. It reads what the
7
+ // job kept; the refresh asks the job. A file opens through a link signed for the hour at the click, never one kept in
8
+ // an answer, and only for a key the kept listing holds
9
+ import type { Database } from 'bun:sqlite'
10
+ import { homedir } from 'os'
11
+ import { ago } from '../hq/machine-notes.ts'
12
+ import type { Proof } from '../media-store/copy/proof.ts'
13
+ import { BACKUP_LABEL, RUNS_PREFIX } from '../media-store/backup/keys.ts'
14
+ import { PARTS_PREFIX } from '../media-store/backup/manifest.ts'
15
+ import { SNAPSHOTS } from '../media-store/copy/config.ts'
16
+ import { PUBLIC_PREFIX, type SpaceConfig } from '../media-store/space.ts'
17
+ import { counted, findKeys, folderFiles, folderSum, keptListing, parentOf, subFolders, topOf, type FolderSum, type Listed, type ListingRecord, type Split } from '../media-store/space-listing.ts'
18
+ import { SPACE_PREFIX as VAULT_SNAPSHOTS } from '../vault/vault-snapshot.ts'
19
+ import { count, size } from './database-words.ts'
20
+ import type { Fact, FileRow, FolderPage, FolderRow, SpacePage, SpaceView } from './space-words.ts'
21
+
22
+ /** one Space the house config names: its words, and its signed config read only when a listing or a link needs it */
23
+ export type SpaceEnd = {
24
+ id: 'space' | 'copy'
25
+ bucket: string
26
+ region: string
27
+ /** the origin in words: the endpoint, or the NAME of the secret that holds it */
28
+ origin: string
29
+ cdn: string | null
30
+ /** the NAME of the secret that holds its key pair */
31
+ secret: string
32
+ config: () => Promise<SpaceConfig | { why: string }>
33
+ /** the prefixes a copy never mirrors */
34
+ skip?: string[]
35
+ }
36
+
37
+ /** what the page reads, each one a test replaces */
38
+ export type SpacePageDeps = {
39
+ machine: string
40
+ now: number
41
+ ends: SpaceEnd[]
42
+ /** why the house config names no Space, null when it names one */
43
+ noEnds: string | null
44
+ /** the machine db, where the job keeps the listings */
45
+ kept: <R>(body: (db: Database) => R) => R | null
46
+ /** the media index, null when it does not open */
47
+ media: Database | null
48
+ /** the hq this machine carries, for a file another machine put; null when it carries none */
49
+ hq: Database | null
50
+ repos: { name: string; path: string }[]
51
+ kinds: { kind: string; what?: string }[]
52
+ /** the hq replica's folder in the Space, when it is in this bucket */
53
+ replica: string | null
54
+ /** what the job records: the listing that runs, the refresh asked, why a Space could not be listed */
55
+ job: { running: { at: number } | null; asked: number | null; why: Record<string, string> }
56
+ proof: Proof | null
57
+ backup: { key: string; at: string } | null
58
+ }
59
+
60
+ const ROLE = { space: 'the private Space', copy: 'its second copy, at another provider' } as const
61
+
62
+ const folderOfTop = (prefix: string): string => prefix.slice(0, prefix.indexOf('/') + 1)
63
+
64
+ /** what a folder is, in words, from the code's own names: a kind, the public folder, the backup, the snapshots, the
65
+ * hq's replica; null when the code names none */
66
+ export function folderWhat(prefix: string, d: Pick<SpacePageDeps, 'kinds' | 'replica'>): string | null {
67
+ const kind = (label: string): string | null => {
68
+ const k = d.kinds.find((x) => x.kind === label)
69
+ return k == null ? null : (k.what ?? `the media kind ${label}`)
70
+ }
71
+ if (prefix === PUBLIC_PREFIX) return 'anyone with its URL downloads it, nobody lists it'
72
+ if (prefix.startsWith(PUBLIC_PREFIX)) {
73
+ const rest = prefix.slice(PUBLIC_PREFIX.length)
74
+ return rest.split('/').length === 2 ? kind(rest.slice(0, -1)) : null
75
+ }
76
+ if (prefix === `${BACKUP_LABEL}/`) return 'the backup of each machine\'s own state, never deleted'
77
+ if (prefix === RUNS_PREFIX) return 'one manifest a backup run'
78
+ if (prefix === PARTS_PREFIX) return 'the parts of the manifests'
79
+ if (prefix === SNAPSHOTS) return 'snapshots: the vault\'s sealed ones, the hq\'s nightly one'
80
+ if (prefix === VAULT_SNAPSHOTS) return 'the vault\'s sealed snapshots, one folder a machine'
81
+ if (prefix === `${SNAPSHOTS}hq/`) return 'the hq\'s nightly snapshot'
82
+ if (d.replica != null && prefix === folderOfTop(d.replica)) return 'the hq\'s database, copied as it is written (Litestream)'
83
+ if (d.replica != null && prefix === d.replica) return 'its live copy: a snapshot and the pages written since'
84
+ return prefix.split('/').length === 2 ? kind(prefix.slice(0, -1)) : null
85
+ }
86
+
87
+ const nameOf = (prefix: string): string => prefix.slice(parentOf(prefix.slice(0, -1)).length)
88
+ const rowOf = (s: FolderSum, d: Pick<SpacePageDeps, 'kinds' | 'replica'>): FolderRow => ({ prefix: s.prefix, name: nameOf(s.prefix), bytes: s.bytes, objects: s.objects, what: folderWhat(s.prefix, d) })
89
+
90
+ /** a split in words: its count, its bytes, its three biggest top folders */
91
+ const splitWords = (s: Split, what: string): string => `${count(s.n)} ${what} (${size(s.bytes)})${s.top.length === 0 ? '' : `: ${s.top.slice(0, 3).map((t) => `${t.prefix === '' ? '(no folder)' : t.prefix} ${count(t.n)}`).join(', ')}${s.top.length > 3 ? ', …' : ''}`}`
92
+
93
+ /** a path under the user's home as `~/…` */
94
+ const shown = (path: string, home: string = homedir()): string => (path === home || path.startsWith(`${home}/`) ? `~${path.slice(home.length)}` : path)
95
+
96
+ /** about a Space: which bucket, where, who may read it, its versioning and rules, its key's name, its copy */
97
+ function aboutFacts(e: SpaceEnd, r: ListingRecord | null, d: SpacePageDeps): Fact[] {
98
+ const out: Fact[] = [{ text: `the bucket ${e.bucket}, region ${e.region}, at ${e.origin}${e.cdn == null ? '' : `, handed out on the CDN edge ${e.cdn}`}`, tone: 'ok' }]
99
+ if (e.id === 'space') out.push({ text: `private: every object but those under ${PUBLIC_PREFIX}, which anyone with its URL downloads; nobody lists it but its key`, tone: 'ok' })
100
+ else out.push({ text: 'a copy of every object of the Space but the hq\'s replica, and its own snapshots; nothing deletes at either end', tone: 'ok' })
101
+ const v = r?.versioning
102
+ out.push(v == null ? { text: 'versioning: not read yet (the listing reads it)', tone: 'dim' } : !counted(v) ? { text: `versioning: not read (${v.why})`, tone: 'warn' } : v === 'Enabled' ? { text: 'versioning: on, so an object deleted or written over keeps its older version', tone: 'ok' } : { text: `versioning: ${v === 'off' ? 'off' : 'suspended'}, an object deleted or written over is gone for good`, tone: e.id === 'space' ? 'warn' : 'dim' })
103
+ const l = r?.lifecycle
104
+ if (r == null || l === undefined) out.push({ text: 'lifecycle rules: not read yet (the listing reads them)', tone: 'dim' })
105
+ else if (!counted(l)) out.push({ text: `lifecycle rules: not read (${l.why})`, tone: 'dim' })
106
+ else if (l === null || l.length === 0) out.push({ text: 'lifecycle rules: none, nothing expires', tone: 'ok' })
107
+ else for (const rule of l) out.push({ text: `lifecycle rule ${rule}`, tone: 'ok' })
108
+ out.push({ text: `its key: the secret ${e.secret} of the registry, read through the house's secret manager, held in memory only`, tone: 'ok' })
109
+ if (e.id === 'space') {
110
+ if (d.replica != null) out.push({ text: `the hq's replica: ${d.replica} in this bucket`, tone: 'ok' })
111
+ const copy = d.ends.find((x) => x.id === 'copy')
112
+ out.push(copy == null ? { text: 'its second copy: none named in the house config (serve.spaceCopy)', tone: 'dim' } : { text: `its second copy: the bucket ${copy.bucket} (serve.spaceCopy)`, tone: 'ok' })
113
+ }
114
+ if (e.id === 'copy' || d.ends.every((x) => x.id !== 'copy')) {
115
+ const p = d.proof
116
+ if (d.ends.some((x) => x.id === 'copy')) out.push(p == null ? { text: 'its last proof: none yet (sk space proof)', tone: 'warn' } : { text: `its last proof, ${ago(Math.max(0, d.now - p.at))} ago: ${p.ok ? 'green' : 'RED'}${p.why.length > 0 ? `, ${p.why[0]}` : ''}`, tone: p.ok ? 'ok' : 'danger' })
117
+ }
118
+ return out
119
+ }
120
+
121
+ /** what waits to go up from this machine, grouped by why */
122
+ function waiting(d: SpacePageDeps): Fact[] {
123
+ if (d.media == null) return [{ text: 'what waits to go up: the media index does not open', tone: 'warn' }]
124
+ const rows = d.media.query('select count(*) as n, coalesce(sum(size), 0) as bytes, error, max(tries) as tries, min(next) as next from media_objects where up is null group by error order by n desc').all() as { n: number; bytes: number; error: string | null; tries: number; next: number }[]
125
+ if (rows.length === 0) return [{ text: 'nothing waits to go up from this machine', tone: 'ok' }]
126
+ return rows.slice(0, 4).map((r) => ({ text: `${count(r.n)} object${r.n === 1 ? '' : 's'} (${size(r.bytes)}) wait${r.n === 1 ? 's' : ''} to go up: ${r.error == null ? (r.tries === 0 ? 'not tried yet, the media job sends them' : 'tried, no error kept') : `${r.error.slice(0, 160)}, tried ${r.tries} time${r.tries === 1 ? '' : 's'}${r.next > d.now ? `, again in ${ago(r.next - d.now)}` : ''}`}`, tone: r.error == null ? 'dim' : 'warn' }))
127
+ }
128
+
129
+ /** how a Space stands: its listing, what waits, what the index and the listing disagree on, the room nobody sees */
130
+ function healthFacts(e: SpaceEnd, r: ListingRecord | null, d: SpacePageDeps): Fact[] {
131
+ const out: Fact[] = []
132
+ const why = d.job.why[e.id]
133
+ if (why != null && why !== '') out.push({ text: `the last listing failed: ${why}`, tone: 'warn' })
134
+ if (r != null) out.push({ text: `the listing: ${ago(Math.max(0, d.now - r.at))} ago, ${count(r.calls)} calls in ${(r.ms / 1000).toFixed(1)} s, kept in the machine db (about ${size(r.keptBytes)}); the daemon lists it again each day, ↻ now`, tone: d.now - r.at > 3 * 86_400_000 ? 'warn' : 'ok' })
135
+ if (e.id === 'space') out.push(...waiting(d))
136
+ if (r != null) {
137
+ const vs = r.vsIndex
138
+ if (vs != null && counted(vs)) {
139
+ out.push(vs.upNotListed.n === 0 ? { text: 'every object this machine\'s index says is up is in the listing', tone: 'ok' } : { text: splitWords(vs.upNotListed, `object${vs.upNotListed.n === 1 ? '' : 's'} this machine's index says ${vs.upNotListed.n === 1 ? 'is' : 'are'} up, missing from the listing`), tone: 'danger' })
140
+ if (vs.notIndexed.n > 0) out.push({ text: `${splitWords(vs.notIndexed, `object${vs.notIndexed.n === 1 ? '' : 's'} of the listing in no index of this machine`)}; the backup, the snapshots, the hq's replica and other machines' files never are`, tone: 'dim' })
141
+ } else if (vs != null) out.push({ text: `the listing against the index: not compared (${vs.why})`, tone: 'dim' })
142
+ const vsSpace = r.vsSpace
143
+ if (vsSpace != null && counted(vsSpace)) {
144
+ out.push(vsSpace.lacks.n === 0 ? { text: 'the copy holds every object of the Space\'s last listing', tone: 'ok' } : { text: splitWords(vsSpace.lacks, `object${vsSpace.lacks.n === 1 ? '' : 's'} of the Space the copy lacks`), tone: 'warn' })
145
+ if (vsSpace.only.n > 0) out.push({ text: `${splitWords(vsSpace.only, `object${vsSpace.only.n === 1 ? '' : 's'} at the copy the Space no longer lists`)}; a forget or a purge of versions, the copy never deletes`, tone: 'dim' })
146
+ }
147
+ const v = r.versions
148
+ out.push(counted(v) ? (v.n === 0 ? { text: `no older version kept${v.markers > 0 ? `, ${count(v.markers)} delete markers` : ''}`, tone: 'ok' } : { text: `${splitWords(v, `older version${v.n === 1 ? ' takes' : 's take'} room nobody sees in the list`)}${v.markers > 0 ? `; ${count(v.markers)} delete marker${v.markers === 1 ? '' : 's'}` : ''}`, tone: 'dim' }) : { text: `older versions: not counted (${v.why})`, tone: 'dim' })
149
+ const u = r.uploads
150
+ out.push(counted(u) ? (u.n === 0 ? { text: 'no upload left unfinished', tone: 'ok' } : { text: `${splitWords(u, `upload${u.n === 1 ? '' : 's'} never completed`)}; their parts take room, their size is not counted (a call each)`, tone: 'warn' }) : { text: `unfinished uploads: not counted (${u.why})`, tone: 'dim' })
151
+ }
152
+ if (e.id === 'space') {
153
+ const b = d.backup
154
+ const folder = r == null ? null : d.kept((db) => folderSum(db, e.id, `${BACKUP_LABEL}/`))
155
+ out.push(b == null ? { text: 'the backup: no run from this machine yet', tone: 'dim' } : { text: `the last backup run from this machine: ${ago(Math.max(0, d.now - Date.parse(b.at)))} ago${folder == null ? '' : `; ${BACKUP_LABEL}/ holds ${size(folder.bytes)} in ${count(folder.objects)} objects, every machine's runs`}`, tone: d.now - Date.parse(b.at) > 2 * 86_400_000 ? 'warn' : 'ok' })
156
+ }
157
+ return out
158
+ }
159
+
160
+ /** the top folders from this machine's index, when no listing was kept: what it says is up */
161
+ function indexTop(d: SpacePageDeps): { top: FolderRow[]; loose: { n: number; bytes: number } } {
162
+ const rows = (d.media?.query("select substr(key, 1, instr(key, '/')) as prefix, count(*) as n, coalesce(sum(size), 0) as bytes from media_objects where up is not null group by 1 order by bytes desc").all() ?? []) as { prefix: string; n: number; bytes: number }[]
163
+ const loose = rows.find((r) => r.prefix === '')
164
+ return { top: rows.filter((r) => r.prefix !== '').map((r) => ({ prefix: r.prefix, name: r.prefix, bytes: r.bytes, objects: r.n, what: folderWhat(r.prefix, d) })), loose: { n: loose?.n ?? 0, bytes: loose?.bytes ?? 0 } }
165
+ }
166
+
167
+ function viewOf(e: SpaceEnd, d: SpacePageDeps): SpaceView {
168
+ const r = d.kept((db) => keptListing(db, e.id))
169
+ const why = d.job.why[e.id] ?? null
170
+ const noKey = r == null && why != null && why !== '' ? `this machine does not list ${e.id === 'space' ? 'the Space' : 'the copy'}: ${why}` : null
171
+ const asked = d.job.asked != null && (r == null || d.job.asked > r.at) && d.job.running == null ? d.job.asked : null
172
+ const base = { id: e.id, title: e.bucket, role: ROLE[e.id], running: d.job.running?.at ?? null, asked, noKey, about: aboutFacts(e, r, d), health: healthFacts(e, r, d) }
173
+ if (r == null) {
174
+ const i = e.id === 'space' ? indexTop(d) : { top: [], loose: { n: 0, bytes: 0 } }
175
+ return { ...base, listing: null, ...i, fromIndex: e.id === 'space' }
176
+ }
177
+ const top = d.kept((db) => subFolders(db, e.id, '')) ?? []
178
+ // the objects of no folder: the whole less its folders, no scan of the keys
179
+ const loose = { n: r.objects - top.reduce((n, s) => n + s.objects, 0), bytes: r.bytes - top.reduce((n, s) => n + s.bytes, 0) }
180
+ return { ...base, listing: { at: r.at, ms: r.ms, calls: r.calls, objects: r.objects, bytes: r.bytes, keptBytes: r.keptBytes }, top: top.map((s) => rowOf(s, d)), loose, fromIndex: false }
181
+ }
182
+
183
+ /** the page's data: each Space the house names, what its kept listing says, about and health */
184
+ export function spacePage(d: SpacePageDeps): SpacePage {
185
+ return { at: d.now, machine: d.machine, spaces: d.ends.map((e) => viewOf(e, d)) }
186
+ }
187
+
188
+ /** the repo that holds a store folder, by the longest house path it sits under */
189
+ const repoOfStore = (store: string, repos: SpacePageDeps['repos']): string => repos.filter((r) => store === r.path || store.startsWith(`${r.path}/`)).sort((a, b) => b.path.length - a.path.length)[0]?.name ?? shown(store)
190
+
191
+ const SHA = /[0-9a-f]{64}/
192
+
193
+ /** each listed object with its file's name and who put it: this machine's index by key (a preview by its content),
194
+ * then the hq for what another machine put */
195
+ /** whether the page hands out a link to this object. A snapshot (the vault's sealed one, the hq's whole database) and
196
+ * a part of the backup hold the house's state: their own commands read them, never a click in a browser */
197
+ export const opensFromPage = (key: string): boolean => !key.startsWith(SNAPSHOTS) && !key.startsWith(`${BACKUP_LABEL}/`)
198
+
199
+ export const filesOf = (rows: readonly Listed[], d: Pick<SpacePageDeps, 'media' | 'hq' | 'repos'>): FileRow[] => namedRows(rows, d).map((x) => ({ ...x, opens: opensFromPage(x.key) }))
200
+
201
+ function namedRows(rows: readonly Listed[], d: Pick<SpacePageDeps, 'media' | 'hq' | 'repos'>): Omit<FileRow, 'opens'>[] {
202
+ const keys = JSON.stringify(rows.map((r) => r.key))
203
+ const here = new Map<string, { store: string; name: string }>()
204
+ for (const x of (d.media?.query('select key, store, name from media_files where key in (select value from json_each(?))').all(keys) ?? []) as { key: string; store: string; name: string }[]) if (!here.has(x.key)) here.set(x.key, x)
205
+ const bySha = new Map<string, { store: string; name: string; key: string }>()
206
+ if (d.media != null) {
207
+ const q = d.media.query('select key, store, name from media_files where key >= ? and key < ? limit 1')
208
+ for (const r of rows) {
209
+ const sha = SHA.exec(r.key)?.[0]
210
+ if (sha == null || here.has(r.key) || bySha.has(sha)) continue
211
+ const top = topOf(r.key)
212
+ const hit = q.get(`${top}${sha}`, `${top}${sha}~`) as { key: string; store: string; name: string } | null
213
+ if (hit != null) bySha.set(sha, hit)
214
+ }
215
+ }
216
+ const hq = new Map<string, { repo: string; name: string; node: string }>()
217
+ if (d.hq != null) {
218
+ try {
219
+ for (const x of d.hq.query('select key, repo, name, node from media where key in (select value from json_each(?)) order by at').all(keys) as { key: string; repo: string; name: string; node: string }[]) if (!hq.has(x.key)) hq.set(x.key, x)
220
+ } catch {
221
+ // an hq of older code holds no media table
222
+ }
223
+ }
224
+ return rows.map((r) => {
225
+ const last = r.key.slice(r.key.lastIndexOf('/') + 1)
226
+ const kind = topOf(r.key).slice(0, -1)
227
+ const h = here.get(r.key)
228
+ if (h != null) return { key: r.key, name: h.name, named: true, size: r.size, modified: r.modified, by: `${repoOfStore(h.store, d.repos)} · ${kind}`, from: 'here' }
229
+ const sha = SHA.exec(r.key)?.[0]
230
+ const p = sha == null ? undefined : bySha.get(sha)
231
+ if (p != null) return { key: r.key, name: `${p.name} (${last.slice(64).replace(/^\./, '') || 'a copy'})`, named: true, size: r.size, modified: r.modified, by: `${repoOfStore(p.store, d.repos)} · ${kind}`, from: 'here' }
232
+ const o = hq.get(r.key)
233
+ if (o != null) return { key: r.key, name: o.name, named: true, size: r.size, modified: r.modified, by: `${o.repo === '' ? 'no repo' : o.repo} · ${kind}, put on ${o.node}`, from: 'hq' }
234
+ return { key: r.key, name: last === '' ? '(the folder\'s own marker)' : last, named: false, size: r.size, modified: r.modified, by: null, from: null }
235
+ })
236
+ }
237
+
238
+ /** the rows a folder holds, or the filter's matches over keys and names */
239
+ export const FILES_MAX = 200
240
+
241
+ /** a folder of a Space opened: its sub folders and its files, the biggest first; with `q`, the objects whose key or
242
+ * file name holds its words, anywhere in the Space */
243
+ export function folderPage(d: SpacePageDeps, space: string, prefix: string, q: string): FolderPage {
244
+ const r = d.kept((db) => keptListing(db, space))
245
+ if (r == null) return { space, prefix, q, at: null, folders: [], files: [], n: 0, bytes: 0, more: 0 }
246
+ if (q.trim() !== '') {
247
+ const words = q.toLowerCase().split(/\s+/).filter((w) => w !== '')
248
+ const also = words.length === 0 || d.media == null ? [] : (d.media.query(`select distinct key from media_files where ${words.map(() => 'instr(lower(name), ?) > 0').join(' and ')} limit 5000`).all(...words) as { key: string }[]).map((x) => x.key)
249
+ const found = d.kept((db) => findKeys(db, space, q, also, FILES_MAX)) ?? { files: [], n: 0 }
250
+ const files = filesOf(found.files, d)
251
+ return { space, prefix: '', q, at: r.at, folders: [], files, n: found.n, bytes: files.reduce((n, f) => n + f.size, 0), more: Math.max(0, found.n - files.length) }
252
+ }
253
+ const sum = prefix === '' ? { bytes: r.bytes, objects: r.objects } : d.kept((db) => folderSum(db, space, prefix))
254
+ const folders = (d.kept((db) => subFolders(db, space, prefix)) ?? []).map((s) => rowOf(s, d))
255
+ const own = d.kept((db) => folderFiles(db, space, prefix, FILES_MAX)) ?? { files: [], n: 0, bytes: 0 }
256
+ return { space, prefix, q: '', at: r.at, folders, files: filesOf(own.files, d), n: sum?.objects ?? 0, bytes: sum?.bytes ?? 0, more: Math.max(0, own.n - own.files.length) }
257
+ }
@@ -0,0 +1,167 @@
1
+ // the Space page's routes on the home and its reads on this machine (space-page.ts): the page, a folder opened, a
2
+ // file opened, a listing asked. Every answer is what the job kept; none lists a bucket or reads a secret, but the
3
+ // file's link, which reads the Space's key (held ten minutes) to sign one key the kept listing holds
4
+ import { Database } from 'bun:sqlite'
5
+ import { existsSync } from 'fs'
6
+ import { SIGNED_S } from '../media-store/space.ts'
7
+ import { keptListing, listedSize } from '../media-store/space-listing.ts'
8
+ import { folderPage, opensFromPage, spacePage, filesOf, type SpaceEnd, type SpacePageDeps } from './space-page.ts'
9
+
10
+ /** each Space the house config names: the Space, then its second copy. Its words come from the config alone; its key
11
+ * is read only by `config()` */
12
+ export async function houseEnds(root: string | null): Promise<{ ends: SpaceEnd[]; why: string | null; replica: string | null }> {
13
+ if (root == null) return { ends: [], why: 'no house repo seen from here', replica: null }
14
+ const { loadRepoConfig } = await import('../repo-config.ts')
15
+ const c = await loadRepoConfig(root).catch(() => null)
16
+ const s = c?.serve?.mediaSpace
17
+ if (s == null) return { ends: [], why: `the house config names no serve.mediaSpace`, replica: null }
18
+ const ends: SpaceEnd[] = [
19
+ {
20
+ id: 'space',
21
+ bucket: s.bucket,
22
+ region: s.region,
23
+ origin: s.endpoint,
24
+ cdn: s.cdn ?? null,
25
+ secret: s.secret,
26
+ config: async () => {
27
+ const { houseSpaceConfig } = await import('../media-store/space.ts')
28
+ const h = await houseSpaceConfig()
29
+ return h.config ?? { why: h.why }
30
+ },
31
+ },
32
+ ]
33
+ const copy = c?.serve?.spaceCopy
34
+ if (copy != null) {
35
+ let skip: string[] = []
36
+ ends.push({
37
+ id: 'copy',
38
+ bucket: copy.bucket,
39
+ region: copy.region,
40
+ origin: copy.endpoint ?? `the origin the secret ${copy.endpointSecret ?? '(none named)'} holds`,
41
+ cdn: null,
42
+ secret: copy.secret,
43
+ get skip() {
44
+ return skip
45
+ },
46
+ config: async () => {
47
+ const { houseCopy } = await import('../media-store/copy/config.ts')
48
+ const e = await houseCopy(root)
49
+ if ('why' in e) return { why: e.why }
50
+ skip = e.skip
51
+ return e.to
52
+ },
53
+ })
54
+ }
55
+ const r = c?.serve?.hqReplica
56
+ const replica = r != null && r.bucket === s.bucket ? `${(r.path ?? 'hq').replace(/\/$/, '')}/` : null
57
+ return { ends, why: null, replica }
58
+ }
59
+
60
+ const openRead = (path: string): Database | null => {
61
+ if (!existsSync(path)) return null
62
+ try {
63
+ return new Database(path, { readonly: true })
64
+ } catch {
65
+ return null
66
+ }
67
+ }
68
+
69
+ /** the page's reads on this machine, for the house at `root` */
70
+ export async function spaceDeps(root: string | null, repos: { name: string; path: string }[], now: number = Date.now()): Promise<SpacePageDeps> {
71
+ const [{ machineName }, { machineDb, machineGet }, { mediaDb }, { mediaKinds }, { lastCopyProof }, { lastRun }, hq, { hqDbPath }, job] = await Promise.all([
72
+ import('./machine-host.ts'),
73
+ import('../core/machine-db.ts'),
74
+ import('../media-store/db.ts'),
75
+ import('../media-kinds.ts'),
76
+ import('../media-store/copy/proof.ts'),
77
+ import('../media-store/backup/run.ts'),
78
+ import('../hq/hq-local.ts'),
79
+ import('../hq/hq-db.ts'),
80
+ import('./space-job.ts'),
81
+ ])
82
+ const e = await houseEnds(root)
83
+ const run = machineGet<{ pid: number; at: number }>(job.RUN_KEY)
84
+ const alive = (pid: number): boolean => {
85
+ try {
86
+ process.kill(pid, 0)
87
+ return true
88
+ } catch (x) {
89
+ return (x as { code?: string }).code === 'EPERM'
90
+ }
91
+ }
92
+ return {
93
+ machine: machineName(),
94
+ now,
95
+ ends: e.ends,
96
+ noEnds: e.why,
97
+ kept: (body) => {
98
+ try {
99
+ return machineDb(body)
100
+ } catch {
101
+ return null
102
+ }
103
+ },
104
+ media: mediaDb(),
105
+ hq: hq.carriesHq() ? openRead(hqDbPath()) : null,
106
+ repos,
107
+ kinds: mediaKinds().map((k) => ({ kind: k.kind, ...(k.what == null ? {} : { what: k.what }) })),
108
+ replica: e.replica,
109
+ job: { running: run != null && alive(run.pid) ? { at: run.at } : null, asked: machineGet<number>(job.ASKED_KEY), why: machineGet<Record<string, string>>(job.WHY_KEY) ?? {} },
110
+ proof: lastCopyProof(),
111
+ backup: lastRun(),
112
+ }
113
+ }
114
+
115
+ /** one answer at a time, kept a few seconds: two tabs polling make one read */
116
+ let last: { at: number; v: Promise<unknown> } | null = null
117
+ const TTL_MS = 5_000
118
+ const NO_STORE = { 'cache-control': 'no-store' }
119
+
120
+ type Deps = (fresh: boolean) => Promise<SpacePageDeps>
121
+
122
+ /** `/api/home/space*`: the page (GET), a folder (GET `/ls?space=&prefix=&q=`), a file opened (GET
123
+ * `/file?space=&key=`, a redirect to a link signed for the hour), a listing asked (POST `/list`); null for another path */
124
+ export async function spaceRoute(req: Request, path: string, o: { root: string | null; repos: { name: string; path: string }[]; deps?: Deps; ask?: () => boolean }): Promise<Response | null> {
125
+ if (path !== '/api/home/space' && !path.startsWith('/api/home/space/')) return null
126
+ const deps: Deps = o.deps ?? (() => spaceDeps(o.root, o.repos))
127
+ const u = new URL(req.url)
128
+ try {
129
+ if (path === '/api/home/space' && req.method === 'GET') {
130
+ if (last == null || Date.now() - last.at > TTL_MS || o.deps != null) last = { at: Date.now(), v: deps(false).then(spacePage) }
131
+ return Response.json(await last.v, { headers: NO_STORE })
132
+ }
133
+ if (path === '/api/home/space/ls' && req.method === 'GET') {
134
+ const d = await deps(false)
135
+ return Response.json(folderPage(d, u.searchParams.get('space') ?? 'space', u.searchParams.get('prefix') ?? '', u.searchParams.get('q') ?? ''), { headers: NO_STORE })
136
+ }
137
+ if (path === '/api/home/space/list' && req.method === 'POST') {
138
+ const ok = o.ask != null ? o.ask() : (await import('./space-job.ts')).askListing()
139
+ last = null
140
+ return ok ? Response.json({ asked: true }) : Response.json({ refused: 'the machine db does not open: no listing asked' }, { status: 503 })
141
+ }
142
+ if (path === '/api/home/space/file' && req.method === 'GET') {
143
+ const d = await deps(false)
144
+ const id = u.searchParams.get('space') ?? 'space'
145
+ const key = u.searchParams.get('key') ?? ''
146
+ const end = d.ends.find((e) => e.id === id)
147
+ const listed = end == null ? null : d.kept((db) => (keptListing(db, id) == null ? null : listedSize(db, id, key)))
148
+ if (end == null || listed == null) return Response.json({ refused: 'no such object in the kept listing' }, { status: 404 })
149
+ // a link signed for an hour opens for whoever holds it: only the home's own page, or a typed address, asks for one
150
+ const site = req.headers.get('sec-fetch-site')
151
+ if (site != null && site !== 'same-origin' && site !== 'none') return Response.json({ refused: 'a file opens from the home\'s own page only' }, { status: 403 })
152
+ if (!opensFromPage(key)) return Response.json({ refused: 'a snapshot or a part of the backup does not open from the page: its own command reads it (sk vault, sk hq, sk backup)' }, { status: 403 })
153
+ const c = await end.config()
154
+ if ('why' in c) return Response.json({ refused: `this machine cannot sign a link to it: ${c.why}` }, { status: 503 })
155
+ const { spaceOf } = await import('../media-store/space.ts')
156
+ const { typeOf } = await import('../media-store/content.ts')
157
+ const name = filesOf([{ key, size: listed, modified: null }], d)[0]!.name
158
+ const url = spaceOf(c).signed(key, SIGNED_S, { name, type: typeOf(name), inline: true })
159
+ return new Response(null, { status: 302, headers: { Location: url, 'cache-control': 'no-store' } })
160
+ }
161
+ return Response.json({ refused: `no route ${req.method} ${path}` }, { status: 404 })
162
+ } catch {
163
+ last = null
164
+ return Response.json({ refused: 'the Space page could not be read on this machine: sk space says why' }, { status: 503 })
165
+ }
166
+ }
167
+
@@ -0,0 +1,103 @@
1
+ // the Space page's shape and its words, shared by the home page and `sk space`: pure and browser safe. The constraint
2
+ // a reader breaks first: an answer holds keys, sizes, dates and names; never a signed URL, never a key's secret
3
+ import { ago } from '../hq/machine-notes.ts'
4
+ import { count, size } from './database-words.ts'
5
+ import { factLine, type Fact } from './vault-words.ts'
6
+
7
+ export type { Fact }
8
+
9
+ /** a folder of a Space: its sums under it at any depth, and what it is in words when the code names it */
10
+ export type FolderRow = { prefix: string; name: string; bytes: number; objects: number; what: string | null }
11
+
12
+ /** an object of a Space: its key, the file's name where shipkit knows it, who put it */
13
+ export type FileRow = {
14
+ key: string
15
+ /** the file's own name from the media index (or the hq's), else the key's last part */
16
+ name: string
17
+ /** the name came from an index: the key is said dim beside it */
18
+ named: boolean
19
+ size: number
20
+ modified: number | null
21
+ /** the repo and kind that put it, in words (`orchard · review`), null when no index names it */
22
+ by: string | null
23
+ /** where that comes from: this machine's index, or the hq (another machine put it) */
24
+ from: 'here' | 'hq' | null
25
+ /** the page opens it at a click: false for a snapshot or a part of the backup */
26
+ opens: boolean
27
+ }
28
+
29
+ export type ListingFacts = { at: number; ms: number; calls: number; objects: number; bytes: number; keptBytes: number }
30
+
31
+ /** one Space as the page shows it */
32
+ export type SpaceView = {
33
+ /** `space` the private one, `copy` its second place */
34
+ id: string
35
+ /** the bucket, as the house config names it */
36
+ title: string
37
+ /** what it is, in words */
38
+ role: string
39
+ listing: ListingFacts | null
40
+ /** a listing runs since then, in the daemon's job */
41
+ running: number | null
42
+ /** the refresh button asked a listing then, and none started since */
43
+ asked: number | null
44
+ /** why this machine cannot list it (no key), null when it can */
45
+ noKey: string | null
46
+ /** the top folders, the biggest first; from the media index when no listing was kept (`fromIndex`) */
47
+ top: FolderRow[]
48
+ /** the objects of no folder, at the top */
49
+ loose: { n: number; bytes: number }
50
+ fromIndex: boolean
51
+ about: Fact[]
52
+ health: Fact[]
53
+ }
54
+
55
+ export type SpacePage = { at: number; machine: string; spaces: SpaceView[] }
56
+
57
+ /** a folder opened, or the filter's matches (`q`) */
58
+ export type FolderPage = { space: string; prefix: string; q: string; at: number | null; folders: FolderRow[]; files: FileRow[]; n: number; bytes: number; more: number }
59
+
60
+ /** how long ago a listing ran, the page's top line */
61
+ export function listedWords(v: Pick<SpaceView, 'listing' | 'running' | 'asked' | 'noKey'>, now: number): string {
62
+ if (v.running != null) return `listing now, since ${ago(Math.max(0, now - v.running))}`
63
+ if (v.listing == null) return v.noKey != null ? 'never listed: this machine holds no key to the Space' : v.asked != null ? 'not listed yet: a listing starts within a minute' : 'not listed yet: the daemon lists it within minutes of its start, then once a day'
64
+ const l = `listed ${ago(Math.max(0, now - v.listing.at))} ago`
65
+ return v.asked != null ? `${l}, a new listing starts within a minute` : l
66
+ }
67
+
68
+ /** the whole Space in one line: its size and its count */
69
+ export const totalWords = (l: Pick<ListingFacts, 'objects' | 'bytes'>): string => `${size(l.bytes)} in ${count(l.objects)} object${l.objects === 1 ? '' : 's'}`
70
+
71
+ /** a share of the whole, said under 1% where it rounds to nothing */
72
+ export const shareWords = (part: number, whole: number): string => (whole <= 0 || part <= 0 ? '' : part / whole < 0.005 ? '<1%' : `${Math.round((100 * part) / whole)}%`)
73
+
74
+ /** the page as the console prints it: each Space, its listing, its top folders, its facts */
75
+ export function spaceLines(p: SpacePage, o: { facts?: boolean } = {}): string[] {
76
+ const out: string[] = []
77
+ for (const v of p.spaces) {
78
+ out.push(`${v.title} (${v.role}): ${v.listing == null ? listedWords(v, p.at) : `${totalWords(v.listing)}, ${listedWords(v, p.at)}`}`)
79
+ if (v.noKey != null) out.push(` ${v.noKey}`)
80
+ if (v.listing == null && v.top.length > 0) out.push(' what this machine\'s media index says is up, not the whole Space:')
81
+ const whole = v.listing?.bytes ?? v.top.reduce((n, f) => n + f.bytes, 0)
82
+ const w = Math.max(8, ...v.top.map((f) => f.name.length))
83
+ for (const f of v.top) out.push(` ${f.name.padEnd(w)} ${size(f.bytes).padStart(9)} ${count(f.objects).padStart(8)} ${shareWords(f.bytes, whole).padStart(4)}${f.what == null ? '' : ` ${f.what}`}`)
84
+ if (v.loose.n > 0) out.push(` ${'(no folder)'.padEnd(w)} ${size(v.loose.bytes).padStart(9)} ${count(v.loose.n).padStart(8)}`)
85
+ if (o.facts === true) {
86
+ out.push(' about')
87
+ out.push(...v.about.map((f) => ` ${factLine(f)}`))
88
+ out.push(' health')
89
+ out.push(...v.health.map((f) => ` ${factLine(f)}`))
90
+ }
91
+ }
92
+ return out.map((l) => l.trimEnd())
93
+ }
94
+
95
+ /** a folder as the console prints it: its sub folders, then its files */
96
+ export function folderLines(f: FolderPage): string[] {
97
+ const out = [`${f.q !== '' ? `matching « ${f.q} »` : f.prefix === '' ? 'the top' : f.prefix}: ${size(f.bytes)} in ${count(f.n)} object${f.n === 1 ? '' : 's'}`]
98
+ const w = Math.max(8, ...f.folders.map((x) => x.name.length))
99
+ for (const x of f.folders) out.push(` ${`${x.name}`.padEnd(w)} ${size(x.bytes).padStart(9)} ${count(x.objects).padStart(8)}${x.what == null ? '' : ` ${x.what}`}`)
100
+ for (const x of f.files) out.push(` ${size(x.size).padStart(9)} ${x.modified == null ? ''.padEnd(10) : new Date(x.modified).toISOString().slice(0, 10)} ${x.named ? `${x.name} (${x.key})` : x.key}${x.by == null ? '' : ` ${x.by}`}`)
101
+ if (f.more > 0) out.push(` … and ${count(f.more)} more: sk space ls ${f.prefix} --find <text>`)
102
+ return out
103
+ }