rvlib-shipkit 2.26.0 → 2.28.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 (605) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/package.json +1 -1
  3. package/src/agent-time/diet.ts +77 -0
  4. package/src/agent-time/family.ts +72 -0
  5. package/src/agent-time/hooks.ts +16 -7
  6. package/src/agent-time/limits.ts +44 -0
  7. package/src/agent-time/live.ts +12 -8
  8. package/src/agent-time/mask.ts +96 -18
  9. package/src/agent-time/refused.ts +45 -0
  10. package/src/agent-time/registry.ts +289 -0
  11. package/src/agent-time/render.ts +122 -21
  12. package/src/agent-time/report-cache.ts +57 -0
  13. package/src/agent-time/report.ts +314 -40
  14. package/src/agent-time/shape.ts +50 -3
  15. package/src/agent-time/store.ts +322 -101
  16. package/src/agent-time/timeline.ts +140 -21
  17. package/src/agent-time/turns.ts +18 -8
  18. package/src/annex/born.ts +2 -2
  19. package/src/annex/offload.ts +29 -17
  20. package/src/annex/tidy.ts +70 -10
  21. package/src/asks/ask-after.ts +44 -0
  22. package/src/asks/ask-bar-fold.ts +57 -0
  23. package/src/asks/ask-migrate.ts +280 -0
  24. package/src/asks/ask-steps-fold.ts +166 -0
  25. package/src/asks/ask-store.ts +586 -0
  26. package/src/assets/kit-config.ts +7 -3
  27. package/src/assets/kits/identity-kit.ts +361 -14
  28. package/src/assets/kits/poster-thumbnail.ts +282 -0
  29. package/src/check.ts +3 -1
  30. package/src/checks/SK003-claude-md-shape.check.ts +92 -25
  31. package/src/checks/SK004-gitignore-policy.check.ts +20 -9
  32. package/src/checks/SK013-one-way-in-policy.check.ts +18 -3
  33. package/src/checks/SK026-asks-autoclose.check.ts +9 -23
  34. package/src/checks/SK028-readme.check.ts +7 -66
  35. package/src/checks/SK030-cache-audit.check.ts +6 -1
  36. package/src/checks/SK031-trace-audit.check.ts +2 -0
  37. package/src/checks/SK033-global-contribution.check.ts +3 -1
  38. package/src/checks/SK035-public-clean.check.ts +2 -2
  39. package/src/checks/SK038-speaks-as.check.ts +3 -3
  40. package/src/checks/SK042-post-kinds.check.ts +26 -24
  41. package/src/checks/SK043-scratch-on-the-mac.check.ts +59 -4
  42. package/src/checks/SK047-login-in-description.check.ts +36 -0
  43. package/src/checks/SK048-one-local-file.check.ts +36 -0
  44. package/src/checks/SK049-thread-answers-hook.check.ts +81 -0
  45. package/src/checks/SK050-retired-commands.check.ts +127 -0
  46. package/src/cli/cmd_Asks.ts +244 -27
  47. package/src/cli/cmd_Backup.ts +153 -10
  48. package/src/cli/cmd_Calls.ts +1 -0
  49. package/src/cli/cmd_Capacity.ts +2 -2
  50. package/src/cli/cmd_Commands.ts +140 -34
  51. package/src/cli/cmd_Contracts.ts +1 -0
  52. package/src/cli/cmd_CrossRepoActivity.ts +5 -4
  53. package/src/cli/cmd_Db.ts +253 -0
  54. package/src/cli/cmd_History.ts +212 -0
  55. package/src/cli/cmd_Home.ts +31 -3
  56. package/src/cli/cmd_Hq.ts +516 -0
  57. package/src/cli/cmd_Keys.ts +1 -0
  58. package/src/cli/cmd_Lanes.ts +15 -4
  59. package/src/cli/cmd_Machines.ts +36 -0
  60. package/src/cli/cmd_Media.ts +38 -6
  61. package/src/cli/cmd_Messages.ts +152 -1
  62. package/src/cli/cmd_Needs.ts +1 -0
  63. package/src/cli/cmd_Reflect.ts +23 -2
  64. package/src/cli/cmd_Review.ts +1357 -223
  65. package/src/cli/cmd_Secret.ts +295 -24
  66. package/src/cli/cmd_Social.ts +113 -28
  67. package/src/cli/cmd_SocialDrafts.ts +235 -0
  68. package/src/cli/cmd_Sound.ts +22 -1
  69. package/src/cli/cmd_Space.ts +324 -0
  70. package/src/cli/cmd_Start.ts +3 -2
  71. package/src/cli/cmd_ThreadHolds.ts +34 -0
  72. package/src/cli/cmd_ThreadKinds.ts +146 -0
  73. package/src/cli/cmd_ThreadReflect.ts +83 -0
  74. package/src/cli/cmd_ThreadSyncNeeds.ts +62 -0
  75. package/src/cli/cmd_Time.ts +76 -5
  76. package/src/cli/cmd_Tmp.ts +28 -4
  77. package/src/cli/cmd_Trailer.ts +14 -10
  78. package/src/cli/cmd_Urls.ts +56 -0
  79. package/src/cli/cmd_Vault.ts +583 -0
  80. package/src/cli/cmd_When.ts +1 -0
  81. package/src/cli/family-help.ts +5 -3
  82. package/src/cli/family-pages.ts +1 -1
  83. package/src/cli/kit/builtins.ts +1 -0
  84. package/src/cli/kit/verb.ts +6 -2
  85. package/src/cli/registry.ts +44 -4
  86. package/src/cli.ts +5 -2
  87. package/src/collections/actions.ts +42 -41
  88. package/src/collections/collection-types.ts +30 -4
  89. package/src/collections/md-body.ts +5 -3
  90. package/src/collections/pings.ts +13 -6
  91. package/src/collections/providers.ts +147 -61
  92. package/src/collections/reflections.ts +9 -4
  93. package/src/collections/review.ts +4 -4
  94. package/src/contracts/contract-manifests.ts +6 -5
  95. package/src/contracts/contract-types.ts +6 -4
  96. package/src/contracts/contracts-engine.ts +11 -0
  97. package/src/contracts/manifests/chrome-web-store.contract.ts +31 -0
  98. package/src/core/budget.ts +12 -17
  99. package/src/core/capacity.ts +27 -18
  100. package/src/core/check-runner.ts +7 -4
  101. package/src/core/discover-checks.ts +18 -3
  102. package/src/core/git.ts +31 -0
  103. package/src/core/house-layout.ts +17 -0
  104. package/src/core/layout.ts +13 -5
  105. package/src/core/locked-write.ts +4 -1
  106. package/src/core/machine-busy.ts +127 -0
  107. package/src/core/machine-commit.ts +6 -1
  108. package/src/core/machine-db.ts +370 -20
  109. package/src/core/machine-layout.ts +137 -0
  110. package/src/core/machine-read.ts +81 -0
  111. package/src/core/migrate-layout.ts +9 -11
  112. package/src/core/one-way-in-policy.ts +64 -7
  113. package/src/core/polling-policy.ts +27 -0
  114. package/src/core/retention.ts +16 -2
  115. package/src/core/scope.ts +107 -14
  116. package/src/core/slots.ts +5 -4
  117. package/src/drill/clean.ts +25 -1
  118. package/src/drill/run.ts +1 -1
  119. package/src/drill/seal.ts +27 -4
  120. package/src/home/activity-shape.ts +2 -0
  121. package/src/home/activity.ts +59 -3
  122. package/src/home/app-sign.ts +15 -4
  123. package/src/home/daemon-jobs.ts +161 -7
  124. package/src/home/database-projects.ts +111 -0
  125. package/src/home/database-words.ts +203 -0
  126. package/src/home/databases.ts +460 -0
  127. package/src/home/global-units.ts +6 -0
  128. package/src/home/gui-app/ShipkitGui.swift +122 -1
  129. package/src/home/gui-app.ts +6 -3
  130. package/src/home/home-move.ts +514 -0
  131. package/src/home/home-paths.ts +18 -6
  132. package/src/home/home-routes.ts +76 -0
  133. package/src/home/inbox-shape.ts +234 -91
  134. package/src/home/inbox.ts +26 -71
  135. package/src/home/machine-fold.ts +815 -0
  136. package/src/home/machine-host.ts +38 -5
  137. package/src/home/machine-repair.ts +503 -0
  138. package/src/home/machine-stores.ts +66 -15
  139. package/src/home/machine-temp.ts +547 -86
  140. package/src/home/other-macs.ts +2 -2
  141. package/src/home/resume.ts +79 -0
  142. package/src/home/run-daemon.ts +25 -4
  143. package/src/home/run-pm.ts +18 -5
  144. package/src/home/serve-daemon.ts +18 -3
  145. package/src/home/serve-web.ts +179 -10
  146. package/src/home/space-job.ts +115 -0
  147. package/src/home/space-page.ts +257 -0
  148. package/src/home/space-route.ts +167 -0
  149. package/src/home/space-words.ts +103 -0
  150. package/src/home/time-page-shape.ts +202 -0
  151. package/src/home/time-page.ts +64 -0
  152. package/src/home/vault-page.ts +516 -0
  153. package/src/home/vault-words.ts +132 -0
  154. package/src/hooks/leak-guard.ts +40 -13
  155. package/src/hooks/one-way-in-guard.ts +41 -6
  156. package/src/hq/cards.ts +581 -0
  157. package/src/hq/door-route.ts +43 -0
  158. package/src/hq/door.ts +163 -0
  159. package/src/hq/files-send.ts +347 -0
  160. package/src/hq/forgotten-log.ts +35 -0
  161. package/src/hq/history-check.ts +255 -0
  162. package/src/hq/history-place.ts +146 -0
  163. package/src/hq/history-send.ts +487 -0
  164. package/src/hq/hq-db.ts +102 -0
  165. package/src/hq/hq-local.ts +502 -0
  166. package/src/hq/hq-routes.ts +204 -0
  167. package/src/hq/hq-store.ts +603 -0
  168. package/src/hq/kinds/ask.ts +147 -0
  169. package/src/hq/kinds/card-gone.ts +83 -0
  170. package/src/hq/kinds/card-msg.ts +66 -0
  171. package/src/hq/kinds/card.ts +99 -0
  172. package/src/hq/kinds/index.ts +21 -0
  173. package/src/hq/kinds/kind.ts +126 -0
  174. package/src/hq/kinds/media.ts +125 -0
  175. package/src/hq/kinds/prompt.ts +219 -0
  176. package/src/hq/kinds/reflection.ts +128 -0
  177. package/src/hq/kinds/report.ts +55 -0
  178. package/src/hq/kinds/time-day.ts +236 -0
  179. package/src/hq/ledger.ts +473 -0
  180. package/src/hq/machine-key.ts +44 -0
  181. package/src/hq/machine-notes.ts +131 -0
  182. package/src/hq/outbox.ts +374 -0
  183. package/src/hq/replica.ts +167 -0
  184. package/src/hq/repo-id.ts +4 -0
  185. package/src/hq/report-facts.ts +117 -0
  186. package/src/hq/report.ts +274 -0
  187. package/src/hq/switch.ts +151 -0
  188. package/src/hq/vault-grant.ts +92 -0
  189. package/src/hq/vault-route.ts +112 -0
  190. package/src/identities/collection.ts +2 -2
  191. package/src/identities/identities.ts +24 -11
  192. package/src/identities/machine-route.ts +8 -3
  193. package/src/identities/steps.ts +31 -0
  194. package/src/ledger/db.ts +81 -27
  195. package/src/ledger/gate-checks.ts +6 -2
  196. package/src/ledger/run-log.ts +11 -3
  197. package/src/ledger/store.ts +26 -4
  198. package/src/media-store/backup/daemon.ts +73 -25
  199. package/src/media-store/backup/kept.ts +241 -0
  200. package/src/media-store/backup/keys.ts +1 -1
  201. package/src/media-store/backup/manifest.ts +20 -2
  202. package/src/media-store/backup/prune.ts +365 -0
  203. package/src/media-store/backup/restore.ts +14 -4
  204. package/src/media-store/backup/retention.ts +122 -0
  205. package/src/media-store/backup/run.ts +25 -19
  206. package/src/media-store/backup/secret.ts +6 -4
  207. package/src/media-store/backup/snapshot.ts +4 -2
  208. package/src/media-store/backup/sources.ts +83 -31
  209. package/src/media-store/backup/thread-copy.ts +340 -0
  210. package/src/media-store/copy/config.ts +76 -0
  211. package/src/media-store/copy/copy.ts +194 -0
  212. package/src/media-store/copy/lifecycle.ts +43 -0
  213. package/src/media-store/copy/night.ts +90 -0
  214. package/src/media-store/copy/proof.ts +151 -0
  215. package/src/media-store/copy/snapshot.ts +152 -0
  216. package/src/media-store/copy/store.ts +62 -0
  217. package/src/media-store/copy/stream.ts +176 -0
  218. package/src/media-store/daemon.ts +66 -16
  219. package/src/media-store/db.ts +24 -13
  220. package/src/media-store/forget.ts +141 -3
  221. package/src/media-store/hand.ts +4 -3
  222. package/src/media-store/hq-find.ts +75 -0
  223. package/src/media-store/hq-send.ts +277 -0
  224. package/src/media-store/kind.ts +2 -0
  225. package/src/media-store/purge.ts +21 -17
  226. package/src/media-store/put.ts +24 -8
  227. package/src/media-store/remote.ts +16 -7
  228. package/src/media-store/space-listing.ts +256 -0
  229. package/src/media-store/space.ts +46 -26
  230. package/src/media-store/sync.ts +5 -5
  231. package/src/media-store/tidy.ts +98 -0
  232. package/src/media-store/upload.ts +3 -3
  233. package/src/media-store/webp.ts +66 -0
  234. package/src/messages/guard.ts +49 -0
  235. package/src/messages/model.ts +16 -7
  236. package/src/messages/objects.ts +201 -0
  237. package/src/messages/routes.ts +14 -4
  238. package/src/messages/score.ts +3 -3
  239. package/src/messages/write.ts +285 -0
  240. package/src/pages/frame-client.ts +191 -4
  241. package/src/plan/planner.ts +28 -17
  242. package/src/recordings/media-kind.ts +1 -0
  243. package/src/recordings/model.ts +1 -1
  244. package/src/recordings/recorder-app/Capture.swift +9 -7
  245. package/src/reflect/hq-corpus.ts +56 -0
  246. package/src/reflect/prompt-corpus.ts +3 -1
  247. package/src/reflect/transcript.ts +129 -37
  248. package/src/reflections/reflections-queue.ts +1 -1
  249. package/src/release/gate-checkout.ts +2 -1
  250. package/src/release/git-facts.ts +3 -2
  251. package/src/release/machine-words.ts +67 -0
  252. package/src/release/public-clean.ts +11 -5
  253. package/src/releases/from-card.ts +1 -1
  254. package/src/releases/routes.ts +10 -5
  255. package/src/releases/store.ts +10 -1
  256. package/src/repo-config.ts +71 -19
  257. package/src/review/anim.ts +3 -3
  258. package/src/review/answer-kinds.ts +131 -0
  259. package/src/review/auto.ts +2 -2
  260. package/src/review/band.ts +53 -0
  261. package/src/review/branch-hold.ts +84 -0
  262. package/src/review/card-db.ts +254 -0
  263. package/src/review/card-rows.ts +267 -0
  264. package/src/review/cells.ts +360 -57
  265. package/src/review/close.ts +92 -0
  266. package/src/review/draft-card.ts +33 -0
  267. package/src/review/draft-model.ts +78 -0
  268. package/src/review/events.ts +171 -0
  269. package/src/review/format.ts +152 -19
  270. package/src/review/glyphs.ts +63 -0
  271. package/src/review/gone.ts +98 -0
  272. package/src/review/holds-sync.ts +62 -0
  273. package/src/review/holds.ts +85 -0
  274. package/src/review/house-kind-defs.ts +41 -0
  275. package/src/review/inbox-hook.ts +23 -10
  276. package/src/review/inbox-read.ts +201 -0
  277. package/src/review/instructions.ts +199 -0
  278. package/src/review/kind-apply.ts +61 -0
  279. package/src/review/kind-catalog.ts +96 -0
  280. package/src/review/kinds.ts +278 -0
  281. package/src/review/lane-ask.ts +109 -0
  282. package/src/review/marks.ts +1 -1
  283. package/src/review/media-kind.ts +7 -5
  284. package/src/review/media-read.ts +9 -7
  285. package/src/review/media.ts +32 -5
  286. package/src/review/model.ts +582 -109
  287. package/src/review/move.ts +491 -0
  288. package/src/review/need-address.ts +15 -0
  289. package/src/review/need-threads.ts +93 -0
  290. package/src/review/notes.ts +12 -20
  291. package/src/review/object-card.ts +48 -0
  292. package/src/review/object-read.ts +31 -0
  293. package/src/review/owner-verdict.ts +36 -0
  294. package/src/review/parties.ts +182 -0
  295. package/src/review/previews.ts +18 -20
  296. package/src/review/project.ts +1 -1
  297. package/src/review/projections.ts +235 -0
  298. package/src/review/referring.ts +54 -0
  299. package/src/review/reflection-object.ts +195 -0
  300. package/src/review/rev.ts +8 -0
  301. package/src/review/role.ts +1 -1
  302. package/src/review/routes.ts +194 -38
  303. package/src/review/secret-route.ts +80 -0
  304. package/src/review/snooze.ts +38 -0
  305. package/src/review/stage-card.ts +12 -8
  306. package/src/review/stage-routes.ts +1 -1
  307. package/src/review/store.ts +851 -124
  308. package/src/review/supersede.ts +116 -0
  309. package/src/review/take-back.ts +52 -0
  310. package/src/review/thread-fold.ts +64 -0
  311. package/src/review/threads.ts +349 -14
  312. package/src/review/traces.ts +218 -0
  313. package/src/review/trailer-auto-mock.ts +63 -0
  314. package/src/review/trailer-card.ts +6 -6
  315. package/src/review/trailer-desk.ts +41 -7
  316. package/src/review/trailer-media.ts +1 -0
  317. package/src/review/trailer-model.ts +8 -0
  318. package/src/review/trailer-notes.ts +1 -1
  319. package/src/review/trailer-routes.ts +9 -1
  320. package/src/review/unit.ts +77 -11
  321. package/src/review/verdict-items.ts +73 -0
  322. package/src/review/verdict-write.ts +15 -0
  323. package/src/review/wait.ts +85 -0
  324. package/src/review/watchers.ts +23 -10
  325. package/src/rules/untrack-generated.ts +92 -8
  326. package/src/scaffold/files/claude-settings-local.json +2 -0
  327. package/src/secrets/archive-mark.ts +52 -0
  328. package/src/secrets/archive.ts +83 -0
  329. package/src/secrets/copy.ts +14 -14
  330. package/src/secrets/held.ts +16 -0
  331. package/src/secrets/keychain-write.ts +48 -0
  332. package/src/secrets/keychain.ts +116 -0
  333. package/src/secrets/lapse-mark.ts +33 -0
  334. package/src/secrets/lapse.ts +60 -0
  335. package/src/secrets/list.ts +21 -17
  336. package/src/secrets/manager.ts +55 -26
  337. package/src/secrets/read.ts +385 -0
  338. package/src/secrets/tail.ts +31 -0
  339. package/src/secrets/who-reads.ts +49 -0
  340. package/src/serve/door-forward.ts +268 -0
  341. package/src/serve/door-names.ts +47 -0
  342. package/src/serve/embed.ts +1 -1
  343. package/src/serve/hub-app/activity-view.tsx +56 -32
  344. package/src/serve/hub-app/activity.css +7 -1
  345. package/src/serve/hub-app/asks-page.tsx +49 -0
  346. package/src/serve/hub-app/asks-st.ts +25 -0
  347. package/src/serve/hub-app/auto-text.tsx +14 -6
  348. package/src/serve/hub-app/benign-errors.ts +15 -1
  349. package/src/serve/hub-app/card-head.tsx +49 -0
  350. package/src/serve/hub-app/check-view.tsx +3 -2
  351. package/src/serve/hub-app/clock-svc.ts +1 -2
  352. package/src/serve/hub-app/code-copy.ts +35 -0
  353. package/src/serve/hub-app/col-card.tsx +72 -30
  354. package/src/serve/hub-app/col-list-page.tsx +125 -0
  355. package/src/serve/hub-app/col-list-st.ts +103 -0
  356. package/src/serve/hub-app/col-tables-view.tsx +17 -45
  357. package/src/serve/hub-app/col-tables.ts +76 -8
  358. package/src/serve/hub-app/cols-svc.ts +18 -39
  359. package/src/serve/hub-app/commands/commands-page.tsx +2 -1
  360. package/src/serve/hub-app/controls.css +83 -0
  361. package/src/serve/hub-app/database-st.ts +260 -0
  362. package/src/serve/hub-app/database-view.tsx +289 -0
  363. package/src/serve/hub-app/database.css +32 -0
  364. package/src/serve/hub-app/entry-bar.css +14 -0
  365. package/src/serve/hub-app/entry-bar.tsx +33 -0
  366. package/src/serve/hub-app/entry-pick.ts +31 -0
  367. package/src/serve/hub-app/floating.tsx +1 -0
  368. package/src/serve/hub-app/frames-st.ts +17 -1
  369. package/src/serve/hub-app/git-view.tsx +3 -2
  370. package/src/serve/hub-app/hash-route.ts +11 -1
  371. package/src/serve/hub-app/header-bar.tsx +14 -18
  372. package/src/serve/hub-app/home-st.ts +142 -11
  373. package/src/serve/hub-app/home-strip.css +6 -25
  374. package/src/serve/hub-app/home-strip.tsx +60 -93
  375. package/src/serve/hub-app/home.html +10 -0
  376. package/src/serve/hub-app/house-wiki-view.tsx +20 -0
  377. package/src/serve/hub-app/hub-app.tsx +71 -166
  378. package/src/serve/hub-app/hub-types.ts +5 -1
  379. package/src/serve/hub-app/hub.css +146 -71
  380. package/src/serve/hub-app/icons.tsx +32 -5
  381. package/src/serve/hub-app/identities-st.ts +56 -6
  382. package/src/serve/hub-app/identities-view.tsx +104 -61
  383. package/src/serve/hub-app/identities.css +17 -15
  384. package/src/serve/hub-app/identity-address.ts +5 -0
  385. package/src/serve/hub-app/inbox-st.ts +227 -49
  386. package/src/serve/hub-app/inbox-view.tsx +204 -120
  387. package/src/serve/hub-app/inbox.css +47 -47
  388. package/src/serve/hub-app/index.html +10 -0
  389. package/src/serve/hub-app/instructions.css +30 -0
  390. package/src/serve/hub-app/kept-cols.tsx +7 -0
  391. package/src/serve/hub-app/keys.ts +32 -17
  392. package/src/serve/hub-app/later.tsx +26 -0
  393. package/src/serve/hub-app/list-filter.tsx +14 -0
  394. package/src/serve/hub-app/list-walk.ts +72 -3
  395. package/src/serve/hub-app/machine-st.ts +2 -2
  396. package/src/serve/hub-app/machines-st.ts +251 -0
  397. package/src/serve/hub-app/machines-view.tsx +217 -0
  398. package/src/serve/hub-app/machines.css +67 -0
  399. package/src/serve/hub-app/markdown.css +51 -0
  400. package/src/serve/hub-app/md-copy.tsx +57 -0
  401. package/src/serve/hub-app/md.ts +25 -9
  402. package/src/serve/hub-app/media-view.tsx +4 -2
  403. package/src/serve/hub-app/messages/messages-page.tsx +81 -8
  404. package/src/serve/hub-app/messages/messages-st.ts +99 -3
  405. package/src/serve/hub-app/messages.css +14 -1
  406. package/src/serve/hub-app/objects.css +51 -0
  407. package/src/serve/hub-app/page-keys.ts +175 -0
  408. package/src/serve/hub-app/pages-frames.tsx +21 -3
  409. package/src/serve/hub-app/palette-st.ts +58 -11
  410. package/src/serve/hub-app/palette-view.tsx +3 -1
  411. package/src/serve/hub-app/pane-boundary.tsx +72 -0
  412. package/src/serve/hub-app/pane-errors.ts +54 -0
  413. package/src/serve/hub-app/plan-view.tsx +3 -2
  414. package/src/serve/hub-app/planned-view.tsx +3 -3
  415. package/src/serve/hub-app/planned.css +0 -4
  416. package/src/serve/hub-app/processes-view.tsx +3 -2
  417. package/src/serve/hub-app/project-list.css +46 -8
  418. package/src/serve/hub-app/project-list.tsx +125 -59
  419. package/src/serve/hub-app/projects-svc.ts +83 -8
  420. package/src/serve/hub-app/reader-chips.tsx +13 -0
  421. package/src/serve/hub-app/readme-view.tsx +2 -3
  422. package/src/serve/hub-app/readme.css +22 -6
  423. package/src/serve/hub-app/reflections-page.tsx +95 -0
  424. package/src/serve/hub-app/reflections-st.ts +17 -0
  425. package/src/serve/hub-app/releases/releases-page.tsx +28 -4
  426. package/src/serve/hub-app/releases/releases-st.ts +1 -1
  427. package/src/serve/hub-app/releases.css +0 -1
  428. package/src/serve/hub-app/repo-sections.ts +9 -5
  429. package/src/serve/hub-app/repo-st.ts +35 -8
  430. package/src/serve/hub-app/review/code-colors.ts +30 -0
  431. package/src/serve/hub-app/review/diff-view.tsx +75 -0
  432. package/src/serve/hub-app/review/dock.tsx +104 -0
  433. package/src/serve/hub-app/review/draft-card.tsx +163 -0
  434. package/src/serve/hub-app/review/group-block.tsx +209 -0
  435. package/src/serve/hub-app/review/instructions-view.tsx +116 -0
  436. package/src/serve/hub-app/review/item-verdict.tsx +38 -0
  437. package/src/serve/hub-app/review/kind-states.tsx +193 -0
  438. package/src/serve/hub-app/review/kind-view.tsx +1 -37
  439. package/src/serve/hub-app/review/kit.tsx +75 -29
  440. package/src/serve/hub-app/review/lane-bar.tsx +64 -0
  441. package/src/serve/hub-app/review/note-place.ts +1 -1
  442. package/src/serve/hub-app/review/object-card.tsx +62 -0
  443. package/src/serve/hub-app/review/object-panel.tsx +179 -0
  444. package/src/serve/hub-app/review/question-views.tsx +385 -0
  445. package/src/serve/hub-app/review/review-board.tsx +2 -2
  446. package/src/serve/hub-app/review/review-cells.tsx +148 -87
  447. package/src/serve/hub-app/review/review-kit.ts +27 -1
  448. package/src/serve/hub-app/review/review-list.tsx +160 -65
  449. package/src/serve/hub-app/review/review-page.tsx +12 -12
  450. package/src/serve/hub-app/review/review-st.ts +174 -47
  451. package/src/serve/hub-app/review/review-thread.tsx +214 -53
  452. package/src/serve/hub-app/review/review-views.tsx +494 -159
  453. package/src/serve/hub-app/review/thread-close.tsx +124 -0
  454. package/src/serve/hub-app/review/thread-control-st.ts +115 -0
  455. package/src/serve/hub-app/review/thread-control.tsx +74 -0
  456. package/src/serve/hub-app/review/thread-st.ts +288 -41
  457. package/src/serve/hub-app/review/trailer-card.tsx +2 -2
  458. package/src/serve/hub-app/review/trailer-page.tsx +37 -16
  459. package/src/serve/hub-app/review/trailer-st.ts +41 -7
  460. package/src/serve/hub-app/review/trailer-timeline.tsx +2 -2
  461. package/src/serve/hub-app/review.css +462 -97
  462. package/src/serve/hub-app/section-head.tsx +51 -0
  463. package/src/serve/hub-app/side-lists.ts +72 -0
  464. package/src/serve/hub-app/sidebar.tsx +6 -3
  465. package/src/serve/hub-app/site/site-part.tsx +2 -8
  466. package/src/serve/hub-app/site/site-st.ts +4 -4
  467. package/src/serve/hub-app/social/calendar.tsx +5 -11
  468. package/src/serve/hub-app/social/comms-page.tsx +43 -15
  469. package/src/serve/hub-app/social/kit.tsx +32 -13
  470. package/src/serve/hub-app/social/next-release.tsx +3 -5
  471. package/src/serve/hub-app/social/post-card.tsx +142 -49
  472. package/src/serve/hub-app/social/post-page.tsx +80 -0
  473. package/src/serve/hub-app/social/problems.tsx +5 -9
  474. package/src/serve/hub-app/social/serial-writes.ts +13 -0
  475. package/src/serve/hub-app/social/social-model.ts +24 -5
  476. package/src/serve/hub-app/social/social-page.tsx +95 -36
  477. package/src/serve/hub-app/social/social-st.ts +162 -41
  478. package/src/serve/hub-app/social/stage-popup.tsx +1 -1
  479. package/src/serve/hub-app/social/stage-st.ts +1 -1
  480. package/src/serve/hub-app/social/step-layout.ts +1 -1
  481. package/src/serve/hub-app/social.css +10 -17
  482. package/src/serve/hub-app/space-st.ts +209 -0
  483. package/src/serve/hub-app/space-view.tsx +196 -0
  484. package/src/serve/hub-app/space.css +27 -0
  485. package/src/serve/hub-app/stores/stores-page.tsx +97 -25
  486. package/src/serve/hub-app/stores/stores-st.ts +44 -19
  487. package/src/serve/hub-app/stores.css +6 -1
  488. package/src/serve/hub-app/theme-st.ts +22 -9
  489. package/src/serve/hub-app/thread-row.tsx +101 -0
  490. package/src/serve/hub-app/time-ago.tsx +3 -2
  491. package/src/serve/hub-app/time-charts.tsx +291 -0
  492. package/src/serve/hub-app/time-pages.tsx +749 -0
  493. package/src/serve/hub-app/time-st.ts +162 -0
  494. package/src/serve/hub-app/time-view.tsx +77 -0
  495. package/src/serve/hub-app/time.css +135 -0
  496. package/src/serve/hub-app/tree-build.ts +52 -42
  497. package/src/serve/hub-app/tree-row.tsx +3 -11
  498. package/src/serve/hub-app/tree-svc.ts +18 -9
  499. package/src/serve/hub-app/urls-svc.ts +154 -0
  500. package/src/serve/hub-app/urls-view.tsx +117 -0
  501. package/src/serve/hub-app/urls.css +30 -0
  502. package/src/serve/hub-app/vault-st.ts +127 -0
  503. package/src/serve/hub-app/vault-view.tsx +154 -0
  504. package/src/serve/hub-app/vault.css +38 -0
  505. package/src/serve/hub-app/veille/veille-page.tsx +2 -11
  506. package/src/serve/hub-app/veille/veille-st.ts +12 -10
  507. package/src/serve/hub-app/veille.css +0 -1
  508. package/src/serve/hub-app/waiting-svc.ts +29 -0
  509. package/src/serve/hub-app/when-view.tsx +6 -3
  510. package/src/serve/hub-app/wiki-st.ts +30 -4
  511. package/src/serve/hub-app/wikis-view.tsx +6 -5
  512. package/src/serve/hub-runtime.ts +35 -8
  513. package/src/serve/project-gutter-route.ts +42 -19
  514. package/src/serve/project-gutter.ts +16 -50
  515. package/src/serve/same-origin.ts +13 -0
  516. package/src/serve/secret-gate.ts +21 -0
  517. package/src/serve/serve-hub.ts +38 -20
  518. package/src/serve/tailnet-caller.ts +117 -0
  519. package/src/shipkit-files.ts +16 -2
  520. package/src/shipkit.ts +3 -3
  521. package/src/shot/shooter.ts +616 -420
  522. package/src/shot/shot-ask.ts +246 -155
  523. package/src/site/desk.ts +4 -4
  524. package/src/smoke/run-smoke.ts +6 -6
  525. package/src/social/brands.ts +4 -0
  526. package/src/social/card-drafts.ts +11 -19
  527. package/src/social/cover.ts +202 -0
  528. package/src/social/desk-index.ts +34 -13
  529. package/src/social/discord-layout.ts +37 -13
  530. package/src/social/drafts.ts +7 -4
  531. package/src/social/import-drafts.ts +244 -0
  532. package/src/social/kind-pages.ts +3 -3
  533. package/src/social/kinds.ts +1 -1
  534. package/src/social/load.ts +111 -65
  535. package/src/social/media-kind.ts +68 -160
  536. package/src/social/media-of.ts +5 -4
  537. package/src/social/open.ts +3 -2
  538. package/src/social/post-object.ts +120 -0
  539. package/src/social/post-sources.ts +136 -0
  540. package/src/social/post-text.ts +103 -0
  541. package/src/social/posts.ts +378 -0
  542. package/src/social/presence.ts +7 -5
  543. package/src/social/publish/discord.ts +5 -2
  544. package/src/social/publish/index.ts +17 -5
  545. package/src/social/publish/secret.ts +4 -4
  546. package/src/social/release-stage.ts +79 -63
  547. package/src/social/routes.ts +89 -24
  548. package/src/social/stage.ts +43 -58
  549. package/src/social/stats.ts +12 -9
  550. package/src/social/strip.ts +4 -1
  551. package/src/social/text.ts +4 -3
  552. package/src/social/thumbnail.ts +347 -0
  553. package/src/social/tracker.ts +1 -1
  554. package/src/social/writes.ts +12 -29
  555. package/src/stores/collection.ts +15 -11
  556. package/src/stores/desk.ts +246 -47
  557. package/src/stores/model.ts +72 -6
  558. package/src/stores/routes.ts +37 -12
  559. package/src/stores/unit.ts +16 -10
  560. package/src/suite/judge-suites.ts +41 -11
  561. package/src/suite/select.ts +45 -3
  562. package/src/suite/suite-cli.ts +16 -10
  563. package/src/trailer/bed.ts +1 -1
  564. package/src/trailer/build.ts +134 -21
  565. package/src/trailer/ffmpeg.ts +7 -0
  566. package/src/trailer/fonts.ts +3 -2
  567. package/src/trailer/grammar.ts +201 -2
  568. package/src/trailer/graph.ts +42 -5
  569. package/src/trailer/look.ts +21 -0
  570. package/src/trailer/mock.ts +154 -0
  571. package/src/trailer/passage.ts +65 -26
  572. package/src/trailer/score/heard.ts +89 -0
  573. package/src/trailer/score/sound.ts +14 -8
  574. package/src/trailer/sound/eleven.ts +33 -3
  575. package/src/trailer/sound/run.ts +16 -6
  576. package/src/trailer/stitch.ts +26 -5
  577. package/src/trailer/titles.ts +82 -19
  578. package/src/trailer/versions.ts +1 -3
  579. package/src/trailer/vertical.ts +3 -1
  580. package/src/urls/frame.ts +195 -0
  581. package/src/urls/routes.ts +43 -0
  582. package/src/urls/rows.ts +171 -0
  583. package/src/urls/unit.ts +73 -0
  584. package/src/vault/house-keys.ts +42 -0
  585. package/src/vault/layout.ts +50 -0
  586. package/src/vault/policy.ts +165 -0
  587. package/src/vault/vault-audit.ts +276 -0
  588. package/src/vault/vault-client.ts +40 -0
  589. package/src/vault/vault-config.ts +159 -0
  590. package/src/vault/vault-destroy.ts +78 -0
  591. package/src/vault/vault-handover.ts +305 -0
  592. package/src/vault/vault-http.ts +360 -0
  593. package/src/vault/vault-import.ts +213 -0
  594. package/src/vault/vault-init.ts +328 -0
  595. package/src/vault/vault-minter.ts +271 -0
  596. package/src/vault/vault-restore.ts +333 -0
  597. package/src/vault/vault-serve.ts +342 -0
  598. package/src/vault/vault-snapshot.ts +281 -0
  599. package/src/veille/asks.ts +1 -1
  600. package/src/veille/desk.ts +2 -2
  601. package/src/veille/identity.ts +2 -2
  602. package/src/wiki/graph-pages.ts +13 -1
  603. package/src/wiki/scan-md.ts +1 -1
  604. package/src/asks/asks-queue.ts +0 -266
  605. package/src/social/migrate.ts +0 -123
