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
package/src/mv/mv-md.ts CHANGED
@@ -1,4 +1,4 @@
1
- // shipkit mv — rename an md page the AGILE way: one command moves the .md,
1
+ // shipkit mv — rename an md page the AGILE way: one command moves the .md (or makes it a `<topic>/index.md`),
2
2
  // its sibling asset dir and <name>.check.ts, then sweeps EVERY tracked text
3
3
  // file for refs (full path, docs-root-relative id, check filename). Dry by
4
4
  // default; --write applies; --commit adds one conventional commit (the
@@ -6,19 +6,20 @@
6
6
  // script it runs after the moves (repo-specific re-stamps). TS module moves
7
7
  // are a different concern (a TS-aware renamer owns import graphs).
8
8
  import { execSync } from 'child_process'
9
- import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'fs'
9
+ import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'fs'
10
10
  import { basename, dirname, join, relative } from 'path'
11
11
  import { isVendored } from '../core/vendored.ts'
12
12
  import { vendoredAround } from '../core/vendored-read.ts'
13
13
 
14
14
  export type MvIo = { print: (l: string) => void; printErr: (l: string) => void }
15
- export type MvOpts = { write?: boolean; commit?: boolean }
15
+ export type MvOpts = { write?: boolean; commit?: boolean; /** run the repo's `mv:after` script (a batch runs it once, at the end) */ after?: boolean }
16
16
 
17
17
  const sh = (cmd: string, cwd: string): string => execSync(cmd, { cwd }).toString()
18
18
 
19
- /** a page's own probe, named after the page: a check file, or a legacy
20
- * check script, which shares the suffix. */
21
- const SIBLING_SUFFIXES = ['.check.ts'] as const
19
+ /** a page's own files, named after the page: its check file (either suffix)
20
+ * and its unit file (a global process or a widget). Longest first, so the
21
+ * unit suffix never claims a check file. */
22
+ const SIBLING_SUFFIXES = ['.check.shipkit.ts', '.check.ts', '.shipkit.ts'] as const
22
23
 
23
24
  const posix = (p: string): string => p.replace(/\\/g, '/')
