rvlib-shipkit 2.26.0 → 2.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (442) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/package.json +1 -1
  3. package/src/agent-time/diet.ts +77 -0
  4. package/src/agent-time/family.ts +72 -0
  5. package/src/agent-time/hooks.ts +6 -4
  6. package/src/agent-time/limits.ts +44 -0
  7. package/src/agent-time/live.ts +1 -3
  8. package/src/agent-time/mask.ts +96 -18
  9. package/src/agent-time/refused.ts +45 -0
  10. package/src/agent-time/render.ts +122 -21
  11. package/src/agent-time/report-cache.ts +57 -0
  12. package/src/agent-time/report.ts +314 -40
  13. package/src/agent-time/shape.ts +50 -3
  14. package/src/agent-time/store.ts +320 -99
  15. package/src/agent-time/timeline.ts +140 -21
  16. package/src/agent-time/turns.ts +18 -8
  17. package/src/annex/offload.ts +17 -6
  18. package/src/annex/tidy.ts +70 -10
  19. package/src/asks/ask-after.ts +40 -0
  20. package/src/asks/asks-queue.ts +205 -47
  21. package/src/assets/kit-config.ts +7 -3
  22. package/src/assets/kits/identity-kit.ts +289 -10
  23. package/src/check.ts +3 -1
  24. package/src/checks/SK004-gitignore-policy.check.ts +12 -5
  25. package/src/checks/SK013-one-way-in-policy.check.ts +8 -3
  26. package/src/checks/SK026-asks-autoclose.check.ts +5 -5
  27. package/src/checks/SK028-readme.check.ts +7 -66
  28. package/src/checks/SK030-cache-audit.check.ts +6 -1
  29. package/src/checks/SK031-trace-audit.check.ts +2 -0
  30. package/src/checks/SK033-global-contribution.check.ts +3 -1
  31. package/src/checks/SK035-public-clean.check.ts +2 -2
  32. package/src/checks/SK043-scratch-on-the-mac.check.ts +59 -4
  33. package/src/checks/SK047-login-in-description.check.ts +36 -0
  34. package/src/checks/SK048-one-local-file.check.ts +36 -0
  35. package/src/cli/cmd_Asks.ts +71 -5
  36. package/src/cli/cmd_Backup.ts +2 -2
  37. package/src/cli/cmd_Capacity.ts +2 -2
  38. package/src/cli/cmd_CrossRepoActivity.ts +5 -4
  39. package/src/cli/cmd_Db.ts +253 -0
  40. package/src/cli/cmd_History.ts +212 -0
  41. package/src/cli/cmd_Home.ts +31 -3
  42. package/src/cli/cmd_Hq.ts +516 -0
  43. package/src/cli/cmd_Machines.ts +36 -0
  44. package/src/cli/cmd_Media.ts +38 -6
  45. package/src/cli/cmd_Reflect.ts +23 -2
  46. package/src/cli/cmd_Review.ts +548 -116
  47. package/src/cli/cmd_Secret.ts +62 -12
  48. package/src/cli/cmd_Social.ts +83 -1
  49. package/src/cli/cmd_Space.ts +324 -0
  50. package/src/cli/cmd_Time.ts +76 -5
  51. package/src/cli/cmd_Tmp.ts +28 -4
  52. package/src/cli/cmd_Trailer.ts +14 -10
  53. package/src/cli/cmd_Urls.ts +56 -0
  54. package/src/cli/cmd_Vault.ts +583 -0
  55. package/src/cli/family-help.ts +4 -2
  56. package/src/cli/family-pages.ts +1 -1
  57. package/src/cli/registry.ts +24 -3
  58. package/src/collections/actions.ts +63 -13
  59. package/src/collections/collection-types.ts +23 -1
  60. package/src/collections/providers.ts +117 -23
  61. package/src/collections/review.ts +4 -4
  62. package/src/contracts/contract-manifests.ts +6 -5
  63. package/src/contracts/contract-types.ts +6 -4
  64. package/src/contracts/contracts-engine.ts +11 -0
  65. package/src/contracts/manifests/chrome-web-store.contract.ts +31 -0
  66. package/src/core/budget.ts +12 -17
  67. package/src/core/capacity.ts +27 -18
  68. package/src/core/check-runner.ts +7 -4
  69. package/src/core/layout.ts +3 -0
  70. package/src/core/machine-busy.ts +127 -0
  71. package/src/core/machine-commit.ts +6 -1
  72. package/src/core/machine-db.ts +368 -20
  73. package/src/core/machine-layout.ts +137 -0
  74. package/src/core/machine-read.ts +81 -0
  75. package/src/core/migrate-layout.ts +1 -1
  76. package/src/core/one-way-in-policy.ts +64 -7
  77. package/src/core/polling-policy.ts +27 -0
  78. package/src/core/retention.ts +16 -2
  79. package/src/core/scope.ts +107 -14
  80. package/src/core/slots.ts +5 -4
  81. package/src/drill/clean.ts +25 -1
  82. package/src/drill/run.ts +1 -1
  83. package/src/drill/seal.ts +27 -4
  84. package/src/home/activity-shape.ts +2 -0
  85. package/src/home/activity.ts +66 -3
  86. package/src/home/app-sign.ts +15 -4
  87. package/src/home/daemon-jobs.ts +149 -7
  88. package/src/home/database-projects.ts +111 -0
  89. package/src/home/database-words.ts +203 -0
  90. package/src/home/databases.ts +460 -0
  91. package/src/home/global-units.ts +6 -0
  92. package/src/home/gui-app/ShipkitGui.swift +122 -1
  93. package/src/home/gui-app.ts +6 -3
  94. package/src/home/home-move.ts +514 -0
  95. package/src/home/home-paths.ts +12 -3
  96. package/src/home/home-routes.ts +68 -0
  97. package/src/home/inbox-shape.ts +24 -14
  98. package/src/home/machine-fold.ts +820 -0
  99. package/src/home/machine-host.ts +20 -5
  100. package/src/home/machine-repair.ts +503 -0
  101. package/src/home/machine-stores.ts +66 -15
  102. package/src/home/machine-temp.ts +547 -86
  103. package/src/home/resume.ts +79 -0
  104. package/src/home/run-daemon.ts +25 -4
  105. package/src/home/run-pm.ts +18 -5
  106. package/src/home/serve-daemon.ts +18 -3
  107. package/src/home/serve-web.ts +175 -7
  108. package/src/home/space-job.ts +115 -0
  109. package/src/home/space-page.ts +257 -0
  110. package/src/home/space-route.ts +167 -0
  111. package/src/home/space-words.ts +103 -0
  112. package/src/home/time-page-shape.ts +202 -0
  113. package/src/home/time-page.ts +64 -0
  114. package/src/home/vault-page.ts +482 -0
  115. package/src/home/vault-words.ts +132 -0
  116. package/src/hooks/leak-guard.ts +40 -13
  117. package/src/hooks/one-way-in-guard.ts +17 -4
  118. package/src/hq/cards.ts +581 -0
  119. package/src/hq/door-route.ts +43 -0
  120. package/src/hq/door.ts +163 -0
  121. package/src/hq/files-send.ts +348 -0
  122. package/src/hq/forgotten-log.ts +35 -0
  123. package/src/hq/history-check.ts +255 -0
  124. package/src/hq/history-place.ts +146 -0
  125. package/src/hq/history-send.ts +487 -0
  126. package/src/hq/hq-db.ts +99 -0
  127. package/src/hq/hq-local.ts +469 -0
  128. package/src/hq/hq-routes.ts +196 -0
  129. package/src/hq/hq-store.ts +599 -0
  130. package/src/hq/kinds/ask.ts +147 -0
  131. package/src/hq/kinds/card-gone.ts +83 -0
  132. package/src/hq/kinds/card-msg.ts +66 -0
  133. package/src/hq/kinds/card.ts +99 -0
  134. package/src/hq/kinds/index.ts +21 -0
  135. package/src/hq/kinds/kind.ts +126 -0
  136. package/src/hq/kinds/media.ts +125 -0
  137. package/src/hq/kinds/prompt.ts +219 -0
  138. package/src/hq/kinds/reflection.ts +128 -0
  139. package/src/hq/kinds/report.ts +55 -0
  140. package/src/hq/kinds/time-day.ts +236 -0
  141. package/src/hq/ledger.ts +473 -0
  142. package/src/hq/machine-key.ts +44 -0
  143. package/src/hq/machine-notes.ts +131 -0
  144. package/src/hq/outbox.ts +372 -0
  145. package/src/hq/replica.ts +168 -0
  146. package/src/hq/repo-id.ts +4 -0
  147. package/src/hq/report-facts.ts +117 -0
  148. package/src/hq/report.ts +274 -0
  149. package/src/hq/switch.ts +151 -0
  150. package/src/hq/vault-grant.ts +92 -0
  151. package/src/identities/identities.ts +15 -3
  152. package/src/identities/steps.ts +31 -0
  153. package/src/ledger/db.ts +73 -26
  154. package/src/ledger/gate-checks.ts +6 -2
  155. package/src/ledger/run-log.ts +11 -3
  156. package/src/ledger/store.ts +26 -4
  157. package/src/media-store/backup/daemon.ts +25 -17
  158. package/src/media-store/backup/kept.ts +241 -0
  159. package/src/media-store/backup/restore.ts +14 -4
  160. package/src/media-store/backup/run.ts +11 -11
  161. package/src/media-store/backup/secret.ts +6 -4
  162. package/src/media-store/backup/snapshot.ts +4 -2
  163. package/src/media-store/backup/sources.ts +67 -16
  164. package/src/media-store/copy/config.ts +77 -0
  165. package/src/media-store/copy/copy.ts +194 -0
  166. package/src/media-store/copy/lifecycle.ts +43 -0
  167. package/src/media-store/copy/night.ts +90 -0
  168. package/src/media-store/copy/proof.ts +151 -0
  169. package/src/media-store/copy/snapshot.ts +152 -0
  170. package/src/media-store/copy/store.ts +62 -0
  171. package/src/media-store/copy/stream.ts +176 -0
  172. package/src/media-store/daemon.ts +66 -16
  173. package/src/media-store/db.ts +22 -11
  174. package/src/media-store/forget.ts +23 -3
  175. package/src/media-store/hand.ts +4 -3
  176. package/src/media-store/hq-find.ts +75 -0
  177. package/src/media-store/hq-send.ts +277 -0
  178. package/src/media-store/kind.ts +2 -0
  179. package/src/media-store/purge.ts +18 -15
  180. package/src/media-store/put.ts +24 -8
  181. package/src/media-store/remote.ts +16 -7
  182. package/src/media-store/space-listing.ts +240 -0
  183. package/src/media-store/space.ts +40 -21
  184. package/src/media-store/sync.ts +5 -5
  185. package/src/media-store/tidy.ts +98 -0
  186. package/src/media-store/upload.ts +3 -3
  187. package/src/media-store/webp.ts +66 -0
  188. package/src/messages/model.ts +16 -7
  189. package/src/messages/routes.ts +14 -4
  190. package/src/messages/score.ts +2 -2
  191. package/src/messages/suggest.ts +96 -0
  192. package/src/pages/frame-client.ts +10 -0
  193. package/src/plan/planner.ts +28 -17
  194. package/src/recordings/media-kind.ts +1 -0
  195. package/src/recordings/model.ts +1 -1
  196. package/src/recordings/recorder-app/Capture.swift +9 -7
  197. package/src/reflect/hq-corpus.ts +56 -0
  198. package/src/reflect/prompt-corpus.ts +3 -1
  199. package/src/reflect/transcript.ts +129 -37
  200. package/src/release/machine-words.ts +67 -0
  201. package/src/release/public-clean.ts +8 -3
  202. package/src/releases/from-card.ts +1 -1
  203. package/src/releases/routes.ts +10 -5
  204. package/src/releases/store.ts +10 -1
  205. package/src/repo-config.ts +32 -2
  206. package/src/review/anim.ts +2 -2
  207. package/src/review/auto.ts +2 -2
  208. package/src/review/card-db.ts +244 -0
  209. package/src/review/card-rows.ts +266 -0
  210. package/src/review/cells.ts +76 -5
  211. package/src/review/draft-card.ts +41 -0
  212. package/src/review/draft-model.ts +78 -0
  213. package/src/review/format.ts +29 -10
  214. package/src/review/gone.ts +98 -0
  215. package/src/review/inbox-hook.ts +4 -4
  216. package/src/review/marks.ts +1 -1
  217. package/src/review/media-kind.ts +7 -5
  218. package/src/review/media-read.ts +9 -7
  219. package/src/review/media.ts +32 -5
  220. package/src/review/model.ts +202 -39
  221. package/src/review/move.ts +491 -0
  222. package/src/review/notes.ts +12 -20
  223. package/src/review/previews.ts +15 -19
  224. package/src/review/project.ts +1 -1
  225. package/src/review/rev.ts +8 -0
  226. package/src/review/role.ts +1 -1
  227. package/src/review/routes.ts +64 -13
  228. package/src/review/stage-card.ts +8 -4
  229. package/src/review/stage-routes.ts +1 -1
  230. package/src/review/store.ts +529 -83
  231. package/src/review/thread-fold.ts +51 -0
  232. package/src/review/threads.ts +147 -9
  233. package/src/review/trailer-auto-mock.ts +63 -0
  234. package/src/review/trailer-card.ts +4 -4
  235. package/src/review/trailer-desk.ts +41 -7
  236. package/src/review/trailer-media.ts +1 -0
  237. package/src/review/trailer-model.ts +8 -0
  238. package/src/review/trailer-notes.ts +1 -1
  239. package/src/review/trailer-routes.ts +9 -1
  240. package/src/review/unit.ts +6 -6
  241. package/src/review/watchers.ts +1 -1
  242. package/src/rules/untrack-generated.ts +92 -8
  243. package/src/secrets/held.ts +16 -0
  244. package/src/secrets/keychain.ts +113 -0
  245. package/src/secrets/list.ts +16 -6
  246. package/src/secrets/manager.ts +24 -10
  247. package/src/secrets/read.ts +257 -0
  248. package/src/secrets/who-reads.ts +49 -0
  249. package/src/serve/door-forward.ts +268 -0
  250. package/src/serve/door-names.ts +47 -0
  251. package/src/serve/embed.ts +1 -1
  252. package/src/serve/hub-app/activity-view.tsx +56 -32
  253. package/src/serve/hub-app/activity.css +7 -1
  254. package/src/serve/hub-app/asks-page.tsx +48 -0
  255. package/src/serve/hub-app/asks-st.ts +25 -0
  256. package/src/serve/hub-app/clock-svc.ts +1 -2
  257. package/src/serve/hub-app/col-card.tsx +64 -13
  258. package/src/serve/hub-app/col-list-page.tsx +122 -0
  259. package/src/serve/hub-app/col-list-st.ts +103 -0
  260. package/src/serve/hub-app/col-tables-view.tsx +10 -41
  261. package/src/serve/hub-app/col-tables.ts +76 -8
  262. package/src/serve/hub-app/cols-svc.ts +70 -16
  263. package/src/serve/hub-app/database-st.ts +260 -0
  264. package/src/serve/hub-app/database-view.tsx +289 -0
  265. package/src/serve/hub-app/database.css +32 -0
  266. package/src/serve/hub-app/entry-bar.css +14 -0
  267. package/src/serve/hub-app/entry-bar.tsx +33 -0
  268. package/src/serve/hub-app/entry-pick.ts +31 -0
  269. package/src/serve/hub-app/floating.tsx +1 -0
  270. package/src/serve/hub-app/hash-route.ts +11 -1
  271. package/src/serve/hub-app/header-bar.tsx +14 -18
  272. package/src/serve/hub-app/home-st.ts +89 -9
  273. package/src/serve/hub-app/home-strip.css +5 -19
  274. package/src/serve/hub-app/home-strip.tsx +58 -92
  275. package/src/serve/hub-app/home.html +7 -0
  276. package/src/serve/hub-app/hub-app.tsx +31 -142
  277. package/src/serve/hub-app/hub-types.ts +3 -1
  278. package/src/serve/hub-app/hub.css +109 -23
  279. package/src/serve/hub-app/icons.tsx +18 -1
  280. package/src/serve/hub-app/identities-st.ts +56 -6
  281. package/src/serve/hub-app/identities-view.tsx +100 -58
  282. package/src/serve/hub-app/identities.css +17 -15
  283. package/src/serve/hub-app/identity-address.ts +5 -0
  284. package/src/serve/hub-app/inbox-st.ts +41 -24
  285. package/src/serve/hub-app/inbox-view.tsx +37 -41
  286. package/src/serve/hub-app/inbox.css +2 -5
  287. package/src/serve/hub-app/index.html +7 -0
  288. package/src/serve/hub-app/kept-cols.tsx +7 -0
  289. package/src/serve/hub-app/keys.ts +28 -15
  290. package/src/serve/hub-app/later.tsx +26 -0
  291. package/src/serve/hub-app/list-filter.tsx +14 -0
  292. package/src/serve/hub-app/list-walk.ts +72 -3
  293. package/src/serve/hub-app/machines-st.ts +251 -0
  294. package/src/serve/hub-app/machines-view.tsx +224 -0
  295. package/src/serve/hub-app/machines.css +76 -0
  296. package/src/serve/hub-app/md-copy.tsx +79 -0
  297. package/src/serve/hub-app/media-view.tsx +2 -0
  298. package/src/serve/hub-app/messages/messages-page.tsx +79 -7
  299. package/src/serve/hub-app/messages/messages-st.ts +99 -3
  300. package/src/serve/hub-app/messages.css +14 -0
  301. package/src/serve/hub-app/page-keys.ts +175 -0
  302. package/src/serve/hub-app/pages-frames.tsx +11 -3
  303. package/src/serve/hub-app/palette-st.ts +58 -11
  304. package/src/serve/hub-app/palette-view.tsx +3 -1
  305. package/src/serve/hub-app/project-list.css +54 -8
  306. package/src/serve/hub-app/project-list.tsx +128 -59
  307. package/src/serve/hub-app/projects-svc.ts +78 -7
  308. package/src/serve/hub-app/reader-chips.tsx +13 -0
  309. package/src/serve/hub-app/readme-view.tsx +2 -3
  310. package/src/serve/hub-app/readme.css +27 -5
  311. package/src/serve/hub-app/reflections-page.tsx +42 -0
  312. package/src/serve/hub-app/reflections-st.ts +17 -0
  313. package/src/serve/hub-app/releases/releases-page.tsx +25 -2
  314. package/src/serve/hub-app/releases/releases-st.ts +1 -1
  315. package/src/serve/hub-app/repo-sections.ts +9 -5
  316. package/src/serve/hub-app/repo-st.ts +35 -8
  317. package/src/serve/hub-app/review/draft-card.tsx +163 -0
  318. package/src/serve/hub-app/review/kit.tsx +50 -7
  319. package/src/serve/hub-app/review/note-place.ts +1 -1
  320. package/src/serve/hub-app/review/review-board.tsx +2 -2
  321. package/src/serve/hub-app/review/review-cells.tsx +145 -65
  322. package/src/serve/hub-app/review/review-kit.ts +27 -1
  323. package/src/serve/hub-app/review/review-list.tsx +68 -30
  324. package/src/serve/hub-app/review/review-page.tsx +7 -8
  325. package/src/serve/hub-app/review/review-st.ts +111 -24
  326. package/src/serve/hub-app/review/review-thread.tsx +49 -19
  327. package/src/serve/hub-app/review/review-views.tsx +475 -144
  328. package/src/serve/hub-app/review/thread-control-st.ts +115 -0
  329. package/src/serve/hub-app/review/thread-control.tsx +74 -0
  330. package/src/serve/hub-app/review/thread-st.ts +73 -26
  331. package/src/serve/hub-app/review/trailer-card.tsx +1 -1
  332. package/src/serve/hub-app/review/trailer-page.tsx +37 -16
  333. package/src/serve/hub-app/review/trailer-st.ts +41 -7
  334. package/src/serve/hub-app/review.css +267 -61
  335. package/src/serve/hub-app/side-lists.ts +72 -0
  336. package/src/serve/hub-app/sidebar.tsx +6 -3
  337. package/src/serve/hub-app/site/site-part.tsx +2 -8
  338. package/src/serve/hub-app/site/site-st.ts +4 -4
  339. package/src/serve/hub-app/social/comms-page.tsx +20 -5
  340. package/src/serve/hub-app/social/kit.tsx +30 -4
  341. package/src/serve/hub-app/social/post-card.tsx +139 -49
  342. package/src/serve/hub-app/social/serial-writes.ts +13 -0
  343. package/src/serve/hub-app/social/social-model.ts +11 -0
  344. package/src/serve/hub-app/social/social-page.tsx +94 -35
  345. package/src/serve/hub-app/social/social-st.ts +120 -36
  346. package/src/serve/hub-app/social/stage-popup.tsx +1 -1
  347. package/src/serve/hub-app/social/stage-st.ts +1 -1
  348. package/src/serve/hub-app/social/step-layout.ts +1 -1
  349. package/src/serve/hub-app/social.css +3 -0
  350. package/src/serve/hub-app/space-st.ts +209 -0
  351. package/src/serve/hub-app/space-view.tsx +196 -0
  352. package/src/serve/hub-app/space.css +27 -0
  353. package/src/serve/hub-app/stores/stores-page.tsx +91 -23
  354. package/src/serve/hub-app/stores/stores-st.ts +44 -19
  355. package/src/serve/hub-app/stores.css +6 -1
  356. package/src/serve/hub-app/theme-st.ts +22 -9
  357. package/src/serve/hub-app/time-charts.tsx +291 -0
  358. package/src/serve/hub-app/time-pages.tsx +749 -0
  359. package/src/serve/hub-app/time-st.ts +162 -0
  360. package/src/serve/hub-app/time-view.tsx +76 -0
  361. package/src/serve/hub-app/time.css +138 -0
  362. package/src/serve/hub-app/tree-build.ts +52 -42
  363. package/src/serve/hub-app/tree-row.tsx +4 -4
  364. package/src/serve/hub-app/tree-svc.ts +18 -9
  365. package/src/serve/hub-app/urls-svc.ts +154 -0
  366. package/src/serve/hub-app/urls-view.tsx +117 -0
  367. package/src/serve/hub-app/urls.css +30 -0
  368. package/src/serve/hub-app/vault-st.ts +127 -0
  369. package/src/serve/hub-app/vault-view.tsx +154 -0
  370. package/src/serve/hub-app/vault.css +38 -0
  371. package/src/serve/hub-app/veille/veille-st.ts +12 -10
  372. package/src/serve/hub-app/waiting-svc.ts +29 -0
  373. package/src/serve/hub-app/wikis-view.tsx +2 -2
  374. package/src/serve/hub-runtime.ts +15 -2
  375. package/src/serve/project-gutter-route.ts +27 -14
  376. package/src/serve/project-gutter.ts +25 -12
  377. package/src/serve/same-origin.ts +10 -0
  378. package/src/serve/serve-hub.ts +13 -4
  379. package/src/shipkit-files.ts +16 -2
  380. package/src/shipkit.ts +1 -1
  381. package/src/shot/shooter.ts +616 -420
  382. package/src/shot/shot-ask.ts +246 -155
  383. package/src/site/desk.ts +2 -2
  384. package/src/smoke/run-smoke.ts +3 -2
  385. package/src/social/cover.ts +202 -0
  386. package/src/social/discord-layout.ts +37 -13
  387. package/src/social/drafts.ts +3 -0
  388. package/src/social/load.ts +23 -2
  389. package/src/social/media-kind.ts +2 -1
  390. package/src/social/publish/discord.ts +5 -2
  391. package/src/social/publish/secret.ts +2 -2
  392. package/src/social/release-stage.ts +28 -13
  393. package/src/social/routes.ts +26 -1
  394. package/src/social/stage.ts +1 -1
  395. package/src/social/stats.ts +12 -9
  396. package/src/social/strip.ts +4 -1
  397. package/src/social/thumbnail.ts +255 -0
  398. package/src/stores/collection.ts +15 -11
  399. package/src/stores/desk.ts +236 -42
  400. package/src/stores/model.ts +72 -6
  401. package/src/stores/routes.ts +37 -12
  402. package/src/stores/unit.ts +14 -8
  403. package/src/suite/judge-suites.ts +41 -11
  404. package/src/suite/select.ts +45 -3
  405. package/src/suite/suite-cli.ts +16 -10
  406. package/src/trailer/bed.ts +1 -1
  407. package/src/trailer/build.ts +134 -21
  408. package/src/trailer/ffmpeg.ts +7 -0
  409. package/src/trailer/fonts.ts +3 -2
  410. package/src/trailer/grammar.ts +201 -2
  411. package/src/trailer/graph.ts +42 -5
  412. package/src/trailer/look.ts +21 -0
  413. package/src/trailer/mock.ts +154 -0
  414. package/src/trailer/passage.ts +65 -26
  415. package/src/trailer/score/heard.ts +89 -0
  416. package/src/trailer/score/sound.ts +14 -8
  417. package/src/trailer/sound/run.ts +16 -6
  418. package/src/trailer/stitch.ts +26 -5
  419. package/src/trailer/titles.ts +82 -19
  420. package/src/trailer/versions.ts +1 -3
  421. package/src/trailer/vertical.ts +3 -1
  422. package/src/urls/frame.ts +195 -0
  423. package/src/urls/routes.ts +43 -0
  424. package/src/urls/rows.ts +171 -0
  425. package/src/urls/unit.ts +73 -0
  426. package/src/vault/house-keys.ts +42 -0
  427. package/src/vault/layout.ts +50 -0
  428. package/src/vault/policy.ts +165 -0
  429. package/src/vault/vault-audit.ts +276 -0
  430. package/src/vault/vault-client.ts +40 -0
  431. package/src/vault/vault-config.ts +159 -0
  432. package/src/vault/vault-destroy.ts +78 -0
  433. package/src/vault/vault-handover.ts +305 -0
  434. package/src/vault/vault-http.ts +352 -0
  435. package/src/vault/vault-import.ts +208 -0
  436. package/src/vault/vault-init.ts +328 -0
  437. package/src/vault/vault-minter.ts +271 -0
  438. package/src/vault/vault-restore.ts +333 -0
  439. package/src/vault/vault-serve.ts +342 -0
  440. package/src/vault/vault-snapshot.ts +281 -0
  441. package/src/veille/asks.ts +1 -1
  442. package/src/veille/desk.ts +2 -2