@@ -0,0 +1,256 @@
1
+ // the listing of a Space as its own bucket gives it (wiki tools/shipkit/media-store.md, The Space page): every key
2
+ // with its size and date (ListObjectsV2), the older versions and delete markers the versioning keeps
3
+ // (ListObjectVersions), the uploads never completed (ListMultipartUploads). A whole listing is about one call per
4
+ // 1,000 objects and the same for hours, so it is kept in the machine db with its date: one row a key, one row a
5
+ // folder with its sums, one row a listing. The page and `sk space` read what is kept and never list.
6
+ //
7
+ // The constraint a reader breaks first: nothing here writes to a bucket, every call is a GET of a listing, and a
8
+ // listing that fails half way keeps the one before it whole (a partial listing is never kept as the truth)
9
+ import type { Database } from 'bun:sqlite'
10
+ import { listCall, listPages, tagOf } from './copy/copy.ts'
11
+ import type { SpaceConfig } from './space.ts'
12
+
13
+ export type Listed = { key: string; size: number; modified: number | null }
14
+ /** a folder and every object under it, at any depth: `''` is the whole Space */
15
+ export type FolderSum = { prefix: string; parent: string; bytes: number; objects: number }
16
+
17
+ /** the folder a key sits in: everything up to its last `/` (`''` for a key of no folder) */
18
+ export const parentOf = (key: string): string => key.slice(0, key.lastIndexOf('/') + 1)
19
+ /** a key's first folder, `''` for a key of no folder */
20
+ export const topOf = (key: string): string => key.slice(0, key.indexOf('/') + 1)
21
+
22
+ /** every folder of the listing with the bytes and the count of the objects under it: the whole Space first, then each
23
+ * folder named by its keys (a key ending in `/` is the marker object of the folder it names) */
24
+ export function folderSums(rows: Iterable<Listed>): FolderSum[] {
25
+ const sums = new Map<string, FolderSum>([['', { prefix: '', parent: '', bytes: 0, objects: 0 }]])
26
+ for (const r of rows) {
27
+ const root = sums.get('')!
28
+ root.bytes += r.size
29
+ root.objects++
30
+ let at = r.key.indexOf('/')
31
+ while (at >= 0) {
32
+ const prefix = r.key.slice(0, at + 1)
33
+ let s = sums.get(prefix)
34
+ if (s == null) sums.set(prefix, (s = { prefix, parent: parentOf(prefix.slice(0, -1)), bytes: 0, objects: 0 }))
35
+ s.bytes += r.size
36
+ s.objects++
37
+ at = r.key.indexOf('/', at + 1)
38
+ }
39
+ }
40
+ return [...sums.values()]
41
+ }
42
+
43
+ /** a count and its bytes, and how they split by top folder */
44
+ export type Split = { n: number; bytes: number; top: { prefix: string; n: number; bytes: number }[] }
45
+ /** what a listing could not count says why */
46
+ export type Counted<T> = T | { why: string }
47
+ /** a count that was made (null is a count too: no rule, nothing), not its reason why not */
48
+ export const counted = <T>(c: Counted<T> | undefined): c is T => c !== undefined && !(typeof c === 'object' && c !== null && 'why' in c)
49
+
50
+ export function splitOf(rows: Iterable<{ key: string; size: number }>): Split {
51
+ const by = new Map<string, { prefix: string; n: number; bytes: number }>()
52
+ let n = 0
53
+ let bytes = 0
54
+ for (const r of rows) {
55
+ n++
56
+ bytes += r.size
57
+ const t = topOf(r.key)
58
+ const s = by.get(t) ?? { prefix: t, n: 0, bytes: 0 }
59
+ s.n++
60
+ s.bytes += r.size
61
+ by.set(t, s)
62
+ }
63
+ return { n, bytes, top: [...by.values()].sort((a, b) => b.bytes - a.bytes || b.n - a.n) }
64
+ }
65
+
66
+ /** one listing as kept: when, how long, how many calls, what it found and what it could not count */
67
+ export type ListingRecord = {
68
+ space: string
69
+ at: number
70
+ ms: number
71
+ calls: number
72
+ objects: number
73
+ bytes: number
74
+ /** the older versions the versioning keeps (room nobody sees in the list), and the delete markers */
75
+ versions: Counted<Split & { markers: number }>
76
+ /** the multipart uploads started and never completed: their parts take room, their size needs a call each */
77
+ uploads: Counted<Split>
78
+ versioning: Counted<'Enabled' | 'Suspended' | 'off'>
79
+ /** the bucket's lifecycle rules, as ids and what each does; null when it holds none */
80
+ lifecycle: Counted<string[] | null>
81
+ /** the bytes the kept rows take in the machine db, about */
82
+ keptBytes: number
83
+ /** the Space's listing against this machine's index: up in the index and not listed, listed and in no index */
84
+ vsIndex?: Counted<{ upNotListed: Split; notIndexed: Split }>
85
+ /** the copy's listing against the Space's: what the copy lacks, what only the copy holds */
86
+ vsSpace?: Counted<{ lacks: Split; only: Split }>
87
+ }
88
+
89
+ /** every object of the bucket and the calls it took */
90
+ export async function listObjects(c: SpaceConfig): Promise<{ rows: Listed[]; calls: number }> {
91
+ const rows: Listed[] = []
92
+ let calls = 0
93
+ await listPages(c, (page) => {
94
+ calls++
95
+ for (const r of page) rows.push(r)
96
+ })
97
+ return { rows, calls }
98
+ }
99
+
100
+ /** the older versions and delete markers, a page of 1,000 at a time; the current versions are the listing's own */
101
+ export async function listVersions(c: SpaceConfig): Promise<{ versions: Split & { markers: number }; calls: number }> {
102
+ const old: { key: string; size: number }[] = []
103
+ let markers = 0
104
+ const calls = await eachVersion(c, {}, (v) => {
105
+ if (v.marker) markers++
106
+ else if (!v.latest) old.push({ key: v.key, size: v.size })
107
+ })
108
+ return { versions: { ...splitOf(old), markers }, calls }
109
+ }
110
+
111
+ /** one version or delete marker of a key, as ListObjectVersions answers it */
112
+ export type VersionRow = { key: string; versionId: string; latest: boolean; marker: boolean; modified: number | null; size: number }
113
+
114
+ /** every version and delete marker (under `prefix`), a page of 1,000 at a time, in the bucket's order: a key's
115
+ * versions together, newest first. The calls it took */
116
+ export async function eachVersion(c: SpaceConfig, o: { prefix?: string }, fn: (v: VersionRow) => void): Promise<number> {
117
+ let calls = 0
118
+ let key: string | null = null
119
+ let vid: string | null = null
120
+ do {
121
+ const text = await listCall(c, { versions: '', 'max-keys': '1000', ...(o.prefix ? { prefix: o.prefix } : {}), ...(key != null ? { 'key-marker': key } : {}), ...(vid != null ? { 'version-id-marker': vid } : {}) })
122
+ calls++
123
+ for (const m of text.matchAll(/<(Version|DeleteMarker)>([\s\S]*?)<\/\1>/g)) {
124
+ const b = m[2]!
125
+ const at = tagOf(b, 'LastModified')
126
+ fn({ key: tagOf(b, 'Key') ?? '', versionId: tagOf(b, 'VersionId') ?? '', latest: tagOf(b, 'IsLatest') === 'true', marker: m[1] === 'DeleteMarker', modified: at ? Date.parse(at) || null : null, size: Number(tagOf(b, 'Size') ?? 0) })
127
+ }
128
+ const more = /<IsTruncated>true<\/IsTruncated>/.test(text)
129
+ key = more ? tagOf(text, 'NextKeyMarker') : null
130
+ vid = more ? tagOf(text, 'NextVersionIdMarker') : null
131
+ if (more && key == null) throw new Error(`the versions of ${c.bucket} say more and name no next page`)
132
+ } while (key != null)
133
+ return calls
134
+ }
135
+
136
+ /** the uploads never completed, a page of 1,000 at a time; a part's size is not in this answer */
137
+ export async function listUploads(c: SpaceConfig): Promise<{ uploads: Split; calls: number }> {
138
+ const keys: { key: string; size: number }[] = []
139
+ let calls = 0
140
+ let key: string | null = null
141
+ let id: string | null = null
142
+ do {
143
+ const text = await listCall(c, { uploads: '', 'max-uploads': '1000', ...(key != null ? { 'key-marker': key } : {}), ...(id != null ? { 'upload-id-marker': id } : {}) })
144
+ calls++
145
+ for (const m of text.matchAll(/<Upload>([\s\S]*?)<\/Upload>/g)) keys.push({ key: tagOf(m[1]!, 'Key') ?? '', size: 0 })
146
+ const more = /<IsTruncated>true<\/IsTruncated>/.test(text)
147
+ key = more ? tagOf(text, 'NextKeyMarker') : null
148
+ id = more ? tagOf(text, 'NextUploadIdMarker') : null
149
+ if (more && key == null) throw new Error(`the uploads of ${c.bucket} say more and name no next page`)
150
+ } while (key != null)
151
+ return { uploads: splitOf(keys), calls }
152
+ }
153
+
154
+ /** a lifecycle rule in words: its id, its folder, what it does */
155
+ export function ruleWords(rule: string): string {
156
+ const id = tagOf(rule, 'ID') ?? 'a rule of no id'
157
+ const prefix = tagOf(rule, 'Prefix') ?? ''
158
+ const on = tagOf(rule, 'Status') === 'Enabled' ? '' : ' (off)'
159
+ const days = tagOf(rule, 'Days')
160
+ const does = rule.includes('<AbortIncompleteMultipartUpload>') ? `aborts an upload left unfinished after ${tagOf(rule, 'DaysAfterInitiation') ?? '?'} days` : rule.includes('<NoncurrentVersionExpiration>') ? `deletes an older version after ${tagOf(rule, 'NoncurrentDays') ?? '?'} days` : days != null ? `deletes an object ${days} days after it is written` : 'a rule this page does not read'
161
+ return `${id}${on}: ${prefix === '' ? 'the whole bucket' : prefix}, ${does}`
162
+ }
163
+
164
+ const SCHEMA = `
165
+ create table if not exists space_listings (space text primary key, at integer not null, record text not null) without rowid;
166
+ create table if not exists space_folders (space text not null, prefix text not null, parent text not null, bytes integer not null, objects integer not null, primary key (space, prefix)) without rowid;
167
+ create index if not exists space_folders_parent on space_folders (space, parent, bytes);
168
+ create table if not exists space_keys (space text not null, key text not null, size integer not null, modified integer, primary key (space, key)) without rowid;
169
+ `
170
+ /** the listing's tables, made where they are not: tables of their own, the machine db's version untouched. A key is
171
+ * kept once, in its primary key: a folder's files are a range of it (about 12 MB for 115,000 keys) */
172
+ export const spaceTables = (db: Database): void => void db.exec(SCHEMA)
173
+
174
+ const has = (db: Database): boolean => db.query("select 1 from sqlite_master where type = 'table' and name = 'space_listings'").get() != null
175
+
176
+ /** a whole listing kept in place of the one before, in one transaction: a reader sees the old one or the new one */
177
+ export function keepListing(db: Database, record: Omit<ListingRecord, 'keptBytes' | 'objects' | 'bytes'>, rows: readonly Listed[]): ListingRecord {
178
+ spaceTables(db)
179
+ const sums = folderSums(rows)
180
+ const root = sums.find((s) => s.prefix === '')!
181
+ // about what sqlite spends on a row: its text, its numbers, the key's copy in the index
182
+ const keptBytes = rows.reduce((n, r) => n + r.key.length + 30, 0) + sums.reduce((n, s) => n + 3 * s.prefix.length + 60, 0)
183
+ const out: ListingRecord = { ...record, objects: root.objects, bytes: root.bytes, keptBytes }
184
+ db.transaction(() => {
185
+ db.query('delete from space_keys where space = ?').run(record.space)
186
+ db.query('delete from space_folders where space = ?').run(record.space)
187
+ const k = db.query('insert into space_keys (space, key, size, modified) values (?, ?, ?, ?)')
188
+ for (const r of rows) k.run(record.space, r.key, r.size, r.modified)
189
+ const f = db.query('insert into space_folders (space, prefix, parent, bytes, objects) values (?, ?, ?, ?, ?)')
190
+ for (const s of sums) f.run(record.space, s.prefix, s.parent, s.bytes, s.objects)
191
+ db.query('insert into space_listings (space, at, record) values (?, ?, ?) on conflict (space) do update set at = excluded.at, record = excluded.record').run(record.space, record.at, JSON.stringify(out))
192
+ })()
193
+ return out
194
+ }
195
+
196
+ /** the listing kept of a Space, null when none was ever kept */
197
+ export function keptListing(db: Database, space: string): ListingRecord | null {
198
+ if (!has(db)) return null
199
+ const r = db.query('select record from space_listings where space = ?').get(space) as { record: string } | null
200
+ if (r == null) return null
201
+ try {
202
+ return JSON.parse(r.record) as ListingRecord
203
+ } catch {
204
+ return null
205
+ }
206
+ }
207
+
208
+ /** the folders right under a folder, the biggest first */
209
+ export function subFolders(db: Database, space: string, prefix: string, limit = 500): FolderSum[] {
210
+ if (!has(db)) return []
211
+ return db.query('select prefix, parent, bytes, objects from space_folders where space = ? and parent = ? and prefix <> ? order by bytes desc, prefix limit ?').all(space, prefix, '', limit) as FolderSum[]
212
+ }
213
+
214
+ /** the objects right in a folder, the biggest first, and how many there are in all */
215
+ export function folderFiles(db: Database, space: string, prefix: string, limit = 200): { files: Listed[]; n: number; bytes: number } {
216
+ if (!has(db)) return { files: [], n: 0, bytes: 0 }
217
+ // the range of the folder's keys, and of those the ones with no further folder
218
+ const where = `space = ? and key >= ? and key < ? and instr(substr(key, ?), '/') = 0`
219
+ const args = [space, prefix, `${prefix}\u{10ffff}`, prefix.length + 1] as const
220
+ const files = db.query(`select key, size, modified from space_keys where ${where} order by size desc, key limit ?`).all(...args, limit) as Listed[]
221
+ const all = db.query(`select count(*) as n, coalesce(sum(size), 0) as bytes from space_keys where ${where}`).get(...args) as { n: number; bytes: number }
222
+ return { files, ...all }
223
+ }
224
+
225
+ /** the folder's own sums, null when the listing holds no such folder */
226
+ export function folderSum(db: Database, space: string, prefix: string): FolderSum | null {
227
+ if (!has(db)) return null
228
+ return (db.query('select prefix, parent, bytes, objects from space_folders where space = ? and prefix = ?').get(space, prefix) as FolderSum | null) ?? null
229
+ }
230
+
231
+ /** the objects whose key holds every word of `q`, or whose key is in `also` (the index's names that match), the
232
+ * biggest first */
233
+ export function findKeys(db: Database, space: string, q: string, also: readonly string[], limit = 200): { files: Listed[]; n: number } {
234
+ if (!has(db)) return { files: [], n: 0 }
235
+ const words = q.toLowerCase().split(/\s+/).filter((w) => w !== '')
236
+ if (words.length === 0) return { files: [], n: 0 }
237
+ const like = words.map(() => "instr(lower(key), ?) > 0").join(' and ')
238
+ const named = also.length === 0 ? '' : ` or key in (select value from json_each(?))`
239
+ const args = [space, ...words, ...(also.length === 0 ? [] : [JSON.stringify(also)])]
240
+ const where = `space = ? and ((${like})${named})`
241
+ const files = db.query(`select key, size, modified from space_keys where ${where} order by size desc, key limit ?`).all(...args, limit) as Listed[]
242
+ const n = (db.query(`select count(*) as n from space_keys where ${where}`).get(...args) as { n: number }).n
243
+ return { files, n }
244
+ }
245
+
246
+ /** is the key in the kept listing, at what size */
247
+ export function listedSize(db: Database, space: string, key: string): number | null {
248
+ if (!has(db)) return null
249
+ return (db.query('select size from space_keys where space = ? and key = ?').get(space, key) as { size: number } | null)?.size ?? null
250
+ }
251
+
252
+ /** every key the listing holds, for the join with the media index */
253
+ export function listedKeys(db: Database, space: string): Set<string> {
254
+ if (!has(db)) return new Set()
255
+ return new Set((db.query('select key from space_keys where space = ?').all(space) as { key: string }[]).map((r) => r.key))
256
+ }
@@ -1,12 +1,11 @@
1
1
  // the private S3 bucket that keeps every media file of the machine's store (wiki tools/shipkit/media-store.md), named by
