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,9 +1,10 @@
1
- // THE TRACED AUDIT: which gitignored paths a task reads that its key cannot
2
- // see. A task's key covers the tracked tree and the paths `ignoredInputs`
3
- // names; a generated type or a local fixture it reads outside those is a
4
- // stale green waiting for its first edit. Each gate task runs once under the
5
- // tracer (trace/tracer.ts), and the ignored paths it touched that no key
6
- // covers become that task's proposals: the keys read them at once
1
+ // THE TRACED AUDIT: which paths a task reads that its key cannot see. An
2
+ // undeclared task's key covers the tracked tree, a declared one its list
3
+ // (a unit's `test:<unit>` is its dir and siblings), and each adds the paths
4
+ // `ignoredInputs` names; a generated type, a local fixture, or a doc a unit
5
+ // test reads outside its dir is a stale green waiting for its first edit.
6
+ // Each gate task runs once under the tracer (trace/tracer.ts), and the paths
7
+ // it touched that no key covers become that task's proposals: the keys read them at once
7
8
  // (core/audit-report.ts), and `sk trace-audit --fix` writes them into their
8
9
  // own managed block of repo.config.ts (core/ignored-block.ts).
9
10
  //
@@ -14,7 +15,7 @@
14
15
  // git common dir and reused while it is young: rule SK031 in
15
16
  // the health pass pays for it, and the fix pass that applies it reads it.
16
17
  import { mkdirSync, writeFileSync } from 'fs'
17
- import { dirname, posix } from 'path'
18
+ import { dirname, isAbsolute, posix, relative, resolve, sep } from 'path'
18
19
  import type { RepoConfig } from '../repo-config.ts'
19
20
  import { composeChecks } from '../ledger/gate-checks.ts'
20
21
  import { isNamesInput } from '../ledger/git-key.ts'
@@ -22,7 +23,7 @@ import { readTrace } from '../trace/read-trace.ts'
22
23
  import { dropTrace, learnBlind, traceUnavailable, tracedCommand } from '../trace/tracer.ts'
23
24
  import { spawnWithTimeout } from './spawn-timeout.ts'
24
25
  import { gitBin } from './git-bin.ts'
25
- import { auditReportPath, ignoredFor, pendingByTask, readAuditReport, type AuditReport, type AuditTask, type IgnoredInputs } from './audit-report.ts'
26
+ import { auditReportPath, auditedExtras, ignoredFor, pendingByTask, readAuditReport, type AuditReport, type AuditTask, type IgnoredInputs } from './audit-report.ts'
26
27
  import { addIgnoredInputs } from './ignored-block.ts'
27
28
  import { loadRepoConfig } from '../repo-config.ts'
28
29
 
@@ -39,6 +40,25 @@ function gitIgnored(root: string, paths: string[]): Set<string> {
39
40
  return new Set(p.stdout.toString().split('\n').filter((l) => l !== ''))
40
41
  }
41
42
 
43
+ /** the paths of `paths` in the work tree's key, by their exact name: tracked,
44
+ * or untracked and not ignored. A case insensitive disk answers a probe of
45
+ * `TSCONFIG.JSON` with `tsconfig.json`, and only git says which name exists */
46
+ function inWorkTree(root: string, paths: string[]): Set<string> {
47
+ if (paths.length === 0) return new Set()
48
+ const p = Bun.spawnSync([gitBin(), 'ls-files', '-z', '--cached', '--others', '--exclude-standard', '--', ...paths.map((x) => `:(literal)${x}`)], { cwd: root, stdout: 'pipe', stderr: 'pipe' })
49
+ const listed = new Set(p.stdout.toString().split('\0').filter((l) => l !== ''))
50
+ return new Set(paths.filter((x) => listed.has(x)))
51
+ }
52
+
53
+ /** the toolkit running this audit, repo-relative when the repo hosts it. Its
54
+ * files are keyed by the code that produces each answer (the runner, a
55
+ * toolkit module's closure, `libused`), never by path, so a read under it
56
+ * is no finding */
57
+ function toolkitDir(root: string): string | null {
58
+ const rel = relative(root, resolve(import.meta.dir, '../..'))
59
+ return rel === '' || rel.startsWith('..') || isAbsolute(rel) ? null : rel.split(sep).join('/')
60
+ }
61
+
42
62
  const under = (p: string, dir: string): boolean => p === dir || p.startsWith(`${dir}/`)
43
63
 
