@defrex/autobuild 1.10.0 → 1.11.1

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 (255) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +745 -69
  3. package/bin/ab-dispatch-generation.ts +3 -1
  4. package/docs/accounts.md +2 -1
  5. package/docs/answering-blocked-builds.md +20 -0
  6. package/docs/architecture.md +165 -29
  7. package/docs/build-store.md +10 -7
  8. package/docs/cli.md +33 -1
  9. package/docs/configuration-overview.md +4 -1
  10. package/docs/configuration.md +381 -29
  11. package/docs/dispatcher.md +64 -4
  12. package/docs/forges.md +7 -0
  13. package/docs/integration-tree.md +2 -2
  14. package/docs/operating.md +4 -2
  15. package/docs/operator-api.md +134 -6
  16. package/docs/operator-surfaces.md +85 -0
  17. package/docs/optimization-nodes.md +69 -11
  18. package/docs/plugin-authoring.md +37 -1
  19. package/docs/remote-store-protocol.md +94 -13
  20. package/docs/remote-ticket-protocol.md +40 -0
  21. package/docs/restacking.md +20 -4
  22. package/docs/setup.md +14 -2
  23. package/docs/ticket-dependencies.md +10 -3
  24. package/docs/ticket-sources.md +24 -2
  25. package/docs/tickets.md +7 -1
  26. package/docs/troubleshooting.md +8 -0
  27. package/docs/verification.md +4 -3
  28. package/docs/workspaces.md +3 -0
  29. package/package.json +9 -5
  30. package/packages/core/src/cli/accounts.ts +7 -2
  31. package/packages/core/src/cli/attention.ts +3 -1
  32. package/packages/core/src/cli/binary-direct.ts +2 -0
  33. package/packages/core/src/cli/binary-lifecycle.ts +2 -1
  34. package/packages/core/src/cli/build-control.ts +79 -1
  35. package/packages/core/src/cli/context.ts +4 -0
  36. package/packages/core/src/cli/dashboard/facts.ts +49 -53
  37. package/packages/core/src/cli/dashboard/header.ts +111 -0
  38. package/packages/core/src/cli/dashboard/model.ts +31 -39
  39. package/packages/core/src/cli/dashboard/objective-row.ts +46 -14
  40. package/packages/core/src/cli/dashboard/poll.ts +179 -76
  41. package/packages/core/src/cli/dashboard/render.ts +159 -230
  42. package/packages/core/src/cli/dashboard/row-text.ts +538 -0
  43. package/packages/core/src/cli/dashboard/timeline.ts +288 -0
  44. package/packages/core/src/cli/dashboard/vocabulary.ts +188 -0
  45. package/packages/core/src/cli/dispatch-args.ts +44 -1
  46. package/packages/core/src/cli/dispatch-frontend.ts +40 -40
  47. package/packages/core/src/cli/dispatch-launch-stop.ts +18 -0
  48. package/packages/core/src/cli/dispatch-launcher.ts +20 -7
  49. package/packages/core/src/cli/dispatch-web.ts +155 -0
  50. package/packages/core/src/cli/dispatch.ts +202 -38
  51. package/packages/core/src/cli/help.ts +87 -3
  52. package/packages/core/src/cli/init-validation.ts +3 -3
  53. package/packages/core/src/cli/main.ts +70 -6
  54. package/packages/core/src/cli/mcp.ts +35 -3
  55. package/packages/core/src/cli/objective.ts +1 -1
  56. package/packages/core/src/cli/operator-preference.ts +57 -0
  57. package/packages/core/src/cli/repo-lease.ts +2 -0
  58. package/packages/core/src/cli/repo-state.ts +56 -6
  59. package/packages/core/src/cli/repository-status.ts +105 -49
  60. package/packages/core/src/cli/status.ts +82 -1
  61. package/packages/core/src/cli/terminal-restore.ts +32 -7
  62. package/packages/core/src/cli/ticket.ts +98 -36
  63. package/packages/core/src/cli/wait.ts +14 -6
  64. package/packages/core/src/cli/watch.ts +20 -4
  65. package/packages/core/src/cli/web.ts +139 -0
  66. package/packages/core/src/config/live.ts +99 -14
  67. package/packages/core/src/config/load.ts +61 -20
  68. package/packages/core/src/config/local.ts +212 -0
  69. package/packages/core/src/config/pipeline-source.ts +2 -0
  70. package/packages/core/src/config/reference.ts +18 -0
  71. package/packages/core/src/config/schema.ts +45 -10
  72. package/packages/core/src/events/catalog.ts +4 -0
  73. package/packages/core/src/events/payloads.ts +97 -0
  74. package/packages/core/src/events/policy.ts +10 -0
  75. package/packages/core/src/events/repository.ts +46 -3
  76. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +381 -30
  77. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/017d8dd5bb6dd80b.json.gz +0 -0
  78. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/178e12f1759b7552.json.gz +0 -0
  79. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/4932c70a2af97faf.json.gz +0 -0
  80. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/536085773daf6b58.json.gz +0 -0
  81. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/6bd6275061aaffa5.json.gz +0 -0
  82. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/89625654b02e9ac1.json.gz +0 -0
  83. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a98af134be2da8a9.json.gz +0 -0
  84. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/d5d5ccca80a893d8.json.gz +0 -0
  85. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/f8155387eb5f375c.json.gz +0 -0
  86. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3c27f918b194e3b3.json +465 -0
  87. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/46196d8f0076496a.json +97 -0
  88. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/79f0e0f4ccd43ba2.json +455 -0
  89. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/859c09edac738823.json +1086 -0
  90. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a283c1f3462b1cc1.json +81 -0
  91. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a6e570fb126991ff.json +36 -0
  92. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a8acf22c968b6e3d.json +81 -0
  93. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/ba7b85895bf6698e.json +1153 -0
  94. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/fc66408cde0b6b04.json +637 -0
  95. package/packages/core/src/kernel/build-roster.ts +230 -0
  96. package/packages/core/src/kernel/dispatch-capacity.ts +4 -2
  97. package/packages/core/src/kernel/dispatch-status.ts +139 -0
  98. package/packages/core/src/kernel/engine.ts +43 -5
  99. package/packages/core/src/kernel/execution-intervals.ts +61 -0
  100. package/packages/core/src/kernel/generators/optimization-log.ts +101 -0
  101. package/packages/core/src/kernel/generators/repository-journals.ts +13 -0
  102. package/packages/core/src/kernel/leaf-restack-base.ts +33 -7
  103. package/packages/core/src/kernel/leaf-restack-state.ts +82 -3
  104. package/packages/core/src/kernel/log-index.ts +19 -0
  105. package/packages/core/src/kernel/optimization-admission.ts +244 -3
  106. package/packages/core/src/kernel/optimization.ts +183 -4
  107. package/packages/core/src/kernel/phase-failures.ts +121 -0
  108. package/packages/core/src/kernel/published-branch-head.ts +60 -0
  109. package/packages/core/src/kernel/read-facts.ts +15 -13
  110. package/packages/core/src/kernel/reducer-registry.ts +27 -8
  111. package/packages/core/src/kernel/reducer-revisions.ts +27 -0
  112. package/packages/core/src/kernel/reducer.ts +63 -4
  113. package/packages/core/src/kernel/rollup.ts +61 -0
  114. package/packages/core/src/kernel/setup-streak.ts +38 -0
  115. package/packages/core/src/kernel/step-durations.ts +257 -0
  116. package/packages/core/src/kernel/target-observation.ts +6 -1
  117. package/packages/core/src/kernel/target-rewrite-recovery.ts +116 -0
  118. package/packages/core/src/kernel/verify-diff-base.ts +5 -0
  119. package/packages/core/src/kernel/verify-stages.ts +13 -3
  120. package/packages/core/src/ontology.ts +5 -0
  121. package/packages/core/src/operator/agent-context-serve.ts +631 -0
  122. package/packages/core/src/operator/annotations.ts +75 -5
  123. package/packages/core/src/operator/attention.ts +470 -0
  124. package/packages/core/src/operator/canonical-skills.ts +35 -0
  125. package/packages/core/src/operator/cli-equivalents.ts +270 -0
  126. package/packages/core/src/operator/context-prompts.ts +61 -0
  127. package/packages/core/src/operator/index.ts +49 -1
  128. package/packages/core/src/operator/landings.ts +28 -19
  129. package/packages/core/src/operator/optimization.ts +7 -0
  130. package/packages/core/src/operator/protocol.ts +3 -0
  131. package/packages/core/src/operator/query.ts +129 -74
  132. package/packages/core/src/operator/read-view.ts +5 -2
  133. package/packages/core/src/operator/registry.ts +406 -46
  134. package/packages/core/src/operator/requests.ts +20 -18
  135. package/packages/core/src/operator/sandbox-host.ts +107 -11
  136. package/packages/core/src/operator/sandbox-resolver.ts +253 -0
  137. package/packages/core/src/operator/sandbox.ts +778 -82
  138. package/packages/core/src/operator/ticket-asset-list.ts +77 -0
  139. package/packages/core/src/operator/ticket-assets.ts +167 -0
  140. package/packages/core/src/operator/tickets.ts +33 -2
  141. package/packages/core/src/plugin-sdk/index.ts +22 -0
  142. package/packages/core/src/plugins/manifest.ts +1 -1
  143. package/packages/core/src/ports/forge/fake.ts +92 -1
  144. package/packages/core/src/ports/forge/git-blob.ts +15 -0
  145. package/packages/core/src/ports/forge/github.ts +82 -0
  146. package/packages/core/src/ports/forge/local-git.ts +61 -1
  147. package/packages/core/src/ports/forge-failure.ts +24 -0
  148. package/packages/core/src/ports/runner/antigravity-test.fixture.ts +149 -0
  149. package/packages/core/src/ports/runner/claude-test.fixture.ts +71 -0
  150. package/packages/core/src/ports/runner/codex-test.fixture.ts +63 -0
  151. package/packages/core/src/ports/tickets/contract.ts +71 -0
  152. package/packages/core/src/ports/tickets/fake.ts +11 -0
  153. package/packages/core/src/ports/tickets/file.ts +18 -0
  154. package/packages/core/src/ports/tickets/github-fake.ts +136 -4
  155. package/packages/core/src/ports/tickets/github.ts +387 -30
  156. package/packages/core/src/ports/tickets/hosted-index.ts +10 -0
  157. package/packages/core/src/ports/tickets/linear.ts +130 -0
  158. package/packages/core/src/ports/tickets/priority.ts +9 -0
  159. package/packages/core/src/ports/tickets/remote-protocol.ts +34 -0
  160. package/packages/core/src/ports/tickets/remote.ts +70 -6
  161. package/packages/core/src/ports/tickets/search.ts +139 -0
  162. package/packages/core/src/ports/types.ts +104 -2
  163. package/packages/core/src/ports/workspace/builtin-capabilities.ts +9 -0
  164. package/packages/core/src/ports/workspace/create.ts +15 -1
  165. package/packages/core/src/ports/workspace/fake.ts +340 -12
  166. package/packages/core/src/ports/workspace/git-worktree.ts +833 -42
  167. package/packages/core/src/ports/workspace/operator-sandbox.ts +129 -12
  168. package/packages/core/src/ports/workspace/process-group.ts +48 -0
  169. package/packages/core/src/ports/workspace/vercel-sandbox.ts +1260 -123
  170. package/packages/core/src/processes/agent-context-assemble.ts +576 -0
  171. package/packages/core/src/processes/agent-context.ts +469 -0
  172. package/packages/core/src/processes/build-runner.ts +387 -236
  173. package/packages/core/src/processes/dispatcher.ts +211 -55
  174. package/packages/core/src/processes/execution-no-progress.ts +4 -0
  175. package/packages/core/src/processes/optimization-activity.ts +120 -0
  176. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  177. package/packages/core/src/processes/repo-view.ts +78 -2
  178. package/packages/core/src/processes/sandbox-state.ts +53 -6
  179. package/packages/core/src/processes/tick-publication.ts +2 -0
  180. package/packages/core/src/processes/workspace-preparation.ts +76 -0
  181. package/packages/core/src/scenarios/harness.ts +0 -5
  182. package/packages/core/src/store/account-redaction.ts +1 -0
  183. package/packages/core/src/store/adapter.ts +52 -1
  184. package/packages/core/src/store/agent-context.ts +432 -0
  185. package/packages/core/src/store/build-feed.ts +291 -0
  186. package/packages/core/src/store/build-scope.ts +19 -1
  187. package/packages/core/src/store/contract.ts +911 -14
  188. package/packages/core/src/store/digest.ts +19 -6
  189. package/packages/core/src/store/histogram.ts +113 -0
  190. package/packages/core/src/store/local/schema.ts +62 -0
  191. package/packages/core/src/store/local/store.ts +628 -22
  192. package/packages/core/src/store/local/ticket-asset-heads.ts +23 -0
  193. package/packages/core/src/store/memory.ts +461 -69
  194. package/packages/core/src/store/open-builds.ts +19 -0
  195. package/packages/core/src/store/phase-session.ts +32 -4
  196. package/packages/core/src/store/reduced-reads.ts +14 -4
  197. package/packages/core/src/store/reducer-value-shapes.json +7027 -5751
  198. package/packages/core/src/store/reducer-values.ts +6 -1
  199. package/packages/core/src/store/remote/client.ts +208 -2
  200. package/packages/core/src/store/remote/compatibility.ts +1 -1
  201. package/packages/core/src/store/remote/index.ts +33 -0
  202. package/packages/core/src/store/remote/protocol.ts +69 -0
  203. package/packages/core/src/store/remote/released-clients.json +22 -0
  204. package/packages/core/src/store/remote/released-reducer-values/1.11.0.json +35680 -0
  205. package/packages/core/src/store/remote/released-reducer-values/1.11.1.json +35718 -0
  206. package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
  207. package/packages/core/src/store/retention.ts +23 -1
  208. package/packages/core/src/store/rollups.ts +337 -0
  209. package/packages/core/src/store/session-handle.ts +20 -2
  210. package/packages/core/src/store/snapshots.ts +10 -0
  211. package/packages/core/src/store/types.ts +108 -9
  212. package/packages/core/src/testing/dispatch-journals.ts +117 -0
  213. package/packages/core/src/testing/dispatch-read-budget.ts +1092 -2
  214. package/packages/core/src/testing/git-config-isolation.ts +7 -5
  215. package/packages/core/src/testing/index.ts +27 -0
  216. package/packages/core/src/testing/memory-operator-sandbox.ts +346 -0
  217. package/packages/core/src/testing/reduced-read-budget.ts +1873 -98
  218. package/packages/core/src/web/analytics-source.ts +303 -0
  219. package/packages/core/src/web/assets/Atkinson-OFL.txt +93 -0
  220. package/packages/core/src/web/assets/AtkinsonHyperlegibleNext.latin.woff2 +0 -0
  221. package/packages/core/src/web/assets/JetBrains-OFL.txt +93 -0
  222. package/packages/core/src/web/assets/JetBrainsMono.latin.woff2 +0 -0
  223. package/packages/core/src/web/assets/app.css +1 -0
  224. package/packages/core/src/web/assets/app.js +9 -0
  225. package/packages/core/src/web/assets/manifest.json +31 -0
  226. package/packages/core/src/web/assets/theme.js +1 -0
  227. package/packages/core/src/web/bounded.ts +31 -0
  228. package/packages/core/src/web/http.ts +315 -0
  229. package/packages/core/src/web/hub.ts +160 -0
  230. package/packages/core/src/web/options.ts +38 -0
  231. package/packages/core/src/web/overview-source.ts +322 -0
  232. package/packages/core/src/web/page.ts +56 -0
  233. package/packages/core/src/web/protocol.ts +151 -0
  234. package/packages/core/src/web/read-only.ts +23 -0
  235. package/packages/core/src/web/repository-source.ts +39 -0
  236. package/packages/core/src/web/server.ts +97 -0
  237. package/skills/code-review/SKILL.md +10 -2
  238. package/skills/guide/SKILL.md +376 -54
  239. package/skills/guide/references/accounts.md +2 -1
  240. package/skills/guide/references/integration-tree.md +2 -2
  241. package/skills/guide/references/operator-api.md +134 -6
  242. package/skills/guide/references/optimization-nodes.md +69 -11
  243. package/skills/guide/references/plugin-authoring.md +37 -1
  244. package/skills/guide/references/remote-store-protocol.md +94 -13
  245. package/skills/guide/references/remote-ticket-protocol.md +40 -0
  246. package/skills/guide/references/restacking.md +20 -4
  247. package/skills/guide/references/setup.md +14 -2
  248. package/skills/guide/references/ticket-dependencies.md +10 -3
  249. package/skills/implement/SKILL.md +23 -4
  250. package/skills/operate/SKILL.md +134 -32
  251. package/skills/plan/SKILL.md +10 -4
  252. package/skills/plan-review/SKILL.md +9 -2
  253. package/skills/spec/SKILL.md +34 -8
  254. package/skills/tickets/SKILL.md +51 -5
  255. package/templates/hosted-service/package.json +2 -2
