rvlib-shipkit 2.25.0 → 2.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (456) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/package.json +2 -2
  3. package/src/agent-time/diet.ts +77 -0
  4. package/src/agent-time/family.ts +72 -0
  5. package/src/agent-time/hooks.ts +331 -0
  6. package/src/agent-time/limits.ts +44 -0
  7. package/src/agent-time/live.ts +1 -3
  8. package/src/agent-time/mask.ts +96 -18
  9. package/src/agent-time/refused.ts +45 -0
  10. package/src/agent-time/render.ts +130 -17
  11. package/src/agent-time/report-cache.ts +57 -0
  12. package/src/agent-time/report.ts +349 -23
  13. package/src/agent-time/shape.ts +50 -3
  14. package/src/agent-time/store.ts +370 -95
  15. package/src/agent-time/timeline.ts +140 -21
  16. package/src/agent-time/turns.ts +18 -8
  17. package/src/annex/offload.ts +17 -6
  18. package/src/annex/tidy.ts +70 -10
  19. package/src/asks/ask-after.ts +40 -0
  20. package/src/asks/asks-queue.ts +205 -47
  21. package/src/assets/kit-config.ts +7 -3
  22. package/src/assets/kits/identity-kit.ts +289 -10
  23. package/src/check.ts +3 -1
  24. package/src/checks/SK004-gitignore-policy.check.ts +12 -5
  25. package/src/checks/SK013-one-way-in-policy.check.ts +8 -3
  26. package/src/checks/SK026-asks-autoclose.check.ts +5 -5
  27. package/src/checks/SK028-readme.check.ts +7 -66
  28. package/src/checks/SK030-cache-audit.check.ts +6 -1
  29. package/src/checks/SK031-trace-audit.check.ts +2 -0
  30. package/src/checks/SK033-global-contribution.check.ts +3 -1
  31. package/src/checks/SK035-public-clean.check.ts +2 -2
  32. package/src/checks/SK043-scratch-on-the-mac.check.ts +59 -4
  33. package/src/checks/SK045-slow-hooks.check.ts +47 -0
  34. package/src/checks/SK046-hook-records.check.ts +76 -0
  35. package/src/checks/SK047-login-in-description.check.ts +36 -0
  36. package/src/checks/SK048-one-local-file.check.ts +36 -0
  37. package/src/cli/cmd_Asks.ts +71 -5
  38. package/src/cli/cmd_Backup.ts +5 -3
  39. package/src/cli/cmd_Capacity.ts +2 -2
  40. package/src/cli/cmd_CrossRepoActivity.ts +5 -4
  41. package/src/cli/cmd_Db.ts +253 -0
  42. package/src/cli/cmd_History.ts +212 -0
  43. package/src/cli/cmd_Home.ts +31 -3
  44. package/src/cli/cmd_Hq.ts +516 -0
  45. package/src/cli/cmd_Machines.ts +36 -0
  46. package/src/cli/cmd_Media.ts +38 -6
  47. package/src/cli/cmd_Mv.ts +1 -1
  48. package/src/cli/cmd_Reflect.ts +23 -2
  49. package/src/cli/cmd_Releases.ts +30 -0
  50. package/src/cli/cmd_Review.ts +569 -118
  51. package/src/cli/cmd_Secret.ts +62 -12
  52. package/src/cli/cmd_Social.ts +83 -1
  53. package/src/cli/cmd_Space.ts +324 -0
  54. package/src/cli/cmd_Time.ts +82 -5
  55. package/src/cli/cmd_Tmp.ts +28 -4
  56. package/src/cli/cmd_Trailer.ts +14 -10
  57. package/src/cli/cmd_Urls.ts +56 -0
  58. package/src/cli/cmd_Vault.ts +583 -0
  59. package/src/cli/family-help.ts +4 -2
  60. package/src/cli/family-pages.ts +1 -1
  61. package/src/cli/registry.ts +26 -4
  62. package/src/collections/actions.ts +63 -13
  63. package/src/collections/collection-types.ts +23 -1
  64. package/src/collections/providers.ts +117 -23
  65. package/src/collections/review.ts +4 -4
  66. package/src/commands/runner.ts +5 -1
  67. package/src/contracts/contract-manifests.ts +6 -5
  68. package/src/contracts/contract-types.ts +6 -4
  69. package/src/contracts/contracts-engine.ts +11 -0
  70. package/src/contracts/manifests/chrome-web-store.contract.ts +31 -0
  71. package/src/core/budget.ts +12 -17
  72. package/src/core/capacity.ts +27 -18
  73. package/src/core/check-runner.ts +7 -4
  74. package/src/core/history-files.ts +9 -5
  75. package/src/core/layout.ts +3 -0
  76. package/src/core/machine-busy.ts +127 -0
  77. package/src/core/machine-commit.ts +6 -1
  78. package/src/core/machine-db.ts +368 -20
  79. package/src/core/machine-layout.ts +137 -0
  80. package/src/core/machine-read.ts +81 -0
  81. package/src/core/migrate-layout.ts +1 -1
  82. package/src/core/one-way-in-policy.ts +64 -7
  83. package/src/core/polling-policy.ts +27 -0
  84. package/src/core/retention.ts +16 -2
  85. package/src/core/scope.ts +107 -14
  86. package/src/core/signal-name.ts +6 -0
  87. package/src/core/slots.ts +5 -4
  88. package/src/core/trace-audit.ts +6 -1
  89. package/src/core/transient.ts +6 -0
  90. package/src/drill/clean.ts +25 -1
  91. package/src/drill/run.ts +2 -2
  92. package/src/drill/seal.ts +27 -4
  93. package/src/home/activity-shape.ts +2 -0
  94. package/src/home/activity.ts +66 -3
  95. package/src/home/app-sign.ts +15 -4
  96. package/src/home/daemon-jobs.ts +149 -7
  97. package/src/home/database-projects.ts +111 -0
  98. package/src/home/database-words.ts +203 -0
  99. package/src/home/databases.ts +460 -0
  100. package/src/home/global-units.ts +6 -0
  101. package/src/home/gui-app/ShipkitGui.swift +122 -1
  102. package/src/home/gui-app.ts +6 -3
  103. package/src/home/home-move.ts +514 -0
  104. package/src/home/home-paths.ts +12 -3
  105. package/src/home/home-routes.ts +68 -0
  106. package/src/home/inbox-shape.ts +24 -14
  107. package/src/home/machine-fold.ts +820 -0
  108. package/src/home/machine-host.ts +20 -5
  109. package/src/home/machine-repair.ts +503 -0
  110. package/src/home/machine-stores.ts +66 -15
  111. package/src/home/machine-temp.ts +547 -86
  112. package/src/home/resume.ts +79 -0
  113. package/src/home/run-daemon.ts +25 -4
  114. package/src/home/run-pm.ts +18 -5
  115. package/src/home/serve-daemon.ts +18 -3
  116. package/src/home/serve-web.ts +175 -7
  117. package/src/home/space-job.ts +115 -0
  118. package/src/home/space-page.ts +257 -0
  119. package/src/home/space-route.ts +167 -0
  120. package/src/home/space-words.ts +103 -0
  121. package/src/home/time-page-shape.ts +202 -0
  122. package/src/home/time-page.ts +64 -0
  123. package/src/home/vault-page.ts +482 -0
  124. package/src/home/vault-words.ts +132 -0
  125. package/src/hooks/leak-guard.ts +40 -13
  126. package/src/hooks/one-way-in-guard.ts +17 -4
  127. package/src/hq/cards.ts +581 -0
  128. package/src/hq/door-route.ts +43 -0
  129. package/src/hq/door.ts +163 -0
  130. package/src/hq/files-send.ts +348 -0
  131. package/src/hq/forgotten-log.ts +35 -0
  132. package/src/hq/history-check.ts +255 -0
  133. package/src/hq/history-place.ts +146 -0
  134. package/src/hq/history-send.ts +487 -0
  135. package/src/hq/hq-db.ts +99 -0
  136. package/src/hq/hq-local.ts +469 -0
  137. package/src/hq/hq-routes.ts +196 -0
  138. package/src/hq/hq-store.ts +599 -0
  139. package/src/hq/kinds/ask.ts +147 -0
  140. package/src/hq/kinds/card-gone.ts +83 -0
  141. package/src/hq/kinds/card-msg.ts +66 -0
  142. package/src/hq/kinds/card.ts +99 -0
  143. package/src/hq/kinds/index.ts +21 -0
  144. package/src/hq/kinds/kind.ts +126 -0
  145. package/src/hq/kinds/media.ts +125 -0
  146. package/src/hq/kinds/prompt.ts +219 -0
  147. package/src/hq/kinds/reflection.ts +128 -0
  148. package/src/hq/kinds/report.ts +55 -0
  149. package/src/hq/kinds/time-day.ts +236 -0
  150. package/src/hq/ledger.ts +473 -0
  151. package/src/hq/machine-key.ts +44 -0
  152. package/src/hq/machine-notes.ts +131 -0
  153. package/src/hq/outbox.ts +372 -0
  154. package/src/hq/replica.ts +168 -0
  155. package/src/hq/repo-id.ts +4 -0
  156. package/src/hq/report-facts.ts +117 -0
  157. package/src/hq/report.ts +274 -0
  158. package/src/hq/switch.ts +151 -0
  159. package/src/hq/vault-grant.ts +92 -0
  160. package/src/identities/identities.ts +15 -3
  161. package/src/identities/steps.ts +31 -0
  162. package/src/ledger/db.ts +73 -26
  163. package/src/ledger/gate-checks.ts +29 -4
  164. package/src/ledger/git-key.ts +3 -3
  165. package/src/ledger/git-scan.ts +49 -7
  166. package/src/ledger/run-log.ts +11 -3
  167. package/src/ledger/store.ts +26 -4
  168. package/src/media-store/backup/daemon.ts +36 -17
  169. package/src/media-store/backup/kept.ts +241 -0
  170. package/src/media-store/backup/restore.ts +14 -4
  171. package/src/media-store/backup/run.ts +11 -11
  172. package/src/media-store/backup/secret.ts +6 -4
  173. package/src/media-store/backup/snapshot.ts +4 -2
  174. package/src/media-store/backup/sources.ts +68 -20
  175. package/src/media-store/copy/config.ts +77 -0
  176. package/src/media-store/copy/copy.ts +194 -0
  177. package/src/media-store/copy/lifecycle.ts +43 -0
  178. package/src/media-store/copy/night.ts +90 -0
  179. package/src/media-store/copy/proof.ts +151 -0
  180. package/src/media-store/copy/snapshot.ts +152 -0
  181. package/src/media-store/copy/store.ts +62 -0
  182. package/src/media-store/copy/stream.ts +176 -0
  183. package/src/media-store/daemon.ts +66 -16
  184. package/src/media-store/db.ts +22 -11
  185. package/src/media-store/forget.ts +23 -3
  186. package/src/media-store/hand.ts +4 -3
  187. package/src/media-store/hq-find.ts +75 -0
  188. package/src/media-store/hq-send.ts +277 -0
  189. package/src/media-store/kind.ts +2 -0
  190. package/src/media-store/purge.ts +18 -15
  191. package/src/media-store/put.ts +24 -8
  192. package/src/media-store/remote.ts +16 -7
  193. package/src/media-store/space-listing.ts +240 -0
  194. package/src/media-store/space.ts +40 -21
  195. package/src/media-store/sync.ts +5 -5
  196. package/src/media-store/tidy.ts +98 -0
  197. package/src/media-store/upload.ts +3 -3
  198. package/src/media-store/webp.ts +66 -0
  199. package/src/messages/model.ts +16 -7
  200. package/src/messages/routes.ts +14 -4
  201. package/src/messages/score.ts +2 -2
  202. package/src/messages/suggest.ts +96 -0
  203. package/src/pages/frame-client.ts +10 -0
  204. package/src/plan/planner.ts +28 -17
  205. package/src/recordings/media-kind.ts +1 -0
  206. package/src/recordings/model.ts +1 -1
  207. package/src/recordings/recorder-app/Capture.swift +9 -7
  208. package/src/reflect/hq-corpus.ts +56 -0
  209. package/src/reflect/prompt-corpus.ts +3 -1
  210. package/src/reflect/transcript.ts +146 -36
  211. package/src/release/machine-words.ts +67 -0
  212. package/src/release/public-clean.ts +8 -3
  213. package/src/releases/from-card.ts +1 -1
  214. package/src/releases/model.ts +18 -0
  215. package/src/releases/routes.ts +10 -5
  216. package/src/releases/store.ts +23 -2
  217. package/src/repo-config.ts +42 -2
  218. package/src/review/anim.ts +2 -2
  219. package/src/review/auto.ts +2 -2
  220. package/src/review/card-db.ts +244 -0
  221. package/src/review/card-rows.ts +266 -0
  222. package/src/review/cells.ts +76 -5
  223. package/src/review/draft-card.ts +41 -0
  224. package/src/review/draft-model.ts +78 -0
  225. package/src/review/format.ts +29 -10
  226. package/src/review/gone.ts +98 -0
  227. package/src/review/inbox-hook.ts +35 -0
  228. package/src/review/marks.ts +1 -1
  229. package/src/review/media-kind.ts +7 -5
  230. package/src/review/media-read.ts +9 -7
  231. package/src/review/media.ts +32 -5
  232. package/src/review/model.ts +214 -45
  233. package/src/review/move.ts +491 -0
  234. package/src/review/notes.ts +12 -20
  235. package/src/review/previews.ts +15 -19
  236. package/src/review/project.ts +1 -1
  237. package/src/review/rev.ts +8 -0
  238. package/src/review/role.ts +1 -1
  239. package/src/review/routes.ts +64 -13
  240. package/src/review/stage-card.ts +8 -4
  241. package/src/review/stage-routes.ts +1 -1
  242. package/src/review/store.ts +529 -83
  243. package/src/review/thread-fold.ts +51 -0
  244. package/src/review/threads.ts +147 -9
  245. package/src/review/trailer-auto-mock.ts +63 -0
  246. package/src/review/trailer-card.ts +4 -4
  247. package/src/review/trailer-desk.ts +41 -7
  248. package/src/review/trailer-media.ts +1 -0
  249. package/src/review/trailer-model.ts +8 -0
  250. package/src/review/trailer-notes.ts +1 -1
  251. package/src/review/trailer-routes.ts +9 -1
  252. package/src/review/unit.ts +6 -6
  253. package/src/review/watchers.ts +1 -1
  254. package/src/rules/untrack-generated.ts +92 -8
  255. package/src/secrets/held.ts +16 -0
  256. package/src/secrets/keychain.ts +113 -0
  257. package/src/secrets/list.ts +16 -6
  258. package/src/secrets/manager.ts +24 -10
  259. package/src/secrets/read.ts +257 -0
  260. package/src/secrets/who-reads.ts +49 -0
  261. package/src/serve/door-forward.ts +268 -0
  262. package/src/serve/door-names.ts +47 -0
  263. package/src/serve/embed.ts +1 -1
  264. package/src/serve/hub-app/activity-view.tsx +56 -32
  265. package/src/serve/hub-app/activity.css +7 -1
  266. package/src/serve/hub-app/asks-page.tsx +48 -0
  267. package/src/serve/hub-app/asks-st.ts +25 -0
  268. package/src/serve/hub-app/clock-svc.ts +1 -2
  269. package/src/serve/hub-app/col-card.tsx +64 -13
  270. package/src/serve/hub-app/col-list-page.tsx +122 -0
  271. package/src/serve/hub-app/col-list-st.ts +103 -0
  272. package/src/serve/hub-app/col-tables-view.tsx +10 -41
  273. package/src/serve/hub-app/col-tables.ts +76 -8
  274. package/src/serve/hub-app/cols-svc.ts +70 -16
  275. package/src/serve/hub-app/database-st.ts +260 -0
  276. package/src/serve/hub-app/database-view.tsx +289 -0
  277. package/src/serve/hub-app/database.css +32 -0
  278. package/src/serve/hub-app/entry-bar.css +14 -0
  279. package/src/serve/hub-app/entry-bar.tsx +33 -0
  280. package/src/serve/hub-app/entry-pick.ts +31 -0
  281. package/src/serve/hub-app/floating.tsx +1 -0
  282. package/src/serve/hub-app/hash-route.ts +11 -1
  283. package/src/serve/hub-app/header-bar.tsx +14 -18
  284. package/src/serve/hub-app/home-st.ts +89 -9
  285. package/src/serve/hub-app/home-strip.css +5 -19
  286. package/src/serve/hub-app/home-strip.tsx +58 -92
  287. package/src/serve/hub-app/home.html +7 -0
  288. package/src/serve/hub-app/hub-app.tsx +31 -142
  289. package/src/serve/hub-app/hub-types.ts +3 -1
  290. package/src/serve/hub-app/hub.css +109 -23
  291. package/src/serve/hub-app/icons.tsx +18 -1
  292. package/src/serve/hub-app/identities-st.ts +56 -6
  293. package/src/serve/hub-app/identities-view.tsx +100 -58
  294. package/src/serve/hub-app/identities.css +17 -15
  295. package/src/serve/hub-app/identity-address.ts +5 -0
  296. package/src/serve/hub-app/inbox-st.ts +41 -24
  297. package/src/serve/hub-app/inbox-view.tsx +37 -41
  298. package/src/serve/hub-app/inbox.css +2 -5
  299. package/src/serve/hub-app/index.html +7 -0
  300. package/src/serve/hub-app/kept-cols.tsx +7 -0
  301. package/src/serve/hub-app/keys.ts +28 -15
  302. package/src/serve/hub-app/later.tsx +26 -0
  303. package/src/serve/hub-app/list-filter.tsx +14 -0
  304. package/src/serve/hub-app/list-walk.ts +72 -3
  305. package/src/serve/hub-app/machines-st.ts +251 -0
  306. package/src/serve/hub-app/machines-view.tsx +224 -0
  307. package/src/serve/hub-app/machines.css +76 -0
  308. package/src/serve/hub-app/md-copy.tsx +79 -0
  309. package/src/serve/hub-app/media-view.tsx +2 -0
  310. package/src/serve/hub-app/messages/messages-page.tsx +79 -7
  311. package/src/serve/hub-app/messages/messages-st.ts +99 -3
  312. package/src/serve/hub-app/messages.css +14 -0
  313. package/src/serve/hub-app/page-keys.ts +175 -0
  314. package/src/serve/hub-app/pages-frames.tsx +11 -3
  315. package/src/serve/hub-app/palette-st.ts +58 -11
  316. package/src/serve/hub-app/palette-view.tsx +3 -1
  317. package/src/serve/hub-app/project-list.css +54 -8
  318. package/src/serve/hub-app/project-list.tsx +128 -59
  319. package/src/serve/hub-app/projects-svc.ts +78 -7
  320. package/src/serve/hub-app/reader-chips.tsx +13 -0
  321. package/src/serve/hub-app/readme-view.tsx +2 -3
  322. package/src/serve/hub-app/readme.css +27 -5
  323. package/src/serve/hub-app/reflections-page.tsx +42 -0
  324. package/src/serve/hub-app/reflections-st.ts +17 -0
  325. package/src/serve/hub-app/releases/releases-page.tsx +25 -2
  326. package/src/serve/hub-app/releases/releases-st.ts +1 -1
  327. package/src/serve/hub-app/repo-sections.ts +9 -5
  328. package/src/serve/hub-app/repo-st.ts +35 -8
  329. package/src/serve/hub-app/review/draft-card.tsx +163 -0
  330. package/src/serve/hub-app/review/kit.tsx +50 -7
  331. package/src/serve/hub-app/review/note-place.ts +1 -1
  332. package/src/serve/hub-app/review/review-board.tsx +2 -2
  333. package/src/serve/hub-app/review/review-cells.tsx +145 -65
  334. package/src/serve/hub-app/review/review-kit.ts +27 -1
  335. package/src/serve/hub-app/review/review-list.tsx +68 -30
  336. package/src/serve/hub-app/review/review-page.tsx +7 -8
  337. package/src/serve/hub-app/review/review-st.ts +111 -24
  338. package/src/serve/hub-app/review/review-thread.tsx +49 -19
  339. package/src/serve/hub-app/review/review-views.tsx +475 -144
  340. package/src/serve/hub-app/review/thread-control-st.ts +115 -0
  341. package/src/serve/hub-app/review/thread-control.tsx +74 -0
  342. package/src/serve/hub-app/review/thread-st.ts +73 -26
  343. package/src/serve/hub-app/review/trailer-card.tsx +1 -1
  344. package/src/serve/hub-app/review/trailer-page.tsx +37 -16
  345. package/src/serve/hub-app/review/trailer-st.ts +41 -7
  346. package/src/serve/hub-app/review.css +267 -61
  347. package/src/serve/hub-app/side-lists.ts +72 -0
  348. package/src/serve/hub-app/sidebar.tsx +6 -3
  349. package/src/serve/hub-app/site/site-part.tsx +2 -8
  350. package/src/serve/hub-app/site/site-st.ts +4 -4
  351. package/src/serve/hub-app/social/comms-page.tsx +20 -5
  352. package/src/serve/hub-app/social/kit.tsx +30 -4
  353. package/src/serve/hub-app/social/post-card.tsx +139 -49
  354. package/src/serve/hub-app/social/serial-writes.ts +13 -0
  355. package/src/serve/hub-app/social/social-model.ts +11 -0
  356. package/src/serve/hub-app/social/social-page.tsx +94 -35
  357. package/src/serve/hub-app/social/social-st.ts +120 -36
  358. package/src/serve/hub-app/social/stage-popup.tsx +1 -1
  359. package/src/serve/hub-app/social/stage-st.ts +1 -1
  360. package/src/serve/hub-app/social/step-layout.ts +1 -1
  361. package/src/serve/hub-app/social.css +3 -0
  362. package/src/serve/hub-app/space-st.ts +209 -0
  363. package/src/serve/hub-app/space-view.tsx +196 -0
  364. package/src/serve/hub-app/space.css +27 -0
  365. package/src/serve/hub-app/stores/stores-page.tsx +91 -23
  366. package/src/serve/hub-app/stores/stores-st.ts +44 -19
  367. package/src/serve/hub-app/stores.css +6 -1
  368. package/src/serve/hub-app/theme-st.ts +22 -9
  369. package/src/serve/hub-app/time-charts.tsx +291 -0
  370. package/src/serve/hub-app/time-pages.tsx +749 -0
  371. package/src/serve/hub-app/time-st.ts +162 -0
  372. package/src/serve/hub-app/time-view.tsx +76 -0
  373. package/src/serve/hub-app/time.css +138 -0
  374. package/src/serve/hub-app/tree-build.ts +52 -42
  375. package/src/serve/hub-app/tree-row.tsx +4 -4
  376. package/src/serve/hub-app/tree-svc.ts +18 -9
  377. package/src/serve/hub-app/urls-svc.ts +154 -0
  378. package/src/serve/hub-app/urls-view.tsx +117 -0
  379. package/src/serve/hub-app/urls.css +30 -0
  380. package/src/serve/hub-app/vault-st.ts +127 -0
  381. package/src/serve/hub-app/vault-view.tsx +154 -0
  382. package/src/serve/hub-app/vault.css +38 -0
  383. package/src/serve/hub-app/veille/veille-st.ts +12 -10
  384. package/src/serve/hub-app/waiting-svc.ts +29 -0
  385. package/src/serve/hub-app/wikis-view.tsx +2 -2
  386. package/src/serve/hub-runtime.ts +15 -2
  387. package/src/serve/project-gutter-route.ts +27 -14
  388. package/src/serve/project-gutter.ts +25 -12
  389. package/src/serve/same-origin.ts +10 -0
  390. package/src/serve/serve-hub.ts +13 -4
  391. package/src/shipkit-files.ts +16 -2
  392. package/src/shipkit.ts +1 -1
  393. package/src/shot/shooter.ts +616 -420
  394. package/src/shot/shot-ask.ts +246 -155
  395. package/src/site/desk.ts +2 -2
  396. package/src/smoke/run-smoke.ts +3 -2
  397. package/src/social/cover.ts +202 -0
  398. package/src/social/discord-layout.ts +37 -13
  399. package/src/social/drafts.ts +3 -0
  400. package/src/social/load.ts +23 -2
  401. package/src/social/media-kind.ts +2 -1
  402. package/src/social/publish/discord.ts +5 -2
  403. package/src/social/publish/secret.ts +2 -2
  404. package/src/social/release-stage.ts +28 -13
  405. package/src/social/routes.ts +26 -1
  406. package/src/social/stage.ts +1 -1
  407. package/src/social/stats.ts +12 -9
  408. package/src/social/strip.ts +4 -1
  409. package/src/social/thumbnail.ts +255 -0
  410. package/src/stores/collection.ts +15 -11
  411. package/src/stores/desk.ts +236 -42
  412. package/src/stores/model.ts +72 -6
  413. package/src/stores/routes.ts +37 -12
  414. package/src/stores/unit.ts +14 -8
  415. package/src/suite/judge-suites.ts +113 -16
  416. package/src/suite/select.ts +45 -3
  417. package/src/suite/suite-cli.ts +81 -34
  418. package/src/trailer/bed.ts +1 -1
  419. package/src/trailer/build.ts +134 -21
  420. package/src/trailer/ffmpeg.ts +7 -0
  421. package/src/trailer/fonts.ts +3 -2
  422. package/src/trailer/grammar.ts +201 -2
  423. package/src/trailer/graph.ts +42 -5
  424. package/src/trailer/look.ts +21 -0
  425. package/src/trailer/mock.ts +154 -0
  426. package/src/trailer/passage.ts +65 -26
  427. package/src/trailer/score/heard.ts +89 -0
  428. package/src/trailer/score/sound.ts +14 -8
  429. package/src/trailer/sound/run.ts +16 -6
  430. package/src/trailer/stitch.ts +26 -5
  431. package/src/trailer/titles.ts +82 -19
  432. package/src/trailer/versions.ts +1 -3
  433. package/src/trailer/vertical.ts +3 -1
  434. package/src/urls/frame.ts +195 -0
  435. package/src/urls/routes.ts +43 -0
  436. package/src/urls/rows.ts +171 -0
  437. package/src/urls/unit.ts +73 -0
  438. package/src/vault/house-keys.ts +42 -0
  439. package/src/vault/layout.ts +50 -0
  440. package/src/vault/policy.ts +165 -0
  441. package/src/vault/vault-audit.ts +276 -0
  442. package/src/vault/vault-client.ts +40 -0
  443. package/src/vault/vault-config.ts +159 -0
  444. package/src/vault/vault-destroy.ts +78 -0
  445. package/src/vault/vault-handover.ts +305 -0
  446. package/src/vault/vault-http.ts +352 -0
  447. package/src/vault/vault-import.ts +208 -0
  448. package/src/vault/vault-init.ts +328 -0
  449. package/src/vault/vault-minter.ts +271 -0
  450. package/src/vault/vault-restore.ts +333 -0
  451. package/src/vault/vault-serve.ts +342 -0
  452. package/src/vault/vault-snapshot.ts +281 -0
  453. package/src/veille/asks.ts +1 -1
  454. package/src/veille/desk.ts +2 -2
  455. package/src/wiki/run-wiki.ts +2 -1
  456. package/src/wiki/scan-md.ts +42 -2
