@defrex/autobuild 1.11.1 → 1.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 (213) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +601 -203
  3. package/bin/ab-build-runner.ts +8 -0
  4. package/docs/answering-blocked-builds.md +32 -2
  5. package/docs/architecture.md +188 -57
  6. package/docs/assets/headline-wide.png +0 -0
  7. package/docs/cli.md +1 -1
  8. package/docs/configuration.md +120 -23
  9. package/docs/dispatcher.md +19 -8
  10. package/docs/integration-overview.md +1 -1
  11. package/docs/integration-tree.md +33 -18
  12. package/docs/merge-policy.md +7 -2
  13. package/docs/operating.md +5 -3
  14. package/docs/operator-api.md +48 -25
  15. package/docs/operator-surfaces.md +39 -3
  16. package/docs/optimization-nodes.md +10 -8
  17. package/docs/plugin-authoring.md +46 -18
  18. package/docs/remote-store-protocol.md +51 -12
  19. package/docs/remote-ticket-protocol.md +85 -38
  20. package/docs/restacking.md +48 -3
  21. package/docs/setup.md +2 -1
  22. package/docs/ticket-migration.md +2 -2
  23. package/docs/ticket-sources.md +23 -8
  24. package/docs/tickets.md +4 -4
  25. package/docs/troubleshooting.md +17 -2
  26. package/docs/verification.md +3 -1
  27. package/package.json +3 -3
  28. package/packages/core/src/cli/ambient-errors.ts +17 -0
  29. package/packages/core/src/cli/bounded-io.ts +174 -0
  30. package/packages/core/src/cli/build-control.ts +72 -6
  31. package/packages/core/src/cli/dashboard/actions.ts +4 -0
  32. package/packages/core/src/cli/dashboard/integration-row.ts +43 -19
  33. package/packages/core/src/cli/dashboard/model.ts +93 -29
  34. package/packages/core/src/cli/dashboard/poll.ts +231 -34
  35. package/packages/core/src/cli/dashboard/queue.ts +21 -10
  36. package/packages/core/src/cli/dashboard/render.ts +14 -37
  37. package/packages/core/src/cli/dashboard/row-text.ts +26 -8
  38. package/packages/core/src/cli/dashboard/tone-ansi.ts +39 -0
  39. package/packages/core/src/cli/dashboard/vocabulary.ts +165 -20
  40. package/packages/core/src/cli/dispatch-frontend.ts +2 -1
  41. package/packages/core/src/cli/dispatch-handoff.ts +41 -10
  42. package/packages/core/src/cli/dispatch-launch-contract.ts +5 -0
  43. package/packages/core/src/cli/dispatch-launcher-cadence.ts +80 -0
  44. package/packages/core/src/cli/dispatch-launcher.ts +9 -10
  45. package/packages/core/src/cli/dispatch-preflight.ts +12 -3
  46. package/packages/core/src/cli/dispatch-release-observer.ts +53 -0
  47. package/packages/core/src/cli/dispatch-runtime-cache.ts +204 -82
  48. package/packages/core/src/cli/dispatch-runtime-dependencies.ts +250 -43
  49. package/packages/core/src/cli/dispatch-tickets.ts +33 -12
  50. package/packages/core/src/cli/dispatch-upgrade-install.ts +36 -16
  51. package/packages/core/src/cli/dispatch-upgrade-source.ts +8 -2
  52. package/packages/core/src/cli/dispatch-yield-observer.ts +82 -0
  53. package/packages/core/src/cli/dispatch.ts +595 -149
  54. package/packages/core/src/cli/env.ts +2 -15
  55. package/packages/core/src/cli/help.ts +43 -28
  56. package/packages/core/src/cli/main.ts +11 -7
  57. package/packages/core/src/cli/production-store.ts +102 -0
  58. package/packages/core/src/cli/publication-settlement.ts +4 -0
  59. package/packages/core/src/cli/remote-poll.ts +22 -5
  60. package/packages/core/src/cli/repo-state.ts +2 -3
  61. package/packages/core/src/cli/repository-status.ts +44 -28
  62. package/packages/core/src/cli/sessionless-store.ts +26 -0
  63. package/packages/core/src/cli/status.ts +188 -47
  64. package/packages/core/src/cli/store-opening.ts +26 -57
  65. package/packages/core/src/cli/store-ref.ts +6 -1
  66. package/packages/core/src/cli/ticket-start.ts +3 -3
  67. package/packages/core/src/cli/ticket.ts +12 -11
  68. package/packages/core/src/cli/wait.ts +8 -28
  69. package/packages/core/src/cli/watch.ts +113 -50
  70. package/packages/core/src/config/reference-metadata.ts +7 -1
  71. package/packages/core/src/config/reference.ts +5 -2
  72. package/packages/core/src/config/schema.ts +51 -16
  73. package/packages/core/src/distribution-packaging.ts +156 -18
  74. package/packages/core/src/events/catalog-identity.ts +28 -0
  75. package/packages/core/src/events/catalog.ts +3 -9
  76. package/packages/core/src/events/compatibility.ts +2 -30
  77. package/packages/core/src/events/payloads.ts +85 -14
  78. package/packages/core/src/events/policy.ts +3 -0
  79. package/packages/core/src/events/repository.ts +15 -4
  80. package/packages/core/src/events/sessions.ts +1 -1
  81. package/packages/core/src/events/validation-error.ts +12 -0
  82. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +36 -0
  83. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/0a10010ee5cf2e47.json +577 -0
  84. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/227701361be6d1e0.json +490 -0
  85. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3064e337cc75f8d6.json +310 -0
  86. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/76e5043bae7a80ab.json +86 -0
  87. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/87a917802870bbed.json +87 -0
  88. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/9d85616e5b9e24c1.json +500 -0
  89. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a1e90a969d32a367.json +307 -0
  90. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/c7c94fbe7f63cf07.json +84 -0
  91. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/da3bc91c49211eab.json +310 -0
  92. package/packages/core/src/kernel/auto-merge-default.ts +2 -1
  93. package/packages/core/src/kernel/capacity-build.ts +21 -0
  94. package/packages/core/src/kernel/clean-restack-policy.ts +40 -0
  95. package/packages/core/src/kernel/discard-in-flight.ts +13 -0
  96. package/packages/core/src/kernel/dispatch-capacity.ts +578 -235
  97. package/packages/core/src/kernel/done-escalations.ts +269 -0
  98. package/packages/core/src/kernel/engine.ts +30 -17
  99. package/packages/core/src/kernel/integration-landing.ts +24 -4
  100. package/packages/core/src/kernel/integration-stack.ts +39 -0
  101. package/packages/core/src/kernel/janitor-failure.ts +20 -1
  102. package/packages/core/src/kernel/log-index-value.ts +3 -0
  103. package/packages/core/src/kernel/log-index.ts +41 -2
  104. package/packages/core/src/kernel/measurement.ts +24 -0
  105. package/packages/core/src/kernel/open-pr-backpressure.ts +3 -3
  106. package/packages/core/src/kernel/read-facts.ts +8 -370
  107. package/packages/core/src/kernel/reducer-registry.ts +43 -125
  108. package/packages/core/src/kernel/reducer-revisions.ts +18 -0
  109. package/packages/core/src/kernel/reducer-value-entry.ts +98 -0
  110. package/packages/core/src/kernel/reducer-value-index.ts +75 -0
  111. package/packages/core/src/kernel/reducer.ts +84 -16
  112. package/packages/core/src/kernel/reopen-state.ts +10 -0
  113. package/packages/core/src/kernel/repository-attention.ts +14 -5
  114. package/packages/core/src/kernel/repository-read-facts.ts +375 -0
  115. package/packages/core/src/kernel/ticket-starts.ts +15 -4
  116. package/packages/core/src/kernel/verify-stage-state.ts +145 -3
  117. package/packages/core/src/kernel/verify-stages.ts +46 -7
  118. package/packages/core/src/operator/attention.ts +28 -3
  119. package/packages/core/src/operator/done-escalations.ts +38 -0
  120. package/packages/core/src/operator/presentation.ts +14 -1
  121. package/packages/core/src/operator/protocol.ts +8 -5
  122. package/packages/core/src/operator/query.ts +72 -57
  123. package/packages/core/src/operator/registry.ts +19 -15
  124. package/packages/core/src/operator/ticket-start.ts +8 -7
  125. package/packages/core/src/operator/tickets.ts +28 -9
  126. package/packages/core/src/plugin-sdk/index.ts +10 -0
  127. package/packages/core/src/plugins/manifest.ts +14 -1
  128. package/packages/core/src/ports/forge/create.ts +8 -0
  129. package/packages/core/src/ports/forge/github-transport.ts +5 -1
  130. package/packages/core/src/ports/forge/github.ts +3 -0
  131. package/packages/core/src/ports/tickets/contract.ts +147 -76
  132. package/packages/core/src/ports/tickets/create.ts +47 -7
  133. package/packages/core/src/ports/tickets/fake.ts +8 -4
  134. package/packages/core/src/ports/tickets/file-codec.ts +4 -3
  135. package/packages/core/src/ports/tickets/file.ts +7 -3
  136. package/packages/core/src/ports/tickets/github.ts +1 -0
  137. package/packages/core/src/ports/tickets/grants.ts +11 -3
  138. package/packages/core/src/ports/tickets/hosted-index.ts +5 -0
  139. package/packages/core/src/ports/tickets/linear.ts +28 -9
  140. package/packages/core/src/ports/tickets/migration.ts +4 -4
  141. package/packages/core/src/ports/tickets/operations.ts +4 -2
  142. package/packages/core/src/ports/tickets/priority-labels.ts +213 -0
  143. package/packages/core/src/ports/tickets/priority.ts +127 -21
  144. package/packages/core/src/ports/tickets/remote-protocol.ts +10 -0
  145. package/packages/core/src/ports/tickets/remote.ts +104 -11
  146. package/packages/core/src/ports/tickets/revision.ts +5 -3
  147. package/packages/core/src/ports/tickets/search.ts +9 -0
  148. package/packages/core/src/ports/tickets/tree.ts +8 -6
  149. package/packages/core/src/ports/types.ts +30 -15
  150. package/packages/core/src/ports/workspace/build-execution.ts +4 -0
  151. package/packages/core/src/ports/workspace/builtin-capabilities.ts +4 -0
  152. package/packages/core/src/ports/workspace/create.ts +16 -3
  153. package/packages/core/src/ports/workspace/execution-exit-marker.ts +41 -0
  154. package/packages/core/src/ports/workspace/fake.ts +15 -3
  155. package/packages/core/src/ports/workspace/recovery-step.ts +101 -0
  156. package/packages/core/src/ports/workspace/vercel-sandbox.ts +510 -145
  157. package/packages/core/src/processes/build-execution-state.ts +4 -0
  158. package/packages/core/src/processes/build-runner.ts +14 -1
  159. package/packages/core/src/processes/dispatcher.ts +777 -288
  160. package/packages/core/src/processes/execution-no-progress.ts +1 -0
  161. package/packages/core/src/processes/execution-settlement.ts +1 -0
  162. package/packages/core/src/processes/harvest-runner.ts +12 -7
  163. package/packages/core/src/processes/infrastructure-failure-budget.ts +7 -2
  164. package/packages/core/src/processes/invocation-budget.ts +176 -0
  165. package/packages/core/src/processes/publication-loss.ts +38 -3
  166. package/packages/core/src/processes/workspace-preservation.ts +86 -15
  167. package/packages/core/src/store/contract.ts +81 -3
  168. package/packages/core/src/store/event-reads.ts +30 -1
  169. package/packages/core/src/store/local/capabilities.ts +115 -0
  170. package/packages/core/src/store/local/store.ts +86 -56
  171. package/packages/core/src/store/reduced-reads.ts +32 -1
  172. package/packages/core/src/store/reducer-value-read.ts +235 -0
  173. package/packages/core/src/store/reducer-value-shapes.json +6722 -6475
  174. package/packages/core/src/store/reducer-value-validation.ts +181 -33
  175. package/packages/core/src/store/reducer-values.ts +36 -204
  176. package/packages/core/src/store/remote/client.ts +169 -29
  177. package/packages/core/src/store/remote/compatibility.ts +113 -56
  178. package/packages/core/src/store/remote/credentials.ts +4 -1
  179. package/packages/core/src/store/remote/protocol.ts +3 -0
  180. package/packages/core/src/store/remote/released-clients.json +22 -0
  181. package/packages/core/src/store/remote/released-reducer-values/1.12.0.json +35806 -0
  182. package/packages/core/src/store/remote/released-reducer-values/1.13.0.json +35966 -0
  183. package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
  184. package/packages/core/src/store/remote/released-value-policy.ts +144 -0
  185. package/packages/core/src/store/remote/retry.ts +406 -0
  186. package/packages/core/src/store/rollup-lease.ts +41 -0
  187. package/packages/core/src/store/rollups.ts +7 -38
  188. package/packages/core/src/store/snapshots.ts +1 -1
  189. package/packages/core/src/testing/dispatch-read-budget.ts +409 -14
  190. package/packages/core/src/testing/import-graph.ts +78 -0
  191. package/packages/core/src/testing/index.ts +2 -0
  192. package/packages/core/src/testing/invocation-budget.ts +42 -0
  193. package/packages/core/src/testing/reduced-read-budget.ts +602 -40
  194. package/packages/core/src/testing/released-value-coverage.ts +423 -0
  195. package/packages/core/src/testing/slot-agreement.ts +52 -0
  196. package/packages/core/src/web/assets/app.js +5 -5
  197. package/packages/core/src/web/overview-source.ts +19 -6
  198. package/skills/guide/SKILL.md +245 -103
  199. package/skills/guide/references/integration-tree.md +33 -18
  200. package/skills/guide/references/merge-policy.md +7 -2
  201. package/skills/guide/references/operator-api.md +48 -25
  202. package/skills/guide/references/optimization-nodes.md +10 -8
  203. package/skills/guide/references/plugin-authoring.md +46 -18
  204. package/skills/guide/references/remote-store-protocol.md +51 -12
  205. package/skills/guide/references/remote-ticket-protocol.md +85 -38
  206. package/skills/guide/references/restacking.md +48 -3
  207. package/skills/guide/references/setup.md +2 -1
  208. package/skills/guide/references/ticket-migration.md +2 -2
  209. package/skills/operate/SKILL.md +114 -65
  210. package/skills/plan/SKILL.md +4 -3
  211. package/skills/spec/SKILL.md +9 -5
  212. package/skills/tickets/SKILL.md +25 -17
  213. package/templates/hosted-service/package.json +2 -2
