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,79 @@
1
+ // could this machine be made again from the Space alone? One line a thing a resume needs, each with where its copy
2
+ // is and its age, from what the jobs and the drills already recorded: no download and no restore here (the drills
3
+ // stay their own commands). What is not in the Space by design is said as such, never claimed present
4
+ import type { Drill } from '../hq/replica.ts'
5
+ import type { BackupDrill } from '../media-store/backup/restore.ts'
6
+ import type { ProvedRecord, Sent } from '../vault/vault-snapshot.ts'
7
+ import { snapshotHealth } from '../vault/vault-snapshot.ts'
8
+
9
+ const H = 3600_000
10
+ const DAY = 24 * H
11
+ /** a backup run older than this is stale: the daemon runs one within minutes of a change */
12
+ export const RUN_STALE_MS = 26 * H
13
+ /** a drill older than this is stale: the hq's runs once a week */
14
+ export const DRILL_STALE_MS = 8 * DAY
15
+
16
+ export type ResumeState = {
17
+ now: number
18
+ /** the hq's database: null when this machine joined another hq (its copy is checked there) */
19
+ hq: { replica: boolean; drill: Drill | null } | null
20
+ backup: { lastRun: { at: number } | null; drill: BackupDrill | null }
21
+ media: { waiting: number; bytes: number; failing: number }
22
+ /** null when this machine runs no vault */
23
+ vault: { sent: Sent | null; proved: ProvedRecord | null; changed: { stamp: string; at: number } | null; stamp: string | null; deadDisk?: ProvedRecord | null } | null
24
+ }
25
+
26
+ export type ResumeLine = { level: 'ok' | 'warn' | 'fail' | 'note'; text: string; fix?: string }
27
+
28
+ const age = (ms: number): string => (ms < H ? `${Math.round(ms / 60_000)} min` : ms < 2 * DAY ? `${(ms / H).toFixed(1)} h` : `${(ms / DAY).toFixed(1)} days`)
29
+
30
+ export function resumeLines(s: ResumeState): ResumeLine[] {
31
+ const out: ResumeLine[] = []
32
+ if (s.hq == null) out.push({ level: 'note', text: "the hq's database: this machine joined another hq, whose machine holds its copy" })
33
+ else if (!s.hq.replica) out.push({ level: 'fail', text: "the hq's database: no second copy, it is on this disk only", fix: 'serve.hqReplica in repo.config.ts, then sk gp start hq-replica' })
34
+ else if (s.hq.drill == null) out.push({ level: 'warn', text: "the hq's database: its replica runs, and no drill has proved it yet", fix: 'sk hq drill' })
35
+ else if (!s.hq.drill.ok) out.push({ level: 'fail', text: `the hq's database: its replica failed its last drill, ${age(s.now - s.hq.drill.at)} ago: ${s.hq.drill.why}`, fix: 'sk gp restart hq-replica, then sk hq drill' })
36
+ else out.push({ level: s.now - s.hq.drill.at > DRILL_STALE_MS ? 'warn' : 'ok', text: `the hq's database: in its replica (Litestream); last drill passed ${age(s.now - s.hq.drill.at)} ago, ${s.hq.drill.rows} rows (the replica's last write is not recorded: the drill proves it)`, ...(s.now - s.hq.drill.at > DRILL_STALE_MS ? { fix: 'sk hq drill' } : {}) })
37
+ const run = s.backup.lastRun
38
+ if (run == null) out.push({ level: 'fail', text: "this machine's own state: no backup run yet", fix: 'sk backup' })
39
+ else out.push({ level: s.now - run.at > RUN_STALE_MS ? 'warn' : 'ok', text: `this machine's own state, the hq's forgotten rows with it (hq.sqlite.forgotten): in the backup, last run ${age(s.now - run.at)} ago`, ...(s.now - run.at > RUN_STALE_MS ? { fix: 'sk backup' } : {}) })
40
+ const d = s.backup.drill
41
+ if (d == null) out.push({ level: 'warn', text: 'the backup: no drill has restored it yet', fix: 'sk backup drill' })
42
+ else if (d.failed > 0) out.push({ level: 'fail', text: `the backup: its last drill, ${age(s.now - d.at)} ago, did not bring back ${d.failed} of ${d.files} files`, fix: 'sk backup drill' })
43
+ else out.push({ level: s.now - d.at > DRILL_STALE_MS ? 'warn' : 'ok', text: `the backup: last drill restored ${d.restored} of ${d.files} files ${age(s.now - d.at)} ago`, ...(s.now - d.at > DRILL_STALE_MS ? { fix: 'sk backup drill' } : {}) })
44
+ if (s.media.waiting === 0) out.push({ level: 'ok', text: 'the media: every file is up in the Space, none waits' })
45
+ else out.push({ level: 'warn', text: `the media: ${s.media.waiting} files (${(s.media.bytes / 1e6).toFixed(1)} MB) wait to go up${s.media.failing > 0 ? `, ${s.media.failing} failed their last try` : ''}`, fix: 'sk media status' })
46
+ if (s.vault == null) out.push({ level: 'note', text: 'the vault: this machine runs none' })
47
+ else {
48
+ const h = snapshotHealth({ ...s.vault, now: s.now })
49
+ out.push({ level: h.warn.length === 0 ? 'ok' : s.vault.sent == null ? 'fail' : 'warn', text: `the vault: ${h.lines.join('; ')}`, ...(h.warn.length > 0 ? { fix: 'sk vault snapshot --copy, then sk vault snapshot --prove --from-space' } : {}) })
50
+ }
51
+ out.push({ level: 'note', text: "not in the Space, by design: the vault's seal key and its recovery key. They belong in the owner's password manager; this check cannot see a password manager and does not claim they are there" })
52
+ out.push({ level: 'note', text: "not in the Space, by design: the Space's own access key, without which nothing above can be fetched. It belongs in the owner's password manager; a new one is made in the provider's control panel (DigitalOcean: API, Spaces Keys)" })
53
+ return out
54
+ }
55
+
56
+ /** the state of this machine, from the records the jobs and drills wrote, and the vault's stamp: no download */
57
+ export async function resumeHere(root: string, now: number = Date.now()): Promise<ResumeState> {
58
+ const { carriesHq } = await import('../hq/hq-local.ts')
59
+ const { lastDrill } = await import('../hq/replica.ts')
60
+ const { loadRepoConfig } = await import('../repo-config.ts')
61
+ const { lastRun } = await import('../media-store/backup/run.ts')
62
+ const { lastBackupDrill } = await import('../media-store/backup/restore.ts')
63
+ const { waitingCounts } = await import('../media-store/daemon.ts')
64
+ const { vaultInitialised, vaultPlace } = await import('../vault/vault-config.ts')
65
+ const { machineGet } = await import('../core/machine-db.ts')
66
+ const { CHANGED_KEY, DEAD_DISK_KEY, PROVED_KEY, SENT_KEY, vaultStamp } = await import('../vault/vault-snapshot.ts')
67
+ const { minterOf } = await import('../vault/vault-minter.ts')
68
+ const run = lastRun()
69
+ const minter = vaultInitialised() ? minterOf(vaultPlace()) : null
70
+ return {
71
+ now,
72
+ hq: carriesHq() ? { replica: (await loadRepoConfig(root).catch(() => null))?.serve?.hqReplica != null, drill: lastDrill() } : null,
73
+ backup: { lastRun: run == null ? null : { at: Date.parse(run.at) }, drill: lastBackupDrill() },
74
+ media: waitingCounts(),
75
+ vault: vaultInitialised()
76
+ ? { sent: machineGet<Sent>(SENT_KEY), proved: machineGet<ProvedRecord>(PROVED_KEY), changed: machineGet<{ stamp: string; at: number }>(CHANGED_KEY), deadDisk: machineGet<ProvedRecord>(DEAD_DISK_KEY), stamp: minter == null ? null : await vaultStamp(minter).then((x) => x.stamp, () => null) }
77
+ : null,
78
+ }
79
+ }
@@ -20,6 +20,7 @@ import { ensureIdentity } from '../core/identity.ts'
20
20
  import { homedir } from 'os'