@@ -0,0 +1,491 @@
1
+ // the move of a store's cards between its two backends (wiki tools/shipkit/threads-store.md): its files into the rows
2
+ // (`sk thread move --go`), the rows back into files (`sk thread move --back --go`, `sk thread export`). Both directions keep
3
+ // the later of two heads and every message by its id, so a move run twice, or stopped and run again, does what is left
4
+ // and nothing else. The one constraint a reader breaks first: nothing here deletes or rewrites a file or a row another
5
+ // write made later; a head the other side holds later stays, and is named
6
+ import { copyFileSync, existsSync, linkSync, mkdirSync, readdirSync, readFileSync, statSync } from 'node:fs'
7
+ import { dirname, join, relative } from 'node:path'
8
+ import { rowsGone, rowsGoneCreated, rowsIO, rowsKeepGone, type CardBackend } from './card-rows.ts'
9
+ import { GONE, goneFolderCreated, goneFolders } from './gone.ts'
10
+ import { ID_RE, itemProblems, mediaFilesOf, MESSAGE_RE, messageProblems, type Message } from './model.ts'
11
+ import { revOf } from './rev.ts'
12
+ import { BUSY_MS } from '../ledger/db.ts'
13
+ import { filesIO } from './store.ts'
14
+
15
+ /** what one pass did for one store: heads and messages written, cards set aside carried, cards both sides hold alike,
16
+ * a line for each one left as it was, a line for each file that does not read */
17
+ export type Moved = { dir: string; cards: number; heads: number; msgs: number; gone: number; same: number; files: number; kept: string[]; broken: string[]; media?: { copied: number; missing: string[] }; read: { id: string; msgs: string[] }[] }
18
+
19
+ const fresh = (dir: string): Moved => ({ dir, cards: 0, heads: 0, msgs: 0, gone: 0, same: 0, files: 0, kept: [], broken: [], read: [] })
20
+
21
+ /** the files of a card's folder that are its media (its pictures, clips, posters, a message's image), never its head,
22
+ * its messages or its lock: what the rows keep in the spool */
23
+ function mediaOf(folder: string): string[] {
24
+ if (!existsSync(folder)) return []
25
+ const out: string[] = []
26
+ const walk = (d: string): void => {
27
+ for (const e of readdirSync(d, { withFileTypes: true })) {
28
+ const f = join(d, e.name)
29
+ const rel = relative(folder, f)
30
+ if (e.isDirectory()) {
31
+ if (e.name !== '.lock') walk(f)
32
+ } else if (!/^item(\.replaced)?\.json$/.test(rel) && !(rel.startsWith('thread/') && rel.endsWith('.json')) && !e.name.endsWith('.tmp')) out.push(rel)
33
+ }
34
+ }
35
+ walk(folder)
36
+ return out
37
+ }
38
+
39
+ /** a card's media the other side lacks, linked there (copied across two disks): the side they come from stays as it is */
40
+ function carryMedia(id: string, from: CardBackend, to: CardBackend, out: Moved, dry: boolean): void {
41
+ const src = from.folder(id)
42
+ const dst = to.folder(id)
43
+ if (src === dst) return
44
+ for (const rel of mediaOf(src)) {
45
+ const t = join(dst, rel)
46
+ if (existsSync(t)) continue
47
+ out.files++
48
+ if (dry) continue
49
+ mkdirSync(dirname(t), { recursive: true })
50
+ try {
51
+ linkSync(join(src, rel), t)
52
+ } catch {
53
+ copyFileSync(join(src, rel), t)
54
+ }
55
+ }
56
+ }
57
+
58
+ /** a card from one backend into the other: its head when the target lacks it or holds an older one, each message the
59
+ * target lacks. The head the target holds later stays */
60
+ /** the cards a side set aside, as `<id> <created>`: a card the other side still holds is not carried back over its
61
+ * deletion */
62
+ function goneOf(dir: string, rows: boolean): Set<string> {
63
+ if (rows) return new Set(rowsGone(dir).map((g) => `${g.id} ${rowsGoneCreated(dir, g.entry) ?? ''}`))
64
+ try {
65
+ return new Set(goneFolders(dir).map((g) => `${g.id} ${goneFolderCreated(dir, g.entry) ?? ''}`))
66
+ } catch {
67
+ return new Set()
68
+ }
69
+ }
70
+
71
+ /** one card carried from one side into the other while a move runs: a verb of a process that read the switch before it
72
+ * turned made it on the side the move left */
73
+ export function carryCard(dir: string, id: string, from: CardBackend, to: CardBackend): void {
74
+ copyCard(id, from, to, fresh(dir), false, goneOf(dir, to.rows))
75
+ }
76
+
77
+ function copyCard(id: string, from: CardBackend, to: CardBackend, out: Moved, dry: boolean, gone: ReadonlySet<string>): void {
78
+ let h: { head: unknown; at: number } | null
79
+ try {
80
+ h = from.head(id)
81
+ } catch (e) {
82
+ out.broken.push(`${id}: ${(e as Error).message}`)
83
+ return
84
+ }
85
+ if (h == null) {
86
+ if (!from.rows) out.broken.push(`${id}: a folder with no item.json`)
87
+ return
88
+ }
89
+ const problems = itemProblems(h.head)
90
+ if (problems.length > 0 || (h.head as { id?: unknown }).id !== id) {
91
+ out.broken.push(`${id}: ${problems.join('; ') || 'another id in its head'}`)
92
+ return
93
+ }
94
+ if (to.head(id) == null && gone.has(`${id} ${String((h.head as { created?: unknown }).created ?? '')}`)) {
95
+ out.kept.push(`${id}: deleted on the other side, it stays deleted`)
96
+ return
97
+ }
98
+ const msgs: Message[] = []
99
+ for (const mid of from.threadIds(id)) {
100
+ try {
101
+ const m = from.message(id, mid)
102
+ const p = MESSAGE_RE.test(mid) ? messageProblems(m, mid) : ['no message name']
103
+ if (p.length > 0) out.broken.push(`${id}/${mid}: ${p.join('; ')}`)
104
+ else msgs.push(m as Message)
105
+ } catch (e) {
106
+ out.broken.push(`${id}/${mid}: ${(e as Error).message}`)
107
+ }
108
+ }
109
+ out.cards++
110
+ let there: { head: unknown; at: number } | null = null
111
+ try {
112
+ there = to.head(id)
113
+ } catch (e) {
114
+ out.kept.push(`${id}: its head on the other side does not read (${(e as Error).message}), it stays as it is`)
115
+ return
116
+ }
117
+ if (there != null && (there.head as { created?: unknown }).created !== (h.head as { created?: unknown }).created) {
118
+ out.kept.push(`${id}: another card of that id is on the other side, made at another moment: each stays`)
119
+ return
120
+ }
121
+ if (there == null || revOf(there.head) !== revOf(h.head)) {
122
+ if (there != null && there.at > h.at) out.kept.push(`${id}: the other side holds a later head, it stays`)
123
+ else {
124
+ if (!dry) {
125
+ if (!to.rows) mkdirSync(to.folder(id), { recursive: true })
126
+ // the head it replaces is an earlier write of the same card on this machine
127
+ to.write(id, h.head, h.at)
128
+ }
129
+ out.heads++
130
+ }
131
+ } else out.same++
132
+ for (const m of msgs) {
133
+ if (to.hasMessage(id, m.id)) {
134
+ if (revOf(to.message(id, m.id)) !== revOf(m)) out.kept.push(`${id}/${m.id}: another message of that id is on the other side, each stays`)
135
+ continue
136
+ }
137
+ if (!dry) to.append(id, m)
138
+ out.msgs++
139
+ }
140
+ out.read.push({ id, msgs: msgs.map((m) => m.id) })
141
+ carryMedia(id, from, to, out, dry)
142
+ }
143
+
144
+ /** every card file of a store the rows lack, into the rows, with its cards set aside. `dry` counts and writes nothing */
145
+ export function importFiles(dir: string, o: { dry?: boolean } = {}): Moved {
146
+ const out = fresh(dir)
147
+ const from = filesIO(dir)
148
+ const to = rowsIO(dir)
149
+ const deleted = goneOf(dir, true)
150
+ for (const id of from.names()) {
151
+ if (!ID_RE.test(id)) continue
152
+ copyCard(id, from, to, out, o.dry === true, deleted)
153
+ }
154
+ const held = new Set(rowsGone(dir).map((g) => g.entry))
155
+ let gone: { id: string; entry: string }[] = []
156
+ try {
157
+ gone = goneFolders(dir)
158
+ } catch (e) {
159
+ out.broken.push(`${GONE}: ${(e as Error).message}`)
160
+ }
161
+ for (const g of gone) {
162
+ if (held.has(g.entry)) continue
163
+ const folder = join(dir, GONE, g.entry)
164
+ try {
165
+ const head = JSON.parse(readFileSync(join(folder, 'item.json'), 'utf8')) as { created?: unknown }
166
+ const t = join(folder, 'thread')
167
+ const thread = existsSync(t) ? readdirSync(t).filter((n) => n.endsWith('.json')).sort().map((n) => JSON.parse(readFileSync(join(t, n), 'utf8')) as unknown) : []
168
+ if (!o.dry) rowsKeepGone(dir, { entry: g.entry, id: g.id, created: typeof head.created === 'string' ? head.created : '', at: Math.floor(statSync(folder).ctimeMs), head, thread })
169
+ out.gone++
170
+ } catch (e) {
171
+ out.broken.push(`${GONE}/${g.entry}: ${(e as Error).message}`)
172
+ }
173
+ }
174
+ return out
175
+ }
176
+
177
+ /** every card of the rows into files: the store's own folder (`--back`), or a folder of its own (`to`, an export, with
178
+ * the media files this machine holds). `ids`: those cards only. A card the rows set aside that the files still hold
179
+ * goes aside in the files too */
180
+ export function exportRows(dir: string, o: { to?: string; ids?: readonly string[]; dry?: boolean } = {}): Moved {
181
+ const out = fresh(dir)
182
+ const from = rowsIO(dir)
183
+ const target = o.to ?? dir
184
+ const to = filesIO(target)
185
+ const ids = o.ids ?? from.names()
186
+ const deleted = goneOf(target, false)
187
+ for (const id of ids) {
188
+ if (!from.has(id)) {
189
+ out.kept.push(`${id}: no card of that id in the rows`)
190
+ continue
191
+ }
192
+ const was = out.files
193
+ copyCard(id, from, to, out, o.dry === true, deleted)
194
+ if (o.to != null && !o.dry) {
195
+ out.media ??= { copied: 0, missing: [] }
196
+ out.media.copied += out.files - was
197
+ const x = from.raw(id)
198
+ // a file the Space holds and this disk let go: said, the export does not fetch it
199
+ for (const name of x == null ? [] : mediaFilesOf(x)) if (!existsSync(join(from.folder(id), name))) out.media.missing.push(`${id}/${name}`)
200
+ }
201
+ }
202
+ if (o.to == null && o.ids == null)
203
+ for (const g of rowsGone(dir)) {
204
+ const cur = to.head(g.id)
205
+ const created = (cur?.head as { created?: unknown } | undefined)?.created
206
+ if (cur == null || created !== rowsGoneCreated(dir, g.entry)) continue
207
+ if (!o.dry) to.setAside(g.id, { created: String(created) })
208
+ out.gone++
209
+ }
210
+ return out
211
+ }
212
+
213
+ /** what an import read that the rows do not hold: a card, or a message of one */
214
+ function unproven(p: Moved): string[] {
215
+ const rows = rowsIO(p.dir)
216
+ return p.read.flatMap((r) => (rows.has(r.id) ? r.msgs.filter((m) => !rows.hasMessage(r.id, m)).map((m) => `message ${r.id}/${m}`) : [`card ${r.id}`]))
217
+ }
218
+
219
+ /** what the files hold that the rows do not, by name and rev: a head the rows lack or hold older, a message they lack.
220
+ * Empty once a move took everything */
221
+ export function filesNotInRows(dir: string): string[] {
222
+ const files = filesIO(dir)
223
+ const rows = rowsIO(dir)
224
+ const deleted = goneOf(dir, true)
225
+ const out: string[] = []
226
+ for (const id of files.names()) {
227
+ if (!ID_RE.test(id)) continue
228
+ let h: { head: unknown; at: number } | null
229
+ try {
230
+ h = files.head(id)
231
+ } catch {
232
+ continue
233
+ }
234
+ if (h == null || itemProblems(h.head).length > 0) continue
235
+ const r = rows.head(id)
236
+ // a card the rows set aside after the move began: deleted, not missing
237
+ if (r == null && deleted.has(`${id} ${String((h.head as { created?: unknown }).created ?? '')}`)) continue
238
+ if (r == null) out.push(`card ${id}`)
239
+ else if (revOf(r.head) !== revOf(h.head) && !(r.at > h.at)) out.push(`card ${id} (another head)`)
240
+ for (const mid of files.threadIds(id))
241
+ if (!rows.hasMessage(id, mid)) {
242
+ try {
243
+ if (messageProblems(files.message(id, mid), mid).length === 0) out.push(`message ${id}/${mid}`)
244
+ } catch {
245
+ // a message that does not read is the broken line of the move
246
+ }
247
+ }
248
+ }
249
+ return out
250
+ }
251
+
252
+ /** a pass's lines, one a store that did something */
253
+ function passLines(passes: readonly Moved[], would: boolean): string[] {
254
+ const w = would ? 'would ' : ''
255
+ const lines: string[] = []
256
+ for (const p of passes) {
257
+ if (p.heads + p.msgs + p.gone + p.files > 0 || would) lines.push(`${p.dir}: ${p.cards} cards, ${w}write ${p.heads} heads and ${p.msgs} messages, ${w === '' ? '' : 'would '}carry ${p.files} media files, ${p.gone} cards set aside, ${p.same} alike`)
258
+ for (const k of p.kept.slice(0, 5)) lines.push(` kept: ${k}`)
259
+ if (p.kept.length > 5) lines.push(` kept: and ${p.kept.length - 5} more`)
260
+ // a folder that does not read stays a folder: never a row, never lost, said here
261
+ if (p.broken.length > 0) lines.push(` ${p.broken.length} files do not read and stay as they are (${p.broken.slice(0, 3).join('; ')})`)
262
+ }
263
+ return lines
264
+ }
265
+
266
+ /** how long a writer may still commit to the store it read: its switch read (at most a second old), then a commit that
267
+ * waits its turn on the daemon's file (the busy timeout); the move reads the old store again after it */
268
+ export const MOVE_LAG_MS = 1000 + BUSY_MS + 1000
269
+
270
+ /** the line a machine whose cards are rows says at every move and every health pass: a shipkit older than the switch
271
+ * reads the files alone, so it would show none of the cards made since the move */
272
+ export const BACK_FIRST = 'the review cards of this machine are rows of the daemon\'s database: run `sk thread move --back --go` before any older shipkit runs here (a revert, a checkout, an older install)'
273
+
274
+ export type MoveOptions = {
275
+ dry: boolean
276
+ /** what the hq lacks of this machine's files, a line each; empty when both sides are equal; null skips (no hq) */
277
+ hqDiff?: () => Promise<string[] | null>
278
+ /** how long another process may still write what it read of the switch */
279
+ lagMs?: number
280
+ }
281
+
282
+ /** the move of this machine's cards into the rows: the files imported, every one proven in the rows, the switch on, the
283
+ * files read again after the lag for a writer that had not seen it. The files stay where they are, untouched */
284
+ export async function moveGo(stores: readonly string[], o: MoveOptions): Promise<{ ok: boolean; lines: string[] }> {
285
+ return o.dry ? goOnce(stores, o) : moving(o, () => goOnce(stores, o))
286
+ }
287
+
288
+ /** a move's run, its window said to every process: a verb that misses its card finds it on the other side meanwhile */
289
+ async function moving<T>(o: MoveOptions, fn: () => Promise<T>): Promise<T> {
290
+ const { setCardsMoving } = await import('../hq/switch.ts')
291
+ setCardsMoving(Date.now() + 2 * (o.lagMs ?? MOVE_LAG_MS) + 10 * 60_000)
292
+ try {
293
+ return await fn()
294
+ } finally {
295
+ setCardsMoving(null)
296
+ }
297
+ }
298
+
299
+ async function goOnce(stores: readonly string[], o: MoveOptions): Promise<{ ok: boolean; lines: string[] }> {
300
+ const { cardsInDb, setCardsInDb } = await import('../hq/switch.ts')
301
+ const lines: string[] = []
302
+ // the look asks the hq too: it says what --go would refuse
303
+ if (o.hqDiff != null) {
304
+ const d = await o.hqDiff()
305
+ if (d != null && d.length > 0) return { ok: false, lines: [`the hq and this machine do not hold the same cards (the check hq-cards): ${o.dry ? '--go would refuse, ' : ''}nothing moves until they do`, ...d] }
306
+ }
307
+ const first = stores.map((d) => importFiles(d, { dry: o.dry }))
308
+ lines.push(...passLines(first, o.dry))
309
+ if (o.dry) return { ok: true, lines: [`the switch cards-in-db is ${cardsInDb() ? 'on' : 'off'}`, ...lines] }
310
+ // the proof: every card and message the import read is in the rows. A writer still on the files may write after the
311
+ // read: that is the second pass's, after the switch and its lag
312
+ const left = first.flatMap((p) => unproven(p).map((l) => `${p.dir}: ${l}`))
313
+ if (left.length > 0) return { ok: false, lines: [...lines, `${left.length} rows the files hold are not in the rows after the import: the switch stays off`, ...left.slice(0, 20)] }
314
+ const was = cardsInDb()
315
+ if (!was && !setCardsInDb(true)) return { ok: false, lines: [...lines, 'the machine db does not open: the switch stays off'] }
316
+ // a writer that read the switch off before it moved may still write a file: read the files once more after it
317
+ await Bun.sleep(o.lagMs ?? MOVE_LAG_MS)
318
+ const second = stores.map((d) => importFiles(d))
319
+ const late = passLines(second, false)
320
+ const after = stores.flatMap((d) => filesNotInRows(d).map((l) => `${d}: ${l}`))
321
+ return {
322
+ ok: after.length === 0,
323
+ lines: [
324
+ ...lines,
325
+ ...(late.length > 0 ? ['read again after the switch:', ...late] : []),
326
+ ...(after.length > 0 ? [`WARN ${after.length} files written after the switch are not in the rows: run sk thread move --go again`, ...after.slice(0, 20)] : []),
327
+ `ok: the switch cards-in-db is on${was ? ' (it was already)' : ''}: every card is read and written in the daemon's database; the files stay where they are, untouched (sk thread move --back --go goes back)`,
328
+ ],
329
+ }
330
+ }
331
+
332
+ /** each media file a card of the rows names that neither the spool nor the repo's folder holds (the media store sent it
333
+ * up and let it go), with the fetch that gives it back into the spool */
334
+ function onlyInSpace(dir: string): { what: string; fetch: () => Promise<string | null> }[] {
335
+ const rows = rowsIO(dir)
336
+ const out: { what: string; fetch: () => Promise<string | null> }[] = []
337
+ for (const id of rows.names()) {
338
+ const x = rows.raw(id)
339
+ if (x == null) continue
340
+ for (const name of mediaFilesOf(x)) {
341
+ const here = join(rows.folder(id), name)
342
+ if (existsSync(here) || existsSync(join(dir, id, name))) continue
343
+ const f = x.item.media?.[name]
344
+ const what = `${id}/${name}`
345
+ if (f == null) {
346
+ out.push({ what: `${what} (its head keeps no fact of it)`, fetch: async () => null })
347
+ continue
348
+ }
349
+ out.push({
350
+ what,
351
+ fetch: async () => {
352
+ const { fetchBack } = await import('../media-store/remote.ts')
353
+ const { reviewKey } = await import('./media-read.ts')
354
+ mkdirSync(dirname(here), { recursive: true })
355
+ return fetchBack(here, reviewKey(f, name), f, { store: dirname(rows.folder(id)), item: id, name })
356
+ },
357
+ })
358
+ }
359
+ }
360
+ return out
361
+ }
362
+
363
+ /** the way back: every card of the rows written into the files (a card made since included), the switch off, the rows
364
+ * written out again after the lag. The rows stay */
365
+ export async function moveBack(all: readonly string[], o: MoveOptions): Promise<{ ok: boolean; lines: string[] }> {
366
+ return o.dry ? backOnce(all, o) : moving(o, () => backOnce(all, o))
367
+ }
368
+
369
+ async function backOnce(all: readonly string[], o: MoveOptions): Promise<{ ok: boolean; lines: string[] }> {
370
+ const { cardsInDb, setCardsInDb } = await import('../hq/switch.ts')
371
+ // one folder a repo: a worktree shares its checkout's rows, which go back into the checkout's folder alone
372
+ const { repoIdOf } = await import('./card-db.ts')
373
+ const seen = new Set<string>()
374
+ const stores = all.filter((d) => {
375
+ const id = repoIdOf(d)
376
+ if (seen.has(id)) return false
377
+ seen.add(id)
378
+ return true
379
+ })
380
+ // the files go back whole: a media file the spool let go comes back from the Space first, or nothing moves
381
+ const away = stores.flatMap((d) => onlyInSpace(d))
382
+ if (o.dry && away.length > 0) {
383
+ const lines = passLines(stores.map((d) => exportRows(d, { dry: true })), true)
384
+ return { ok: true, lines: [`the switch cards-in-db is ${cardsInDb() ? 'on' : 'off'}`, ...lines, `${away.length} media files are only in the Space: --back --go fetches them first, and refuses if the Space is not reached`] }
385
+ }
386
+ const lacking: string[] = []
387
+ for (const a of away) if ((await a.fetch()) == null) lacking.push(a.what)
388
+ if (lacking.length > 0) return { ok: false, lines: [`${lacking.length} media files would be lacking in the files: neither this disk nor the Space gives them back, nothing moved`, ...lacking.slice(0, 20)] }
389
+ const first = stores.map((d) => exportRows(d, { dry: o.dry }))
390
+ const lines = passLines(first, o.dry)
391
+ if (away.length > 0) lines.push(`${away.length} media files fetched back from the Space first`)
392
+ if (o.dry) return { ok: true, lines: [`the switch cards-in-db is ${cardsInDb() ? 'on' : 'off'}`, ...lines] }
393
+ const was = cardsInDb()
394
+ if (was && !setCardsInDb(false)) return { ok: false, lines: [...lines, 'the machine db does not open: the switch stays on'] }
395
+ await Bun.sleep(o.lagMs ?? MOVE_LAG_MS)
396
+ const second = stores.map((d) => exportRows(d))
397
+ const late = passLines(second, false)
398
+ return { ok: true, lines: [...lines, ...(late.length > 0 ? ['written out again after the switch:', ...late] : []), `ok: the switch cards-in-db is off${was ? '' : ' (it was already)'}: the files are the store again; the rows stay in the daemon's database`] }
399
+ }
400
+
401
+ /** what the tidy asks outside the store: the names of a repo's rows the hq does not hold at their rev (`card <id>`,
402
+ * `card-msg <id>/<message>`), or why it cannot say; and whether the Space holds a file */
403
+ export type TidyProof = {
404
+ hqLacks: (dir: string) => Promise<Set<string> | { refused: string }>
405
+ up: (key: string, size: number) => Promise<boolean>
406
+ }
407
+
408
+ /** where a folder goes before it is removed: a tidy killed between the two leaves it there, and the next one ends it */
409
+ const TIDY = '.tidy'
410
+
411
+ /** the files of the cards that also live as rows, removed from each repo once the rows hold all of them, the hq holds
412
+ * them, and their media are in the Space; never while the switch is off. A look by default. After it, the way back
413
+ * writes the files again from the rows */
414
+ export async function tidyFiles(stores: readonly string[], o: { dry: boolean; proof: TidyProof }): Promise<{ ok: boolean; lines: string[] }> {
415
+ const { cardsInDb } = await import('../hq/switch.ts')
416
+ if (!cardsInDb()) return { ok: false, lines: ['the switch cards-in-db is off: the files are the store, the tidy removes nothing'] }
417
+ const { reviewKey } = await import('./media-read.ts')
418
+ const { renameSync, rmSync } = await import('node:fs')
419
+ const lines: string[] = []
420
+ let removed = 0
421
+ let kept = 0
422
+ for (const dir of stores) {
423
+ if (!o.dry && existsSync(join(dir, TIDY))) rmSync(join(dir, TIDY), { recursive: true, force: true })
424
+ const files = filesIO(dir)
425
+ const rows = rowsIO(dir)
426
+ const ids = files.names().filter((n) => ID_RE.test(n))
427
+ if (ids.length === 0) continue
428
+ const lacks = await o.proof.hqLacks(dir)
429
+ if (!(lacks instanceof Set)) {
430
+ lines.push(`${dir}: ${ids.length} card folders stay: ${lacks.refused}`)
431
+ kept += ids.length
432
+ continue
433
+ }
434
+ const stay: string[] = []
435
+ let gone = 0
436
+ for (const id of ids) {
437
+ const why = await keepWhy(dir, id, files, rows, lacks, o.proof, reviewKey)
438
+ if (why != null) {
439
+ stay.push(`${id}: ${why}`)
440
+ continue
441
+ }
442
+ gone++
443
+ if (o.dry) continue
444
+ const aside = join(dir, TIDY, id)
445
+ mkdirSync(dirname(aside), { recursive: true })
446
+ renameSync(join(dir, id), aside)
447
+ rmSync(aside, { recursive: true, force: true })
448
+ }
449
+ if (!o.dry) rmSync(join(dir, TIDY), { recursive: true, force: true })
450
+ removed += gone
451
+ kept += stay.length
452
+ lines.push(`${dir}: ${o.dry ? 'would remove' : 'removed'} ${gone} card folders, ${stay.length} stay`)
453
+ for (const s of stay.slice(0, 5)) lines.push(` stays: ${s}`)
454
+ if (stay.length > 5) lines.push(` stays: and ${stay.length - 5} more`)
455
+ }
456
+ lines.push(`${o.dry ? 'a look: nothing removed. ' : ''}${removed} card folders ${o.dry ? 'would go' : 'gone'}, ${kept} stay; after it, sk thread move --back --go writes the files again from the rows, the media fetched back from the Space`)
457
+ return { ok: true, lines }
458
+ }
459
+
460
+ /** why a card's folder stays, null when it may go: the rows hold its head (the same, or a later one of the same card)
461
+ * and each of its messages at the same rev, the hq holds every one of them, and the Space each media file it holds */
462
+ async function keepWhy(dir: string, id: string, files: CardBackend, rows: CardBackend, lacks: ReadonlySet<string>, proof: TidyProof, keyOf: (f: { sha: string }, name: string) => string): Promise<string | null> {
463
+ let h: { head: unknown; at: number } | null
464
+ try {
465
+ h = files.head(id)
466
+ } catch (e) {
467
+ return `its head does not read (${(e as Error).message})`
468
+ }
469
+ if (h == null) return 'a folder with no head'
470
+ // the only copy of a head another machine's change replaced: the way back does not write it again
471
+ if (existsSync(join(dir, id, 'item.replaced.json'))) return 'it holds a replaced head (item.replaced.json), kept nowhere else'
472
+ const r = rows.head(id)
473
+ if (r == null) return 'its rows lack it'
474
+ const created = (x: unknown): unknown => (x as { created?: unknown }).created
475
+ if (revOf(r.head) !== revOf(h.head) && !(created(r.head) === created(h.head) && r.at >= h.at)) return 'its rows differ from its files'
476
+ const mids = files.threadIds(id)
477
+ for (const m of mids) {
478
+ if (!rows.hasMessage(id, m)) return `its rows lack the message ${m}`
479
+ if (revOf(rows.message(id, m)) !== revOf(files.message(id, m))) return `its message ${m} differs in the rows`
480
+ }
481
+ if (lacks.has(`card ${id}`) || mids.some((m) => lacks.has(`card-msg ${id}/${m}`))) return 'the hq does not hold all of it'
482
+ const x = files.raw(id)
483
+ const media = (x?.item.media ?? {}) as Record<string, { sha: string; size: number }>
484
+ for (const name of x == null ? [] : mediaFilesOf(x)) {
485
+ if (!existsSync(join(dir, id, name))) continue
486
+ const f = media[name]
487
+ if (f == null) return `its file ${name} has no fact in its head`
488
+ if (!(await proof.up(keyOf(f, name), f.size))) return `its file ${name} is not in the Space`
489
+ }
490
+ return null
491
+ }
@@ -1,16 +1,16 @@
1
- // his notes on one thing a desk shows (a store page's picture or field, a draft): the first an item of the one store,
2
- // its subject the thing, so the review page and `sk review inbox` hold it; the next ones, while that thread is open,
3
- // his replies on it, never a second item. The one path for a note on a thing (wiki tools/shipkit/stores.md)
4
- import { stateOf, subjectKey, type Origin, type ReviewItem, type Subject } from './model.ts'
5
- import { addMessage, raiseItem, readAll, specOf } from './store.ts'
6
- import { membersOf, threadsOf, type Thread } from './threads.ts'
1
+ // his notes on one thing a desk shows (a store page's picture or field, a draft): each an item of the one store with its
2
+ // own state, so an agent owes it and closes it, its subject the thing; it reads in the thread its address has, never a
3
+ // second thread (threads.ts threadsOf). The one path for a note on a thing (wiki tools/shipkit/threads-raised-notes.md)
4
+ import { addressesOf, stateOf, type Item, type Origin, type ReviewItem, type Subject } from './model.ts'
5
+ import { raiseItem, readAll, specOf } from './store.ts'
6
+ import { addressesOfThread, membersOf, threadOfAddress, threadsOf, type Thread } from './threads.ts'
7
7
 