@@ -1,12 +1,11 @@
1
- import { enrichIntegrationRows } from './integration-row'
1
+ import { enrichIntegrationRows, unresolvedIntegrationRecords } from './integration-row'
2
2
  import {
3
3
  dispatchCapacity,
4
4
  startClaimDemand,
5
- urgentClaimDemand,
5
+ claimDemand,
6
6
  type CapacityBuild,
7
7
  } from '../../kernel/dispatch-capacity'
8
8
  import type { DispatchStatus } from '../../kernel/dispatch-status'
9
- import { migrationIdentity } from '../../kernel/ticket-migrations'
10
9
  import {
11
10
  openBuildWorkspaceReducer,
12
11
  provisionMarkerReducer,
@@ -17,6 +16,8 @@ import type { PipelineSourceMeta } from '../../config/pipeline-source'
17
16
  import type { AbEvent } from '../../events/catalog'
18
17
  import { buildReducer, type BuildAcc, type BuildState } from '../../kernel/reducer'
19
18
  import { landingRestackDue } from '../../kernel/engine'
19
+ import { openOnDone } from '../../kernel/done-escalations'
20
+ import { capacityBuildFromFacts } from '../../kernel/capacity-build'
20
21
  import { leafRestackReducer, type LeafRestackState } from '../../kernel/leaf-restack-state'
21
22
  import {
22
23
  BUILD_EFFECTIVE_CONFIG_ARTIFACT,
@@ -32,10 +33,12 @@ import type {
32
33
  } from '../../store/types'
33
34
  import {
34
35
  readBuildFacts,
36
+ readDoneEscalations,
35
37
  type CurrentBuildFacts,
36
38
  type RepositoryReadFacts,
37
39
  } from '../../store/reduced-reads'
38
40
  import { dispatchWarningLines, repositoryQueueDepth } from './header'
41
+ import { mapBounded } from '../../web/bounded'
39
42
  import {
40
43
  projectBuild,
41
44
  projectBuildFromFacts,
@@ -49,9 +52,15 @@ import {
49
52
  * row's session history with authoritative stream ids and statuses (SPEC §9).
50
53
  * `getArtifact` is optional: when present, the effective-config artifact's
51
54
  * metadata decorates each row with its pinned pipeline source and revision
52
- * (SPEC §16.1). */
55
+ * (SPEC §16.1). A reader with saved values, the change position, the open
56
+ * builds and the changed-builds feed (every `BuildStore`) takes the bounded
57
+ * path; the listing path serves narrow readers only. */
53
58
  export interface DashboardBuildReader {
54
59
  getReducerValue?: BuildStore['getReducerValue']
60
+ getRepoChangePosition?: BuildStore['getRepoChangePosition']
61
+ listOpenBuilds?: BuildStore['listOpenBuilds']
62
+ listBuildsChangedSince?: BuildStore['listBuildsChangedSince']
63
+ getBuild?: BuildStore['getBuild']
55
64
  listBuildsForRepo(repo: string): Promise<BuildRecord[]>
56
65
  getEvents(slug: string, sinceSeq?: number): Promise<AbEvent[]>
57
66
  listStreams?(scope: StreamScope): Promise<StreamRecord[]>
@@ -98,31 +107,63 @@ interface ReducedEntry {
98
107
  state: BuildState
99
108
  workspace: boolean
100
109
  provisioning: boolean
110
+ provisioningSeq?: number
101
111
  restackDue: boolean
102
112
  build: DashboardBuild | null
103
113
  }
104
114
 
105
115
  type PollEntry = LiveEntry | TerminalEntry | ReducedEntry
106
116
 
117
+ /** One visible build on the bounded path: its saved facts and row
118
+ * enrichment, so a config change re-projects it without reading events. */
119
+ interface BoundedEntry {
120
+ record: BuildRecord
121
+ facts: CurrentBuildFacts
122
+ enrichment: RowEnrichment
123
+ capacity: CapacityBuild
124
+ build: DashboardBuild | null
125
+ }
126
+
127
+ type BoundedReader = DashboardBuildReader &
128
+ Pick<
129
+ BuildStore,
130
+ | 'getReducerValue'
131
+ | 'getRepoChangePosition'
132
+ | 'listOpenBuilds'
133
+ | 'listBuildsChangedSince'
134
+ | 'getBuild'
135
+ >
136
+
137
+ function boundedReader(reader: DashboardBuildReader): BoundedReader | undefined {
138
+ return reader.getReducerValue !== undefined &&
139
+ reader.getRepoChangePosition !== undefined &&
140
+ reader.listOpenBuilds !== undefined &&
141
+ reader.listBuildsChangedSince !== undefined &&
142
+ reader.getBuild !== undefined
143
+ ? (reader as BoundedReader)
144
+ : undefined
145
+ }
146
+
147
+ /** Whether any visible build is still in flight: a `done` build with an open
148
+ * escalation waits on an operator, never on the pipeline, so it does not hold
149
+ * the fast refresh cadence. */
150
+ export function hasActiveBuilds(snapshot: Pick<DashboardPollSnapshot, 'states'>): boolean {
151
+ for (const state of snapshot.states.values()) if (state.status !== 'done') return true
152
+ return false
153
+ }
154
+
107
155
  /** A build the dashboard no longer shows. `build.aborted` acknowledges
108
156
  * cancellation but begins the checkpointed cleanup saga, so an aborted build
109
- * stays visible until its final `build.completed` fact. */
157
+ * stays visible until its final `build.completed` fact. A `done` build with an
158
+ * open escalation stays visible until an operator acknowledges it. */
110
159
  export function isDashboardTerminal(state: BuildState): boolean {
111
- return state.status === 'done'
160
+ return state.status === 'done' && !openOnDone(state)
112
161
  }
113
162
 
114
- /** One build's capacity facts from its saved `buildReadFacts` value. */
115
- export function capacityBuildFromFacts(
116
- record: BuildRecord,
117
- value: CurrentBuildFacts,
118
- ): Required<CapacityBuild> {
119
- return {
120
- record,
121
- state: value.state,
122
- workspace: value.workspace !== null,
123
- provisioning: value.provisionMarker !== undefined,
124
- restackDue: landingRestackDue(value.state, value.log),
125
- }
163
+ export { capacityBuildFromFacts }
164
+
165
+ function provisioningSeqOf(seq: number | undefined): Pick<CapacityBuild, 'provisioningSeq'> {
166
+ return seq === undefined ? {} : { provisioningSeq: seq }
126
167
  }
127
168
 
128
169
  /** The display-only reads that decorate one row: authoritative stream
@@ -243,20 +284,14 @@ export function repositoryDashboardHeader(input: {
243
284
  (state) => state.kind !== 'node' && state.status !== 'done' && state.status !== 'aborted',
244
285
  ).length,
245
286
  capacity: config.capacity,
246
- capacityProjection: dispatchCapacity(
247
- input.capacityBuilds,
248
- config.capacity,
249
- input.now,
250
- migrationIdentity(repositoryFacts.ticketMigrations, config.tickets.source),
251
- {
252
- urgentClaims: urgentClaimDemand(repositoryFacts),
253
- openPrs: {
254
- policy: config.policy,
255
- engaged: repositoryFacts.openPrBackpressure !== undefined,
256
- },
257
- startRequests: startClaimDemand(repositoryFacts),
287
+ capacityProjection: dispatchCapacity(input.capacityBuilds, config.capacity, input.now, {
288
+ claims: claimDemand(repositoryFacts),
289
+ openPrs: {
290
+ policy: config.policy,
291
+ engaged: repositoryFacts.openPrBackpressure !== undefined,
258
292
  },
259
- ),
293
+ startRequests: startClaimDemand(repositoryFacts),
294
+ }),
260
295
  ...(input.triage !== undefined ? { triage: input.triage } : {}),
261
296
  ...(status.availableUpgrade !== undefined ? { availableUpgrade: status.availableUpgrade } : {}),
262
297
  ...(warningLines.length > 0 ? { warningLines } : {}),
@@ -286,7 +321,24 @@ function validateDelta(slug: string, sinceSeq: number, events: AbEvent[]): void
286
321
  /**
287
322
  * Process-local, display-only acceleration for the interactive dispatch frame.
288
323
  *
289
- * Every refresh still discovers records with `listBuildsForRepo(repo)`. A first-seen
324
+ * The bounded path (every `BuildStore` reader, so both production frontends)
325
+ * costs the same at 100 and 100,000 builds (SPEC §14):
326
+ *
327
+ * - Cold start (first refresh, or the feed reports a reset): the change
328
+ * position, sampled first as the feed watermark; `listOpenBuilds` (every
329
+ * nonterminal build, aborted cleanup included); the `doneEscalations`
330
+ * rollup; then `getBuild` (escalated done builds only) and the saved
331
+ * `buildReadFacts` value plus row enrichment per candidate.
332
+ * - Refresh: one `listBuildsChangedSince` from the watermark, then `getBuild`,
333
+ * the saved facts and row enrichment per changed build. Nothing changed:
334
+ * the feed read only, zero build reads and zero event rows.
335
+ * - A full enrichment refresh or a config change re-reads row enrichment of
336
+ * the visible builds only and re-projects them from their cached facts.
337
+ *
338
+ * It never lists builds or reads events, and keeps only visible builds.
339
+ *
340
+ * The listing path serves narrow readers (unit tests): every refresh
341
+ * discovers records with `listBuildsForRepo(repo)`. A first-seen
290
342
  * stream uses persisted build facts when available, with no event reads; local
291
343
  * readers without reduced values hydrate from seq 0, then read only after their
292
344
  * reduced `lastSeq`. Empty deltas preserve the exact reduction and
@@ -301,6 +353,12 @@ function validateDelta(slug: string, sinceSeq: number, events: AbEvent[]): void
301
353
  */
302
354
  export class DashboardBuildPollCache {
303
355
  private entries = new Map<string, PollEntry>()
356
+ /** Bounded path: the changed-builds watermark and the visible builds. */
357
+ private feed: string | undefined
358
+ private visible = new Map<string, BoundedEntry>()
359
+ /** Settled child records the visible node rows still resolve titles from;
360
+ * each is read once while a row needs it. */
361
+ private settled = new Map<string, BuildRecord | null>()
304
362
  private committedRevision = 0
305
363
  private refreshTail: Promise<void> = Promise.resolve()
306
364
 
@@ -349,6 +407,9 @@ export class DashboardBuildPollCache {
349
407
  fullEnrichment: boolean,
350
408
  ): Promise<DashboardPollSnapshot> {
351
409
  const configChanged = configRevision !== this.configRevision || config !== this.config
410
+ const bounded = boundedReader(this.reader)
411
+ if (bounded !== undefined)
412
+ return this.refreshBounded(bounded, config, configRevision, configChanged || fullEnrichment)
352
413
  const records = await this.reader.listBuildsForRepo(this.repo)
353
414
  const next = new Map<string, PollEntry>()
354
415
 
@@ -375,6 +436,9 @@ export class DashboardBuildPollCache {
375
436
  state: value.state,
376
437
  workspace: capacity.workspace,
377
438
  provisioning: capacity.provisioning,
439
+ ...(capacity.provisioningSeq !== undefined
440
+ ? { provisioningSeq: capacity.provisioningSeq }
441
+ : {}),
378
442
  restackDue: capacity.restackDue,
379
443
  build:
380
444
  current?.kind === 'reduced' &&
@@ -448,25 +512,158 @@ export class DashboardBuildPollCache {
448
512
  return this.snapshot()
449
513
  }
450
514
 
515
+ private async refreshBounded(
516
+ reader: BoundedReader,
517
+ config: Config,
518
+ configRevision: number,
519
+ reenrich: boolean,
520
+ ): Promise<DashboardPollSnapshot> {
521
+ let feed = this.feed
522
+ let next: Map<string, BoundedEntry> | undefined
523
+ if (feed !== undefined) {
524
+ const changed = await reader.listBuildsChangedSince(this.repo, feed)
525
+ // A head below the watermark means the repository was reset.
526
+ if (BigInt(changed.position) >= BigInt(feed)) {
527
+ const visible = new Map(this.visible)
528
+ const changedSlugs = [...new Set(changed.builds.map((build) => build.slug))]
529
+ const reads = await mapBounded(changedSlugs, async (slug) => {
530
+ const record = await reader.getBuild(slug)
531
+ return record === null ? undefined : this.readBounded(reader, record, config)
532
+ })
533
+ changedSlugs.forEach((slug, at) => {
534
+ const entry = reads[at]
535
+ if (entry === undefined) visible.delete(slug)
536
+ else visible.set(slug, entry)
537
+ })
538
+ if (reenrich) {
539
+ const unchanged = [...visible.values()].filter(
540
+ (entry) => !changedSlugs.includes(entry.record.slug),
541
+ )
542
+ const projected = await mapBounded(unchanged, (entry) =>
543
+ this.projectBounded(reader, entry.record, entry.facts, config),
544
+ )
545
+ for (const entry of projected) visible.set(entry.record.slug, entry)
546
+ }
547
+ next = visible
548
+ feed = changed.position
549
+ }
550
+ }
551
+ if (next === undefined) {
552
+ // Cold start. The watermark is sampled before the listings, so a change
553
+ // after it is replayed by the next feed read (a repeat read is harmless).
554
+ feed = await reader.getRepoChangePosition(this.repo)
555
+ const [open, escalated] = await Promise.all([
556
+ reader.listOpenBuilds(this.repo),
557
+ readDoneEscalations(reader, this.repo),
558
+ ])
559
+ const records = new Map(open.map(({ record }) => [record.slug, record]))
560
+ const done = escalated.builds.filter(({ slug }) => !records.has(slug))
561
+ for (const record of await mapBounded(done, ({ slug }) => reader.getBuild(slug)))
562
+ if (record !== null) records.set(record.slug, record)
563
+ const entries = await mapBounded([...records.values()], (record) =>
564
+ this.readBounded(reader, record, config),
565
+ )
566
+ next = new Map()
567
+ for (const entry of entries) if (entry !== undefined) next.set(entry.record.slug, entry)
568
+ }
569
+ const rows = [...next.values()].flatMap((entry) => (entry.build ? [entry.build] : []))
570
+ const settled = new Map<string, BuildRecord | null>()
571
+ const wanted = unresolvedIntegrationRecords(rows, new Set(next.keys()))
572
+ const missing = wanted.filter((slug) => !this.settled.has(slug))
573
+ const read = await mapBounded(missing, (slug) => reader.getBuild(slug))
574
+ missing.forEach((slug, at) => {
575
+ settled.set(slug, read[at] ?? null)
576
+ })
577
+ for (const slug of wanted) if (!settled.has(slug)) settled.set(slug, this.settled.get(slug)!)
578
+ // Publish once, after every read succeeded.
579
+ this.feed = feed
580
+ this.visible = next
581
+ this.settled = settled
582
+ this.config = config
583
+ this.configRevision = configRevision
584
+ this.committedRevision += 1
585
+ return this.boundedSnapshot()
586
+ }
587
+
588
+ /** One build's saved facts, then its row while it is still visible. */
589
+ private async readBounded(
590
+ reader: BoundedReader,
591
+ record: BuildRecord,
592
+ config: Config,
593
+ ): Promise<BoundedEntry | undefined> {
594
+ if (record.repo !== this.repo) return undefined
595
+ const { value: facts } = await readBuildFacts(reader, record.slug)
596
+ if (isDashboardTerminal(facts.state)) return undefined
597
+ return this.projectBounded(reader, record, facts, config)
598
+ }
599
+
600
+ private async projectBounded(
601
+ reader: BoundedReader,
602
+ record: BuildRecord,
603
+ facts: CurrentBuildFacts,
604
+ config: Config,
605
+ ): Promise<BoundedEntry> {
606
+ const enrichment = await readRowEnrichment(reader, record.slug, facts.state.verify.configPin)
607
+ return {
608
+ record,
609
+ facts,
610
+ enrichment,
611
+ capacity: capacityBuildFromFacts(record, facts),
612
+ build: projectRowWithEnrichment(record, facts.state, [], config, enrichment, facts),
613
+ }
614
+ }
615
+
616
+ private boundedSnapshot(): DashboardPollSnapshot {
617
+ const builds: DashboardBuild[] = []
618
+ const states = new Map<string, BuildState>()
619
+ const capacityBuilds: CapacityBuild[] = []
620
+ for (const [slug, entry] of this.visible) {
621
+ // A done build with an open escalation holds no slot.
622
+ if (entry.facts.state.status !== 'done') capacityBuilds.push(entry.capacity)
623
+ states.set(slug, entry.facts.state)
624
+ if (entry.build !== null) builds.push(entry.build)
625
+ }
626
+ builds.sort((a, b) => a.slug.localeCompare(b.slug))
627
+ return {
628
+ revision: this.committedRevision,
629
+ builds: enrichIntegrationRows(
630
+ builds,
631
+ [
632
+ ...[...this.visible.values()].map((entry) => entry.record),
633
+ ...[...this.settled.values()].filter(
634
+ (record): record is BuildRecord => record?.repo === this.repo,
635
+ ),
636
+ ].sort((a, b) => a.createdAt.localeCompare(b.createdAt) || a.slug.localeCompare(b.slug)),
637
+ ),
638
+ states,
639
+ capacityBuilds,
640
+ }
641
+ }
642
+
451
643
  private snapshot(): DashboardPollSnapshot {
452
644
  const builds: DashboardBuild[] = []
453
645
  const states = new Map<string, BuildState>()
454
646
  const capacityBuilds: CapacityBuild[] = []
455
647
  for (const [slug, entry] of this.entries) {
456
648
  if (entry.kind === 'terminal') continue
649
+ states.set(slug, entry.state)
650
+ if (entry.build !== null) builds.push(entry.build)
651
+ // A done build with an open escalation holds no slot.
652
+ if (entry.state.status === 'done') continue
457
653
  capacityBuilds.push({
458
654
  record: entry.record,
459
655
  state: entry.state,
460
656
  workspace: entry.kind === 'reduced' ? entry.workspace : entry.workspace.open !== null,
461
657
  provisioning:
462
658
  entry.kind === 'reduced' ? entry.provisioning : entry.provisionMarker.marker !== null,
659
+ ...provisioningSeqOf(
660
+ entry.kind === 'reduced' ? entry.provisioningSeq : entry.provisionMarker.marker?.seq,
661
+ ),
463
662
  restackDue:
464
663
  entry.kind === 'reduced'
465
664
  ? entry.restackDue
466
665
  : landingRestackDue(entry.state, { restack: entry.restack }),
467
666
  })
468
- states.set(slug, entry.state)
469
- if (entry.build !== null) builds.push(entry.build)
470
667
  }
471
668
  builds.sort((a, b) => a.slug.localeCompare(b.slug))
472
669
  return {
@@ -1,21 +1,32 @@
1
- import { ticketPriority, urgentFirst } from '../../ports/tickets/priority'
2
- import type { Ticket } from '../../ports/types'
1
+ import { byPriority, ticketPriority } from '../../ports/tickets/priority'
2
+ import type { Ticket, TicketPriority } from '../../ports/types'
3
3
 
4
- /** The word every frontend shows on an urgent queued ticket. */
4
+ /** The word every frontend shows on an urgent queued ticket or build. */
5
5
  export const URGENT_MARK = 'URGENT'
6
6
 
7
+ /** The word every frontend shows for each level; normal is unmarked. */
8
+ export const PRIORITY_MARKS: Record<TicketPriority, string | undefined> = {
9
+ urgent: URGENT_MARK,
10
+ high: 'HIGH',
11
+ normal: undefined,
12
+ low: 'LOW',
13
+ }
14
+
7
15
  export interface QueuedTicket<T> {
8
16
  ticket: T
9
- urgent: boolean
17
+ level: TicketPriority
18
+ /** The level's mark (`PRIORITY_MARKS`); omitted for normal. */
19
+ mark?: string
10
20
  }
11
21
 
12
- /** Queued tickets in dispatch order — urgent first, then normal, each in the
13
- * source's order — each saying whether it is urgent. */
22
+ /** Queued tickets in dispatch order — urgent, high, normal, then low, each in
23
+ * the source's order — each with its level and mark. */
14
24
  export function queuedTickets<T extends Pick<Ticket, 'priority'>>(
15
25
  tickets: readonly T[],
16
26
  ): QueuedTicket<T>[] {
17
- return urgentFirst(tickets).map((ticket) => ({
18
- ticket,
19
- urgent: ticketPriority(ticket) === 'urgent',
20
- }))
27
+ return byPriority(tickets).map((ticket) => {
28
+ const level = ticketPriority(ticket)
29
+ const mark = PRIORITY_MARKS[level]
30
+ return { ticket, level, ...(mark !== undefined ? { mark } : {}) }
31
+ })
21
32
  }
@@ -45,6 +45,7 @@ import { displayText, layoutComposer, packAtomic, wrapDisplay } from './composer
45
45
  import { cellWidth, graphemes, padEndCells } from './cells'
46
46
  import {
47
47
  HARVEST_TITLE,
48
+ buildRowStatus,
48
49
  projectHarvestRowText,
49
50
  projectHeaderText,
50
51
  projectProgress,
@@ -52,14 +53,8 @@ import {
52
53
  reviewRoundCeilingText,
53
54
  type RowAttention,
54
55
  } from './row-text'
55
- import {
56
- PROGRESS_VERIFIED,
57
- statusText,
58
- stepLine,
59
- stepTone,
60
- viewerLabel,
61
- type DashboardTone,
62
- } from './vocabulary'
56
+ import { RESET, TONE_COLOR, paint, type ColorName } from './tone-ansi'
57
+ import { PROGRESS_VERIFIED, harvestStatusText, stepLine, stepTone, viewerLabel } from './vocabulary'
63
58
 
64
59
  export { formatDuration } from './vocabulary'
65
60
 
@@ -107,34 +102,9 @@ export type DashboardRendererResolver = () => DashboardRenderer
107
102
 
108
103
  // ── ANSI ─────────────────────────────────────────────────────────────────────
109
104
 
110
- const ESC = '\x1b['
111
- const RESET = `${ESC}0m`
112
105
  /** Closes an OSC 8 hyperlink. `RESET` does NOT: it is an SGR reset, and the
113
106
  * two families are independent — only this ends the link. */
114
107
  const LINK_OFF = '\x1b]8;;\x07'
115
- const CODES = {
116
- dim: 2,
117
- red: 31,
118
- green: 32,
119
- yellow: 33,
120
- blue: 34,
121
- cyan: 36,
122
- bold: 1,
123
- } as const
124
- type ColorName = keyof typeof CODES
125
-
126
- /** The terminal's colour for each shared tone. */
127
- const TONE_COLOR: Record<DashboardTone, ColorName> = {
128
- ok: 'green',
129
- live: 'cyan',
130
- held: 'yellow',
131
- alert: 'red',
132
- pending: 'dim',
133
- }
134
-
135
- function paint(text: string, color: ColorName, on: boolean): string {
136
- return on ? `${ESC}${CODES[color]}m${text}${RESET}` : text
137
- }
138
108
 
139
109
  /** OSC 8: the escape common terminals turn into a real hyperlink. In plain
140
110
  * mode we emit the bare URL, which those same terminals linkify on sight —
@@ -356,7 +326,12 @@ function renderBuild(
356
326
  if (text.pr !== undefined) rightTokens.push(link(text.pr.url, text.pr.text, color))
357
327
  for (const flag of text.flags)
358
328
  rightTokens.push(paint(`(${flag.term})`, TONE_COLOR[flag.tone], color))
359
- rightTokens.push(paint(text.status.word.padStart(widths.status), statusColor, color))
329
+ // The status note (`(merge decision)`) hugs the word it explains; the
330
+ // padding goes ahead of both so the word still ends at the right edge.
331
+ const statusPad = ' '.repeat(Math.max(0, widths.status - cellWidth(text.status.word)))
332
+ const statusNote =
333
+ text.status.note !== undefined ? `${paint(`(${text.status.note})`, 'dim', color)} ` : ''
334
+ rightTokens.push(`${statusPad}${statusNote}${paint(text.status.word, statusColor, color)}`)
360
335
  const rightStr = rightTokens.join(' ')
361
336
 
362
337
  // The slug is the sole flexible segment; narrow frames truncate it before
@@ -497,8 +472,8 @@ function frameWidths(builds: DashboardBuild[], harvest: DashboardHarvest | undef
497
472
  ),
498
473
  status: Math.max(
499
474
  0,
500
- ...builds.map((b) => cellWidth(statusText(b.status).word)),
501
- ...(harvest !== undefined ? [cellWidth(statusText(harvest.status).word)] : []),
475
+ ...builds.map((b) => cellWidth(buildRowStatus(b).word)),
476
+ ...(harvest !== undefined ? [cellWidth(harvestStatusText(harvest.status).word)] : []),
502
477
  ),
503
478
  }
504
479
  }
@@ -1001,11 +976,13 @@ function renderDetail(model: DashboardModel, opts: RenderOpts): string[] {
1001
976
  const { color, width, height } = opts
1002
977
  const draining = build.draining ? ` ${paint('(draining)', 'yellow', color)}` : ''
1003
978
  const paused = build.alsoPaused ? ' (also paused)' : ''
979
+ const status = buildRowStatus(build)
980
+ const statusNote = status.note !== undefined ? ` (${status.note})` : ''
1004
981
  const notice = upgradeNoticeLine(model, color, width)
1005
982
  const top = [
1006
983
  truncate(`${paint('Build', 'bold', color)} ${displayText(build.slug)}`, width),
1007
984
  truncate(
1008
- ` status ${paint(statusText(build.status).word, TONE_COLOR[statusText(build.status).tone], color)}${paused}${draining}`,
985
+ ` status ${paint(`${status.word}${statusNote}`, TONE_COLOR[status.tone], color)}${paused}${draining}`,
1009
986
  width,
1010
987
  ),
1011
988
  ...standbyLine(model, color, width),
@@ -11,7 +11,7 @@
11
11
  *
12
12
  * Layout (padding, truncation, wrapping, separators) stays with each frontend.
13
13
  */
14
- import { capacityExplanation } from '../../kernel/dispatch-capacity'
14
+ import { capacityExplanation, type SlotState } from '../../kernel/dispatch-capacity'
15
15
  import type { BuildRosterFinished } from '../../kernel/build-roster'
16
16
  import type { DispatchHealth } from '../../kernel/dispatch-status'
17
17
  import { NO_DISPATCHER_RUN_LINE, activeCounterText } from './configuration'
@@ -24,8 +24,9 @@ import { treeVocabulary } from './tree'
24
24
  import {
25
25
  dispatchedByText,
26
26
  dispatcherModeWord,
27
+ buildStatusText,
27
28
  finishedOutcomeText,
28
- statusText,
29
+ harvestStatusText,
29
30
  stepMark,
30
31
  stepTone,
31
32
  type DashboardTone,
@@ -67,6 +68,9 @@ export interface DashboardRowText {
67
68
  ticketUrl?: string
68
69
  kind: 'work' | 'integration'
69
70
  status: StatusText
71
+ /** The build's slot state, passed through from the projection; absent is
72
+ * unknown, never `none`. */
73
+ slot?: SlotState
70
74
  /** The label of the step currently running. */
71
75
  phase?: string
72
76
  /** Ordered parenthesised annotations beside the status. */
@@ -231,6 +235,17 @@ function treeLines(build: DashboardBuild): string[] | undefined {
231
235
  ]
232
236
  }
233
237
 
238
+ /** A build row's status word, tone and note (SPEC §14 "Status words"). */
239
+ export function buildRowStatus(
240
+ build: Pick<DashboardBuild, 'status' | 'slot' | 'statusBasis'>,
241
+ ): StatusText {
242
+ return buildStatusText({
243
+ status: build.status,
244
+ ...(build.slot !== undefined ? { slot: build.slot } : {}),
245
+ ...(build.statusBasis !== undefined ? { basis: build.statusBasis } : {}),
246
+ })
247
+ }
248
+
234
249
  /**
235
250
  * Everything one build row says. Integration rows (an `integrationRow` is
236
251
  * present) show their own steps, progress and alert, and hide the tree,
@@ -240,13 +255,14 @@ export function projectRowText(
240
255
  build: DashboardBuild,
241
256
  options: { repositoryPaused: boolean },
242
257
  ): DashboardRowText {
243
- const status = statusText(build.status)
258
+ const status = buildRowStatus(build)
244
259
  const row = build.integrationRow
245
260
  const steps = (row?.steps ?? build.steps).map(stepText)
246
261
  const phase = steps.find((step) => step.state === 'current')?.label
247
262
  const flags: DashboardRowText['flags'] = [
248
- // A repository hold changes no build lifecycle state: QUEUED stays literal
249
- // and only the rows the hold prevents from launching are annotated.
263
+ // A repository hold changes no build lifecycle state: a newly claimed
264
+ // build still reads STARTING, and only the rows the hold prevents from
265
+ // launching are annotated.
250
266
  ...(options.repositoryPaused && build.status === 'queued'
251
267
  ? [{ term: 'held' as const, tone: 'held' as const }]
252
268
  : []),
@@ -315,6 +331,7 @@ export function projectRowText(
315
331
  : {}),
316
332
  kind: build.kind === 'integration' ? 'integration' : 'work',
317
333
  status,
334
+ ...(build.slot !== undefined ? { slot: build.slot } : {}),
318
335
  ...(phase !== undefined ? { phase } : {}),
319
336
  flags,
320
337
  ...(build.kind !== 'integration'
@@ -338,7 +355,7 @@ export function projectRowText(
338
355
  }
339
356
 
340
357
  export function projectHarvestRowText(harvest: DashboardHarvest): HarvestRowText {
341
- const status = statusText(harvest.status)
358
+ const status = harvestStatusText(harvest.status)
342
359
  return {
343
360
  title: HARVEST_TITLE,
344
361
  status,
@@ -451,7 +468,7 @@ export function projectAttention(
451
468
  ): AttentionItem[] {
452
469
  const items: AttentionItem[] = []
453
470
  if (harvest !== undefined && (harvest.status === 'escalated' || harvest.status === 'failed')) {
454
- const status = statusText(harvest.status)
471
+ const status = harvestStatusText(harvest.status)
455
472
  items.push({
456
473
  kind: 'harvest',
457
474
  tone: status.tone,
@@ -472,7 +489,8 @@ export function projectAttention(
472
489
  text: build.setupError,
473
490
  ...identity,
474
491
  })
475
- const alert = build.alert ?? build.integrationRow?.alert
492
+ // A done node's row alert repeats its open escalations, listed above.
493
+ const alert = build.alert ?? (build.statusBasis?.done ? undefined : build.integrationRow?.alert)
476
494
  if (alert?.tone === 'red')
477
495
  items.push({
478
496
  kind: 'failure',
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The terminal's ANSI colour for each shared tone. The dashboard renderer and
3
+ * the plain `ab builds` / `ab build status` text paint a tone through the same
4
+ * table, so a status word has one colour on every terminal surface.
5
+ *
6
+ * Pure: no IO and no `process`. Whether to paint is the caller's decision.
7
+ */
8
+ import type { DashboardTone } from './vocabulary'
9
+
10
+ export const ESC = '\x1b['
11
+ export const RESET = `${ESC}0m`
12
+
13
+ export const CODES = {
14
+ dim: 2,
15
+ red: 31,
16
+ green: 32,
17
+ yellow: 33,
18
+ blue: 34,
19
+ cyan: 36,
20
+ bold: 1,
21
+ } as const
22
+ export type ColorName = keyof typeof CODES
23
+
24
+ /** The terminal's colour for each shared tone. */
25
+ export const TONE_COLOR: Record<DashboardTone, ColorName> = {
26
+ ok: 'green',
27
+ live: 'cyan',
28
+ held: 'yellow',
29
+ alert: 'red',
30
+ pending: 'dim',
31
+ }
32
+
33
+ export function paint(text: string, color: ColorName, on: boolean): string {
34
+ return on ? `${ESC}${CODES[color]}m${text}${RESET}` : text
35
+ }
36
+
37
+ export function paintTone(text: string, tone: DashboardTone, on: boolean): string {
38
+ return paint(text, TONE_COLOR[tone], on)
39
+ }