21
21
  import { join } from 'path'
22
22
  import { startBeat } from './beat.ts'
23
+ import { startPublishing } from '../core/machine-read.ts'
23
24
  import { childBeat, childLog, daemonPort, homeDir, homePort, homeUp, houseOfIndex, hubBase, publicHome, WORKER_ENV } from './home-paths.ts'
24
25
  import { inboxAddress } from './inbox-shape.ts'
25
26
  import { HomeState } from './home-state.ts'
@@ -27,7 +28,8 @@ import { Hubs } from './hubs.ts'
27
28
  import { Planner } from '../plan/planner.ts'
28
29
  import { machineCatchUp } from '../plan/catch-up.ts'
29
30
  import { serveDaemon } from './serve-daemon.ts'
30
- import { startJobs } from './daemon-jobs.ts'
31
+ import { carriedHq, carriesHq, hqOpen, joinCarriedHq, setHqPort } from '../hq/hq-local.ts'
32
+ import { jobsLimit, startJobs } from './daemon-jobs.ts'
31
33
  import { Widgets } from './widgets.ts'
32
34
  import { machinePublicHost } from './machine-host.ts'
33
35
  import { OtherMacs } from './other-macs.ts'
@@ -42,6 +44,22 @@ const onlyRepos = (): Set<string> | undefined => {
42
44
 
43
45
  export type HomeIo = { print: (l: string) => void; printErr: (l: string) => void }
44
46
 
47
+ /** a daemon that joined no other hq carries one and is its first node (wiki tools/shipkit/hq.md): a failure is
48
+ * said and never stops the daemon, since nothing but the machines page reads the hq yet */
49
+ function joinOwnHq(printErr: (l: string) => void): void {
50
+ if (!carriesHq()) return
51
+ try {
52
+ const store = carriedHq()
53
+ const r = store == null ? { refused: 'its file does not open' } : joinCarriedHq(store, Date.now())
54
+ if ('refused' in r) printErr(`WARN the hq this daemon carries: ${r.refused}`)
55
+ // the owner opened this hq to his other machines (sk hq open): its door again, after a restart
56
+ const d = hqOpen() ? setHqPort(true) : null
57
+ if (d != null && 'refused' in d) printErr(`WARN ${d.refused}`)
58
+ } catch (e) {
59
+ printErr(`WARN the hq this daemon carries: ${(e as Error).message}`)
60
+ }
61
+ }
62
+
45
63
  export async function runDaemon(root: string, io: HomeIo, o: { port?: number } = {}): Promise<number> {
46
64
  const own = o.port ?? daemonPort()
47
65
  // the port a page reaches every hub on: the web's
@@ -132,17 +150,20 @@ export async function runDaemon(root: string, io: HomeIo, o: { port?: number } =
132
150
  otherMacs: () => otherMacs.get(),
133
151
  })
134
152
  io.print(`daemon → http://127.0.0.1:${home.server.port} (the page: http://localhost:${port})`)
153
+ joinOwnHq(io.printErr)
135
154
  // the retention sweep (nothing grows unbound, core/retention.ts), the media store and the backup of the
136
155
  // machine-only state, each a niced child process: never a job's body on this loop (daemon-jobs.ts). A daemon
137
- // limited to some repos (SHIPKIT_DAEMON_ONLY) is a trial and runs none
138
- const jobs = onlyRepos() == null ? startJobs({ cli: CLI, cwd: root, dir: join(dir, 'jobs'), log: childLog(dir, 'daemon'), printErr: io.printErr }) : null
156
+ // limited to some repos (SHIPKIT_DAEMON_ONLY) is a trial and runs none, unless SHIPKIT_DAEMON_JOBS names some
157
+ const jobs = onlyRepos() == null || jobsLimit() != null ? startJobs({ cli: CLI, cwd: root, dir: join(dir, 'jobs'), log: childLog(dir, 'daemon'), printErr: io.printErr }) : null
139
158
  // a job that holds the loop holds every page: each stall is said with the work that overlapped it
140
159
  const stalls = loopWatch.start(io.printErr)
141
160
  // pm tells a starved daemon from a hung one by this beat: it turns with the loop
142
161
  const beat = startBeat(childBeat(dir, 'daemon'))
143
162
  // its memory as a trend: a line only when it moved by a tenth, at most every 10 minutes
144
163
  const memory = new MemoryWatch().start(io.print)
145
- const code = reloadOnOwnCode({ role: 'daemon', entry: fileURLToPath(import.meta.url), busy: () => hubs.busy(), before: () => { stalls(); beat(); memory(); jobs?.stop(); home.stop() }, keep: true, io })
164
+ // the cores in use, smoothed over twenty seconds, for every command that judges the machine
165
+ const cpu = startPublishing()
166
+ const code = reloadOnOwnCode({ role: 'daemon', entry: fileURLToPath(import.meta.url), busy: () => hubs.busy(), before: () => { stalls(); beat(); memory(); cpu(); jobs?.stop(); home.stop() }, keep: true, io })
146
167
  io.print(` ${house.repos.length} repos, state in ${dir}, reloads on ${code.files} lib files`)
147
168
  for (const sig of ['SIGINT', 'SIGTERM'] as const)
148
169
  process.on(sig, () => {
@@ -21,25 +21,38 @@ const RUN_PM = fileURLToPath(import.meta.url)
21
21
 
22
22
  /** how often pm stats what its last read of the house side saw */
23
23
  export const PM_RESCAN_MS = 15_000
24
+ /** the longest wait between two reads of an answer that holds errors */
25
+ export const PM_RETRY_MAX_MS = 10 * 60_000
24
26
 
25
27
  /** pm's reread of the house side: the child runs again only once a stat of
26
28
  * a path the last answer read moved. A few ms of stats per poll, against a
27
29
  * child that imports every unit file */
28
30
  export class PmConfigWatch {
29
31
  private last: PmConfig | null = null
32
+ /** reads in a row that came back with errors, and when the next one is due */
33
+ private failed = 0
34
+ private retryAt = 0
30
35
 
31
36
  constructor(private readonly read: () => Promise<PmConfig>) {}
32
37
 
33
- seed(c: PmConfig): void {
38
+ seed(c: PmConfig, now = Date.now()): void {
34
39
  this.last = c
40
+ this.failed = c.errors.length === 0 ? 0 : 1
41
+ this.retryAt = now + PM_RESCAN_MS
35
42
  }
36
43
 
37
- /** the new answer, or null when nothing it read moved */
38
- async poll(): Promise<PmConfig | null> {
39
- if (this.last != null && stampOf(this.last.inputs) === this.last.stamp) return null
44
+ /** the new answer, or null when nothing it read moved. An answer that holds errors is read again though no input
45
+ * moved, each wait twice the last up to PM_RETRY_MAX_MS: the cause can sit in the lib, which is no input, and an
46
+ * unchanged answer is null */
47
+ async poll(now = Date.now()): Promise<PmConfig | null> {
48
+ const was = this.last
49
+ const moved = was == null || stampOf(was.inputs) !== was.stamp
50
+ if (!moved && (was.errors.length === 0 || now < this.retryAt)) return null
40
51
  const c = await this.read()
41
52
  this.last = c
42
- return c
53
+ this.failed = c.errors.length === 0 ? 0 : moved ? 1 : this.failed + 1
54
+ this.retryAt = now + Math.min(PM_RETRY_MAX_MS, PM_RESCAN_MS * 2 ** (this.failed - 1))
55
+ return !moved && was != null && JSON.stringify([c.errors, c.processes]) === JSON.stringify([was.errors, was.processes]) ? null : c
43
56
  }
44
57
  }
45
58
 
@@ -4,13 +4,28 @@
4
4
  // sees the web origin. A terminal client (via-hub.ts, attach.ts) talks here
5
5
  // directly, so a gate never depends on the web.
6
6
  import { loopWatch } from '../core/loop-watch.ts'
7
+ import { carriedHqRoute } from '../hq/hq-local.ts'
8
+ import { loopbackHost } from '../serve/same-origin.ts'
7
9
  import { homeRoutes, TICK_MS, type HomeDeps } from './home-routes.ts'
8
10
 
9
11
  export function serveDaemon(d: HomeDeps & { daemonPort: number }) {
10
12
  const routes = homeRoutes(d)
11
- const fetch = (req: Request, srv: Bun.Server<unknown>): Promise<Response> =>
12
- loopWatch.spanned(`${req.method} ${new URL(req.url).pathname}`, async () => (await routes.handle(req, srv)) ?? new Response('not found', { status: 404 }))
13
- const server = Bun.serve({ port: d.daemonPort, hostname: '127.0.0.1', fetch })
13
+ const fetch = (req: Request, srv: Bun.Server<unknown>): Promise<Response> | Response =>
14
+ // the web and the terminal clients call the daemon by a loopback name: any other Host is a page of another
15
+ // site rebound to this machine
16
+ !loopbackHost(req) ? new Response(`refused: the daemon answers to a loopback name, never to ${req.headers.get('host') ?? 'a request with no Host'}`, { status: 403 }) :
17
+ // the hq this daemon carries answers its own paths behind its own token (hq/hq-routes.ts), before the home's routes
18
+ loopWatch.spanned(`${req.method} ${new URL(req.url).pathname}`, async () => (await carriedHqRoute(req, new URL(req.url).pathname)) ?? (await routes.handle(req, srv)) ?? new Response('not found', { status: 404 }))
19
+ const server = Bun.serve({
20
+ port: d.daemonPort,
21
+ hostname: '127.0.0.1',
22
+ fetch,
23
+ // a throw is said in the log and never to the caller: with no handler Bun answers a page with the source
24
+ error: (e) => {
25
+ console.error(`WARN the daemon failed a request: ${e.message}`)
26
+ return new Response('the daemon failed this request: its log says why', { status: 500 })
27
+ },
28
+ })
14
29
  let stopped = false
15
30
  let running = false
16
31
  const timer = setInterval(() => {
@@ -10,16 +10,19 @@
10
10
  // port directly, and lets this door through. The host guard runs here too: Bun's dev server, which bundles the page
11
11
  // and drives its hot reload, answers only to a loopback Host, so it sits on a port of its own behind this one, and a
12
12
  // request reaches it only once its Host is a loopback name or this Mac's tailnet name (machine-host.ts)
13
- import { hostName, loopbackName, REACH_HEADER, reachOfHost, sameOrigin } from '../serve/same-origin.ts'
13
+ import { hostName, loopbackName, REACH_HEADER, reachOfCaller, sameOrigin } from '../serve/same-origin.ts'
14
14
  import { hubBase } from './home-paths.ts'
15
15
  import { forwardPage, pagePath } from '../pages/forward.ts'
16
16
  import { statSync } from 'fs'
17
17
  import { HMR_BEAT_MS, HMR_KEEP_SCRIPT, HMR_WORDS } from './hmr-keep.ts'
18
+ import { broughtByProxy, crossSiteRefusal, DOOR_KEY_HEADER, DOOR_PATH, doorHostOf, doorKeyFor, doorPathOf, doorPolicy, foreignOrigin, forwardHop, loginHop, protocolsOf, urlHostOf, urlPolicy, wsUrl } from '../serve/door-forward.ts'
19
+ import type { DoorTarget } from '../hq/door.ts'
20
+ import type { UrlLogin } from '../urls/frame.ts'
18
21
 
19
22
  /** the page routes: ONE app for the overview, the plan, and the hub page of
20
23
  * each known repo, which moves between them in place (home-st.ts) */
21
24
  export function pageRoutes<T>(names: string[], page: T): Record<string, T> {
22
- const out: Record<string, T> = { '/': page, '/inbox': page, '/planned': page, '/activity': page, '/archived': page, '/insights': page, '/recordings': page, '/identities': page }
25
+ const out: Record<string, T> = { '/': page, '/inbox': page, '/machines': page, '/database': page, '/vault': page, '/space': page, '/planned': page, '/activity': page, '/archived': page, '/insights': page, '/time': page, '/recordings': page, '/identities': page }
23
26
  for (const n of names) out[`${hubBase(n)}/`] = page
24
27
  return out
25
28
  }
@@ -58,8 +61,8 @@ export const LIST_RETRY_MS = 1_000
58
61
  /** how long the web keeps a repo's page urls before it asks the daemon again */
59
62
  export const PAGE_URLS_MS = 10_000
60
63
 
61
- /** the home answers that can wait on git: the activity page's first read of a window, a repo's git page, and the insights page's read of every manifest */
62
- export const readsGit = (path: string): boolean => path === '/api/home/activity.json' || path === '/api/home/git.json' || path === '/api/home/insights.json'
64
+ /** the home answers that can wait on git or on a child: the activity page's first read of a window, a repo's git page, the insights page's read of every manifest, the time page's report */
65
+ export const readsGit = (path: string): boolean => path === '/api/home/activity.json' || path === '/api/home/git.json' || path === '/api/home/insights.json' || path === '/api/home/time.json'
63
66
 
64
67
  /** a run or a check run streams for minutes, and a silent one is never cut */
65
68
  export const streams = (path: string): boolean => /\/api\/(run|check\/run)$/.test(path)
@@ -202,11 +205,46 @@ export type WebDeps<T> = {
202
205
  /** the files of the page's bundle: a page back on the hot reload socket after a gap reloads only when one moved.
203
206
  * Without them it always reloads */
204
207
  pageFiles?: () => Iterable<string>
208
+ /** the door's two lookups, in place of asking the daemon (a test) */
209
+ door?: DoorAsk
205
210
  }
206
211
 
212
+ /** a refusal of the door: its words and its status */
213
+ export type DoorRefused = { refused: string; status: number }
214
+ /** where the door sends a request: on the hq's machine, a process of a machine; on any machine, its own process, and
215
+ * a declared url with the login its hop adds */
216
+ export type DoorAsk = { target(machine: string, process: string): Promise<DoorTarget | DoorRefused>; local(id: string, key: string | null): Promise<{ origin: string } | DoorRefused>; url(repo: string, id: string): Promise<UrlLogin | DoorRefused> }
217
+
218
+ /** how long the web keeps a url's login: a framed page asks dozens of files at once, the daemon reads it once */
219
+ export const URL_LOGIN_MS = 10_000
220
+
221
+ /** the door's lookups as the daemon answers them (hq/door-route.ts), never through the proxy: a page never asks them */
222
+ export function daemonDoor(daemon: string): DoorAsk {
223
+ const ask = async <T>(path: string, headers: Record<string, string> = {}): Promise<T | DoorRefused> => {
224
+ try {
225
+ const r = await fetch(`${daemon}${path}`, { headers, signal: AbortSignal.timeout(MACHINE_ANSWER_MS) })
226
+ const j = (await r.json().catch(() => ({ refused: `the daemon answers ${r.status}` }))) as T | { refused: string }
227
+ return r.ok ? (j as T) : { refused: (j as { refused?: string }).refused ?? `the daemon answers ${r.status}`, status: r.status }
228
+ } catch (e) {
229
+ return { refused: daemonDownText(daemon, (e as Error).message), status: 502 }
230
+ }
231
+ }
232
+ return {
233
+ target: (machine, process) => ask<DoorTarget>(`/api/home/door/target?${new URLSearchParams({ machine, process })}`),
234
+ local: (id, key) => ask<{ origin: string }>(`/api/home/door/local?${new URLSearchParams({ id })}`, key == null ? {} : { [DOOR_KEY_HEADER]: key }),
235
+ url: (repo, id) => ask<UrlLogin>(`/api/home/door/url?${new URLSearchParams({ repo, id })}`),
236
+ }
237
+ }
238
+
239
+ /** a close code one side may send again: a reserved one (no status, an abnormal end, a tls failure) reads as normal */
240
+ const sendableClose = (c: number): number => ((c >= 1000 && c <= 1003) || (c >= 1007 && c <= 1014) || (c >= 3000 && c <= 4999) ? c : 1000)
241
+
242
+ const doorText = (text: string, status: number): Response => new Response(text, { status, headers: { 'content-type': 'text/plain; charset=utf-8', 'cache-control': 'no-store' } })
243
+
207
244
  /** one browser socket to the page server's hot reload, piped to the same path there. `since`: the last time a socket
208
- * that came back heard this web, null on a page's first socket */
209
- type Pipe = { path: string; up: WebSocket | null; queue: (string | Uint8Array<ArrayBuffer>)[]; since: number | null }
245
+ * that came back heard this web, null on a page's first socket. `door`: a socket through the door instead, piped to
246
+ * that url with those headers */
247
+ type Pipe = { path: string; up: WebSocket | null; queue: (string | Uint8Array<ArrayBuffer>)[]; since: number | null; door?: { url: string; headers: Record<string, string>; protocols: string[] } }
210
248
 
211
249
  export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
212
250
  let known = ''
@@ -252,7 +290,7 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
252
290
  const headers = new Headers()
253
291
  req.headers.forEach((v, k) => { if (!DROP.has(k)) headers.set(k, v) })
254
292
  // set after the copy, so a value the browser sent never passes
255
- headers.set(REACH_HEADER, reachOfHost(req.headers.get('host')))
293
+ headers.set(REACH_HEADER, reachOfCaller(req))
256
294
  // a run or a live stream can stay silent for minutes
257
295
  srv.timeout(req, 0)
258
296
  const body = req.method === 'GET' || req.method === 'HEAD' ? undefined : await req.arrayBuffer()
@@ -337,6 +375,8 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
337
375
  out.delete('content-length')
338
376
  out.delete('transfer-encoding')
339
377
  out.delete('connection')
378
+ // a page of another site never frames the home: it would frame a url's hop with the hub's own Referer
379
+ out.set('content-security-policy', "frame-ancestors 'self'")
340
380
  const type = out.get('content-type') ?? ''
341
381
  if (r.status === 200 && type.startsWith('text/html')) {
342
382
  const page = new Response(r.body, { status: r.status, headers: out })
@@ -362,11 +402,126 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
362
402
  return new Response(zipped, { status: 200, headers: out })
363
403
  }
364
404
 
405
+ const doorAsk = d.door ?? daemonDoor(d.daemon)
406
+ const upgrading = (req: Request): boolean => req.headers.get('upgrade')?.toLowerCase() === 'websocket'
407
+
408
+ /** a socket through the door: the browser's upgraded here, the same path opened at `url` */
409
+ function doorSocket(req: Request, srv: Bun.Server<Pipe>, url: string, headers: Record<string, string>, answer: Record<string, string> = {}): Response | undefined {
410
+ const protocols = protocolsOf(req)
411
+ const ok = srv.upgrade(req, { data: { path: '', up: null, queue: [], since: null, door: { url, headers, protocols } }, headers: { ...answer, ...(protocols[0] == null ? {} : { 'sec-websocket-protocol': protocols[0] }) } })
412
+ return ok ? undefined : doorText('the socket through the door did not open', 400)
413
+ }
414
+
415
+ /** `<process>.<machine>.localhost` on the hq's machine: that process, wherever the hq says it runs. Every answer
416
+ * under that name carries the door's content policy, added here last beside the process's own */
417
+ async function toDoor(req: Request, at: { process: string; machine: string }, srv: Bun.Server<Pipe>): Promise<Response | undefined> {
418
+ const host = (req.headers.get('host') ?? '').toLowerCase()
419
+ const policy = doorPolicy(host)
420
+ const r = await throughDoor(req, at, srv, host, policy)
421
+ if (r === undefined) return r
422
+ // beside the process's own, never in its place: the browser applies each policy, the stricter wins on each
423
+ const headers = new Headers(r.headers)
424
+ headers.append('content-security-policy', policy)
425
+ return new Response(r.body, { status: r.status, statusText: r.statusText, headers })
426
+ }
427
+
428
+ async function throughDoor(req: Request, at: { process: string; machine: string }, srv: Bun.Server<Pipe>, host: string, policy: string): Promise<Response | undefined> {
429
+ // a request a proxy brought (tailscale serve, from a device of the tailnet) never reaches the door
430
+ if (broughtByProxy(req)) return doorText('not found: the door answers on the machine that carries the hq only', 404)
431
+ const t = await doorAsk.target(at.machine, at.process)
432
+ if ('refused' in t) return doorText(`not found: ${t.refused}`, t.status === 502 ? 502 : 404)
433
+ const own = `http://${host}`
434
+ const foreign = foreignOrigin(req, own)
435
+ if (foreign != null) return doorText(foreign, 403)
436
+ const url = new URL(req.url)
437
+ const base = t.hop == null ? t.origin : `${t.hop.base}${DOOR_PATH}${at.process}`
438
+ const key = t.hop == null ? null : doorKeyFor(t.hop.node)
439
+ if (t.hop != null && key == null) return doorText('not found: the hq has no door secret yet: sk hq proxy on, then a report of that machine', 404)
440
+ if (upgrading(req)) return doorSocket(req, srv, wsUrl(base, `${url.pathname}${url.search}`), { origin: t.origin, ...(key == null ? {} : { [DOOR_KEY_HEADER]: key }) }, { 'content-security-policy': policy })
441
+ return forwardHop(req, `${base}${url.pathname}${url.search}`, { target: t.origin, own, key, srv })
442
+ }
443
+
444
+ /** each url name's login as the daemon gave it, kept URL_LOGIN_MS: one lookup for a burst of requests */
445
+ const urlLogins = new Map<string, { at: number; p: Promise<UrlLogin | DoorRefused> }>()
446
+ function urlLoginOf(repo: string, id: string): Promise<UrlLogin | DoorRefused> {
447
+ const key = `${repo}/${id}`
448
+ const held = urlLogins.get(key)
449
+ if (held != null && Date.now() - held.at < URL_LOGIN_MS) return held.p
450
+ const p = doorAsk.url(repo, id)
451
+ urlLogins.set(key, { at: Date.now(), p })
452
+ return p
453
+ }
454
+
455
+ /** each url name whose site took its login, by the declared origin and login it took: the login then goes at once.
456
+ * Server memory only; a refusal or another declaration forgets it */
457
+ const tookLogin = new Map<string, string>()
458
+
459
+ /** `<url id>--<repo>.localhost` on this Mac: that declared url, framed, its basic login added when the site asks it.
460
+ * Every answer under that name carries the url policy, added last beside the site's own */
461
+ async function toUrl(req: Request, at: { id: string; repo: string }, srv: Bun.Server<Pipe>): Promise<Response | undefined> {
462
+ const host = (req.headers.get('host') ?? '').toLowerCase()
463
+ const policy = urlPolicy(host)
464
+ const r = await throughUrl(req, at, srv, host, policy)
465
+ if (r === undefined) return r
466
+ const headers = new Headers(r.headers)
467
+ headers.append('content-security-policy', policy)
468
+ return new Response(r.body, { status: r.status, statusText: r.statusText, headers })
469
+ }
470
+
471
+ async function throughUrl(req: Request, at: { id: string; repo: string }, srv: Bun.Server<Pipe>, host: string, policy: string): Promise<Response | undefined> {
472
+ // the tailnet reaches the home through a proxy: a login is added for this Mac's own browser alone
473
+ if (broughtByProxy(req)) return doorText('not found: a url framed with its login answers on the Mac that serves the hub only', 404)
474
+ // a navigation another site started is a 204: the browser stays where it was, so no document of this origin
475
+ // is left for that site (its favicon would then be a same origin request)
476
+ const cross = crossSiteRefusal(req)
477
+ if (cross != null) return req.headers.get('sec-fetch-mode') === 'navigate' ? new Response(null, { status: 204, headers: { 'cache-control': 'no-store' } }) : doorText(cross, 403)
478
+ const own = `http://${host}`
479
+ const foreign = foreignOrigin(req, own)
480
+ if (foreign != null) return doorText(foreign, 403)
481
+ const t = await urlLoginOf(at.repo, at.id)
482
+ if ('refused' in t) return doorText(`not found: ${t.refused}`, t.status === 502 ? 502 : 404)
483
+ const url = new URL(req.url)
484
+ const key = `${at.repo}/${at.id}`
485
+ const declared = `${t.origin}\n${t.authorization ?? ''}`
486
+ const atOnce = t.authorization != null && tookLogin.get(key) === declared
487
+ if (upgrading(req)) {
488
+ const ws = wsUrl(t.origin, `${url.pathname}${url.search}`)
489
+ if (!loginHop(ws, t.origin)) return doorText('refused: a hop goes to the origin its repo declares', 403)
490
+ // a socket follows the http rule: its own authorization kept, the login only once the site took it
491
+ const auth = req.headers.get('authorization') ?? (atOnce ? t.authorization : null)
492
+ const cookie = req.headers.get('cookie')
493
+ return doorSocket(req, srv, ws, { origin: t.origin, ...(auth == null ? {} : { authorization: auth }), ...(cookie == null ? {} : { cookie }) }, { 'content-security-policy': policy })
494
+ }
495
+ const took = (yes: boolean): void => {
496
+ if (yes) tookLogin.set(key, declared)
497
+ else tookLogin.delete(key)
498
+ }
499
+ return forwardHop(req, `${t.origin}${url.pathname}${url.search}`, { target: t.origin, own, site: { login: t.authorization, atOnce, took }, srv })
500
+ }
501
+
502
+ /** `/door/<id>/<rest>` on any machine: its own process, for the hq's home and its key alone */
503
+ async function ownDoor(req: Request, url: URL, srv: Bun.Server<Pipe>): Promise<Response | undefined> {
504
+ const at = doorPathOf(url.pathname)
505
+ if (at == null) return doorText('not found: a door is /door/<process id>/', 404)
506
+ const t = await doorAsk.local(at.id, req.headers.get(DOOR_KEY_HEADER))
507
+ if ('refused' in t) return doorText(`not found: ${t.refused}`, t.status === 502 ? 502 : 404)
508
+ const foreign = foreignOrigin(req, t.origin)
509
+ if (foreign != null) return doorText(foreign, 403)
510
+ if (upgrading(req)) return doorSocket(req, srv, wsUrl(t.origin, `${at.rest}${url.search}`), { origin: t.origin })
511
+ return forwardHop(req, `${t.origin}${at.rest}${url.search}`, { target: t.origin, own: null, srv })
512
+ }
513
+
365
514
  const fetchFn = async (req: Request, srv: Bun.Server<Pipe>): Promise<Response | undefined> => {
366
515
  const host = req.headers.get('host')
367
516
  if (!hostAllowed(host, hosts)) return new Response(hostRefusedText(host), { status: 403, headers: { 'content-type': 'text/plain; charset=utf-8' } })
517
+ // a door's own name is never a page of the home: none of the home's routes answers under it
518
+ const named = urlHostOf(host)
519
+ if (named != null) return toUrl(req, named, srv)
520
+ const door = doorHostOf(host)
521
+ if (door != null) return toDoor(req, door, srv)
368
522
  const url = new URL(req.url)
369
523
  const path = url.pathname
524
+ if (path.startsWith(DOOR_PATH)) return ownDoor(req, url, srv)
370
525
  if (path === '/_bun/hmr' && req.headers.get('upgrade')?.toLowerCase() === 'websocket') {
371
526
  const since = url.searchParams.get('since')
372
527
  url.searchParams.delete('since')
@@ -405,6 +560,19 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
405
560
  fetch: fetchFn,
406
561
  websocket: {
407
562
  open(ws) {
563
+ const door = ws.data.door
564
+ if (door != null) {
565
+ const up = new WebSocket(door.url, { headers: door.headers, protocols: door.protocols } as never)
566
+ up.binaryType = 'arraybuffer'
567
+ ws.data.up = up
568
+ up.onopen = () => {
569
+ for (const m of ws.data.queue.splice(0)) up.send(m)
570
+ }
571
+ up.onmessage = (e) => void ws.send(e.data as string | ArrayBuffer)
572
+ up.onclose = (e) => ws.close(sendableClose(e.code))
573
+ up.onerror = () => ws.close(1011)
574
+ return
575
+ }
408
576
  hmrSockets.add(ws)
409
577
  ws.send(`${HMR_WORDS.beat}${Date.now()}`)
410
578
  ws.send(`${HMR_WORDS.head}${HEAD_STAMP}`)
@@ -0,0 +1,115 @@
1
+ // the daemon's job `space listing` (daemon-jobs.ts): each Space the house names listed whole, in a child, and kept
2
+ // in the machine db (media-store/space-listing.ts), at most once a day by itself and at once when the page's
3
+ // refresh asks. A look of the daemon is three rows of the machine db.
4
+ //
5
+ // The constraint a reader breaks first: every call here is a GET of a listing or of the bucket's settings. The job
6
+ // never puts, copies or deletes, and a Space it cannot list keeps its last listing and says why
7
+ import type { Database } from 'bun:sqlite'
8
+ import { machineDb, machineGet, machineSet } from '../core/machine-db.ts'
9
+ import { readLifecycle } from '../media-store/copy/lifecycle.ts'
10
+ import { signedCall, type SpaceConfig } from '../media-store/space.ts'
11
+ import { keepListing, listObjects, listUploads, listVersions, ruleWords, splitOf, type Counted, type Listed, type ListingRecord, type Split } from '../media-store/space-listing.ts'
12
+ import type { SpaceEnd } from './space-page.ts'
13
+
14
+ /** a listing by itself this often at most */
15
+ export const LIST_EVERY_MS = 86_400_000
16
+ /** the listing that runs: its pid and since when */
17
+ export const RUN_KEY = 'space-listing-run'
18
+ /** when the page's refresh asked a listing */
19
+ export const ASKED_KEY = 'space-listing-asked'
20
+ /** when the job last started a listing, whatever came of it */
21
+ export const TRIED_KEY = 'space-listing-tried'
22
+ /** why each Space could not be listed at the last try, '' when it was */
23
+ export const WHY_KEY = 'space-listing-why'
24
+
25
+ /** due when the page asked since the last try, or the last try is a day old */
26
+ export function spaceListingDue(now: number, get: <T>(k: string) => T | null = machineGet): boolean {
27
+ const tried = get<number>(TRIED_KEY) ?? 0
28
+ return (get<number>(ASKED_KEY) ?? 0) > tried || now - tried >= LIST_EVERY_MS
29
+ }
30
+
31
+ /** the refresh button: the next look of the daemon starts a listing */
32
+ export const askListing = (now: number = Date.now()): boolean => machineSet(ASKED_KEY, now)
33
+
34
+ const fail = (e: unknown): { why: string } => ({ why: (e as Error).message.slice(0, 300) })
35
+
36
+ /** the bucket's versioning, one GET */
37
+ async function versioningOf(c: SpaceConfig): Promise<'Enabled' | 'Suspended' | 'off'> {
38
+ const s = /<Status>([^<]+)<\/Status>/.exec(await signedCall(c, 'GET', null, { versioning: '' }))?.[1]
39
+ return s === 'Enabled' || s === 'Suspended' ? s : 'off'
40
+ }
41
+
42
+ /** the listing against the machine's media index: what the index says is up and the listing lacks, what the listing
43
+ * holds and no row of the index names (an object the index derives, a preview, is named by media_objects). `since`:
44
+ * when the listing started; an object sent up from then on may sit behind the page already read, so it is not missing */
45
+ export function againstIndex(rows: readonly Listed[], media: Database | null, since: number): Counted<{ upNotListed: Split; notIndexed: Split }> {
46
+ if (media == null) return { why: 'the media index does not open' }
47
+ const listed = new Set(rows.map((r) => r.key))
48
+ const up = media.query('select key, size, up from media_objects where up is not null').all() as { key: string; size: number; up: number }[]
49
+ const known = new Set(up.map((u) => u.key))
50
+ for (const f of media.query('select key from media_files').all() as { key: string }[]) known.add(f.key)
51
+ return { upNotListed: splitOf(up.filter((u) => u.up < since && !listed.has(u.key))), notIndexed: splitOf(rows.filter((r) => !known.has(r.key))) }
52
+ }
53
+
54
+ const under = (key: string, prefixes: readonly string[]): boolean => prefixes.some((p) => key.startsWith(p))
55
+
56
+ /** the copy against the Space, both just listed */
57
+ export function againstSpace(space: readonly Listed[], copy: readonly Listed[], skip: readonly string[]): { lacks: Split; only: Split } {
58
+ const s = new Set(space.map((r) => r.key))
59
+ const c = new Set(copy.map((r) => r.key))
60
+ return { lacks: splitOf(space.filter((r) => !c.has(r.key) && !under(r.key, skip))), only: splitOf(copy.filter((r) => !s.has(r.key) && !under(r.key, ['_snapshots/']))) }
61
+ }
62
+
63
+ export type Listing = { record: ListingRecord; rows: Listed[] }
64
+
65
+ /** one Space listed whole: its objects, its older versions, its unfinished uploads, its versioning and rules. Only
66
+ * the objects' listing is the truth: a part that fails is « not counted » with its reason */
67
+ export async function listOne(id: string, c: SpaceConfig, clock: () => number = () => performance.now(), now: () => number = Date.now): Promise<Listing> {
68
+ const t0 = clock()
69
+ const at = now()
70
+ const o = await listObjects(c)
71
+ let calls = o.calls
72
+ const v = await listVersions(c).then((x) => ((calls += x.calls), x.versions), fail)
73
+ const u = await listUploads(c).then((x) => ((calls += x.calls), x.uploads), fail)
74
+ const versioning = await versioningOf(c).then((x) => (calls++, x), fail)
75
+ const lifecycle = await readLifecycle(c).then((x) => (calls++, x == null ? null : x.map(ruleWords)), fail)
76
+ const record = { space: id, at, ms: Math.round(clock() - t0), calls, objects: 0, bytes: 0, versions: v, uploads: u, versioning, lifecycle, keptBytes: 0 }
77
+ return { record, rows: o.rows }
78
+ }
79
+
80
+ /** every Space the house names listed and kept; each one's reason when it could not be */
81
+ export async function spaceListingTick(o: { ends: SpaceEnd[]; media: Database | null; keep?: <R>(body: (db: Database) => R) => R; print: (l: string) => void; printErr: (l: string) => void; now?: () => number }): Promise<Record<string, string>> {
82
+ const now = o.now ?? Date.now
83
+ const keep = o.keep ?? machineDb
84
+ machineSet(TRIED_KEY, now())
85
+ machineSet(RUN_KEY, { pid: process.pid, at: now() })
86
+ const why: Record<string, string> = {}
87
+ try {
88
+ let space: Listed[] | null = null
89
+ for (const e of o.ends) {
90
+ const c = await e.config()
91
+ if ('why' in c) {
92
+ why[e.id] = c.why
93
+ continue
94
+ }
95
+ try {
96
+ const l = await listOne(e.id, c, undefined, now)
97
+ if (e.id === 'space') {
98
+ l.record.vsIndex = againstIndex(l.rows, o.media, l.record.at)
99
+ space = l.rows
100
+ }
101
+ if (e.id === 'copy' && space != null) l.record.vsSpace = againstSpace(space, l.rows, e.skip ?? [])
102
+ const kept = keep((db) => keepListing(db, l.record, l.rows))
103
+ why[e.id] = ''
104
+ o.print(`ok: space listing ${e.id}: ${kept.objects} objects, ${(kept.bytes / 1e9).toFixed(2)} GB, ${kept.calls} calls in ${(kept.ms / 1000).toFixed(1)} s`)
105
+ } catch (x) {
106
+ why[e.id] = fail(x).why
107
+ o.printErr(`WARN space listing ${e.id}: ${why[e.id]}; the last listing is kept`)
108
+ }
109
+ }
110
+ } finally {
111
+ machineSet(WHY_KEY, why)
112
+ machineSet(RUN_KEY, null)
113
+ }
114
+ return why
115
+ }