@@ -0,0 +1,117 @@
1
+ // the facts of a report that are not git's (hq/report.ts): the global processes as pm holds them, the live agents as
2
+ // counts a house repo, the declared switches. The one constraint a reader breaks first: a lane's row carries what it
3
+ // does, made of the owner's prompts, and the name of any folder it works in: only counts leave, and only a house
4
+ // repo's name
5
+ import { dirname, resolve } from 'path'
6
+ import { gitRoot } from '../core/git-root.ts'
7
+ import type { LaneCount, ProcFact, Report } from './report.ts'
8
+ import { MAX_LANE_REPOS, MAX_PROCESSES, MAX_URL } from './report.ts'
9
+
10
+ /** a process as pm answers it, the fields a report keeps */
11
+ type PmResource = { id: string; repo: string; status: string; since: number; url?: string | null }
12
+
13
+ /** pm's processes, null when pm does not answer: never its command line, its env or its log. Its url as declared,
14
+ * kept only when it is a plain http url with no user or password in it */
15
+ export function procFacts(resources: readonly PmResource[] | null): ProcFact[] | undefined {
16
+ if (resources == null) return undefined
17
+ return resources
18
+ .slice(0, MAX_PROCESSES)
19
+ .map((r) => {
20
+ const url = plainUrl(r.url)
21
+ return { id: String(r.id).slice(0, 128), repo: String(r.repo ?? '').slice(0, 128), state: String(r.status).slice(0, 128), since: Number.isSafeInteger(r.since) && r.since > 0 ? r.since : 0, ...(url == null ? {} : { url }) }
22
+ })
23
+ .filter((p) => p.id !== '' && p.state !== '')
24
+ }
25
+
26
+ /** an http url with no credential in it, at most MAX_URL; null for anything else */
27
+ export function plainUrl(v: unknown): string | null {
28
+ if (typeof v !== 'string' || v.length > MAX_URL) return null
29
+ try {
30
+ const u = new URL(v)
31
+ return (u.protocol === 'http:' || u.protocol === 'https:') && u.username === '' && u.password === '' ? v : null
32
+ } catch {
33
+ return null
34
+ }
35
+ }
36
+
37
+ /** a live agent as its transcript says it: the folder it works in, a lane or a session, when it started */
38
+ export type LiveAgent = { cwd: string; agent: string; startedAt: number | null }
39
+
40
+ /** the house repo a folder belongs to: the repo itself, a folder in it, or a linked worktree of it anywhere */
41
+ export function houseRepoOf(cwd: string, repos: readonly { name: string; path: string }[], mainOf: (cwd: string) => string | null): string | null {
42
+ if (cwd === '') return null
43
+ const at = resolve(cwd)
44
+ const inside = (p: string): boolean => at === p || at.startsWith(`${p}/`)
45
+ // the deepest repo first: a repo cloned inside another is its own
46
+ const byDepth = [...repos].sort((a, b) => b.path.length - a.path.length)
47
+ const direct = byDepth.find((r) => inside(resolve(r.path)))
48
+ const main = mainOf(at)
49
+ const viaMain = main == null ? null : byDepth.find((r) => resolve(r.path) === main)
50
+ // a worktree under .claude/worktrees/ of a repo is that repo; so is one beside it, through its common dir
51
+ return viaMain?.name ?? direct?.name ?? null
52
+ }
53
+
54
+ /** the main work tree of the checkout at `cwd`: the parent of its git common dir */
55
+ export const mainTreeOf = (cwd: string): string | null => {
56
+ const root = gitRoot(cwd)
57
+ return root == null ? null : dirname(root.commonDir)
58
+ }
59
+
60
+ /** the live agents as counts: a house repo by its name, any other folder in `elsewhere` */
61
+ export function laneCounts(agents: readonly LiveAgent[], repos: readonly { name: string; path: string }[], mainOf: (cwd: string) => string | null = mainTreeOf): NonNullable<Report['lanes']> {
62
+ const by = new Map<string, LaneCount>()
63
+ let elsewhere = 0
64
+ for (const a of agents) {
65
+ const name = houseRepoOf(a.cwd, repos, mainOf)
66
+ if (name == null) {
67
+ elsewhere++
68
+ continue
69
+ }
70
+ const c = by.get(name) ?? { name, sessions: 0, lanes: 0, since: null }
71
+ if (a.agent === '') c.sessions++
72
+ else c.lanes++
73
+ if (a.startedAt != null && Number.isSafeInteger(a.startedAt) && a.startedAt > 0) c.since = c.since == null ? a.startedAt : Math.min(c.since, a.startedAt)
74
+ by.set(name, c)
75
+ }
76
+ return { repos: [...by.values()].sort((a, b) => a.name.localeCompare(b.name)).slice(0, MAX_LANE_REPOS), elsewhere }
77
+ }
78
+
79
+ /** the agents at work on this machine now, as `sk lanes` sees them: a turn that ended holds nothing */
80
+ export async function liveAgents(now: number): Promise<LiveAgent[]> {
81
+ const { liveRow, oneRowAnAgent } = await import('../agent-time/live.ts')
82
+ const { listTranscripts } = await import('../agent-time/store.ts')
83
+ const { LIVE_WINDOW_MS } = await import('../core/capacity.ts')
84
+ const out: LiveAgent[] = []
85
+ for (const f of oneRowAnAgent(listTranscripts().filter((x) => now - x.mtime <= LIVE_WINDOW_MS))) {
86
+ try {
87
+ const r = liveRow(f, { calls: false })
88
+ if (r.state.kind !== 'ended') out.push({ cwd: r.cwd, agent: r.agent, startedAt: r.startedAt })
89
+ } catch {
90
+ // a transcript gone between the listing and the read
91
+ }
92
+ }
93
+ return out
94
+ }
95
+
96
+ /** what the facts read: pm's answer, the live agents, a machine db value. Handed in, so a test or a scratch run never
97
+ * reaches the real ones */
98
+ export type FactReaders = { pm: () => Promise<{ resources: readonly PmResource[] } | null>; agents: (now: number) => Promise<LiveAgent[]>; get: (name: string) => unknown }
99
+
100
+ /** the readers of this machine, for the report job alone */
101
+ export async function realReaders(): Promise<FactReaders> {
102
+ const { askPm } = await import('../home/pm-switch.ts')
103
+ const { machineGet } = await import('../core/machine-db.ts')
104
+ return { pm: askPm, agents: liveAgents, get: machineGet }
105
+ }
106
+
107
+ /** everything of the report that is not git's, each part absent when it does not read */
108
+ export async function machineFacts(o: { repos: readonly { name: string; path: string }[]; now: number } & FactReaders): Promise<Pick<Report, 'processes' | 'lanes' | 'switches'>> {
109
+ const { switchValues } = await import('./switch.ts')
110
+ const [pm, agents] = await Promise.all([o.pm().catch(() => null), o.agents(o.now).catch(() => null)])
111
+ const processes = procFacts(pm?.resources ?? null)
112
+ return {
113
+ ...(processes == null ? {} : { processes }),
114
+ ...(agents == null ? {} : { lanes: laneCounts(agents, o.repos) }),
115
+ switches: switchValues(o.get),
116
+ }
117
+ }
@@ -0,0 +1,274 @@
1
+ // what a daemon says of its machine to the hq (wiki tools/shipkit/hq.md): the shipkit that runs, the house checkout,
2
+ // the disk, the tailnet, each house repo's branch, head and key, the global processes, the lanes as counts, the
3
+ // declared switches. Names and counts only: no file content, no path, no command line, never what a lane does, and
4
+ // never what a remote's url holds beside its host and path (a user, a token)
5
+ import { repoId } from './repo-id.ts'
6
+ import { readFileSync, statfsSync } from 'fs'
7
+ import { join } from 'path'
8
+ import { gitRoot } from '../core/git-root.ts'
9
+ import { LIB_VERSION } from '../core/lib-version.ts'
10
+ import { maskSecrets } from '../agent-time/mask.ts'
11
+ import { maskFields } from './kinds/kind.ts'
12
+
13
+ export type RepoFacts = {
14
+ /** the folder's name on this machine */
15
+ name: string
16
+ /** what two machines share for one repo: its first remote, as host and path. Absent for a repo with no remote
17
+ * and in a report made before the key existed */
18
+ key?: string
19
+ branch: string
20
+ head: string
21
+ ahead: number
22
+ behind: number
23
+ dirty: number
24
+ /** its checks as its run record last saw them: absent where shipkit never ran, and in a report made before */
25
+ gate?: GateFact
26
+ }
27
+
28
+ /** a repo's checks, last seen: at most MAX_REDS red ids, the warnings as a count, the latest time a check ran (ms) */
29
+ export type GateFact = { state: 'red' | 'orange' | 'green'; reds: string[]; warns: number; at: number | null }
30
+
31
+ /** one commit of a house repo: `branch` null on the checked out one, the title masked and cut at MAX_TITLE */
32
+ export type ActivityFact = { repo: string; sha: string; at: number; branch: string | null; title: string }
33
+
34
+ /** a remote's url as host and path, lowercase: no scheme, no user, no token, no port, no `.git`. Null for what is
35
+ * no url of a remote (a local path) */
36
+ export function repoKeyOf(url: string): string | null {
37
+ const u = url.trim()
38
+ const m = /^[a-z][a-z0-9+.-]*:\/\/(?:[^@/]*@)?([^/:]+)(?::\d+)?\/(.+)$/i.exec(u) ?? /^(?:[^@/]*@)?([^/:]+):(?!\/)(.+)$/.exec(u)
39
+ if (m == null) return null
40
+ const path = m[2]!.replace(/\/+$/, '').replace(/\.git$/i, '').replace(/^\/+/, '')
41
+ return path === '' ? null : `${m[1]}/${path}`.toLowerCase()
42
+ }
43
+
44
+ export { repoId }
45
+ export type Report = {
46
+ version: string
47
+ /** the house checkout: its head, and how far it is behind its upstream as last fetched */
48
+ house: { head: string; behind: number } | null
49
+ disk: { free: number; total: number }
50
+ tailnet: { name: string | null; up: boolean }
51
+ repos: RepoFacts[]
52
+ /** the rows of the cards' feed that wait for this machine's disk, and since when the oldest; absent before */
53
+ cards?: { waiting: number; since: number | null }
54
+ /** what the media job saw at its last pass (media-store/daemon.ts): why nothing goes up to the Space and since when,
55
+ * the files that wait to go up and their bytes, the uploads that failed; absent before */
56
+ media?: MediaReport
57
+ /** each global process as pm holds it; absent before, and while pm does not answer */
58
+ processes?: ProcFact[]
59
+ /** the live agents, as counts: a house repo's by its folder's name, every other folder in one bare count */
60
+ lanes?: { repos: LaneCount[]; elsewhere: number }
61
+ /** each switch hq/switch.ts declares, with its value here; absent before */
62
+ switches?: Record<string, boolean | number | null>
63
+ /** the newest commits of its house repos over ACTIVITY_MS, every local branch, newest first; absent before */
64
+ activity?: ActivityFact[]
65
+ }
66
+
67
+ export type MediaReport = { at: number; noSpace: string | null; since: number | null; waiting: number; bytes: number; failing: number }
68
+
69
+ /** a global process: its id, the house repo that declares it, its state, since when (ms), the url it declares */
70
+ export type ProcFact = { id: string; repo: string; state: string; since: number; url?: string }
71
+ /** the live agents of one house repo: its sessions, its lanes, the start of the oldest (ms, null when none says it) */
72
+ export type LaneCount = { name: string; sessions: number; lanes: number; since: number | null }
73
+
74
+ /** what one report may carry of each, so the hq keeps what it is sent within a few kB */
75
+ export const MAX_PROCESSES = 200
76
+ export const MAX_LANE_REPOS = 200
77
+ export const MAX_SWITCHES = 64
78
+ export const MAX_REPOS = 200
79
+ export const MAX_ACTIVITY = 40
80
+ export const MAX_TITLE = 120
81
+ export const MAX_REDS = 8
82
+ export const MAX_URL = 300
83
+ /** the window of the activity a report carries */
84
+ export const ACTIVITY_MS = 24 * 3600_000
85
+ /** the free text fields of a report, masked by the sender and again by the hq as it takes them in (kinds/kind.ts, maskFields): a
86
+ * branch is named by whoever made it, so a token's shape in it is masked like a title */
87
+ export const REPORT_TEXTS = ['activity.*.title', 'activity.*.branch', 'repos.*.branch'] as const
88
+ const MAX_NAME = 128
89
+ const name = (v: unknown): v is string => typeof v === 'string' && v.length > 0 && v.length <= MAX_NAME
90
+ const whole = (v: unknown): v is number => typeof v === 'number' && Number.isSafeInteger(v) && v >= 0
91
+ const isUrl = (v: unknown): boolean => typeof v === 'string' && v.length <= MAX_URL && /^https?:\/\//.test(v)
92
+ const isProc = (v: unknown): v is ProcFact => isObj(v) && name(v['id']) && typeof v['repo'] === 'string' && v['repo'].length <= MAX_NAME && name(v['state']) && whole(v['since']) && (v['url'] === undefined || isUrl(v['url']))
93
+ const isGate = (v: unknown): v is GateFact => isObj(v) && ['red', 'orange', 'green'].includes(v['state'] as string) && Array.isArray(v['reds']) && v['reds'].length <= MAX_REDS && v['reds'].every(name) && whole(v['warns']) && (v['at'] === null || whole(v['at']))
94
+ const isActivity = (v: unknown): v is ActivityFact => isObj(v) && name(v['repo']) && typeof v['sha'] === 'string' && /^[0-9a-f]{4,40}$/.test(v['sha']) && whole(v['at']) && (v['branch'] === null || name(v['branch'])) && typeof v['title'] === 'string' && v['title'].length <= MAX_TITLE
95
+ const isLane = (v: unknown): v is LaneCount => isObj(v) && name(v['name']) && whole(v['sessions']) && whole(v['lanes']) && (v['since'] === null || whole(v['since']))
96
+ const isSwitches = (v: unknown): boolean => isObj(v) && Object.keys(v).length <= MAX_SWITCHES && Object.entries(v).every(([k, x]) => name(k) && (x === null || typeof x === 'boolean' || (typeof x === 'number' && Number.isFinite(x))))
97
+
98
+ const isNum = (v: unknown): v is number => typeof v === 'number' && Number.isFinite(v)
99
+ const isObj = (v: unknown): v is Record<string, unknown> => v != null && typeof v === 'object' && !Array.isArray(v)
100
+
101
+ /** is this what a daemon may store as a report: the hq keeps what it is sent, so the shape is checked at intake */
102
+ export function isReport(v: unknown): v is Report {
103
+ if (!isObj(v) || typeof v['version'] !== 'string') return false
104
+ const { house, disk, tailnet, repos } = v
105
+ if (house !== null && !(isObj(house) && typeof house['head'] === 'string' && isNum(house['behind']))) return false
106
+ if (!(isObj(disk) && isNum(disk['free']) && isNum(disk['total']))) return false
107
+ if (!(isObj(tailnet) && (tailnet['name'] === null || typeof tailnet['name'] === 'string') && typeof tailnet['up'] === 'boolean')) return false
108
+ const cards = v['cards']
109
+ if (cards !== undefined && !(isObj(cards) && isNum(cards['waiting']) && (cards['since'] === null || isNum(cards['since'])))) return false
110
+ const media = v['media']
111
+ if (media !== undefined && !(isObj(media) && isNum(media['at']) && (media['noSpace'] === null || (typeof media['noSpace'] === 'string' && media['noSpace'].length <= 300)) && (media['since'] === null || isNum(media['since'])) && isNum(media['waiting']) && isNum(media['bytes']) && isNum(media['failing']))) return false
112
+ const { processes, lanes, switches } = v
113
+ if (processes !== undefined && !(Array.isArray(processes) && processes.length <= MAX_PROCESSES && processes.every(isProc))) return false
114
+ if (lanes !== undefined && !(isObj(lanes) && whole(lanes['elsewhere']) && Array.isArray(lanes['repos']) && lanes['repos'].length <= MAX_LANE_REPOS && lanes['repos'].every(isLane))) return false
115
+ if (switches !== undefined && !isSwitches(switches)) return false
116
+ const activity = v['activity']
117
+ if (activity !== undefined && !(Array.isArray(activity) && activity.length <= MAX_ACTIVITY && activity.every(isActivity))) return false
118
+ return Array.isArray(repos) && repos.length <= MAX_REPOS && repos.every((r) => isObj(r) && typeof r['name'] === 'string' && (r['key'] === undefined || typeof r['key'] === 'string') && typeof r['branch'] === 'string' && typeof r['head'] === 'string' && isNum(r['ahead']) && isNum(r['behind']) && isNum(r['dirty']) && (r['gate'] === undefined || isGate(r['gate'])))
119
+ }
120
+
121
+ /** a repo's facts from `git status --porcelain=v2 --branch`: one spawn tells the branch, the head, the distance to
122
+ * the upstream and each dirty path */
123
+ export function repoFacts(name: string, status: string): RepoFacts {
124
+ const out: RepoFacts = { name, branch: '', head: '', ahead: 0, behind: 0, dirty: 0 }
125
+ for (const line of status.split('\n')) {
126
+ if (line.startsWith('# branch.oid ')) out.head = line.slice(13, 13 + 12).replace('(initial)', '')
127
+ else if (line.startsWith('# branch.head ')) out.branch = line.slice(14)
128
+ else if (line.startsWith('# branch.ab ')) {
129
+ const m = /\+(\d+) -(\d+)/.exec(line)
130
+ if (m != null) [out.ahead, out.behind] = [Number(m[1]), Number(m[2])]
131
+ } else if (line !== '' && !line.startsWith('#')) out.dirty++
132
+ }
133
+ return out
134
+ }
135
+
136
+ async function git(path: string, args: string[]): Promise<string> {
137
+ try {
138
+ const p = Bun.spawn(['git', '-C', path, ...args], { stdout: 'pipe', stderr: 'ignore' })
139
+ const timer = setTimeout(() => p.kill(), 10_000)
140
+ const text = await new Response(p.stdout).text()
141
+ clearTimeout(timer)
142
+ return (await p.exited) === 0 ? text : ''
143
+ } catch {
144
+ return ''
145
+ }
146
+ }
147
+
148
+ const gitStatus = (path: string): Promise<string> => git(path, ['status', '--porcelain=v2', '--branch'])
149
+
150
+ /** the url of the first remote a git config file names, null for a file with none. Undefined for a file only git
151
+ * reads right: an include, a quoted or continued value, a comment after it, a section head of another form */
152
+ export function remoteUrlIn(config: string): string | null | undefined {
153
+ if (/^\s*\[include/im.test(config)) return undefined
154
+ let inRemote = false
155
+ for (const raw of config.split('\n')) {
156
+ const line = raw.trim()
157
+ if (line.startsWith('[')) {
158
+ inRemote = /^\[remote\s+"[^"\\]*"\]$/i.test(line)
159
+ if (!inRemote && /^\[remote[\s.]/i.test(line)) return undefined
160
+ continue
161
+ }
162
+ const m = inRemote ? /^url\s*=\s*(.*)$/i.exec(line) : null
163
+ if (m != null) return /["\\#;]/.test(m[1]!) ? undefined : m[1]!
164
+ }
165
+ return null
166
+ }
167
+
168
+ /** the key of the repo at `path`: its first remote's, undefined with none. Read from the repo's own config file,
169
+ * since a secret's read asks it each time and a process costs it 14 ms; git answers for a file it alone reads right */
170
+ export async function repoKey(path: string): Promise<string | undefined> {
171
+ return keyFrom(path, async (p) => git(p, ['config', '--get-regexp', '^remote\\..*\\.url$']))
172
+ }
173
+
174
+ /** the same key without an await, for the review store that files a card under it (review/card-db.ts) */
175
+ export function repoKeySync(path: string): string | undefined {
176
+ return keyFrom(path, (p) => {
177
+ try {
178
+ const r = Bun.spawnSync(['git', '-C', p, 'config', '--get-regexp', '^remote\\..*\\.url$'], { stdout: 'pipe', stderr: 'ignore', timeout: 10_000 })
179
+ return r.exitCode === 0 ? (r.stdout?.toString() ?? '') : ''
180
+ } catch {
181
+ return ''
182
+ }
183
+ })
184
+ }
185
+
186
+ function keyFrom(path: string, ask: (path: string) => string): string | undefined
187
+ function keyFrom(path: string, ask: (path: string) => Promise<string>): Promise<string | undefined>
188
+ function keyFrom(path: string, ask: (path: string) => string | Promise<string>): string | undefined | Promise<string | undefined> {
189
+ const root = gitRoot(path)
190
+ if (root == null) return undefined
191
+ let url: string | null | undefined
192
+ try {
193
+ url = remoteUrlIn(readFileSync(join(root.commonDir, 'config'), 'utf8'))
194
+ } catch {
195
+ url = undefined
196
+ }
197
+ const of = (u: string | null): string | undefined => (u == null ? undefined : (repoKeyOf(u) ?? undefined))
198
+ if (url !== undefined) return of(url)
199
+ const first = (text: string): string => {
200
+ const line = text.split('\n')[0] ?? ''
201
+ return line.slice(line.indexOf(' ') + 1)
202
+ }
203
+ const asked = ask(path)
204
+ return typeof asked === 'string' ? of(first(asked)) : asked.then((t) => of(first(t)))
205
+ }
206
+
207
+ const SEP = '\x1f'
208
+ const END = '\x1e'
209
+
210
+ /** `git log --branches --source` in `%h SEP %ct SEP %S SEP %s END`, read: the checked out branch reads null, every
211
+ * title masked whole, then cut at MAX_TITLE */
212
+ export function activityFacts(repo: string, text: string, branch: string): ActivityFact[] {
213
+ const out: ActivityFact[] = []
214
+ for (const rec of text.split(END)) {
215
+ const f = rec.replace(/^\n/, '').split(SEP)
216
+ if (f.length < 4 || !/^[0-9a-f]{4,40}$/.test(f[0]!)) continue
217
+ const src = f[2]!.replace(/^refs\/heads\//, '')
218
+ const at = Number(f[1]) * 1000
219
+ if (!Number.isSafeInteger(at) || at <= 0) continue
220
+ out.push({ repo, sha: f[0]!, at, branch: src === '' || src === branch ? null : maskSecrets(src).text.slice(0, MAX_NAME), title: maskSecrets(f.slice(3).join(SEP)).text.slice(0, MAX_TITLE) })
221
+ }
222
+ return out
223
+ }
224
+
225
+ /** the newest commits of every local branch since `since` (ms), one spawn */
226
+ const gitActivity = (path: string, since: number): Promise<string> => git(path, ['log', '--branches', '--source', `--since=${new Date(since).toISOString()}`, `--max-count=${MAX_ACTIVITY}`, '--no-show-signature', `--format=%h${SEP}%ct${SEP}%S${SEP}%s${END}`])
227
+
228
+ /** a repo's checks as its run record last saw them, absent where shipkit never ran. A warning an ask holds (`held`)
229
+ * waits on the owner and counts as no warning, as on the activity page */
230
+ export function gateFact<R extends { id: string; status: string; at: number }>(rows: readonly R[], held: (r: R) => boolean = () => false): GateFact | undefined {
231
+ if (rows.length === 0) return undefined
232
+ const reds = rows.filter((r) => r.status === 'fail').map((r) => r.id).sort()
233
+ const warns = rows.filter((r) => r.status === 'warn' && !held(r)).length
234
+ const at = rows.reduce<number | null>((a, r) => (Number.isSafeInteger(r.at) && r.at > 0 && (a == null || r.at > a) ? r.at : a), null)
235
+ return { state: reds.length > 0 ? 'red' : warns > 0 ? 'orange' : 'green', reds: reds.filter(name).slice(0, MAX_REDS), warns, at }
236
+ }
237
+
238
+ async function gateOf(path: string): Promise<GateFact | undefined> {
239
+ const [{ recordOf }, { readLastStatusReadonly }, { heldByAsk, waitsOf }] = await Promise.all([import('../serve/project-gutter.ts'), import('../ledger/run-log.ts'), import('../home/activity.ts')])
240
+ const record = recordOf(path)
241
+ if (record == null) return undefined
242
+ const waits = waitsOf(path)
243
+ return gateFact(readLastStatusReadonly(record, { lines: true }), (r) => heldByAsk(r.id, r.lines, waits))
244
+ }
245
+
246
+ /** this machine's report. `house` is the checkout shipkit runs from, null on a machine with none */
247
+ export async function buildReport(o: { repos: { name: string; path: string }[]; house: string | null; tailnet: { name: string | null; up: boolean }; diskOf: string; cards?: { waiting: number; since: number | null }; media?: MediaReport | null; now?: number } & Pick<Report, 'processes' | 'lanes' | 'switches'>): Promise<Report> {
248
+ const since = (o.now ?? Date.now()) - ACTIVITY_MS
249
+ const read = await Promise.all(
250
+ o.repos.slice(0, MAX_REPOS).map(async (r) => {
251
+ const [status, key, log, gate] = await Promise.all([gitStatus(r.path), repoKey(r.path), gitActivity(r.path, since), gateOf(r.path).catch(() => undefined)])
252
+ const facts: RepoFacts = { ...repoFacts(r.name, status), ...(key == null ? {} : { key }), ...(gate == null ? {} : { gate }) }
253
+ return { facts, activity: activityFacts(r.name, log, facts.branch) }
254
+ }),
255
+ )
256
+ const repos = read.map((x) => x.facts)
257
+ const activity = read.flatMap((x) => x.activity).sort((a, b) => b.at - a.at).slice(0, MAX_ACTIVITY)
258
+ const houseFacts = o.house == null ? null : repoFacts('', await gitStatus(o.house))
259
+ const fs = statfsSync(o.diskOf)
260
+ const report: Report = {
261
+ version: LIB_VERSION,
262
+ house: houseFacts == null || houseFacts.head === '' ? null : { head: houseFacts.head, behind: houseFacts.behind },
263
+ disk: { free: Number(fs.bavail) * Number(fs.bsize), total: Number(fs.blocks) * Number(fs.bsize) },
264
+ tailnet: o.tailnet,
265
+ repos: repos.filter((r) => r.head !== ''),
266
+ ...(o.cards == null ? {} : { cards: o.cards }),
267
+ ...(o.media == null ? {} : { media: o.media }),
268
+ ...(o.processes == null ? {} : { processes: o.processes }),
269
+ ...(o.lanes == null ? {} : { lanes: o.lanes }),
270
+ ...(o.switches == null ? {} : { switches: o.switches }),
271
+ activity,
272
+ }
273
+ return maskFields(report, REPORT_TEXTS)
274
+ }
@@ -0,0 +1,151 @@
1
+ // the machine db switches: each declared once here, its name, its type, its default, and whether the hq's machine may
2
+ // set it from afar. The report sends the values of this list and nothing else of the machine db. The one constraint a
3
+ // reader breaks first: a switch that sends the owner's data somewhere (the cards, the history, the reflections) or
4
+ // opens a door is never settable from afar, it stays his word on that machine
5
+ import { machineGet, machineRead, machineSet } from '../core/machine-db.ts'
6
+
7
+ export const HQ_CARDS = 'hq-cards'
8
+ export const cardsOn = (): boolean => machineGet<boolean>(HQ_CARDS) === true
9
+ /** false when the machine db does not open */
10
+ export const setCardsOn = (on: boolean): boolean => machineSet(HQ_CARDS, on)
11
+
12
+ /** the switch of the cards in the database: on, every review card of this machine is a row of the daemon's own file
13
+ * (review/card-db.ts) and its media wait in the spool beside it until the media store sent them up, so nothing of a
14
+ * card is written in a repo; off, its default, the files are the store. Turned on and off by `sk thread move`, never
15
+ * alone: the move imports the files first and exports the rows back */
16
+ export const CARDS_IN_DB = 'cards-in-db'
17
+ /** a process reads it at most once a second: the store asks it at every read and write */
18
+ const IN_DB_EVERY_MS = 1000
19
+ let inDb: { on: boolean; at: number } | null = null
20
+ /** a machine db that does not read THROWS: read as off, a card would go to the files while the rows are the store */
21
+ export function cardsInDb(now: number = Date.now()): boolean {
22
+ if (inDb == null || now - inDb.at >= IN_DB_EVERY_MS) inDb = { on: machineRead<boolean>(CARDS_IN_DB) === true, at: now }
23
+ return inDb.on
24
+ }
25
+ /** false when the machine db does not open; this process reads the new value at once */
26
+ export function setCardsInDb(on: boolean): boolean {
27
+ inDb = null
28
+ return machineSet(CARDS_IN_DB, on)
29
+ }
30
+ /** how long another process may still read the value it had: the move waits this before it reads the files again */
31
+ export const CARDS_IN_DB_LAG_MS = IN_DB_EVERY_MS
32
+
33
+ /** until when a move runs (ms): meanwhile a verb that misses its card in the store the switch names finds it in the
34
+ * other one (a process that read the switch before it turned), and a deletion always leaves its card aside */
35
+ const CARDS_MOVING = 'cards-in-db-moving'
36
+ export const cardsMoving = (now: number = Date.now()): boolean => (machineGet<number>(CARDS_MOVING) ?? 0) > now
37
+ export const setCardsMoving = (until: number | null): boolean => machineSet(CARDS_MOVING, until)
38
+
39
+ /** the switch of the history in the hq: on, the agent time job sends the owner's prompts and the day rows of `sk time`
40
+ * to the hq. Off, its default, nothing of the sender runs */
41
+ export const HQ_HISTORY = 'hq-history'
42
+ export const historyOn = (): boolean => machineGet<boolean>(HQ_HISTORY) === true
43
+ /** false when the machine db does not open */
44
+ export const setHistoryOn = (on: boolean): boolean => machineSet(HQ_HISTORY, on)
45
+
46
+ /** the switch of the media in the hq: on, the media job tells the hq each object this machine saw up in the Space, and
47
+ * a file this machine's index lacks is asked of the hq. Off, its default, neither runs */
48
+ export const HQ_MEDIA = 'hq-media'
49
+ export const mediaOn = (): boolean => machineGet<boolean>(HQ_MEDIA) === true
50
+ /** false when the machine db does not open */
51
+ export const setMediaOn = (on: boolean): boolean => machineSet(HQ_MEDIA, on)
52
+
53
+ /** the switch of the reflections in the hq: on, the report job sends each reflection file of this machine, its text
54
+ * masked. Off, its default, none leaves */
55
+ export const HQ_REFLECTIONS = 'hq-reflections'
56
+ export const reflectionsOn = (): boolean => machineGet<boolean>(HQ_REFLECTIONS) === true
57
+ export const setReflectionsOn = (on: boolean): boolean => machineSet(HQ_REFLECTIONS, on)
58
+
59
+ /** the switch of the vault's copy in the Space: on, its default, the vault job on the machine that runs a vault takes,
60
+ * proves and sends a sealed snapshot once a day and after a change. A vault with no copy is the defect, so it is on
61
+ * until the owner turns it off on that machine */
62
+ export const VAULT_SNAPSHOTS = 'vault-snapshots'
63
+ export const vaultSnapshotsOn = (): boolean => machineGet<boolean>(VAULT_SNAPSHOTS) !== false
64
+ export const setVaultSnapshotsOn = (on: boolean): boolean => machineSet(VAULT_SNAPSHOTS, on)
65
+ /** the prune of the vault's sealed snapshots in the Space: a delete for good of a backup, so OFF until the owner says
66
+ * on, on this machine, never from afar */
67
+ export const VAULT_SNAPSHOTS_PRUNE = 'vault-snapshots-prune'
68
+ export const vaultPruneOn = (): boolean => machineGet<boolean>(VAULT_SNAPSHOTS_PRUNE) === true
69
+ export const setVaultPruneOn = (on: boolean): boolean => machineSet(VAULT_SNAPSHOTS_PRUNE, on)
70
+
71
+ export type SwitchValue = boolean | number | null
72
+
73
+ export type SwitchDecl = {
74
+ name: string
75
+ /** on or off, or a time (ms) the owner's code writes */
76
+ type: 'bool' | 'time'
77
+ /** its value while the machine db holds none */
78
+ default: SwitchValue
79
+ /** the file that reads it, from src/: a test holds the name to the literal there */
80
+ owner: string
81
+ what: string
82
+ /** how the hq's machine sets it from afar, through its owner's code; absent: never from afar */
83
+ afar?: (on: boolean) => Promise<boolean>
84
+ /** on, it deletes or moves files on its machine: from afar it is only turned off, on stays the word of the person at
85
+ * that machine */
86
+ deletes?: true
87
+ }
88
+
89
+ export const SWITCHES: readonly SwitchDecl[] = [
90
+ { name: HQ_CARDS, type: 'bool', default: false, owner: 'hq/switch.ts', what: "this machine's cards to the hq and the hq's to it" },
91
+ { name: CARDS_IN_DB, type: 'bool', default: false, owner: 'hq/switch.ts', what: "this machine's review cards as rows of the daemon's database, their media in its spool until sent up" },
92
+ { name: HQ_HISTORY, type: 'bool', default: false, owner: 'hq/switch.ts', what: "the owner's prompts and the day rows of sk time to the hq" },
93
+ { name: HQ_REFLECTIONS, type: 'bool', default: false, owner: 'hq/switch.ts', what: "this machine's reflections, their text masked, to the hq" },
94
+ { name: HQ_MEDIA, type: 'bool', default: false, owner: 'hq/switch.ts', what: 'the objects this machine saw up in the Space told to the hq, and a file this machine lacks asked of it' },
95
+ { name: VAULT_SNAPSHOTS, type: 'bool', default: true, owner: 'hq/switch.ts', what: "this machine's vault, sealed, to its Space once a day and after a change" },
96
+ { name: VAULT_SNAPSHOTS_PRUNE, type: 'bool', default: false, owner: 'hq/switch.ts', what: "the vault's sealed snapshots older than 30 days deleted from the Space for good", deletes: true },
97
+ { name: 'hq-open', type: 'bool', default: false, owner: 'hq/hq-local.ts', what: "the hq's port to the other machines" },
98
+ { name: 'hq-proxy', type: 'bool', default: false, owner: 'hq/door.ts', what: "the hq's home opens a process of any machine at <process>.<machine>.localhost, on the hq's machine only" },
99
+ { name: 'machine-door', type: 'bool', default: false, owner: 'hq/door.ts', what: "this machine's web opens its own global processes to the hq's home, for the key the hq gave it" },
100
+ { name: 'media-purge-auto', type: 'bool', default: false, owner: 'media-store/daemon.ts', what: 'an uploaded media file leaves the disk after a day', deletes: true, afar: async (on) => (await import('../media-store/daemon.ts')).setAutoPurge(on) },
101
+ { name: 'annex-auto', type: 'bool', default: false, owner: 'annex/tidy.ts', what: 'the daemon tidies the annex on its own', deletes: true, afar: async (on) => (await import('../annex/tidy.ts')).setAnnexAuto(on) },
102
+ { name: 'temp-auto', type: 'bool', default: false, owner: 'home/machine-temp.ts', what: 'the hourly sweep deletes what the temp folders hold idle', deletes: true, afar: async (on) => (await import('../home/machine-temp.ts')).setTempAuto(on) },
103
+ { name: 'temp-auto-at', type: 'time', default: null, owner: 'home/machine-temp.ts', what: 'since when the temp sweep is on' },
104
+ { name: 'temp-repos-from', type: 'time', default: null, owner: 'home/machine-temp.ts', what: "since when the sweep deletes in each repo's .shipkit/tmp" },
105
+ { name: 'db-fold-auto', type: 'bool', default: true, owner: 'core/machine-db.ts', what: 'the daemon folds the media index and the agent time index into the machine db; off (a way back), a store not folded is read in its own file' },
106
+ { name: 'time-diet', type: 'bool', default: false, owner: 'agent-time/diet.ts', what: "the agent time index drops the command text of an ordinary call older than 7 days (never back: Claude Code prunes the transcripts)", deletes: true },
107
+ { name: 'trace.enabled', type: 'bool', default: true, owner: 'trace/tracer.ts', what: 'the traces of shipkit runs', afar: async (on) => ((await import('../trace/tracer.ts')).setTraceEnabled(on), true) },
108
+ ]
109
+
110
+ export const switchOf = (name: string): SwitchDecl | null => SWITCHES.find((s) => s.name === name) ?? null
111
+
112
+ /** a value as the report carries it: a bool switch true or false, a time a number or null, anything else its default */
113
+ export function switchValue(d: SwitchDecl, v: unknown): SwitchValue {
114
+ if (d.type === 'bool') return typeof v === 'boolean' ? v : d.default
115
+ return typeof v === 'number' && Number.isFinite(v) ? v : d.default
116
+ }
117
+
118
+ /** every declared switch with its value on this machine */
119
+ export const switchValues = (get: (name: string) => unknown = machineGet): Record<string, SwitchValue> => Object.fromEntries(SWITCHES.map((d) => [d.name, switchValue(d, get(d.name))]))
120
+
121
+ /** why the hq's machine may not ask this value of a node, null when it may */
122
+ export function afarRefusal(name: string, on: boolean): string | null {
123
+ const d = switchOf(name)
124
+ if (d?.afar == null || d.type !== 'bool') return `the switch ${JSON.stringify(name).slice(0, 80)} is not settable from afar${d == null ? ': no such switch is declared' : `: it stays the owner's word on its machine (${d.what})`}`
125
+ if (on && d.deletes === true) return `the switch ${d.name} deletes or moves files on its machine: it is set off from afar, never on from afar (on is the word of the person at that machine)`
126
+ return null
127
+ }
128
+
129
+ /** one value the hq's machine wants a node to take */
130
+ export type Wanted = { name: string; on: boolean; at: number }
131
+
132
+ /** the wanted values this machine's code takes: a switch it declares settable from afar, at a value it does not hold
133
+ * yet. Each through its owner's code. Lines that say what it did, the refusals included */
134
+ export async function applyWanted(wanted: readonly Wanted[], get: (name: string) => unknown = machineGet): Promise<{ set: Wanted[]; lines: string[] }> {
135
+ const set: Wanted[] = []
136
+ const lines: string[] = []
137
+ for (const w of wanted) {
138
+ const d = switchOf(w.name)
139
+ const refused = afarRefusal(w.name, w.on)
140
+ if (d?.afar == null || refused != null) {
141
+ lines.push(`WARN the hq asked to set ${JSON.stringify(w.name).slice(0, 80)} ${w.on ? 'on' : 'off'}: ${refused ?? 'refused'}, it stays as it is`)
142
+ continue
143
+ }
144
+ if (switchValue(d, get(d.name)) === w.on) continue
145
+ if (await d.afar(w.on)) {
146
+ set.push(w)
147
+ lines.push(`ok: switch ${d.name} set ${w.on ? 'on' : 'off'}, as the hq's machine asked at ${new Date(w.at).toISOString()}`)
148
+ } else lines.push(`WARN the switch ${d.name} is not set: the machine db does not open`)
149
+ }
150
+ return { set, lines }
151
+ }
@@ -0,0 +1,92 @@
1
+ // the hq's half of the vault (wiki services/secrets, step 2): a node's vault token minted from that node's grant rows,
2
+ // and the vault kept true to them. The hq keeps a token's accessor and its entity, never the token: the accessor is
3
+ // what revokes it. A row the vault may not match yet (an end, a grant changed, a call that failed) is `dirty`, and
4
+ // every mint and every check settles the dirty rows first, so a failed revoke is retried, never forgotten
5
+ import type { HqStore, Refused } from './hq-store.ts'
6
+ import type { VaultApi } from '../vault/vault-http.ts'
7
+ import { mintNode, nodeDrift, setNodeSlots, setupDrift } from '../vault/vault-minter.ts'
8
+
9
+ /** the minter of the vault beside this hq, null when this machine runs none */
10
+ export type VaultMinter = () => VaultApi | null
11
+
12
+ type Row = { node: string; accessor: string; entity: string; minted: number; dirty: number }
13
+
14
+ const rowOf = (store: HqStore, node: string): Row | null => store.db.query('select node, accessor, entity, minted, dirty from vault_tokens where node = ?').get(node) as Row | null
15
+
16
+ /** the vault may not match this node any more: its next settle makes it */
17
+ export const markVault = (store: HqStore, node: string): void => void store.db.query('update vault_tokens set dirty = 1 where node = ?').run(node)
18
+
19
+ /** every row the vault may not match, made true: an ended node's slots emptied, its token revoked and its row gone;
20
+ * a live node's slots set to its grants. What failed stays dirty, and is said */
21
+ export async function settleVault(store: HqStore, api: VaultApi): Promise<{ settled: number; failed: string[] }> {
22
+ store.db.exec('update vault_tokens set dirty = 1 where dirty = 0 and node in (select id from nodes where ended is not null)')
23
+ const rows = store.db.query('select node, accessor, entity, minted, dirty from vault_tokens where dirty = 1').all() as Row[]
24
+ const failed: string[] = []
25
+ let settled = 0
26
+ for (const r of rows) {
27
+ const n = store.nodeById(r.node)
28
+ try {
29
+ if (n == null || n.ended != null) {
30
+ await setNodeSlots(api, r.entity, null)
31
+ await api.revokeAccessor(r.accessor)
32
+ store.db.query('delete from vault_tokens where node = ? and accessor = ?').run(r.node, r.accessor)
33
+ } else {
34
+ await setNodeSlots(api, r.entity, store.grantsOf(r.node))
35
+ store.db.query('update vault_tokens set dirty = 0 where node = ? and accessor = ?').run(r.node, r.accessor)
36
+ }
37
+ settled++
38
+ } catch (e) {
39
+ failed.push(`node ${r.node}: ${(e as Error).message}`)
40
+ }
41
+ }
42
+ return { settled, failed }
43
+ }
44
+
45
+ /** the mint under way of each node, in the one process that writes the hq: the next ask waits for it */
46
+ const minting = new Map<string, Promise<unknown>>()
47
+
48
+ /** a live node's vault token, made from its grant rows: one mint at a time a node, each revoking the token the one
49
+ * before it made, so asks made at once leave one live token, the one the hq tracks. A node whose old token cannot
50
+ * be revoked gets no new one */
51
+ export function vaultTokenFor(store: HqStore, minter: VaultMinter, node: string, now: number): Promise<{ token: string; expires: number } | Refused> {
52
+ const before = minting.get(node) ?? Promise.resolve()
53
+ const mine = before.then(() => mintFor(store, minter, node, now))
54
+ const held = mine.catch(() => undefined)
55
+ minting.set(node, held)
56
+ void held.then(() => {
57
+ if (minting.get(node) === held) minting.delete(node)
58
+ })
59
+ return mine
60
+ }
61
+
62
+ async function mintFor(store: HqStore, minter: VaultMinter, node: string, now: number): Promise<{ token: string; expires: number } | Refused> {
63
+ const n = store.nodeById(node)
64
+ if (n == null || n.ended != null) return { refused: 'this node is ended: it gets no vault token' }
65
+ const grants = store.grantsOf(node)
66
+ if (grants.length === 0) return { refused: 'this node holds no grant: it gets no vault token' }
67
+ const api = minter()
68
+ if (api == null) return { refused: "this hq's machine runs no vault, or its vault is not initialised (sk vault status there)" }
69
+ try {
70
+ await settleVault(store, api)
71
+ const prev = rowOf(store, node)
72
+ if (prev != null) await api.revokeAccessor(prev.accessor)
73
+ const t = await mintNode(api, node, grants)
74
+ store.db.query('insert into vault_tokens (node, accessor, entity, minted, dirty) values (?, ?, ?, ?, 0) on conflict (node) do update set accessor = excluded.accessor, entity = excluded.entity, minted = excluded.minted, dirty = 0').run(node, t.accessor, t.entity, now)
75
+ return { token: t.token, expires: now + t.ttlS * 1000 }
76
+ } catch (e) {
77
+ return { refused: `the vault made no token for this node: ${(e as Error).message}` }
78
+ }
79
+ }
80
+
81
+ /** what differs between the vault and the grants: its setup, then each node that holds a token. Each line a
82
+ * difference; the dirty rows are settled first, and the ones that stay are said */
83
+ export async function vaultDrift(store: HqStore, api: VaultApi): Promise<{ problems: string[]; nodes: number }> {
84
+ const { failed } = await settleVault(store, api)
85
+ const problems = [...(await setupDrift(api)), ...failed.map((f) => `the vault was not brought to the grants of ${f}`)]
86
+ const rows = store.db.query('select node, accessor, entity, minted, dirty from vault_tokens').all() as Row[]
87
+ for (const r of rows) {
88
+ const n = store.nodeById(r.node)
89
+ problems.push(...(await nodeDrift(api, { id: r.node, accessor: r.accessor, entity: r.entity, grants: n == null || n.ended != null ? null : store.grantsOf(r.node) })))
90
+ }
91
+ return { problems, nodes: rows.length }
92
+ }