@defrex/autobuild 0.13.0 → 1.0.0-beta.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 (210) hide show
  1. package/README.md +5 -3
  2. package/SPEC.md +673 -99
  3. package/bin/ab-dispatch-kernel.ts +4 -6
  4. package/docs/architecture.md +322 -75
  5. package/docs/assets/headline-wide.png +0 -0
  6. package/docs/configuration.md +112 -12
  7. package/docs/hosted-service.md +20 -2
  8. package/docs/integration-tree.md +117 -0
  9. package/docs/landing-policy.md +150 -0
  10. package/docs/mcp.md +24 -0
  11. package/docs/migration-1.0.md +68 -0
  12. package/docs/operator-api.md +20 -9
  13. package/docs/remote-store-protocol.md +114 -9
  14. package/docs/remote-ticket-protocol.md +26 -5
  15. package/docs/restacking.md +79 -0
  16. package/docs/setup.md +49 -6
  17. package/docs/ticket-dependencies.md +69 -0
  18. package/docs/ticket-migration.md +8 -0
  19. package/package.json +4 -3
  20. package/packages/core/src/cli/attention.ts +40 -163
  21. package/packages/core/src/cli/build-control.ts +75 -55
  22. package/packages/core/src/cli/bulk-control.ts +3 -2
  23. package/packages/core/src/cli/context.ts +68 -78
  24. package/packages/core/src/cli/dashboard/actions.ts +6 -3
  25. package/packages/core/src/cli/dashboard/landing-display.ts +6 -0
  26. package/packages/core/src/cli/dashboard/live.ts +5 -0
  27. package/packages/core/src/cli/dashboard/model.ts +178 -40
  28. package/packages/core/src/cli/dashboard/poll.ts +15 -9
  29. package/packages/core/src/cli/dashboard/refresh.ts +176 -0
  30. package/packages/core/src/cli/dashboard/render.ts +78 -28
  31. package/packages/core/src/cli/dashboard/repository-poll.ts +57 -0
  32. package/packages/core/src/cli/dashboard/selection.ts +7 -1
  33. package/packages/core/src/cli/dashboard/tree.ts +107 -0
  34. package/packages/core/src/cli/dispatch-frontend.ts +173 -169
  35. package/packages/core/src/cli/dispatch-process.ts +14 -7
  36. package/packages/core/src/cli/dispatch-repository-feed.ts +196 -0
  37. package/packages/core/src/cli/dispatch.ts +397 -214
  38. package/packages/core/src/cli/dispatcher-liveness.ts +41 -21
  39. package/packages/core/src/cli/harvest.ts +71 -39
  40. package/packages/core/src/cli/help.ts +49 -32
  41. package/packages/core/src/cli/historical-build-state.ts +27 -0
  42. package/packages/core/src/cli/init-validation.ts +43 -2
  43. package/packages/core/src/cli/keyboard.ts +6 -0
  44. package/packages/core/src/cli/landings.ts +18 -0
  45. package/packages/core/src/cli/main.ts +52 -18
  46. package/packages/core/src/cli/mcp.ts +9 -0
  47. package/packages/core/src/cli/pr-attachments.ts +10 -13
  48. package/packages/core/src/cli/pr-summary-publication.ts +27 -60
  49. package/packages/core/src/cli/pr-summary.ts +43 -13
  50. package/packages/core/src/cli/publication-settlement.ts +177 -21
  51. package/packages/core/src/cli/repository-status.ts +49 -2
  52. package/packages/core/src/cli/status.ts +133 -36
  53. package/packages/core/src/cli/terminal-restore.ts +54 -0
  54. package/packages/core/src/cli/terminal.ts +16 -2
  55. package/packages/core/src/cli/terminals.ts +121 -219
  56. package/packages/core/src/cli/ticket-editor.ts +10 -3
  57. package/packages/core/src/cli/ticket.ts +115 -20
  58. package/packages/core/src/cli/upgrade-commit.ts +4 -0
  59. package/packages/core/src/cli/upgrade-compatibility.ts +2 -2
  60. package/packages/core/src/cli/upgrade-landing.ts +69 -0
  61. package/packages/core/src/cli/upgrade.ts +16 -0
  62. package/packages/core/src/cli/wait.ts +194 -91
  63. package/packages/core/src/cli/watch.ts +111 -109
  64. package/packages/core/src/config/landing.ts +22 -0
  65. package/packages/core/src/config/live.ts +1 -0
  66. package/packages/core/src/config/pipeline-source.ts +4 -3
  67. package/packages/core/src/config/schema.ts +3 -0
  68. package/packages/core/src/events/catalog.ts +48 -3
  69. package/packages/core/src/events/payloads.ts +295 -6
  70. package/packages/core/src/events/repository.ts +38 -3
  71. package/packages/core/src/integration/harness.ts +11 -2
  72. package/packages/core/src/kernel/__snapshots__/reducer-registry.test.ts.snap +3330 -119
  73. package/packages/core/src/kernel/auto-merge-default.ts +1 -0
  74. package/packages/core/src/kernel/auto-merge.ts +29 -4
  75. package/packages/core/src/kernel/build-identity.ts +94 -0
  76. package/packages/core/src/kernel/change-presence.ts +179 -0
  77. package/packages/core/src/kernel/dispatch-status.ts +17 -1
  78. package/packages/core/src/kernel/dispatcher-liveness.ts +10 -4
  79. package/packages/core/src/kernel/engine.ts +89 -2
  80. package/packages/core/src/kernel/generators/build-log.ts +23 -0
  81. package/packages/core/src/kernel/generators/leaf-restack-log.ts +110 -0
  82. package/packages/core/src/kernel/generators/node-restack-log.ts +94 -0
  83. package/packages/core/src/kernel/generators/repository-journals.ts +25 -3
  84. package/packages/core/src/kernel/harvest.ts +25 -23
  85. package/packages/core/src/kernel/integration-completeness.ts +81 -0
  86. package/packages/core/src/kernel/integration-landing.ts +263 -0
  87. package/packages/core/src/kernel/integration-stack.ts +36 -0
  88. package/packages/core/src/kernel/integration-state.ts +135 -0
  89. package/packages/core/src/kernel/landing-policy.ts +47 -0
  90. package/packages/core/src/kernel/landing-publication.ts +41 -0
  91. package/packages/core/src/kernel/landing-readiness.ts +67 -0
  92. package/packages/core/src/kernel/landing-state.ts +96 -0
  93. package/packages/core/src/kernel/leaf-restack-completion.ts +24 -0
  94. package/packages/core/src/kernel/leaf-restack-state.ts +73 -0
  95. package/packages/core/src/kernel/log-index-value.ts +38 -0
  96. package/packages/core/src/kernel/log-index.ts +35 -5
  97. package/packages/core/src/kernel/node-landing.ts +439 -0
  98. package/packages/core/src/kernel/node-parent.ts +184 -0
  99. package/packages/core/src/kernel/node-restack-state.ts +191 -0
  100. package/packages/core/src/kernel/node-restack-transaction.ts +210 -0
  101. package/packages/core/src/kernel/node-restack.ts +274 -0
  102. package/packages/core/src/kernel/read-facts.ts +704 -0
  103. package/packages/core/src/kernel/reconcile-head.ts +51 -0
  104. package/packages/core/src/kernel/reconcile-restack.ts +560 -0
  105. package/packages/core/src/kernel/reducer-registry.ts +153 -3
  106. package/packages/core/src/kernel/reducer.ts +121 -6
  107. package/packages/core/src/kernel/repository-attention.ts +179 -0
  108. package/packages/core/src/kernel/service-facts.ts +135 -0
  109. package/packages/core/src/kernel/snapshot-parent.ts +33 -0
  110. package/packages/core/src/kernel/terminal-guard.ts +133 -0
  111. package/packages/core/src/ontology.ts +9 -1
  112. package/packages/core/src/operator/annotations.ts +12 -0
  113. package/packages/core/src/operator/control.ts +11 -6
  114. package/packages/core/src/operator/index.ts +6 -0
  115. package/packages/core/src/operator/landings.ts +35 -0
  116. package/packages/core/src/operator/presentation.ts +1 -0
  117. package/packages/core/src/operator/protocol.ts +12 -3
  118. package/packages/core/src/operator/query.ts +40 -21
  119. package/packages/core/src/operator/read-view.ts +4 -13
  120. package/packages/core/src/operator/registry.ts +48 -19
  121. package/packages/core/src/operator/requests.ts +3 -22
  122. package/packages/core/src/operator/sandbox.ts +10 -9
  123. package/packages/core/src/operator/tickets.ts +57 -11
  124. package/packages/core/src/plugin-sdk/index.ts +13 -0
  125. package/packages/core/src/ports/forge/contract.ts +91 -3
  126. package/packages/core/src/ports/forge/fake.ts +142 -4
  127. package/packages/core/src/ports/forge/git-rewrite.ts +232 -0
  128. package/packages/core/src/ports/forge/github-readiness.ts +421 -0
  129. package/packages/core/src/ports/forge/github.ts +631 -35
  130. package/packages/core/src/ports/forge/local-git.ts +119 -5
  131. package/packages/core/src/ports/forge/readiness.ts +99 -0
  132. package/packages/core/src/ports/tickets/contract.ts +41 -0
  133. package/packages/core/src/ports/tickets/create.ts +8 -1
  134. package/packages/core/src/ports/tickets/fake.ts +32 -1
  135. package/packages/core/src/ports/tickets/file-codec.ts +7 -0
  136. package/packages/core/src/ports/tickets/file.ts +18 -1
  137. package/packages/core/src/ports/tickets/hosted-index.ts +2 -0
  138. package/packages/core/src/ports/tickets/linear.ts +124 -4
  139. package/packages/core/src/ports/tickets/migration.ts +25 -1
  140. package/packages/core/src/ports/tickets/operations.ts +7 -2
  141. package/packages/core/src/ports/tickets/remote-protocol.ts +19 -0
  142. package/packages/core/src/ports/tickets/remote.ts +10 -1
  143. package/packages/core/src/ports/tickets/revision.ts +3 -1
  144. package/packages/core/src/ports/tickets/tree.ts +148 -0
  145. package/packages/core/src/ports/tickets/update.ts +15 -2
  146. package/packages/core/src/ports/types.ts +135 -5
  147. package/packages/core/src/ports/workspace/git-worktree.ts +2 -1
  148. package/packages/core/src/ports/workspace/provider-capabilities.ts +1 -1
  149. package/packages/core/src/ports/workspace/vercel-sandbox.ts +60 -3
  150. package/packages/core/src/processes/build-child.ts +6 -6
  151. package/packages/core/src/processes/build-runner.ts +586 -87
  152. package/packages/core/src/processes/dispatch-failure-budget.ts +5 -4
  153. package/packages/core/src/processes/dispatcher-selectors.ts +15 -9
  154. package/packages/core/src/processes/dispatcher.ts +2239 -357
  155. package/packages/core/src/processes/execution-no-progress.ts +46 -1
  156. package/packages/core/src/processes/harvest-execution-state.ts +15 -9
  157. package/packages/core/src/processes/harvest-runner.ts +34 -70
  158. package/packages/core/src/processes/harvest.ts +38 -15
  159. package/packages/core/src/processes/infrastructure-failure-budget.ts +13 -15
  160. package/packages/core/src/processes/orchestrator-tick.ts +2 -2
  161. package/packages/core/src/processes/publication-loss.ts +35 -21
  162. package/packages/core/src/processes/publication-state.ts +30 -5
  163. package/packages/core/src/processes/repo-view.ts +244 -1130
  164. package/packages/core/src/processes/tick-publication.ts +110 -0
  165. package/packages/core/src/store/adapter.ts +23 -0
  166. package/packages/core/src/store/build-scope.ts +35 -0
  167. package/packages/core/src/store/contract.ts +909 -0
  168. package/packages/core/src/store/digest.ts +52 -4
  169. package/packages/core/src/store/local/schema.ts +26 -13
  170. package/packages/core/src/store/local/store.ts +296 -55
  171. package/packages/core/src/store/memory.ts +181 -30
  172. package/packages/core/src/store/phase-session.ts +34 -0
  173. package/packages/core/src/store/reduced-reads.ts +240 -0
  174. package/packages/core/src/store/reducer-value-shapes.json +18323 -0
  175. package/packages/core/src/store/reducer-value-validation.ts +96 -0
  176. package/packages/core/src/store/reducer-values.ts +145 -0
  177. package/packages/core/src/store/remote/client.ts +85 -0
  178. package/packages/core/src/store/remote/compatibility.ts +21 -9
  179. package/packages/core/src/store/remote/index.ts +19 -0
  180. package/packages/core/src/store/remote/protocol.ts +27 -0
  181. package/packages/core/src/store/remote/version.ts +3 -1
  182. package/packages/core/src/store/repo-state-events.ts +3 -1
  183. package/packages/core/src/store/repo-tick.ts +72 -0
  184. package/packages/core/src/store/session-handle.ts +34 -0
  185. package/packages/core/src/store/snapshots.ts +10 -0
  186. package/packages/core/src/store/subscribe.ts +1 -1
  187. package/packages/core/src/store/ticket-assets.ts +4 -4
  188. package/packages/core/src/store/types.ts +71 -6
  189. package/packages/core/src/testing/dispatch-read-budget.ts +215 -0
  190. package/packages/core/src/testing/index.ts +10 -0
  191. package/packages/core/src/testing/reduced-read-budget.ts +502 -0
  192. package/packages/core/src/testing/refresh-scheduler.ts +32 -0
  193. package/skills/guide/SKILL.md +116 -62
  194. package/skills/guide/references/integration-tree.md +117 -0
  195. package/skills/guide/references/landing-policy.md +150 -0
  196. package/skills/guide/references/migration-1.0.md +68 -0
  197. package/skills/guide/references/operator-api.md +13 -6
  198. package/skills/guide/references/plugin-authoring.md +34 -0
  199. package/skills/guide/references/remote-store-protocol.md +114 -9
  200. package/skills/guide/references/remote-ticket-protocol.md +26 -5
  201. package/skills/guide/references/restacking.md +79 -0
  202. package/skills/guide/references/setup.md +49 -6
  203. package/skills/guide/references/ticket-dependencies.md +69 -0
  204. package/skills/guide/references/ticket-migration.md +8 -0
  205. package/skills/operate/SKILL.md +55 -5
  206. package/skills/reconcile/SKILL.md +55 -48
  207. package/skills/spec/SKILL.md +67 -1
  208. package/skills/tickets/SKILL.md +55 -2
  209. package/templates/autobuild.toml +3 -0
  210. package/templates/hosted-service/package.json +2 -2
