rvlib-shipkit 2.31.0 → 2.33.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 (408) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/package.json +1 -1
  3. package/src/advisors/acts.ts +16 -15
  4. package/src/advisors/advice.ts +56 -102
  5. package/src/advisors/advisor-view.ts +122 -76
  6. package/src/advisors/app-graph.ts +1 -1
  7. package/src/advisors/app.ts +3 -11
  8. package/src/advisors/cf-api.ts +1 -1
  9. package/src/advisors/dir-bucket.ts +4 -3
  10. package/src/advisors/edge/api.ts +20 -221
  11. package/src/advisors/edge/bucket.ts +2 -2
  12. package/src/advisors/edge/handler.ts +13 -155
  13. package/src/advisors/edge/here.ts +5 -5
  14. package/src/advisors/edge/pages.ts +12 -9
  15. package/src/advisors/edge/shell.ts +6 -5
  16. package/src/advisors/edge/sign-in.ts +101 -36
  17. package/src/advisors/edge/status.ts +19 -6
  18. package/src/advisors/edge/types.ts +36 -60
  19. package/src/advisors/expose.ts +29 -29
  20. package/src/advisors/here.ts +12 -12
  21. package/src/advisors/invite-send.ts +79 -35
  22. package/src/advisors/invite.ts +31 -8
  23. package/src/advisors/job.ts +24 -16
  24. package/src/advisors/login.ts +40 -15
  25. package/src/advisors/owner-store.ts +46 -22
  26. package/src/advisors/photos.ts +3 -3
  27. package/src/advisors/project.ts +27 -25
  28. package/src/advisors/reach.ts +89 -0
  29. package/src/advisors/rights.ts +1 -1
  30. package/src/advisors/routes.ts +55 -74
  31. package/src/advisors/scan.ts +0 -4
  32. package/src/advisors/setup-run.ts +14 -14
  33. package/src/advisors/share-trace.ts +3 -3
  34. package/src/advisors/{door-probe.ts → sign-in-probe.ts} +7 -6
  35. package/src/advisors/speaks.ts +29 -0
  36. package/src/advisors/sync.ts +97 -183
  37. package/src/advisors/tunnel.ts +6 -5
  38. package/src/advisors/users-listen.ts +92 -0
  39. package/src/advisors/users-router.ts +261 -87
  40. package/src/advisors/users-store.ts +81 -0
  41. package/src/agent-time/blocked-scan.ts +181 -0
  42. package/src/agent-time/registry.ts +12 -5
  43. package/src/agent-time/store.ts +9 -109
  44. package/src/asks/ask-bar-fold.ts +2 -1
  45. package/src/asks/ask-close.ts +2 -1
  46. package/src/asks/ask-doc.ts +2 -1
  47. package/src/asks/ask-migrate.ts +3 -2
  48. package/src/asks/ask-steps-fold.ts +2 -1
  49. package/src/asks/ask-store.ts +4 -3
  50. package/src/check.ts +3 -43
  51. package/src/checks/SK001-package-json-shape.check.ts +4 -55
  52. package/src/checks/SK004-gitignore-policy.check.ts +24 -69
  53. package/src/checks/SK013-one-way-in-policy.check.ts +3 -7
  54. package/src/checks/SK017-vscode-hub-task.check.ts +4 -4
  55. package/src/checks/SK019-tests-run-in-units.check.ts +3 -14
  56. package/src/checks/SK020-self-spawning-check.check.ts +5 -7
  57. package/src/checks/SK035-public-clean.check.ts +1 -1
  58. package/src/checks/SK039-vscode-watch-generated.check.ts +1 -1
  59. package/src/checks/SK042-post-kinds.check.ts +5 -14
  60. package/src/checks/SK054-agent-allow-list.check.ts +5 -74
  61. package/src/checks/SK055-retired-config-keys.check.ts +45 -0
  62. package/src/cli/cmd_Advisors.ts +11 -45
  63. package/src/cli/cmd_Asks.ts +3 -10
  64. package/src/cli/cmd_Backup.ts +25 -127
  65. package/src/cli/cmd_BackupTargets.ts +1 -1
  66. package/src/cli/cmd_Capacity.ts +6 -2
  67. package/src/cli/cmd_Checks.ts +0 -14
  68. package/src/cli/cmd_Ci.ts +2 -1
  69. package/src/cli/cmd_Db.ts +3 -82
  70. package/src/cli/cmd_Home.ts +4 -32
  71. package/src/cli/cmd_Hq.ts +0 -17
  72. package/src/cli/cmd_Releases.ts +57 -4
  73. package/src/cli/cmd_Review.ts +333 -354
  74. package/src/cli/cmd_Shot.ts +26 -4
  75. package/src/cli/cmd_SocialDrafts.ts +6 -13
  76. package/src/cli/cmd_ThreadSyncNeeds.ts +6 -2
  77. package/src/cli/cmd_Time.ts +1 -1
  78. package/src/cli/cmd_Trailer.ts +1 -1
  79. package/src/cli/inbox-hook-run.ts +5 -23
  80. package/src/cli/registry-heads.ts +5 -55
  81. package/src/cli/registry.ts +1 -5
  82. package/src/cli/review-here.ts +1 -1
  83. package/src/cli.ts +15 -4
  84. package/src/collections/collection-types.ts +1 -1
  85. package/src/collections/review.ts +5 -4
  86. package/src/core/admission.ts +268 -0
  87. package/src/core/agent-allow-policy.ts +32 -2
  88. package/src/core/agent-env.ts +8 -0
  89. package/src/core/allow-rows.ts +74 -0
  90. package/src/core/check-file-names.ts +19 -106
  91. package/src/core/code-lines.ts +36 -21
  92. package/src/core/footprint.ts +17 -13
  93. package/src/core/identities-root.ts +1 -4
  94. package/src/core/layout.ts +1 -2
  95. package/src/core/machine-db.ts +33 -208
  96. package/src/core/machine-layout.ts +14 -127
  97. package/src/core/machine-read.ts +5 -2
  98. package/src/core/mask-source.ts +60 -0
  99. package/src/core/memory-watch.ts +17 -14
  100. package/src/core/motherhome.ts +8 -35
  101. package/src/core/one-way-in-policy.ts +0 -3
  102. package/src/core/peer-sk.ts +8 -0
  103. package/src/core/repo-walk.ts +0 -9
  104. package/src/core/retention.ts +1 -9
  105. package/src/core/retired-checks.ts +2 -0
  106. package/src/core/tmux-policy.ts +1 -1
  107. package/src/core/tree-watch.ts +2 -2
  108. package/src/core/when.ts +7 -45
  109. package/src/gate/admit-heavy.ts +150 -0
  110. package/src/gate/check-runner.ts +6 -0
  111. package/src/gate/discover-checks.ts +42 -32
  112. package/src/gate/gate-checks.ts +21 -131
  113. package/src/gate/head-gate.ts +1 -1
  114. package/src/gate/job-run.ts +2 -1
  115. package/src/gate/pre-commit-discovery.ts +22 -28
  116. package/src/gate/run-check.ts +3 -4
  117. package/src/gate/run-ci.ts +4 -0
  118. package/src/gate/run-fix.ts +5 -17
  119. package/src/gate/run-fixers.ts +6 -42
  120. package/src/home/app-sign.ts +2 -2
  121. package/src/home/backup-status.ts +52 -92
  122. package/src/home/backup-verdict.ts +2 -2
  123. package/src/home/daemon-jobs.ts +51 -95
  124. package/src/home/database-words.ts +1 -2
  125. package/src/home/databases.ts +9 -25
  126. package/src/home/home-launchd.ts +0 -6
  127. package/src/home/home-paths.ts +8 -4
  128. package/src/home/home-routes.ts +3 -10
  129. package/src/home/home-state.ts +2 -14
  130. package/src/home/inbox-shape.ts +14 -15
  131. package/src/home/inbox.ts +1 -1
  132. package/src/home/machine-repair.ts +102 -103
  133. package/src/home/resume.ts +1 -15
  134. package/src/home/run-daemon.ts +7 -12
  135. package/src/home/space-page.ts +3 -2
  136. package/src/home/supervise.ts +3 -7
  137. package/src/hooks/commit-msg-run.ts +61 -0
  138. package/src/hooks/commit-run.ts +16 -166
  139. package/src/hooks/gate-outcome.ts +108 -0
  140. package/src/hooks/git-hook.ts +9 -9
  141. package/src/hooks/hook-config.ts +8 -8
  142. package/src/hooks/leak-guard.ts +1 -1
  143. package/src/hooks/pre-commit-checks.ts +1 -1
  144. package/src/hooks/run-hooks.ts +2 -6
  145. package/src/hooks/shared-file.ts +3 -2
  146. package/src/hq/daemon-db.ts +8 -8
  147. package/src/hq/door.ts +3 -16
  148. package/src/hq/hq-db.ts +4 -3
  149. package/src/hq/hq-local.ts +1 -2
  150. package/src/hq/hq-store.ts +0 -15
  151. package/src/hq/item-direct.ts +8 -10
  152. package/src/hq/item-fill.ts +37 -0
  153. package/src/hq/kinds/item-gone.ts +7 -10
  154. package/src/hq/kinds/item-msg.ts +12 -18
  155. package/src/hq/kinds/item.ts +13 -19
  156. package/src/hq/kinds/report.ts +3 -4
  157. package/src/hq/owner-switch.ts +3 -3
  158. package/src/hq/report.ts +5 -9
  159. package/src/hq/switch.ts +2 -11
  160. package/src/hq/thread-sync.ts +5 -17
  161. package/src/hq/{shapes-words.ts → threads-words.ts} +2 -12
  162. package/src/http/owner-word.ts +1 -1
  163. package/src/identities/machine.ts +16 -0
  164. package/src/init-repo.ts +0 -1
  165. package/src/ledger/check-stats.ts +6 -5
  166. package/src/ledger/db.ts +2 -4
  167. package/src/ledger/record-kept.ts +117 -48
  168. package/src/ledger/run-log.ts +21 -2
  169. package/src/ledger/slow-tests.ts +96 -0
  170. package/src/ledger/store.ts +3 -86
  171. package/src/ledger/suite-log.ts +8 -2
  172. package/src/media-store/backup/facts.ts +3 -37
  173. package/src/media-store/backup/keys.ts +1 -8
  174. package/src/media-store/backup/manifest.ts +6 -67
  175. package/src/media-store/backup/restore.ts +4 -13
  176. package/src/media-store/backup/retention.ts +13 -1
  177. package/src/media-store/backup/run.ts +6 -267
  178. package/src/media-store/backup/snapshot.ts +2 -38
  179. package/src/media-store/backup/sources.ts +3 -113
  180. package/src/media-store/backup/target-send.ts +5 -29
  181. package/src/media-store/db.ts +8 -7
  182. package/src/media-store/forget-one.ts +1 -1
  183. package/src/media-store/forget.ts +1 -80
  184. package/src/orchestrator/guards.ts +0 -1
  185. package/src/orchestrator/presence.ts +2 -2
  186. package/src/orchestrator/routes.ts +1 -1
  187. package/src/orchestrator/started.ts +0 -9
  188. package/src/orchestrator/talk-key.ts +3 -4
  189. package/src/orchestrator/unheard.ts +1 -1
  190. package/src/plan/planner.ts +3 -2
  191. package/src/recordings/edit.ts +3 -3
  192. package/src/recordings/marks-draw.ts +17 -6
  193. package/src/recordings/marks.ts +120 -9
  194. package/src/reflections/reflections-queue.ts +3 -10
  195. package/src/release/notes.ts +1 -1
  196. package/src/release/public-clean.ts +66 -6
  197. package/src/release/run-bump.ts +11 -0
  198. package/src/release/run-release.ts +4 -0
  199. package/src/releases/from-thread.ts +3 -3
  200. package/src/releases/model.ts +186 -36
  201. package/src/releases/store.ts +13 -3
  202. package/src/releases/validate.ts +83 -0
  203. package/src/repo-config.ts +36 -64
  204. package/src/review/answer-kinds.ts +63 -4
  205. package/src/review/blocked-guard.ts +11 -0
  206. package/src/review/blocked-object.ts +298 -0
  207. package/src/review/cells.ts +144 -230
  208. package/src/review/close.ts +39 -1
  209. package/src/review/doc-save.ts +3 -2
  210. package/src/review/draft-item.ts +1 -1
  211. package/src/review/events.ts +3 -7
  212. package/src/review/expect.ts +23 -39
  213. package/src/review/format.ts +79 -46
  214. package/src/review/glyphs.ts +1 -0
  215. package/src/review/hand-over.ts +3 -3
  216. package/src/review/heard.ts +1 -1
  217. package/src/review/holds-sync.ts +2 -1
  218. package/src/review/inbox-hook.ts +2 -2
  219. package/src/review/inbox-read.ts +39 -33
  220. package/src/review/instruction-guards.ts +12 -0
  221. package/src/review/instructions.ts +0 -1
  222. package/src/review/item-db.ts +13 -43
  223. package/src/review/item-hq.ts +2 -2
  224. package/src/review/item-rows.ts +3 -14
  225. package/src/review/kind-catalog.ts +3 -1
  226. package/src/review/kinds.ts +18 -8
  227. package/src/review/live-view.ts +3 -0
  228. package/src/review/media-kind.ts +1 -1
  229. package/src/review/mentions.ts +1 -2
  230. package/src/review/model.ts +158 -114
  231. package/src/review/move.ts +149 -0
  232. package/src/review/need-threads.ts +3 -2
  233. package/src/review/object-card.ts +11 -0
  234. package/src/review/object-read.ts +6 -1
  235. package/src/review/one-block.ts +1 -1
  236. package/src/review/owner-read.ts +1 -1
  237. package/src/review/phone-push.ts +10 -9
  238. package/src/review/previews.ts +32 -4
  239. package/src/review/push.ts +2 -2
  240. package/src/review/recap.ts +129 -0
  241. package/src/review/referring.ts +6 -3
  242. package/src/review/reflection-object.ts +4 -3
  243. package/src/review/routes.ts +51 -47
  244. package/src/review/secret-route.ts +3 -2
  245. package/src/review/settle.ts +0 -6
  246. package/src/review/snooze.ts +5 -3
  247. package/src/review/speaker.ts +68 -0
  248. package/src/review/start-title.ts +19 -0
  249. package/src/review/store-parties.ts +28 -0
  250. package/src/review/store.ts +94 -59
  251. package/src/review/{wakes.ts → thread-events.ts} +92 -7
  252. package/src/review/thread-md.ts +35 -14
  253. package/src/review/thread-state.ts +804 -0
  254. package/src/review/threads.ts +29 -347
  255. package/src/review/traces.ts +104 -7
  256. package/src/review/trailer-item.ts +1 -1
  257. package/src/review/unit.ts +7 -9
  258. package/src/review/verdict-items.ts +12 -10
  259. package/src/review/view-layout.ts +25 -1
  260. package/src/review/watch-feed.ts +1 -2
  261. package/src/review/working-guards.ts +2 -3
  262. package/src/rules/untrack-generated.ts +1 -15
  263. package/src/secrets/copy.ts +4 -4
  264. package/src/secrets/lapse.ts +2 -1
  265. package/src/serve/hub-app/advisor-app.tsx +4 -4
  266. package/src/serve/hub-app/advisor-face.tsx +9 -3
  267. package/src/serve/hub-app/advisor-host.ts +27 -27
  268. package/src/serve/hub-app/advisors-model.ts +17 -8
  269. package/src/serve/hub-app/advisors-rights.tsx +1 -1
  270. package/src/serve/hub-app/advisors-st.ts +15 -14
  271. package/src/serve/hub-app/advisors-view.tsx +13 -11
  272. package/src/serve/hub-app/app-bridge.ts +23 -3
  273. package/src/serve/hub-app/asks-page.tsx +1 -1
  274. package/src/serve/hub-app/auto-text.tsx +71 -16
  275. package/src/serve/hub-app/check-view.tsx +0 -8
  276. package/src/serve/hub-app/controls.css +14 -3
  277. package/src/serve/hub-app/database-view.tsx +1 -2
  278. package/src/serve/hub-app/dock-st.ts +1 -1
  279. package/src/serve/hub-app/git-view.tsx +3 -1
  280. package/src/serve/hub-app/hub.css +12 -5
  281. package/src/serve/hub-app/icons.tsx +1 -1
  282. package/src/serve/hub-app/inbox-view.tsx +1 -2
  283. package/src/serve/hub-app/live-sources.ts +2 -2
  284. package/src/serve/hub-app/main-panel.tsx +2 -1
  285. package/src/serve/hub-app/panel-repo.ts +0 -9
  286. package/src/serve/hub-app/pic.tsx +29 -12
  287. package/src/serve/hub-app/polled.ts +16 -2
  288. package/src/serve/hub-app/recordings-st.ts +23 -2
  289. package/src/serve/hub-app/recordings-view.tsx +68 -10
  290. package/src/serve/hub-app/ref-pill.ts +1 -1
  291. package/src/serve/hub-app/repo-st.ts +1 -2
  292. package/src/serve/hub-app/review/advisor-add.tsx +1 -1
  293. package/src/serve/hub-app/review/advisor-invite.tsx +1 -1
  294. package/src/serve/hub-app/review/draft-body.tsx +2 -2
  295. package/src/serve/hub-app/review/heard-line.tsx +1 -1
  296. package/src/serve/hub-app/review/instructions-view.tsx +1 -8
  297. package/src/serve/hub-app/review/kind-states.tsx +14 -9
  298. package/src/serve/hub-app/review/kit.tsx +4 -11
  299. package/src/serve/hub-app/review/lane-bar.tsx +3 -3
  300. package/src/serve/hub-app/review/lightbox.tsx +15 -11
  301. package/src/serve/hub-app/review/line-window.ts +4 -1
  302. package/src/serve/hub-app/review/live-bar-st.ts +2 -2
  303. package/src/serve/hub-app/review/live-view.tsx +57 -1
  304. package/src/serve/hub-app/review/object-panel.tsx +20 -8
  305. package/src/serve/hub-app/review/question-views.tsx +191 -53
  306. package/src/serve/hub-app/review/recap-bar.tsx +40 -0
  307. package/src/serve/hub-app/review/request-cell.tsx +48 -0
  308. package/src/serve/hub-app/review/review-cells.tsx +154 -96
  309. package/src/serve/hub-app/review/review-host.ts +8 -4
  310. package/src/serve/hub-app/review/review-kit.ts +17 -11
  311. package/src/serve/hub-app/review/review-list.tsx +30 -35
  312. package/src/serve/hub-app/review/review-st.ts +32 -42
  313. package/src/serve/hub-app/review/review-thread.tsx +139 -85
  314. package/src/serve/hub-app/review/review-views.tsx +127 -68
  315. package/src/serve/hub-app/review/share-lines.tsx +4 -4
  316. package/src/serve/hub-app/review/start-st.ts +2 -5
  317. package/src/serve/hub-app/review/superseded-runs.ts +4 -3
  318. package/src/serve/hub-app/review/thread-close.tsx +10 -7
  319. package/src/serve/hub-app/review/thread-st.ts +381 -202
  320. package/src/serve/hub-app/review/tone-bar.tsx +129 -0
  321. package/src/serve/hub-app/review/tones.ts +53 -0
  322. package/src/serve/hub-app/review/trailer-body.tsx +2 -2
  323. package/src/serve/hub-app/review/trailer-st.ts +3 -2
  324. package/src/serve/hub-app/review/trailer-voices-st.ts +3 -2
  325. package/src/serve/hub-app/review.css +189 -106
  326. package/src/serve/hub-app/search-view.tsx +1 -1
  327. package/src/serve/hub-app/social/social-model.ts +0 -4
  328. package/src/serve/hub-app/source-acts.ts +2 -1
  329. package/src/serve/hub-app/stores/stores-page.tsx +2 -2
  330. package/src/serve/hub-app/terminal-sources.tsx +2 -1
  331. package/src/serve/hub-app/thread-row.tsx +3 -4
  332. package/src/serve/hub-app/tree-build.ts +0 -4
  333. package/src/serve/hub-app/urls-view.tsx +2 -1
  334. package/src/serve/hub-app/view-layout.css +13 -3
  335. package/src/serve/hub-app/wikis-view.tsx +5 -2
  336. package/src/serve/hub-runtime.ts +7 -37
  337. package/src/serve/project-gutter-route.ts +6 -2
  338. package/src/serve/read-thread.ts +20 -2
  339. package/src/serve/read-worker.ts +9 -1
  340. package/src/serve/record-pages.ts +46 -0
  341. package/src/serve/serve-hub.ts +2 -2
  342. package/src/serve/terminal-host.ts +1 -1
  343. package/src/serve/terminal-route.ts +1 -3
  344. package/src/serve/tracked-watch.ts +1 -3
  345. package/src/setup-house.ts +2 -2
  346. package/src/shipkit-files.ts +1 -1
  347. package/src/shipkit.ts +1 -6
  348. package/src/shot/client.ts +2 -1
  349. package/src/shot/film-box.ts +0 -20
  350. package/src/shot/on-place.ts +141 -0
  351. package/src/social/drafts.ts +1 -1
  352. package/src/social/kinds.ts +6 -29
  353. package/src/social/load.ts +2 -2
  354. package/src/social/post-object.ts +3 -2
  355. package/src/social/release-stage.ts +1 -1
  356. package/src/social/stage.ts +2 -2
  357. package/src/stores/model.ts +4 -0
  358. package/src/stores/routes.ts +11 -3
  359. package/src/suite/judge-suites.ts +58 -0
  360. package/src/suite/red-alone.ts +54 -18
  361. package/src/suite/runner-shapes.ts +2 -2
  362. package/src/suite/suite-cli.ts +67 -14
  363. package/src/suite/test-units.ts +2 -1
  364. package/src/urls/fill.ts +1 -1
  365. package/src/urls/places.ts +1 -2
  366. package/src/vault/vault-config.ts +2 -2
  367. package/src/vault/vault-init.ts +1 -5
  368. package/src/wiki/graph-page.ts +14 -2
  369. package/src/advisors/copy-truth.ts +0 -49
  370. package/src/advisors/door-child.ts +0 -112
  371. package/src/advisors/door-serve.ts +0 -52
  372. package/src/advisors/door.ts +0 -118
  373. package/src/checks/SK016-legacy-check-shapes.check.ts +0 -189
  374. package/src/checks/SK029-explicit-check-files.check.ts +0 -112
  375. package/src/checks/SK048-one-local-file.check.ts +0 -36
  376. package/src/core/config-rewrite.ts +0 -111
  377. package/src/core/daemon-port.ts +0 -10
  378. package/src/core/legacy-shapes.ts +0 -263
  379. package/src/core/migrate-layout.ts +0 -638
  380. package/src/core/port-check-cli.ts +0 -52
  381. package/src/core/port-check-file.ts +0 -295
  382. package/src/core/port-check-files.ts +0 -31
  383. package/src/gate/discover-legacy-checks.ts +0 -26
  384. package/src/home/home-move.ts +0 -527
  385. package/src/home/machine-fold.ts +0 -810
  386. package/src/hq/item-shapes.ts +0 -54
  387. package/src/hq/kinds/items-read.ts +0 -4
  388. package/src/media-store/backup/daemon.ts +0 -220
  389. package/src/media-store/backup/kept.ts +0 -241
  390. package/src/media-store/backup/prune.ts +0 -359
  391. package/src/media-store/backup/secret.ts +0 -88
  392. package/src/media-store/backup/ssh-space.ts +0 -202
  393. package/src/media-store/backup/watch.ts +0 -117
  394. package/src/review/band.ts +0 -182
  395. package/src/review/folders.ts +0 -216
  396. package/src/review/hook-ask.ts +0 -58
  397. package/src/review/role.ts +0 -48
  398. package/src/review/thread-fold.ts +0 -64
  399. package/src/review/wait.ts +0 -91
  400. package/src/rules/rule.ts +0 -43
  401. package/src/serve/hook-thread.ts +0 -37
  402. package/src/serve/hook-work.ts +0 -92
  403. package/src/serve/hook-worker.ts +0 -57
  404. package/src/serve/hub-app/review/dock.tsx +0 -147
  405. package/src/serve/hub-app/review/faces.tsx +0 -18
  406. package/src/serve/hub-app/review/item-verdict.tsx +0 -112
  407. package/src/serve/hub-app/review/review-board.tsx +0 -48
  408. /package/src/{scaffold → core}/jsonc-spans.ts +0 -0
