rvlib-shipkit 2.25.0 → 2.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (456) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/package.json +2 -2
  3. package/src/agent-time/diet.ts +77 -0
  4. package/src/agent-time/family.ts +72 -0
  5. package/src/agent-time/hooks.ts +331 -0
  6. package/src/agent-time/limits.ts +44 -0
  7. package/src/agent-time/live.ts +1 -3
  8. package/src/agent-time/mask.ts +96 -18
  9. package/src/agent-time/refused.ts +45 -0
  10. package/src/agent-time/render.ts +130 -17
  11. package/src/agent-time/report-cache.ts +57 -0
  12. package/src/agent-time/report.ts +349 -23
  13. package/src/agent-time/shape.ts +50 -3
  14. package/src/agent-time/store.ts +370 -95
  15. package/src/agent-time/timeline.ts +140 -21
  16. package/src/agent-time/turns.ts +18 -8
  17. package/src/annex/offload.ts +17 -6
  18. package/src/annex/tidy.ts +70 -10
  19. package/src/asks/ask-after.ts +40 -0
  20. package/src/asks/asks-queue.ts +205 -47
  21. package/src/assets/kit-config.ts +7 -3
  22. package/src/assets/kits/identity-kit.ts +289 -10
  23. package/src/check.ts +3 -1
  24. package/src/checks/SK004-gitignore-policy.check.ts +12 -5
  25. package/src/checks/SK013-one-way-in-policy.check.ts +8 -3
  26. package/src/checks/SK026-asks-autoclose.check.ts +5 -5
  27. package/src/checks/SK028-readme.check.ts +7 -66
  28. package/src/checks/SK030-cache-audit.check.ts +6 -1
  29. package/src/checks/SK031-trace-audit.check.ts +2 -0
  30. package/src/checks/SK033-global-contribution.check.ts +3 -1
  31. package/src/checks/SK035-public-clean.check.ts +2 -2
  32. package/src/checks/SK043-scratch-on-the-mac.check.ts +59 -4
  33. package/src/checks/SK045-slow-hooks.check.ts +47 -0
  34. package/src/checks/SK046-hook-records.check.ts +76 -0
  35. package/src/checks/SK047-login-in-description.check.ts +36 -0
  36. package/src/checks/SK048-one-local-file.check.ts +36 -0
  37. package/src/cli/cmd_Asks.ts +71 -5
  38. package/src/cli/cmd_Backup.ts +5 -3
  39. package/src/cli/cmd_Capacity.ts +2 -2
  40. package/src/cli/cmd_CrossRepoActivity.ts +5 -4
  41. package/src/cli/cmd_Db.ts +253 -0
  42. package/src/cli/cmd_History.ts +212 -0
  43. package/src/cli/cmd_Home.ts +31 -3
  44. package/src/cli/cmd_Hq.ts +516 -0
  45. package/src/cli/cmd_Machines.ts +36 -0
  46. package/src/cli/cmd_Media.ts +38 -6
  47. package/src/cli/cmd_Mv.ts +1 -1
  48. package/src/cli/cmd_Reflect.ts +23 -2
  49. package/src/cli/cmd_Releases.ts +30 -0
  50. package/src/cli/cmd_Review.ts +569 -118
  51. package/src/cli/cmd_Secret.ts +62 -12
  52. package/src/cli/cmd_Social.ts +83 -1
  53. package/src/cli/cmd_Space.ts +324 -0
  54. package/src/cli/cmd_Time.ts +82 -5
  55. package/src/cli/cmd_Tmp.ts +28 -4
  56. package/src/cli/cmd_Trailer.ts +14 -10
  57. package/src/cli/cmd_Urls.ts +56 -0
  58. package/src/cli/cmd_Vault.ts +583 -0
  59. package/src/cli/family-help.ts +4 -2
  60. package/src/cli/family-pages.ts +1 -1
  61. package/src/cli/registry.ts +26 -4
  62. package/src/collections/actions.ts +63 -13
  63. package/src/collections/collection-types.ts +23 -1
  64. package/src/collections/providers.ts +117 -23
  65. package/src/collections/review.ts +4 -4
  66. package/src/commands/runner.ts +5 -1
  67. package/src/contracts/contract-manifests.ts +6 -5
  68. package/src/contracts/contract-types.ts +6 -4
  69. package/src/contracts/contracts-engine.ts +11 -0
  70. package/src/contracts/manifests/chrome-web-store.contract.ts +31 -0
  71. package/src/core/budget.ts +12 -17
  72. package/src/core/capacity.ts +27 -18
  73. package/src/core/check-runner.ts +7 -4
  74. package/src/core/history-files.ts +9 -5
  75. package/src/core/layout.ts +3 -0
  76. package/src/core/machine-busy.ts +127 -0
  77. package/src/core/machine-commit.ts +6 -1
  78. package/src/core/machine-db.ts +368 -20
  79. package/src/core/machine-layout.ts +137 -0
  80. package/src/core/machine-read.ts +81 -0
  81. package/src/core/migrate-layout.ts +1 -1
  82. package/src/core/one-way-in-policy.ts +64 -7
  83. package/src/core/polling-policy.ts +27 -0
  84. package/src/core/retention.ts +16 -2
  85. package/src/core/scope.ts +107 -14
  86. package/src/core/signal-name.ts +6 -0
  87. package/src/core/slots.ts +5 -4
  88. package/src/core/trace-audit.ts +6 -1
  89. package/src/core/transient.ts +6 -0
  90. package/src/drill/clean.ts +25 -1
  91. package/src/drill/run.ts +2 -2
  92. package/src/drill/seal.ts +27 -4
  93. package/src/home/activity-shape.ts +2 -0
  94. package/src/home/activity.ts +66 -3
  95. package/src/home/app-sign.ts +15 -4
  96. package/src/home/daemon-jobs.ts +149 -7
  97. package/src/home/database-projects.ts +111 -0
  98. package/src/home/database-words.ts +203 -0
  99. package/src/home/databases.ts +460 -0
  100. package/src/home/global-units.ts +6 -0
  101. package/src/home/gui-app/ShipkitGui.swift +122 -1
  102. package/src/home/gui-app.ts +6 -3
  103. package/src/home/home-move.ts +514 -0
  104. package/src/home/home-paths.ts +12 -3
  105. package/src/home/home-routes.ts +68 -0
  106. package/src/home/inbox-shape.ts +24 -14
  107. package/src/home/machine-fold.ts +820 -0
  108. package/src/home/machine-host.ts +20 -5
  109. package/src/home/machine-repair.ts +503 -0
  110. package/src/home/machine-stores.ts +66 -15
  111. package/src/home/machine-temp.ts +547 -86
  112. package/src/home/resume.ts +79 -0
  113. package/src/home/run-daemon.ts +25 -4
  114. package/src/home/run-pm.ts +18 -5
  115. package/src/home/serve-daemon.ts +18 -3
  116. package/src/home/serve-web.ts +175 -7
  117. package/src/home/space-job.ts +115 -0
  118. package/src/home/space-page.ts +257 -0
  119. package/src/home/space-route.ts +167 -0
  120. package/src/home/space-words.ts +103 -0
  121. package/src/home/time-page-shape.ts +202 -0
  122. package/src/home/time-page.ts +64 -0
  123. package/src/home/vault-page.ts +482 -0
  124. package/src/home/vault-words.ts +132 -0
  125. package/src/hooks/leak-guard.ts +40 -13
  126. package/src/hooks/one-way-in-guard.ts +17 -4
  127. package/src/hq/cards.ts +581 -0
  128. package/src/hq/door-route.ts +43 -0
  129. package/src/hq/door.ts +163 -0
  130. package/src/hq/files-send.ts +348 -0
  131. package/src/hq/forgotten-log.ts +35 -0
  132. package/src/hq/history-check.ts +255 -0
  133. package/src/hq/history-place.ts +146 -0
  134. package/src/hq/history-send.ts +487 -0
  135. package/src/hq/hq-db.ts +99 -0
  136. package/src/hq/hq-local.ts +469 -0
  137. package/src/hq/hq-routes.ts +196 -0
  138. package/src/hq/hq-store.ts +599 -0
  139. package/src/hq/kinds/ask.ts +147 -0
  140. package/src/hq/kinds/card-gone.ts +83 -0
  141. package/src/hq/kinds/card-msg.ts +66 -0
  142. package/src/hq/kinds/card.ts +99 -0
  143. package/src/hq/kinds/index.ts +21 -0
  144. package/src/hq/kinds/kind.ts +126 -0
  145. package/src/hq/kinds/media.ts +125 -0
  146. package/src/hq/kinds/prompt.ts +219 -0
  147. package/src/hq/kinds/reflection.ts +128 -0
  148. package/src/hq/kinds/report.ts +55 -0
  149. package/src/hq/kinds/time-day.ts +236 -0
  150. package/src/hq/ledger.ts +473 -0
  151. package/src/hq/machine-key.ts +44 -0
  152. package/src/hq/machine-notes.ts +131 -0
  153. package/src/hq/outbox.ts +372 -0
  154. package/src/hq/replica.ts +168 -0
  155. package/src/hq/repo-id.ts +4 -0
  156. package/src/hq/report-facts.ts +117 -0
  157. package/src/hq/report.ts +274 -0
  158. package/src/hq/switch.ts +151 -0
  159. package/src/hq/vault-grant.ts +92 -0
  160. package/src/identities/identities.ts +15 -3
  161. package/src/identities/steps.ts +31 -0
  162. package/src/ledger/db.ts +73 -26
  163. package/src/ledger/gate-checks.ts +29 -4
  164. package/src/ledger/git-key.ts +3 -3
  165. package/src/ledger/git-scan.ts +49 -7
  166. package/src/ledger/run-log.ts +11 -3
  167. package/src/ledger/store.ts +26 -4
  168. package/src/media-store/backup/daemon.ts +36 -17
  169. package/src/media-store/backup/kept.ts +241 -0
  170. package/src/media-store/backup/restore.ts +14 -4
  171. package/src/media-store/backup/run.ts +11 -11
  172. package/src/media-store/backup/secret.ts +6 -4
  173. package/src/media-store/backup/snapshot.ts +4 -2
  174. package/src/media-store/backup/sources.ts +68 -20
  175. package/src/media-store/copy/config.ts +77 -0
  176. package/src/media-store/copy/copy.ts +194 -0
  177. package/src/media-store/copy/lifecycle.ts +43 -0
  178. package/src/media-store/copy/night.ts +90 -0
  179. package/src/media-store/copy/proof.ts +151 -0
  180. package/src/media-store/copy/snapshot.ts +152 -0
  181. package/src/media-store/copy/store.ts +62 -0
  182. package/src/media-store/copy/stream.ts +176 -0
  183. package/src/media-store/daemon.ts +66 -16
  184. package/src/media-store/db.ts +22 -11
  185. package/src/media-store/forget.ts +23 -3
  186. package/src/media-store/hand.ts +4 -3
  187. package/src/media-store/hq-find.ts +75 -0
  188. package/src/media-store/hq-send.ts +277 -0
  189. package/src/media-store/kind.ts +2 -0
  190. package/src/media-store/purge.ts +18 -15
  191. package/src/media-store/put.ts +24 -8
  192. package/src/media-store/remote.ts +16 -7
  193. package/src/media-store/space-listing.ts +240 -0
  194. package/src/media-store/space.ts +40 -21
  195. package/src/media-store/sync.ts +5 -5
  196. package/src/media-store/tidy.ts +98 -0
  197. package/src/media-store/upload.ts +3 -3
  198. package/src/media-store/webp.ts +66 -0
  199. package/src/messages/model.ts +16 -7
  200. package/src/messages/routes.ts +14 -4
  201. package/src/messages/score.ts +2 -2
  202. package/src/messages/suggest.ts +96 -0
  203. package/src/pages/frame-client.ts +10 -0
  204. package/src/plan/planner.ts +28 -17
  205. package/src/recordings/media-kind.ts +1 -0
  206. package/src/recordings/model.ts +1 -1
  207. package/src/recordings/recorder-app/Capture.swift +9 -7
  208. package/src/reflect/hq-corpus.ts +56 -0
  209. package/src/reflect/prompt-corpus.ts +3 -1
  210. package/src/reflect/transcript.ts +146 -36
  211. package/src/release/machine-words.ts +67 -0
  212. package/src/release/public-clean.ts +8 -3
  213. package/src/releases/from-card.ts +1 -1
  214. package/src/releases/model.ts +18 -0
  215. package/src/releases/routes.ts +10 -5
  216. package/src/releases/store.ts +23 -2
  217. package/src/repo-config.ts +42 -2
  218. package/src/review/anim.ts +2 -2
  219. package/src/review/auto.ts +2 -2
  220. package/src/review/card-db.ts +244 -0
  221. package/src/review/card-rows.ts +266 -0
  222. package/src/review/cells.ts +76 -5
  223. package/src/review/draft-card.ts +41 -0
  224. package/src/review/draft-model.ts +78 -0
  225. package/src/review/format.ts +29 -10
  226. package/src/review/gone.ts +98 -0
  227. package/src/review/inbox-hook.ts +35 -0
  228. package/src/review/marks.ts +1 -1
  229. package/src/review/media-kind.ts +7 -5
  230. package/src/review/media-read.ts +9 -7
  231. package/src/review/media.ts +32 -5
  232. package/src/review/model.ts +214 -45
  233. package/src/review/move.ts +491 -0
  234. package/src/review/notes.ts +12 -20
  235. package/src/review/previews.ts +15 -19
  236. package/src/review/project.ts +1 -1
  237. package/src/review/rev.ts +8 -0
  238. package/src/review/role.ts +1 -1
  239. package/src/review/routes.ts +64 -13
  240. package/src/review/stage-card.ts +8 -4
  241. package/src/review/stage-routes.ts +1 -1
  242. package/src/review/store.ts +529 -83
  243. package/src/review/thread-fold.ts +51 -0
  244. package/src/review/threads.ts +147 -9
  245. package/src/review/trailer-auto-mock.ts +63 -0
  246. package/src/review/trailer-card.ts +4 -4
  247. package/src/review/trailer-desk.ts +41 -7
  248. package/src/review/trailer-media.ts +1 -0
  249. package/src/review/trailer-model.ts +8 -0
  250. package/src/review/trailer-notes.ts +1 -1
  251. package/src/review/trailer-routes.ts +9 -1
  252. package/src/review/unit.ts +6 -6
  253. package/src/review/watchers.ts +1 -1
  254. package/src/rules/untrack-generated.ts +92 -8
  255. package/src/secrets/held.ts +16 -0
  256. package/src/secrets/keychain.ts +113 -0
  257. package/src/secrets/list.ts +16 -6
  258. package/src/secrets/manager.ts +24 -10
  259. package/src/secrets/read.ts +257 -0
  260. package/src/secrets/who-reads.ts +49 -0
  261. package/src/serve/door-forward.ts +268 -0
  262. package/src/serve/door-names.ts +47 -0
  263. package/src/serve/embed.ts +1 -1
  264. package/src/serve/hub-app/activity-view.tsx +56 -32
  265. package/src/serve/hub-app/activity.css +7 -1
  266. package/src/serve/hub-app/asks-page.tsx +48 -0
  267. package/src/serve/hub-app/asks-st.ts +25 -0
  268. package/src/serve/hub-app/clock-svc.ts +1 -2
  269. package/src/serve/hub-app/col-card.tsx +64 -13
  270. package/src/serve/hub-app/col-list-page.tsx +122 -0
  271. package/src/serve/hub-app/col-list-st.ts +103 -0
  272. package/src/serve/hub-app/col-tables-view.tsx +10 -41
  273. package/src/serve/hub-app/col-tables.ts +76 -8
  274. package/src/serve/hub-app/cols-svc.ts +70 -16
  275. package/src/serve/hub-app/database-st.ts +260 -0
  276. package/src/serve/hub-app/database-view.tsx +289 -0
  277. package/src/serve/hub-app/database.css +32 -0
  278. package/src/serve/hub-app/entry-bar.css +14 -0
  279. package/src/serve/hub-app/entry-bar.tsx +33 -0
  280. package/src/serve/hub-app/entry-pick.ts +31 -0
  281. package/src/serve/hub-app/floating.tsx +1 -0
  282. package/src/serve/hub-app/hash-route.ts +11 -1
  283. package/src/serve/hub-app/header-bar.tsx +14 -18
  284. package/src/serve/hub-app/home-st.ts +89 -9
  285. package/src/serve/hub-app/home-strip.css +5 -19
  286. package/src/serve/hub-app/home-strip.tsx +58 -92
  287. package/src/serve/hub-app/home.html +7 -0
  288. package/src/serve/hub-app/hub-app.tsx +31 -142
  289. package/src/serve/hub-app/hub-types.ts +3 -1
  290. package/src/serve/hub-app/hub.css +109 -23
  291. package/src/serve/hub-app/icons.tsx +18 -1
  292. package/src/serve/hub-app/identities-st.ts +56 -6
  293. package/src/serve/hub-app/identities-view.tsx +100 -58
  294. package/src/serve/hub-app/identities.css +17 -15
  295. package/src/serve/hub-app/identity-address.ts +5 -0
  296. package/src/serve/hub-app/inbox-st.ts +41 -24
  297. package/src/serve/hub-app/inbox-view.tsx +37 -41
  298. package/src/serve/hub-app/inbox.css +2 -5
  299. package/src/serve/hub-app/index.html +7 -0
  300. package/src/serve/hub-app/kept-cols.tsx +7 -0
  301. package/src/serve/hub-app/keys.ts +28 -15
  302. package/src/serve/hub-app/later.tsx +26 -0
  303. package/src/serve/hub-app/list-filter.tsx +14 -0
  304. package/src/serve/hub-app/list-walk.ts +72 -3
  305. package/src/serve/hub-app/machines-st.ts +251 -0
  306. package/src/serve/hub-app/machines-view.tsx +224 -0
  307. package/src/serve/hub-app/machines.css +76 -0
  308. package/src/serve/hub-app/md-copy.tsx +79 -0
  309. package/src/serve/hub-app/media-view.tsx +2 -0
  310. package/src/serve/hub-app/messages/messages-page.tsx +79 -7
  311. package/src/serve/hub-app/messages/messages-st.ts +99 -3
  312. package/src/serve/hub-app/messages.css +14 -0
  313. package/src/serve/hub-app/page-keys.ts +175 -0
  314. package/src/serve/hub-app/pages-frames.tsx +11 -3
  315. package/src/serve/hub-app/palette-st.ts +58 -11
  316. package/src/serve/hub-app/palette-view.tsx +3 -1
  317. package/src/serve/hub-app/project-list.css +54 -8
  318. package/src/serve/hub-app/project-list.tsx +128 -59
  319. package/src/serve/hub-app/projects-svc.ts +78 -7
  320. package/src/serve/hub-app/reader-chips.tsx +13 -0
  321. package/src/serve/hub-app/readme-view.tsx +2 -3
  322. package/src/serve/hub-app/readme.css +27 -5
  323. package/src/serve/hub-app/reflections-page.tsx +42 -0
  324. package/src/serve/hub-app/reflections-st.ts +17 -0
  325. package/src/serve/hub-app/releases/releases-page.tsx +25 -2
  326. package/src/serve/hub-app/releases/releases-st.ts +1 -1
  327. package/src/serve/hub-app/repo-sections.ts +9 -5
  328. package/src/serve/hub-app/repo-st.ts +35 -8
  329. package/src/serve/hub-app/review/draft-card.tsx +163 -0
  330. package/src/serve/hub-app/review/kit.tsx +50 -7
  331. package/src/serve/hub-app/review/note-place.ts +1 -1
  332. package/src/serve/hub-app/review/review-board.tsx +2 -2
  333. package/src/serve/hub-app/review/review-cells.tsx +145 -65
  334. package/src/serve/hub-app/review/review-kit.ts +27 -1
  335. package/src/serve/hub-app/review/review-list.tsx +68 -30
  336. package/src/serve/hub-app/review/review-page.tsx +7 -8
  337. package/src/serve/hub-app/review/review-st.ts +111 -24
  338. package/src/serve/hub-app/review/review-thread.tsx +49 -19
  339. package/src/serve/hub-app/review/review-views.tsx +475 -144
  340. package/src/serve/hub-app/review/thread-control-st.ts +115 -0
  341. package/src/serve/hub-app/review/thread-control.tsx +74 -0
  342. package/src/serve/hub-app/review/thread-st.ts +73 -26
  343. package/src/serve/hub-app/review/trailer-card.tsx +1 -1
  344. package/src/serve/hub-app/review/trailer-page.tsx +37 -16
  345. package/src/serve/hub-app/review/trailer-st.ts +41 -7
  346. package/src/serve/hub-app/review.css +267 -61
  347. package/src/serve/hub-app/side-lists.ts +72 -0
  348. package/src/serve/hub-app/sidebar.tsx +6 -3
  349. package/src/serve/hub-app/site/site-part.tsx +2 -8
  350. package/src/serve/hub-app/site/site-st.ts +4 -4
  351. package/src/serve/hub-app/social/comms-page.tsx +20 -5
  352. package/src/serve/hub-app/social/kit.tsx +30 -4
  353. package/src/serve/hub-app/social/post-card.tsx +139 -49
  354. package/src/serve/hub-app/social/serial-writes.ts +13 -0
  355. package/src/serve/hub-app/social/social-model.ts +11 -0
  356. package/src/serve/hub-app/social/social-page.tsx +94 -35
  357. package/src/serve/hub-app/social/social-st.ts +120 -36
  358. package/src/serve/hub-app/social/stage-popup.tsx +1 -1
  359. package/src/serve/hub-app/social/stage-st.ts +1 -1
  360. package/src/serve/hub-app/social/step-layout.ts +1 -1
  361. package/src/serve/hub-app/social.css +3 -0
  362. package/src/serve/hub-app/space-st.ts +209 -0
  363. package/src/serve/hub-app/space-view.tsx +196 -0
  364. package/src/serve/hub-app/space.css +27 -0
  365. package/src/serve/hub-app/stores/stores-page.tsx +91 -23
  366. package/src/serve/hub-app/stores/stores-st.ts +44 -19
  367. package/src/serve/hub-app/stores.css +6 -1
  368. package/src/serve/hub-app/theme-st.ts +22 -9
  369. package/src/serve/hub-app/time-charts.tsx +291 -0
  370. package/src/serve/hub-app/time-pages.tsx +749 -0
  371. package/src/serve/hub-app/time-st.ts +162 -0
  372. package/src/serve/hub-app/time-view.tsx +76 -0
  373. package/src/serve/hub-app/time.css +138 -0
  374. package/src/serve/hub-app/tree-build.ts +52 -42
  375. package/src/serve/hub-app/tree-row.tsx +4 -4
  376. package/src/serve/hub-app/tree-svc.ts +18 -9
  377. package/src/serve/hub-app/urls-svc.ts +154 -0
  378. package/src/serve/hub-app/urls-view.tsx +117 -0
  379. package/src/serve/hub-app/urls.css +30 -0
  380. package/src/serve/hub-app/vault-st.ts +127 -0
  381. package/src/serve/hub-app/vault-view.tsx +154 -0
  382. package/src/serve/hub-app/vault.css +38 -0
  383. package/src/serve/hub-app/veille/veille-st.ts +12 -10
  384. package/src/serve/hub-app/waiting-svc.ts +29 -0
  385. package/src/serve/hub-app/wikis-view.tsx +2 -2
  386. package/src/serve/hub-runtime.ts +15 -2
  387. package/src/serve/project-gutter-route.ts +27 -14
  388. package/src/serve/project-gutter.ts +25 -12
  389. package/src/serve/same-origin.ts +10 -0
  390. package/src/serve/serve-hub.ts +13 -4
  391. package/src/shipkit-files.ts +16 -2
  392. package/src/shipkit.ts +1 -1
  393. package/src/shot/shooter.ts +616 -420
  394. package/src/shot/shot-ask.ts +246 -155
  395. package/src/site/desk.ts +2 -2
  396. package/src/smoke/run-smoke.ts +3 -2
  397. package/src/social/cover.ts +202 -0
  398. package/src/social/discord-layout.ts +37 -13
  399. package/src/social/drafts.ts +3 -0
  400. package/src/social/load.ts +23 -2
  401. package/src/social/media-kind.ts +2 -1
  402. package/src/social/publish/discord.ts +5 -2
  403. package/src/social/publish/secret.ts +2 -2
  404. package/src/social/release-stage.ts +28 -13
  405. package/src/social/routes.ts +26 -1
  406. package/src/social/stage.ts +1 -1
  407. package/src/social/stats.ts +12 -9
  408. package/src/social/strip.ts +4 -1
  409. package/src/social/thumbnail.ts +255 -0
  410. package/src/stores/collection.ts +15 -11
  411. package/src/stores/desk.ts +236 -42
  412. package/src/stores/model.ts +72 -6
  413. package/src/stores/routes.ts +37 -12
  414. package/src/stores/unit.ts +14 -8
  415. package/src/suite/judge-suites.ts +113 -16
  416. package/src/suite/select.ts +45 -3
  417. package/src/suite/suite-cli.ts +81 -34
  418. package/src/trailer/bed.ts +1 -1
  419. package/src/trailer/build.ts +134 -21
  420. package/src/trailer/ffmpeg.ts +7 -0
  421. package/src/trailer/fonts.ts +3 -2
  422. package/src/trailer/grammar.ts +201 -2
  423. package/src/trailer/graph.ts +42 -5
  424. package/src/trailer/look.ts +21 -0
  425. package/src/trailer/mock.ts +154 -0
  426. package/src/trailer/passage.ts +65 -26
  427. package/src/trailer/score/heard.ts +89 -0
  428. package/src/trailer/score/sound.ts +14 -8
  429. package/src/trailer/sound/run.ts +16 -6
  430. package/src/trailer/stitch.ts +26 -5
  431. package/src/trailer/titles.ts +82 -19
  432. package/src/trailer/versions.ts +1 -3
  433. package/src/trailer/vertical.ts +3 -1
  434. package/src/urls/frame.ts +195 -0
  435. package/src/urls/routes.ts +43 -0
  436. package/src/urls/rows.ts +171 -0
  437. package/src/urls/unit.ts +73 -0
  438. package/src/vault/house-keys.ts +42 -0
  439. package/src/vault/layout.ts +50 -0
  440. package/src/vault/policy.ts +165 -0
  441. package/src/vault/vault-audit.ts +276 -0
  442. package/src/vault/vault-client.ts +40 -0
  443. package/src/vault/vault-config.ts +159 -0
  444. package/src/vault/vault-destroy.ts +78 -0
  445. package/src/vault/vault-handover.ts +305 -0
  446. package/src/vault/vault-http.ts +352 -0
  447. package/src/vault/vault-import.ts +208 -0
  448. package/src/vault/vault-init.ts +328 -0
  449. package/src/vault/vault-minter.ts +271 -0
  450. package/src/vault/vault-restore.ts +333 -0
  451. package/src/vault/vault-serve.ts +342 -0
  452. package/src/vault/vault-snapshot.ts +281 -0
  453. package/src/veille/asks.ts +1 -1
  454. package/src/veille/desk.ts +2 -2
  455. package/src/wiki/run-wiki.ts +2 -1
  456. package/src/wiki/scan-md.ts +42 -2
