rvlib-shipkit 2.12.0 → 2.14.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 (378) hide show
  1. package/CHANGELOG.md +75 -21
  2. package/README.md +1 -1
  3. package/package.json +4 -2
  4. package/src/agent-time/store.ts +2 -2
  5. package/src/assets/run-assets.ts +2 -2
  6. package/src/assets/server/studio-server.ts +27 -23
  7. package/src/check.ts +4 -4
  8. package/src/checks/SK001-package-json-shape.check.ts +8 -4
  9. package/src/checks/SK002-contracts-fulfillness.check.ts +2 -2
  10. package/src/checks/SK003-claude-md-shape.check.ts +20 -13
  11. package/src/checks/SK004-gitignore-policy.check.ts +45 -6
  12. package/src/checks/SK005-rvlib-versions.check.ts +2 -2
  13. package/src/checks/SK006-npm-publish-safety.check.ts +3 -3
  14. package/src/checks/SK007-github-visibility.check.ts +2 -2
  15. package/src/checks/SK008-reviewer-agent.check.ts +3 -3
  16. package/src/checks/SK010-undeclared-unit.check.ts +2 -2
  17. package/src/checks/SK011-sibling-unit-ranges.check.ts +2 -2
  18. package/src/checks/SK012-config-barrel-import.check.ts +2 -2
  19. package/src/checks/SK013-one-way-in-policy.check.ts +2 -2
  20. package/src/checks/SK015-nested-repo.check.ts +3 -3
  21. package/src/checks/SK016-legacy-check-shapes.check.ts +2 -2
  22. package/src/checks/SK017-vscode-hub-task.check.ts +2 -2
  23. package/src/checks/SK018-test-files-run.check.ts +2 -2
  24. package/src/checks/SK019-tests-run-in-units.check.ts +2 -2
  25. package/src/checks/SK020-self-spawning-check.check.ts +2 -2
  26. package/src/checks/SK022-machine-runs-the-pin.check.ts +2 -2
  27. package/src/checks/SK024-identity-colors.check.ts +1 -1
  28. package/src/checks/SK025-release-drift.check.ts +2 -2
  29. package/src/checks/SK026-asks-autoclose.check.ts +2 -2
  30. package/src/checks/SK027-agent-wiki-links.check.ts +8 -2
  31. package/src/checks/SK028-readme.check.ts +2 -2
  32. package/src/checks/SK029-explicit-check-files.check.ts +3 -3
  33. package/src/checks/SK030-cache-audit.check.ts +7 -5
  34. package/src/checks/SK031-trace-audit.check.ts +7 -7
  35. package/src/checks/SK032-ignored-inputs.check.ts +3 -3
  36. package/src/checks/SK033-global-contribution.check.ts +11 -4
  37. package/src/checks/SK034-commit-gates-armed.check.ts +2 -2
  38. package/src/checks/SK035-public-clean.check.ts +46 -0
  39. package/src/checks/SK036-draft-media-size.check.ts +28 -0
  40. package/src/checks/SK037-keyword-additions.check.ts +43 -0
  41. package/src/cli/cmd_Backup.ts +152 -0
  42. package/src/cli/cmd_Ci.ts +8 -11
  43. package/src/cli/cmd_Commands.ts +4 -4
  44. package/src/cli/cmd_ConfigKeys.ts +2 -2
  45. package/src/cli/cmd_Drill.ts +145 -0
  46. package/src/cli/cmd_Home.ts +50 -3
  47. package/src/cli/cmd_Init.ts +1 -1
  48. package/src/cli/cmd_Media.ts +10 -8
  49. package/src/cli/cmd_Mv.ts +14 -7
  50. package/src/cli/cmd_Review.ts +6 -4
  51. package/src/cli/cmd_Shot.ts +5 -2
  52. package/src/cli/cmd_Smoke.ts +5 -2
  53. package/src/cli/cmd_Social.ts +226 -0
  54. package/src/cli/cmd_Sound.ts +1 -1
  55. package/src/cli/cmd_Start.ts +1 -1
  56. package/src/cli/cmd_Time.ts +1 -1
  57. package/src/cli/cmd_TraceAudit.ts +6 -6
  58. package/src/cli/cmd_Trailer.ts +7 -4
  59. package/src/cli/cmd_Veille.ts +173 -0
  60. package/src/cli/cmd_When.ts +2 -2
  61. package/src/cli/family-pages.ts +19 -16
  62. package/src/cli/registry.ts +13 -2
  63. package/src/cli.ts +5 -2
  64. package/src/collections/actions.ts +1 -49
  65. package/src/collections/checks.ts +2 -1
  66. package/src/collections/collection-types.ts +12 -3
  67. package/src/collections/providers.ts +4 -4
  68. package/src/collections/review.ts +3 -2
  69. package/src/collections/tests.ts +19 -8
  70. package/src/comfy/comfy-panel.ts +2 -2
  71. package/src/contracts/apply-contracts.ts +1 -3
  72. package/src/contracts/contract-manifests.ts +2 -3
  73. package/src/contracts/contract-types.ts +0 -1
  74. package/src/contracts/contracts-engine.ts +0 -3
  75. package/src/contracts/manifests/discord.contract.ts +1 -1
  76. package/src/contracts/manifests/identity.contract.ts +1 -1
  77. package/src/contracts/manifests/itch.contract.ts +1 -1
  78. package/src/contracts/manifests/steam.contract.ts +1 -1
  79. package/src/core/agent-dir-at.ts +12 -0
  80. package/src/core/agent-dir.ts +16 -0
  81. package/src/core/app-icon.ts +9 -3
  82. package/src/core/budget.ts +1 -1
  83. package/src/core/bun-builtins.ts +2 -2
  84. package/src/core/canonical-scripts.ts +2 -2
  85. package/src/core/discover-checks.ts +38 -6
  86. package/src/core/fix-scope.ts +4 -2
  87. package/src/core/floor-resolve.ts +68 -48
  88. package/src/core/floor.ts +9 -0
  89. package/src/core/git-root.ts +24 -0
  90. package/src/core/global-contribution.ts +4 -1
  91. package/src/core/ignored-block.ts +1 -1
  92. package/src/core/ignored-inputs.ts +3 -2
  93. package/src/core/last-good.ts +3 -1
  94. package/src/core/layout.ts +8 -0
  95. package/src/core/log-stamp.ts +36 -0
  96. package/src/core/loop-watch.ts +93 -0
  97. package/src/core/machine-link.ts +134 -0
  98. package/src/core/memory-watch.ts +41 -0
  99. package/src/core/motherhome.ts +2 -2
  100. package/src/core/one-way-in-policy.ts +34 -26
  101. package/src/core/run-ci.ts +9 -11
  102. package/src/core/run-fixers.ts +9 -9
  103. package/src/core/runs-matrix.ts +1 -1
  104. package/src/core/slots.ts +30 -0
  105. package/src/core/trace-audit.ts +50 -9
  106. package/src/core/tree-rev.ts +60 -0
  107. package/src/core/unit-files.ts +42 -0
  108. package/src/drill/render.ts +140 -0
  109. package/src/drill/run.ts +269 -0
  110. package/src/fleet/scan-fleet.ts +6 -5
  111. package/src/home/daemon-jobs.ts +201 -0
  112. package/src/home/global-context.ts +44 -8
  113. package/src/home/gui-app/ShipkitGui.swift +91 -2
  114. package/src/home/home-routes.ts +22 -15
  115. package/src/home/hubs.ts +10 -3
  116. package/src/home/inbox-shape.ts +54 -5
  117. package/src/home/inbox.ts +17 -2
  118. package/src/home/lib-watch.ts +10 -3
  119. package/src/home/machine-stores.ts +15 -29
  120. package/src/home/pm-config.ts +4 -1
  121. package/src/home/pm-inputs.ts +2 -0
  122. package/src/home/resources.ts +7 -2
  123. package/src/home/run-daemon.ts +15 -18
  124. package/src/home/run-pm.ts +3 -1
  125. package/src/home/serve-daemon.ts +4 -3
  126. package/src/home/serve-web.ts +104 -1
  127. package/src/hooks/commit-message.ts +29 -20
  128. package/src/hooks/hook-gates.ts +1 -1
  129. package/src/hooks/leak-guard.ts +69 -9
  130. package/src/hooks/run-hooks.ts +18 -22
  131. package/src/identities/identities.ts +334 -0
  132. package/src/identities/machine-route.ts +126 -0
  133. package/src/identities/machine.ts +62 -0
  134. package/src/init-repo.ts +3 -3
  135. package/src/ledger/check-stats.ts +10 -9
  136. package/src/ledger/gate-checks.ts +32 -1
  137. package/src/ledger/record-kept.ts +112 -0
  138. package/src/ledger/repo-view.ts +10 -0
  139. package/src/ledger/run-log.ts +17 -12
  140. package/src/ledger/run-timeline.ts +8 -4
  141. package/src/ledger/store.ts +7 -0
  142. package/src/ledger/suite-log.ts +17 -13
  143. package/src/media-kinds.ts +3 -2
  144. package/src/media-store/backup/daemon.ts +73 -0
  145. package/src/media-store/backup/keys.ts +25 -0
  146. package/src/media-store/backup/manifest.ts +193 -0
  147. package/src/media-store/backup/restore.ts +192 -0
  148. package/src/media-store/backup/run.ts +278 -0
  149. package/src/media-store/backup/secret.ts +86 -0
  150. package/src/media-store/backup/snapshot.ts +64 -0
  151. package/src/media-store/backup/sources.ts +199 -0
  152. package/src/media-store/content.ts +1 -1
  153. package/src/media-store/daemon.ts +56 -70
  154. package/src/media-store/db.ts +1 -1
  155. package/src/media-store/fact.ts +1 -1
  156. package/src/media-store/hand.ts +1 -1
  157. package/src/media-store/kind.ts +1 -1
  158. package/src/media-store/purge.ts +1 -1
  159. package/src/media-store/put.ts +5 -3
  160. package/src/media-store/remote.ts +1 -1
  161. package/src/media-store/space.ts +24 -5
  162. package/src/mv/mv-md.ts +63 -22
  163. package/src/pages/forward.ts +35 -0
  164. package/src/pages/frame-client.ts +118 -0
  165. package/src/pages/routes.ts +29 -0
  166. package/src/pages/unit.ts +92 -0
  167. package/src/plan/planner.ts +12 -0
  168. package/src/plan/repo-source.ts +19 -5
  169. package/src/reflect/transcript.ts +35 -10
  170. package/src/release/public-clean.ts +319 -0
  171. package/src/release/published-here.ts +22 -0
  172. package/src/release/run-bump.ts +3 -2
  173. package/src/release/run-release.ts +7 -4
  174. package/src/repo-config.ts +71 -13
  175. package/src/review/anim.ts +1 -1
  176. package/src/review/auto.ts +1 -1
  177. package/src/review/cells.ts +15 -1
  178. package/src/review/format.ts +2 -2
  179. package/src/review/http.ts +16 -2
  180. package/src/review/marks.ts +1 -1
  181. package/src/review/media-kind.ts +1 -1
  182. package/src/review/media-read.ts +1 -1
  183. package/src/review/model.ts +27 -6
  184. package/src/review/notes.ts +125 -0
  185. package/src/review/previews.ts +1 -1
  186. package/src/review/project.ts +7 -39
  187. package/src/review/role.ts +1 -1
  188. package/src/review/routes.ts +18 -14
  189. package/src/review/store.ts +42 -2
  190. package/src/review/threads.ts +1 -1
  191. package/src/review/trailer-desk.ts +3 -3
  192. package/src/review/trailer-media.ts +8 -5
  193. package/src/review/trailer-model.ts +1 -1
  194. package/src/review/trailer-routes.ts +1 -1
  195. package/src/review/trailer-shots.ts +22 -5
  196. package/src/review/unit.ts +2 -2
  197. package/src/scaffold/files/agent-handoff.md +3 -0
  198. package/src/scaffold/files/agent-index.md +4 -12
  199. package/src/scaffold/files/tsconfig.json +1 -1
  200. package/src/scaffold/project-scaffold.ts +6 -5
  201. package/src/serve/embed.ts +2 -2
  202. package/src/serve/hub-app/check-words.ts +1 -1
  203. package/src/serve/hub-app/col-card.tsx +3 -17
  204. package/src/serve/hub-app/col-tables-view.tsx +2 -1
  205. package/src/serve/hub-app/cols-svc.ts +0 -13
  206. package/src/serve/hub-app/dock-st.ts +4 -2
  207. package/src/serve/hub-app/dock-view.tsx +2 -0
  208. package/src/serve/hub-app/frames-st.ts +35 -0
  209. package/src/serve/hub-app/hash-route.ts +64 -1
  210. package/src/serve/hub-app/home-st.ts +32 -8
  211. package/src/serve/hub-app/home-strip.css +9 -1
  212. package/src/serve/hub-app/home-strip.tsx +7 -6
  213. package/src/serve/hub-app/home.html +5 -0
  214. package/src/serve/hub-app/hub-app.tsx +51 -7
  215. package/src/serve/hub-app/hub.css +29 -11
  216. package/src/serve/hub-app/icons.tsx +16 -1
  217. package/src/serve/hub-app/identities-st.ts +210 -0
  218. package/src/serve/hub-app/identities-view.tsx +353 -0
  219. package/src/serve/hub-app/identities.css +48 -0
  220. package/src/serve/hub-app/identity-address.ts +52 -0
  221. package/src/serve/hub-app/inbox-st.ts +60 -7
  222. package/src/serve/hub-app/inbox-view.tsx +49 -7
  223. package/src/serve/hub-app/inbox.css +12 -1
  224. package/src/serve/hub-app/index.html +3 -0
  225. package/src/serve/hub-app/kept-cols.tsx +30 -0
  226. package/src/serve/hub-app/keys.ts +10 -2
  227. package/src/serve/hub-app/list-walk.ts +89 -0
  228. package/src/serve/hub-app/machine-st.ts +12 -0
  229. package/src/serve/hub-app/media-svc.ts +1 -1
  230. package/src/serve/hub-app/media-view.tsx +2 -1
  231. package/src/serve/hub-app/pages-frames.tsx +134 -0
  232. package/src/serve/hub-app/pages-svc.ts +111 -0
  233. package/src/serve/hub-app/palette-st.ts +18 -3
  234. package/src/serve/hub-app/palette-view.tsx +9 -2
  235. package/src/serve/hub-app/planned-view.tsx +2 -1
  236. package/src/serve/hub-app/project-list.css +18 -14
  237. package/src/serve/hub-app/project-list.tsx +88 -49
  238. package/src/serve/hub-app/projects-svc.ts +33 -3
  239. package/src/serve/hub-app/repo-sections.ts +19 -2
  240. package/src/serve/hub-app/repo-st.ts +76 -20
  241. package/src/serve/hub-app/review/review-board.tsx +1 -1
  242. package/src/serve/hub-app/review/review-cells.tsx +6 -5
  243. package/src/serve/hub-app/review/review-kit.ts +30 -7
  244. package/src/serve/hub-app/review/review-page.tsx +6 -5
  245. package/src/serve/hub-app/review/review-st.ts +34 -15
  246. package/src/serve/hub-app/review/review-thread.tsx +63 -14
  247. package/src/serve/hub-app/review/review-views.tsx +133 -51
  248. package/src/serve/hub-app/review/thread-st.ts +80 -37
  249. package/src/serve/hub-app/review/trailer-page.tsx +7 -5
  250. package/src/serve/hub-app/review/trailer-st.ts +1 -1
  251. package/src/serve/hub-app/review.css +26 -9
  252. package/src/serve/hub-app/site/site-part.tsx +173 -0
  253. package/src/serve/hub-app/site/site-st.ts +157 -0
  254. package/src/serve/hub-app/site.css +35 -0
  255. package/src/serve/hub-app/social/calendar.tsx +182 -0
  256. package/src/serve/hub-app/social/comms-page.tsx +330 -0
  257. package/src/serve/hub-app/social/kit.tsx +244 -0
  258. package/src/serve/hub-app/social/post-card.tsx +456 -0
  259. package/src/serve/hub-app/social/problems.tsx +60 -0
  260. package/src/serve/hub-app/social/social-model.ts +154 -0
  261. package/src/serve/hub-app/social/social-page.tsx +681 -0
  262. package/src/serve/hub-app/social/social-st.ts +1014 -0
  263. package/src/serve/hub-app/social.css +289 -0
  264. package/src/serve/hub-app/stores/stores-page.tsx +312 -0
  265. package/src/serve/hub-app/stores/stores-st.ts +286 -0
  266. package/src/serve/hub-app/stores.css +54 -0
  267. package/src/serve/hub-app/timeline-geometry.ts +1 -1
  268. package/src/serve/hub-app/timeline-view.tsx +3 -2
  269. package/src/serve/hub-app/tree-build.ts +6 -0
  270. package/src/serve/hub-app/tree-row.tsx +27 -4
  271. package/src/serve/hub-app/tree-svc.ts +18 -49
  272. package/src/serve/hub-app/veille/veille-page.tsx +515 -0
  273. package/src/serve/hub-app/veille/veille-st.ts +443 -0
  274. package/src/serve/hub-app/veille.css +84 -0
  275. package/src/serve/hub-runtime.ts +20 -11
  276. package/src/serve/project-gutter-route.ts +44 -12
  277. package/src/serve/run-lanes.ts +7 -4
  278. package/src/serve/same-origin.ts +1 -1
  279. package/src/serve/serve-hub.ts +20 -12
  280. package/src/serve/tracked-watch.ts +24 -3
  281. package/src/serve/warm-cell.ts +5 -1
  282. package/src/shipkit-files.ts +15 -4
  283. package/src/shipkit.ts +0 -1
  284. package/src/shot/box.ts +160 -0
  285. package/src/shot/browser-slot.ts +74 -0
  286. package/src/shot/client.ts +42 -7
  287. package/src/shot/clip-encoder.ts +108 -24
  288. package/src/shot/film-box.ts +292 -0
  289. package/src/shot/shooter.ts +71 -17
  290. package/src/shot/shot-ask.ts +10 -2
  291. package/src/shot/stepped-clip.ts +5 -4
  292. package/src/site/desk.ts +242 -0
  293. package/src/site/routes.ts +66 -0
  294. package/src/site/unit.ts +62 -0
  295. package/src/social/brands.ts +22 -0
  296. package/src/social/card-drafts.ts +24 -0
  297. package/src/social/compose.ts +97 -0
  298. package/src/social/desk-index.ts +123 -0
  299. package/src/social/desk-wire.ts +64 -0
  300. package/src/social/drafts.ts +183 -0
  301. package/src/social/house.ts +24 -0
  302. package/src/social/load.ts +332 -0
  303. package/src/social/md.ts +70 -0
  304. package/src/social/media-facts.ts +53 -0
  305. package/src/social/media-kind.ts +189 -0
  306. package/src/social/media-limit.ts +42 -0
  307. package/src/social/media-of.ts +30 -0
  308. package/src/social/migrate.ts +123 -0
  309. package/src/social/open.ts +17 -0
  310. package/src/social/post-url.ts +158 -0
  311. package/src/social/presence.ts +332 -0
  312. package/src/social/public-read.ts +53 -0
  313. package/src/social/publish/bluesky.ts +168 -0
  314. package/src/social/publish/discord.ts +76 -0
  315. package/src/social/publish/index.ts +24 -0
  316. package/src/social/publish/secret.ts +13 -0
  317. package/src/social/push.ts +37 -0
  318. package/src/social/richtext.ts +37 -0
  319. package/src/social/routes.ts +186 -0
  320. package/src/social/stats.ts +134 -0
  321. package/src/social/text.ts +267 -0
  322. package/src/social/tracker-route.ts +39 -0
  323. package/src/social/tracker.ts +255 -0
  324. package/src/social/unit.ts +53 -0
  325. package/src/social/writes.ts +130 -0
  326. package/src/start-repo.ts +14 -9
  327. package/src/stores/collection.ts +27 -0
  328. package/src/stores/desk.ts +336 -0
  329. package/src/stores/model.ts +187 -0
  330. package/src/stores/routes.ts +126 -0
  331. package/src/stores/unit.ts +57 -0
  332. package/src/suite/calibrate.ts +127 -0
  333. package/src/suite/core-counters.ts +91 -0
  334. package/src/suite/judge-suites.ts +95 -35
  335. package/src/suite/suite-cli.ts +44 -10
  336. package/src/suite/suite-cpu-preload.ts +34 -9
  337. package/src/trace/tracer.ts +12 -5
  338. package/src/trailer/adapter.ts +5 -1
  339. package/src/trailer/build.ts +45 -12
  340. package/src/trailer/ffmpeg.ts +11 -0
  341. package/src/trailer/footage.ts +30 -13
  342. package/src/trailer/grammar.ts +18 -2
  343. package/src/trailer/graph.ts +28 -6
  344. package/src/trailer/holes.ts +1 -1
  345. package/src/trailer/passage.ts +18 -6
  346. package/src/trailer/plan.ts +74 -3
  347. package/src/trailer/prune.ts +1 -1
  348. package/src/trailer/states.ts +1 -1
  349. package/src/trailer/stitch.ts +67 -26
  350. package/src/trailer/url.ts +1 -1
  351. package/src/trailer/versions.ts +24 -0
  352. package/src/trailer/words.ts +1 -1
  353. package/src/ts/gate-typecheck.ts +32 -0
  354. package/src/ts/typecheck-cli.ts +9 -11
  355. package/src/tui/run-tui.ts +1 -1
  356. package/src/tui/tui-app.tsx +0 -1
  357. package/src/tui/tui-store.ts +1 -1
  358. package/src/veille/asks.ts +155 -0
  359. package/src/veille/auto.ts +31 -0
  360. package/src/veille/batch.ts +27 -0
  361. package/src/veille/chrome.ts +127 -0
  362. package/src/veille/collection.ts +28 -0
  363. package/src/veille/desk.ts +242 -0
  364. package/src/veille/identity.ts +80 -0
  365. package/src/veille/import.ts +68 -0
  366. package/src/veille/log.ts +183 -0
  367. package/src/veille/platforms.ts +118 -0
  368. package/src/veille/reads.ts +66 -0
  369. package/src/veille/replied.ts +110 -0
  370. package/src/veille/routes.ts +185 -0
  371. package/src/veille/service.ts +81 -0
  372. package/src/veille/watch.ts +116 -0
  373. package/src/veille/worth.ts +46 -0
  374. package/src/wiki/scan-md.ts +18 -0
  375. package/src/collections/posts.ts +0 -142
  376. package/src/contracts/manifests/social.contract.ts +0 -20
  377. package/src/scaffold/files/agent-coding.md +0 -35
  378. package/src/ts/typecheck-cache.ts +0 -11