@@ -1,21 +1,20 @@
1
1
  // the inbox as data (wiki tools/shipkit/home-inbox.md): every thread of every house repo, each once, in the list of who
2
- // acts now, badged with what it waits on from him (review/wait.ts). Pure and browser safe: the daemon (inbox.ts), the
2
+ // acts now, badged with what it waits on from him (review/thread-state.ts). Pure and browser safe: the daemon (inbox.ts), the
3
3
  // page and the tests share it. Each repo gives what it already holds, never a store of its own: its review store's
4
4
  // thread index and its hub's needs, a need being a row only while no thread stands for it.
5
5
  //
6
6
  // the one constraint a reader breaks first: a row is never typed by what its thread is (a version, an ask, a check);
7
7
  // its badge is the verb, so the filter and the counts read one field, `wait`
8
8
  import { REVIEW_COL, type Resource } from '../collections/collection-types.ts'
9
- import { bandOf, staleWorkingOf } from '../review/band.ts'
10
9
  import type { ThreadIndex, ThreadRow } from '../review/cells.ts'
11
10
  import { canonicalAddress } from '../review/model.ts'
12
11
  import { needAddress } from '../review/need-address.ts'
13
12
  import { hearingOf, NO_PARTIES, type Parties } from '../review/parties.ts'