8
8
  /** one note as a desk shows it: the owner's words, where it stands, the agent's last word once answered */
9
9
  export type SubjectNote = { id: string; at: string; text: string; state: string; answer?: string }
10
10
 
11
11
  const keyIn = (dir: string) => {
12
12
  const spec = specOf(dir)
13
- return (s: Subject): string | null => subjectKey(s, spec)
13
+ return (s: Subject): string | null => addressesOf({ subject: s, origin: { by: 'owner', from: 'desk' }, views: [] } as unknown as Item, spec)[0] ?? null
14
14
  }
15
15
 
16
16
  /** every word of his on the thing's threads, the first note and each reply, with the thread's state and last answer */
@@ -36,9 +36,8 @@ function notesOfThreads(threads: readonly Thread[]): SubjectNote[] {
36
36
  export function notesBy(dir: string, items: readonly ReviewItem[]): (subject: Subject) => SubjectNote[] {
37
37
  const key = keyIn(dir)
38
38
  const by = new Map<string, Thread[]>()
39
- for (const t of threadsOf(items))
40
- for (const k of new Set(membersOf(t).map((x) => key(x.item.subject))))
41
- if (k !== null) by.set(k, [...(by.get(k) ?? []), t])
39
+ const spec = specOf(dir)
40
+ for (const t of threadsOf(items, spec)) for (const k of addressesOfThread(t, spec)) by.set(k, [...(by.get(k) ?? []), t])
42
41
  return (subject) => {
43
42
  const k = key(subject)
44
43
  if (k === null) throw new Error(`notes: a ${subject.kind} names no one thing`)
@@ -46,7 +45,8 @@ export function notesBy(dir: string, items: readonly ReviewItem[]): (subject: Su
46
45
  }
47
46
  }
48
47
 
49
- /** his note on the thing: a reply on its thread still open, else a new item titled `<name> : <first line>` */
48
+ /** his note on the thing: a raised item titled `<name> : <first line>`, read in the thread its address has; the id of
49
+ * that thread's head, or of the note when it starts its own */
50
50
  export async function noteOn(
51
51
  dir: string,
52
52
  o: { subject: Subject; origin: Extract<Origin, { by: 'owner' }>; name: string; text: string; topic?: string; image?: string; what?: string },
@@ -56,14 +56,6 @@ export async function noteOn(
56
56
  const text = o.text.trim()
57
57
  if (k === null) throw new Error(`note: a ${o.subject.kind} names no one thing`)
58
58
  if (!text) throw new Error('note: the text is empty')
59
- const open = threadsOf(readAll(dir).items)
60
- .filter((t) => membersOf(t).some((x) => key(x.item.subject) === k))
61
- .filter((t) => stateOf(t.head, false).state !== 'closed')
62
- .sort((a, b) => b.head.item.created.localeCompare(a.head.item.created))[0]?.head.item.id
63
- if (open) {
64
- addMessage(dir, open, 'owner', text)
65
- return { id: open }
66
- }
67
59
  const head = `${o.name} : ${text.split('\n')[0] ?? ''}`
68
60
  const x = await raiseItem(dir, {
69
61
  subject: o.subject,
@@ -74,6 +66,6 @@ export async function noteOn(
74
66
  ...(o.image ? { image: o.image } : {}),
75
67
  ...(o.what ? { what: o.what } : {}),
76
68
  })
77
- return { id: x.item.id }
69
+ return { id: threadOfAddress(k, readAll(dir).items, specOf(dir), { up: true })?.head.item.id ?? x.item.id }
78
70
  }
79
71
 
@@ -1,4 +1,4 @@
1
- // a view's image at the size the page draws it, a clip as the page plays it (wiki tools/shipkit/review-store.md,
1
+ // a view's image at the size the page draws it, a clip as the page plays it (wiki tools/shipkit/threads-store.md,
2
2
  // Previews, A clip's play copy): made once per media file, kept in the repo's cache
3
3
  // (`.shipkit/cache/review-previews/<id>/<name>.<size>.<webp|mp4>`, local, never in the store), made again only when its
4
4
  // source is newer. The full file is fetched only on zoom and download
@@ -7,8 +7,11 @@ import { dirname, join } from 'node:path'
7
7
  import { LAYOUT } from '../core/layout.ts'
8
8
  import { ffmpeg } from '../trailer/ffmpeg.ts'
9
9
  import { FILE_RE, firstView, ID_RE, isGallery, isPair, thumbFileOf, type Item, type ReviewItem, type ReviewView } from './model.ts'
10
- import { probe, stillAt } from './media.ts'
10
+ import { isBlack, probe, stillAt } from './media.ts'
11
11
  import { ensureLocal, remotePreviewUrl, remoteUrl } from './media-read.ts'
12
+ import { mediaDir, rawHead } from './store.ts'
13
+ import { cardsInDb } from '../hq/switch.ts'
14
+ import { spoolOf } from './card-db.ts'
12
15
 
13
16
  /** `thumb` a list row's picture, `fit` a view in the card column: the widest each is drawn, at 2x */
14
17
  export const PREVIEW_W = { thumb: 480, fit: 1600 } as const
@@ -48,8 +51,9 @@ async function slot<T>(work: () => Promise<T>): Promise<T> {
48
51
  }
49
52
  }
50
53
 
51
- /** the preview folder of a store: `<repo>/.shipkit/cache/review-previews`, the store being `<repo>/.shipkit/review` */
52
- export const previewDir = (dir: string): string => join(dirname(dirname(dir)), LAYOUT.cache, 'review-previews')
54
+ /** the preview folder of a store: `<repo>/.shipkit/cache/review-previews`, the store being `<repo>/.shipkit/review`;
55
+ * with the cards as rows, `.previews` in the media spool, so nothing of a card is written in the repo */
56
+ export const previewDir = (dir: string): string => (cardsInDb() ? join(spoolOf(dir), '.previews') : join(dirname(dirname(dir)), LAYOUT.cache, 'review-previews'))
53
57
 
54
58
  /** what a preview of a file is: a webp of an image, the play copy of a clip; null for any other file or size */
55
59
  const kindOf = (name: string, size: PreviewSize): 'image' | 'clip' | null => (IMAGE.test(name) ? 'image' : CLIP.test(name) && size === 'fit' ? 'clip' : null)
@@ -61,7 +65,7 @@ const outOf = (dir: string, id: string, name: string, size: PreviewSize): string
61
65
  /** the item.json of a card as a preview reads it: its media facts and its views */
62
66
  const headOf = (dir: string, id: string): Pick<Item, 'media' | 'views'> => {
63
67
  try {
64
- return JSON.parse(readFileSync(join(dir, id, 'item.json'), 'utf8')) as Item
68
+ return (rawHead(dir, id)?.head as Item | undefined) ?? { views: [] }
65
69
  } catch {
66
70
  return { views: [] }
67
71
  }
@@ -78,7 +82,7 @@ const lengthOf = (views: readonly ReviewView[], name: string): number | undefine
78
82
  export function playsCopy(dir: string, id: string, name: string): boolean {
79
83
  if (!ID_RE.test(id) || !FILE_RE.test(name) || !CLIP.test(name)) return false
80
84
  const head = headOf(dir, id)
81
- const bytes = statSync(join(dir, id, name), { throwIfNoEntry: false })?.size ?? head.media?.[name]?.size
85
+ const bytes = statSync(join(mediaDir(dir), id, name), { throwIfNoEntry: false })?.size ?? head.media?.[name]?.size
82
86
  const seconds = lengthOf(head.views, name)
83
87
  return bytes !== undefined && seconds !== undefined && seconds > 0 && (bytes * 8) / seconds > PLAY_OVER
84
88
  }
@@ -92,7 +96,7 @@ export async function previewFile(dir: string, id: string, name: string, size: P
92
96
  if (!kind) return null
93
97
  if (kind === 'clip' && !playsCopy(dir, id, name)) return ensureLocal(dir, id, name)
94
98
  const out = outOf(dir, id, name, size)
95
- const here = join(dir, id, name)
99
+ const here = join(mediaDir(dir), id, name)
96
100
  if (!existsSync(here) && existsSync(out)) return out
97
101
  const src = await ensureLocal(dir, id, name)
98
102
  if (!src) return null
@@ -138,7 +142,7 @@ export async function previewOrRemote(dir: string, id: string, name: string, siz
138
142
  if (!ID_RE.test(id) || !FILE_RE.test(name)) return null
139
143
  const kind = kindOf(name, size)
140
144
  if (!kind) return null
141
- const here = join(dir, id, name)
145
+ const here = join(mediaDir(dir), id, name)
142
146
  if (kind === 'clip' && !playsCopy(dir, id, name)) {
143
147
  if (existsSync(here)) return { file: here }
144
148
  const url = await remoteUrl(dir, id, name)
@@ -153,25 +157,17 @@ export async function previewOrRemote(dir: string, id: string, name: string, siz
153
157
  }
154
158
 
155
159
  const POSTER = /^(v\d+-)?poster\.png$/
156
- /** a picture whose brightest channel averages under this is black: a trailer's first frame fades in from black */
157
- const BLACK = 12
158
160
  /** where in a clip a poster is looked for when its first frame is black, a share of its length */
159
161
  const TRIES = [0.1, 0.25, 0.5]
160
162
 
161
- const isBlack = async (png: string): Promise<boolean> => {
162
- const { default: sharp } = await import('sharp')
163
- // read as bytes: libvips caches by file name, and the still is written again at the same path
164
- const st = await sharp(readFileSync(png)).stats()
165
- return Math.max(...st.channels.slice(0, 3).map((c) => c.mean)) < BLACK
166
- }
167
-
168
163
  /** a clip's poster for its preview: the poster itself, or when it is black (a trailer opens on black) the first frame
169
164
  * further in that is not; the clip's file is the poster's view's video, or its after on a pair */
170
165
  async function litStill(dir: string, id: string, name: string, poster: string, out: string): Promise<string> {
171
166
  if (!(await isBlack(poster))) return poster
172
167
  const prefix = name.slice(0, name.length - 'poster.png'.length)
173
168
  const clipRe = new RegExp(`^${prefix}(video|after)\\.(mp4|webm)$`)
174
- const clip = readdirSync(join(dir, id)).find((f) => clipRe.test(f)) ?? Object.keys(headOf(dir, id).media ?? {}).find((f) => clipRe.test(f))
169
+ // a card of the rows that came from another machine has no folder here: its head names its clip
170
+ const clip = (existsSync(join(mediaDir(dir), id)) ? readdirSync(join(mediaDir(dir), id)) : []).find((f) => clipRe.test(f)) ?? Object.keys(headOf(dir, id).media ?? {}).find((f) => clipRe.test(f))
175
171
  const video = clip ? await ensureLocal(dir, id, clip) : null
176
172
  if (!video) return poster
177
173
  const still = `${out}.still.png`
@@ -228,7 +224,7 @@ export async function playCopies(dir: string, item: Pick<Item, 'id' | 'views'>,
228
224
  .filter((n) => playsCopy(dir, item.id, n))
229
225
  .map(async (n) => {
230
226
  const t0 = performance.now()
231
- const src = join(dir, item.id, n)
227
+ const src = join(mediaDir(dir), item.id, n)
232
228
  const out = await previewFile(dir, item.id, n, 'fit')
233
229
  const took = ((performance.now() - t0) / 1000).toFixed(1)
234
230
  if (!out || out === src) return `play copy of ${n}: FAIL after ${took} s, the hub plays the clip itself`