@@ -1,6 +1,7 @@
1
1
  import { normalizeEffectiveConfigArtifact } from '../config/effective-artifact'
2
2
  import { migrationIdentity } from '../kernel/ticket-migrations'
3
3
  import { enrichDrainingRow, projectHandoffs } from '../cli/dashboard/handoff'
4
+ import { repositoryQueueDepth } from '../cli/dashboard/header'
4
5
  import { enrichIntegrationRows } from '../cli/dashboard/integration-row'
5
6
  import {
6
7
  dispatchCapacity,
@@ -20,7 +21,12 @@ import {
20
21
  import { readDispatcherLiveness } from '../cli/dispatcher-liveness'
21
22
  import { composeBuildConfig } from '../config/live'
22
23
  import type { PipelineSourceMeta } from '../config/pipeline-source'
23
- import { configSchema, type Config } from '../config/schema'
24
+ import {
25
+ configSchema,
26
+ orchestratorEnabled,
27
+ type Config,
28
+ type OrchestratorHost,
29
+ } from '../config/schema'
24
30
  import {
25
31
  BUILD_EFFECTIVE_CONFIG_ARTIFACT,
26
32
  parseBuildConfigMetadata,
@@ -36,6 +42,8 @@ import {
36
42
  } from '../cli/status'
37
43
  import {
38
44
  repositoryStatusFromFacts,
45
+ localOverridesFromArtifact,
46
+ readHeldEffectiveConfig,
39
47
  readRepositoryCapacity,
40
48
  type RepositoryStatus,
41
49
  } from '../cli/repository-status'
@@ -53,7 +61,7 @@ import { reduceDispatchStatus } from '../kernel/dispatch-status'
53
61
  import type { RepoViewStore } from '../processes/repo-view'
54
62
  import { withOperatorView } from './read-view'
55
63
  import type { RepositoryEvent } from '../events/repository'
56
- import type { BuildStore, Clock } from '../store/types'
64
+ import type { BuildRecord, BuildStore, Clock } from '../store/types'
57
65
 
58
66
  export type BuildListScope = 'active' | 'queued' | 'all'
59
67
 
@@ -85,40 +93,25 @@ async function listFromView(
85
93
  opts: { repo: string; scope: BuildListScope; now: Date },
86
94
  ): Promise<BuildSummary[]> {
87
95
  const statuses = new Set(statusFilter(opts.scope === 'all', opts.scope === 'queued'))
88
- // Records are read and held before the digest read: builds are never
89
- // deleted, so every record iterated below is guaranteed an entry in the
90
- // digest map fetched after it — a build created between the two reads
91
- // appears only in the digest map, which is harmless — and the completeness
92
- // check can only ever catch a genuine adapter bug, never a concurrent
93
- // dispatch. The reverse order would let a concurrent creation abort the
94
- // whole listing (AUT-488 finding f_3cb67aba).
95
- const records = await view.listBuilds()
96
- // One digest read gates the per-build reads (AUT-488): the active and queued
97
- // scopes never show a terminal build, so a build whose digest already
98
- // carries a terminal fact is skipped and the listing's cost stays flat as
99
- // finished builds accumulate. The `--all` scope includes terminal statuses,
100
- // so it takes no digest read and skips nothing; its terminal builds are
101
- // restored from the reducer snapshots the dispatcher leaves at settlement.
102
- const digests = opts.scope === 'all' ? undefined : await readBuildDigests(view, opts.repo)
96
+ // The active and queued scopes never show a terminal build, so they iterate
97
+ // the store's open-build listing: its cost follows open builds and stays
98
+ // flat as finished builds accumulate. The `--all` scope is an explicit
99
+ // history read and lists every build; its terminal builds are restored from
100
+ // the reducer snapshots the dispatcher leaves at settlement.
101
+ const records =
102
+ opts.scope === 'all'
103
+ ? await view.listBuilds()
104
+ : (await view.listOpenBuilds(opts.repo))
105
+ // The digest's `terminal` follows `reduceBuild`'s terminal rule
106
+ // exactly (pinned in store/digest.test.ts), so `terminal !==
107
+ // undefined` is exactly reduced status `done`/`aborted`, which the
108
+ // active and queued status sets never include. Skipping an aborted
109
+ // build still in cleanup therefore cannot change the summaries.
110
+ .filter(({ digest }) => digest.terminal === undefined)
111
+ .map(({ record }) => record)
103
112
  const output: BuildSummary[] = []
104
113
  for (const record of records) {
105
114
  if (record.repo !== opts.repo) continue
106
- if (digests !== undefined) {
107
- // Completeness is contractual (one entry per repo build); a missing
108
- // entry is an adapter bug and must fail loudly rather than silently
109
- // drop the build from the listing.
110
- const digest = digests.get(record.slug)
111
- if (digest === undefined) {
112
- throw new Error(`getRepoBuildDigests is missing an entry for build "${record.slug}"`)
113
- }
114
- // The digest's `terminal` follows `reduceBuild`'s terminal rule exactly
115
- // (in-order overwrite of `build.completed`/`build.aborted`, never
116
- // cleared — pinned against `reduceBuild` in store/digest.test.ts), so
117
- // `terminal !== undefined` is exactly reduced status `done`/`aborted`,
118
- // which the active and queued status sets never include. Skipping the
119
- // build therefore cannot change the emitted summaries.
120
- if (digest.terminal !== undefined) continue
121
- }
122
115
  const facts = await view.buildFacts(record.slug)
123
116
  const projected = summarizeFrom(
124
117
  record,
@@ -365,8 +358,14 @@ export async function getRepositoryStatus(
365
358
  const { dispatcher } = await readDispatcherLiveness(store, repo, now)
366
359
  const facts = (await readRepositoryFacts(view, repo)).value
367
360
  const status = repositoryStatusFromFacts(repo, facts, dispatcher, now)
368
- const capacity = await readRepositoryCapacity(store, repo, facts, dispatcher, now)
369
- return { ...status, ...(capacity ? { capacity } : {}) }
361
+ const held = await readHeldEffectiveConfig(store, repo, facts, dispatcher)
362
+ const capacity = await readRepositoryCapacity(store, repo, facts, held, now)
363
+ const localOverrides = localOverridesFromArtifact(held)
364
+ return {
365
+ ...status,
366
+ ...(capacity ? { capacity } : {}),
367
+ ...(localOverrides ? { localOverrides } : {}),
368
+ }
370
369
  })
371
370
  }
372
371
 
@@ -408,28 +407,20 @@ async function dashboardFromView(
408
407
  // more: no build can exist before a dispatcher claims one.
409
408
  if (facts.config.run === undefined) return noDispatcherRunSnapshot(opts.repo, facts, opts.clock)
410
409
  const { config, repositoryEvents, status } = await effectiveConfig(view, opts.repo, facts)
411
- const records = await view.listBuilds()
412
- // One digest read covers every build of the repository (AUT-487): the
413
- // row gate (a `done` digest means no row) needs no per-build histories, so
414
- // the snapshot's traffic stays flat as finished builds accumulate. Row-rendering builds derive from the repository view's
415
- // reducer snapshots plus a delta read (AUT-650); every snapshot is a cache
416
- // the event log regenerates, so the response equals a full replay's.
417
- const digests = await readBuildDigests(view, opts.repo)
410
+ // The open-build listing covers every build that can render a row or hold
411
+ // capacity (AUT-487, #1230): settled builds are never read, so the
412
+ // snapshot's traffic stays flat as finished builds accumulate. Row-rendering
413
+ // builds derive from the repository view's reducer snapshots plus a delta
414
+ // read (AUT-650); every snapshot is a cache the event log regenerates, so
415
+ // the response equals a full replay's.
416
+ const open = await view.listOpenBuilds(opts.repo)
417
+ const records = open.map(({ record }) => record)
418
418
  const projected: DashboardBuild[] = []
419
419
  const capacityBuilds: CapacityBuild[] = []
420
- for (const record of records) {
420
+ for (const { record, digest } of open) {
421
421
  if (record.repo !== opts.repo) continue
422
- const digest = digests.get(record.slug)
423
- // Completeness is contractual (one entry per repo build); a missing entry
424
- // is an adapter bug and must fail loudly rather than silently drop the
425
- // build from the active count or the row list.
426
- if (digest === undefined) {
427
- throw new Error(`getRepoBuildDigests is missing an entry for build "${record.slug}"`)
428
- }
429
- // Reduced status is `done`/`aborted` exactly when a terminal fact exists,
430
- // so `terminal === undefined` is exactly the old active test — no history
431
- // read needed for the count.
432
-
422
+ // The listing holds no completed build; the guard keeps the row gate
423
+ // explicit should a store ever answer one.
433
424
  if (digest.terminal === 'done') continue
434
425
  // Both query surfaces share the `projectsNoDashboardRow` gate (AUT-486
435
426
  // snapshot, AUT-496 detail query): a build that projects no row —
@@ -483,10 +474,10 @@ async function dashboardFromView(
483
474
  },
484
475
  )
485
476
  const model = buildDashboardFromProjected(
486
- enrichIntegrationRows(projected, records),
477
+ enrichIntegrationRows(projected, await integrationRecords(view, opts.repo, projected, records)),
487
478
  {
488
479
  repo: opts.repo,
489
- queued: status.queued ?? 0,
480
+ queued: repositoryQueueDepth(repositoryEvents),
490
481
  activeCount: capacityProjection.occupied,
491
482
  capacityProjection,
492
483
  capacity: config.capacity,
@@ -501,6 +492,32 @@ async function dashboardFromView(
501
492
  return dashboardSnapshot(model, opts.clock)
502
493
  }
503
494
 
495
+ /** The records `enrichIntegrationRows` resolves node children against: the
496
+ * open records, plus the settled child builds a rendered node row still needs
497
+ * for a ticket identity or title. The extra reads are bounded by the rendered
498
+ * rows' own unresolved children, never by repository history. */
499
+ async function integrationRecords(
500
+ view: RepoViewStore,
501
+ repo: string,
502
+ rows: readonly DashboardBuild[],
503
+ open: readonly BuildRecord[],
504
+ ): Promise<BuildRecord[]> {
505
+ const listed = new Set(open.map((record) => record.slug))
506
+ const wanted = new Set<string>()
507
+ for (const row of rows)
508
+ for (const child of row.integrationDetail?.children ?? []) {
509
+ if (!child.builds?.length) continue
510
+ if (!child.builds.includes(child.id) && child.title !== 'title unavailable') continue
511
+ for (const slug of child.builds) if (!listed.has(slug)) wanted.add(slug)
512
+ }
513
+ if (wanted.size === 0) return [...open]
514
+ const settled = await Promise.all([...wanted].map((slug) => view.getBuild(slug)))
515
+ return [
516
+ ...open,
517
+ ...settled.filter((record): record is BuildRecord => record !== null && record.repo === repo),
518
+ ].sort((a, b) => a.createdAt.localeCompare(b.createdAt) || a.slug.localeCompare(b.slug))
519
+ }
520
+
504
521
  /** The dashboard of a repository with no recorded dispatcher run: repository
505
522
  * controls reduce from the journal, pipeline configuration is unknown. */
506
523
  function noDispatcherRunSnapshot(
@@ -509,7 +526,11 @@ function noDispatcherRunSnapshot(
509
526
  clock: Clock,
510
527
  ): OperatorDashboardSnapshot {
511
528
  const model: DashboardModel = {
512
- ...buildDashboardFromProjected([], { repo, queued: 0, activeCount: 0, capacity: 0 }, facts),
529
+ ...buildDashboardFromProjected(
530
+ [],
531
+ { repo, queued: repositoryQueueDepth(facts), activeCount: 0, capacity: 0 },
532
+ facts,
533
+ ),
513
534
  configuration: 'no-dispatcher-run',
514
535
  }
515
536
  return dashboardSnapshot(model, clock)
@@ -536,33 +557,67 @@ export class OrchestratorConfigError extends Error {
536
557
  }
537
558
  }
538
559
 
539
- /** Resolve the sandbox gate from the latest effective config; absent/disabled returns null. */
540
- export async function orchestratorConfig(store: BuildStore, repo: string): Promise<Config | null> {
560
+ /** The sandbox gate's answer for one repository: its latest deposited
561
+ * effective config when that config enables `[orchestrator]` for the given
562
+ * host, else the reason the gate is closed. */
563
+ export type OrchestratorGate =
564
+ | { enabled: true; config: Config; revision: number }
565
+ | { enabled: false; reason: 'no-effective-config' | 'orchestrator-disabled' }
566
+
567
+ /** Read the sandbox gate from the repository's LATEST deposited effective
568
+ * config, resolving `[orchestrator].enabled` for `host` through
569
+ * `orchestratorEnabled` (an unset value is enabled on a hosted deployment).
570
+ * Bounded: one repository read plus the latest artifact row and its blob,
571
+ * never a listing of every revision. Throws `OrchestratorConfigError` when
572
+ * the latest deposit is unreadable or invalid. */
573
+ export async function readOrchestratorGate(
574
+ store: BuildStore,
575
+ repo: string,
576
+ host: OrchestratorHost,
577
+ ): Promise<OrchestratorGate> {
541
578
  // A repository the store has no record for has no deposited artifact and
542
579
  // no dispatcher history: sandbox tools are disabled there.
543
- if ((await store.getRepo(repo)) === null) return null
544
- const artifacts = await store.listRepoArtifacts(repo, DISPATCHER_EFFECTIVE_CONFIG_ARTIFACT)
545
- if (artifacts.length === 0) return null
546
- const latest = [...artifacts].sort((a, b) => b.revision - a.revision)[0]!
547
- const artifact = await store.getRepoArtifact(repo, latest.kind, latest.revision)
548
- if (artifact === null) {
549
- throw new OrchestratorConfigError(
550
- `effective config ${latest.kind}@${latest.revision} is not retrievable`,
551
- )
552
- }
580
+ if ((await store.getRepo(repo)) === null) return { enabled: false, reason: 'no-effective-config' }
581
+ const artifact = await store.getRepoArtifact(repo, DISPATCHER_EFFECTIVE_CONFIG_ARTIFACT)
582
+ if (artifact === null) return { enabled: false, reason: 'no-effective-config' }
583
+ const label = `${artifact.meta.kind}@${artifact.meta.revision}`
553
584
  let raw: unknown
554
585
  try {
555
586
  raw = JSON.parse(new TextDecoder().decode(artifact.content))
556
587
  } catch {
557
- throw new OrchestratorConfigError(
558
- `effective config ${latest.kind}@${latest.revision} is not valid JSON`,
559
- )
588
+ throw new OrchestratorConfigError(`effective config ${label} is not valid JSON`)
560
589
  }
561
590
  const parsed = configSchema.safeParse(normalizeEffectiveConfigArtifact(raw))
562
591
  if (!parsed.success) {
563
592
  throw new OrchestratorConfigError(
564
- `effective config ${latest.kind}@${latest.revision} is invalid: ${parsed.error.message}`,
593
+ `effective config ${label} is invalid: ${parsed.error.message}`,
565
594
  )
566
595
  }
567
- return parsed.data.orchestrator.enabled ? parsed.data : null
596
+ return orchestratorEnabled(parsed.data, host)
597
+ ? { enabled: true, config: parsed.data, revision: artifact.meta.revision }
598
+ : { enabled: false, reason: 'orchestrator-disabled' }
599
+ }
600
+
601
+ /** Whether a repository-scoped binding lists `sandbox.*` for `repo`: the
602
+ * same bounded gate read as a sandbox call (one repository read plus the
603
+ * latest effective-config artifact), with an unusable deposit reading as
604
+ * closed. Uses the hosted default for an unset enabled value. Listing never reads events or every revision. */
605
+ export async function sandboxToolsListed(store: BuildStore, repo: string): Promise<boolean> {
606
+ try {
607
+ return (await readOrchestratorGate(store, repo, 'hosted')).enabled
608
+ } catch (error) {
609
+ if (error instanceof OrchestratorConfigError) return false
610
+ throw error
611
+ }
612
+ }
613
+
614
+ /** Resolve the sandbox gate for `host` from the latest effective config;
615
+ * no deposit or a closed gate returns null. */
616
+ export async function orchestratorConfig(
617
+ store: BuildStore,
618
+ repo: string,
619
+ host: OrchestratorHost,
620
+ ): Promise<Config | null> {
621
+ const gate = await readOrchestratorGate(store, repo, host)
622
+ return gate.enabled ? gate.config : null
568
623
  }
@@ -2,7 +2,10 @@
2
2
  * The operator read paths' repository view: every poll-driven route (dashboard,
3
3
  * repository and harvest status, build listings) derives its state from a
4
4
  * `RepoViewStore` backed by persisted reduced values. Each pass refreshes
5
- * repository facts and metadata without hydrating raw history.
5
+ * repository facts and metadata without hydrating raw history. A pass that
6
+ * needs builds discovers them through the store's open-build listing
7
+ * (`refreshOpen`), so its cost follows open builds and never settled history;
8
+ * only an explicit history read (`builds.list --all`) lists every build.
6
9
  *
7
10
  * Passes are single-flight per `(store, repo)` within one serving process: at
8
11
  * most one pass runs at a time, and requests arriving while it runs join the
@@ -50,7 +53,7 @@ function flightFor(store: BuildStore, repo: string): Flight {
50
53
  async function pass(store: BuildStore, repo: string, waiters: Waiter[]): Promise<void> {
51
54
  const view = new RepoViewStore(store, { repo })
52
55
  try {
53
- if (waiters.some((waiter) => waiter.need === 'builds')) await view.refresh()
56
+ if (waiters.some((waiter) => waiter.need === 'builds')) await view.refreshOpen()
54
57
  else await view.startJournal()
55
58
  } catch (error) {
56
59
  for (const waiter of waiters) waiter.reject(error)