24
25
  /** a link points at a file. A directory that happens to share a prose word's
@@ -99,25 +100,31 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
99
100
  // refusing, so the probe lands one level too deep and the run still says
100
101
  // ok. Unreachable while every move was a same-dir rename, likely the
101
102
  // moment a move crosses directories
102
- const oldSiblingDir = oldRel.slice(0, -3)
103
- if (existsSync(join(root, oldSiblingDir)) && existsSync(join(root, newRel.slice(0, -3))))
104
- return die(`${newRel.slice(0, -3)}/ already exists, and ${oldSiblingDir}/ would be nested inside it rather than become it — move or merge it by hand first`)
103
+ // the index form: `<topic>/index.md` names a topic folder, so the page's
104
+ // asset dir BECOMES that folder instead of sitting beside the page
105
+ const indexForm = basename(newRel) === 'index.md' && basename(oldRel) !== 'index.md'
106
+ const oldBase = oldRel.slice(0, -3) // full path sans .md, the sibling dir
107
+ const newBase = indexForm ? dirOf(newRel) : newRel.slice(0, -3)
108
+ // in place: the page moves into its own asset dir, which already is the topic folder
109
+ const inPlace = indexForm && newBase === oldBase
110
+ if (indexForm && !inPlace && existsSync(join(root, newBase))) return die(`${newBase}/ already exists: a topic folder is created by its move, never merged into`)
111
+ if (!indexForm && existsSync(join(root, oldBase)) && existsSync(join(root, newBase)))
112
+ return die(`${newBase}/ already exists, and ${oldBase}/ would be nested inside it rather than become it: move or merge it by hand first`)
105
113
 
106
114
  const write = o.write === true || o.commit === true
107
115
  const oldName = basename(oldRel, '.md')
108
- const newName = basename(newRel, '.md')
109
- const oldBase = oldRel.slice(0, -3) // full path sans .md — the sibling dir
110
- const newBase = newRel.slice(0, -3)
116
+ const newName = basename(newBase)
111
117
  // docs-root-relative id: refs inside a wiki usually omit the top dir
112
118
  // (`build/state`, not `wiki/build/state`) — sweep both forms
113
119
  const tail = (p: string): string | null => { const seg = p.split('/'); return seg.length >= 3 ? seg.slice(1).join('/') : null }
114
120
  const oldId = tail(oldBase)
115
121
  const newId = tail(newBase)
122
+ const newPageId = tail(newRel.slice(0, -3))
116
123
 
117
124
  // longest-first so `wiki/x/state.md` beats `x/state` beats bare tokens
118
125
  const pairs: [string, string][] = [
119
- [`${oldBase}.md`, `${newBase}.md`],
120
- ...(oldId != null ? [[`${oldId}.md`, `${newId}.md`] as [string, string]] : []),
126
+ [`${oldBase}.md`, newRel],
127
+ ...(oldId != null ? [[`${oldId}.md`, `${newPageId}.md`] as [string, string]] : []),
121
128
  // probe file is named after its page; DIR-qualified so another
122
129
  // page's same-named check.ts in a different dir never gets rewritten
123
130
  ...SIBLING_SUFFIXES.flatMap((sfx): [string, string][] => [
@@ -142,7 +149,9 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
142
149
  // whole subtree, and the probe is renamed after the page, so its own entry
143
150
  // is written LAST and wins over the subtree rule.
144
151
  const moves = new Map<string, string>([[oldRel, newRel]])
145
- if (existsSync(join(root, oldBase))) {
152
+ // an asset dir is one git tracks: an empty leftover dir is not, and git mv refuses it
153
+ const hasDir = tracked.some((f) => f.startsWith(`${oldBase}/`))
154
+ if (hasDir) {
146
155
  moves.set(oldBase, newBase)
147
156
  for (const f of tracked) if (f.startsWith(`${oldBase}/`)) moves.set(f, `${newBase}${f.slice(oldBase.length)}`)
148
157
  for (const sfx of SIBLING_SUFFIXES) {
@@ -171,10 +180,15 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
171
180
  // moves AFTER the sweep (the sweep rewrote files at their old paths).
172
181
  // git mv refuses into a directory that is not there yet, and a move
173
182
  // between directories is the case where it usually is not
183
+ // the index form moves the asset dir FIRST, so it becomes the topic
184
+ // folder; created first, git mv would nest it one level down
185
+ if (!hasDir && existsSync(join(root, oldBase)) && readdirSync(join(root, oldBase)).every((e) => e === '.DS_Store')) rmSync(join(root, oldBase), { recursive: true })
186
+ mkdirSync(join(root, dirOf(hasDir ? newBase : newRel)), { recursive: true })
187
+ if (indexForm && hasDir && !inPlace) sh(`git mv ${JSON.stringify(oldBase)} ${JSON.stringify(newBase)}`, root)
174
188
  mkdirSync(join(root, dirOf(newRel)), { recursive: true })
175
189
  sh(`git mv ${JSON.stringify(oldRel)} ${JSON.stringify(newRel)}`, root)
176
- if (existsSync(join(root, oldBase))) {
177
- sh(`git mv ${JSON.stringify(oldBase)} ${JSON.stringify(newBase)}`, root)
190
+ if (hasDir) {
191
+ if (!indexForm) sh(`git mv ${JSON.stringify(oldBase)} ${JSON.stringify(newBase)}`, root)
178
192
  // the probe is named after its page, so it only moves when the NAME
179
193
  // changed. A move that keeps the name and changes the directory takes
180
194
  // the probe along inside the dir, and `git mv X X` is a fatal
@@ -184,11 +198,7 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
184
198
  }
185
199
  }
186
200
 
187
- // repo-specific re-stamps (e.g. wiki depth frontmatter) — loud on failure
188
- const pkg = existsSync(join(root, 'package.json')) ? (JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as { scripts?: Record<string, string> }) : {}
189
- if (pkg.scripts?.['mv:after'] != null) {
190
- try { execSync('bun run mv:after', { cwd: root, stdio: 'inherit' }) } catch { return die('mv:after failed, fix before committing') }
191
- }
201
+ if (o.after !== false && !runAfter(root)) return die('mv:after failed, fix before committing')
192
202
  if (o.commit === true) {
193
203
  sh('git add -A', root)
194
204
  try {
@@ -198,3 +208,34 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
198
208
  io.print(`ok: ${oldBase} → ${newBase}${o.commit === true ? ' (committed)' : ''}`)
199
209
  return 0
200
210
  }
211
+
212
+ /** the repo's own follow up to a move (`mv:after` in package.json), loud on failure */
213
+ function runAfter(root: string): boolean {
214
+ const pkg = existsSync(join(root, 'package.json')) ? (JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as { scripts?: Record<string, string> }) : {}
215
+ if (pkg.scripts?.['mv:after'] == null) return true
216
+ try { execSync('bun run mv:after', { cwd: root, stdio: 'inherit' }); return true } catch { return false }
217
+ }
218
+
219
+ /** a move map: one `<old> <new>` pair per line, `#` comments and blank lines skipped */
220
+ export function parseMoveMap(text: string): [string, string][] {
221
+ return text.split('\n').map((l) => l.replace(/#.*/, '').trim()).filter(Boolean).map((l, i) => {
222
+ const parts = l.split(/\s+/)
223
+ if (parts.length !== 2) throw new Error(`move map line ${i + 1}: want "<old> <new>", got "${l}"`)
224
+ return [parts[0]!, parts[1]!]
225
+ })
226
+ }
227
+
228
+ /** many pages in one run, in map order: each move sweeps the tree the previous
229
+ * one left, and `mv:after` runs once at the end. A dry run shows each move
230
+ * against the CURRENT tree, so a later pair that depends on an earlier one
231
+ * only reports true once applied. Stops at the first failure. */
232
+ export function movePages(root: string, pairs: [string, string][], io: MvIo, o: MvOpts = {}): number {
233
+ if (o.commit === true) { io.printErr('FAIL: a move map applies with --write, then you commit what you own'); return 1 }
234
+ for (const [from, to] of pairs) {
235
+ const code = movePage(root, from, to, io, { ...o, after: false })
236
+ if (code !== 0) return code
237
+ }
238
+ if (o.write === true && !runAfter(root)) { io.printErr('FAIL: mv:after failed, fix before committing'); return 1 }
239
+ io.print(`ok: ${pairs.length} move(s)${o.write === true ? '' : ' (dry run)'}`)
240
+ return 0
241
+ }
@@ -0,0 +1,35 @@
1
+ // a repo page's request sent on to the repo's process and streamed back (wiki tools/shipkit/project-pages.md, The
2
+ // proxy): the daemon's hub route and the web's direct path both go through here. Light on purpose: the web imports it
3
+ /** what names the browser or this hop: the page's process sees a plain local client */
4
+ const DROP = new Set(['host', 'origin', 'referer', 'sec-fetch-site', 'sec-fetch-mode', 'sec-fetch-dest', 'connection', 'keep-alive', 'content-length'])
5
+ const NO_STORE = { 'cache-control': 'no-store' }
6
+
7
+ export const PAGE_DOWN_HEADER = 'x-shipkit-page'
8
+
9
+ /** a page's request, sent on to its process and streamed back: `target` the page's url plus the rest. The process down
10
+ * answers 502 with PAGE_DOWN_HEADER, which the hub's frame reads as « start it » */
11
+ export async function forwardPage(req: Request, target: string, id: string, process: string | undefined, srv: { timeout: (req: Request, seconds: number) => void } | undefined): Promise<Response> {
12
+ const headers = new Headers()
13
+ req.headers.forEach((v, k) => { if (!DROP.has(k)) headers.set(k, v) })
14
+ // a live channel stays silent between reloads: never cut
15
+ srv?.timeout(req, 0)
16
+ const body = req.method === 'GET' || req.method === 'HEAD' ? undefined : await req.arrayBuffer()
17
+ try {
18
+ const r = await fetch(`${target}${new URL(req.url).search}`, { method: req.method, headers, body, redirect: 'manual', decompress: false } as RequestInit)
19
+ const out = new Headers(r.headers)
20
+ out.delete('content-length')
21
+ out.delete('transfer-encoding')
22
+ out.delete('connection')
23
+ return new Response(r.body, { status: r.status, statusText: r.statusText, headers: out })
24
+ } catch (e) {
25
+ const text = `the page ${id} does not answer on ${target} (${(e as Error).message})${process ? `: sk gp start ${process}` : ''}`
26
+ return new Response(text, { status: 502, headers: { 'content-type': 'text/plain; charset=utf-8', [PAGE_DOWN_HEADER]: 'down', ...NO_STORE } })
27
+ }
28
+ }
29
+
30
+ /** `/page/<id>/<rest>` of a hub: the page and the rest of its path, or null; a bare `/page/<id>` has rest null */
31
+ export function pagePath(path: string): { id: string; rest: string | null } | null {
32
+ const m = /^\/page\/([a-z][a-z0-9-]*)(\/.*)?$/.exec(path)
33
+ return m == null ? null : { id: m[1]!, rest: m[2] === undefined ? null : m[2].slice(1) }
34
+ }
35
+
@@ -0,0 +1,118 @@
1
+ // the page side of a repo page's frame (wiki tools/shipkit/project-pages.md, The frame contract): the one module a
2
+ // repo's page bundles to live in the hub. No framework, no hub code beyond the keys table. Framed, it speaks the
3
+ // `{ shipkit: <verb> }` messages on its origin; alone at its own url, it keeps the keys in its own address, so the
4
+ // page works the same either way
5
+ import { pageKey, pageLetterKey, sectionKey } from '../serve/hub-app/keys.ts'
6
+
7
+ export type FrameTheme = 'dark' | 'light'
8
+ export type FrameBadge = { count: number; tone?: 'red' | 'warn' | null; title?: string }
9
+
10
+ export interface FrameOpts {
11
+ /** the page's state as url keys: from the hub's address, or the page's own; the page applies them */
12
+ onKeys(keys: string): void
13
+ onTheme?(theme: FrameTheme): void
14
+ /** the identity the repo speaks as (its `speaksAs`, else the machine's default), null with none; alone: never called */
15
+ onIdentity?(identity: string | null): void
16
+ /** shown (true) or hidden (false): a page stops its sound */
17
+ onFocus?(on: boolean): void
18
+ /** a relative path of the page's process sending `reload` when its bundle moved (an EventSource). Open only while
19
+ * the page shows: a browser holds six connections to one origin, and the hub needs them. On each open it carries
20
+ * `?build=<the page's module script>`, so the process can say at once that the page runs an older build */
21
+ live?: string
22
+ /** a plain message of the live channel (no event name): the page's own events, its data as sent */
23
+ onLive?(data: string): void
24
+ }
25
+
26
+ export interface PageFrame {
27
+ /** in the hub's frame, or alone at its url */
28
+ readonly framed: boolean
29
+ /** the page's state moved: the hub's address follows in place */
30
+ setKeys(keys: string): void
31
+ setTitle(title: string, badge?: FrameBadge | null): void
32
+ /** another hub page, by its address (`#page:review:<id>`) */
33
+ open(hash: string): void
34
+ stop(): void
35
+ }
36
+
37
+ type KeyLike = Pick<KeyboardEvent, 'key' | 'code' | 'altKey' | 'shiftKey' | 'metaKey' | 'ctrlKey'>
38
+
39
+ /** a key the hub owns: its ⌥ sections, a page's ⌥⇧ letter, the home's ⌘ keys */
40
+ export const hubOwns = (e: KeyLike): boolean => sectionKey(e) != null || pageLetterKey(e) != null || pageKey(e) != null
41
+
42
+ export function frameClient(o: FrameOpts): PageFrame {
43
+ const framed = typeof window !== 'undefined' && window.parent !== window
44
+ const origin = location.origin
45
+ const up = (m: Record<string, unknown>): void => { if (framed) window.parent.postMessage({ ...m }, origin) }
46
+ let last = framed ? '' : location.search.replace(/^\?/, '')
47
+ let live: EventSource | null = null
48
+ const openLive = (): void => {
49
+ if (o.live == null || live != null) return
50
+ const build = document.querySelector('script[type="module"][src]')?.getAttribute('src') ?? ''
51
+ live = new EventSource(`${o.live}?build=${encodeURIComponent(build)}`)
52
+ live.addEventListener('reload', () => location.reload())
53
+ if (o.onLive != null) live.onmessage = (e: MessageEvent<string>) => o.onLive?.(e.data)
54
+ }
55
+ const closeLive = (): void => {
56
+ live?.close()
57
+ live = null
58
+ }
59
+
60
+ const onMessage = (e: MessageEvent): void => {
61
+ if (e.source !== window.parent || e.origin !== origin) return
62
+ const m = (e.data ?? {}) as { shipkit?: unknown; keys?: unknown; theme?: unknown; identity?: unknown; on?: unknown }
63
+ if ((m.shipkit === 'hello' || m.shipkit === 'keys') && typeof m.keys === 'string') {
64
+ last = m.keys
65
+ o.onKeys(m.keys)
66
+ }
67
+ if ((m.shipkit === 'hello' || m.shipkit === 'theme') && (m.theme === 'dark' || m.theme === 'light')) o.onTheme?.(m.theme)
68
+ if ((m.shipkit === 'hello' || m.shipkit === 'identity') && (typeof m.identity === 'string' || m.identity === null)) o.onIdentity?.(m.identity)
69
+ if ((m.shipkit === 'hello' || m.shipkit === 'focus') && typeof m.on === 'boolean') {
70
+ if (m.on) openLive()
71
+ else closeLive()
72
+ o.onFocus?.(m.on)
73
+ }
74
+ }
75
+ // after the page's own handlers: a key it took stays its own
76
+ const onKey = (e: KeyboardEvent): void => {
77
+ if (e.defaultPrevented || !hubOwns(e)) return
78
+ e.preventDefault()
79
+ up({ shipkit: 'key', key: e.key, code: e.code, altKey: e.altKey, shiftKey: e.shiftKey, metaKey: e.metaKey, ctrlKey: e.ctrlKey })
80
+ }
81
+ const mq = framed ? null : window.matchMedia('(prefers-color-scheme: dark)')
82
+ const onScheme = (e: MediaQueryListEvent): void => o.onTheme?.(e.matches ? 'dark' : 'light')
83
+ if (framed) {
84
+ window.addEventListener('message', onMessage)
85
+ window.addEventListener('keydown', onKey)
86
+ up({ shipkit: 'ready' })
87
+ } else {
88
+ openLive()
89
+ o.onKeys(last)
90
+ if (mq != null) {
91
+ o.onTheme?.(mq.matches ? 'dark' : 'light')
92
+ mq.addEventListener('change', onScheme)
93
+ }
94
+ }
95
+
96
+ return {
97
+ framed,
98
+ setKeys(keys) {
99
+ if (keys === last) return
100
+ last = keys
101
+ if (framed) up({ shipkit: 'keys', keys })
102
+ else history.replaceState(history.state, '', `${location.pathname}${keys ? `?${keys}` : ''}${location.hash}`)
103
+ },
104
+ setTitle(title, badge) {
105
+ if (framed) up({ shipkit: 'title', title, ...(badge === undefined ? {} : { badge }) })
106
+ else document.title = title
107
+ },
108
+ open(hash) {
109
+ up({ shipkit: 'open', hash })
110
+ },
111
+ stop() {
112
+ window.removeEventListener('message', onMessage)
113
+ window.removeEventListener('keydown', onKey)
114
+ mq?.removeEventListener('change', onScheme)
115
+ closeLive()
116
+ },
117
+ }
118
+ }
@@ -0,0 +1,29 @@
1
+ // a repo's own pages on the hub (wiki tools/shipkit/project-pages.md): their list, and the proxy that serves each one
2
+ // from the repo's process under the hub's origin, `/page/<id>/<rest>` to `<url><rest>`, streamed both ways. The one
3
+ // constraint a reader breaks first: a page must use relative paths, an absolute one reaches the hub, never the page
4
+ import { forwardPage, pagePath } from './forward.ts'
5
+ import { loadPages, type PageRow } from './unit.ts'
6
+
7
+ const NO_STORE = { 'cache-control': 'no-store' }
8
+
9
+ /** the repo's pages, or why they do not load */
10
+ async function list(root: string): Promise<{ pages: PageRow[]; problem: string | null }> {
11
+ try {
12
+ return { pages: await loadPages(root), problem: null }
13
+ } catch (e) {
14
+ return { pages: [], problem: (e as Error).message }
15
+ }
16
+ }
17
+
18
+ /** the pages' routes of the repo at `root`; null for any other path */
19
+ export async function pagesRoutes(root: string, req: Request, path: string, srv?: Bun.Server<unknown>): Promise<Response | null> {
20
+ if (path === '/api/pages.json') return Response.json(await list(root), { headers: NO_STORE })
21
+ const at = pagePath(path)
22
+ if (at == null) return null
23
+ // the page's own relative paths resolve from its folder
24
+ if (at.rest === null) return new Response(null, { status: 308, headers: { location: `${at.id}/${new URL(req.url).search}` } })
25
+ const { pages, problem } = await list(root)
26
+ const p = pages.find((x) => x.id === at.id)
27
+ if (p == null) return new Response(problem ?? `no page ${at.id} in this repo: a page({...}) unit declares one`, { status: 404, headers: NO_STORE })
28
+ return forwardPage(req, `${p.url}${at.rest}`, p.id, p.process, srv)
29
+ }
@@ -0,0 +1,92 @@
1
+ // a repo's own pages in its hub (wiki tools/shipkit/project-pages.md): a `page({...})` unit of any `<name>.shipkit.ts`,
2
+ // one page or an array of them as the default export. Every unit file imports this module, so it stays light: the
3
+ // daemon reads the declarations and never the page's code
4
+ import { existsSync } from 'node:fs'
5
+ import { relative } from 'node:path'
6
+ import { importFresh } from '../core/discover-checks.ts'
7
+ import { unitFilesDeclaring } from '../core/unit-files.ts'
8
+
9
+ export interface PageDef {
10
+ /** the address part, `#page:<repo>/<id>`: a lowercase word */
11
+ id: string
12
+ /** the row's words */
13
+ title: string
14
+ /** a 20 unit stroked svg path, drawn as the hub's own icons */
15
+ icon: string
16
+ /** where the repo's process serves the page: a loopback http url ending in `/` */
17
+ url: string
18
+ /** the global process that serves it: the down page's start button */
19
+ process?: string
20
+ /** a path relative to `url` answering `{ count, tone?, title? }` */
21
+ badge?: string
22
+ /** ⌥⇧ + this letter opens it; else the first free letter of the title */
23
+ key?: string
24
+ /** it draws in WebGL: a hidden frame of it holds a context and its GPU memory, so fewer stay kept */
25
+ gl?: boolean
26
+ }
27
+
28
+ export type PageUnit = PageDef & { kind: 'page' }
29
+
30
+ /** a page as the hub's list serves it: its key settled, the file that declares it */
31
+ export type PageRow = Omit<PageDef, 'key'> & { key: string; file: string }
32
+
33
+ const WORD = /^[a-z][a-z0-9-]*$/
34
+ const LOOPBACK = /^http:\/\/(127\.0\.0\.1|localhost)(:\d+)?\/([^?#]*\/)?$/
35
+
36
+ /** why a page cannot be read, or null */
37
+ export function pageProblem(d: PageDef): string | null {
38
+ if (typeof d.id !== 'string' || !WORD.test(d.id)) return `page: id '${String(d.id)}' is a lowercase word`
39
+ if (typeof d.title !== 'string' || d.title.trim() === '') return `page ${d.id}: title is a text`
40
+ if (typeof d.icon !== 'string' || !/^M[\d\s.,MmLlHhVvCcSsQqTtAaZz-]+$/.test(d.icon)) return `page ${d.id}: icon is an svg path, starting with M`
41
+ if (typeof d.url !== 'string' || !LOOPBACK.test(d.url)) return `page ${d.id}: url '${String(d.url)}' is a loopback http url ending in /`
42
+ if (d.process !== undefined && (typeof d.process !== 'string' || !/^[a-z0-9][a-z0-9-]*$/.test(d.process))) return `page ${d.id}: process '${String(d.process)}' is a global process id`
43
+ if (d.badge !== undefined && (typeof d.badge !== 'string' || d.badge.startsWith('/') || d.badge.includes('..') || d.badge === '')) return `page ${d.id}: badge '${String(d.badge)}' is a path relative to url`
44
+ if (d.key !== undefined && (typeof d.key !== 'string' || !/^[A-Z]$/.test(d.key))) return `page ${d.id}: key '${String(d.key)}' is one capital letter`
45
+ if (d.gl !== undefined && typeof d.gl !== 'boolean') return `page ${d.id}: gl is true or false`
46
+ return null
47
+ }
48
+
49
+ export function page(d: PageDef): PageUnit {
50
+ const why = pageProblem(d)
51
+ if (why !== null) throw new Error(why)
52
+ return { ...d, kind: 'page' }
53
+ }
54
+
55
+ /** each page's letter: its own, else the first letter of its title no earlier page took; null past 26 */
56
+ export function settleKeys(defs: readonly PageDef[]): (string | null)[] {
57
+ const taken = new Set(defs.flatMap((d) => (d.key === undefined ? [] : [d.key])))
58
+ return defs.map((d) => {
59
+ if (d.key !== undefined) return d.key
60
+ const letters = [...d.title.toUpperCase().normalize('NFD').replace(/[^A-Z]/g, ''), ...'ABCDEFGHIJKLMNOPQRSTUVWXYZ']
61
+ const free = letters.find((l) => !taken.has(l)) ?? null
62
+ if (free !== null) taken.add(free)
63
+ return free
64
+ })
65
+ }
66
+
67
+ const isPage = (u: unknown): u is PageUnit => typeof u === 'object' && u !== null && (u as { kind?: unknown }).kind === 'page'
68
+
69
+ /** the repo's pages in declaration order, files sorted; a wrong unit, a twice used id or key throws naming the files */
70
+ export async function loadPages(root: string): Promise<PageRow[]> {
71
+ if (!existsSync(root)) return []
72
+ const found: { file: string; def: PageDef }[] = []
73
+ for (const f of [...unitFilesDeclaring(root, 'page')].sort()) {
74
+ const d = (await importFresh(f)) as unknown
75
+ const file = relative(root, f)
76
+ for (const u of Array.isArray(d) ? d : [d]) {
77
+ if (!isPage(u)) continue
78
+ const why = pageProblem(u)
79
+ if (why !== null) throw new Error(`${file}: ${why}`)
80
+ const twin = found.find((x) => x.def.id === u.id || (u.key !== undefined && x.def.key === u.key))
81
+ if (twin) throw new Error(`two pages share ${twin.def.id === u.id ? `the id ${u.id}` : `the key ${u.key}`}: ${twin.file} and ${file}`)
82
+ found.push({ file, def: u })
83
+ }
84
+ }
85
+ const keys = settleKeys(found.map((x) => x.def))
86
+ return found.flatMap((x, i) => {
87
+ const key = keys[i]
88
+ if (key == null) return []
89
+ const d = x.def
90
+ return [{ id: d.id, title: d.title, icon: d.icon, url: d.url, ...(d.process ? { process: d.process } : {}), ...(d.badge ? { badge: d.badge } : {}), ...(d.gl === true ? { gl: true } : {}), key, file: x.file }]
91
+ })
92
+ }
@@ -17,6 +17,7 @@
17
17
  import { availableParallelism, loadavg } from 'os'
18
18
  import { CATCH_UP_BEAT_MS, resumeCatchUp, type CatchUpStore } from './catch-up.ts'
19
19
  import { nextDue, resolveCadence, resolveWhenInactive, stablePoint, type EveryValue, type LastResult, type PlanDecl } from './cadence.ts'
20
+ import { yieldLoop } from '../core/loop-watch.ts'
20
21
 
21
22
  export type PlanReason = 'changed' | 'scheduled' | 'late' | 'asked'
22
23
 
@@ -377,6 +378,17 @@ export class Planner {
377
378
  return out
378
379
  }
379
380
 
381
+ /** the last results of every repo whose look is due, read one repo at a time with the loop given back between
382
+ * two, so the sync reads of the run records never stand together (wiki tools/shipkit/home.md, Nothing heavy on
383
+ * the daemon's loop). The host calls it before `tick`, which then finds them read */
384
+ async refresh(): Promise<void> {
385
+ for (const r of [...this.repos.values()]) {
386
+ if (this.now() - r.lastRead < LAST_EVERY_MS) continue
387
+ await yieldLoop()
388
+ if (this.repos.get(r.src.repo) === r) this.readLast(r)
389
+ }
390
+ }
391
+
380
392
  /** a batch is in flight */
381
393
  busy(): boolean {
382
394
  return this.running != null
@@ -16,6 +16,7 @@ import { planned } from '../core/runs.ts'
16
16
  import { ONCE, type LastResult } from './cadence.ts'
17
17
  import { openDb } from '../ledger/db.ts'
18
18
  import { readLastResults } from '../ledger/run-log.ts'
19
+ import { recordFileStamp } from '../ledger/record-kept.ts'
19
20
  import { gateBinary } from '../ledger/toolchain-identity.ts'
20
21
  import { populationOf } from '../problems/problem-line.ts'
21
22
  import { movedSince } from '../serve/tracked-watch.ts'
@@ -72,7 +73,10 @@ export function readLastCosts(path: string): Record<string, { at: number; ms: nu
72
73
  if (opened == null) return {}
73
74
  const out: Record<string, { at: number; ms: number }> = {}
74
75
  try {
75
- const rows = opened.db.query(`select id, max(at) as at, ms from runs where replayed = 0 group by id`).all() as { id: string; at: number; ms: number }[]
76
+ // per check id off the (id, at) index: a group by over every row held the daemon's loop on a large record
77
+ const rows = opened.db.query(`select r.id as id, r.at as at, r.ms as ms
78
+ from (select d.id as id, (select r2.rowid from runs r2 where r2.id = d.id and r2.replayed = 0 order by r2.at desc limit 1) as rid from (select distinct id from runs) d) x
79
+ join runs r on r.rowid = x.rid`).all() as { id: string; at: number; ms: number }[]
76
80
  for (const r of rows) out[r.id] = { at: Number(r.at), ms: Number(r.ms) }
77
81
  } catch {
78
82
  return {}
@@ -122,6 +126,16 @@ export function repoSource(d: RepoSourceDeps): PlanSource {
122
126
  const moved = new Set<string>()
123
127
  const facts = new Map<string, string>()
124
128
  const cache = (): WorldCache => ({ db: answersDb(d.root), ns: d.config().name, now: Date.now })
129
+ /** the three reads of the run record the plan looks at every LAST_EVERY_MS, read again only once the record moved:
130
+ * over a large record they are a sync read of every run (wiki tools/shipkit/home.md, Nothing heavy on the daemon's
131
+ * loop) */
132
+ let held: { stamp: string; results: Record<string, LastResult>; costs: Record<string, { at: number; ms: number }>; gatedAt: number | null } | null = null
133
+ const readRecord = (): NonNullable<typeof held> => {
134
+ if (d.record === '') return { stamp: '', results: {}, costs: {}, gatedAt: null }
135
+ const stamp = recordFileStamp(d.record)
136
+ if (held?.stamp !== stamp) held = { stamp, results: readLastResults(d.record), costs: readLastCosts(d.record), gatedAt: lastStarted(d.record, { asked: true }) }
137
+ return held
138
+ }
125
139
  return {
126
140
  repo: d.repo,
127
141
  checks: async () => {
@@ -136,18 +150,18 @@ export function repoSource(d: RepoSourceDeps): PlanSource {
136
150
  return rows.map(planCheckOf)
137
151
  },
138
152
  last: () => {
139
- const all: Record<string, LastResult> = d.record === '' ? {} : readLastResults(d.record)
153
+ const read = readRecord()
154
+ const all: Record<string, LastResult> = { ...read.results }
140
155
  // a fact with no answer runs; one whose probe could not answer
141
156
  // retries on a backoff from its skip, never at each boot
142
157
  for (const id of unknown) {
143
158
  if (all[id]?.status === 'skip') all[id] = { ...all[id]!, unknown: true }
144
159
  else delete all[id]
145
160
  }
146
- const costs = d.record === '' ? {} : readLastCosts(d.record)
147
- for (const [id, cost] of Object.entries(costs)) if (all[id] != null) all[id] = { ...all[id]!, cost }
161
+ for (const [id, cost] of Object.entries(read.costs)) if (all[id] != null) all[id] = { ...all[id]!, cost }
148
162
  return all
149
163
  },
150
- gatedAt: () => (d.record === '' ? null : lastStarted(d.record, { asked: true })),
164
+ gatedAt: () => readRecord().gatedAt,
151
165
  changed: async () => {
152
166
  const decls = rows.map((r) => r.decl)
153
167
  if (decls.length === 0) return []
@@ -85,7 +85,7 @@ export type RawEntry = {
85
85
  /** queue-operation entries only */
86
86
  operation?: unknown
87
87
  content?: unknown
88
- message?: { role?: unknown; content?: unknown }
88
+ message?: { role?: unknown; content?: unknown; id?: unknown; model?: unknown; usage?: { input_tokens?: unknown; output_tokens?: unknown; cache_read_input_tokens?: unknown; cache_creation_input_tokens?: unknown } }
89
89
  toolUseResult?: unknown
90
90
  /** on a tool_result entry: who allowed the call (`config`, `user_temporary`, …) */
91
91
  permissionDecision?: { source?: unknown; reasonType?: unknown }
@@ -179,9 +179,41 @@ export function detailOf(name: string, input: unknown): string {
179
179
  if (name === 'Skill') return clip(str('skill'))
180
180
  if (name === 'WebFetch') return clip(str('url'))
181
181
  if (name === 'Monitor' || name === 'TaskOutput' || name === 'TaskStop') return clip(str('description') || str('task_id'))
182
+ if (name === 'Read' || name === 'Edit' || name === 'Write' || name === 'MultiEdit' || name === 'NotebookEdit') return clip(str('file_path') || str('notebook_path'))
183
+ if (name === 'Grep' || name === 'Glob') return clip([str('pattern'), str('path')].filter((s) => s !== '').join(' '))
182
184
  return ''
183
185
  }
184
186
 
187
+ /** one transcript line as an entry, or null for a line no reader wants (the
188
+ * same skip as readTranscriptLine): for a reader that needs more than events */
189
+ export function parseEntry(line: string): RawEntry | null {
190
+ if (line.startsWith('{"type":"') && !KEPT_TYPE_PREFIXES.some((p) => line.startsWith(p))) return null
191
+ try {
192
+ const parsed: unknown = JSON.parse(line)
193
+ return parsed != null && typeof parsed === 'object' ? (parsed as RawEntry) : null
194
+ } catch {
195
+ return null
196
+ }
197
+ }
198
+
199
+ export type Usage = { messageId: string; input: number; output: number; cacheRead: number; cacheWrite: number; model: string }
200
+
201
+ /** the token usage an assistant entry carries. The harness writes one entry per
202
+ * content block, each with the same message id and usage, so a reader counts
203
+ * each message id once */
204
+ export function usageOf(entry: RawEntry): Usage | null {
205
+ if (entry.type !== 'assistant') return null
206
+ const m = entry.message
207
+ const u = m?.usage
208
+ if (m == null || u == null || typeof m.id !== 'string') return null
209
+ const n = (v: unknown): number => (typeof v === 'number' ? v : 0)
210
+ return { messageId: m.id, input: n(u.input_tokens), output: n(u.output_tokens), cacheRead: n(u.cache_read_input_tokens), cacheWrite: n(u.cache_creation_input_tokens), model: typeof m.model === 'string' ? m.model : '' }
211
+ }
212
+
213
+ /** the text of a user entry, typed or not (a sub-agent's task prompt is a
214
+ * sidechain entry nobody typed), reminders stripped */
215
+ export const userTextOf = (entry: RawEntry): string | null => (entry.type === 'user' && entry.message?.role === 'user' ? userText(entry) : null)
216
+
185
217
  const resultText = (content: unknown): string => {
186
218
  if (typeof content === 'string') return content
187
219
  if (Array.isArray(content)) {
@@ -199,15 +231,8 @@ const KEPT_TYPE_PREFIXES = ['{"type":"user"', '{"type":"assistant"', '{"type":"q
199
231
  /** every event one transcript line holds; [] for anything else, a truncated
200
232
  * tail line of a live session included */
201
233
  export function readTranscriptLine(line: string): TranscriptEvent[] {
202
- if (line.startsWith('{"type":"') && !KEPT_TYPE_PREFIXES.some((p) => line.startsWith(p))) return []
203
- let parsed: unknown
204
- try {
205
- parsed = JSON.parse(line)
206
- } catch {
207
- return []
208
- }
209
- if (parsed == null || typeof parsed !== 'object') return []
210
- return eventsOf(parsed as RawEntry)
234
+ const entry = parseEntry(line)
235
+ return entry == null ? [] : eventsOf(entry)
211
236
  }
212
237
 
213
238
  export function eventsOf(entry: RawEntry): TranscriptEvent[] {