rvlib-shipkit 2.12.0 → 2.13.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 (290) hide show
  1. package/CHANGELOG.md +48 -13
  2. package/README.md +1 -1
  3. package/package.json +4 -2
  4. package/src/agent-time/store.ts +2 -2
  5. package/src/check.ts +1 -1
  6. package/src/checks/SK001-package-json-shape.check.ts +4 -0
  7. package/src/checks/SK003-claude-md-shape.check.ts +1 -1
  8. package/src/checks/SK004-gitignore-policy.check.ts +27 -2
  9. package/src/checks/SK005-rvlib-versions.check.ts +1 -1
  10. package/src/checks/SK008-reviewer-agent.check.ts +2 -2
  11. package/src/checks/SK012-config-barrel-import.check.ts +1 -1
  12. package/src/checks/SK015-nested-repo.check.ts +1 -1
  13. package/src/checks/SK035-public-clean.check.ts +46 -0
  14. package/src/checks/SK036-draft-media-size.check.ts +28 -0
  15. package/src/cli/cmd_Backup.ts +152 -0
  16. package/src/cli/cmd_Ci.ts +8 -11
  17. package/src/cli/cmd_Drill.ts +145 -0
  18. package/src/cli/cmd_Home.ts +50 -3
  19. package/src/cli/cmd_Media.ts +7 -5
  20. package/src/cli/cmd_Review.ts +4 -2
  21. package/src/cli/cmd_Shot.ts +5 -2
  22. package/src/cli/cmd_Smoke.ts +4 -1
  23. package/src/cli/cmd_Social.ts +226 -0
  24. package/src/cli/cmd_Start.ts +1 -1
  25. package/src/cli/cmd_Time.ts +1 -1
  26. package/src/cli/cmd_Trailer.ts +5 -2
  27. package/src/cli/cmd_Veille.ts +173 -0
  28. package/src/cli/family-pages.ts +3 -0
  29. package/src/cli/registry.ts +13 -2
  30. package/src/cli.ts +5 -2
  31. package/src/collections/actions.ts +1 -49
  32. package/src/collections/checks.ts +2 -1
  33. package/src/collections/collection-types.ts +11 -2
  34. package/src/collections/providers.ts +4 -4
  35. package/src/collections/review.ts +2 -1
  36. package/src/collections/tests.ts +19 -8
  37. package/src/contracts/apply-contracts.ts +1 -3
  38. package/src/contracts/contract-manifests.ts +2 -3
  39. package/src/contracts/contract-types.ts +0 -1
  40. package/src/contracts/contracts-engine.ts +0 -3
  41. package/src/core/app-icon.ts +9 -3
  42. package/src/core/bun-builtins.ts +2 -2
  43. package/src/core/discover-checks.ts +37 -5
  44. package/src/core/fix-scope.ts +4 -2
  45. package/src/core/floor-resolve.ts +68 -48
  46. package/src/core/floor.ts +9 -0
  47. package/src/core/git-root.ts +24 -0
  48. package/src/core/last-good.ts +3 -1
  49. package/src/core/layout.ts +8 -0
  50. package/src/core/log-stamp.ts +36 -0
  51. package/src/core/loop-watch.ts +93 -0
  52. package/src/core/machine-link.ts +134 -0
  53. package/src/core/memory-watch.ts +41 -0
  54. package/src/core/one-way-in-policy.ts +27 -19
  55. package/src/core/run-ci.ts +6 -8
  56. package/src/core/run-fixers.ts +9 -9
  57. package/src/core/slots.ts +21 -0
  58. package/src/core/tree-rev.ts +60 -0
  59. package/src/core/unit-files.ts +42 -0
  60. package/src/drill/render.ts +140 -0
  61. package/src/drill/run.ts +269 -0
  62. package/src/fleet/scan-fleet.ts +6 -5
  63. package/src/home/daemon-jobs.ts +201 -0
  64. package/src/home/global-context.ts +34 -1
  65. package/src/home/home-routes.ts +22 -15
  66. package/src/home/hubs.ts +10 -3
  67. package/src/home/inbox-shape.ts +53 -4
  68. package/src/home/inbox.ts +16 -1
  69. package/src/home/lib-watch.ts +10 -3
  70. package/src/home/machine-stores.ts +15 -29
  71. package/src/home/run-daemon.ts +15 -18
  72. package/src/home/run-pm.ts +2 -0
  73. package/src/home/serve-daemon.ts +4 -3
  74. package/src/home/serve-web.ts +104 -1
  75. package/src/hooks/commit-message.ts +28 -19
  76. package/src/hooks/leak-guard.ts +10 -3
  77. package/src/hooks/run-hooks.ts +2 -6
  78. package/src/identities/identities.ts +334 -0
  79. package/src/identities/machine-route.ts +126 -0
  80. package/src/identities/machine.ts +62 -0
  81. package/src/init-repo.ts +1 -1
  82. package/src/ledger/check-stats.ts +10 -9
  83. package/src/ledger/gate-checks.ts +32 -1
  84. package/src/ledger/record-kept.ts +112 -0
  85. package/src/ledger/repo-view.ts +10 -0
  86. package/src/ledger/run-log.ts +17 -12
  87. package/src/ledger/run-timeline.ts +8 -4
  88. package/src/ledger/store.ts +7 -0
  89. package/src/ledger/suite-log.ts +17 -13
  90. package/src/media-kinds.ts +2 -1
  91. package/src/media-store/backup/daemon.ts +73 -0
  92. package/src/media-store/backup/keys.ts +25 -0
  93. package/src/media-store/backup/manifest.ts +193 -0
  94. package/src/media-store/backup/restore.ts +192 -0
  95. package/src/media-store/backup/run.ts +278 -0
  96. package/src/media-store/backup/secret.ts +86 -0
  97. package/src/media-store/backup/snapshot.ts +64 -0
  98. package/src/media-store/backup/sources.ts +199 -0
  99. package/src/media-store/daemon.ts +56 -70
  100. package/src/media-store/put.ts +4 -2
  101. package/src/media-store/space.ts +23 -4
  102. package/src/pages/forward.ts +35 -0
  103. package/src/pages/frame-client.ts +118 -0
  104. package/src/pages/routes.ts +29 -0
  105. package/src/pages/unit.ts +92 -0
  106. package/src/plan/planner.ts +12 -0
  107. package/src/plan/repo-source.ts +19 -5
  108. package/src/reflect/transcript.ts +35 -10
  109. package/src/release/public-clean.ts +301 -0
  110. package/src/release/published-here.ts +22 -0
  111. package/src/release/run-bump.ts +2 -1
  112. package/src/release/run-release.ts +4 -1
  113. package/src/repo-config.ts +53 -2
  114. package/src/review/http.ts +16 -2
  115. package/src/review/model.ts +15 -4
  116. package/src/review/notes.ts +77 -0
  117. package/src/review/project.ts +6 -38
  118. package/src/review/routes.ts +4 -12
  119. package/src/review/store.ts +41 -1
  120. package/src/review/trailer-media.ts +7 -4
  121. package/src/review/trailer-shots.ts +21 -4
  122. package/src/review/unit.ts +1 -1
  123. package/src/scaffold/files/agent-handoff.md +3 -0
  124. package/src/scaffold/files/agent-index.md +4 -12
  125. package/src/scaffold/project-scaffold.ts +5 -4
  126. package/src/serve/embed.ts +1 -1
  127. package/src/serve/hub-app/col-card.tsx +3 -17
  128. package/src/serve/hub-app/col-tables-view.tsx +2 -1
  129. package/src/serve/hub-app/cols-svc.ts +0 -13
  130. package/src/serve/hub-app/dock-st.ts +4 -2
  131. package/src/serve/hub-app/dock-view.tsx +2 -0
  132. package/src/serve/hub-app/frames-st.ts +35 -0
  133. package/src/serve/hub-app/hash-route.ts +64 -1
  134. package/src/serve/hub-app/home-st.ts +31 -7
  135. package/src/serve/hub-app/home-strip.css +9 -1
  136. package/src/serve/hub-app/home-strip.tsx +7 -6
  137. package/src/serve/hub-app/home.html +5 -0
  138. package/src/serve/hub-app/hub-app.tsx +49 -5
  139. package/src/serve/hub-app/hub.css +29 -11
  140. package/src/serve/hub-app/icons.tsx +16 -1
  141. package/src/serve/hub-app/identities-st.ts +210 -0
  142. package/src/serve/hub-app/identities-view.tsx +352 -0
  143. package/src/serve/hub-app/identities.css +48 -0
  144. package/src/serve/hub-app/identity-address.ts +52 -0
  145. package/src/serve/hub-app/inbox-st.ts +59 -6
  146. package/src/serve/hub-app/inbox-view.tsx +48 -6
  147. package/src/serve/hub-app/inbox.css +12 -1
  148. package/src/serve/hub-app/index.html +3 -0
  149. package/src/serve/hub-app/keys.ts +10 -2
  150. package/src/serve/hub-app/list-walk.ts +89 -0
  151. package/src/serve/hub-app/machine-st.ts +12 -0
  152. package/src/serve/hub-app/media-view.tsx +2 -1
  153. package/src/serve/hub-app/pages-frames.tsx +134 -0
  154. package/src/serve/hub-app/pages-svc.ts +111 -0
  155. package/src/serve/hub-app/palette-st.ts +18 -3
  156. package/src/serve/hub-app/palette-view.tsx +9 -2
  157. package/src/serve/hub-app/planned-view.tsx +2 -1
  158. package/src/serve/hub-app/project-list.css +18 -14
  159. package/src/serve/hub-app/project-list.tsx +88 -49
  160. package/src/serve/hub-app/projects-svc.ts +33 -3
  161. package/src/serve/hub-app/repo-sections.ts +19 -2
  162. package/src/serve/hub-app/repo-st.ts +75 -19
  163. package/src/serve/hub-app/review/review-cells.tsx +3 -3
  164. package/src/serve/hub-app/review/review-kit.ts +30 -7
  165. package/src/serve/hub-app/review/review-page.tsx +1 -1
  166. package/src/serve/hub-app/review/review-st.ts +19 -8
  167. package/src/serve/hub-app/review/review-thread.tsx +11 -9
  168. package/src/serve/hub-app/review/review-views.tsx +84 -19
  169. package/src/serve/hub-app/review/thread-st.ts +1 -10
  170. package/src/serve/hub-app/review/trailer-page.tsx +2 -1
  171. package/src/serve/hub-app/review.css +17 -8
  172. package/src/serve/hub-app/site/site-part.tsx +173 -0
  173. package/src/serve/hub-app/site/site-st.ts +157 -0
  174. package/src/serve/hub-app/site.css +35 -0
  175. package/src/serve/hub-app/social/calendar.tsx +182 -0
  176. package/src/serve/hub-app/social/comms-page.tsx +306 -0
  177. package/src/serve/hub-app/social/kit.tsx +244 -0
  178. package/src/serve/hub-app/social/post-card.tsx +456 -0
  179. package/src/serve/hub-app/social/problems.tsx +60 -0
  180. package/src/serve/hub-app/social/social-model.ts +154 -0
  181. package/src/serve/hub-app/social/social-page.tsx +674 -0
  182. package/src/serve/hub-app/social/social-st.ts +986 -0
  183. package/src/serve/hub-app/social.css +289 -0
  184. package/src/serve/hub-app/stores/stores-page.tsx +311 -0
  185. package/src/serve/hub-app/stores/stores-st.ts +286 -0
  186. package/src/serve/hub-app/stores.css +54 -0
  187. package/src/serve/hub-app/timeline-geometry.ts +1 -1
  188. package/src/serve/hub-app/timeline-view.tsx +3 -2
  189. package/src/serve/hub-app/tree-build.ts +6 -0
  190. package/src/serve/hub-app/tree-row.tsx +27 -4
  191. package/src/serve/hub-app/tree-svc.ts +18 -49
  192. package/src/serve/hub-app/veille/veille-page.tsx +514 -0
  193. package/src/serve/hub-app/veille/veille-st.ts +443 -0
  194. package/src/serve/hub-app/veille.css +84 -0
  195. package/src/serve/hub-runtime.ts +14 -9
  196. package/src/serve/project-gutter-route.ts +44 -12
  197. package/src/serve/run-lanes.ts +7 -4
  198. package/src/serve/same-origin.ts +1 -1
  199. package/src/serve/serve-hub.ts +20 -12
  200. package/src/serve/tracked-watch.ts +24 -3
  201. package/src/serve/warm-cell.ts +5 -1
  202. package/src/shipkit-files.ts +15 -4
  203. package/src/shipkit.ts +0 -1
  204. package/src/shot/box.ts +162 -0
  205. package/src/shot/browser-slot.ts +62 -0
  206. package/src/shot/client.ts +43 -7
  207. package/src/shot/clip-encoder.ts +93 -12
  208. package/src/shot/film-box.ts +188 -0
  209. package/src/shot/shooter.ts +50 -15
  210. package/src/shot/shot-ask.ts +10 -2
  211. package/src/shot/stepped-clip.ts +5 -4
  212. package/src/site/desk.ts +242 -0
  213. package/src/site/routes.ts +66 -0
  214. package/src/site/unit.ts +62 -0
  215. package/src/social/brands.ts +22 -0
  216. package/src/social/compose.ts +97 -0
  217. package/src/social/desk-index.ts +123 -0
  218. package/src/social/desk-wire.ts +64 -0
  219. package/src/social/drafts.ts +183 -0
  220. package/src/social/house.ts +24 -0
  221. package/src/social/load.ts +319 -0
  222. package/src/social/md.ts +70 -0
  223. package/src/social/media-facts.ts +53 -0
  224. package/src/social/media-kind.ts +189 -0
  225. package/src/social/media-limit.ts +42 -0
  226. package/src/social/media-of.ts +30 -0
  227. package/src/social/migrate.ts +123 -0
  228. package/src/social/open.ts +17 -0
  229. package/src/social/post-url.ts +158 -0
  230. package/src/social/presence.ts +332 -0
  231. package/src/social/public-read.ts +53 -0
  232. package/src/social/publish/bluesky.ts +168 -0
  233. package/src/social/publish/discord.ts +76 -0
  234. package/src/social/publish/index.ts +24 -0
  235. package/src/social/publish/secret.ts +13 -0
  236. package/src/social/push.ts +31 -0
  237. package/src/social/richtext.ts +37 -0
  238. package/src/social/routes.ts +180 -0
  239. package/src/social/stats.ts +134 -0
  240. package/src/social/text.ts +267 -0
  241. package/src/social/tracker-route.ts +39 -0
  242. package/src/social/tracker.ts +255 -0
  243. package/src/social/unit.ts +53 -0
  244. package/src/social/writes.ts +130 -0
  245. package/src/start-repo.ts +14 -9
  246. package/src/stores/collection.ts +27 -0
  247. package/src/stores/desk.ts +336 -0
  248. package/src/stores/model.ts +187 -0
  249. package/src/stores/routes.ts +126 -0
  250. package/src/stores/unit.ts +57 -0
  251. package/src/suite/calibrate.ts +127 -0
  252. package/src/suite/core-counters.ts +91 -0
  253. package/src/suite/judge-suites.ts +94 -34
  254. package/src/suite/suite-cli.ts +44 -10
  255. package/src/suite/suite-cpu-preload.ts +34 -9
  256. package/src/trailer/adapter.ts +4 -0
  257. package/src/trailer/build.ts +42 -11
  258. package/src/trailer/ffmpeg.ts +11 -0
  259. package/src/trailer/footage.ts +30 -13
  260. package/src/trailer/grammar.ts +18 -2
  261. package/src/trailer/graph.ts +28 -6
  262. package/src/trailer/passage.ts +17 -5
  263. package/src/trailer/plan.ts +74 -3
  264. package/src/trailer/stitch.ts +67 -26
  265. package/src/trailer/url.ts +1 -1
  266. package/src/trailer/versions.ts +24 -0
  267. package/src/ts/gate-typecheck.ts +32 -0
  268. package/src/ts/typecheck-cli.ts +9 -11
  269. package/src/tui/tui-app.tsx +0 -1
  270. package/src/veille/asks.ts +155 -0
  271. package/src/veille/auto.ts +31 -0
  272. package/src/veille/batch.ts +27 -0
  273. package/src/veille/chrome.ts +127 -0
  274. package/src/veille/collection.ts +28 -0
  275. package/src/veille/desk.ts +242 -0
  276. package/src/veille/identity.ts +80 -0
  277. package/src/veille/import.ts +68 -0
  278. package/src/veille/log.ts +183 -0
  279. package/src/veille/platforms.ts +118 -0
  280. package/src/veille/reads.ts +66 -0
  281. package/src/veille/replied.ts +110 -0
  282. package/src/veille/routes.ts +185 -0
  283. package/src/veille/service.ts +81 -0
  284. package/src/veille/watch.ts +116 -0
  285. package/src/veille/worth.ts +46 -0
  286. package/src/wiki/scan-md.ts +18 -0
  287. package/src/collections/posts.ts +0 -142
  288. package/src/contracts/manifests/social.contract.ts +0 -20
  289. package/src/scaffold/files/agent-coding.md +0 -35
  290. package/src/ts/typecheck-cache.ts +0 -11