@@ -1,4 +1,4 @@
1
- // the inbox as data (wiki build/shipkit/home.md, The inbox): everything that waits on the owner in every house repo,
1
+ // the inbox as data (wiki tools/shipkit/home.md, The inbox): everything that waits on the owner in every house repo,
2
2
  // one list. Pure and browser safe: the daemon (inbox.ts), the page and the tests share it. Each repo gives what it
3
3
  // already holds, never a store of its own: its review store's thread index and its hub's rows that need someone.
4
4
  //
@@ -15,6 +15,14 @@ export type InboxKind = 'card' | 'question' | 'ask' | 'need' | 'raised'
15
15
  export type InboxTone = 'review' | 'red' | 'yellow'
16
16
  /** the main list (what waits on him) or the folded one (what can wait, what he can only read) */
17
17
  export type InboxList = 'main' | 'yellow'
18
+ /** the review store's rows only (the default), or every row, the checks and asks included */
19
+ export type InboxShow = 'cards' | 'all'
20
+ /** what the rows group by: each one on or off on its own, nested in this order */
21
+ export const INBOX_GROUPS = ['repo', 'kind', 'lane'] as const
22
+ export type InboxGroup = (typeof INBOX_GROUPS)[number]
23
+
24
+ /** a row the review store gives: a card, a question, an item raised in it */
25
+ export const isCardKind = (k: InboxKind): boolean => k === 'card' || k === 'question' || k === 'raised'
18
26
 