@@ -15,6 +15,8 @@ export type Call = {
15
15
  tool: string
16
16
  shape: string
17
17
  cmd: string
18
+ /** the sum of the command's text once the diet dropped it (diet.ts cmdSum), absent or null while the text is there */
19
+ cmdSum?: number | null
18
20
  outcome: Outcome | null
19
21
  code: number | null
20
22
  /** it waited for the human to allow it */
@@ -23,19 +25,34 @@ export type Call = {
23
25
  perm: string
24
26
  /** it only read (turns.ts isReadOnly, judged when indexed) */
25
27
  read: boolean
28
+ /** the model message that carries it, the same for every call of one turn; absent or '' when none was recorded */
29
+ msg?: string
30
+ /** the model of the turn that wrote it, '' when the transcript does not say */
31
+ model: string
32
+ /** the tokens that turn read (input, cache read and cache write), 0 when unknown */
33
+ ctx: number
34
+ /** the tokens that turn wrote, 0 when unknown */
35
+ out: number
36
+ /** a call refused before it ran (blocked, denied): what refused it, in the harness's words; absent or '' otherwise */
37
+ why?: string
26
38
  /** the call returned while its command ran on in the background: `end`
27
39
  * is when it returned, `bgEnd` when the run ended (its task notification),
28
40
  * null while no end is recorded */
29
41
  bg: boolean
30
42
  bgEnd: number | null
43
+ /** its foreground call ended on its time limit, and the harness ran the command on in the background: `end`
44
+ * is the limit, `bgEnd` and `outcome` what became of it after */
45
+ limited: boolean
31
46
  }
32
47
 
33
- /** `end`: the agent ended its turn (a text block, stop_reason end_turn) */
34
- export type Mark = { at: number; kind: 'prompt' | 'wake' | 'message' | 'reply' | 'end' }
48
+ /** `act`: he did something that is no prompt (a slash command, an interrupt);
49
+ * `lapse`: a watch of the agent's ran out in silence, and the harness woke it to arm the watch again;
50
+ * `end`: the agent ended its turn (a text block, stop_reason end_turn), or the API refused its request */
51
+ export type Mark = { at: number; kind: 'prompt' | 'act' | 'wake' | 'lapse' | 'message' | 'reply' | 'end' }
35
52
 
36
53
  export type Stream = { calls: Call[]; marks: Mark[] }
37
54
 
38
- /** where a slice of wall time went. `human`: stopped until his typed prompt;
55
+ /** where a slice of wall time went. `human`: stopped until he typed or acted;
39
56
  * `parked`: stopped until a message relayed in (the coordinator, another
40
57
  * session), so a lane that handed back and waits to be written to */
41
58
  export type Bucket = 'model' | 'tools' | 'approval' | 'subagent' | 'background' | 'parked' | 'human' | 'idle' | 'unknown'
@@ -47,6 +64,9 @@ export const IDLE_MS = 30 * 60 * 1000
47
64
 
48
65
  export const emptyBreakdown = (): Breakdown => ({ model: 0, tools: 0, approval: 0, subagent: 0, background: 0, parked: 0, human: 0, idle: 0, unknown: 0 })
49
66
 
67
+ /** the call a sub-agent ends on: its report handed back to the session that started it */
68
+ export const HAND_BACK = 'SubagentHandback'
69
+
50
70
  /** a foreground sub-agent call: the session waits on another agent's work */
51
71
  export const isAgentCall = (c: Call): boolean => c.tool === 'Agent' || c.tool === 'Task'
52
72
 
@@ -91,28 +111,98 @@ export const runMs = (c: Closed): number | null => (!c.bg ? callMs(c) : c.bgEnd
91
111
 
92
112
  type Point = { at: number; d: 'start' | 'stop' | Mark['kind']; lane: 'tool' | 'agent' | 'approval'; ix: number }
93
113
 
114
+ /** a stretch of time, from and to */
115
+ export type Span = readonly [number, number]
116
+
117
+ /** sorted by start, the ones that touch joined */
118
+ export function joinSpans(spans: readonly Span[]): Span[] {
119
+ const out: [number, number][] = []
120
+ for (const [a, b] of [...spans].sort((x, y) => x[0] - y[0])) {
121
+ const last = out[out.length - 1]
122
+ if (last != null && a <= last[1]) last[1] = Math.max(last[1], b)
123
+ else if (b > a) out.push([a, b])
124
+ }
125
+ return out
126
+ }
127
+
128
+ /** the ms of [a, b] that joined spans hold */
129
+ function heldMs(spans: readonly Span[], a: number, b: number): number {
130
+ let lo = 0
131
+ let hi = spans.length
132
+ while (lo < hi) {
133
+ const mid = (lo + hi) >> 1
134
+ if ((spans[mid] as Span)[1] <= a) lo = mid + 1
135
+ else hi = mid
136
+ }
137
+ let ms = 0
138
+ for (let i = lo; i < spans.length && (spans[i] as Span)[0] < b; i++) ms += Math.min(b, (spans[i] as Span)[1]) - Math.max(a, (spans[i] as Span)[0])
139
+ return ms
140
+ }
141
+
142
+ /** the buckets of a lane that is not done: in its turn, in a call, or stopped on a run of its own */
143
+ const AT_WORK: ReadonlySet<Bucket> = new Set<Bucket>(['model', 'tools', 'approval', 'subagent', 'background'])
144
+
145
+ /** when the lanes of each session were at work, by session: what a main
146
+ * session's long stop is checked against (wallBreakdown, `lanes`). `now`:
147
+ * the time of the report, so a lane stopped on a run still open counts up to it */
148
+ export function lanesAtWork(streams: readonly { session: string; agent: string; stream: Stream; closed: Closed[] }[], now = Infinity, idleMs = IDLE_MS): Map<string, Span[]> {
149
+ const by = new Map<string, Span[]>()
150
+ for (const g of streams) {
151
+ if (g.agent === '') continue
152
+ const spans = by.get(g.session) ?? []
153
+ cut(g.stream, -Infinity, now, idleMs, g.closed, now, undefined, undefined, (bucket, a, b) => {
154
+ if (AT_WORK.has(bucket)) spans.push([a, b])
155
+ })
156
+ by.set(g.session, spans)
157
+ }
158
+ for (const [session, spans] of by) by.set(session, joinSpans(spans))
159
+ return by
160
+ }
161
+
94
162
  /** the wall of one stream cut into buckets, clipped to [from, to]. Between two
95
163
  * boundaries: a tool in flight → tools; only calls waiting for his allow →
96
164
  * approval; only a sub-agent in flight → subagent;
97
- * nothing in flight and the next thing is his prompt → human (idle past
98
- * IDLE_MS); a message relayed in → parked (idle past IDLE_MS: a sub-agent
99
- * that handed back sits there until the coordinator writes to it); a wake (a
100
- * task notification, a hand-back) → background. Else, when the agent ended
101
- * its turn (an `end` mark) and nothing since: it was stopped, and no record
102
- * says on what → unknown (idle past IDLE_MS); else the agent was in its turn,
103
- * its API request in flight → model.
165
+ * nothing in flight and the next thing is his prompt or his act → human
166
+ * (idle past IDLE_MS); a message relayed in → parked (idle past IDLE_MS: a
167
+ * sub-agent that handed back sits there until the coordinator writes to it);
168
+ * a wake (a task notification, a hand-back) → background, but for a
169
+ * sub-agent that handed back: it is done until someone writes to it, so a
170
+ * leftover run of its own that ends later finds it parked (idle past
171
+ * IDLE_MS), not waiting. Else, when the
172
+ * agent ended its turn (an `end` mark) and nothing since: it was stopped,
173
+ * and no record says on what → unknown (idle past IDLE_MS); else the agent
174
+ * was in its turn, its API request in flight → model.
175
+ *
176
+ * `lanes` (a main session: when its lanes were at work, lanesAtWork) cuts a
177
+ * wait a wake ends that is longer than IDLE_MS: background only while a lane
178
+ * was at work or a background run of its own ran to its end, the rest idle. A
179
+ * notice written hours after everything of the session ended is no wait.
180
+ * A wait a `lapse` ends is cut the same way whatever its length: the watch
181
+ * ran its whole time and nothing came, so with nothing of its own at work
182
+ * the session was parked on someone else's move. Without `lanes` (a
183
+ * sub-agent, whose own sub-agents are not known here) a lapse counts as a wake.
104
184
  *
105
- * Past the stream's last event nothing counts, a run that ended included,
106
- * but one case: the report runs (`to`, finite) while the stream is stopped
107
- * on a background run of its own that has no end yet, its stop under
108
- * IDLE_MS old → background up to `to`.
185
+ * Past the stream's last event nothing counts, but one case: the report
186
+ * runs (`now`, finite) while the stream's stop on a background run of its
187
+ * own is under IDLE_MS old → background up to `now`, or up to the end of
188
+ * that run when it has one (its notice stayed in the queue: nothing woke
189
+ * the stream). `now` is the time of the report, `to` when not given: a cut
190
+ * of one day passes both, since a day's last second is not when the report runs.
109
191
  *
110
192
  * `turnModel` (one slot per closed call) receives the model stretch that
111
193
  * ended in each call: the turn that issued it, split evenly over the calls
112
194
  * of one batch. A stretch that ends in his prompt, a wake or the turn's end
113
195
  * was the final reply and goes to no call */
114
- export function wallBreakdown(s: Stream, from = -Infinity, to = Infinity, idleMs = IDLE_MS, closed: Closed[] = closeCalls(s), turnModel?: Float64Array): Breakdown {
196
+ export function wallBreakdown(s: Stream, from = -Infinity, to = Infinity, idleMs = IDLE_MS, closed: Closed[] = closeCalls(s), turnModel?: Float64Array, lanes?: readonly Span[], now = to): Breakdown {
197
+ return cut(s, from, to, idleMs, closed, now, turnModel, lanes)
198
+ }
199
+
200
+ /** the sweep behind wallBreakdown; `slice` receives each stretch that went whole to one bucket */
201
+ function cut(s: Stream, from: number, to: number, idleMs: number, closed: Closed[], now: number, turnModel?: Float64Array, lanes?: readonly Span[], slice?: (bucket: Bucket, a: number, b: number) => void): Breakdown {
115
202
  const out = emptyBreakdown()
203
+ // what of its own a main session can be stopped on: its lanes at work, its background runs that ran to their
204
+ // end (a run somebody stopped, a dev server, is nothing it waited on)
205
+ const own = lanes == null ? null : joinSpans([...lanes, ...closed.filter((c) => c.bg && c.bgEnd != null && c.outcome !== 'interrupted').map((c): Span => [c.start, c.bgEnd as number])])
116
206
  const points: Point[] = []
117
207
  closed.forEach((c, ix) => {
118
208
  const lane = isAgentCall(c) ? 'agent' : c.approval ? 'approval' : 'tool'
@@ -125,6 +215,8 @@ export function wallBreakdown(s: Stream, from = -Infinity, to = Infinity, idleMs
125
215
  let approvals = 0
126
216
  let pending = 0
127
217
  let stopped = false
218
+ // it handed its report back, and nobody wrote to it since
219
+ let handed = false
128
220
  const issued: number[] = []
129
221
  let i = 0
130
222
  while (i < points.length) {
@@ -138,8 +230,10 @@ export function wallBreakdown(s: Stream, from = -Infinity, to = Infinity, idleMs
138
230
  else if (p.lane === 'approval') approvals += n
139
231
  else tools += n
140
232
  if (p.d === 'start') issued.push(p.ix)
141
- else if (p.d === 'prompt' || p.d === 'wake' || p.d === 'message' || p.d === 'end') ended = true
233
+ else if (p.d === 'prompt' || p.d === 'act' || p.d === 'wake' || p.d === 'lapse' || p.d === 'message' || p.d === 'end') ended = true
142
234
  if (p.d !== 'stop') stopped = p.d === 'end'
235
+ if (p.d === 'stop' && (closed[p.ix] as Closed).tool === HAND_BACK) handed = true
236
+ else if (p.d === 'prompt' || p.d === 'act' || p.d === 'message') handed = false
143
237
  i++
144
238
  }
145
239
  if (turnModel != null) {
@@ -147,8 +241,15 @@ export function wallBreakdown(s: Stream, from = -Infinity, to = Infinity, idleMs
147
241
  if (issued.length > 0 || ended) pending = 0
148
242
  }
149
243
  if (i >= points.length) {
150
- const waitsOnItsOwn = stopped && Number.isFinite(to) && to - at <= idleMs && closed.some((c) => c.bg && c.start <= at && (c.bgEnd == null || c.bgEnd > at))
151
- if (waitsOnItsOwn) out.background += Math.max(0, to - Math.max(at, from))
244
+ // the latest end of the runs of its own open at its stop: Infinity while one has no end yet
245
+ let until = -Infinity
246
+ for (const c of closed) if (c.bg && c.start <= at && (c.bgEnd == null || c.bgEnd > at)) until = Math.max(until, c.bgEnd ?? Infinity)
247
+ const a = Math.max(at, from)
248
+ const b = Math.min(to, now, until)
249
+ if (stopped && !handed && Number.isFinite(now) && now - at <= idleMs && b > a) {
250
+ out.background += b - a
251
+ slice?.('background', a, b)
252
+ }
152
253
  break
153
254
  }
154
255
  const nextAt = (points[i] as Point).at
@@ -165,17 +266,26 @@ export function wallBreakdown(s: Stream, from = -Infinity, to = Infinity, idleMs
165
266
  let typed = false
166
267
  let message = false
167
268
  let wake = false
269
+ let lapse = false
168
270
  while (next < points.length && (points[next] as Point).at === nextAt) {
169
271
  const d = (points[next] as Point).d
170
- if (d === 'prompt') typed = true
272
+ if (d === 'prompt' || d === 'act') typed = true
171
273
  if (d === 'message') message = true
172
274
  if (d === 'wake') wake = true
275
+ if (d === 'lapse') lapse = true
173
276
  next++
174
277
  }
175
278
  const gap = nextAt - at
176
- bucket = typed ? (gap > idleMs ? 'idle' : 'human') : message ? (gap > idleMs ? 'idle' : 'parked') : wake ? 'background' : !stopped ? 'model' : gap > idleMs ? 'idle' : 'unknown'
279
+ bucket = typed ? (gap > idleMs ? 'idle' : 'human') : message || ((wake || lapse) && handed) ? (gap > idleMs ? 'idle' : 'parked') : wake || lapse ? 'background' : !stopped ? 'model' : gap > idleMs ? 'idle' : 'unknown'
280
+ if (bucket === 'background' && own != null && (gap > idleMs || !wake)) {
281
+ const busy = heldMs(own, a, b)
282
+ out.background += busy
283
+ out.idle += len - busy
284
+ continue
285
+ }
177
286
  }
178
287
  out[bucket] += len
288
+ slice?.(bucket, a, b)
179
289
  if (bucket === 'model') pending += len
180
290
  }
181
291
  return out
@@ -194,6 +304,15 @@ export const FAILED: ReadonlySet<Outcome> = new Set<Outcome>(['exit', 'error', '
194
304
 
195
305
  export type Retry = { failed: Closed; next: Closed; blind: boolean }
196
306
 
307
+ /** the 53 bit sum of a command's text, trimmed: what the blind retry test compares once the diet dropped a text */
308
+ export const cmdSum = (cmd: string): number => Number(BigInt.asUintN(53, BigInt(Bun.hash(cmd.trim()))))
309
+
310
+ /** two calls ran the same command: their texts, or a text's sum against a sum the diet kept */
311
+ export function sameCommand(a: Pick<Call, 'cmd' | 'cmdSum'>, b: Pick<Call, 'cmd' | 'cmdSum'>): boolean {
312
+ if (a.cmdSum == null && b.cmdSum == null) return a.cmd.trim() === b.cmd.trim()
313
+ return (a.cmdSum ?? cmdSum(a.cmd)) === (b.cmdSum ?? cmdSum(b.cmd))
314
+ }
315
+
197
316
  /** every failed call followed by the same shape again: `blind` when the
198
317
  * command is the exact same text, so nothing changed between the two.
199
318
  * `calls` sorted by start (closeCalls) */
@@ -206,7 +325,7 @@ export function retries(calls: Closed[]): Retry[] {
206
325
  nextOfShape.set(c.shape, c)
207
326
  if (c.outcome == null || !FAILED.has(c.outcome)) continue
208
327
  if (next == null || next.start - c.stop > RETRY_MS) continue
209
- out.push({ failed: c, next, blind: next.cmd.trim() === c.cmd.trim() })
328
+ out.push({ failed: c, next, blind: sameCommand(c, next) })
210
329
  }
211
330
  return out.reverse()
212
331
  }
@@ -1,13 +1,13 @@
1
1
  // Turn count: what makes an agent slow when no command is. Every tool call
2
2
  // costs a model turn before it, so an agent that reads one file per turn
3
3
  // spends its wall on the model, not on the reads. The two questions this
4
- // module answers on pure data: was a call a single read, and did it go out in
5
- // parallel with the one before it.
4
+ // module answers on pure data: was a call a single read, and did it go out
5
+ // with others, in one model message.
6
6
  //
7
7
  // The constraint a reader breaks first: a read is judged on the WHOLE command,
8
8
  // never on its shape alone. `grep -l x | xargs sed -i` shapes as `grep`, and
9
9
  // it writes.
10
- import { stripHeredocs } from './shape.ts'
10
+ import { MORE, stripHeredocs } from './shape.ts'
11
11
  import type { Closed } from './timeline.ts'
12
12
 
13
13
  /** bumped with any read rule below: the index judges every stored call again */
@@ -79,18 +79,28 @@ function partReads(part: string, whole: string): boolean {
79
79
  * loop over one included) whose every part reads */
80
80
  export function isReadOnly(c: { tool: string; shape: string; cmd: string }): boolean {
81
81
  if (READ_TOOLS.has(c.tool)) return true
82
- if (c.tool !== 'Bash' || !READ_SHAPES.has(c.shape.replace(/^\(for\) /, ''))) return false
82
+ if (c.tool !== 'Bash' || !READ_SHAPES.has(c.shape.replace(/^\(for\) /, '').replace(MORE, ''))) return false
83
83
  return parts(c.cmd).every((p) => p.trim() === '' || partReads(p, c.cmd))
84
84
  }
85
85
 
86
- /** a call issued this soon after the one before, while that one still ran,
87
- * went out in the same turn */
86
+ /** with no message id recorded: a call issued this soon after the one before,
87
+ * while that one still ran, went out in the same turn */
88
88
  export const PARALLEL_MS = 2000
89
89
 
90
- /** one flag per call (sorted by start, closeCalls): it started before the
91
- * previous call ended, within PARALLEL_MS of its start */
90
+ /** one flag per call (sorted by start, closeCalls): it is not the first call
91
+ * of its model message, so it cost no model turn of its own. The harness
92
+ * runs some calls as soon as they are written, so an overlap test misses the
93
+ * ones answered before the next was written. A call with no message id (a
94
+ * row indexed before the id was kept) falls back on the overlap: it started
95
+ * before the previous call ended, within PARALLEL_MS of its start */
92
96
  export function parallelFlags(calls: readonly Closed[]): boolean[] {
97
+ const seen = new Set<string>()
93
98
  return calls.map((c, i) => {
99
+ if (c.msg != null && c.msg !== '') {
100
+ if (seen.has(c.msg)) return true
101
+ seen.add(c.msg)
102
+ return false
103
+ }
94
104
  const prev = calls[i - 1]
95
105
  return prev != null && c.start < prev.stop && c.start - prev.start <= PARALLEL_MS
96
106
  })
@@ -2,7 +2,7 @@
2
2
  // tools/shipkit/annex.md, Scratch). Each refusal guards what an unplugged drive must never take: a db, a lock, a git
3
3
  // worktree, what the backup holds, what the media store indexes, a file a process holds open. A move is a copy checked
4
4
  // by its count and bytes, then the swap
5
- import { closeSync, existsSync, lstatSync, mkdirSync, openSync, readdirSync, readlinkSync, readSync, renameSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
5
+ import { closeSync, existsSync, lstatSync, mkdirSync, openSync, readdirSync, readFileSync, readlinkSync, readSync, renameSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
6
6
  import { homedir } from 'node:os'
7
7
  import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path'
8
8
  import { machineGet, machineRead, machineSet } from '../core/machine-db.ts'
@@ -98,8 +98,8 @@ const save = (list: Offload[]): void => {
98
98
  }
99
99
 
100
100
  /** a name that marks a db or a lock: never on a drive that can be unplugged. LevelDB keeps `LOCK` and `MANIFEST-<n>`,
101
- * LMDB `data.mdb` and `lock.mdb` */
102
- export const DB_NAME = /(\.(sqlite3?|db)(-wal|-shm|-journal)?|\.lock|\.mdb)$|^(LOCK|MANIFEST-\d+|pb_data)$/i
101
+ * LMDB `data.mdb` and `lock.mdb`, DuckDB `<name>.duckdb` and its `.wal` */
102
+ export const DB_NAME = /(\.(sqlite3?|db|duckdb)(-wal|-shm|-journal|\.wal)?|\.lock|\.mdb)$|^(LOCK|MANIFEST-\d+|pb_data)$/i
103
103
  /** a package manager's lockfile is a text file, never a lock: it moves */
104
104
  const PACKAGE_LOCKS = new Set(['bun.lock', 'yarn.lock', 'Cargo.lock', 'poetry.lock', 'uv.lock', 'Gemfile.lock', 'composer.lock', 'flake.lock', 'Pipfile.lock', 'pdm.lock'])
105
105
  /** a vendored package's own marker files (setuptools' `_vendor/.lock`) are files of the package, never a live lock */
@@ -113,6 +113,13 @@ export function isDb(dir: string, rel: string, file: boolean): boolean {
113
113
  if (parts.some((p) => p === 'pb_data')) return true
114
114
  if (DB_NAME.test(name) && !PACKAGE_LOCKS.has(name) && !(name.endsWith('.lock') && parts.some((p) => PACKAGE_DIRS.has(p)))) return true
115
115
  if (!file) return false
116
+ // a LevelDB folder that holds no LOCK: its CURRENT names a manifest, or sits beside its tables and logs
117
+ if (name === 'CURRENT') {
118
+ const at = join(dir, ...parts.slice(0, -1))
119
+ try {
120
+ if (readdirSync(at).some((n) => /\.(ldb|log)$/.test(n)) || readFileSync(join(at, name), 'utf8').startsWith('MANIFEST-')) return true
121
+ } catch { /* unreadable: the header test below */ }
122
+ }
116
123
  let fd = -1
117
124
  try {
118
125
  fd = openSync(join(dir, rel), 'r')
@@ -211,7 +218,7 @@ export async function refusal(root: string, rel: string, o: Checks = {}): Promis
211
218
  const kept = await (o.backupHolds ?? backupHolds)(root, path, o.home ?? homedir())
212
219
  if (kept) return `the backup holds ${relative(root, kept)}: what a backup keeps stays on the Mac`
213
220
  const { mediaDb } = await import('../media-store/db.ts')
214
- const rows = (mediaDb()?.query('select store, item, name from files where local = 1').all() ?? []) as { store: string; item: string; name: string }[]
221
+ const rows = (mediaDb()?.query('select store, item, name from media_files where local = 1').all() ?? []) as { store: string; item: string; name: string }[]
215
222
  const indexed = rows.map((r) => join(r.store, r.item, r.name)).find((p) => p === path || p.startsWith(`${path}/`))
216
223
  if (indexed) return `the media store indexes ${relative(root, indexed)}: its purge moves media to the annex, never an offload`
217
224
  if (o.open === false) return null
@@ -221,6 +228,10 @@ export async function refusal(root: string, rel: string, o: Checks = {}): Promis
221
228
  return null
222
229
  }
223
230
 
231
+ /** no annex is present, or none keeps its free space with the folder: a caller with somewhere else to go (the temp
232
+ * sweep deletes scratch) tells it from a refusal of the folder itself */
233
+ export class NoRoom extends Error {}
234
+
224
235
  export interface Moved {
225
236
  rel: string
226
237
  target: string
@@ -237,9 +248,9 @@ export async function offload(root: string, rel: string, o: Probe & { dry?: bool
237
248
  const src = join(root, rel)
238
249
  const t = tally(src)
239
250
  const present = await presentAnnexes()
240
- if (present.length === 0) throw new Error('no annex is present: plug the drive in, or sk annex init <path>')
251
+ if (present.length === 0) throw new NoRoom('no annex is present: plug the drive in, or sk annex init <path>')
241
252
  const annex = present.find((a) => driveFree(a.path) - t.bytes >= keepFree(a))
242
- if (!annex) throw new Error(`no annex present keeps its free space with ${rel} (${(t.bytes / GB).toFixed(1)} GB)`)
253
+ if (!annex) throw new NoRoom(`no annex present keeps its free space with ${rel} (${(t.bytes / GB).toFixed(1)} GB)`)
243
254
  const target = join(annex.path, 'offload', basename(root), rel)
244
255
  if (existsSync(target)) throw new Error(`${target} exists already: an earlier offload, look before you move`)
245
256
  const owner = ownerOf(root, target)
package/src/annex/tidy.ts CHANGED
@@ -7,7 +7,9 @@
7
7
  // whatever the pressure: lanes write into scratch all day, and the offload's own checks are the net, not the plan
8
8
  import { existsSync, lstatSync, readdirSync, readFileSync, rmSync, type Stats, writeFileSync } from 'node:fs'
9
9
  import { dirname, join } from 'node:path'
10
+ import { LAYOUT } from '../core/layout.ts'
10
11
  import { machineDbPath, machineGet, machineSet } from '../core/machine-db.ts'
12
+ import { repoSweepOn } from '../home/machine-temp.ts'
11
13
  import { freeBytes } from '../media-store/purge.ts'
12
14
  import { annexSpecs, type AnnexSpec, driveFree, isPresent, keepFree, type Sweep } from './annex.ts'
13
15
  import { bear, bornCheck, deadStage, type Pass, sayOnce, settle } from './born.ts'
@@ -74,6 +76,26 @@ export function policyOf(house: AnnexScratch | undefined, repo: RepoAnnex | unde
74
76
  }
75
77
  }
76
78
 
79
+ /** the scratch folders the annex config declares for the repo at `root`, repo relative: its own `annex.born` and
80
+ * `annex.keep` and the house's `serve.annexScratch.born`, read from the configs the annex pass reads. A repo with no
81
+ * repo.config.ts declares the house's only. A config that does not load throws: a caller judges nothing of that repo
82
+ * without its declarations */
83
+ export async function annexDeclared(root: string, house: string | null): Promise<string[]> {
84
+ const { loadRepoConfig } = await import('../repo-config.ts')
85
+ const own = existsSync(join(root, 'repo.config.ts')) ? await loadRepoConfig(root) : null
86
+ const houseScratch = house == null ? undefined : house === root ? own?.serve?.annexScratch : (await loadRepoConfig(house)).serve?.annexScratch
87
+ const p = policyOf(houseScratch, own?.annex ?? {})
88
+ return [...new Set([...p.born, ...p.keep])]
89
+ }
90
+
91
+ /** the one answer to « is this folder declared »: `inside`, at or under a declared folder; `holds`, a folder above one;
92
+ * `which`, the declared folder that keeps `rel` either way, or null */
93
+ export function declaredOf(fixed: readonly string[]): { inside: (rel: string) => boolean; holds: (rel: string) => boolean; which: (rel: string) => string | null } {
94
+ const inside = (rel: string): boolean => fixed.some((k) => rel === k || rel.startsWith(`${k}/`))
95
+ const holds = (rel: string): boolean => fixed.some((k) => k.startsWith(`${rel}/`))
96
+ return { inside, holds, which: (rel) => fixed.find((k) => rel === k || rel.startsWith(`${k}/`) || k.startsWith(`${rel}/`)) ?? null }
97
+ }
98
+
77
99
  /** bytes of a repo's scratch on the Mac: `.shipkit/tmp` and `.shipkit/cache`, links not followed, so an offloaded
78
100
  * folder counts nothing and a spill counts whole (`du`: 0.5 s on 36 GB) */
79
101
  export function scratchOnMac(root: string): number {
@@ -112,19 +134,18 @@ function walk(dir: string): { bytes: number; newest: number } {
112
134
  }
113
135
 
114
136
  /** the name a move in flight leaves: an offload's `.part` or aside, a swap first move's aside, a copy brought back */
115
- const IN_FLIGHT = /\.\d+\.(part|offloading|moving|back)$/
137
+ export const IN_FLIGHT = /\.\d+\.(part|offloading|moving|back)$/
116
138
 
117
139
  export type Stale = { rel: string; bytes: number; newest: number }
118
140
 
119
141
  /** folders of the repo's scratch nothing touched for `days`, 50 MB or more, oldest first: each child of
120
142
  * `.shipkit/tmp` and `.shipkit/cache`, and the children of a fresh one of 1 GB or more. Never a born or kept folder,
121
- * nor one that holds one */
143
+ * nor one that holds one. `.shipkit/tmp` is the machine's temp sweep's once its repo roots delete (machine-temp.ts):
144
+ * one mechanism a folder */
122
145
  export function staleFolders(root: string, p: ScratchPolicy, now: number, days: number, o: { minBytes?: number; descendBytes?: number } = {}): Stale[] {
123
146
  const minBytes = o.minBytes ?? MIN_STALE_BYTES
124
147
  const descendBytes = o.descendBytes ?? DESCEND_BYTES
125
- const fixed = [...p.born, ...p.keep]
126
- const inside = (rel: string): boolean => fixed.some((k) => rel === k || rel.startsWith(`${k}/`))
127
- const holds = (rel: string): boolean => fixed.some((k) => k.startsWith(`${rel}/`))
148
+ const { inside, holds } = declaredOf([...p.born, ...p.keep])
128
149
  const out: Stale[] = []
129
150
  const look = (rel: string, depth: number): void => {
130
151
  for (const name of readdirSync(join(root, rel))) {
@@ -140,14 +161,15 @@ export function staleFolders(root: string, p: ScratchPolicy, now: number, days:
140
161
  else if (depth === 1 && w.bytes >= descendBytes) look(r, 2)
141
162
  }
142
163
  }
143
- for (const base of SCRATCH) if (lstatSync(join(root, base), { throwIfNoEntry: false })?.isDirectory() && !inside(base)) look(base, 1)
164
+ const bases = SCRATCH.filter((b) => b !== LAYOUT.tmp || !repoSweepOn(now))
165
+ for (const base of bases) if (lstatSync(join(root, base), { throwIfNoEntry: false })?.isDirectory() && !inside(base)) look(base, 1)
144
166
  return out.sort((a, b) => a.newest - b.newest || b.bytes - a.bytes)
145
167
  }
146
168
 
147
169
  export type Aged = { moved: { rel: string; bytes: number }[]; refused: { rel: string; why: string }[]; onMac: number; free: number; days: number | null }
148
170
 
149
171
  /** stale scratch of `root` to the annex, oldest first, while the disk is under the floor or the repo over its cap */
150
- export async function agePass(root: string, p: ScratchPolicy, o: Probe & { now?: number; dry?: boolean; minBytes?: number }): Promise<Aged> {
172
+ export async function agePass(root: string, p: ScratchPolicy, o: Probe & { now?: number; dry?: boolean; minBytes?: number; fresh?: boolean }): Promise<Aged> {
151
173
  const now = o.now ?? Date.now()
152
174
  let onMac = scratchOnMac(root)
153
175
  let free = freeBytes(root)
@@ -156,23 +178,61 @@ export async function agePass(root: string, p: ScratchPolicy, o: Probe & { now?:
156
178
  if (!pressed()) return out
157
179
  const days = free < p.floorGb * GB ? 1 : p.staleDays
158
180
  out.days = days
159
- for (const s of staleFolders(root, p, now, days, o)) {
181
+ // a dry pass and a pass by hand (`fresh`) ask every folder again and leave the memory as it is
182
+ const remembers = o.dry !== true && o.fresh !== true
183
+ const known: Refusals = remembers ? (machineGet<Refusals>(REFUSED) ?? {}) : {}
184
+ let moved = false
185
+ const stale = staleFolders(root, p, now, days, o)
186
+ for (const s of stale) {
160
187
  if (!pressed()) break
188
+ const key = refusalKey(root, s.rel)
189
+ const was = known[key]
190
+ if (was !== undefined && was.newest === s.newest && now - was.at < REFUSAL_KEEP_MS) {
191
+ out.refused.push({ rel: s.rel, why: was.why })
192
+ continue
193
+ }
161
194
  try {
162
195
  const m = await offload(root, s.rel, { ...o, dry: o.dry === true })
163
196
  onMac -= m.bytes
164
197
  if (o.dry) free += m.bytes
165
198
  else free = freeBytes(root)
166
199
  out.moved.push({ rel: s.rel, bytes: m.bytes })
200
+ if (was !== undefined) {
201
+ delete known[key]
202
+ moved = true
203
+ }
167
204
  } catch (e) {
168
- out.refused.push({ rel: s.rel, why: (e as Error).message })
205
+ const why = (e as Error).message
206
+ out.refused.push({ rel: s.rel, why })
207
+ if (remembers) {
208
+ known[key] = { why, newest: s.newest, at: now }
209
+ moved = true
210
+ }
169
211
  }
170
212
  }
213
+ if (remembers) {
214
+ const here = new Set(stale.map((s) => refusalKey(root, s.rel)))
215
+ for (const k of Object.keys(known))
216
+ if (k.startsWith(`${root}\u0000`) && !here.has(k)) {
217
+ delete known[k]
218
+ moved = true
219
+ }
220
+ if (moved) machineSet(REFUSED, known)
221
+ }
171
222
  out.onMac = onMac
172
223
  out.free = free
173
224
  return out
174
225
  }
175
226
 
227
+ /** how long the daemon's pass trusts a refusal of a folder nothing wrote since. Each refused folder costs its
228
+ * checks again at every pass (a `lsof`, a look at the annex: 0.05 to 1.6 s each, 6.4 s for one repo's 14 folders
229
+ * every 10 min): the reason holds while the folder is as it was, and the rest (a process that left, an annex copy
230
+ * someone removed) is asked again after this long */
231
+ export const REFUSAL_KEEP_MS = 6 * 3_600_000
232
+ const REFUSED = 'annex-refused'
233
+ type Refusals = Record<string, { why: string; newest: number; at: number }>
234
+ const refusalKey = (root: string, rel: string): string => `${root}\u0000${rel}`
235
+
176
236
  /** trim an annex's scratch (`offload/`) under its `scratchMaxGb`, and its drive to `keepFreeGb`: files untouched for
177
237
  * SCRATCH_KEEP_DAYS at the least, oldest first. A loser a merge kept is never one of them: it goes only by a hand.
178
238
  * A staging folder shipkit marked whose process is dead goes at every sweep. Its measure is kept for `sk annex` */
@@ -341,7 +401,7 @@ async function tick(o: TickOpts): Promise<void> {
341
401
  if (offloads().some(unborn)) editOffloads((list) => list.map((x) => (unborn(x) ? { ...x, born: false } : x)))
342
402
  }
343
403
  floor = p.floorGb
344
- const a = await agePass(root, p, { ...o, now })
404
+ const a = await agePass(root, p, { ...o, now, fresh: o.full === true })
345
405
  if (a.days === null) {
346
406
  if (o.dry) o.print(`${root}: scratch on the Mac ${(a.onMac / GB).toFixed(1)} GB of ${p.capGb} GB, the disk ${(a.free / GB).toFixed(1)} GB free over its ${p.floorGb} GB floor: nothing to move`)
347
407
  continue
@@ -0,0 +1,40 @@
1
+ // an ask's `after:` value: the moment the ask waits for. Before it the ask is later (out of the open count and the
2
+ // ping), from it an open ask. Pure and browser safe: the queue (asks-queue.ts) parses with it, the hub draws with it
3
+ const VALUE = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2}))?$/
4
+
5
+ export const AFTER_FORMS = 'YYYY-MM-DD or YYYY-MM-DDTHH:MM, local time'
6
+
7
+ /** the moment a value names, local time, a bare date the start of its day; null when it names none */
8
+ export function afterMs(v: string): number | null {
9
+ const m = VALUE.exec(v.trim())
10
+ if (m == null) return null
11
+ const [y, mo, d, h, mi] = [Number(m[1]), Number(m[2]), Number(m[3]), Number(m[4] ?? 0), Number(m[5] ?? 0)]
12
+ const t = new Date(y, mo - 1, d, h, mi)
13
+ // a value that rolls over (02-30, 25:00) names no moment
14
+ if (t.getFullYear() !== y || t.getMonth() !== mo - 1 || t.getDate() !== d || h > 23 || mi > 59) return null
15
+ return t.getTime()
16
+ }
17
+
18
+ const pad = (n: number): string => String(n).padStart(2, '0')
19
+ const dayOf = (t: Date): string => `${t.getFullYear()}-${pad(t.getMonth() + 1)}-${pad(t.getDate())}`
20
+
21
+ /** what `--after` writes: a date or a date and time as given, `<n>d` or `<n>w` from `now` as that day */
22
+ export function afterValue(arg: string, now: Date): string {
23
+ const v = arg.trim()
24
+ if (afterMs(v) != null) return v
25
+ const rel = /^(\d+)([dw])$/.exec(v)
26
+ if (rel == null) throw new Error(`--after '${arg}' names no day: write ${AFTER_FORMS}, or 2d, 1w from today`)
27
+ const days = Number(rel[1]) * (rel[2] === 'w' ? 7 : 1)
28
+ return dayOf(new Date(now.getFullYear(), now.getMonth(), now.getDate() + days))
29
+ }
30
+
31
+ const DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
32
+ const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
33
+
34
+ /** `after Sat 21 Nov`, with its time when the value names one; the value itself when it names no moment */
35
+ export function afterWords(v: string): string {
36
+ const ms = afterMs(v)
37
+ if (ms == null) return `after ${v}`
38
+ const t = new Date(ms)
39
+ return `after ${DAYS[t.getDay()]} ${t.getDate()} ${MONTHS[t.getMonth()]}${v.includes('T') ? ` ${pad(t.getHours())}:${pad(t.getMinutes())}` : ''}`
40
+ }