@@ -1,10 +1,20 @@
1
+ import { forgeReadinessWarnings } from '../kernel/dispatch-status'
2
+ import { RepositoryPollCache } from './dashboard/repository-poll'
3
+ import {
4
+ DashboardRefresh,
5
+ interactionRead,
6
+ presentationReader,
7
+ type RefreshScheduler,
8
+ } from './dashboard/refresh'
9
+ import { FOCUS_REPORTING_MODE, installPresentationSuspension } from './terminal-restore'
10
+ import { DispatchRepositoryFeed } from './dispatch-repository-feed'
1
11
  import { StandbyIdentityResolver } from './dispatcher-liveness'
2
12
  import { configSchema, type Config } from '../config/schema'
3
13
  import { humanActor } from '../events/envelope'
4
14
  import type { RepositoryEvent } from '../events/repository'
5
15
  import { reduceDispatchStatus, type DispatchStatus } from '../kernel/dispatch-status'
6
16
  import type { BuildState } from '../kernel/reducer'
7
- import { sampleUnclaimedObservationCount } from '../processes/harvest'
17
+ import { unclaimedObservationCount } from '../processes/harvest'
8
18
  import {
9
19
  controlHarvestRun,
10
20
  OperatorControlError,
@@ -24,7 +34,7 @@ import {
24
34
  type DashboardSelection,
25
35
  type DashboardView,
26
36
  } from './dashboard/model'
27
- import { DashboardBuildPollCache } from './dashboard/poll'
37
+ import { DashboardBuildPollCache, type DashboardPollSnapshot } from './dashboard/poll'
28
38
  import {
29
39
  dashboardContentWidth,
30
40
  detailScrollLimit,
@@ -47,9 +57,10 @@ import {
47
57
  type DispatchChildOptions,
48
58
  } from './dispatch-process'
49
59
 
50
- const POLL_MS = 500
60
+ import type { TicketSource } from '../ports/types'
61
+
51
62
  const PAINT_MS = 250
52
- const ABORTABLE_STATUSES = new Set(['queued', 'running', 'paused', 'blocked'])
63
+ const ABORTABLE_STATUSES = new Set(['queued', 'running', 'collecting', 'paused', 'blocked'])
53
64
 
54
65
  function validAbortConfirmation(state: BuildState | undefined): boolean {
55
66
  return (
@@ -68,15 +79,6 @@ function isStaleAbortControlError(error: unknown): error is BuildControlError {
68
79
  )
69
80
  }
70
81
 
71
- function isDashboardRepositoryEvent(event: RepositoryEvent): boolean {
72
- return (
73
- event.type.startsWith('harvest.') ||
74
- event.type === 'dispatcher.intake-set' ||
75
- event.type === 'dispatcher.pause-set' ||
76
- event.type === 'dispatcher.auto-merge-default-set'
77
- )
78
- }
79
-
80
82
  interface ResumePrompt {
81
83
  slug: string
82
84
  escalationIds: string[]
@@ -92,6 +94,7 @@ export interface DispatchFrontendOptions {
92
94
  checkout?: string
93
95
  storeRef: string
94
96
  store: BuildStore
97
+ ticketSource?: () => Promise<TicketSource>
95
98
  env: Record<string, string | undefined>
96
99
  terminal: TerminalOut
97
100
  input: TerminalInput
@@ -100,6 +103,7 @@ export interface DispatchFrontendOptions {
100
103
  intervalMs?: number
101
104
  intake?: boolean
102
105
  defaultAutoMerge?: boolean
106
+ refreshScheduler?: RefreshScheduler
103
107
  clock?: Clock
104
108
  resolveDashboardRenderer?: DashboardRendererResolver
105
109
  launchChild?: (input: {
@@ -121,11 +125,7 @@ export class DispatchFrontend {
121
125
  private readonly region: LiveRegion
122
126
  private readonly keyboard
123
127
  private child: DispatchChildHandle | undefined
124
- private repositorySeq = 0
125
- /** Set only after a successful initial fold; every later `events()` call
126
- * takes the delta path. */
127
- private seeded = false
128
- private repositoryEvents: RepositoryEvent[] = []
128
+ private readonly repositoryFeed: DispatchRepositoryFeed
129
129
  private dispatchStatus: DispatchStatus = reduceDispatchStatus([], this.runId)
130
130
  private eventRefreshTail: Promise<void> = Promise.resolve()
131
131
  private cache: DashboardBuildPollCache | undefined
@@ -146,17 +146,22 @@ export class DispatchFrontend {
146
146
  private abortConfirmation: { slug: string } | undefined
147
147
  private accepting = false
148
148
  private cleanupInput: (() => void) | undefined
149
- private pollTimer: ReturnType<typeof setInterval> | undefined
149
+ private refresh: DashboardRefresh | undefined
150
+ private suspension: ReturnType<typeof installPresentationSuspension> | undefined
151
+ private readonly reader: BuildStore
150
152
  private paintTimer: ReturnType<typeof setInterval> | undefined
151
- private polling = false
152
- private pollInFlight: Promise<void> | undefined
153
153
  private actionTail: Promise<void> = Promise.resolve()
154
154
  private presentationRestored = false
155
155
  private operatorStopRequested = false
156
156
 
157
157
  constructor(private readonly opts: DispatchFrontendOptions) {
158
- this.standbyResolver = new StandbyIdentityResolver(opts.store, opts.repo)
158
+ this.reader = presentationReader(opts.store, () => this.refresh?.admitted ?? true)
159
159
  this.clock = opts.clock ?? systemClock
160
+ this.repositoryFeed = new DispatchRepositoryFeed(this.reader, opts.repo, this.clock)
161
+ this.standbyResolver = new StandbyIdentityResolver(this.reader, opts.repo, {
162
+ allowLookup: () => this.repositoryFeed.incompleteIdentities,
163
+ remember: (events, complete) => this.repositoryFeed.remember(events, complete),
164
+ })
160
165
  this.keyboard = createKeyboardProtocol(
161
166
  (chunk) => opts.terminal.write(chunk),
162
167
  opts.terminal.modes,
@@ -170,47 +175,14 @@ export class DispatchFrontend {
170
175
  * are retained for their existing replay reducers. */
171
176
  private async events(): Promise<RepositoryEvent[]> {
172
177
  const refresh = this.eventRefreshTail.then(async () => {
173
- if (!this.seeded) {
174
- // Initial fold (AUT-534): the whole-journal read the first poll used
175
- // to pay is replaced by AUT-489's bounded read where that is provably
176
- // equivalent. The bounded attempt is confined to the pre-launch
177
- // window (`this.child === undefined`): before `launchChild` no
178
- // run-scoped journal fact can carry `this.runId` (only the supervised
179
- // child appends run-scoped facts with it), so every run-scoped event
180
- // in the bounded subset is skipped by `reduceDispatchStatus` exactly
181
- // as it would be in a full replay, and the dashboard filter keeps
182
- // only durable types, which the subset carries in full. After launch
183
- // a bounded subset cannot guarantee the child's `run-started` under a
184
- // competing dispatcher's later anchor — dropping it would leave
185
- // `effectiveConfig` unset and the first frame would never render —
186
- // so a post-launch seed always takes the full read (the pre-AUT-534
187
- // behavior). `once` mode's teardown fold runs after the child exits,
188
- // so the same guard routes it to the full read.
189
- const seed =
190
- this.child === undefined
191
- ? await this.opts.store.getRepoStateEvents(this.opts.repo).catch(() =>
192
- // Bounded-read failure falls back to the exact pre-AUT-534
193
- // full read within this same seed attempt.
194
- this.opts.store.getRepoEvents(this.opts.repo, 0),
195
- )
196
- : await this.opts.store.getRepoEvents(this.opts.repo, 0)
197
- this.standbyResolver.ingest(seed)
198
- this.repositorySeq = seed.at(-1)?.seq ?? 0
199
- this.dispatchStatus = reduceDispatchStatus(seed, this.runId)
200
- this.repositoryEvents.push(...seed.filter(isDashboardRepositoryEvent))
201
- this.seeded = true
202
- return
203
- }
204
- const delta = await this.opts.store.getRepoEvents(this.opts.repo, this.repositorySeq)
205
- if (delta.length === 0) return
178
+ const delta = await this.repositoryFeed.refresh(false)
179
+ this.standbyResolver.ingest(this.repositoryFeed.identities)
206
180
  this.standbyResolver.ingest(delta)
207
- this.repositorySeq = delta.at(-1)!.seq
208
181
  this.dispatchStatus = reduceDispatchStatus(delta, this.runId, this.dispatchStatus)
209
- this.repositoryEvents.push(...delta.filter(isDashboardRepositoryEvent))
210
182
  })
211
183
  this.eventRefreshTail = refresh.catch(() => {})
212
184
  await refresh
213
- return this.repositoryEvents
185
+ return this.repositoryFeed.events
214
186
  }
215
187
 
216
188
  private async report(message: string, level: 'info' | 'warning' = 'info'): Promise<void> {
@@ -221,8 +193,10 @@ export class DispatchFrontend {
221
193
  })
222
194
  }
223
195
 
224
- private queue(operation: () => Promise<void>): void {
225
- const result = this.actionTail.then(operation)
196
+ private queue(operation: () => Promise<void>, interaction = true): void {
197
+ const result = this.actionTail.then(() =>
198
+ interaction ? interactionRead(operation) : operation(),
199
+ )
226
200
  this.actionTail = result.then(
227
201
  () => undefined,
228
202
  async (error) => {
@@ -231,7 +205,7 @@ export class DispatchFrontend {
231
205
  `dashboard action failed: ${error instanceof Error ? error.message : String(error)}`,
232
206
  'warning',
233
207
  )
234
- await this.renderOnce()
208
+ await this.renderOnce(interaction)
235
209
  } catch {
236
210
  // The next poll remains the recovery boundary.
237
211
  }
@@ -295,6 +269,7 @@ export class DispatchFrontend {
295
269
  }
296
270
 
297
271
  private paint(): void {
272
+ if (this.refresh !== undefined && !this.refresh.painting) return
298
273
  if (this.model === undefined) return
299
274
  const renderer = this.opts.resolveDashboardRenderer?.() ?? renderDashboard
300
275
  this.region.update(
@@ -310,7 +285,7 @@ export class DispatchFrontend {
310
285
  private async loadConfig(kind: string, rev: number): Promise<Config> {
311
286
  const key = `${kind}@${rev}`
312
287
  if (this.config !== undefined && this.configRef === key) return this.config
313
- const artifact = await this.opts.store.getRepoArtifact(this.opts.repo, kind, rev)
288
+ const artifact = await this.reader.getRepoArtifact(this.opts.repo, kind, rev)
314
289
  if (artifact === null) throw new Error(`effective config ${key} is not retrievable`)
315
290
  const parsed = configSchema.parse(JSON.parse(new TextDecoder().decode(artifact.content)))
316
291
  this.config = parsed
@@ -319,37 +294,69 @@ export class DispatchFrontend {
319
294
  return parsed
320
295
  }
321
296
 
322
- private async renderOnce(): Promise<void> {
323
- let repositoryEvents = await this.events()
324
- let status = this.dispatchStatus
325
- const ref = status.effectiveConfig
326
- // No filesystem fallback: the first frame waits for the child's durable,
327
- // run-correlated effective snapshot.
328
- if (ref === undefined) {
329
- if (status.health === 'failed' && status.warningNotice !== undefined) {
330
- this.region.update([status.warningNotice])
331
- }
332
- return
333
- }
334
- const config = await this.loadConfig(ref.kind, ref.rev)
335
- try {
336
- // Journal + digests (AUT-487): one journal read for the claimed set
337
- // (this class's cached `repositoryEvents` is dashboard-filtered, so the
338
- // claimed set needs the full journal, exactly as the old per-build scan
339
- // read it) plus one repo-scoped digest read — the sample's store
340
- // traffic stays flat as finished builds accumulate. A journal record
341
- // that does not yet exist reads as an empty journal (AUT-524); the
342
- // sample writes nothing.
343
- this.observationCount = await sampleUnclaimedObservationCount(this.opts.store, this.opts.repo)
344
- } catch {
345
- // Before the first successful sample there is no factual zero to place in
346
- // a complete frame. Leave the prior frame untouched and retry on the next
347
- // ordinary poll, without manufacturing a repository notice.
348
- if (this.observationCount === undefined) return
349
- }
350
- this.cache ??= new DashboardBuildPollCache(this.opts.store, this.opts.repo, config)
351
- const snapshot = await this.cache.refresh(config, this.configRevision)
352
- if (!this.cache.isCurrent(snapshot)) return
297
+ private async renderOnce(interaction = true): Promise<void> {
298
+ if (this.refresh !== undefined) return this.refresh.request(interaction)
299
+ return this.readFrame()
300
+ }
301
+
302
+ private readonly repositoryPoll = new RepositoryPollCache<{
303
+ repositoryEvents: RepositoryEvent[]
304
+ status: DispatchStatus
305
+ config: Config
306
+ observationCount: number
307
+ snapshot: DashboardPollSnapshot
308
+ }>()
309
+
310
+ private async readFrame(): Promise<void> {
311
+ if (this.refresh !== undefined && !this.refresh.admitted) return
312
+ const frame = await this.repositoryPoll.refresh({
313
+ position: () => this.reader.getRepoChangePosition(this.opts.repo),
314
+ now: () => this.clock().getTime(),
315
+ revision: 0,
316
+ enabled: !this.opts.once,
317
+ valid: (frame) => this.cache?.isCurrent(frame.snapshot) ?? false,
318
+ admitted: () => this.refresh === undefined || this.refresh.admitted,
319
+ nextPollMs: this.refresh?.intervalMs ?? 0,
320
+ read: async ({ fullEnrichment }) => {
321
+ const repositoryEvents = await this.events()
322
+ const status = this.dispatchStatus
323
+ const ref = status.effectiveConfig
324
+ if (ref === undefined) {
325
+ if (status.health === 'failed' && status.warningNotice !== undefined)
326
+ this.region.update([status.warningNotice])
327
+ // Startup is incomplete: retry at the same position.
328
+ return undefined
329
+ }
330
+ const config = await this.loadConfig(ref.kind, ref.rev)
331
+ let observationCount: number
332
+ try {
333
+ observationCount = unclaimedObservationCount({
334
+ digests: await this.reader.getRepoBuildDigests(this.opts.repo),
335
+ harvestEvents: repositoryEvents,
336
+ })
337
+ } catch {
338
+ // Incomplete snapshots never acknowledge the sampled position.
339
+ this.syncControls()
340
+ this.paint()
341
+ return undefined
342
+ }
343
+ this.cache ??= new DashboardBuildPollCache(this.reader, this.opts.repo, config)
344
+ const snapshot = await this.cache.refresh(config, this.configRevision, fullEnrichment)
345
+ if (!this.opts.once)
346
+ await this.standbyResolver.refresh(this.runId, status.yieldedHolder, this.clock())
347
+ await this.repositoryFeed.save()
348
+ if (!this.cache.isCurrent(snapshot)) return undefined
349
+ return { repositoryEvents, status, config, observationCount, snapshot }
350
+ },
351
+ })
352
+ if (frame === undefined) return
353
+ let { repositoryEvents, status } = frame
354
+ const { config, snapshot } = frame
355
+ const standby = this.opts.once
356
+ ? undefined
357
+ : this.standbyResolver.current(this.runId, status.yieldedHolder, this.clock())
358
+ this.observationCount = frame.observationCount
359
+ this.refresh?.activity(snapshot.states.size > 0)
353
360
 
354
361
  if (this.resumePrompt !== undefined) {
355
362
  const state = snapshot.states.get(this.resumePrompt.slug)
@@ -370,11 +377,9 @@ export class DispatchFrontend {
370
377
  const previous = this.model === undefined ? [] : dashboardSelections(this.model)
371
378
  const warningLines = [
372
379
  ...status.roleWarnings,
380
+ ...forgeReadinessWarnings(status),
373
381
  ...(status.warningNotice !== undefined ? [status.warningNotice] : []),
374
382
  ]
375
- const standby = this.opts.once
376
- ? undefined
377
- : await this.standbyResolver.refresh(this.runId, status.yieldedHolder, this.clock())
378
383
  const projected = buildDashboardFromProjected(
379
384
  snapshot.builds,
380
385
  {
@@ -382,7 +387,7 @@ export class DispatchFrontend {
382
387
  ...(standby !== undefined ? { standby } : {}),
383
388
  queued: status.queued ?? 0,
384
389
  activeCount: [...snapshot.states.values()].filter(
385
- (state) => state.status !== 'done' && state.status !== 'aborted',
390
+ (state) => state.kind !== 'node' && state.status !== 'done' && state.status !== 'aborted',
386
391
  ).length,
387
392
  capacity: config.capacity,
388
393
  observationCount: this.observationCount,
@@ -527,7 +532,7 @@ export class DispatchFrontend {
527
532
  follow: true,
528
533
  scroll: 0,
529
534
  }
530
- this.sessionFeed = new SessionStreamFeed(this.opts.store, captured.slug)
535
+ this.sessionFeed = new SessionStreamFeed(this.reader, captured.slug)
531
536
  this.syncControls()
532
537
  this.paint()
533
538
  // Kick the first read immediately rather than waiting one interval.
@@ -584,6 +589,7 @@ export class DispatchFrontend {
584
589
  * feed's identity+cursor fence — the same pattern the DispatchLoop path
585
590
  * uses, from the same shared feed module. */
586
591
  private pollSessionFeed(): void {
592
+ if (this.refresh !== undefined && !this.refresh.admitted) return
587
593
  const view = this.view
588
594
  if (view?.kind !== 'session') return
589
595
  if (view.status !== 'open' && view.error === undefined) {
@@ -618,7 +624,7 @@ export class DispatchFrontend {
618
624
  }
619
625
  this.syncControls()
620
626
  this.paint()
621
- })
627
+ }, false)
622
628
  })
623
629
  .catch(() => {
624
630
  // The feed contains its own failures; the next poll retries.
@@ -660,7 +666,7 @@ export class DispatchFrontend {
660
666
  const ref = this.dispatchStatus.effectiveConfig
661
667
  if (ref === undefined) throw new Error('effective config is not available')
662
668
  const config = await this.loadConfig(ref.kind, ref.rev)
663
- this.cache ??= new DashboardBuildPollCache(this.opts.store, this.opts.repo, config)
669
+ this.cache ??= new DashboardBuildPollCache(this.reader, this.opts.repo, config)
664
670
  let snapshot = await this.cache.refresh(config, this.configRevision)
665
671
  while (!this.cache.isCurrent(snapshot)) {
666
672
  snapshot = await this.cache.refresh(config, this.configRevision)
@@ -682,11 +688,12 @@ export class DispatchFrontend {
682
688
  }
683
689
 
684
690
  private async buildAction(
685
- kind: 'pause' | 'resume' | 'discard' | 'toggle-auto-merge' | 'abort',
691
+ kind: 'pause' | 'resume' | 'discard' | 'hold' | 'land' | 'abort',
686
692
  slug: string,
687
693
  ): Promise<void> {
688
694
  const result = await controlBuild({
689
695
  store: this.opts.store,
696
+ ticketSource: this.opts.ticketSource,
690
697
  repo: this.opts.repo,
691
698
  slug,
692
699
  env: this.opts.env,
@@ -716,9 +723,9 @@ export class DispatchFrontend {
716
723
  ? `build ${slug}: discard requested`
717
724
  : result.command === 'abort'
718
725
  ? `build ${slug}: abort requested`
719
- : result.command === 'auto-merge-on'
720
- ? `build ${slug}: auto-merge requested`
721
- : `build ${slug}: auto-merge cancelled`
726
+ : result.command === 'land'
727
+ ? `build ${slug}: landing consent requested`
728
+ : `build ${slug}: landing hold requested`
722
729
  await this.report(message)
723
730
  await this.renderOnce()
724
731
  }
@@ -735,18 +742,6 @@ export class DispatchFrontend {
735
742
  await this.renderOnce()
736
743
  }
737
744
 
738
- private async toggleDefaultAutoMerge(): Promise<void> {
739
- const event = await toggleRepositorySetting({
740
- store: this.opts.store,
741
- repo: this.opts.repo,
742
- user: buildControlUser(this.opts.env),
743
- setting: 'auto-merge-default',
744
- run: this.runId,
745
- })
746
- await this.report(`dispatcher auto-merge default ${event.enabled ? 'ON' : 'OFF'}`)
747
- await this.renderOnce()
748
- }
749
-
750
745
  private async bulk(direction: 'pause' | 'resume'): Promise<void> {
751
746
  const summary = await bulkControlRepository({
752
747
  store: this.opts.store,
@@ -838,6 +833,7 @@ export class DispatchFrontend {
838
833
  }
839
834
 
840
835
  private onInput(input: TerminalInputEvent): void {
836
+ this.refresh?.interaction()
841
837
  if (!this.accepting) return
842
838
  if (input.type === 'interrupt') {
843
839
  this.requestOperatorStop()
@@ -884,7 +880,7 @@ export class DispatchFrontend {
884
880
  if (enter) {
885
881
  // List/detail identity is captured synchronously before any Store read;
886
882
  // a later selection move cannot retarget this navigation.
887
- void this.openSelected().catch((error) =>
883
+ void interactionRead(() => this.openSelected()).catch((error) =>
888
884
  this.report(
889
885
  `dashboard open action failed: ${error instanceof Error ? error.message : String(error)}`,
890
886
  'warning',
@@ -902,13 +898,13 @@ export class DispatchFrontend {
902
898
  if (this.selection?.kind === 'global' && this.view === undefined)
903
899
  this.queue(() => this.toggleIntake())
904
900
  break
905
- case 'm': {
901
+ case 'o':
902
+ case 'l': {
906
903
  const slug = this.selectedSlug()
907
- if (this.view === undefined && this.selection?.kind === 'global') {
908
- this.queue(() => this.toggleDefaultAutoMerge())
909
- } else if (slug !== undefined) {
910
- this.queue(() => this.buildAction('toggle-auto-merge', slug))
911
- }
904
+ if (slug !== undefined)
905
+ this.queue(() =>
906
+ this.buildAction(input.text.toLowerCase() === 'o' ? 'hold' : 'land', slug),
907
+ )
912
908
  break
913
909
  }
914
910
  case 'p': {
@@ -953,38 +949,49 @@ export class DispatchFrontend {
953
949
  }
954
950
  }
955
951
 
956
- private startPresentation(): void {
957
- this.accepting = true
952
+ private listen(): void {
958
953
  this.cleanupInput = this.opts.input.start((input) => this.onInput(input), {
959
954
  onListening: () => this.keyboard.query(),
960
955
  onKeyboardFlags: (flags) => this.keyboard.reported(flags),
961
956
  onDeviceAttributes: () => this.keyboard.deviceAttributes(),
957
+ onFocus: (focused) => this.refresh?.focus(focused),
958
+ onInteraction: () => this.refresh?.interaction(),
959
+ onSuspend: () => this.suspension?.suspend(),
962
960
  })
963
- const poll = (): void => {
964
- if (this.polling) return
965
- this.polling = true
966
- const current = this.renderOnce()
967
- .catch(async (error) => {
968
- try {
969
- await this.report(
970
- `dashboard render failed: ${error instanceof Error ? error.message : String(error)}`,
971
- 'warning',
972
- )
973
- } catch {
974
- // retry on the next poll
975
- }
976
- })
977
- .finally(() => {
978
- if (this.pollInFlight === current) this.pollInFlight = undefined
979
- this.polling = false
980
- })
981
- this.pollInFlight = current
982
- }
983
- this.pollTimer = setInterval(poll, POLL_MS)
961
+ }
962
+
963
+ private startPresentation(): void {
964
+ this.accepting = true
965
+ this.refresh = new DashboardRefresh(async () => {
966
+ try {
967
+ await this.readFrame()
968
+ } catch (error) {
969
+ if (this.refresh?.admitted)
970
+ await this.report(
971
+ `dashboard render failed: ${error instanceof Error ? error.message : String(error)}`,
972
+ 'warning',
973
+ )
974
+ throw error
975
+ }
976
+ }, this.opts.refreshScheduler)
977
+ this.listen()
978
+ this.opts.terminal.modes.enter(FOCUS_REPORTING_MODE)
979
+ this.suspension = installPresentationSuspension(
980
+ this.opts.terminal.modes,
981
+ () => {
982
+ this.refresh?.suspend()
983
+ this.cleanupInput?.()
984
+ this.cleanupInput = undefined
985
+ },
986
+ () => {
987
+ this.listen()
988
+ this.region.invalidate()
989
+ this.refresh?.resume()
990
+ },
991
+ )
984
992
  this.paintTimer = setInterval(() => this.paint(), PAINT_MS)
985
- this.pollTimer.unref?.()
986
993
  this.paintTimer.unref?.()
987
- poll()
994
+ void this.refresh.request()
988
995
  }
989
996
 
990
997
  private requestOperatorStop(): void {
@@ -1003,13 +1010,14 @@ export class DispatchFrontend {
1003
1010
  if (this.presentationRestored) return
1004
1011
  this.presentationRestored = true
1005
1012
  this.accepting = false
1013
+ this.refresh?.stop()
1014
+ this.suspension?.close()
1015
+ this.opts.terminal.modes.leave(FOCUS_REPORTING_MODE)
1006
1016
  try {
1007
1017
  this.cleanupInput?.()
1008
1018
  } finally {
1009
1019
  this.cleanupInput = undefined
1010
- if (this.pollTimer !== undefined) clearInterval(this.pollTimer)
1011
1020
  if (this.paintTimer !== undefined) clearInterval(this.paintTimer)
1012
- this.pollTimer = undefined
1013
1021
  this.paintTimer = undefined
1014
1022
  this.region.finish()
1015
1023
  }
@@ -1018,22 +1026,24 @@ export class DispatchFrontend {
1018
1026
  private async finishPresentation(): Promise<void> {
1019
1027
  if (!this.presentationRestored) {
1020
1028
  this.accepting = false
1029
+ this.refresh?.stop()
1030
+ this.suspension?.close()
1031
+ this.opts.terminal.modes.leave(FOCUS_REPORTING_MODE)
1021
1032
  try {
1022
1033
  this.cleanupInput?.()
1023
1034
  } finally {
1024
1035
  this.cleanupInput = undefined
1025
1036
  }
1026
- if (this.pollTimer !== undefined) clearInterval(this.pollTimer)
1027
1037
  if (this.paintTimer !== undefined) clearInterval(this.paintTimer)
1028
- this.pollTimer = undefined
1029
1038
  this.paintTimer = undefined
1030
1039
  }
1031
1040
  try {
1032
- await this.pollInFlight
1041
+ await this.refresh?.join()
1033
1042
  await this.actionTail
1034
- await this.renderOnce()
1043
+ if (this.opts.once) await this.readFrame()
1044
+ else if (!this.presentationRestored) await this.refresh?.finalRefresh()
1035
1045
  } catch {
1036
- // final frame is best-effort
1046
+ // Final presentation remains best-effort.
1037
1047
  } finally {
1038
1048
  this.region.finish()
1039
1049
  }
@@ -1049,21 +1059,14 @@ export class DispatchFrontend {
1049
1059
  payload: { enabled: this.opts.intake, run: this.runId },
1050
1060
  })
1051
1061
  }
1052
- if (this.opts.defaultAutoMerge !== undefined) {
1053
- await this.opts.store.appendRepo(this.opts.repo, {
1054
- actor,
1055
- type: 'dispatcher.auto-merge-default-set',
1056
- payload: { enabled: this.opts.defaultAutoMerge, run: this.runId },
1057
- })
1058
- }
1059
1062
 
1060
- // Warm the initial fold before `launchChild` (AUT-534): the bounded seed
1061
- // is only safe while `this.child === undefined`, so the one opportunity
1062
- // to take it is here. A failed warm-up leaves the seed unset; the poll
1063
- // loop's existing failure reporting covers the retry, which then takes
1064
- // the full-read path post-launch. `once` mode gains no read — its single
1065
- // fold runs from `finishPresentation()` after the child exits.
1066
- if (!this.opts.once) await this.events().catch(() => {})
1063
+ try {
1064
+ const delta = await this.repositoryFeed.warm()
1065
+ this.standbyResolver.ingest(this.repositoryFeed.identities)
1066
+ this.dispatchStatus = reduceDispatchStatus(delta, this.runId, this.dispatchStatus)
1067
+ } catch {
1068
+ /* Display initialization must not gate the kernel. */
1069
+ }
1067
1070
 
1068
1071
  const options: DispatchChildOptions = {
1069
1072
  targetRepo: this.opts.checkout ?? this.opts.repo,
@@ -1104,6 +1107,7 @@ export class DispatchFrontend {
1104
1107
  this.opts.signal?.removeEventListener('abort', stop)
1105
1108
  await this.child.stop()
1106
1109
  await this.finishPresentation()
1110
+ await this.repositoryFeed.save(true)
1107
1111
  }
1108
1112
  }
1109
1113
  }
@@ -1,6 +1,6 @@
1
+ import { readDispatcherRunFacts, readOpenTick } from '../store/reduced-reads'
1
2
  import { distributionPath } from '../distribution'
2
3
  import { DISPATCHER } from '../events/envelope'
3
- import { hasOpenTick } from '../processes/tick-state'
4
4
  import type { BuildStore } from '../store/types'
5
5
 
6
6
  export const DISPATCH_CHILD_OPTIONS_ENV = 'AB_DISPATCH_CHILD_OPTIONS'
@@ -168,10 +168,8 @@ export function superviseDispatchChild(deps: DispatchChildSupervisorDeps): Dispa
168
168
  // chooses/awaits process termination, avoiding check-then-append races.
169
169
  const completed = child.exited.then(async (exitCode): Promise<DispatchChildResult> => {
170
170
  const processSignal = child.signalCode === null ? requestedSignal : String(child.signalCode)
171
- const events = await deps.store.getRepoEvents(deps.repo)
172
- const recorded = events.findLast(
173
- (event) => event.type === 'dispatcher.run-stopped' && event.payload.run === deps.run,
174
- )
171
+ const recorded = (await readDispatcherRunFacts(deps.store, deps.repo, deps.run, false)).value
172
+ .stop
175
173
  if (recorded?.type === 'dispatcher.run-stopped') {
176
174
  const signal = processSignal ?? recorded.payload.signal
177
175
  return {
@@ -245,12 +243,21 @@ export function superviseDispatchChild(deps: DispatchChildSupervisorDeps): Dispa
245
243
  // Ready with no durable build to recover. Let an open tick reach its
246
244
  // normal boundary; all non-tick work is lease-backed/recoverable and a
247
245
  // child stuck there is safe to terminate.
248
- const events = await deps.store.getRepoEvents(deps.repo)
246
+ let open = true
247
+ try {
248
+ const record = await deps.store.getRepo(deps.repo)
249
+ open =
250
+ record?.tick?.run === deps.run
251
+ ? record.tick.open !== undefined
252
+ : await readOpenTick(deps.store, deps.repo, deps.run, false)
253
+ } catch {
254
+ // Unreadable telemetry cannot authorize an unsafe kill.
255
+ }
249
256
  // The child may have exited while the asynchronous journal read was in
250
257
  // flight. Re-check at the force boundary so evidence never claims a
251
258
  // SIGKILL that was not actually sent.
252
259
  if (child.exitCode !== null) return
253
- if (hasOpenTick(events, deps.run)) {
260
+ if (open) {
254
261
  await child.exited
255
262
  return
256
263
  }