@@ -0,0 +1,126 @@
1
+ // the home's identities page (wiki build/shipkit/home.md, Identities): every identity, its accounts, the repos that
2
+ // speak as it, and where its data lives on disk. `POST /api/home/identities/open` opens one of those places in VS Code
3
+ // or the Finder; it names an identity, a place and a repo, never a path
4
+ import { existsSync, readdirSync } from 'node:fs'
5
+ import { homedir } from 'node:os'
6
+ import { openInCode } from '../serve/project-gutter-route.ts'
7
+ import { houseRepoRoots } from '../social/house.ts'
8
+ import { draftsDir } from '../social/load.ts'
9
+ import { veilleLogDir } from '../veille/identity.ts'
10
+ import { identitiesDir, readIdentities, type Identities, type Identity } from './identities.ts'
11
+ import { railOf, speakerIdOf, type RailIdentity } from './machine.ts'
12
+
13
+ /** a place on disk that holds an identity's data */
14
+ export type DataPlace = {
15
+ place: 'folder' | 'pictures' | 'veille' | 'drafts'
16
+ /** the repo, for a drafts folder */
17
+ repo: string | null
18
+ /** what it holds, in words */
19
+ label: string
20
+ /** the path, `~` for the home */
21
+ shown: string
22
+ exists: boolean
23
+ /** the drafts in it, the days of the Veille log; null where nothing is counted */
24
+ count: number | null
25
+ }
26
+
27
+ export type MachineAccount = { id: string; name: string; handle: string; live: string; profile: string; automation: string }
28
+
29
+ export type MachineIdentity = RailIdentity & {
30
+ bio: string
31
+ site: string
32
+ siteRepo: string
33
+ accounts: MachineAccount[]
34
+ repos: string[]
35
+ data: DataPlace[]
36
+ }
37
+
38
+ export type IdentitiesAnswer = {
39
+ dir: string | null
40
+ identities: MachineIdentity[]
41
+ /** repos whose `speaksAs` no folder holds */
42
+ strays: { repo: string; speaksAs: string }[]
43
+ errors: string[]
44
+ }
45
+
46
+ const tilde = (abs: string): string => (abs.startsWith(homedir() + '/') ? `~${abs.slice(homedir().length)}` : abs)
47
+
48
+ const count = (dir: string, keep: (name: string) => boolean): number | null => {
49
+ try {
50
+ return readdirSync(dir).filter(keep).length
51
+ } catch {
52
+ return null
53
+ }
54
+ }
55
+
56
+ type Repo = { name: string; path: string; speaksAs: string | undefined }
57
+
58
+ /** each place of an identity's data, with its absolute path */
59
+ function placesOf(i: Identity, repos: Repo[], ids: Identities): (DataPlace & { abs: string })[] {
60
+ const mine = repos.filter((r) => speakerIdOf(r.speaksAs, ids) === i.id)
61
+ const out: (DataPlace & { abs: string })[] = [
62
+ { place: 'folder', repo: null, label: 'its profile, accounts and places (identity.md, accounts/)', abs: i.dir, shown: '', exists: true, count: null },
63
+ ]
64
+ if (i.files != null && i.files !== i.dir) out.push({ place: 'pictures', repo: null, label: 'its pictures (files: in identity.md)', abs: i.files, shown: '', exists: existsSync(i.files), count: null })
65
+ const log = veilleLogDir(i.id)
66
+ out.push({ place: 'veille', repo: null, label: 'its Veille log, this machine only', abs: log, shown: '', exists: existsSync(log), count: count(log, (n) => n.endsWith('.jsonl')) })
67
+ for (const r of mine) {
68
+ const d = draftsDir(r.path)
69
+ out.push({ place: 'drafts', repo: r.name, label: `the drafts of ${r.name}`, abs: d, shown: '', exists: existsSync(d), count: count(d, (n) => !n.startsWith('.')) })
70
+ }
71
+ return out.map((p) => ({ ...p, shown: tilde(p.abs) }))
72
+ }
73
+
74
+ async function read(root: string): Promise<{ ids: Identities; repos: Repo[] }> {
75
+ return { ids: readIdentities(await identitiesDir(root)), repos: await houseRepoRoots(root) }
76
+ }
77
+
78
+ export async function identitiesAnswer(root: string): Promise<IdentitiesAnswer> {
79
+ const { ids, repos } = await read(root)
80
+ const known = new Set(ids.identities.map((i) => i.id))
81
+ return {
82
+ dir: ids.dir == null ? null : tilde(ids.dir),
83
+ identities: ids.identities.map((i) => ({
84
+ ...railOf(i),
85
+ bio: i.rows.find((r) => r.field === 'bio')?.value ?? '',
86
+ site: i.site,
87
+ siteRepo: i.siteRepo,
88
+ accounts: i.accounts.map((a) => ({ id: a.id, name: a.name, handle: a.handle, live: a.live, profile: a.profile, automation: a.automation })),
89
+ repos: repos.filter((r) => speakerIdOf(r.speaksAs, ids) === i.id).map((r) => r.name),
90
+ data: placesOf(i, repos, ids).map(({ abs: _abs, ...p }) => p),
91
+ })),
92
+ strays: repos.filter((r) => r.speaksAs != null && !known.has(r.speaksAs)).map((r) => ({ repo: r.name, speaksAs: r.speaksAs! })),
93
+ errors: ids.errors,
94
+ }
95
+ }
96
+
97
+ /** what opens a place: VS Code, or the Finder */
98
+ export type Opener = { code: (abs: string) => void; finder: (abs: string) => void }
99
+
100
+ const OPEN: Opener = {
101
+ code: openInCode,
102
+ finder: (abs) => {
103
+ if (process.platform !== 'darwin') throw new Error('the Finder is macOS only')
104
+ Bun.spawn(['open', abs], { stdio: ['ignore', 'ignore', 'ignore'] }).unref()
105
+ },
106
+ }
107
+
108
+ /** null when the path is not this route's */
109
+ export async function identitiesRoute(req: Request, path: string, root: string, open: Opener = OPEN): Promise<Response | null> {
110
+ if (path === '/api/home/identities.json') return Response.json(await identitiesAnswer(root), { headers: { 'cache-control': 'no-store' } })
111
+ if (path !== '/api/home/identities/open' || req.method !== 'POST') return null
112
+ const b = (await req.json().catch(() => ({}))) as { id?: unknown; place?: unknown; repo?: unknown; app?: unknown }
113
+ if (b.app !== 'code' && b.app !== 'finder') return new Response('app must be code or finder', { status: 400 })
114
+ const { ids, repos } = await read(root)
115
+ const i = ids.identities.find((x) => x.id === b.id)
116
+ if (i == null) return new Response(`no identity ${JSON.stringify(b.id)} (${ids.identities.map((x) => x.id).join(', ') || 'none'})`, { status: 404 })
117
+ const hit = placesOf(i, repos, ids).find((p) => p.place === b.place && (p.repo ?? null) === (b.repo ?? null))
118
+ if (hit == null) return new Response(`${i.id} has no place ${JSON.stringify(b.place)}${b.repo == null ? '' : ` in ${JSON.stringify(b.repo)}`}`, { status: 404 })
119
+ if (!existsSync(hit.abs)) return new Response(`${hit.shown} does not exist yet`, { status: 404 })
120
+ try {
121
+ open[b.app](hit.abs)
122
+ } catch (e) {
123
+ return new Response((e as Error).message, { status: 400 })
124
+ }
125
+ return Response.json({ ok: true, opened: hit.shown })
126
+ }
@@ -0,0 +1,62 @@
1
+ // the identities as the machine's surfaces show them (wiki build/shipkit/social.md, Identities): the project list's
2
+ // headers (`railIdentities`: a name, a colour, a mark) and the repo each row speaks as. Read again only when an
3
+ // `identity.md` of the folder moves, so the list's 5 s poll costs a few stats
4
+ import { existsSync, readdirSync, statSync } from 'node:fs'
5
+ import { join } from 'node:path'
6
+ import { readIdentities, speakerOf, type Identities, type Identity } from './identities.ts'
7
+
8
+ /** one identity as a header of the project list draws it */
9
+ export type RailIdentity = {
10
+ id: string
11
+ name: string
12
+ default: boolean
13
+ /** its first brand colour, a hex; null when its brand names none */
14
+ colour: string | null
15
+ /** the url of its mark (the first file of its profile's avatar row), null with none: the initial on its colour */
16
+ mark: string | null
17
+ }
18
+
19
+ const HEX = /^#[0-9a-f]{6}$/i
20
+
21
+ export const colourOf = (i: Identity): string | null => i.brand.find((r) => HEX.test(r.value))?.value ?? null
22
+
23
+ /** the avatar's file, absolute: the first file its profile's avatar row names */
24
+ export function markFile(i: Identity): string | null {
25
+ const f = i.rows.find((r) => r.field === 'avatar')?.files[0]
26
+ return f == null || i.files == null ? null : join(i.files, f)
27
+ }
28
+
29
+ const stampOf = (abs: string): number => {
30
+ try {
31
+ return Math.round(statSync(abs).mtimeMs)
32
+ } catch {
33
+ return 0
34
+ }
35
+ }
36
+
37
+ /** the folder's listing and each identity.md's mtime: what moves when an identity is added, renamed or edited */
38
+ function folderStamp(dir: string | null): string {
39
+ if (dir == null || !existsSync(dir)) return `${dir}:none`
40
+ return readdirSync(dir).sort().map((id) => `${id}:${stampOf(join(dir, id, 'identity.md'))}`).join('|')
41
+ }
42
+
43
+ /** the url the gutter serves an identity's mark at (project-gutter-route.ts), its stamp in it */
44
+ export const markUrl = (i: Identity): string | null => {
45
+ const f = markFile(i)
46
+ return f == null ? null : `/api/projects/identity-mark/${encodeURIComponent(i.id)}?v=${stampOf(f)}`
47
+ }
48
+
49
+ export const railOf = (i: Identity): RailIdentity => ({ id: i.id, name: i.name, default: i.default, colour: colourOf(i), mark: markUrl(i) })
50
+
51
+ /** the identities of a folder, read once per change of an identity.md; one cache per caller */
52
+ export function identityCache(): (dir: string | null) => Identities {
53
+ let held: { dir: string | null; stamp: string; ids: Identities } | null = null
54
+ return (dir) => {
55
+ const stamp = folderStamp(dir)
56
+ if (held == null || held.dir !== dir || held.stamp !== stamp) held = { dir, stamp, ids: readIdentities(dir) }
57
+ return held.ids
58
+ }
59
+ }
60
+
61
+ /** the id a repo speaks as: its own `speaksAs`, else the default; null on a machine with no identity, or an id no folder holds */
62
+ export const speakerIdOf = (speaksAs: string | undefined, ids: Identities): string | null => speakerOf(speaksAs, ids)?.id ?? null
package/src/init-repo.ts CHANGED
@@ -27,7 +27,7 @@ const CONFIG_TEMPLATE = (name: string): string => `import { defineRepo } from 'r
27
27
  export default defineRepo({
28
28
  name: '${name}',
29
29
  venues: [], // e.g. ['itch', 'steam'], selects which .shipkit/<venue>/ contracts are REQUIRED
30
- social: [], // e.g. ['x', 'discord'], the .shipkit/social/<channel>/ post folders (+ .shipkit/discord/)
30
+ // speaksAs: 'me', // the identity that speaks for this repo (sk identities); unset, the default one
31
31
  tasks: [], // repo commit-gate tasks; deps double as race guards
32
32
  // lint, typecheck, imports:check and cycles are cached on the tracked tree.
33
33
  // \`test\` runs every time until you say what it reads, because an
@@ -16,7 +16,7 @@
16
16
  // measures a check, and the store is only ever the history of the other two.
17
17
  import type { RunRow, RunStatus } from './run-log.ts'
18
18
  import { readRuns, runsPath, runsStamp } from './run-log.ts'
19
- import { answersDb, answersStamp, listAnswers } from './store.ts'
19
+ import { answerMeasures, answersDb, answersStamp } from './store.ts'
20
20
 
21
21
  /** one measurement read back off the store */
22
22
  export type StoreSample = { key: string; at: number; ms: number; status: RunStatus }
@@ -99,19 +99,16 @@ export function mergeCheckStats(o: { runs: RunRow[]; store: StoreSample[] }): Ma
99
99
  export function scanCheckStore(db: string, checks: { id: string }[]): StoreSample[] {
100
100
  const ids = new Set(checks.map((c) => c.id))
101
101
  const out: StoreSample[] = []
102
- for (const r of listAnswers(db, 'checks')) {
103
- if (!ids.has(r.name)) continue
104
- try {
105
- const p = JSON.parse(r.payload) as { measuredMs?: number; status?: RunStatus }
106
- if (typeof p.measuredMs !== 'number') continue
107
- out.push({ key: r.name, at: r.at, ms: p.measuredMs, status: p.status === 'warn' ? 'warn' : 'pass' })
108
- } catch { /* a row that does not parse is no sample */ }
102
+ for (const r of answerMeasures(db, 'checks')) {
103
+ if (!ids.has(r.name) || typeof r.ms !== 'number') continue
104
+ out.push({ key: r.name, at: r.at, ms: r.ms, status: r.status === 'warn' ? 'warn' : 'pass' })
109
105
  }
110
106
  return out
111
107
  }
112
108
 
113
109
  type Cached = { stamp: string; stats: Map<string, CheckStat> }
114
110
  const cache = new Map<string, Cached>()
111
+ const stores = new Map<string, { key: string; samples: StoreSample[] }>()
115
112
 
116
113
  /** the per check numbers for a repo, cached on what the two sources look like
117
114
  * from the outside: a count and newest stamp of each, since the hub asks on
@@ -123,7 +120,11 @@ export function checkStatsFor(root: string, checks: { id: string }[], o?: { fres
123
120
  const stamp = `${checks.length}:${answersStamp(db, 'checks')}:${runsStamp(record)}`
124
121
  const hit = cache.get(root)
125
122
  if (o?.fresh !== true && hit != null && hit.stamp === stamp) return hit.stats
126
- const stats = mergeCheckStats({ runs: readRuns(record), store: scanCheckStore(db, checks) })
123
+ // the store moves only when a check writes an answer; a run moves only the record
124
+ const storeKey = `${checks.map((c) => c.id).join(',')}:${answersStamp(db, 'checks')}`
125
+ let store = stores.get(root)
126
+ if (store?.key !== storeKey) stores.set(root, (store = { key: storeKey, samples: scanCheckStore(db, checks) }))
127
+ const stats = mergeCheckStats({ runs: readRuns(record), store: store.samples })
127
128
  cache.set(root, { stamp, stats })
128
129
  return stats
129
130
  }
@@ -17,6 +17,8 @@ import type { CheckCtx } from '../core/check-ctx.ts'
17
17
  import { type RepoConfig } from '../repo-config.ts'
18
18
  import { auditedExtras, ignoredFor, readAuditReport } from '../core/audit-report.ts'
19
19
  import { listRepoFiles, resolveFloor, slotDescription, type FloorResolution } from '../core/floor.ts'
20
+ import { treeRev } from '../core/tree-rev.ts'
21
+ import { yieldLoop } from '../core/loop-watch.ts'
20
22
  import { discoverLegacyChecks } from '../core/discover-legacy-checks.ts'
21
23
  import { checkFileRunBy } from '../core/legacy-shapes.ts'
22
24
  import { ruleCacheExtra } from '../rules/rule.ts'
@@ -258,6 +260,9 @@ function fileRuns(def: CheckDef, id: string, c: RepoConfig, env: CheckEnv): Reso
258
260
  return withRepoOff(base, repoOff(c, id))
259
261
  }
260
262
 
263
+ /** check files a compose reads (their key, their code) before it gives the loop back */
264
+ const COMPOSE_STEP = 8
265
+
261
266
  /** THE enumeration. Everything below reads it, nothing else walks. */
262
267
  export async function composeChecks(root: string, c: RepoConfig, o: ComposeOpts = {}): Promise<GateCheck[]> {
263
268
  const out: GateCheck[] = []
@@ -295,7 +300,11 @@ export async function composeChecks(root: string, c: RepoConfig, o: ComposeOpts
295
300
  // carries the tier flag rather than one task id: a repo names its suites
296
301
  // what it likes, and a gate that guesses which one is the tests will miss
297
302
  // one.
303
+ // a compose is seconds of sync work on a large repo: the loop goes back to the pages between its parts (wiki
304
+ // build/shipkit/home.md, Nothing heavy on the daemon's loop)
305
+ await yieldLoop()
298
306
  const rootTest = rootTestKey(root, c, floor)
307
+ await yieldLoop()
299
308
  // a task that declares nothing is keyed on the whole work tree, plus the
300
309
  // gitignored paths it reads. The work tree sees no ignored file, so those
301
310
  // are named: by the config, and by the kept traced audit (SK031), whose
@@ -387,7 +396,9 @@ export async function composeChecks(root: string, c: RepoConfig, o: ComposeOpts
387
396
  // every `*.check.ts` this repo and the toolkit declare
388
397
  const configs = new Map<string, RvtConfig>()
389
398
  const texts = new Map<string, string>()
399
+ let n = 0
390
400
  for (const u of checks) {
401
+ if (++n % COMPOSE_STEP === 0) await yieldLoop()
391
402
  const runs = fileRuns(u.def, u.id, c, env)
392
403
  const cache = declOfCache(u.def.cache, env)
393
404
  // a body keyed on what it reads through its context (git-key.ts
@@ -559,9 +570,29 @@ export async function composeChecks(root: string, c: RepoConfig, o: ComposeOpts
559
570
 
560
571
  /** every check the gate knows, with its metadata. */
561
572
  export async function gateInventory(root: string, c: RepoConfig, o: ComposeOpts = {}): Promise<CheckRow[]> {
562
- return (await composeChecks(root, c, o)).map((g) => g.row)
573
+ const rev = treeRev(root)
574
+ if (rev == null) return (await composeChecks(root, c, o)).map((g) => g.row)
575
+ const tier = o.tier ?? 'quick'
576
+ const byTier = inventories.get(c) ?? new Map<string, KeptInventory>()
577
+ inventories.set(c, byTier)
578
+ const key = `${root}\0${tier}`
579
+ const held = byTier.get(key)
580
+ if (held != null && held.rev === rev && Date.now() - held.at < INVENTORY_KEEP_MS) return (await held.rows).slice()
581
+ const rows = composeChecks(root, c, o).then((all) => all.map((g) => g.row))
582
+ byTier.set(key, { rev, at: Date.now(), rows })
583
+ rows.catch(() => { if (byTier.get(key)?.rows === rows) byTier.delete(key) })
584
+ return (await rows).slice()
563
585
  }
564
586
 
587
+ /** how long a kept inventory stands for what no save moves: the cache keys of its checks read a few things outside the
588
+ * tree (the house repos, the hooks path, the keyword files) */
589
+ export const INVENTORY_KEEP_MS = 60_000
590
+ type KeptInventory = { rev: number; at: number; rows: Promise<CheckRow[]> }
591
+ /** the read side's inventory (the pages, the plan, the timeline), by config and tier, kept while the tree's revision
592
+ * holds (core/tree-rev.ts): a compose costs a repo listing and every check's key, and the warm answers ask it several
593
+ * times a refresh. A gate composes its own, never from here */
594
+ const inventories = new WeakMap<RepoConfig, Map<string, KeptInventory>>()
595
+
565
596
  /** the same list, as the runner takes it */
566
597
  export async function gateRunnables(root: string, c: RepoConfig, o: ComposeOpts = {}): Promise<RunnableCheck[]> {
567
598
  return (await composeChecks(root, c, o)).map((g) => g.runnable)
@@ -0,0 +1,112 @@
1
+ // a whole table of a run record, read again only once the record moved: the daemon's warm answers read every run and
2
+ // every suite row of each repo on each compute (thousands of rows, a sync read that held its loop). The stamp is the
3
+ // db file's and its WAL's time and size: any write moves one of them. A table that only grows at its end and loses its
4
+ // oldest rows (runs, suites: every write sweeps what is past the keep window) is read whole once, then by the rows
5
+ // written since, the swept ones dropped from its front; what does not add up reads it whole again. `warmTable` is the
6
+ // same whole read in pages, the loop given back between two (wiki build/shipkit/home.md, Nothing heavy on the
7
+ // daemon's loop)
8
+ import { statSync } from 'fs'
9
+ import type { Database } from 'bun:sqlite'
10
+ import { yieldLoop } from '../core/loop-watch.ts'
11
+ import { openDb } from './db.ts'
12
+
13
+ const one = (p: string): string => {
14
+ try {
15
+ const s = statSync(p)
16
+ return `${s.mtimeMs}:${s.size}`
17
+ } catch {
18
+ return '-'
19
+ }
20
+ }
21
+
22
+ /** a record file's stamp: the db and its WAL */
23
+ export const recordFileStamp = (path: string): string => `${one(path)}|${one(`${path}-wal`)}`
24
+
25
+ /** a table that grows at its end, as its reader reads it: `rowid as rid` and `at` among its columns */
26
+ export interface AppendTable<T> {
27
+ /** the table's name */
28
+ table: string
29
+ /** its columns as the select names them */
30
+ columns: string
31
+ /** one row as the callers take it */
32
+ row: (raw: Record<string, unknown>) => T
33
+ }
34
+
35
+ /** rows a page of a whole read holds */
36
+ const PAGE = 25_000
37
+
38
+ type Rowed<T> = { rid: number; at: number; row: T }
39
+ type Held<T> = { stamp: string; list: Rowed<T>[]; last: number }
40
+ const tables = new Map<string, Held<unknown>>()
41
+
42
+ const pageOf = <T>(db: Database, t: AppendTable<T>, after: number, limit: number | null): Rowed<T>[] =>
43
+ (db.query(`select ${t.columns} from ${t.table} where rowid > ? order by rowid asc${limit == null ? '' : ` limit ${limit}`}`).all(after) as Record<string, unknown>[])
44
+ .map((r) => ({ rid: Number(r.rid), at: Number(r.at), row: t.row(r) }))
45
+
46
+ /** oldest first: by `at`, then by rowid, the order every reader of the record keeps */
47
+ const byAt = (a: Rowed<unknown>, b: Rowed<unknown>): number => a.at - b.at || a.rid - b.rid
48
+
49
+ const heldOf = <T>(stamp: string, list: Rowed<T>[]): Held<T> => ({ stamp, list: list.sort(byAt), last: list.reduce((m, x) => Math.max(m, x.rid), 0) })
50
+
51
+ /** what is held, its swept front dropped and the rows written since appended; null when that does not add up */
52
+ function grown<T>(db: Database, t: AppendTable<T>, held: Held<T>, stamp: string): Held<T> | null {
53
+ const still = Number((db.query(`select count(*) as n from ${t.table} where rowid <= ?`).get(held.last) as { n: number }).n)
54
+ const swept = held.list.length - still
55
+ if (swept < 0) return null
56
+ const list = held.list.slice(swept)
57
+ if (swept > 0) {
58
+ const first = db.query(`select min(at) as at from ${t.table} where rowid <= ?`).get(held.last) as { at: number | null }
59
+ if ((list[0]?.at ?? null) !== (first.at == null ? null : Number(first.at))) return null
60
+ }
61
+ const fresh = pageOf(db, t, held.last, null).sort(byAt)
62
+ const tail = list.at(-1)
63
+ if (fresh.length > 0 && tail != null && byAt(fresh[0]!, tail) < 0) return null
64
+ list.push(...fresh)
65
+ return { stamp, list, last: fresh.reduce((m, x) => Math.max(m, x.rid), held.last) }
66
+ }
67
+
68
+ /** every row of the table, oldest first; an unreadable record is none */
69
+ export function keptTable<T>(path: string, t: AppendTable<T>): T[] {
70
+ const key = `${t.table}\0${path}`
71
+ const stamp = recordFileStamp(path)
72
+ const held = tables.get(key) as Held<T> | undefined
73
+ if (held != null && held.stamp === stamp) return held.list.map((x) => x.row)
74
+ const opened = openDb(path, { create: false })
75
+ if (opened == null) return []
76
+ try {
77
+ const next = (held == null ? null : grown(opened.db, t, held, stamp)) ?? heldOf(stamp, pageOf(opened.db, t, 0, null))
78
+ tables.set(key, next)
79
+ return next.list.map((x) => x.row)
80
+ } catch {
81
+ return []
82
+ } finally {
83
+ try { opened.db.close() } catch { /* already gone */ }
84
+ }
85
+ }
86
+
87
+ /** a table not held yet, read whole in pages with the loop given back between two, so the sync reader after it finds
88
+ * it held and reads only the rows written since */
89
+ export async function warmTable<T>(path: string, t: AppendTable<T>): Promise<void> {
90
+ const key = `${t.table}\0${path}`
91
+ if (tables.has(key)) return
92
+ // the stamp before the first page: a write during the read moves it, and the next reader reads what came after
93
+ const stamp = recordFileStamp(path)
94
+ const all: Rowed<T>[] = []
95
+ for (let after = 0; ; ) {
96
+ const opened = openDb(path, { create: false })
97
+ if (opened == null) return
98
+ let page: Rowed<T>[]
99
+ try {
100
+ page = pageOf(opened.db, t, after, PAGE)
101
+ } catch {
102
+ return
103
+ } finally {
104
+ try { opened.db.close() } catch { /* already gone */ }
105
+ }
106
+ for (const x of page) all.push(x)
107
+ if (page.length < PAGE) break
108
+ after = page.at(-1)!.rid
109
+ await yieldLoop()
110
+ }
111
+ if (!tables.has(key)) tables.set(key, heldOf(stamp, all))
112
+ }
@@ -15,6 +15,7 @@ import { relative } from 'path'
15
15
  import { listingWithoutVendored } from '../core/vendored.ts'
16
16
  import { readVendored } from '../core/vendored-read.ts'
17
17
  import { GitScanError, scanPaths, WHOLE_TREE, type ScanResult } from './git-scan.ts'
18
+ import { keptOnTree } from '../core/tree-rev.ts'
18
19
 
19
20
  export class RepoView {
20
21
  private constructor(
@@ -34,6 +35,13 @@ export class RepoView {
34
35
  * still staged and hashed fresh, so the list is today's, and an unchanged
35
36
  * tree reuses the prior's answer */
36
37
  static open(root: string, prior?: RepoView | null): RepoView {
38
+ // with no prior, a process a save watch runs in (the daemon) keeps the view while no file moved: the scan
39
+ // stages and hashes the whole tree (core/tree-rev.ts)
40
+ if (prior == null) return keptOnTree(views, root, () => RepoView.scan(root))
41
+ return RepoView.scan(root, prior)
42
+ }
43
+
44
+ private static scan(root: string, prior?: RepoView | null): RepoView {
37
45
  const vendored = readVendored(root)
38
46
  try {
39
47
  const scan = scanPaths(root, [WHOLE_TREE], prior?.scan ?? undefined, { treeOnly: true })
@@ -52,6 +60,8 @@ export class RepoView {
52
60
  }
53
61
  }
54
62
 
63
+ const views = new Map<string, { rev: number; value: RepoView }>()
64
+
55
65
  /** no git: every file under the root, installs and dot dirs left out */
56
66
  function walk(root: string): string[] {
57
67
  try {
@@ -18,6 +18,7 @@
18
18
  // 3. SWEPT BY AGE, like the store beside it, because a run knows nothing
19
19
  // about the checks it did not run. The sweep is a DELETE now rather than a
20
20
  // rewrite of the whole file, so a row written while it runs is kept.
21
+ import { keptTable, warmTable, type AppendTable } from './record-kept.ts'
21
22
  import { Database } from 'bun:sqlite'
22
23
  import { existsSync } from 'fs'
23
24
  import type { Line } from '../core/wire.ts'
@@ -368,9 +369,12 @@ export function readLastResults(path: string): Record<string, { status: RunStatu
368
369
  if (opened == null) return {}
369
370
  const out: Record<string, { status: RunStatus; at: number; streak: number }> = {}
370
371
  try {
372
+ // per check id off the (id, at) index: its newest row, then the run of rows since its last other status. A
373
+ // scan of every row with a lookup each held the daemon's loop on a large record
371
374
  const rows = opened.db.query(`select l.id as id, l.status as status, l.at as at,