14
- import { askVerb, isOwnerWait, OWNER_WAITS, waitsMatch, type OwnerWait, type Wait, type WaitsOn } from '../review/wait.ts'
13
+ import { bandOf, staleWorkingOf, askVerb, isOwnerWait, OWNER_WAITS, waitsMatch, type OwnerWait, type Wait, type WaitsOn } from '../review/thread-state.ts'
15
14
 
16
- export { OWNER_WAITS, type OwnerWait, type Wait } from '../review/wait.ts'
15
+ export { OWNER_WAITS, type OwnerWait, type Wait } from '../review/thread-state.ts'
17
16
 
18
- /** who acts now (review/band.ts): him (`main`), a live agent works on it (`working`), an agent's move nobody works
17
+ /** who acts now (review/thread-state.ts): him (`main`), a live agent works on it (`working`), an agent's move nobody works
19
18
  * (`waiting`), him from a day still ahead (`later`), nobody (`done`) */
20
19
  export type InboxList = 'main' | 'working' | 'waiting' | 'later' | 'done'
21
20
  /** the lists in the order drawn */
@@ -44,11 +43,11 @@ export interface InboxRow {
44
43
  col?: string
45
44
  /** what it waits on from him first: the badge */
46
45
  wait: Wait
47
- /** what waits on him first, the icon its row draws (review/wait.ts waitEntryOf) */
46
+ /** what waits on him first, the icon its row draws (review/thread-state.ts ThreadState wait, waitsOn) */
48
47
  waitsOn?: WaitsOn
49
- /** on an agent's move after his last word, what still waits on him: a quiet mark, never his list (review/wait.ts waitEntryOf) */
48
+ /** on an agent's move after his last word, what still waits on him: a quiet mark, never his list (review/thread-state.ts ThreadState owed) */
50
49
  owed?: OwnerWait
51
- /** every verb its open objects ask: what the verbs filter and its counts read (review/wait.ts verbsOf) */
50
+ /** every verb its open objects ask: what the verbs filter and its counts read (review/thread-state.ts ThreadState verbs) */
52
51
  verbs: OwnerWait[]
53
52
  title: string
54
53
  /** agent words he has not read */
@@ -120,16 +119,16 @@ const IMAGE = /\.(png|jpe?g|webp)$/i
120
119
 
121
120
  /** the list of who acts now on a thread: its band, with the repo's parties */
122
121
  const listOfRow = (r: ThreadRow, p: Parties): InboxList => {
123
- const b = bandOf(r, p)
122
+ const b = bandOf(r.state, p)
124
123
  return b === 'yours' ? 'main' : b === 'aside' ? 'later' : b
125
124
  }
126
125
 
127
126
  function threadRow(repo: string, r: ThreadRow, wait: Wait, verbs: OwnerWait[], p: Parties | null): InboxRow {
128
- const later = r.turn === 'aside' && r.aside != null ? `after ${r.aside.until.slice(0, 10)}` : null
127
+ const later = r.state.turn === 'aside' && r.state.aside != null ? `after ${r.state.aside.until.slice(0, 10)}` : null
129
128
  // his turn and no live party hears his answer: he knows to ping a session
130
- const hearing = p !== null && isOwnerWait(wait) && r.turn !== 'aside' ? hearingOf(r.holder ? { ...r.holder, at: '' } : null, p, repo) : null
129
+ const hearing = p !== null && isOwnerWait(wait) && r.state.turn !== 'aside' ? hearingOf(r.state.holder, p, repo) : null
131
130
  const deaf = hearing?.light === 'nobody' ? hearing.chip : null
132
- const sub = [later, staleWorkingOf(r), r.lane, r.versions > 1 ? `v${r.versions}` : null].filter((x): x is string => x != null && x !== '').join(' · ')
131
+ const sub = [later, staleWorkingOf(r.state), r.lane, r.versions > 1 ? `v${r.versions}` : null].filter((x): x is string => x != null && x !== '').join(' · ')
133
132
  const at = Date.parse(r.updated)
134
133
  return {
135
134
  key: `${repo}/${r.head}`,
@@ -137,8 +136,8 @@ function threadRow(repo: string, r: ThreadRow, wait: Wait, verbs: OwnerWait[], p
137
136
  id: r.head,
138
137
  wait,
139
138
  verbs,
140
- ...(r.waitsOn && isOwnerWait(wait) ? { waitsOn: r.waitsOn } : {}),
141
- ...(r.owed && wait === 'agents' ? { owed: r.owed } : {}),
139
+ ...(r.state.waitsOn && isOwnerWait(wait) ? { waitsOn: r.state.waitsOn } : {}),
140
+ ...(r.state.owed && wait === 'agents' ? { owed: r.state.owed } : {}),
142
141
  title: r.title,
143
142
  ...(r.unread ? { unread: true as const } : {}),
144
143
  ...(sub !== '' ? { sub } : {}),
@@ -203,7 +202,7 @@ export function repoRows(s: InboxSource, dated: Dated, withDone: boolean | strin
203
202
  * list, its wait and its verbs are all read off the index's row, made at one moment (review/store-index.ts) */
204
203
  export function threadInboxRow(s: Pick<InboxSource, 'repo' | 'parties'>, e: Pick<ThreadIndex['entries'][number], 'row'>): { list: InboxList; row: InboxRow } {
205
204
  const l = listOfRow(e.row, s.parties ?? NO_PARTIES)
206
- return { list: l, row: threadRow(s.repo, e.row, l === 'done' ? 'done' : l === 'working' || l === 'waiting' ? 'agents' : e.row.wait, HIS.has(l) ? e.row.verbs : [], s.parties ?? null) }
205
+ return { list: l, row: threadRow(s.repo, e.row, l === 'done' ? 'done' : l === 'working' || l === 'waiting' ? 'agents' : e.row.state.wait, HIS.has(l) ? e.row.state.verbs : [], s.parties ?? null) }
207
206
  }
208
207
 
209
208
  /** newest first; what nothing dates goes last, by repo and title */
package/src/home/inbox.ts CHANGED
@@ -28,7 +28,7 @@ export const datedIn = (root: string): Dated => (n: Resource) => {
28
28
  export const INBOX_SHARE_MS = 1_000
29
29
  const shared = new WeakMap<object, { end: number | null; read: ReturnType<typeof readSources> }>()
30
30
 
31
- /** a repo's parties: who holds its threads and who lives (review/band.ts reads them), the threads page's own read */
31
+ /** a repo's parties: who holds its threads and who lives (review/thread-state.ts reads them), the threads page's own read */
32
32
  export type PartiesOf = (root: string) => Promise<Parties>
33
33
  const partiesOfRepo: PartiesOf = async (root) => (await partiesOfStore(storeDir(root))).parties
34
34
 
@@ -6,34 +6,113 @@
6
6
  // The one constraint a reader breaks first: the agent time index alone holds what Claude Code pruned, so nothing here
7
7
  // empties one of its tables to clear a damage
8
8
  import type { Database } from 'bun:sqlite'
9
- import { existsSync } from 'fs'
10
- import { type FoldedStore, machineDb, machineDbPath, REPAIR_MARK, REPAIR_UNUSED, type RepairMark, repairMarkOf } from '../core/machine-db.ts'
11
- import { COPY_STEP, count, dropTables, foldState, openHost, type Print, q, shapeOf, STORES, tablesOf, takeLock } from './machine-fold.ts'
12
- import { vacuumSteps } from '../core/machine-db.ts'
9
+ import { chmodSync, existsSync } from 'fs'
10
+ import { createIndexTables } from '../agent-time/store.ts'
11
+ import { type MachinePart, machineDb, machineDbPath, openMachineFile, REPAIR_MARK, REPAIR_UNUSED, type RepairMark, repairMarkOf, vacuumSteps } from '../core/machine-db.ts'
12
+ import { pidAlive as alive } from '../core/pid-alive.ts'
13
+ import { createDaemonTables, DAEMON_TABLES } from '../hq/daemon-db.ts'
14
+ import { createMediaTables } from '../media-store/db.ts'
13
15
 
14
- /** the part of the machine db a name says: `media` or `time`, or the store's own name */
15
- export const partNamed = (name: string): FoldedStore | null => (/^media( index)?$/i.test(name) ? 'media index' : /^(agent )?time( index)?$/i.test(name) ? 'agent time index' : /^daemon( file)?$/i.test(name) ? 'daemon file' : null)
16
- export const partWord = (store: FoldedStore): string => (store === 'media index' ? 'media' : store === 'daemon file' ? 'daemon' : 'time')
16
+ export type Print = (l: string) => void
17
+
18
+ /** each part's tables and its prefix in the machine db; `kept`, a table that is no cache, under its own name: a drop of
19
+ * the cache part leaves it (the owner's forget log) */
20
+ export const STORES: Record<MachinePart, { prefix: string; tables: readonly string[]; kept?: readonly string[]; create: (db: Database) => void }> = {
21
+ 'media index': { prefix: 'media_', tables: ['codes', 'items', 'files', 'objects', 'fetched'], kept: ['forgotten_media'], create: createMediaTables },
22
+ 'agent time index': { prefix: 'time_', tables: ['files', 'calls', 'marks', 'prompts', 'meta', 'hooks', 'bg_ends'], create: createIndexTables },
23
+ 'daemon file': { prefix: '', tables: DAEMON_TABLES, create: createDaemonTables },
24
+ }
25
+
26
+ /** every table of a part in the machine db; `cache`: the derived ones alone, those a drop of the part may lose */
27
+ export function tablesOf(store: MachinePart, part: 'all' | 'cache' = 'all'): string[] {
28
+ const { prefix, tables, kept = [] } = STORES[store]
29
+ return [...tables.map((t) => `${prefix}${t}`), ...(part === 'all' ? kept : [])]
30
+ }
31
+
32
+ /** rows one copy step writes: a few ms of the machine db's write lock */
33
+ export const COPY_STEP = 500
34
+ /** rows one step of a drop deletes: each row leaves every index of its table, so fewer than a copy step */
35
+ const DROP_STEP = 200
36
+ /** the row of the one repair, drop or rebuild at a time on a machine: the pid that runs it */
37
+ const LOCK = 'db-repair-lock'
38
+
39
+ export const q = (name: string): string => `"${name.replace(/"/g, '""')}"`
40
+ export const count = (db: Database, schema: string, table: string): number => (db.query(`select count(*) as n from ${schema}.${q(table)}`).get() as { n: number }).n
41
+
42
+ export type Shape = { rowid: boolean; pk: string[]; cols: string[] }
43
+ export function shapeOf(db: Database, schema: string, table: string): Shape | null {
44
+ const info = db.query(`select name, pk from ${schema}.pragma_table_info(?)`).all(table) as { name: string; pk: number }[]
45
+ if (info.length === 0) return null
46
+ const wr = (db.query(`select wr from ${schema}.pragma_table_list where name = ?`).get(table) as { wr: number } | null)?.wr === 1
47
+ return { rowid: !wr, pk: info.filter((c) => c.pk > 0).sort((a, b) => a.pk - b.pk).map((c) => c.name), cols: info.map((c) => c.name) }
48
+ }
49
+
50
+ /** the lock taken, or the pid that holds it: a dead holder's lock is taken over */
51
+ function takeLock(): { ok: true; release: () => void } | { ok: false; pid: number } {
52
+ const held = machineDb((db) =>
53
+ db.transaction(() => {
54
+ const row = db.query('select value from state where name = ?').get(LOCK) as { value: string } | null
55
+ const pid = row == null ? null : (JSON.parse(row.value) as { pid: number }).pid
56
+ if (pid != null && pid !== process.pid && alive(pid)) return pid
57
+ db.query('insert or replace into state (name, value, at) values (?, ?, ?)').run(LOCK, JSON.stringify({ pid: process.pid }), Date.now())
58
+ return null
59
+ }).immediate(),
60
+ )
61
+ if (held != null) return { ok: false, pid: held }
62
+ return { ok: true, release: () => void machineDb((db) => db.query('delete from state where name = ?').run(LOCK)) }
63
+ }
64
+ const locked = (): { release: () => void } => {
65
+ const lock = takeLock()
66
+ if (!lock.ok) throw new Error(`a repair, a drop or a rebuild of the machine db runs (pid ${lock.pid}): one at a time`)
67
+ return lock
68
+ }
69
+
70
+ /** the machine db opened for a repair, with the timeout every machine write has */
71
+ function openHost(): Database {
72
+ const path = machineDbPath()
73
+ // its own tables first, through its own open
74
+ machineDb(() => null)
75
+ // it holds prompts and commands: the owner's only, its log and shared memory too
76
+ for (const f of [path, `${path}-wal`, `${path}-shm`]) try { chmodSync(f, 0o600) } catch { /* not made yet */ }
77
+ const db = openMachineFile(path)
78
+ // the unique index of a call's id takes its rows in no order: with sqlite's small default cache a copy step of
79
+ // 2,000 rows held the lock 838 ms on a real sized index; the pages of the indexes stay in memory instead
80
+ db.exec('pragma cache_size = -262144')
81
+ return db
82
+ }
17
83
 
84
+ /** a part's tables out of the machine db: emptied in steps (by rowid, or by primary key for a table of none), then
85
+ * dropped, their pages given back in steps */
86
+ async function dropTables(db: Database, store: MachinePart, part: 'all' | 'cache'): Promise<void> {
87
+ for (const name of tablesOf(store, part)) {
88
+ const s = shapeOf(db, 'main', name)
89
+ if (s == null) continue
90
+ const keys = (s.rowid ? ['rowid'] : s.pk).map(q).join(', ')
91
+ for (;;) if (db.transaction(() => db.query(`delete from ${q(name)} where (${keys}) in (select ${keys} from ${q(name)} limit ${DROP_STEP})`).run().changes).immediate() === 0) break
92
+ db.transaction(() => db.exec(`drop table ${q(name)}`)).immediate()
93
+ }
94
+ await vacuumSteps(db)
95
+ }
96
+
97
+ /** the part of the machine db a name says: `media` or `time`, or the store's own name */
98
+ export const partNamed = (name: string): MachinePart | null => (/^media( index)?$/i.test(name) ? 'media index' : /^(agent )?time( index)?$/i.test(name) ? 'agent time index' : /^daemon( file)?$/i.test(name) ? 'daemon file' : null)
99
+ export const partWord = (store: MachinePart): string => (store === 'media index' ? 'media' : store === 'daemon file' ? 'daemon' : 'time')
18
100
  /** the system's sqlite shell: the one sqlite here that may edit a schema (bun's refuses: « table sqlite_master may not
19
101
  * be modified »), the only way to cut out a table a damaged page makes undroppable */
20
102
  const SQLITE_SHELL = '/usr/bin/sqlite3'
21
103
  /** where a repair keeps a table's rows while the table is made again */
22
104
  const saved = (table: string): string => `${table}__saved`
23
105
 
24
- export type Dropped = { store: FoldedStore; tables: { table: string; rows: number | null }[]; done: boolean; why: string }
106
+ export type Dropped = { store: MachinePart; tables: { table: string; rows: number | null }[]; done: boolean; why: string }
25
107
 
26
108
  /** a cache part's tables dropped in steps and made again empty: the media index builds again from the files and the
27
109
  * Space; the agent time index is never dropped whole. `go` false: says what it would do */
28
- export async function dropPart(store: FoldedStore, o: { go: boolean; print: Print }): Promise<Dropped> {
110
+ export async function dropPart(store: MachinePart, o: { go: boolean; print: Print }): Promise<Dropped> {
29
111
  const { create } = STORES[store]
30
- const state = foldState().find((s) => s.store === store)!
31
- if (state.state !== 'folded') return { store, tables: [], done: false, why: `the ${store} is not tables of the machine db (${state.state}): nothing to drop` }
32
- const lock = takeLock()
33
- if (!lock.ok) throw new Error(`a fold runs (pid ${lock.pid}): one at a time`)
112
+ const lock = locked()
34
113
  const db = openHost()
35
114
  try {
36
- const list = tablesOf(store, 'cache').map((t) => t.name).filter((t) => shapeOf(db, 'main', t) != null).map((t) => ({ table: t, rows: rowsOf(db, t) }))
115
+ const list = tablesOf(store, 'cache').filter((t) => shapeOf(db, 'main', t) != null).map((t) => ({ table: t, rows: rowsOf(db, t) }))
37
116
  if (store === 'agent time index') return { store, tables: list, done: false, why: 'the agent time index is no cache: it alone holds what Claude Code pruned, so it is never dropped whole; sk db repair time repairs a damaged table' }
38
117
  if (!o.go) return { store, tables: list, done: false, why: `dry run: --go drops ${list.map((x) => x.table).join(', ')} and makes each again empty` }
39
118
  try {
@@ -63,7 +142,7 @@ const rowsOf = (db: Database, t: string): number | null => {
63
142
  /** `cut`: read by key order with no index that lists its keys, so the read stopped at the damaged page and every row
64
143
  * after it is lost too */
65
144
  export type Repaired = { table: string; damaged: string[]; saved: number; held: number | null; lost: number | null; cut?: boolean }
66
- export type Repair = { store: FoldedStore; tables: Repaired[]; done: boolean; why: string }
145
+ export type Repair = { store: MachinePart; tables: Repaired[]; done: boolean; why: string }
67
146
 
68
147
  /** every rowid range of `table` that reads, in steps of `step` rowids; a range that does not read is halved until one
69
148
  * rowid, which is lost. `each` takes the rows of a range that reads */
@@ -170,7 +249,7 @@ function heldBy(db: Database, table: string, damaged: readonly string[]): number
170
249
 
171
250
  /** the tables of a part sqlite finds damaged, a table or one of its indexes, with what each still holds; `go` saves
172
251
  * every row that reads, cuts the table out, makes it again from the store's schema and fills it again, in steps */
173
- export async function repairPart(store: FoldedStore, o: { go: boolean; print: Print; step?: number; pmUp?: boolean }): Promise<Repair> {
252
+ export async function repairPart(store: MachinePart, o: { go: boolean; print: Print; step?: number; pmUp?: boolean }): Promise<Repair> {
174
253
  const r = await repairTables(store, o)
175
254
  if (!r.done || machineDb((db) => db.query('select 1 from state where name = ?').get(REPAIR_UNUSED)) == null) return r
176
255
  // the cut tables' pages are unused and unknown to the page map: the file is written again whole as the last step,
@@ -184,12 +263,8 @@ export async function repairPart(store: FoldedStore, o: { go: boolean; print: Pr
184
263
  return r
185
264
  }
186
265
 
187
- async function repairTables(store: FoldedStore, o: { go: boolean; print: Print; step?: number }): Promise<Repair> {
188
- const state = foldState().find((s) => s.store === store)!
189
- if (state.state === 'own file') return recoverOwn(store, state.old, o)
190
- if (state.state !== 'folded') return { store, tables: [], done: false, why: `the ${store} is neither tables of the machine db nor a file of its own (${state.state}): nothing to repair` }
191
- const lock = takeLock()
192
- if (!lock.ok) throw new Error(`a fold runs (pid ${lock.pid}): one at a time`)
266
+ async function repairTables(store: MachinePart, o: { go: boolean; print: Print; step?: number }): Promise<Repair> {
267
+ const lock = locked()
193
268
  const db = openHost()
194
269
  const step = o.step ?? COPY_STEP
195
270
  try {
@@ -202,7 +277,7 @@ async function repairTables(store: FoldedStore, o: { go: boolean; print: Print;
202
277
  for (const t of was.tables) await dropSaved(db, t)
203
278
  clearRepair(store)
204
279
  }
205
- const names = new Set(tablesOf(store).map((t) => t.name))
280
+ const names = new Set(tablesOf(store))
206
281
  // --go: the mark first, before the first read, so no reader nor the indexer uses a table it is about to cut
207
282
  if (o.go) {
208
283
  setRepair(store, { tables: [...names], phase: 'saving' })
@@ -263,7 +338,7 @@ async function dropSaved(db: Database, t: string): Promise<void> {
263
338
 
264
339
  /** the tables of a repair cut out of the schema, made again empty from the store's schema, filled from their saved
265
340
  * rows in steps (each row under its rowid, so a rerun takes up where it stopped), the saved rows dropped */
266
- async function finish(db: Database, store: FoldedStore, mark: RepairMark, step: number, print: Print): Promise<Repair> {
341
+ async function finish(db: Database, store: MachinePart, mark: RepairMark, step: number, print: Print): Promise<Repair> {
267
342
  const { create } = STORES[store]
268
343
  // a table there is the damaged one, or one a stopped rerun made again: cut either, its rows are all saved
269
344
  const live = mark.tables.filter((t) => shapeOf(db, 'main', t) != null)
@@ -300,8 +375,8 @@ async function finish(db: Database, store: FoldedStore, mark: RepairMark, step:
300
375
  return { store, tables: out, done: true, why: 'repaired' }
301
376
  }
302
377
 
303
- const setRepair = (store: FoldedStore, m: Omit<RepairMark, 'pid' | 'at'>): void => void machineDb((db) => db.query('insert or replace into state (name, value, at) values (?, ?, ?)').run(`${REPAIR_MARK}${store}`, JSON.stringify({ ...m, pid: process.pid, at: Date.now() } satisfies RepairMark), Date.now()))
304
- const clearRepair = (store: FoldedStore): void => void machineDb((db) => db.query('delete from state where name = ?').run(`${REPAIR_MARK}${store}`))
378
+ const setRepair = (store: MachinePart, m: Omit<RepairMark, 'pid' | 'at'>): void => void machineDb((db) => db.query('insert or replace into state (name, value, at) values (?, ?, ?)').run(`${REPAIR_MARK}${store}`, JSON.stringify({ ...m, pid: process.pid, at: Date.now() } satisfies RepairMark), Date.now()))
379
+ const clearRepair = (store: MachinePart): void => void machineDb((db) => db.query('delete from state where name = ?').run(`${REPAIR_MARK}${store}`))
305
380
 
306
381
  /** where the machine db is kept as it was before a rebuild */
307
382
  export const rebuildCopy = (path: string): string => `${path}.before-rebuild`
@@ -351,8 +426,7 @@ export async function rebuild(o: { go: boolean; print: Print; pmUp: boolean; sto
351
426
  if (!o.go) return done({ why: `dry run: --go writes ${path} again into a new file (it needs ${Math.round(before / 1e6)} MB, the disk has ${Math.round(free / 1e6)} MB free), checks every table's rows and hash against it, and keeps the old one as ${rebuildCopy(path)}; with the home down (sk pm uninstall): its processes hold the file open` })
352
427
  if (o.pmUp) throw new Error(`the rebuild needs the home down (pm answers on port ${process.env.SHIPKIT_PM_PORT ?? 'its default'}): its processes hold ${path} open and would go on writing the old file; sk pm uninstall, then sk db rebuild --go, then sk pm install`)
353
428
  if (before > free) throw new Error(`the rebuild needs ${Math.round(before / 1e6)} MB and the disk has ${Math.round(free / 1e6)} MB free`)
354
- const lock = takeLock()
355
- if (!lock.ok) throw new Error(`a fold runs (pid ${lock.pid}): one at a time`)
429
+ const lock = locked()
356
430
  const db = openHost()
357
431
  const tmp = `${path}.rebuild-tmp`
358
432
  try {
@@ -425,78 +499,3 @@ export async function rebuild(o: { go: boolean; print: Print; pmUp: boolean; sto
425
499
  lock.release()
426
500
  }
427
501
  }
428
-
429
- /** a store's own file (not folded) that sqlite finds damaged, written again by sqlite's own recovery (`.recover` of the
430
- * system's shell: every row that reads, page by page) into a new file that replaces it; the damaged one kept as
431
- * `<file>.damaged`. Then the fold or this code reads it as before */
432
- async function recoverOwn(store: FoldedStore, old: string, o: { go: boolean; print: Print }): Promise<Repair> {
433
- const { oldDamage, forgetDamage } = await import('./machine-fold.ts')
434
- const hurt = oldDamage(old)
435
- if (hurt == null) return { store, tables: [], done: false, why: `its own file ${old} reads whole: nothing to repair` }
436
- if (!existsSync(SQLITE_SHELL)) throw new Error(`no ${SQLITE_SHELL} here: sqlite3 ${old} .recover | sqlite3 ${old}.recovered, then mv ${old} ${old}.damaged and mv ${old}.recovered ${old}`)
437
- const lock = takeLock()
438
- if (!lock.ok) throw new Error(`a fold runs (pid ${lock.pid}): one at a time`)
439
- const { rmSync, renameSync, chmodSync } = await import('fs')
440
- const tmp = `${old}.recovered`
441
- const clear = (): void => {
442
- for (const f of [tmp, `${tmp}-journal`, `${tmp}-wal`, `${tmp}-shm`]) rmSync(f, { force: true })
443
- }
444
- try {
445
- // the look runs the same recovery into a file beside, counts it and deletes it: the counts it promises are
446
- // what --go puts in place, and the store is not written
447
- clear()
448
- const dump = Bun.spawn([SQLITE_SHELL, '-batch', '-init', '/dev/null', old, '.recover'], { stdout: 'pipe', stderr: 'pipe' })
449
- const load = Bun.spawn([SQLITE_SHELL, '-batch', '-init', '/dev/null', tmp], { stdin: dump.stdout, stdout: 'pipe', stderr: 'pipe' })
450
- const [a, b] = [await dump.exited, await load.exited]
451
- if (a !== 0 || b !== 0 || oldDamage(tmp) != null) {
452
- const why = (await new Response(dump.stderr).text()).trim().slice(0, 200)
453
- clear()
454
- throw new Error(`sqlite's recovery of ${old} did not give a whole file (${why}): the file stays as it is`)
455
- }
456
- const list = recoveredCounts(old, tmp)
457
- const words = list.map((r) => `${r.table}: ${r.saved.toLocaleString('en-US')} rows kept, ${r.lost == null ? 'how many lost is unknown (nothing of the damaged file counts them)' : `${r.lost.toLocaleString('en-US')} lost`}`)
458
- if (!o.go) {
459
- clear()
460
- return { store, tables: list, done: false, why: `dry run: its own file ${old} is damaged (${hurt}); sqlite's recovery (${SQLITE_SHELL} .recover) keeps ${words.join('; ')}. --go puts that file in its place and keeps the damaged one as ${old}.damaged` }
461
- }
462
- chmodSync(tmp, 0o600)
463
- renameSync(old, `${old}.damaged`)
464
- for (const f of [`${old}-wal`, `${old}-shm`]) {
465
- try {
466
- renameSync(f, `${old}.damaged${f.slice(old.length)}`)
467
- } catch { /* none */ }
468
- }
469
- renameSync(tmp, old)
470
- forgetDamage(store)
471
- o.print(`ok: the ${store}: ${old} written again from every row that read (${words.join('; ')}), the damaged file kept as ${old}.damaged`)
472
- return { store, tables: list, done: true, why: 'recovered' }
473
- } finally {
474
- lock.release()
475
- }
476
- }
477
-
478
- /** per table, the rows sqlite's recovery kept, and those it lost against what the damaged file still counts (through
479
- * an index that reads, else its count) */
480
- function recoveredCounts(old: string, recovered: string): Repaired[] {
481
- const { Database } = require('bun:sqlite') as typeof import('bun:sqlite')
482
- const was = new Database(old, { readwrite: true, create: false })
483
- const now = new Database(recovered, { readwrite: true, create: false })
484
- try {
485
- const names = (now.query("select name from sqlite_master where type = 'table' and name not like 'sqlite_%' and name != 'lost_and_found'").all() as { name: string }[]).map((r) => r.name)
486
- return names.map((t) => {
487
- const saved = (now.query(`select count(*) as n from ${q(t)}`).get() as { n: number }).n
488
- let held = heldBy(was, t, [])
489
- if (held == null) {
490
- try {
491
- held = (was.query(`select count(*) as n from ${q(t)}`).get() as { n: number }).n
492
- } catch {
493
- held = null
494
- }
495
- }
496
- return { table: t, damaged: [], saved, held, lost: held == null ? null : Math.max(0, held - saved) }
497
- })
498
- } finally {
499
- was.close()
500
- now.close()
501
- }
502
- }
@@ -2,14 +2,11 @@
2
2
  // is and its age, from what the jobs and the drills already recorded: no download and no restore here (the drills
3
3
  // stay their own commands). What is not in the Space by design is said as such, never claimed present
4
4
  import type { Drill } from '../hq/replica.ts'
5
- import type { BackupDrill } from '../media-store/backup/restore.ts'
6
5
  import type { ProvedRecord, Sent } from '../vault/vault-snapshot.ts'
7
6
  import { snapshotHealth } from '../vault/vault-snapshot.ts'
8
7
 
9
8
  const H = 3600_000
10
9
  const DAY = 24 * H
11
- /** a backup run older than this is stale: the daemon runs one within minutes of a change */
12
- export const RUN_STALE_MS = 26 * H
13
10
  /** a drill older than this is stale: the hq's runs once a week */
14
11
  export const DRILL_STALE_MS = 8 * DAY
15
12
 
@@ -17,7 +14,6 @@ export type ResumeState = {
17
14
  now: number
18
15
  /** the hq's database: null when this machine joined another hq (its copy is checked there) */
19
16
  hq: { replica: boolean; drill: Drill | null } | null
20
- backup: { lastRun: { at: number } | null; drill: BackupDrill | null }
21
17
  /** this machine's media index; null when it does not open */
22
18
  media: { waiting: number; bytes: number; failing: number } | null
23
19
  /** null when this machine runs no vault */
@@ -35,13 +31,7 @@ export function resumeLines(s: ResumeState): ResumeLine[] {
35
31
  else if (s.hq.drill == null) out.push({ level: 'warn', text: "the hq's database: its replica runs, and no drill has proved it yet", fix: 'sk hq drill' })
36
32
  else if (!s.hq.drill.ok) out.push({ level: 'fail', text: `the hq's database: its replica failed its last drill, ${age(s.now - s.hq.drill.at)} ago: ${s.hq.drill.why}`, fix: 'sk gp restart hq-replica, then sk hq drill' })
37
33
  else out.push({ level: s.now - s.hq.drill.at > DRILL_STALE_MS ? 'warn' : 'ok', text: `the hq's database: in its replica (Litestream); last drill passed ${age(s.now - s.hq.drill.at)} ago, ${s.hq.drill.rows} rows (the replica's last write is not recorded: the drill proves it)`, ...(s.now - s.hq.drill.at > DRILL_STALE_MS ? { fix: 'sk hq drill' } : {}) })
38
- const run = s.backup.lastRun
39
- if (run == null) out.push({ level: 'fail', text: "this machine's untracked project files: no backup run yet", fix: 'sk backup' })
40
- else out.push({ level: s.now - run.at > RUN_STALE_MS ? 'warn' : 'ok', text: `this machine's untracked project files: in the backup, last run ${age(s.now - run.at)} ago`, ...(s.now - run.at > RUN_STALE_MS ? { fix: 'sk backup' } : {}) })
41
- const d = s.backup.drill
42
- if (d == null) out.push({ level: 'warn', text: 'the backup: no drill has restored it yet', fix: 'sk backup drill' })
43
- else if (d.failed > 0) out.push({ level: 'fail', text: `the backup: its last drill, ${age(s.now - d.at)} ago, did not bring back ${d.failed} of ${d.files} files`, fix: 'sk backup drill' })
44
- else out.push({ level: s.now - d.at > DRILL_STALE_MS ? 'warn' : 'ok', text: `the backup: last drill restored ${d.restored} of ${d.files} files ${age(s.now - d.at)} ago`, ...(s.now - d.at > DRILL_STALE_MS ? { fix: 'sk backup drill' } : {}) })
34
+ out.push({ level: 'note', text: "not in the Space, by design: this machine's untracked project files, whose backup is retired. A precious one belongs in git, the hq, the Space or the vault; the house check RV049 names each one that has none" })
45
35
  if (s.media == null) out.push({ level: 'warn', text: "this machine's media: not read, its media index does not open, so what waits to go up is not known", fix: 'sk media status' })
46
36
  else if (s.media.waiting === 0) out.push({ level: 'ok', text: "this machine's media: every file is up in the Space, none waits" })
47
37
  else out.push({ level: 'warn', text: `this machine's media: ${s.media.waiting} files (${(s.media.bytes / 1e6).toFixed(1)} MB) wait to go up${s.media.failing > 0 ? `, ${s.media.failing} failed their last try` : ''}`, fix: 'sk media status' })
@@ -60,19 +50,15 @@ export async function resumeHere(root: string, now: number = Date.now()): Promis
60
50
  const { carriesHq } = await import('../hq/hq-role.ts')
61
51
  const { lastDrill } = await import('../hq/replica.ts')
62
52
  const { loadRepoConfig } = await import('../repo-config.ts')
63
- const { lastRun } = await import('../media-store/backup/run.ts')
64
- const { lastBackupDrill } = await import('../media-store/backup/restore.ts')
65
53
  const { waitingCounts } = await import('../media-store/daemon.ts')
66
54
  const { vaultInitialised, vaultPlace } = await import('../vault/vault-config.ts')
67
55
  const { machineGet } = await import('../core/machine-db.ts')
68
56
  const { CHANGED_KEY, DEAD_DISK_KEY, PROVED_KEY, SENT_KEY, vaultStamp } = await import('../vault/vault-snapshot.ts')
69
57
  const { minterOf } = await import('../vault/vault-minter.ts')
70
- const run = lastRun()
71
58
  const minter = vaultInitialised() ? minterOf(vaultPlace()) : null
72
59
  return {
73
60
  now,
74
61
  hq: carriesHq() ? { replica: (await loadRepoConfig(root).catch(() => null))?.serve?.hqReplica != null, drill: lastDrill() } : null,
75
- backup: { lastRun: run == null ? null : { at: Date.parse(run.at) }, drill: lastBackupDrill() },
76
62
  media: waitingCounts(),
77
63
  vault: vaultInitialised()
78
64
  ? { sent: machineGet<Sent>(SENT_KEY), proved: machineGet<ProvedRecord>(PROVED_KEY), changed: machineGet<{ stamp: string; at: number }>(CHANGED_KEY), deadDisk: machineGet<ProvedRecord>(DEAD_DISK_KEY), stamp: minter == null ? null : await vaultStamp(minter).then((x) => x.stamp, () => null) }
@@ -6,6 +6,8 @@
6
6
  // it runs with no bun watch and an edit of its own code restarts it in place
7
7
  // at once (lib-watch.ts): the new image follows the jobs still running. The
8
8
  // machine resources are pm's.
9
+ import { topUserWatch } from '../core/admission.ts'
10
+ import { readWho } from '../gate/admit-heavy.ts'
9
11
  import { loopWatch } from '../core/loop-watch.ts'
10
12
  import { MemoryWatch } from '../core/memory-watch.ts'
11
13
  import { fileURLToPath } from 'url'
@@ -17,7 +19,6 @@ import { reloadOnOwnCode } from './lib-watch.ts'
17
19
  import { modelWatch } from '../review/model-moved.ts'
18
20
  import { loadHub } from '../serve/hub-runtime.ts'
19
21
  import { ReadThread } from '../serve/read-thread.ts'
20
- import { HookThread } from '../serve/hook-thread.ts'
21
22
  import { readPartiesWith } from '../review/routes.ts'
22
23
  import { houseRepos } from '../house/project-gutter.ts'
23
24
  import { projectGutter } from '../serve/project-gutter-route.ts'
@@ -38,7 +39,7 @@ import { serveDaemon } from './serve-daemon.ts'
38
39
  import { carriedHq, joinCarriedHq, setHqPort } from '../hq/hq-local.ts'
39
40
  import { claimRoleAtStart, hqOpen, hqRoleProblem } from '../hq/hq-role.ts'
40
41
  import { jobsLimit, startJobs } from './daemon-jobs.ts'
41
- import { keepDoorServer } from '../advisors/door-child.ts'
42
+ import { usersListener } from '../advisors/users-listen.ts'
42
43
  import { Widgets } from './widgets.ts'
43
44
  import { machineName, machinePublicHost } from './machine-host.ts'
44
45
  import { OtherMacs } from './other-macs.ts'
@@ -121,17 +122,12 @@ export async function runDaemon(root: string, io: HomeIo, o: { port?: number } =
121
122
  const dir = homeDir()
122
123
  // the machine's one plan: every repo and check pair, ticked by the daemon.
123
124
  // Its catch up window lives in the machine db, so a restart in place keeps it
124
- const plan = new Planner({ catchUp: machineCatchUp, onError: (repo, e) => io.printErr(`WARN the plan of ${repo} broke: ${e.message}`) })
125
+ const plan = new Planner({ catchUp: machineCatchUp, who: topUserWatch(readWho), onError: (repo, e) => io.printErr(`WARN the plan of ${repo} broke: ${e.message}`) })
125
126
  // a repo's colour counts only the checks its plan holds today
126
127
  // a page asked of a repo's own app: said on the pages' stream, which exists once the daemon serves
127
128
  let askedPage: (repo: string) => void = () => {}
128
129
  const gutter = projectGutter({ root, warn: (l) => io.printErr(l), declared: (name) => plan.declared(name), asked: (repo) => askedPage(repo) })
129
130
  const readThread = new ReadThread()
130
- // the inbox hook of every session asks here first, a thread of its own (serve/hook-thread.ts)
131
- // off until its memory is measured: with it the daemon grew past 4 GB in its first minute (every hook then runs in
132
- // its own process, as before)
133
- const hookThread: HookThread | undefined = process.env.SHIPKIT_HOOK_THREAD === '1' ? new HookThread() : undefined
134
- hookThread?.open()
135
131
  // every store's parties too: the page and the inbox read them, a lane transcript each
136
132
  readPartiesWith((dir) => readThread.parties(dir))
137
133
  const hubs = new Hubs({
@@ -181,7 +177,7 @@ export async function runDaemon(root: string, io: HomeIo, o: { port?: number } =
181
177
  daemonPort: own,
182
178
  dir,
183
179
  hubs,
184
- state: new HomeState(dir),
180
+ state: new HomeState(),
185
181
  gutter,
186
182
  plan,
187
183
  only: onlyRepos(),
@@ -190,7 +186,6 @@ export async function runDaemon(root: string, io: HomeIo, o: { port?: number } =
190
186
  machineName: hqMachineName,
191
187
  otherMacs: () => otherMacs.get(),
192
188
  accountsUsage: () => readAccounts(),
193
- ...(hookThread !== undefined ? { hook: hookThread } : {}),
194
189
  })
195
190
  askedPage = (repo) => home.routes.push.moved('asked-page', repo)
196
191
  io.print(`daemon → http://127.0.0.1:${home.server.port} (the page: http://localhost:${port})`)
@@ -204,8 +199,8 @@ export async function runDaemon(root: string, io: HomeIo, o: { port?: number } =
204
199
  // machine-only state, each a niced child process: never a job's body on this loop (daemon-jobs.ts). A daemon
205
200
  // limited to some repos (SHIPKIT_DAEMON_ONLY) is a trial and runs none, unless SHIPKIT_DAEMON_JOBS names some
206
201
  const jobs = onlyRepos() == null || jobsLimit() != null ? startJobs({ cli: CLI, cwd: root, dir: join(dir, 'jobs'), log: childLog(dir, 'daemon'), printErr: io.printErr }) : null
207
- // the advisors' door server, while this machine carries the hq (advisors/door-child.ts)
208
- const door = jobs === null ? null : keepDoorServer({ house: root, print: io.print, printErr: io.printErr })
202
+ // the advisors' users' port, while this machine carries the hq (advisors/users-listen.ts)
203
+ const door = jobs === null ? null : usersListener({ house: root, print: io.print, printErr: io.printErr })
209
204
  // a job that holds the loop holds every page: each stall is said with the work that overlapped it
210
205
  const stalls = loopWatch.start(io.printErr)
211
206
  // pm tells a starved daemon from a hung one by this beat: it turns with the loop
@@ -73,7 +73,7 @@ export function folderWhat(prefix: string, d: Pick<SpacePageDeps, 'kinds' | 'rep
73
73
  const rest = prefix.slice(PUBLIC_PREFIX.length)
74
74
  return rest.split('/').length === 2 ? kind(rest.slice(0, -1)) : null
75
75
  }
76
- if (prefix === `${BACKUP_LABEL}/`) return 'the backup of each machine\'s untracked project files, kept as its retention says'
76
+ if (prefix === `${BACKUP_LABEL}/`) return 'the old runs of the backup of untracked project files, retired 2026-11-29: kept, nothing deletes them'
77
77
  if (prefix === RUNS_PREFIX) return 'one manifest a backup run'
78
78
  if (prefix === PARTS_PREFIX) return 'the parts of the manifests'
79
79
  if (prefix === SNAPSHOTS) return 'snapshots: the vault\'s sealed ones, the hq\'s nightly one'
@@ -152,7 +152,8 @@ function healthFacts(e: SpaceEnd, r: ListingRecord | null, d: SpacePageDeps): Fa
152
152
  if (e.id === 'space') {
153
153
  const b = d.backup
154
154
  const folder = r == null ? null : d.kept((db) => folderSum(db, e.id, `${BACKUP_LABEL}/`))
155
- out.push(b == null ? { text: 'the backup: no run from this machine yet', tone: 'dim' } : { text: `the last backup run from this machine: ${ageWords(Date.parse(b.at), d.now)}${folder == null ? '' : `; ${BACKUP_LABEL}/ holds ${bytesWords(folder.bytes)} in ${count(folder.objects)} objects, every machine's runs`}`, tone: d.now - Date.parse(b.at) > 2 * 86_400_000 ? 'warn' : 'ok' })
155
+ // the backup of untracked files retired: its last run only ages, never a fault
156
+ out.push(b == null ? { text: 'the backup of untracked files: retired, no run from this machine', tone: 'dim' } : { text: `the backup of untracked files: retired, the last run from this machine ${ageWords(Date.parse(b.at), d.now)}${folder == null ? '' : `; ${BACKUP_LABEL}/ holds ${bytesWords(folder.bytes)} in ${count(folder.objects)} objects, every machine's old runs, kept`}`, tone: 'dim' })
156
157
  }
157
158
  return out
158
159
  }
@@ -7,9 +7,9 @@
7
7
  //
8
8
  // Truth is the pid and the probe, never this object's memory: tick() asks the
9
9
  // kernel whether the pid lives and the probe whether it answers.
10
- import { closeSync, existsSync, mkdirSync, openSync, readSync, rmSync, statSync, writeFileSync } from 'fs'
10
+ import { closeSync, existsSync, mkdirSync, openSync, readSync, statSync, writeFileSync } from 'fs'
11
11
  import { dirname } from 'path'
12
- import { importMachineFile, machineDelete, machineGet, machineSet } from '../core/machine-db.ts'
12
+ import { machineDelete, machineGet, machineSet } from '../core/machine-db.ts'
13
13
  import { lastWords } from '../problems/failure-words.ts'
14
14
  import { pidAlive } from '../core/pid-alive.ts'
15
15
 
@@ -120,7 +120,6 @@ export type PidRecord = { pid: number; cmd: string[]; at: number }
120
120
  const pidRow = (key: string): string => `pid:${key}`
121
121
 
122
122
  export function readPid(key: string): PidRecord | null {
123
- importMachineFile<PidRecord>(pidRow(key), key)
124
123
  const r = machineGet<PidRecord>(pidRow(key))
125
124
  return r != null && Number.isInteger(r.pid) && r.pid > 0 ? r : null
126
125
  }
@@ -135,10 +134,7 @@ export function handPid(key: string, pid: number, cmd: string[], now = Date.now(
135
134
  writePid(key, { pid, cmd, at: now })
136
135
  }
137
136
 
138
- const dropPid = (key: string): void => {
139
- machineDelete(pidRow(key))
140
- try { rmSync(key, { force: true }) } catch { /* an older copy's file, gone either way */ }
141
- }
137
+ const dropPid = (key: string): void => machineDelete(pidRow(key))
142
138
 
143
139
  export class Proc {
144
140
  status: ProcStatus = 'down'
@@ -0,0 +1,61 @@
1
+ // the commit-msg gate: the shared message predicate, the leak guard on the message, the reflection trailers, then the
2
+ // repo's own. Apart from the pre-commit gates (hooks/commit-run.ts), so the commit-msg hook loads only these.
3
+ // the one constraint a reader breaks first: the hook has 20 ms from bun's start (hooks/hook-gates.ts)
4
+ import { readFileSync } from 'fs'
5
+ import { commitMessageOffenses, stripNonMessage } from './commit-message.ts'
6
+ import { runLeakGuard } from './leak-guard.ts'
7
+ import { hookGateOff } from './hook-gates.ts'
8
+ import { commandGate, hitLine, moduleGate, startTimes, timeRow, waivedLines, type GateOutcome, type Timed } from './gate-outcome.ts'
9
+ import type { HookConfig } from './hook-config.ts'
10
+
11
+ /** what a repo's commit-msg module gate is given */
12
+ export type CommitMsgCtx = { root: string; message: string; messageFile: string; config: HookConfig }
13
+
14
+ export async function runCommitMsgWith(root: string, config: HookConfig, messageFile: string, o: { since?: number; before?: Timed[] } = {}): Promise<GateOutcome[]> {
15
+ const since = o.since ?? performance.now()
16
+ const times = startTimes(since, o.before)
17
+ const h = config.hooks ?? {}
18
+ const out: GateOutcome[] = []
19
+ const message = readFileSync(messageFile, 'utf8')
20
+ if (hookGateOff(config, 'commit-message') == null) {
21
+ const languageOff = hookGateOff(config, 'commit-language') != null
22
+ const offenses = commitMessageOffenses(message, { languageAllow: h.languageAllow })
23
+ .filter((o) => o.kind !== 'language' || !languageOff)
24
+ out.push(offenses.length === 0
25
+ ? { id: 'commit-message', ok: true, lines: [`ok: commit message clean (no dash punctuation${languageOff ? '' : ', English'})`] }
26
+ : {
27
+ id: 'commit-message',
28
+ ok: false,
29
+ lines: [
30
+ `FAIL: commit message has ${offenses.length} offense(s)`,
31
+ ...offenses.map((o) => ` line ${o.line}: ${o.text.slice(0, 100)}\n ${o.why}`),
32
+ ],
33
+ })
34
+ }
35
+ // the leak guard also reads the MESSAGE, a private name pasted into a
36
+ // commit body is as public as one pasted into a file
37
+ if (hookGateOff(config, 'leak-guard') == null) {
38
+ const r = runLeakGuard(root, { keywordFile: h.keywordFile, staged: false, allow: h.leakAllow, text: [{ label: 'commit message', content: message }] })
39
+ if (r.status === 'hit')
40
+ out.push({ id: 'leak-guard', ok: false, lines: [`FAIL: leak-guard matched in the commit message`, ...r.hits.map(hitLine), ...waivedLines(r.waived)] })
41
+ else if (r.status === 'clean' && r.waived.length > 0)
42
+ out.push({ id: 'leak-guard', ok: true, lines: [`ok: leak-guard clean in the commit message (${r.waived.length} waived)`, ...waivedLines(r.waived)] })
43
+ }
44
+ if (hookGateOff(config, 'reflection-trailer') == null && /^(Fixes|Declines)-reflection:/im.test(message)) {
45
+ const t = performance.now()
46
+ const { machinePlaces, trailerErrors } = await import('../reflections/reflection-close.ts')
47
+ const places = await machinePlaces(root)
48
+ const errors = places === null ? ['no house repo on this machine: a reflection closes where its house is'] : trailerErrors(stripNonMessage(message), places)
49
+ out.push(errors.length === 0
50
+ ? { id: 'reflection-trailer', ok: true, lines: ['ok: reflection trailers name open reflections'] }
51
+ : { id: 'reflection-trailer', ok: false, lines: [`FAIL: reflection-trailer: ${errors.length} trailer(s) name no open reflection`, ...errors.map((e) => ` ${e}`)] })
52
+ times.push({ id: 'reflection-trailer', ms: performance.now() - t })
53
+ }
54
+ for (const g of h.commitMsg ?? []) {
55
+ const t = performance.now()
56
+ out.push('module' in g ? await moduleGate<CommitMsgCtx>(root, g, 'commitMsg', { root, message, messageFile, config }) : await commandGate(root, g, [messageFile], 60_000))
57
+ times.push({ id: g.id, ms: performance.now() - t, owner: 'repo' })
58
+ }
59
+ out.push(timeRow('commit-msg', performance.now() - since, times))
60
+ return out
61
+ }