19
27
  export interface InboxRow {
20
28
  /** `<repo>/<id>`, one per row of the whole inbox */
@@ -31,6 +39,8 @@ export interface InboxRow {
31
39
  title: string
32
40
  /** one more line: the lane and the versions, the need's sentence */
33
41
  sub?: string
42
+ /** the lane the card belongs to; a need has none */
43
+ lane?: string
34
44
  /** epoch ms of its newest move, null when nothing dates it */
35
45
  at: number | null
36
46
  /** the review preview thumb, on the home's origin */
@@ -55,7 +65,11 @@ export interface InboxAnswer {
55
65
  total: number
56
66
  offset: number
57
67
  limit: number
68
+ /** the rows of each list the page shows */
58
69
  counts: Record<InboxList, number>
70
+ /** the rows of each list with every kind: what « all » would show */
71
+ all: Record<InboxList, number>
72
+ show: InboxShow
59
73
  /** per repo, the rows of each list: its own badges count the same */
60
74
  repos: Record<string, Record<InboxList, number>>
61
75
  /** a repo whose items are not here, and why (its hub is down, a read broke) */
@@ -98,6 +112,7 @@ function reviewRow(repo: string, r: ThreadRow, kind: InboxKind, tone: InboxTone)
98
112
  tone,
99
113
  title: r.title,
100
114
  ...(sub !== '' ? { sub } : {}),
115
+ ...(r.lane ? { lane: r.lane } : {}),
101
116
  at: Number.isFinite(at) ? at : null,
102
117
  thumb: r.thumb != null && IMAGE.test(r.thumb) ? `${hubOf(repo)}/api/review/${r.head}/preview/thumb/${r.thumb}` : null,
103
118
  open: inboxAddress(repo, r.head),
@@ -164,25 +179,59 @@ export function inboxRows<S extends InboxSource>(sources: readonly S[], dated: (
164
179
  }
165
180
 
166
181
  /** the query from a url's search: a value out of range is its default */
167
- export function inboxQuery(p: URLSearchParams): { list: InboxList; offset: number; limit: number } {
182
+ export function inboxQuery(p: URLSearchParams): { list: InboxList; show: InboxShow; offset: number; limit: number } {
168
183
  const n = (k: string, d: number, max: number): number => {
169
184
  const v = Number(p.get(k) || NaN)
170
185
  return Number.isInteger(v) && v >= 0 ? Math.min(v, max) : d
171
186
  }
172
- return { list: p.get('list') === 'yellow' ? 'yellow' : 'main', offset: n('offset', 0, Number.MAX_SAFE_INTEGER), limit: Math.max(1, n('limit', INBOX_PAGE, INBOX_MAX)) }
187
+ return { list: p.get('list') === 'yellow' ? 'yellow' : 'main', show: p.get('show') === 'all' ? 'all' : 'cards', offset: n('offset', 0, Number.MAX_SAFE_INTEGER), limit: Math.max(1, n('limit', INBOX_PAGE, INBOX_MAX)) }
173
188
  }
174
189
 
175
190
  /** one page of one list */
176
191
  export function inboxPage(all: ReturnType<typeof inboxRows>, q: ReturnType<typeof inboxQuery>, missing: InboxAnswer['missing']): InboxAnswer {
177
- const rows = all[q.list]
192
+ // the kinds filter before the page cuts, so a card past the first page is never lost behind a check
193
+ const shown = (l: InboxList): InboxRow[] => (q.show === 'all' ? all[l] : all[l].filter((r) => isCardKind(r.kind)))
194
+ const rows = shown(q.list)
178
195
  return {
179
196
  list: q.list,
180
197
  rows: rows.slice(q.offset, q.offset + q.limit),
181
198
  total: rows.length,
182
199
  offset: q.offset,
183
200
  limit: q.limit,
184
- counts: { main: all.main.length, yellow: all.yellow.length },
201
+ counts: { main: shown('main').length, yellow: shown('yellow').length },
202
+ all: { main: all.main.length, yellow: all.yellow.length },
203
+ show: q.show,
185
204
  repos: all.repos,
186
205
  missing,
187
206
  }
188
207
  }
208
+
209
+ const KIND_LABEL: Record<InboxKind, string> = { card: 'cards', question: 'questions', ask: 'asks', need: 'needs', raised: 'raised' }
210
+
211
+ /** a group of rows: its words, its rows' count, then its rows or its inner groups */
212
+ export type InboxGroupNode = { key: string; label: string; n: number; rows: InboxRow[]; groups: InboxGroupNode[] | null }
213
+
214
+ const groupOf = (r: InboxRow, by: InboxGroup): string => (by === 'repo' ? r.repo : by === 'kind' ? KIND_LABEL[r.kind] : r.lane ?? 'no lane')
215
+
216
+ /** the rows grouped by each axis that is on, nested repo then kind then lane; a group keeps its rows' order, and the
217
+ * groups come in the order their first row comes (newest first). No axis on: one group of every row */
218
+ export function groupRows(rows: readonly InboxRow[], on: readonly InboxGroup[], prefix = ''): InboxGroupNode[] {
219
+ const axes = INBOX_GROUPS.filter((g) => on.includes(g))
220
+ const [by, ...rest] = axes
221
+ if (by == null) return [{ key: prefix || 'all', label: '', n: rows.length, rows: [...rows], groups: null }]
222
+ const order: string[] = []
223
+ const of = new Map<string, InboxRow[]>()
224
+ for (const r of rows) {
225
+ const k = groupOf(r, by)
226
+ if (!of.has(k)) {
227
+ of.set(k, [])
228
+ order.push(k)
229
+ }
230
+ of.get(k)!.push(r)
231
+ }
232
+ return order.map((k) => {
233
+ const rs = of.get(k)!
234
+ const key = `${prefix}${by}:${k}/`
235
+ return { key, label: k, n: rs.length, rows: rs, groups: rest.length > 0 ? groupRows(rs, rest, key) : null }
236
+ })
237
+ }
package/src/home/inbox.ts CHANGED
@@ -1,4 +1,4 @@
1
- // the daemon's inbox route (wiki build/shipkit/home.md, The inbox): every loaded hub's review index and needing rows,
1
+ // the daemon's inbox route (wiki tools/shipkit/home.md, The inbox): every loaded hub's review index and needing rows,
2
2
  // shaped by inbox-shape.ts. It reads memory only (each store's thread index, each hub's warm rows) and a stat per
3
3
  // dated file, so a poll answers in milliseconds; the whole answer's hash is its ETag
4
4
  import { statSync } from 'fs'
@@ -72,8 +72,23 @@ export const datedIn = (root: string): Dated => (n: Resource) => {
72
72
  }
73
73
  }
74
74
 
75
+ /** one read of every hub's rows is shared by every page that asks within this long */
76
+ export const INBOX_SHARE_MS = 1_000
77
+ const shared = new WeakMap<object, { end: number | null; read: ReturnType<typeof readSources> }>()
78
+
79
+ /** what every hub that is up holds; concurrent pages (windows, the phone) share one read while it runs and for
80
+ * INBOX_SHARE_MS after it ended */
81
+ export function inboxSources(hubs: Pick<Hubs, 'loaded'>, now: () => number = Date.now): ReturnType<typeof readSources> {
82
+ const held = shared.get(hubs)
83
+ if (held != null && (held.end == null || now() - held.end < INBOX_SHARE_MS)) return held.read
84
+ const entry: { end: number | null; read: ReturnType<typeof readSources> } = { end: null, read: readSources(hubs) }
85
+ shared.set(hubs, entry)
86
+ entry.read.then(() => { entry.end = now() }, () => { if (shared.get(hubs) === entry) shared.delete(hubs) })
87
+ return entry.read
88
+ }
89
+
75
90
  /** what every hub that is up holds, read in parallel; a repo whose read broke is named, never dropped silently */
76
- export async function inboxSources(hubs: Pick<Hubs, 'loaded'>): Promise<{ sources: (InboxSource & { root: string })[]; missing: InboxAnswer['missing'] }> {
91
+ async function readSources(hubs: Pick<Hubs, 'loaded'>): Promise<{ sources: (InboxSource & { root: string })[]; missing: InboxAnswer['missing'] }> {
77
92
  const missing: InboxAnswer['missing'] = []
78
93
  const read = await Promise.all(
79
94
  hubs.loaded().map(async ({ repo, rt }) => {
@@ -12,6 +12,7 @@ import { existsSync, readFileSync, realpathSync, statSync, watch, type FSWatcher
12
12
  import { dirname, extname, join, relative, resolve } from 'path'
13
13
  import { copyStamp, heldNow, homeLib, LAST_GOOD_ENV, lastGood, OWN_LIB, setHeld, takeLastGood } from '../core/last-good.ts'
14
14
  import { LIB_VERSION } from '../core/lib-version.ts'
15
+ import { loopWatch } from '../core/loop-watch.ts'
15
16
  import { bootEntries, probeLoad, TreeProbe } from '../core/load-probe.ts'
16
17
  import { reexecBlocker, reexecSelf } from '../core/reexec.ts'
17
18
  import { StaleRestart } from '../serve/stale-restart.ts'
@@ -57,6 +58,10 @@ export function libGraph(entry: string, o: { bundles?: boolean } = {}): Set<stri
57
58
  return out
58
59
  }
59
60
 
61
+ /** a burst of saves is one change once no write came for this long: an agent saves file after file, and each
62
+ * restart rescans every house repo */
63
+ export const SETTLE_MS = 5_000
64
+
60
65
  export class LibWatch {
61
66
  private w: FSWatcher | null = null
62
67
  private last: { file: string; at: number } | null = null
@@ -68,9 +73,9 @@ export class LibWatch {
68
73
  private settleMs: number
69
74
 
70
75
  /** `only`: absolute paths; an edit of any other file is not a change */
71
- constructor(private root: string, o: { settleMs?: number; now?: () => number; only?: Set<string> } = {}) {
76
+ constructor(root: string, o: { settleMs?: number; now?: () => number; only?: Set<string> } = {}) {
72
77
  this.now = o.now ?? Date.now
73
- this.settleMs = o.settleMs ?? 1_000
78
+ this.settleMs = o.settleMs ?? SETTLE_MS
74
79
  // an APFS clone of the tree (the last good copy, a scratch checkout)
75
80
  // fires a change on every source file it reads: only a moved mtime,
76
81
  // or a file gone, is a write
@@ -207,13 +212,15 @@ export function reloadOnOwnCode(o: {
207
212
  const keeper = o.keep === true && !onCopy
208
213
  ? setInterval(() => {
209
214
  if (lib.seq === kept || !lib.settled() || Date.now() - Math.max(lastGood(tree)?.at ?? 0, triedAt) < KEEP_EVERY_MS) return
215
+ const probed = loopWatch.span('load probe')
210
216
  const v = probe.loads()
217
+ probed()
211
218
  if (v === 'pending') return
212
219
  if (v !== 'ok') return hold(v)
213
220
  hold(null)
214
221
  kept = lib.seq
215
222
  triedAt = Date.now()
216
- void takeLastGood(tree).catch((e: Error) => o.io.printErr(`WARN the last good copy of the shipkit source could not be kept: ${e.message}`))
223
+ void loopWatch.spanned('last good copy', () => takeLastGood(tree)).catch((e: Error) => o.io.printErr(`WARN the last good copy of the shipkit source could not be kept: ${e.message}`))
217
224
  }, 2_000)
218
225
  : null
219
226
  function stop(): void {
@@ -1,10 +1,12 @@
1
1
  // the machine's own stores and their caps (core/retention.ts owns the model):
2
2
  // every log under the home dir, and the gui window's Chrome profile. And the
3
- // daemon's timer that sweeps every store, the repos' and these.
3
+ // daemon's retention job that sweeps every store, the repos' and these, in a
4
+ // child process (daemon-jobs.ts).
4
5
  import { existsSync, lstatSync, readdirSync, rmSync, statSync } from 'fs'
5
6
  import { join } from 'path'
6
7
  import { repoStores, sweepStores, walkUse, type Store } from '../core/retention.ts'
7
8
  import { capLog, LOG_MAX_BYTES } from './supervise.ts'
9
+ import { machineSet } from '../core/machine-db.ts'
8
10
 
9
11
  /** a log nothing wrote for this long belongs to a process that is gone (a
10
12
  * repo removed, a resource dropped) */
@@ -85,33 +87,17 @@ export function machineStores(dir: string): Store[] {
85
87
 
86
88
  /** how often the daemon sweeps, after the one on boot */
87
89
  export const SWEEP_EVERY_MS = 60 * 60 * 1000
88
- /** the boot sweep waits this long, so loading the repos goes first */
89
- export const BOOT_SWEEP_DELAY_MS = 10_000
90
-
91
- export type Sweeper = { stop: () => void; once: () => Promise<void> }
92
-
93
- /** the daemon's one retention sweep: every repo it loads, then the machine,
94
- * then `also` (the machine's batched writes), on boot and every hour. A
95
- * store whose sweep throws is one printed line */
96
- export function startSweeps(o: { roots: () => string[]; dir: string; printErr: (l: string) => void; everyMs?: number; bootDelayMs?: number; now?: () => number; also?: (now: number) => void }): Sweeper {
97
- let running = false
98
- const once = async (): Promise<void> => {
99
- if (running) return
100
- running = true
101
- try {
102
- const now = (o.now ?? Date.now)()
103
- for (const root of o.roots()) {
104
- for (const r of await sweepStores(repoStores(root), now)) if (r.error != null) o.printErr(`WARN retention sweep of ${r.id} in ${root} failed: ${r.error}`)
105
- }
106
- for (const r of await sweepStores(machineStores(o.dir), now)) if (r.error != null) o.printErr(`WARN retention sweep of ${r.id} failed: ${r.error}`)
107
- o.also?.(now)
108
- } finally {
109
- running = false
110
- }
90
+ /** when the last sweep ended, in the machine db: the daemon's job sweeps once SWEEP_EVERY_MS passed, a restart
91
+ * included */
92
+ export const SWEPT_AT = 'retention-swept-at'
93
+ /** one sweep of the daemon's retention job, in its child process: every repo, then the machine, then `also`; its
94
+ * end time kept, so the daemon's next look waits SWEEP_EVERY_MS whatever restarts in between */
95
+ export async function sweepTick(o: { roots: string[]; dir: string; printErr: (l: string) => void; now?: () => number; also?: (now: number) => void }): Promise<void> {
96
+ const now = (o.now ?? Date.now)()
97
+ for (const root of o.roots) {
98
+ for (const r of await sweepStores(repoStores(root), now)) if (r.error != null) o.printErr(`WARN retention sweep of ${r.id} in ${root} failed: ${r.error}`)
111
99
  }
112
- const boot = setTimeout(() => void once(), o.bootDelayMs ?? BOOT_SWEEP_DELAY_MS)
113
- const every = setInterval(() => void once(), o.everyMs ?? SWEEP_EVERY_MS)
114
- boot.unref()
115
- every.unref()
116
- return { stop: () => { clearTimeout(boot); clearInterval(every) }, once }
100
+ for (const r of await sweepStores(machineStores(o.dir), now)) if (r.error != null) o.printErr(`WARN retention sweep of ${r.id} failed: ${r.error}`)
101
+ o.also?.(now)
102
+ machineSet(SWEPT_AT, (o.now ?? Date.now)())
117
103
  }
@@ -7,6 +7,7 @@
7
7
  //
8
8
  // bun pm-config.ts <root> prints a PmConfig as json on stdout
9
9
  import { homedir } from 'os'
10
+ import { join } from 'path'
10
11
  import { houseInputs, stampOf, type PmConfig } from './pm-inputs.ts'
11
12
 
12
13
  export type { PmConfig }
@@ -27,7 +28,9 @@ if (import.meta.main) {
27
28
  files.set(r, f)
28
29
  return f
29
30
  })
30
- const out: PmConfig = { index: house.index, processes: [], errors: [], inputs, stamp: stampOf(inputs) }
31
+ // an archived repo's config too: its unarchive must bring its processes back at once
32
+ if (house.index != null) for (const r of house.archived) inputs.push(join(r.path, 'repo.config.ts'))
33
+ const out: PmConfig = { index: house.index, processes: [], errors: [], archived: house.archived.map((r) => r.name), inputs, stamp: stampOf(inputs) }
31
34
  if (house.index != null) {
32
35
  // a unit file imports the lib by name: this copy, like the daemon's
33
36
  const { installOneLib } = await import('../core/one-lib.ts')
@@ -13,6 +13,8 @@ export type PmConfig = {
13
13
  processes: GlobalProcessDecl[]
14
14
  /** the unit files that would not load */
15
15
  errors: string[]
16
+ /** the archived house repos, by name: a process one of them declared is stopped when it leaves (Resources.sync) */
17
+ archived: string[]
16
18
  /** every path whose stat can change this answer (houseInputs) */
17
19
  inputs: string[]
18
20
  /** stampOf(inputs), taken before the unit files were imported */
@@ -398,12 +398,17 @@ export class Resources {
398
398
 
399
399
  /** the declarations as they are now: an unchanged one keeps its state, a
400
400
  * changed or new one starts from its pid record, a dropped one leaves
401
- * its process running for whoever declares it next */
402
- sync(decls: GlobalProcessDecl[], errors: string[] = []): void {
401
+ * its process running for whoever declares it next (a unit file that
402
+ * fails to load mid edit must not kill it). A dropped one whose repo is
403
+ * now `archived` is stopped first: nothing runs in an archived repo */
404
+ async sync(decls: GlobalProcessDecl[], errors: string[] = [], archived: readonly string[] = []): Promise<void> {
403
405
  const key = (d: GlobalProcessDecl): string => JSON.stringify(d)
404
406
  const had = new Map(this.list.map((r) => [key(r.decl), r]))
407
+ const kept = new Set(decls.map(key))
408
+ const gone = this.list.filter((r) => !kept.has(key(r.decl)) && archived.includes(r.decl.repo) && !decls.some((d) => d.id === r.decl.id))
405
409
  this.list = decls.map((d) => had.get(key(d)) ?? new Resource(d, this.dir, this.o))
406
410
  this.errors = errors
411
+ await Promise.all(gone.map((r) => r.set('down')))
407
412
  }
408
413
 
409
414
  get(id: string): Resource | 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 { loopWatch } from '../core/loop-watch.ts'
10
+ import { MemoryWatch } from '../core/memory-watch.ts'
9
11
  import { fileURLToPath } from 'url'
10
12
  import { installOneLib } from '../core/one-lib.ts'
11
13
  import { reclaimPreviousImage } from '../core/instance.ts'
@@ -16,17 +18,15 @@ import { projectGutter } from '../serve/project-gutter-route.ts'
16
18
  import { loadRepoConfig } from '../repo-config.ts'
17
19
  import { ensureIdentity } from '../core/identity.ts'
18
20
  import { homedir } from 'os'
19
- import { daemonPort, homeDir, homePort, homeUp, hubBase, publicHome, WORKER_ENV } from './home-paths.ts'
21
+ import { join } from 'path'
22
+ import { childLog, daemonPort, homeDir, homePort, homeUp, hubBase, publicHome, WORKER_ENV } from './home-paths.ts'
20
23
  import { inboxAddress } from './inbox-shape.ts'
21
24
  import { HomeState } from './home-state.ts'
22
25
  import { Hubs } from './hubs.ts'
23
26
  import { Planner } from '../plan/planner.ts'
24
27
  import { machineCatchUp } from '../plan/catch-up.ts'
25
28
  import { serveDaemon } from './serve-daemon.ts'
26
- import { startSweeps } from './machine-stores.ts'
27
- import { startMediaStore } from '../media-store/daemon.ts'
28
- import { mediaKinds } from '../media-kinds.ts'
29
- import { landMotherhome } from '../core/motherhome.ts'
29
+ import { startJobs } from './daemon-jobs.ts'
30
30
  import { Widgets } from './widgets.ts'
31
31
 
32
32
  const CLI = fileURLToPath(new URL('../cli.ts', import.meta.url))
@@ -114,25 +114,22 @@ export async function runDaemon(root: string, io: HomeIo, o: { port?: number } =
114
114
  publicHost,
115
115
  })
116
116
  io.print(`daemon → http://127.0.0.1:${home.server.port} (the page: http://localhost:${port})`)
117
- // nothing grows unbound: every store of every repo it loads, and the
118
- // machine's, swept on boot and hourly (core/retention.ts)
119
- const only = onlyRepos()
120
- const sweeps = startSweeps({
121
- roots: () => house.repos.filter((r) => only == null || only.has(r.name)).map((r) => r.path), dir, printErr: io.printErr,
122
- // the rows every gate filed land here, one commit a day at most
123
- also: (now) => { for (const n of landMotherhome({ now })) io.printErr(n) },
124
- })
125
- // every kind's media into the machine index, up to the Space, purged when the owner turned it on
126
- const media = startMediaStore({ roots: () => house.repos.filter((r) => only == null || only.has(r.name)).map((r) => r.path), kinds: mediaKinds, print: io.print, printErr: io.printErr })
127
- const code = reloadOnOwnCode({ role: 'daemon', entry: fileURLToPath(import.meta.url), busy: () => hubs.busy(), before: () => { sweeps.stop(); media.stop(); home.stop() }, keep: true, io })
117
+ // the retention sweep (nothing grows unbound, core/retention.ts), the media store and the backup of the
118
+ // machine-only state, each a niced child process: never a job's body on this loop (daemon-jobs.ts). A daemon
119
+ // limited to some repos (SHIPKIT_DAEMON_ONLY) is a trial and runs none
120
+ const jobs = onlyRepos() == null ? startJobs({ cli: CLI, cwd: root, dir: join(dir, 'jobs'), log: childLog(dir, 'daemon'), printErr: io.printErr }) : null
121
+ // a job that holds the loop holds every page: each stall is said with the work that overlapped it
122
+ const stalls = loopWatch.start(io.printErr)
123
+ // its memory as a trend: a line only when it moved by a tenth, at most every 10 minutes
124
+ const memory = new MemoryWatch().start(io.print)
125
+ const code = reloadOnOwnCode({ role: 'daemon', entry: fileURLToPath(import.meta.url), busy: () => hubs.busy(), before: () => { stalls(); memory(); jobs?.stop(); home.stop() }, keep: true, io })
128
126
  io.print(` ${house.repos.length} repos, state in ${dir}, reloads on ${code.files} lib files`)
129
127
  for (const sig of ['SIGINT', 'SIGTERM'] as const)
130
128
  process.on(sig, () => {
131
129
  // the repo processes it started keep running: they are their
132
130
  // own process groups, and the next daemon adopts them
133
131
  code.stop()
134
- sweeps.stop()
135
- media.stop()
132
+ jobs?.stop()
136
133
  home.stop()
137
134
  process.exit(0)
138
135
  })
@@ -5,6 +5,7 @@
5
5
  // It never loads the repo config itself (pm-config.ts), and it runs from this
6
6
  // file, never from cli.ts (execPm): cli.ts loads every command, about 170 MB
7
7
  // against pm's own 20.
8
+ import { stampConsole } from '../core/log-stamp.ts'
8
9
  import { fileURLToPath } from 'url'
9
10
  import { daemonPort, homeDir, homePort, homeUp, homeUrl, pmPort, pmUp, WORKER_ENV } from './home-paths.ts'
10
11
  import { reloadOnOwnCode } from './lib-watch.ts'
@@ -129,7 +130,7 @@ export async function runPm(root: string, io: HomeIo, o: { port?: number } = {})
129
130
  if (reading) return
130
131
  reading = true
131
132
  void watch.poll()
132
- .then((n) => { if (n != null) pm.resources.sync(n.processes, n.errors) })
133
+ .then((n) => (n == null ? undefined : pm.resources.sync(n.processes, n.errors, n.archived)))
133
134
  .catch((e) => io.printErr(`WARN pm could not read the global processes again: ${(e as Error).message}`))
134
135
  .finally(() => { reading = false })
135
136
  }, PM_RESCAN_MS)
@@ -171,5 +172,6 @@ export async function runPm(root: string, io: HomeIo, o: { port?: number } = {})
171
172
  if (import.meta.main) {
172
173
  const i = process.argv.indexOf('--port')
173
174
  const port = i < 0 ? undefined : Number(process.argv[i + 1])
175
+ stampConsole()
174
176
  process.exitCode = await runPm(process.cwd(), { print: (l) => console.log(l), printErr: (l) => console.error(l) }, { port })
175
177
  }
@@ -3,19 +3,20 @@
3
3
  // (serve-web.ts) serves the page and proxies here, so a browser only ever
4
4
  // sees the web origin. A terminal client (via-hub.ts, attach.ts) talks here
5
5
  // directly, so a gate never depends on the web.
6
+ import { loopWatch } from '../core/loop-watch.ts'
6
7
  import { homeRoutes, TICK_MS, type HomeDeps } from './home-routes.ts'
7
8
 
8
9
  export function serveDaemon(d: HomeDeps & { daemonPort: number }) {
9
10
  const routes = homeRoutes(d)
10
- const fetch = async (req: Request, srv: Bun.Server<unknown>): Promise<Response> =>
11
- (await routes.handle(req, srv)) ?? new Response('not found', { status: 404 })
11
+ const fetch = (req: Request, srv: Bun.Server<unknown>): Promise<Response> =>
12
+ loopWatch.spanned(`${req.method} ${new URL(req.url).pathname}`, async () => (await routes.handle(req, srv)) ?? new Response('not found', { status: 404 }))
12
13
  const server = Bun.serve({ port: d.daemonPort, hostname: '127.0.0.1', fetch })
13
14
  let stopped = false
14
15
  let running = false
15
16
  const timer = setInterval(() => {
16
17
  if (running || stopped) return
17
18
  running = true
18
- void routes.tick().catch((e) => console.error(`WARN the daemon tick broke: ${(e as Error).message}`)).finally(() => { running = false })
19
+ void loopWatch.spanned('daemon tick', () => routes.tick()).catch((e) => console.error(`WARN the daemon tick broke: ${(e as Error).message}`)).finally(() => { running = false })
19
20
  }, TICK_MS)
20
21
  void routes.tick().catch(() => {})
21
22
  return {
@@ -12,11 +12,12 @@
12
12
  // request reaches it only once its Host is a loopback name or the tailnet name the house declares (serve.publicHost)
13
13
  import { sameOrigin } from '../serve/same-origin.ts'
14
14
  import { hubBase } from './home-paths.ts'
15
+ import { forwardPage, pagePath } from '../pages/forward.ts'
15
16
 
16
17
  /** the page routes: ONE app for the overview, the plan, and the hub page of
17
18
  * each known repo, which moves between them in place (home-st.ts) */
18
19
  export function pageRoutes<T>(names: string[], page: T): Record<string, T> {
19
- const out: Record<string, T> = { '/': page, '/inbox': page, '/planned': page, '/activity': page, '/archived': page, '/insights': page }
20
+ const out: Record<string, T> = { '/': page, '/inbox': page, '/planned': page, '/activity': page, '/archived': page, '/insights': page, '/identities': page }
20
21
  for (const n of names) out[`${hubBase(n)}/`] = page
21
22
  return out
22
23
  }
@@ -52,6 +53,8 @@ export const REPO_ANSWER_MS = 30_000
52
53
  /** how often the web asks the daemon's repo list once it has one, and while it has none */
53
54
  export const LIST_EVERY_MS = 30_000
54
55
  export const LIST_RETRY_MS = 1_000
56
+ /** how long the web keeps a repo's page urls before it asks the daemon again */
57
+ export const PAGE_URLS_MS = 10_000
55
58
 
56
59
  /** the home answers that can wait on git: the activity page's first read of a window, a repo's git page, and the insights page's read of every manifest */
57
60
  export const readsGit = (path: string): boolean => path === '/api/home/activity.json' || path === '/api/home/git.json' || path === '/api/home/insights.json'
@@ -112,6 +115,56 @@ const ZIPS = /^(text\/|application\/(javascript|json)|image\/svg)/
112
115
  /** the gzipped bodies kept, by path and etag: the bundle changes on an edit, not on a request */
113
116
  const ZIP_KEEP = 64
114
117
 
118
+ /** past this wait on the daemon, a GET the web holds a copy of answers that copy, the request still running */
119
+ export const STALE_AFTER_MS = 1_500
120
+ /** the copies kept: by count, and a copy past this size is never kept */
121
+ const LAST_GOOD_MAX = 400
122
+ const LAST_GOOD_BYTES = 2 * 1024 * 1024
123
+
124
+ /** why the web answered its copy: the daemon did not answer at all (a restart), or not yet (a held loop) */
125
+ export type StaleWhy = 'restarting' | 'slow'
126
+
127
+ /** the last good answer of each GET the page reads from the daemon: a JSON answer of status 200, by path, query and
128
+ * encoding, its body as the daemon sent it. A restart of the daemon or a held loop then answers the page from here
129
+ * (wiki tools/shipkit/home.md, How it stays up: a restart never blanks the page) */
130
+ export class LastGood {
131
+ private held = new Map<string, { body: Uint8Array<ArrayBuffer>; headers: [string, string][]; at: number }>()
132
+
133
+ /** the key of a request whose answer may be kept, null for any other */
134
+ key(req: Request, url: URL): string | null {
135
+ if (req.method !== 'GET' || streams(url.pathname) || toPm(url.pathname)) return null
136
+ return `${url.pathname}${url.search}|${/\bgzip\b/.test(req.headers.get('accept-encoding') ?? '') ? 'gz' : ''}`
137
+ }
138
+
139
+ has(key: string): boolean {
140
+ return this.held.has(key)
141
+ }
142
+
143
+ /** the daemon's answer, kept when it is a JSON 200 small enough: what the browser gets is the same bytes */
144
+ async keep(key: string, r: Response, headers: Headers): Promise<Response> {
145
+ if (r.status !== 200 || !/^application\/json\b/.test(headers.get('content-type') ?? '')) return new Response(r.body, { status: r.status, statusText: r.statusText, headers })
146
+ const body = new Uint8Array(await r.arrayBuffer())
147
+ if (body.length <= LAST_GOOD_BYTES) {
148
+ this.held.delete(key)
149
+ this.held.set(key, { body, headers: [...headers], at: Date.now() })
150
+ if (this.held.size > LAST_GOOD_MAX) this.held.delete(this.held.keys().next().value!)
151
+ }
152
+ return new Response(body, { status: 200, headers })
153
+ }
154
+
155
+ /** the copy, tagged with why it is served; a 304 when the browser holds it already */
156
+ answer(key: string, req: Request, why: StaleWhy): Response | null {
157
+ const h = this.held.get(key)
158
+ if (h == null) return null
159
+ const headers = new Headers(h.headers)
160
+ headers.set('x-shipkit-daemon', why)
161
+ headers.set('x-shipkit-daemon-at', String(h.at))
162
+ const tag = headers.get('etag')
163
+ if (tag != null && req.headers.get('if-none-match') === tag) return new Response(null, { status: 304, headers })
164
+ return new Response(h.body, { status: 200, headers })
165
+ }
166
+ }
167
+
115
168
  export type WebDeps<T> = {
116
169
  port: number
117
170
  /** the daemon's url, e.g. http://127.0.0.1:4798 */
@@ -126,6 +179,8 @@ export type WebDeps<T> = {
126
179
  listEveryMs?: number
127
180
  /** tailnet names allowed before the daemon names any (a test) */
128
181
  hosts?: string[]
182
+ /** in place of STALE_AFTER_MS (a test) */
183
+ staleAfterMs?: number
129
184
  }
130
185
 
131
186
  /** one browser socket to the page server's hot reload, piped to the same path there */
@@ -141,6 +196,8 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
141
196
  /** every page route, as the page server holds them */
142
197
  let pages = new Set(Object.keys(pageRoutes([], d.page)))
143
198
  const zips = new Map<string, Uint8Array<ArrayBuffer>>()
199
+ const lastGood = new LastGood()
200
+ const inflight = new Map<string, Promise<Response>>()
144
201
  /** the repo names the daemon knows and the tailnet names, or the reason it did not answer */
145
202
  async function names(): Promise<{ repos: string[]; hosts: string[] } | Error> {
146
203
  try {
@@ -153,8 +210,23 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
153
210
  }
154
211
  }
155
212
 
213
+ /** a GET with a copy never waits past STALE_AFTER_MS: past it, or with the daemon down, the copy answers and the
214
+ * request runs on, its answer the next copy */
156
215
  async function proxy(req: Request, url: URL, srv: Bun.Server<Pipe>): Promise<Response> {
157
216
  if (!sameOrigin(req)) return new Response('refused: a request that changes something must come from the home page', { status: 403 })
217
+ const key = lastGood.key(req, url)
218
+ if (key == null || !lastGood.has(key)) return forward(req, url, srv, key)
219
+ // one request a key at a time while the daemon is slow: a poll never piles up behind a held loop
220
+ if (inflight.has(key)) return lastGood.answer(key, req, 'slow') ?? forward(req, url, srv, key)
221
+ const live = forward(req, url, srv, key).finally(() => inflight.delete(key))
222
+ inflight.set(key, live)
223
+ const first = await Promise.race([live, Bun.sleep(d.staleAfterMs ?? STALE_AFTER_MS).then(() => null)])
224
+ if (first != null && first.headers.get('x-shipkit-daemon') !== 'down') return first
225
+ if (first == null) void live.then((r) => r.body?.cancel()).catch(() => {})
226
+ return lastGood.answer(key, req, first == null ? 'slow' : 'restarting') ?? (first ?? live)
227
+ }
228
+
229
+ async function forward(req: Request, url: URL, srv: Bun.Server<Pipe>, key: string | null): Promise<Response> {
158
230
  const headers = new Headers()
159
231
  req.headers.forEach((v, k) => { if (!DROP.has(k)) headers.set(k, v) })
160
232
  // a run or a live stream can stay silent for minutes
@@ -178,6 +250,7 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
178
250
  out.delete('content-length')
179
251
  out.delete('transfer-encoding')
180
252
  out.delete('connection')
253
+ if (key != null) return await lastGood.keep(key, r, out)
181
254
  return new Response(r.body, { status: r.status, statusText: r.statusText, headers: out })
182
255
  } catch (e) {
183
256
  if (timer != null) clearTimeout(timer)
@@ -188,6 +261,31 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
188
261
  }
189
262
  }
190
263
 
264
+ /** each repo's pages, by id: where its process serves it, asked of the daemon and kept a while */
265
+ const pageUrls = new Map<string, { at: number; pages: Map<string, { url: string; process?: string }> }>()
266
+ /** a repo page's request straight to the repo's process, the daemon left out of the path: a busy daemon held a page's
267
+ * html 2.5 s (wiki tools/shipkit/project-pages.md, The proxy). null: the daemon answers it (a redirect, an unknown page) */
268
+ async function toPageProcess(req: Request, repo: string, rest: string, srv: Bun.Server<Pipe>): Promise<Response | null> {
269
+ const at = pagePath(rest)
270
+ if (at == null || at.rest === null) return null
271
+ let known = pageUrls.get(repo)
272
+ if (known == null || Date.now() - known.at > PAGE_URLS_MS) {
273
+ try {
274
+ const r = await fetch(`${d.daemon}${hubBase(repo)}/api/pages.json`, { signal: AbortSignal.timeout(3_000) })
275
+ const j = (await r.json()) as { pages: { id: string; url: string; process?: string }[] }
276
+ known = { at: Date.now(), pages: new Map(j.pages.map((p) => [p.id, { url: p.url, ...(p.process ? { process: p.process } : {}) }])) }
277
+ pageUrls.set(repo, known)
278
+ } catch {
279
+ // the daemon restarts: the list it gave last still says where the page process serves
280
+ if (known == null) return null
281
+ }
282
+ }
283
+ const p = known.pages.get(at.id)
284
+ if (p == null) return null
285
+ if (!sameOrigin(req)) return new Response('refused: a request that changes something must come from the home page', { status: 403 })
286
+ return forwardPage(req, `${p.url}${at.rest}`, at.id, p.process, srv)
287
+ }
288
+
191
289
  // the page and its bundle, served by Bun's dev server on a loopback port of its own: it bundles the page, serves
192
290
  // its files under /_bun/ and drives the page's hot reload over /_bun/hmr
193
291
  const notFound = (): Response => new Response('not found: the home page is at /', { status: 404 })
@@ -239,6 +337,11 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
239
337
  if (path === '/_bun/hmr' && req.headers.get('upgrade')?.toLowerCase() === 'websocket')
240
338
  return srv.upgrade(req, { data: { path: `${path}${url.search}`, up: null, queue: [] } }) ? undefined : new Response('the hot reload socket did not open', { status: 400 })
241
339
  if (path === '/manifest.webmanifest') return Response.json(MANIFEST, { headers: { 'content-type': 'application/manifest+json', 'cache-control': 'no-cache' } })
340
+ const page = /^\/r\/([^/]+)(\/page\/.+)$/.exec(path)
341
+ if (page != null) {
342
+ const direct = await toPageProcess(req, decodeURIComponent(page[1]!), page[2]!, srv)
343
+ if (direct != null) return direct
344
+ }
242
345
  if (proxied(path)) return proxy(req, url, srv)
243
346
  if (pages.has(path) || path.startsWith('/_bun/')) return toPage(req, url)
244
347
  const bare = /^\/r\/([^/]+)$/.exec(path)