372
- (select count(*) from runs r where r.id = l.id and r.at > coalesce((select max(r2.at) from runs r2 where r2.id = l.id and r2.status != l.status), 0)) as streak
373
- from runs l where l.rowid = (select r3.rowid from runs r3 where r3.id = l.id order by r3.at desc, r3.rowid desc limit 1)`).all() as { id: string; status: string; at: number; streak: number }[]
375
+ (select count(*) from runs r where r.id = l.id and r.at > coalesce((select r2.at from runs r2 where r2.id = l.id and r2.status != l.status order by r2.at desc limit 1), 0)) as streak
376
+ from (select d.id as id, (select r3.rowid from runs r3 where r3.id = d.id order by r3.at desc, r3.rowid desc limit 1) as rid from (select distinct id from runs) d) x
377
+ join runs l on l.rowid = x.rid`).all() as { id: string; status: string; at: number; streak: number }[]
374
378
  for (const r of rows) out[r.id] = { status: r.status as RunStatus, at: Number(r.at), streak: Math.max(1, Number(r.streak)) }
375
379
  } catch {
376
380
  return {}
@@ -421,16 +425,17 @@ export function readWindowReadonly(path: string, since: number): { live: LiveRow
421
425
  /** every row the record holds, oldest first. A db that cannot be read is no
422
426
  * rows at all: it feeds a dashboard, and an empty history beats a crash. */
423
427
  export function readRuns(path: string): RunRow[] {
424
- const opened = openDb(path, { create: false })
425
- if (opened == null) return []
426
- try {
427
- const rows = opened.db.query(`${RUN_ROWS} order by r.at asc, r.rowid asc`).all() as RawRow[]
428
- return rows.map(runRow)
429
- } catch {
430
- return []
431
- } finally {
432
- try { opened.db.close() } catch { /* already gone */ }
433
- }
428
+ return keptTable(path, RUNS_TABLE)
429
+ }
430
+
431
+ /** the runs read whole in pages before a sync reader asks (record-kept.ts warmTable) */
432
+ export const warmRuns = (path: string): Promise<void> => warmTable(path, RUNS_TABLE)
433
+
434
+ /** every run row with the label of the invocation that wrote it (written in the same transaction, never changed) */
435
+ const RUNS_TABLE: AppendTable<RunRow> = {
436
+ table: 'runs',
437
+ columns: 'rowid as rid, run_id as runId, id, at, ms, status, replayed, (select i.label from invocations i where i.run_id = runs.run_id) as label',
438
+ row: (r) => runRow(r as unknown as RawRow),
434
439
  }
435
440
 
436
441
  type RawRow = { runId: string; id: string; at: number; ms: number; status: string; replayed: number; label: string | null }
@@ -103,8 +103,8 @@ export function invocationsOf(runs: RunRow[], invocations: InvocationRow[]): Tim
103
103
  for (const [runId, rows] of byRun) {
104
104
  const bars = rows.map(barOf).sort((a, b) => a.start - b.start || a.id.localeCompare(b.id))
105
105
  const inv = meta.get(runId)
106
- const first = Math.min(...bars.map((b) => b.start))
107
- const last = Math.max(...bars.map((b) => b.end))
106
+ const first = bars.reduce((a, b) => Math.min(a, b.start), Infinity)
107
+ const last = bars.reduce((a, b) => Math.max(a, b.end), -Infinity)
108
108
  const started = inv != null ? Math.min(inv.started, first) : first
109
109
  const ended = inv != null ? Math.max(inv.ended, last) : last
110
110
  out.push({
@@ -131,7 +131,11 @@ export function slowestChecks(runs: RunRow[], ceilings: Record<string, number>,
131
131
  const live = inventory == null ? null : new Set(inventory)
132
132
  const ms = new Map<string, number[]>()
133
133
  const quick = new Map<string, number[]>()
134
- const add = (m: Map<string, number[]>, id: string, v: number): void => { m.set(id, [...(m.get(id) ?? []), v]) }
134
+ const add = (m: Map<string, number[]>, id: string, v: number): void => {
135
+ const list = m.get(id)
136
+ if (list == null) m.set(id, [v])
137
+ else list.push(v)
138
+ }
135
139
  for (const r of runs) {
136
140
  if (r.replayed || r.status === 'skip') continue
137
141
  if (live != null && !live.has(r.id)) continue
@@ -141,7 +145,7 @@ export function slowestChecks(runs: RunRow[], ceilings: Record<string, number>,
141
145
  const mean = (list: number[]): number => Math.round(list.reduce((a, b) => a + b, 0) / list.length)
142
146
  const out: SlowCheck[] = []
143
147
  for (const [id, list] of ms) {
144
- const worstMs = Math.max(...list)
148
+ const worstMs = list.reduce((a, b) => (b > a ? b : a), -Infinity)
145
149
  const ceilingMs = ceilings[id] ?? null
146
150
  const budgetMs = budgets[id] ?? null
147
151
  const q = quick.get(id) ?? []
@@ -187,6 +187,12 @@ export class Answers {
187
187
  return this.with(READ_BUSY_MS, (h) => h.query('select name, at, payload from answers where ns = ?').all(ns) as { name: string; at: number; payload: string }[]) ?? []
188
188
  }
189
189
 
190
+ /** each answer's measured time and status, read out of its payload by sqlite: a population's payloads are tens of
191
+ * megabytes, and the hub's check stats read only these two fields */
192
+ measures(ns: string): { name: string; at: number; ms: unknown; status: unknown }[] {
193
+ return this.with(READ_BUSY_MS, (h) => h.query("select name, at, json_extract(payload, '$.measuredMs') as ms, json_extract(payload, '$.status') as status from answers where ns = ? and json_valid(payload)").all(ns) as { name: string; at: number; ms: unknown; status: unknown }[]) ?? []
194
+ }
195
+
190
196
  /** a cheap fingerprint of one population, so a reader can cache on it */
191
197
  stamp(ns: string): string {
192
198
  const r = this.with(READ_BUSY_MS, (h) => h.query('select count(*) as n, max(at) as last from answers where ns = ?').get(ns) as { n: number; last: number | null } | null)
@@ -230,6 +236,7 @@ export function withAnswers<R>(db: string, body: (a: Answers) => R): R {
230
236
 
231
237
  export const listAnswers = (db: string, ns: string): { name: string; at: number; payload: string }[] => withAnswers(db, (a) => a.list(ns))
232
238
  export const answersStamp = (db: string, ns: string): string => withAnswers(db, (a) => a.stamp(ns))
239
+ export const answerMeasures = (db: string, ns: string): { name: string; at: number; ms: unknown; status: unknown }[] => withAnswers(db, (a) => a.measures(ns))
233
240
  export const answersUse = (db: string): AnswersUse | null => withAnswers(db, (a) => a.use())
234
241
  export const sweepAnswers = (db: string, now: number, o?: { keepMs?: number; max?: number }): number | null => withAnswers(db, (a) => a.sweep(now, o))
235
242
 
@@ -6,6 +6,7 @@
6
6
  // Same file and same rules as the run record (ledger/run-log.ts): never read by
7
7
  // the gate, one transaction per write, swept by age with the other tables, and
8
8
  // a db that cannot be written costs the history one warn line, never a verdict.
9
+ import { keptTable, warmTable, type AppendTable } from './record-kept.ts'
9
10
  import { treePrefix } from '../core/nesting.ts'
10
11
  import { INSERT_SUITE, INSERT_SUITE_RUN, openDb } from './db.ts'
11
12
  import { runsPath, type RunStatus } from './run-log.ts'
@@ -114,13 +115,20 @@ const PHASES: readonly string[] = ['parallel', 'sequential', 'serial'] satisfies
114
115
 
115
116
  /** every suite row on record, oldest first. An unreadable db is none */
116
117
  export function readSuites(path: string): SuiteRow[] {
117
- const opened = openDb(path, { create: false })
118
- if (opened == null) return []
119
- try {
120
- const rows = opened.db.query('select at, file, ms, status, tier, budget_ms as budgetMs, check_id as checkId, unit, cpu_ms as cpuMs, phase, phase_ms as phaseMs, fail_line as failLine from suites order by at asc, rowid asc').all() as {
121
- at: number; file: string; ms: number; status: string; tier: string; budgetMs: number; checkId: string; unit: string; cpuMs: number | null; phase: string; phaseMs: number | null; failLine: string
122
- }[]
123
- return rows.map((r): SuiteRow => ({
118
+ return keptTable(path, SUITES_TABLE)
119
+ }
120
+
121
+ /** the suite rows read whole in pages before a sync reader asks (record-kept.ts warmTable) */
122
+ export const warmSuites = (path: string): Promise<void> => warmTable(path, SUITES_TABLE)
123
+
124
+ type RawSuite = { at: number; file: string; ms: number; status: string; tier: string; budgetMs: number; checkId: string; unit: string; cpuMs: number | null; phase: string; phaseMs: number | null; failLine: string }
125
+
126
+ const SUITES_TABLE: AppendTable<SuiteRow> = {
127
+ table: 'suites',
128
+ columns: 'rowid as rid, at, file, ms, status, tier, budget_ms as budgetMs, check_id as checkId, unit, cpu_ms as cpuMs, phase, phase_ms as phaseMs, fail_line as failLine',
129
+ row: (raw): SuiteRow => {
130
+ const r = raw as unknown as RawSuite
131
+ return {
124
132
  at: Number(r.at), file: String(r.file), ms: Number(r.ms), status: r.status === 'fail' ? 'fail' : 'pass',
125
133
  tier: r.tier === 'full' ? 'full' : 'quick', budgetMs: Number(r.budgetMs), check: String(r.checkId ?? ''), unit: String(r.unit ?? ''),
126
134
  // each one only where the record holds it, so a row written before
@@ -129,12 +137,8 @@ export function readSuites(path: string): SuiteRow[] {
129
137
  ...(PHASES.includes(r.phase) ? { phase: r.phase as SuitePhase } : {}),
130
138
  ...(r.phaseMs == null ? {} : { phaseMs: Number(r.phaseMs) }),
131
139
  ...(r.failLine == null || r.failLine === '' ? {} : { failLine: String(r.failLine) }),
132
- }))
133
- } catch {
134
- return []
135
- } finally {
136
- try { opened.db.close() } catch { /* already gone */ }
137
- }
140
+ }
141
+ },
138
142
  }
139
143
 
140
144
  /** every run of the suite runner on record, oldest first. An unreadable db,
@@ -4,8 +4,9 @@ import type { MediaKind } from './media-store/kind.ts'
4
4
  import { handKind, labelsInIndex } from './media-store/hand.ts'
5
5
  import { reviewMedia } from './review/media-kind.ts'
6
6
  import { trailerMedia } from './review/trailer-media.ts'
7
+ import { socialMedia } from './social/media-kind.ts'
7
8
 
8
- export const MEDIA_KINDS: readonly MediaKind[] = [reviewMedia, trailerMedia]
9
+ export const MEDIA_KINDS: readonly MediaKind[] = [reviewMedia, trailerMedia, socialMedia]
9
10
 
10
11
  /** the kinds of the code, then the generic kind of every other label the index holds (`sk media put`) */
11
12
  export function mediaKinds(): MediaKind[] {