44
64
  /** is this ignored path already in a key: bytes under a content entry, or a
@@ -47,6 +67,24 @@ function covered(p: string, listing: boolean, extras: string[]): boolean {
47
67
  return extras.some((e) => (isNamesInput(e) ? listing && under(p, e.slice(0, -3)) : under(p, e)))
48
68
  }
49
69
 
70
+ /** the list a task DECLARED, without what the kept audit added to its key:
71
+ * a finding the last audit keyed is still a finding until the config carries
72
+ * it, or the next audit would drop it and the key with it. null for a task
73
+ * keyed on the whole work tree, which covers every tracked file */
74
+ function declaredList(inputs: string[], keptExtras: string[], configExtras: string[]): string[] | null {
75
+ if (inputs.includes('.')) return null
76
+ return inputs.filter((p) => !keptExtras.includes(p) || configExtras.includes(p))
77
+ }
78
+
79
+ /** is this tracked (or untracked, not ignored) file in the key: under a
80
+ * declared path by content. A tracked dir a task only LISTS is not asked:
81
+ * a resolver lists every dir it walks (bun lists `packages/` on the way
82
+ * to a unit), and keying those names would re-run the task for any new file
83
+ * in the repo. A file it reads under that dir is a finding by itself */
84
+ function inTree(p: string, declared: string[], extras: string[]): boolean {
85
+ return [...declared, ...extras].some((e) => !isNamesInput(e) && under(p, e))
86
+ }
87
+
50
88
  /** the fewest entries that cover what was read: each file by itself, or a
51
89
  * dir by content once more than three files under it were read (its own
52
90
  * dir, or the outermost dir the task also listed); each listed dir as
@@ -91,6 +129,7 @@ export async function traceAudit(root: string, config: RepoConfig, o: { fresh?:
91
129
  const off = traceUnavailable(env)
92
130
  if (off != null) return { at: now, skipped: off, tasks: [] }
93
131
  const tasks: AuditTask[] = []
132
+ const toolkit = toolkitDir(root)
94
133
  for (const g of await composeChecks(root, config)) {
95
134
  const u = g.runnable
96
135
  if (u.body.cmd == null || g.row.runs.off != null || !g.row.runs.onCi || g.row.decl.inputs == null) continue
@@ -113,7 +152,9 @@ export async function traceAudit(root: string, config: RepoConfig, o: { fresh?:
113
152
  const dirs = dirsRead(Object.keys(r.reads.dirs ?? {}).filter(rel), Object.entries(r.reads.exists).filter(([, k]) => k === 'dir').map(([p]) => p).filter(rel), files)
114
153
  const ignored = gitIgnored(root, [...files, ...dirs])
115
154
  const extras = ignoredFor(config.ignoredInputs, u.id)
116
- const missF = files.filter((p) => ignored.has(p) && !covered(p, false, extras))
155
+ const declared = declaredList(g.row.decl.inputs, auditedExtras(kept, u.id), extras)
156
+ const outside = declared == null ? new Set<string>() : inWorkTree(root, files.filter((p) => !ignored.has(p) && !(toolkit != null && under(p, toolkit)) && !inTree(p, declared, extras)))
157
+ const missF = files.filter((p) => (ignored.has(p) ? !covered(p, false, extras) : outside.has(p)))
117
158
  const missD = dirs.filter((p) => ignored.has(p) && !covered(p, true, extras))
118
159
  tasks.push({ id: u.id, status: 'audited', uncovered: [...missF, ...missD].sort(), propose: proposeInputs(missF, missD) })
119
160
  } finally {
@@ -0,0 +1,60 @@
1
+ // a work tree's revision in this process: a count the save watch (serve/tracked-watch.ts) moves whenever a file the
2
+ // owner edits moves (tracked, or untracked and not ignored). A reader keyed on it reads the tree again only after a
3
+ // move, where a listing costs a git spawn and a stat per file (wiki tools/shipkit/home.md, Nothing heavy on the
4
+ // daemon's loop).
5
+ //
6
+ // the one constraint a reader breaks first: no watch, no revision. `treeRev` is null for a root no live watch follows
7
+ // (a cli run, a watch that died), and the reader then reads the tree every time, as it did before
8
+ import { dirname, resolve } from 'node:path'
9
+
10
+ const revs = new Map<string, { rev: number; watches: number }>()
11
+ /** one clock for every tree: a revision is never handed out twice, so a watch that stops and starts again never
12
+ * matches what was kept under the one before */
13
+ let clock = 0
14
+
15
+ /** a live watch starts following `root`; the function it returns says it stopped */
16
+ export function followTree(root: string): () => void {
17
+ const key = resolve(root)
18
+ const r = revs.get(key) ?? { rev: 0, watches: 0 }
19
+ r.watches++
20
+ r.rev = ++clock
21
+ revs.set(key, r)
22
+ let done = false
23
+ return () => {
24
+ if (done) return
25
+ done = true
26
+ r.watches--
27
+ if (r.watches <= 0) revs.delete(key)
28
+ }
29
+ }
30
+
31
+ /** a file under `root` moved */
32
+ export function treeMoved(root: string): void {
33
+ const r = revs.get(resolve(root))
34
+ if (r != null) r.rev = ++clock
35
+ }
36
+
37
+ /** the revision of the tree at `root`, null when no live watch follows it */
38
+ export function treeRev(root: string): number | null {
39
+ return revs.get(resolve(root))?.rev ?? null
40
+ }
41
+
42
+ /** the revision of the followed tree `path` sits in (itself or its nearest followed parent), null when none is */
43
+ export function treeRevAt(path: string): number | null {
44
+ for (let p = resolve(path); ; p = dirname(p)) {
45
+ const r = revs.get(p)
46
+ if (r != null) return r.rev
47
+ if (dirname(p) === p) return null
48
+ }
49
+ }
50
+
51
+ /** `read()` of `root`, kept while its revision holds: the same value until a file moves */
52
+ export function keptOnTree<T>(cache: Map<string, { rev: number; value: T }>, root: string, read: () => T): T {
53
+ const rev = treeRev(root)
54
+ if (rev == null) return read()
55
+ const held = cache.get(root)
56
+ if (held != null && held.rev === rev) return held.value
57
+ const value = read()
58
+ cache.set(root, { rev, value })
59
+ return value
60
+ }
@@ -0,0 +1,42 @@
1
+ // the `<name>.shipkit.ts` files that declare one kind of unit (`review(`, `social(`), found by a text test, never an
2
+ // import: the walk's dirs are cached on their times in `.shipkit/cache/<kind>-unit.json`, so a call costs a stat of
3
+ // each walked dir until a file comes or goes
4
+ import { mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs'
5
+ import { join } from 'node:path'
6
+ import { repoUnitFiles } from './discover-checks.ts'
7
+ import { LAYOUT } from './layout.ts'
8
+
9
+ /** the walk's answer kept in the cache: the unit files and every dir it read, each with its time; a dir whose time moved
10
+ * means a file came or went, so the walk runs again */
11
+ interface Found {
12
+ dirs: [string, number][]
13
+ files: [string, number, boolean][]
14
+ }
15
+
16
+ const mtime = (p: string): number => statSync(p, { throwIfNoEntry: false })?.mtimeMs ?? -1
17
+
18
+ /** the unit files of the repo whose text calls `<kind>(` */
19
+ export function unitFilesDeclaring(root: string, kind: string): string[] {
20
+ const cache = join(root, LAYOUT.cache, `${kind}-unit.json`)
21
+ const calls = new RegExp(`\\b${kind}\\s*\\(`)
22
+ let found: Found | null = null
23
+ try {
24
+ found = JSON.parse(readFileSync(cache, 'utf8')) as Found
25
+ } catch {
26
+ found = null
27
+ }
28
+ const fresh = (f: Found): boolean => f.dirs.every(([d, t]) => mtime(d) === t) && f.files.every(([p, t]) => mtime(p) === t)
29
+ if (!found || !fresh(found)) {
30
+ const dirs: string[] = []
31
+ const files = repoUnitFiles(root, dirs).filter((f) => !f.endsWith('.check.shipkit.ts'))
32
+ found = { dirs: dirs.map((d) => [d, mtime(d)]), files: files.map((f) => [f, mtime(f), calls.test(readFileSync(f, 'utf8'))]) }
33
+ try {
34
+ mkdirSync(join(root, LAYOUT.cache), { recursive: true })
35
+ writeFileSync(`${cache}.${process.pid}.tmp`, JSON.stringify(found))
36
+ renameSync(`${cache}.${process.pid}.tmp`, cache)
37
+ } catch {
38
+ // a read only checkout: the next run walks again
39
+ }
40
+ }
41
+ return found.files.filter(([, , has]) => has).map(([f]) => f)
42
+ }
@@ -0,0 +1,140 @@
1
+ // the md views of drill runs (drill/run.ts): one page per run, one comparison across the runs of a drill.
2
+ // Generated from the json every time, never edited by hand. Markers are the house legend only.
3
+ import type { DrillRun } from './run.ts'
4
+
5
+ const secs = (ms: number | null): string => (ms == null ? '-' : `${Math.round(ms / 1000)}`)
6
+ const clock = (ms: number | null): string => {
7
+ if (ms == null) return '-'
8
+ const s = Math.round(ms / 1000)
9
+ return `${Math.floor(s / 60)}m${String(s % 60).padStart(2, '0')}`
10
+ }
11
+ const big = (n: number): string => (n >= 1e6 ? `${(n / 1e6).toFixed(1)}M` : n >= 1e3 ? `${Math.round(n / 1e3)}k` : String(n))
12
+ const cell = (s: string): string => s.replace(/\|/g, '\\|').replace(/\n/g, ' ')
13
+ const fence = (s: string): string => '```\n' + s.replace(/```/g, "'''") + '\n```'
14
+
15
+ export function renderRun(r: DrillRun, label: string): string {
16
+ const out: string[] = [`<!-- generated by \`sk drill report\` from ${r.transcript}, never edited by hand -->`, '', `# drill run: ${label}`, '']
17
+ out.push('## prompt (exact)', '', fence(r.prompt), '', '## TLDR', '')
18
+ out.push(
19
+ r.verdict == null
20
+ ? '- 🔶 no verdict yet: `sk drill verdict` judges the run against its card'
21
+ : `- ${r.verdict.design === 'ok' && r.verdict.quality >= 4 ? '✅' : '🔶'} verdict: done ${r.verdict.done}, quality ${r.verdict.quality}/5, tests ${r.verdict.tests}, design ${r.verdict.design}${r.verdict.note === '' ? '' : `: ${r.verdict.note}`}`,
22
+ )
23
+ out.push(r.docs.length === 0 ? '- 🔶 no md page read: the setup under test never reached the run' : `- ${r.docs.length} md pages read, the first at ${clock(r.firstDoc)}; first write at ${clock(r.firstWrite)}, first check at ${clock(r.firstCheck)}`)
24
+ if (r.errors > 0) out.push(`- 🔶 ${r.errors} failed calls (listed below)`)
25
+ out.push(`- wall ${clock(r.wall)}, ${r.turns} turns, ${r.calls} tool calls, ${r.searches} searches, ${big(r.tokens.total)} tokens, context at end ${big(r.tokens.contextAtEnd)}`)
26
+ out.push('', '## numbers', '', '| metric | value |', '|---|---|')
27
+ const phase = (a: number | null, b: number | null): string => (a == null ? '-' : clock((b ?? r.wall) - a))
28
+ const rows: [string, string][] = [
29
+ ['wall / model / tools', `${clock(r.wall)} / ${clock(r.model)} / ${clock(r.tools)}`],
30
+ ['phases: explore (start → first write)', clock(r.firstWrite ?? r.wall)],
31
+ ['phases: build (first write → first check)', r.firstWrite == null || r.firstCheck == null ? '-' : phase(r.firstWrite, r.firstCheck)],
32
+ ['phases: verify (first check → end)', phase(r.firstCheck, null)],
33
+ ['turns / tool calls / failed', `${r.turns} / ${r.calls} / ${r.errors}`],
34
+ ['searches / reads / sent in parallel', `${r.searches} / ${r.reads} / ${r.parallel}`],
35
+ ['tokens: input / output', `${big(r.tokens.input)} / ${big(r.tokens.output)}`],
36
+ ['tokens: cache read / cache write', `${big(r.tokens.cacheRead)} / ${big(r.tokens.cacheWrite)}`],
37
+ ['context at end', big(r.tokens.contextAtEnd)],
38
+ ['models', r.models.join(', ') || '-'],
39
+ ]
40
+ if (r.patch != null) rows.push(['patch: files / + / − / new / tests / docs', `${r.patch.files} / ${r.patch.added} / ${r.patch.removed} / ${r.patch.newFiles} / ${r.patch.testFiles} / ${r.patch.docFiles}`])
41
+ for (const [k, v] of rows) out.push(`| ${k} | ${v} |`)
42
+ out.push('', '## md pages read', '', '`@` includes load before turn 1 and never show here.', '')
43
+ if (r.docs.length === 0) out.push('none')
44
+ else {
45
+ out.push('| at | page | reader | reads |', '|---|---|---|---|')
46
+ for (const d of r.docs) out.push(`| ${clock(d.first)} | ${cell(d.path)} | ${d.reader} | ${d.reads} |`)
47
+ }
48
+ out.push('', '## per tool', '', '| tool | calls | failed | time |', '|---|---|---|---|')
49
+ for (const t of r.perTool) out.push(`| ${t.tool} | ${t.calls} | ${t.errors} | ${clock(t.ms)} |`)
50
+ out.push('', '## per command shape', '', '| shape | calls | failed | time |', '|---|---|---|---|')
51
+ for (const t of r.perShape) out.push(`| ${cell(t.shape)} | ${t.calls} | ${t.errors} | ${clock(t.ms)} |`)
52
+ out.push('', '## files written (Edit, Write)', '')
53
+ out.push(r.written.length === 0 ? 'none' : r.written.map((w) => `- ${w}`).join('\n'))
54
+ if (r.patch != null) out.push('', '## files in the patch', '', r.patch.paths.length === 0 ? 'none' : r.patch.paths.map((p) => `- ${p}`).join('\n'))
55
+ out.push('', '## failed calls', '')
56
+ out.push(r.failures.length === 0 ? 'none' : r.failures.map((f) => `- 🔶 ${clock(f.at)} ${f.tool} (${f.outcome}): \`${f.detail.replace(/`/g, "'")}\``).join('\n'))
57
+ out.push('', '## final report', '', fence(r.finalReport), '')
58
+ return out.join('\n')
59
+ }
60
+
61
+ type Row = { label: string; get: (r: DrillRun) => number | null; fmt?: (n: number) => string }
62
+
63
+ const ROWS: Row[] = [
64
+ { label: 'wall (s)', get: (r) => r.wall, fmt: (n) => secs(n) },
65
+ { label: 'model (s)', get: (r) => r.model, fmt: (n) => secs(n) },
66
+ { label: 'turns', get: (r) => r.turns },
67
+ { label: 'tool calls', get: (r) => r.calls },
68
+ { label: 'failed calls', get: (r) => r.errors },
69
+ { label: 'searches', get: (r) => r.searches },
70
+ { label: 'reads', get: (r) => r.reads },
71
+ { label: 'md pages read', get: (r) => r.docs.length },
72
+ { label: 'first md page (s)', get: (r) => r.firstDoc, fmt: (n) => secs(n) },
73
+ { label: 'first write (s)', get: (r) => r.firstWrite, fmt: (n) => secs(n) },
74
+ { label: 'first check (s)', get: (r) => r.firstCheck, fmt: (n) => secs(n) },
75
+ { label: 'tokens total', get: (r) => r.tokens.total, fmt: big },
76
+ { label: 'context at end', get: (r) => r.tokens.contextAtEnd, fmt: big },
77
+ { label: 'patch: files', get: (r) => r.patch?.files ?? null },
78
+ { label: 'patch: lines + / −', get: (r) => (r.patch == null ? null : r.patch.added + r.patch.removed) },
79
+ { label: 'patch: test files', get: (r) => r.patch?.testFiles ?? null },
80
+ { label: 'verdict: quality (1-5)', get: (r) => r.verdict?.quality ?? null },
81
+ { label: 'verdict: design ok (1) or wrong (0)', get: (r) => (r.verdict == null ? null : r.verdict.design === 'ok' ? 1 : 0) },
82
+ { label: 'verdict: tests ran (2), written (1), none (0)', get: (r) => (r.verdict == null ? null : { ran: 2, written: 1, none: 0 }[r.verdict.tests]) },
83
+ ]
84
+
85
+ /** under 5% apart, two runs read as the same: one run's noise is larger than that */
86
+ const SAME = 1.05
87
+ /** better by more than the noise: a lower count, a shorter wall */
88
+ const better = (a: number, b: number): boolean => b * SAME < a
89
+
90
+ /** "62 → 50, 1.2x fewer": the ratio always reads up from 1, so a regression never reads "0.6x faster" */
91
+ export function delta(a: number | null, b: number | null, fmt: (n: number) => string = String): string {
92
+ if (a == null || b == null) return '-'
93
+ if (fmt(a) === fmt(b)) return `${fmt(a)} → ${fmt(b)}, same`
94
+ if (a === 0 || b === 0) return `${fmt(a)} → ${fmt(b)}`
95
+ const ratio = Math.max(a, b) / Math.min(a, b)
96
+ if (ratio < SAME) return `${fmt(a)} → ${fmt(b)}, about the same`
97
+ return `${fmt(a)} → ${fmt(b)}, ${ratio.toFixed(1)}x ${b < a ? 'fewer' : 'more'}`
98
+ }
99
+
100
+ const bars = (title: string, labels: string[], values: number[]): string =>
101
+ ['```mermaid', 'xychart-beta', ` title "${title}"`, ` x-axis [${labels.map((l) => `"${l}"`).join(', ')}]`, ` y-axis 0 --> ${Math.max(1, ...values)}`, ` bar [${values.join(', ')}]`, '```'].join('\n')
102
+
103
+ /** every run of a drill side by side, run order as given */
104
+ export function renderCompare(name: string, runs: { label: string; run: DrillRun }[]): string {
105
+ const out: string[] = [`<!-- generated by \`sk drill compare\` from ${runs.map((r) => `${r.label}.json`).join(', ')}, never edited by hand -->`, '', `# drill compare: ${name}`, '']
106
+ const first = runs[0]
107
+ const lastRun = runs[runs.length - 1]
108
+ if (first == null || lastRun == null) return [...out, 'no run.', ''].join('\n')
109
+ const a = first.run
110
+ const z = lastRun.run
111
+ const mismatch = runs.filter((r) => r.run.prompt !== a.prompt).map((r) => r.label)
112
+ out.push('## TLDR', '')
113
+ const prev = runs.length > 2 ? runs[runs.length - 2] : undefined
114
+ out.push(`- ${better(a.calls, z.calls) ? '✅' : '🔶'} tool calls ${first.label} → ${lastRun.label}: ${delta(a.calls, z.calls)}`)
115
+ if (prev != null) out.push(`- ${better(prev.run.calls, z.calls) ? '✅' : '🔶'} tool calls ${prev.label} → ${lastRun.label}, what the stop rule reads: ${delta(prev.run.calls, z.calls)}`)
116
+ out.push(`- ${better(a.wall, z.wall) ? '✅' : '🔶'} wall (s): ${delta(a.wall, z.wall, secs)}`)
117
+ out.push(`- ${better(a.tokens.total, z.tokens.total) ? '✅' : '🔶'} tokens: ${delta(a.tokens.total, z.tokens.total, big)}`)
118
+ const qa = a.verdict?.quality
119
+ const qz = z.verdict?.quality
120
+ out.push(qa == null || qz == null ? '- 🔶 a verdict is missing: a saving with no verdict is not a saving (`sk drill verdict`)' : `- ${qz >= qa ? '✅' : '🔶'} quality ${qa} → ${qz}, design ${a.verdict?.design} → ${z.verdict?.design}`)
121
+ out.push(mismatch.length === 0 ? '- ✅ every run got the same prompt' : `- 🔶 the prompt differs from ${first.label} in: ${mismatch.join(', ')}`)
122
+ const prevHead = prev == null ? '' : ` ${prev.label} → ${lastRun.label} |`
123
+ out.push('', '## metrics', '', `| metric | ${runs.map((r) => r.label).join(' | ')} | ${first.label} → ${lastRun.label} |${prevHead}`, `|---|${runs.map(() => '---|').join('')}---|${prev == null ? '' : '---|'}`)
124
+ for (const row of ROWS) {
125
+ const vals = runs.map((r) => row.get(r.run))
126
+ if (vals.every((v) => v == null)) continue
127
+ const fmt = row.fmt ?? String
128
+ const prevCell = prev == null ? '' : ` ${delta(vals[vals.length - 2] ?? null, vals[vals.length - 1] ?? null, fmt)} |`
129
+ out.push(`| ${row.label} | ${vals.map((v) => (v == null ? '-' : fmt(v))).join(' | ')} | ${delta(vals[0] ?? null, vals[vals.length - 1] ?? null, fmt)} |${prevCell}`)
130
+ }
131
+ const labels = runs.map((r) => r.label)
132
+ out.push('', '## charts', '', bars('tool calls', labels, runs.map((r) => r.run.calls)), '', bars('wall (s)', labels, runs.map((r) => Math.round(r.run.wall / 1000))), '', bars('tokens (k)', labels, runs.map((r) => Math.round(r.run.tokens.total / 1000))), '')
133
+ const docs = [...new Set(runs.flatMap((r) => r.run.docs.map((d) => d.path)))]
134
+ if (docs.length > 0) {
135
+ out.push('## when each md page was first read (mm:ss, - = never)', '', `| page | ${labels.join(' | ')} |`, `|---|${labels.map(() => '---|').join('')}`)
136
+ for (const p of docs) out.push(`| ${cell(p)} | ${runs.map((r) => clock(r.run.docs.find((d) => d.path === p)?.first ?? null)).join(' | ')} |`)
137
+ out.push('')
138
+ }
139
+ return out.join('\n')
140
+ }
@@ -0,0 +1,269 @@
1
+ // one drill run, read from its Claude Code transcript (wiki meta/speed-up-agents/index.md): what it did, in
2
+ // which order, at what cost, through the same transcript reader and timeline as `sk time`. Pure: lines in,
3
+ // a record out, so a test feeds it a fixture. The record is json first; the md is a view of it, regenerated,
4
+ // never edited by hand, so a number copied into a card cannot drift from its source.
5
+ import { callMs, closeCalls, IDLE_MS, wallBreakdown, type Call, type Mark } from '../agent-time/timeline.ts'
6
+ import { isReadOnly, parallelFlags } from '../agent-time/turns.ts'
7
+ import { shellWords, statements, stripHeredocs, toolShape } from '../agent-time/shape.ts'
8
+ import { eventsOf, parseEntry, usageOf, userTextOf, type Outcome, type RawEntry } from '../reflect/transcript.ts'
9
+
10
+ export const RUN_VERSION = 1
11
+
12
+ export type Verdict = { done: string; quality: number; tests: 'ran' | 'written' | 'none'; design: 'ok' | 'wrong'; note: string }
13
+
14
+ export type DocRead = { path: string; first: number; reads: number; reader: string }
15
+
16
+ export type PatchStats = { files: number; added: number; removed: number; newFiles: number; testFiles: number; docFiles: number; paths: string[] }
17
+
18
+ export type DrillRun = {
19
+ version: number
20
+ transcript: string
21
+ prompt: string
22
+ start: string
23
+ /** all durations in ms; every "first" is an offset from the start, null when it never happened */
24
+ wall: number
25
+ model: number
26
+ tools: number
27
+ turns: number
28
+ calls: number
29
+ errors: number
30
+ searches: number
31
+ reads: number
32
+ parallel: number
33
+ firstDoc: number | null
34
+ firstWrite: number | null
35
+ /** the first check after the first write (any check when nothing was written): explore, build, verify cut there */
36
+ firstCheck: number | null
37
+ tokens: { input: number; output: number; cacheRead: number; cacheWrite: number; total: number; contextAtEnd: number }
38
+ models: string[]
39
+ docs: DocRead[]
40
+ perTool: { tool: string; calls: number; errors: number; ms: number }[]
41
+ perShape: { shape: string; calls: number; errors: number; ms: number }[]
42
+ written: string[]
43
+ failures: { at: number; tool: string; detail: string; outcome: Outcome }[]
44
+ finalReport: string
45
+ patch: PatchStats | null
46
+ verdict: Verdict | null
47
+ }
48
+
49
+ const WRITE_TOOLS = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit'])
50
+ const SEARCH_TOOLS = new Set(['Grep', 'Glob'])
51
+ const SEARCH_SHAPE = /^(grep|rg|git grep|find|ag)\b/
52
+ /** what counts as checking the work: a test run, the gate, a typecheck, a lint */
53
+ const CHECK_SHAPE = /^(sk ci|shipkit ci|bun test|bun run test|bun check|bun run check|bun lint|bun run lint|npx tsc|tsc|vitest|jest)\b/
54
+ /** programs that show a file's content; the first word after their flags is a pattern or a script, never a file */
55
+ const CONTENT_READERS = new Set(['cat', 'head', 'tail', 'less', 'more', 'bat', 'nl'])
56
+ const PATTERN_FIRST = new Set(['sed', 'awk', 'grep', 'rg'])
57
+ /** a word with these is a glob or a pattern, never one page */
58
+ const NOT_A_PATH = /[*?[\]{}\\$]/
59
+ const QUOTED = /'[^']*'|"(?:\\.|[^"\\])*"/g
60
+ const REDIRECT = /(?:^|[^<>&0-9])\d?>{1,2}\s*([^\s;&|<>]+)/g
61
+ const TEE = /(?:^|[|;&]\s*)tee\s+(?:-\S+\s+)*([^\s;&|<>]+)/g
62
+ const FINAL_MAX = 3000
63
+
64
+ /** the files a reading Bash statement shows the content of; [] for `wc`, `ls`, `git status` and the like */
65
+ function contentPaths(segment: string): string[] {
66
+ const words = shellWords(segment.trim())
67
+ let i = 0
68
+ while (words[i] != null && /^(nice|time|command|env)$/.test(words[i] as string)) i++
69
+ const prog = words[i] ?? ''
70
+ let args = words.slice(i + 1)
71
+ if (prog === 'git') {
72
+ while (args[0] === '-C' || args[0] === '-c') args = args.slice(2)
73
+ if (args[0] !== 'show' && args[0] !== 'diff') return []
74
+ args = args.slice(1).map((w) => w.slice(w.indexOf(':') + 1))
75
+ } else if (!CONTENT_READERS.has(prog) && !PATTERN_FIRST.has(prog)) return []
76
+ const files = args.filter((w) => !w.startsWith('-')).map((w) => w.replace(/^\$HOME(?=\/)/, '~'))
77
+ return (PATTERN_FIRST.has(prog) ? files.slice(1) : files).filter((w) => w.endsWith('.md') && !NOT_A_PATH.test(w))
78
+ }
79
+
80
+ /** the md files a call read, each once, with how: the Read tool by its path, a content reader by every page it names */
81
+ function docsOf(c: Call): { path: string; reader: string }[] {
82
+ if (c.tool === 'Read') return c.cmd.endsWith('.md') ? [{ path: c.cmd, reader: 'Read' }] : []
83
+ if (c.tool !== 'Bash' || !c.read) return []
84
+ const out = new Map<string, string>()
85
+ for (const s of statements(c.cmd)) for (const p of contentPaths(s)) if (!out.has(p)) out.set(p, `Bash ${shellWords(s.trim())[0] ?? ''}`)
86
+ return [...out].map(([path, reader]) => ({ path, reader }))
87
+ }
88
+
89
+ /** the files a Bash command writes: redirect targets (quoted text and /dev/null left out), `tee` args, an in place edit's last arg */
90
+ function bashTargets(cmd: string): string[] {
91
+ const out: string[] = []
92
+ // the whole command, heredoc bodies and quoted text out: statements() keeps only each pipeline's head
93
+ const bare = stripHeredocs(cmd).replace(QUOTED, "''")
94
+ for (const m of bare.matchAll(REDIRECT)) if (m[1] != null && m[1] !== '/dev/null' && !m[1].startsWith('&')) out.push(m[1])
95
+ for (const m of bare.matchAll(TEE)) if (m[1] != null) out.push(m[1])
96
+ for (const s of statements(cmd)) {
97
+ const words = shellWords(s.trim())
98
+ const prog = words[0] ?? ''
99
+ if ((prog === 'sed' && words.some((w) => w.startsWith('-i'))) || (prog === 'perl' && words.some((w) => /^-p?i/.test(w)))) {
100
+ const last = words[words.length - 1]
101
+ if (last != null) out.push(last)
102
+ }
103
+ }
104
+ return out
105
+ }
106
+
107
+ /** the stats of a unified diff, the kind `git diff --cached` writes */
108
+ export function patchStats(patch: string): PatchStats {
109
+ const paths: string[] = []
110
+ let added = 0
111
+ let removed = 0
112
+ let newFiles = 0
113
+ for (const line of patch.split('\n')) {
114
+ const head = /^diff --git a\/(\S+) b\/(\S+)/.exec(line)
115
+ if (head?.[2] != null) paths.push(head[2])
116
+ else if (line.startsWith('new file mode')) newFiles++
117
+ else if (line.startsWith('+') && !line.startsWith('+++')) added++
118
+ else if (line.startsWith('-') && !line.startsWith('---')) removed++
119
+ }
120
+ return { files: paths.length, added, removed, newFiles, testFiles: paths.filter((p) => /\.(test|spec)\.[jt]sx?$/.test(p)).length, docFiles: paths.filter((p) => p.endsWith('.md')).length, paths }
121
+ }
122
+
123
+ /** the run a transcript records. `root` is the run folder: its prefix is cut from every path, so two runs in two folders compare */
124
+ export function drillRun(lines: readonly string[], o: { transcript: string; root?: string; home?: string; patch?: string; mask?: (s: string) => string }): DrillRun {
125
+ const mask = o.mask ?? ((s: string) => s)
126
+ const home = o.home ?? process.env.HOME ?? ''
127
+ /** one spelling per file: `~/` and `$HOME/` expanded, then the run folder cut, so `Read` and `cat` of one page are one row */
128
+ const rel = (raw: string): string => {
129
+ const p = home !== '' ? raw.replace(/^(~|\$HOME)(?=\/)/, home) : raw
130
+ return o.root != null && p.startsWith(`${o.root}/`) ? p.slice(o.root.length + 1) : p
131
+ }
132
+ /** a write counts when it lands in the run: with a run folder, a relative target or one under it; a scratch file elsewhere is not the work */
133
+ const inRun = (target: string): boolean => {
134
+ if (o.root == null) return target !== ''
135
+ const t = rel(target)
136
+ return t !== '' && !t.startsWith('/') && !t.startsWith('~')
137
+ }
138
+ const writesOf = (c: Call): boolean => (WRITE_TOOLS.has(c.tool) ? inRun(c.cmd) : c.tool === 'Bash' && !c.read && bashTargets(c.cmd).some(inRun))
139
+ const pending = new Map<string, Call>()
140
+ const marks: Mark[] = []
141
+ const usage = new Map<string, NonNullable<ReturnType<typeof usageOf>>>()
142
+ let prompt: string | null = null
143
+ let finalReport = ''
144
+ let first = Infinity
145
+ let last = -Infinity
146
+ for (const line of lines) {
147
+ const entry: RawEntry | null = parseEntry(line)
148
+ if (entry == null) continue
149
+ const at = typeof entry.timestamp === 'string' ? Date.parse(entry.timestamp) : NaN
150
+ if (!Number.isNaN(at)) {
151
+ first = Math.min(first, at)
152
+ last = Math.max(last, at)
153
+ }
154
+ if (prompt == null && entry.type === 'user') {
155
+ const t = userTextOf(entry)
156
+ if (t != null && t !== '') prompt = t
157
+ }
158
+ const u = usageOf(entry)
159
+ if (u != null) usage.set(u.messageId, u)
160
+ if (entry.type === 'assistant' && Array.isArray(entry.message?.content)) {
161
+ for (const b of entry.message.content as { type?: unknown; text?: unknown; name?: unknown; input?: { message?: unknown } }[]) {
162
+ if (b?.type === 'text' && typeof b.text === 'string' && b.text.trim() !== '') finalReport = b.text
163
+ // a sub-agent hands its report back through a tool call, not a text block
164
+ else if (b?.type === 'tool_use' && b.name === 'SubagentHandback' && typeof b.input?.message === 'string') finalReport = b.input.message
165
+ }
166
+ }
167
+ for (const e of eventsOf(entry)) {
168
+ if (e.kind === 'use') {
169
+ const shape = toolShape(e.name, e.detail)
170
+ pending.set(e.id, { id: e.id, start: e.at, end: null, tool: e.name, shape, cmd: e.detail, outcome: null, code: null, approval: false, perm: '', read: isReadOnly({ tool: e.name, shape, cmd: e.detail }) })
171
+ } else if (e.kind === 'result') {
172
+ const c = pending.get(e.id)
173
+ if (c != null) Object.assign(c, { end: e.at, outcome: e.outcome, code: e.code, approval: e.perm === 'user', perm: e.perm })
174
+ } else if (e.kind !== 'prompt') marks.push({ at: e.at, kind: e.kind })
175
+ }
176
+ }
177
+ const start = Number.isFinite(first) ? first : 0
178
+ const calls = closeCalls({ calls: [...pending.values()], marks })
179
+ const wall = Number.isFinite(last) ? Math.max(0, last - start) : 0
180
+ const b = wallBreakdown({ calls: [...pending.values()], marks }, -Infinity, Infinity, IDLE_MS, calls)
181
+ const off = (at: number | undefined): number | null => (at == null ? null : Math.max(0, at - start))
182
+
183
+ const docs = new Map<string, DocRead>()
184
+ for (const c of calls)
185
+ for (const d of docsOf(c)) {
186
+ const path = rel(d.path)
187
+ const seen = docs.get(path)
188
+ if (seen == null) docs.set(path, { path, first: off(c.start) ?? 0, reads: 1, reader: d.reader })
189
+ else seen.reads++
190
+ }
191
+ const tally = (key: (c: (typeof calls)[number]) => string): { key: string; calls: number; errors: number; ms: number }[] => {
192
+ const m = new Map<string, { key: string; calls: number; errors: number; ms: number }>()
193
+ for (const c of calls) {
194
+ const k = key(c)
195
+ const row = m.get(k) ?? { key: k, calls: 0, errors: 0, ms: 0 }
196
+ row.calls++
197
+ if (c.outcome != null && c.outcome !== 'ok') row.errors++
198
+ row.ms += callMs(c)
199
+ m.set(k, row)
200
+ }
201
+ return [...m.values()].sort((x, y) => y.calls - x.calls || y.ms - x.ms)
202
+ }
203
+ const u = [...usage.values()]
204
+ const sum = (f: (x: (typeof u)[number]) => number): number => u.reduce((n, x) => n + f(x), 0)
205
+ const lastUsage = u[u.length - 1]
206
+ const isSearch = (c: Call): boolean => SEARCH_TOOLS.has(c.tool) || (c.tool === 'Bash' && SEARCH_SHAPE.test(c.shape))
207
+ const docList = [...docs.values()].sort((x, y) => x.first - y.first)
208
+ const firstWrite = calls.find(writesOf)
209
+ return {
210
+ version: RUN_VERSION,
211
+ transcript: o.transcript,
212
+ prompt: mask(prompt ?? ''),
213
+ start: new Date(start).toISOString(),
214
+ wall,
215
+ model: b.model,
216
+ tools: b.tools + b.approval + b.subagent,
217
+ turns: usage.size,
218
+ calls: calls.length,
219
+ errors: calls.filter((c) => c.outcome != null && c.outcome !== 'ok').length,
220
+ searches: calls.filter(isSearch).length,
221
+ reads: calls.filter((c) => c.read).length,
222
+ parallel: parallelFlags(calls).filter(Boolean).length,
223
+ firstDoc: docList[0]?.first ?? null,
224
+ firstWrite: off(firstWrite?.start),
225
+ firstCheck: off(calls.find((c) => c.tool === 'Bash' && CHECK_SHAPE.test(c.shape) && (firstWrite == null || c.start >= firstWrite.start))?.start),
226
+ tokens: {
227
+ input: sum((x) => x.input),
228
+ output: sum((x) => x.output),
229
+ cacheRead: sum((x) => x.cacheRead),
230
+ cacheWrite: sum((x) => x.cacheWrite),
231
+ total: sum((x) => x.input + x.output + x.cacheRead + x.cacheWrite),
232
+ contextAtEnd: lastUsage == null ? 0 : lastUsage.input + lastUsage.cacheRead + lastUsage.cacheWrite,
233
+ },
234
+ models: [...new Set(u.map((x) => x.model).filter((m) => m !== ''))],
235
+ docs: docList,
236
+ perTool: tally((c) => c.tool).map(({ key, ...r }) => ({ tool: key, ...r })),
237
+ perShape: tally((c) => c.shape).map(({ key, ...r }) => ({ shape: mask(key), ...r })),
238
+ written: [...new Set(calls.filter((c) => WRITE_TOOLS.has(c.tool) && inRun(c.cmd)).map((c) => rel(c.cmd)))],
239
+ failures: calls.filter((c) => c.outcome != null && c.outcome !== 'ok').map((c) => ({ at: off(c.start) ?? 0, tool: c.tool, detail: mask(rel(c.cmd)).slice(0, 160), outcome: c.outcome as Outcome })),
240
+ finalReport: mask(finalReport).slice(0, FINAL_MAX),
241
+ patch: o.patch == null ? null : patchStats(o.patch),
242
+ verdict: null,
243
+ }
244
+ }
245
+
246
+ /** `done=3/3,quality=4,tests=ran,design=ok[,note=…]`, every field checked; the error names the bad one */
247
+ export function parseVerdict(text: string): Verdict | string {
248
+ const kv = new Map(
249
+ text
250
+ .split(',')
251
+ .map((p) => p.trim())
252
+ .filter((p) => p !== '')
253
+ .map((p) => {
254
+ const i = p.indexOf('=')
255
+ return [i < 0 ? p : p.slice(0, i).trim(), i < 0 ? '' : p.slice(i + 1).trim()] as const
256
+ }),
257
+ )
258
+ const done = kv.get('done') ?? ''
259
+ if (!/^\d+\/\d+$/.test(done)) return `done=${done}: the items done over the items expected, like 3/3`
260
+ const quality = Number(kv.get('quality'))
261
+ if (!Number.isInteger(quality) || quality < 1 || quality > 5) return `quality=${kv.get('quality') ?? ''}: a whole number from 1 to 5`
262
+ const tests = kv.get('tests')
263
+ if (tests !== 'ran' && tests !== 'written' && tests !== 'none') return `tests=${tests ?? ''}: ran, written or none`
264
+ const design = kv.get('design')
265
+ if (design !== 'ok' && design !== 'wrong') return `design=${design ?? ''}: ok or wrong`
266
+ const unknown = [...kv.keys()].filter((k) => !['done', 'quality', 'tests', 'design', 'note'].includes(k))
267
+ if (unknown.length > 0) return `${unknown.join(', ')}: the fields are done, quality, tests, design, note`
268
+ return { done, quality, tests, design, note: kv.get('note') ?? '' }
269
+ }
@@ -16,6 +16,7 @@ import { isArchived } from '../core/archived.ts'
16
16
  import { isLinkedWorktree } from '../core/git-root.ts'
17
17
  import { detectPackageManager, isRefusal } from '../core/package-manager.ts'
18
18
  import { isBreaking, isLinkedInstall, pinFloor } from '../core/update-policy.ts'
19
+ import { publishedHere } from '../release/published-here.ts'
19
20
 
20
21
  export type Pkg = { name?: string; version?: string; dependencies?: Record<string, string>; devDependencies?: Record<string, string> }
21
22
 
@@ -130,11 +131,11 @@ export async function resolveLatest(repos: FleetRepo[], fetchLatest: (name: stri
130
131
  const latest = new Map<string, string | null>()
131
132
  await Promise.all(
132
133
  [...names].map(async (n) => {
133
- try {
134
- latest.set(n, await fetchLatest(n))
135
- } catch {
136
- latest.set(n, null)
137
- }
134
+ let registry: string | null = null
135
+ try { registry = await fetchLatest(n) } catch { /* the registry did not answer */ }
136
+ // a version this machine just published beats the registry's cached latest
137
+ const here = publishedHere(n)
138
+ latest.set(n, here != null && (registry == null || isBehind(registry, here)) ? here : registry)
138
139
  }),
139
140
  )
140
141
  for (const r of repos) {