2
2
  // the house config's `serve.mediaSpace`. Every object is PRIVATE but those under `public/`, and the key alone decides
3
3
  // (`aclOf`); never a bucket policy, never a public listing. A page reads a private one through a URL signed for one hour,
4
- // on the CDN edge. The key pair (`KEY:SECRET`) is read through the house's
5
- // `credsReadCommand`, held in memory only: never written to a file, never printed
4
+ // on the CDN edge. The key pair (`KEY:SECRET`) is read through the house
5
+ // store, held in memory only: never written to a file, never printed
6
6
  import { S3Client } from 'bun'
7
7
  import { mkdirSync, renameSync, rmSync } from 'node:fs'
8
8
  import { dirname } from 'node:path'
9
- import { readSecret } from '../smoke/run-smoke.ts'
10
9
 
11
10
  /** the house config's `serve.mediaSpace`: where the media store's files go up, and the NAME of the secret holding the key pair */
12
11
  export interface MediaSpace {
@@ -16,7 +15,7 @@ export interface MediaSpace {
16
15
  region: string
17
16
  /** the CDN edge a signed URL is handed out on */
18
17
  cdn?: string
19
- /** the secret whose value is `KEY:SECRET`, read through `credsReadCommand` */
18
+ /** the secret whose value is `KEY:SECRET`, read through the house store */
20
19
  secret: string
21
20
  }
22
21
 
@@ -56,7 +55,8 @@ export interface Space {
56
55
  /** the object written at `to`, through a file beside it renamed: no reader sees half of it */
57
56
  get(key: string, to: string): Promise<void>
58
57
  /** every object under the prefix, with its size, page after page (ListObjectsV2) */
59
- list(prefix: string): Promise<{ key: string; size: number }[]>
58
+ /** `modified`: the Space's own date of the object (LastModified), null when it gives none */
59
+ list(prefix: string): Promise<{ key: string; size: number; modified?: number | null }[]>
60
60
  /** the bucket's versioning: `Enabled`, `Suspended`, or `off` when it was never turned on (GetBucketVersioning) */
61
61
  versioning(): Promise<'Enabled' | 'Suspended' | 'off'>
62
62
  /** turns versioning on, so an object deleted or overwritten from outside keeps its older version (PutBucketVersioning) */
@@ -101,13 +101,31 @@ export function signedDelete(c: SpaceConfig, key: string, query: Record<string,
101
101
  }
102
102
 
103
103
  async function signed(c: SpaceConfig, method: 'GET' | 'PUT' | 'DELETE', key: string | null, query: Record<string, string>, body = ''): Promise<string> {
104
+ const r = await sign(c, method, key, query, { body })
105
+ const text = await r.text()
106
+ if (!r.ok) throw new Error(`${method} ${key ?? ''}?${new URL(r.url).search.slice(1)} on ${c.bucket}: ${r.status} ${/<Code>([^<]+)<\/Code>/.exec(text)?.[1] ?? text.slice(0, 200)}`)
107
+ return text
108
+ }
109
+
110
+ /** one SigV4 call (header auth) on the bucket (`key` null) or an object, its answer as it comes: the body unread, a
111
+ * stream a caller reads at its own pace, and any status. A body is hashed into the signature and sent with its MD5,
112
+ * so a part the network bent is refused by the bucket. No DELETE here: signedDelete is the one */
113
+ export async function signedFetch(c: SpaceConfig, method: 'GET' | 'HEAD' | 'PUT' | 'POST', key: string | null, query: Record<string, string>, o: Sending = {}): Promise<Response> {
114
+ return sign(c, method, key, query, o)
115
+ }
116
+
117
+ /** what a signed call sends beside its query: a body, an abort signal, a content type (not signed: S3 takes it as is) */
118
+ export type Sending = { body?: string | Uint8Array<ArrayBuffer>; signal?: AbortSignal; type?: string }
119
+
120
+ async function sign(c: SpaceConfig, method: 'GET' | 'HEAD' | 'PUT' | 'POST' | 'DELETE', key: string | null, query: Record<string, string>, o: Sending = {}): Promise<Response> {
121
+ const body = o.body ?? ''
104
122
  const base = c.path === true ? `${c.endpoint}/${c.bucket}` : c.endpoint
105
123
  const url = new URL(key === null ? (c.path === true ? base : `${base}/`) : `${base}/${s3enc(key, true)}`)
106
124
  const qs = Object.keys(query).sort().map((k) => `${s3enc(k)}=${s3enc(query[k]!)}`).join('&')
107
125
  url.search = qs
108
126
  const now = new Date().toISOString().replace(/[-:]|\.\d{3}/g, '')
109
127
  const day = now.slice(0, 8)
110
- const payload = sha256(body)
128
+ const payload = new Bun.CryptoHasher('sha256').update(body).digest('hex')
111
129
  const headers: Record<string, string> = { host: url.host, 'x-amz-content-sha256': payload, 'x-amz-date': now }
112
130
  const names = Object.keys(headers).sort()
113
131
  const canonical = [method, url.pathname, qs, ...names.map((n) => `${n}:${headers[n]}`), '', names.join(';'), payload].join('\n')
@@ -116,11 +134,9 @@ async function signed(c: SpaceConfig, method: 'GET' | 'PUT' | 'DELETE', key: str
116
134
  const k = hmac(hmac(hmac(hmac(`AWS4${c.creds.secretAccessKey}`, day), c.region), 's3'), 'aws4_request')
117
135
  const auth = `AWS4-HMAC-SHA256 Credential=${c.creds.accessKeyId}/${scope}, SignedHeaders=${names.join(';')}, Signature=${hex(hmac(k, toSign))}`
118
136
  const { host: _, ...sent } = headers
119
- const md5: Record<string, string> = body !== '' ? { 'Content-MD5': new Bun.CryptoHasher('md5').update(body).digest('base64') } : {}
120
- const r = await fetch(url, { method, headers: { ...sent, ...md5, Authorization: auth }, ...(body !== '' ? { body } : {}) })
121
- const text = await r.text()
122
- if (!r.ok) throw new Error(`${method} ${key ?? ''}?${qs} on ${c.bucket}: ${r.status} ${/<Code>([^<]+)<\/Code>/.exec(text)?.[1] ?? text.slice(0, 200)}`)
123
- return text
137
+ const md5: Record<string, string> = body.length > 0 ? { 'Content-MD5': new Bun.CryptoHasher('md5').update(body).digest('base64') } : {}
138
+ const type: Record<string, string> = o.type ? { 'Content-Type': o.type } : {}
139
+ return fetch(url, { method, headers: { ...sent, ...md5, ...type, Authorization: auth }, ...(body.length > 0 ? { body } : {}), ...(o.signal ? { signal: o.signal } : {}) })
124
140
  }
125
141
 
126
142
  const bucketCall = (c: SpaceConfig, method: 'GET' | 'PUT', sub: string, body = ''): Promise<string> => signedCall(c, method, null, { [sub]: '' }, body)
@@ -164,11 +180,11 @@ export function spaceOf(c: SpaceConfig): Space {
164
180
  }
165
181
  },
166
182
  async list(prefix) {
167
- const out: { key: string; size: number }[] = []
183
+ const out: { key: string; size: number; modified: number | null }[] = []
168
184
  let token: string | undefined
169
185
  do {
170
186
  const page = await client.list({ prefix, maxKeys: 1000, ...(token ? { continuationToken: token } : {}) })
171
- for (const o of page.contents ?? []) out.push({ key: o.key, size: o.size ?? 0 })
187
+ for (const o of page.contents ?? []) out.push({ key: o.key, size: o.size ?? 0, modified: o.lastModified == null ? null : new Date(o.lastModified).getTime() || null })
172
188
  token = page.isTruncated ? page.nextContinuationToken : undefined
173
189
  } while (token)
174
190
  return out
@@ -183,28 +199,33 @@ export function spaceOf(c: SpaceConfig): Space {
183
199
  }
184
200
  }
185
201
 
186
- let held: Promise<{ space: Space | null; why: string }> | null = null
202
+ /** how long a process holds the Space's key once read: a key rotated in the vault reaches the daemon and the web
203
+ * within this, with no restart */
204
+ export const SPACE_KEY_HELD_MS = 10 * 60_000
205
+ let held: { at: number; space: Promise<{ space: Space | null; why: string }> } | null = null
187
206
 
188
- /** the machine's Space, from the house config and its key, read once per process; null with the reason when there is none */
207
+ /** the machine's Space, from the house config and its key, held SPACE_KEY_HELD_MS; null with the reason when there is none */
189
208
  export function machineSpace(): Promise<{ space: Space | null; why: string }> {
190
- held ??= spaceFromHouse()
191
- return held
209
+ if (held == null || Date.now() - held.at > SPACE_KEY_HELD_MS) held = { at: Date.now(), space: spaceFromHouse() }
210
+ return held.space
192
211
  }
193
212
 
194
213
  /** the house's Space signed with the key pair of `secret` (the config's own key when none is given). A one time key
195
- * with more rights (turning versioning on) is read anew and never held; the house's own is held for the process */
214
+ * with more rights (turning versioning on) is read anew and never held; the house's own is held SPACE_KEY_HELD_MS */
196
215
  export async function spaceFromHouse(secret?: string): Promise<{ space: Space | null; why: string }> {
197
216
  const c = await houseSpaceConfig(secret)
198
217
  return { space: c.config ? spaceOf(c.config) : null, why: c.why }
199
218
  }
200
219
 
201
- let config: { config: SpaceConfig | null; why: string } | null = null
220
+ let config: { at: number; config: SpaceConfig | null; why: string } | null = null
202
221
 
203
222
  /** the house's Space as a config, the key pair read: what a hand signed call needs (forget.ts) */
204
223
  export async function houseSpaceConfig(secret?: string): Promise<{ config: SpaceConfig | null; why: string }> {
205
- if (secret === undefined && config) return config
224
+ // SHIPKIT_SPACES=off beats a house config read before; a test's own config (useSpaceConfig) stays its own
225
+ const injected = config?.at === Infinity
226
+ if (process.env.SHIPKIT_SPACES === 'off' && !injected) return { config: null, why: 'SHIPKIT_SPACES=off' }
227
+ if (secret === undefined && config && Date.now() - config.at <= SPACE_KEY_HELD_MS) return { config: config.config, why: config.why }
206
228
  const out = await (async (): Promise<{ config: SpaceConfig | null; why: string }> => {
207
- if (process.env.SHIPKIT_SPACES === 'off') return { config: null, why: 'SHIPKIT_SPACES=off' }
208
229
  const { houseRootOf } = await import('../home/home-start.ts')
209
230
  const { loadRepoConfig } = await import('../repo-config.ts')
210
231
  const house = houseRootOf(process.cwd())
@@ -212,11 +233,10 @@ export async function houseSpaceConfig(secret?: string): Promise<{ config: Space
212
233
  const c = await loadRepoConfig(house)
213
234
  const r = c.serve?.mediaSpace
214
235
  if (!r) return { config: null, why: `the house config (${house}) names no serve.mediaSpace` }
215
- if (!c.credsReadCommand) return { config: null, why: `the house config (${house}) declares no credsReadCommand to read ${r.secret}` }
216
236
  const name = secret ?? r.secret
217
237
  let v = ''
218
238
  try {
219
- v = readSecret(c.credsReadCommand, name)
239
+ v = await (await import('../secrets/read.ts')).readThrough(c.credsReadCommand, name)
220
240
  } catch (e) {
221
241
  return { config: null, why: (e as Error).message }
222
242
  }
@@ -224,16 +244,16 @@ export async function houseSpaceConfig(secret?: string): Promise<{ config: Space
224
244
  if (at <= 0) return { config: null, why: `the secret ${name} is no KEY:SECRET pair` }
225
245
  return { config: { ...r, cdn: r.cdn ?? null, creds: { accessKeyId: v.slice(0, at), secretAccessKey: v.slice(at + 1) } }, why: '' }
226
246
  })().catch((e: unknown) => ({ config: null, why: `the house config does not load: ${(e as Error).message}` }))
227
- if (secret === undefined && out.config) config = out
247
+ if (secret === undefined && out.config) config = { at: Date.now(), ...out }
228
248
  return out
229
249
  }
230
250
 
231
251
  /** a test's own Space config in place of the house's (forget.ts); undefined reads the house's again */
232
252
  export function useSpaceConfig(c: SpaceConfig | null | undefined): void {
233
- config = c === undefined ? null : { config: c, why: c ? '' : 'no Space in this test' }
253
+ config = c === undefined ? null : { at: Infinity, config: c, why: c ? '' : 'no Space in this test' }
234
254
  }
235
255
 
236
256
  /** a test's own Space in place of the machine's; undefined gives the machine's back */
237
257
  export function useSpace(space: Space | null | undefined): void {
238
- held = space === undefined ? null : Promise.resolve({ space, why: space ? '' : 'no Space in this test' })
258
+ held = space === undefined ? null : { at: Infinity, space: Promise.resolve({ space, why: space ? '' : 'no Space in this test' }) }
239
259
  }
@@ -33,12 +33,12 @@ export async function syncKind(kind: MediaKind, dir: string, o: { fill?: number
33
33
  const prefix = prefixOf(kind.kind)
34
34
  tryWrite(`the ${kind.kind} media of ${store}`, (db) => {
35
35
  const was = new Map(
36
- (db.query('select item, name, key, size, local, purged from files where store = ? and substr(key, 1, ?) = ?').all(store, prefix.length, prefix) as { item: string; name: string; key: string; size: number; local: number; purged: number | null }[]).map(
36
+ (db.query('select item, name, key, size, local, purged from media_files where store = ? and substr(key, 1, ?) = ?').all(store, prefix.length, prefix) as { item: string; name: string; key: string; size: number; local: number; purged: number | null }[]).map(
37
37
  (r) => [`${r.item}/${r.name}`, r],
38
38
  ),
39
39
  )
40
- const put = db.query('insert or replace into files (store, item, name, key, size, local, purged) values (?, ?, ?, ?, ?, ?, ?)')
41
- const obj = db.query('insert or ignore into objects (key, size) values (?, ?)')
40
+ const put = db.query('insert or replace into media_files (store, item, name, key, size, local, purged) values (?, ?, ?, ?, ?, ?, ?)')
41
+ const obj = db.query('insert or ignore into media_objects (key, size) values (?, ?)')
42
42
  const seen = new Set<string>()
43
43
  for (const r of rows) {
44
44
  const k = `${r.item}/${r.name}`
@@ -48,7 +48,7 @@ export async function syncKind(kind: MediaKind, dir: string, o: { fill?: number
48
48
  put.run(store, r.item, r.name, r.key, r.size, r.local, r.local === 1 ? null : (held?.purged ?? null))
49
49
  obj.run(r.key, r.size)
50
50
  }
51
- const drop = db.query('delete from files where store = ? and item = ? and name = ?')
51
+ const drop = db.query('delete from media_files where store = ? and item = ? and name = ?')
52
52
  for (const [k, r] of was) if (!seen.has(k)) drop.run(store, r.item, r.name)
53
53
  })
54
54
  return out
@@ -74,7 +74,7 @@ export function mediaCounts(): MediaCounts[] {
74
74
  const rows = db
75
75
  .query(
76
76
  `select f.store as store, substr(f.key, 1, instr(f.key, '/') - 1) as kind, f.local as local, f.size as size, o.up is not null as up, o.error as error
77
- from files f left join objects o on o.key = f.key`,
77
+ from media_files f left join media_objects o on o.key = f.key`,
78
78
  )
79
79
  .all() as { store: string; kind: string; local: number; size: number; up: number; error: string | null }[]
80
80
  const by = new Map<string, MediaCounts>()
@@ -0,0 +1,98 @@
1
+ // the machine's media index kept small (wiki tools/shipkit/media-store.md, The index), in the media job's child on a
2
+ // quiet pass: the review store's item reads of a code no process runs, or of a store that is gone, leave in small
3
+ // batches, then the file's free pages go back in steps. Each read of a store keeps one copy of every card a code
4
+ // (review/store.ts), so a day of edits to that code left 18 copies of 4,883 cards: 393 MB. The one constraint a reader
5
+ // breaks first: no step holds the file's lock for long, every other process writes its own reads beside it
6
+ import type { Database } from 'bun:sqlite'
7
+ import { existsSync } from 'node:fs'
8
+ import { yieldLoop } from '../core/loop-watch.ts'
9
+ import { vacuumSteps } from '../core/machine-db.ts'
10
+
11
+ /** the item reads of a code unused this long go, whatever else */
12
+ export const ITEM_READS_KEEP_MS = 24 * 3600_000
13
+ /** the codes a store keeps its reads for, the last used first: the daemon's and a session's, before and after an edit */
14
+ export const ITEM_READS_CODES = 2
15
+ /** a code read this recently runs in some process (each marks its code once an hour, review/store.ts): it keeps its
16
+ * reads whatever its rank, so a third live code never parses every card again at each tidy */
17
+ export const ITEM_READS_LIVE_MS = 2 * 3600_000
18
+ /** rows a step deletes: about 40 ms of the file's lock, measured on 4 kB rows */
19
+ const STEP = 1_000
20
+ /** the free pages go back to the disk when they are this many bytes, at most once a day, in steps of a few ms */
21
+ export const VACUUM_MIN_FREE = 32 * 1024 * 1024
22
+ export const VACUUM_EVERY_MS = 24 * 3600_000
23
+
24
+ export type Tidied = { codes: number; items: number; vacuumed: { before: number; after: number; ms: number } | null }
25
+
26
+ const pragma = (db: Database, name: string): number => Number(Object.values(db.query(`pragma ${name}`).get() as Record<string, number>)[0])
27
+ export const fileBytes = (db: Database): { total: number; free: number } => {
28
+ const size = pragma(db, 'page_size')
29
+ return { total: pragma(db, 'page_count') * size, free: pragma(db, 'freelist_count') * size }
30
+ }
31
+
32
+ /** the (store, code) pairs whose reads go: a store gone from the disk, a code past ITEM_READS_CODES of its store and
33
+ * idle ITEM_READS_LIVE_MS, or unused for ITEM_READS_KEEP_MS */
34
+ export function deadCodes(db: Database, now: number, exists: (dir: string) => boolean = existsSync): { store: string; code: string }[] {
35
+ const rows = db.query('select store, code, used, row_number() over (partition by store order by used desc, code) as r from media_codes').all() as { store: string; code: string; used: number; r: number }[]
36
+ const gone = new Map<string, boolean>()
37
+ const isGone = (s: string): boolean => {
38
+ let g = gone.get(s)
39
+ if (g === undefined) gone.set(s, (g = !exists(s)))
40
+ return g
41
+ }
42
+ const dead = rows.filter((r) => (r.r > ITEM_READS_CODES && r.used < now - ITEM_READS_LIVE_MS) || r.used < now - ITEM_READS_KEEP_MS || isGone(r.store)).map(({ store, code }) => ({ store, code }))
43
+ // reads of a code the codes table lost (an older writer): theirs go too
44
+ const orphans = db.query('select distinct store, code from media_items where (store, code) not in (select store, code from media_codes)').all() as { store: string; code: string }[]
45
+ return [...dead, ...orphans]
46
+ }
47
+
48
+ /** the dead reads out in steps, the loop given back between two; then the vacuum when it pays. `lastVacuum`: when the
49
+ * last one ran, null for never */
50
+ export async function tidyIndex(db: Database, o: { now: number; lastVacuum: number | null; exists?: (dir: string) => boolean; minFree?: number }): Promise<Tidied> {
51
+ const out: Tidied = { codes: 0, items: 0, vacuumed: null }
52
+ const step = db.query('delete from media_items where (store, code, id) in (select store, code, id from media_items where store = ? and code = ? limit ?)')
53
+ for (const d of deadCodes(db, o.now, o.exists)) {
54
+ for (;;) {
55
+ const n = db.transaction(() => step.run(d.store, d.code, STEP).changes).immediate()
56
+ out.items += n
57
+ await yieldLoop()
58
+ if (n < STEP) break
59
+ }
60
+ db.query('delete from media_codes where store = ? and code = ?').run(d.store, d.code)
61
+ out.codes++
62
+ }
63
+ // a fetch back of a store that is gone counts for nothing
64
+ db.query('delete from media_fetched where store not in (select distinct store from media_files)').run()
65
+ // the index shares the machine db: its free pages go back in steps, never by a VACUUM of the whole file
66
+ const f = fileBytes(db)
67
+ if (f.free >= (o.minFree ?? VACUUM_MIN_FREE) && (o.lastVacuum == null || o.now - o.lastVacuum >= VACUUM_EVERY_MS)) {
68
+ const t = performance.now()
69
+ const done = await vacuumSteps(db, yieldLoop)
70
+ if (done !== false) out.vacuumed = { before: f.total, after: fileBytes(db).total, ms: Math.round(performance.now() - t) }
71
+ }
72
+ return out
73
+ }
74
+
75
+ /** the tidy runs at most this often, on a pass of the media job that found nothing else to do */
76
+ export const TIDY_EVERY_MS = 10 * 60_000
77
+ const TIDIED_AT = 'media-tidied-at'
78
+ const VACUUMED_AT = 'media-vacuumed-at'
79
+
80
+ /** the media job's tidy of the index, in its child: its lines say what left and what the vacuum gave back */
81
+ export async function tidyTick(o: { print: (l: string) => void; printErr: (l: string) => void; now: number }): Promise<void> {
82
+ const { machineGet, machineSet } = await import('../core/machine-db.ts')
83
+ const { mediaDb } = await import('./db.ts')
84
+ if (o.now - (machineGet<number>(TIDIED_AT) ?? 0) < TIDY_EVERY_MS) return
85
+ machineSet(TIDIED_AT, o.now)
86
+ const db = mediaDb()
87
+ if (db == null) return
88
+ try {
89
+ const r = await tidyIndex(db, { now: o.now, lastVacuum: machineGet<number>(VACUUMED_AT) })
90
+ if (r.items > 0) o.print(`ok: media store: the reads of ${r.codes} codes no process runs left the index (${r.items} rows)`)
91
+ if (r.vacuumed != null) {
92
+ machineSet(VACUUMED_AT, o.now)
93
+ o.print(`ok: media store: the index vacuumed, ${Math.round(r.vacuumed.before / 1e6)} MB to ${Math.round(r.vacuumed.after / 1e6)} MB in ${r.vacuumed.ms} ms`)
94
+ }
95
+ } catch (e) {
96
+ o.printErr(`WARN media store: the tidy of the index stopped: ${(e as Error).message}`)
97
+ }
98
+ }
@@ -23,7 +23,7 @@ export function waitingObjects(o: { now?: number; limit?: number; store?: string
23
23
  const rows = db
24
24
  .query(
25
25
  `select o.key as key, o.size as size, min(f.store || char(0) || f.item || char(0) || f.name) as at
26
- from objects o join files f on f.key = o.key and f.local = 1
26
+ from media_objects o join media_files f on f.key = o.key and f.local = 1
27
27
  where o.up is null and o.next <= ? ${o.store ? 'and f.store = ?' : ''}
28
28
  group by o.key order by o.next, o.key limit ?`,
29
29
  )
@@ -79,9 +79,9 @@ export async function uploadWaiting(space: Space, o: { limit?: number; jobs?: nu
79
79
  const error = (e as Error).message
80
80
  out.failed.push({ key: w.key, error })
81
81
  tryWrite(`${w.key} failed`, (db) => {
82
- const r = db.query('select tries from objects where key = ?').get(w.key) as { tries: number } | null
82
+ const r = db.query('select tries from media_objects where key = ?').get(w.key) as { tries: number } | null
83
83
  const tries = (r?.tries ?? 0) + 1
84
- db.query('update objects set tries = ?, next = ?, error = ? where key = ?').run(tries, Date.now() + Math.min(RETRY_MS * 2 ** (tries - 1), RETRY_MAX_MS), error, w.key)
84
+ db.query('update media_objects set tries = ?, next = ?, error = ? where key = ?').run(tries, Date.now() + Math.min(RETRY_MS * 2 ** (tries - 1), RETRY_MAX_MS), error, w.key)
85
85
  })
86
86
  }
87
87
  done += w.size