@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
@@ -28,11 +28,18 @@ import {
28
28
  import { readBuildFacts } from '../store/reduced-reads'
29
29
  import {
30
30
  buildPriority,
31
+ markedPriority,
31
32
  slotRequest,
33
+ slotState,
32
34
  slotWaitText,
35
+ type CapacityBuild,
36
+ type MarkedPriority,
33
37
  type SlotRequest,
38
+ type SlotState,
34
39
  } from '../kernel/dispatch-capacity'
35
- import { URGENT_MARK } from './dashboard/queue'
40
+ import { capacityBuildFromFacts } from '../kernel/capacity-build'
41
+ import { openBuildWorkspace, provisionMarkerReducer } from '../processes/dispatcher-selectors'
42
+ import { PRIORITY_MARKS } from './dashboard/queue'
36
43
  import {
37
44
  ticketWaitStatus,
38
45
  ticketWaitText,
@@ -70,10 +77,11 @@ import type { BuildFacts } from '../processes/repo-view'
70
77
  * presentation helper exposes that divergence without folding it into status
71
78
  * or lease health.
72
79
  *
73
- * Output carries no ANSI, ever: §16 puts themes and colors out of scope, and
74
- * "understandable without relying solely on color" plus "--json without ANSI
75
- * formatting" are both satisfied by emitting none rather than by gating on a
76
- * TTY check.
80
+ * Text output colors only the status word, with its shared tone (SPEC §14
81
+ * "Status words"), and only on an interactive terminal; it never does under
82
+ * `--json`, through a pipe or a redirect, or when a caller omits `color`. The
83
+ * word itself always carries the meaning, so the output is understandable
84
+ * without color, and machine readers never see an escape sequence.
77
85
  */
78
86
  import { join } from 'node:path'
79
87
  import type { AbEvent } from '../events/catalog'
@@ -98,7 +106,16 @@ import { sameLandingCandidate } from '../kernel/landing-state'
98
106
  import type { PipelineSourceMeta } from '../config/pipeline-source'
99
107
  import { openExecution } from '../processes/execution-settlement'
100
108
  import { currentLandingWaitReasonFrom } from '../kernel/auto-merge'
101
- import { autoMergeDisplay, effectiveStatus, type AutoMergeDisplay } from './dashboard/model'
109
+ import {
110
+ autoMergeDisplay,
111
+ effectiveStatus,
112
+ statusBasis,
113
+ type AutoMergeDisplay,
114
+ type EffectiveStatus,
115
+ } from './dashboard/model'
116
+ import { buildStatusText, type DashboardTone } from './dashboard/vocabulary'
117
+ import { paint, paintTone } from './dashboard/tone-ansi'
118
+ import type { TerminalOut } from './terminal'
102
119
  import { decideNextFromFacts } from '../kernel/engine'
103
120
  import {
104
121
  reduceBuild,
@@ -181,17 +198,26 @@ export interface BuildSummary {
181
198
  lease: LeaseInfo
182
199
  /** Durable-event progress, separate from mutable lease renewal. */
183
200
  progress: BuildProgress
184
- /** A node's or parked build's runner request, admitted ahead of normal
185
- * ticket claims (urgent work first: SPEC §12 "Slot admission order"). */
201
+ /** A node's or parked build's runner request, admitted ahead of its own
202
+ * level's ticket claims (higher levels first: SPEC §12 "Slot admission
203
+ * order"). */
186
204
  slotWait?: SlotRequest
187
- /** The build's slot-admission priority when urgent; omitted means normal. */
188
- priority?: 'urgent'
205
+ /** The build's slot state by the rules the dispatcher admits work by
206
+ * (SPEC §12 "What holds a slot"). Absent for a `done` build, and unknown
207
+ * (never `none`) when absent on any other: a value from an older server,
208
+ * or a caller without the build's capacity facts. */
209
+ slot?: SlotState
210
+ /** The build's slot-admission level; omitted means normal. */
211
+ priority?: MarkedPriority
189
212
  /** The build's ticket wait while it is requested, open, or ended and not
190
213
  * yet resumed (SPEC §11 "Ticket waits"); omitted otherwise. */
191
214
  wait?: TicketWaitStatus
192
215
  /** Set when the open ticket wait's escalation is the only one open: the
193
216
  * dashboards' `waiting` status. `status` stays the reducer's `blocked`. */
194
217
  waitOnly?: true
218
+ /** The status word every surface shows (SPEC §14 "Status words"), with its
219
+ * tone and note. Absent for a `done` build, and from an older server. */
220
+ statusWord?: { word: string; tone: DashboardTone; note?: string }
195
221
  /** Why the operator held the merge, while a hold that gave one stands. */
196
222
  holdReason?: string
197
223
  /** An operator reopened this leaf and it has not settled again (§15.7). */
@@ -424,6 +450,22 @@ function measurementSummary(state: BuildState): MeasurementSummary | undefined {
424
450
  }
425
451
  }
426
452
 
453
+ /** A nonterminal build's status word from its reduced state and slot. */
454
+ function summaryStatusWord(
455
+ state: BuildState,
456
+ slot: SlotState | undefined,
457
+ ): BuildSummary['statusWord'] {
458
+ const status = effectiveStatus(state)
459
+ const basis = statusBasis(state)
460
+ if (status === 'done' || status === 'aborted' || basis === undefined) return undefined
461
+ const text = buildStatusText({ status, basis, ...(slot !== undefined ? { slot } : {}) })
462
+ return {
463
+ word: text.word,
464
+ tone: text.tone,
465
+ ...(text.note !== undefined ? { note: text.note } : {}),
466
+ }
467
+ }
468
+
427
469
  /**
428
470
  * The summary over an ALREADY-reduced state — so `detail` reduces the log
429
471
  * once and builds both projections from it, rather than reducing twice.
@@ -432,8 +474,10 @@ export function summarizeFrom(
432
474
  record: BuildRecord,
433
475
  state: BuildState,
434
476
  now: Date,
435
- slotWait?: SlotRequest,
477
+ capacity?: CapacityBuild,
436
478
  ): BuildSummary {
479
+ const slotWait = capacity ? slotRequest(capacity, now) : undefined
480
+ const slot = capacity ? slotState(capacity, now) : undefined
437
481
  // `phase`, `round`, and `attempt` describe ONE phase occurrence, so they come
438
482
  // from ONE source: the in-flight phase, else the last completed one — the
439
483
  // same `currentPhase ?? lastCompletedPhase` the reducer uses to derive
@@ -457,6 +501,7 @@ export function summarizeFrom(
457
501
  const heldBecause = holdReason(state.landing)
458
502
  const reopened = reopenedSummary(state)
459
503
  const ciFailure = currentCiFailure(state)
504
+ const word = summaryStatusWord(state, slot)
460
505
  return {
461
506
  slug: record.slug,
462
507
  ...buildVocabulary(state),
@@ -508,9 +553,13 @@ export function summarizeFrom(
508
553
  lease: leaseInfo(record, now),
509
554
  progress: buildProgress(record, state),
510
555
  ...(slotWait ? { slotWait } : {}),
511
- ...(buildPriority(state) === 'urgent' ? { priority: 'urgent' as const } : {}),
556
+ ...(slot ? { slot } : {}),
557
+ ...(markedPriority(buildPriority(state)) !== undefined
558
+ ? { priority: markedPriority(buildPriority(state))! }
559
+ : {}),
512
560
  ...(wait !== undefined ? { wait } : {}),
513
561
  ...(effectiveStatus(state) === 'waiting' ? { waitOnly: true as const } : {}),
562
+ ...(word !== undefined ? { statusWord: word } : {}),
514
563
  ...(heldBecause !== undefined ? { holdReason: heldBecause } : {}),
515
564
  ...(reopened !== undefined ? { reopened } : {}),
516
565
  ...(ciFailure !== undefined
@@ -533,7 +582,20 @@ export function summarizeFrom(
533
582
  * happening now rather than the last thing that finished.
534
583
  */
535
584
  export function summarize(record: BuildRecord, events: AbEvent[], now: Date): BuildSummary {
536
- return summarizeFrom(record, reduceBuild(events), now)
585
+ const state = reduceBuild(events)
586
+ return summarizeFrom(record, state, now, capacityFromEvents(record, state, events))
587
+ }
588
+
589
+ /** A build's capacity facts from its whole log, as `buildDashboard` derives
590
+ * them: pure, for the event-array convenience callers. */
591
+ function capacityFromEvents(record: BuildRecord, state: BuildState, events: AbEvent[]) {
592
+ return {
593
+ record,
594
+ state,
595
+ workspace: openBuildWorkspace(events) !== null,
596
+ provisioning: provisionMarkerReducer.reduce(events) !== undefined,
597
+ restackDue: landingRestackDue(state, indexLog(events)),
598
+ } satisfies CapacityBuild
537
599
  }
538
600
 
539
601
  /** Summary plus the detail fields; `eventCount` appends the newest n events. */
@@ -551,10 +613,11 @@ export function detail(
551
613
  decision?: BuildDecisionProjection,
552
614
  streams?: readonly StreamRecord[],
553
615
  ): BuildDetail {
616
+ const state = reduceBuild(events)
554
617
  return detailFromFacts(
555
618
  record,
556
619
  {
557
- state: reduceBuild(events),
620
+ state,
558
621
  runnerAttaches: buildReadFactsReducer.reduce(events).runnerAttaches,
559
622
  log: indexLog(events),
560
623
  observations: events
@@ -570,6 +633,7 @@ export function detail(
570
633
  eventCount === undefined ? undefined : events.slice(-eventCount),
571
634
  decision,
572
635
  streams,
636
+ capacityFromEvents(record, state, events),
573
637
  )
574
638
  }
575
639
 
@@ -645,6 +709,7 @@ export function detailFromFacts(
645
709
  events?: AbEvent[],
646
710
  decision?: BuildDecisionProjection,
647
711
  streams?: readonly StreamRecord[],
712
+ capacity?: CapacityBuild,
648
713
  ): BuildDetail {
649
714
  const state = facts.state
650
715
  const streamStatus = new Map<string, { stream?: string; status: 'open' | 'closed' }>()
@@ -657,7 +722,7 @@ export function detailFromFacts(
657
722
  })
658
723
  }
659
724
  }
660
- const summary = summarizeFrom(record, state, now)
725
+ const summary = summarizeFrom(record, state, now, capacity)
661
726
  // §15.6-A: only the CURRENT cycle's results describe the current code.
662
727
  // Without this filter an earlier cycle's passes read as current — wrong, and
663
728
  // wrong in the reassuring direction.
@@ -866,16 +931,26 @@ function viaMarker(actor: Actor): string {
866
931
  return `human (via ${actor.via.kind === 'session' ? `session ${actor.via.id}` : `mcp ${actor.via.client}`})`
867
932
  }
868
933
 
869
- function padColumns(rows: string[][]): string[] {
934
+ /** A table cell: plain text, or text painted with escapes whose visible
935
+ * width is `plain`'s. Padding always goes outside the escapes. */
936
+ type Cell = string | { plain: string; painted: string }
937
+
938
+ function padColumns(rows: Cell[][]): string[] {
939
+ const plain = (cell: Cell) => (typeof cell === 'string' ? cell : cell.plain)
940
+ const painted = (cell: Cell) => (typeof cell === 'string' ? cell : cell.painted)
870
941
  const widths: number[] = []
871
942
  for (const row of rows) {
872
943
  row.forEach((cell, i) => {
873
- widths[i] = Math.max(widths[i] ?? 0, cell.length)
944
+ widths[i] = Math.max(widths[i] ?? 0, plain(cell).length)
874
945
  })
875
946
  }
876
947
  return rows.map((row) =>
877
948
  row
878
- .map((cell, i) => (i === row.length - 1 ? cell : cell.padEnd(widths[i] ?? 0)))
949
+ .map((cell, i) =>
950
+ i === row.length - 1
951
+ ? painted(cell)
952
+ : `${painted(cell)}${' '.repeat(Math.max(0, (widths[i] ?? 0) - plain(cell).length))}`,
953
+ )
879
954
  .join(' ')
880
955
  .trimEnd(),
881
956
  )
@@ -886,12 +961,17 @@ function padColumns(rows: string[][]): string[] {
886
961
  * is nothing to show, so an empty result is an honest answer rather than a
887
962
  * blank that reads like a bug.
888
963
  */
889
- export function renderSummaries(summaries: BuildSummary[], now: Date, emptyNote: string): string[] {
964
+ export function renderSummaries(
965
+ summaries: BuildSummary[],
966
+ now: Date,
967
+ emptyNote: string,
968
+ opts: { color?: boolean } = {},
969
+ ): string[] {
890
970
  if (summaries.length === 0) return [emptyNote]
891
971
  // The two free-text columns (ticket title, PR link) go last, where their
892
972
  // width costs no alignment on the scannable columns to their left.
893
- const rows: string[][] = [
894
- ['BUILD', 'STATUS', 'PHASE', 'LEASE', 'HEARTBEAT', 'PROGRESS', 'TICKET', 'PR'],
973
+ const rows: Cell[][] = [
974
+ ['BUILD', 'STATUS', 'SLOT', 'PHASE', 'LEASE', 'HEARTBEAT', 'PROGRESS', 'TICKET', 'PR'],
895
975
  ]
896
976
  for (const summary of summaries) {
897
977
  const progressAge =
@@ -905,7 +985,12 @@ export function renderSummaries(summaries: BuildSummary[], now: Date, emptyNote:
905
985
  : ''
906
986
  rows.push([
907
987
  summary.slug,
908
- `${summaryStatus(summary)}${summary.priority === 'urgent' ? ` ${URGENT_MARK}` : ''}`,
988
+ statusCell(
989
+ summary,
990
+ summary.priority !== undefined ? ` ${PRIORITY_MARKS[summary.priority]}` : '',
991
+ opts.color,
992
+ ),
993
+ slotText(summary) ?? '—',
909
994
  summary.kind === 'integration'
910
995
  ? `${summary.optimization ? treeVocabulary.optimizationKind : treeVocabulary.integrationKind} ${summary.integration ?? ''}${slotWait}`
911
996
  : `${phaseCell(summary)}${slotWait}${ticketWait}`,
@@ -941,14 +1026,67 @@ export function renderSummaries(summaries: BuildSummary[], now: Date, emptyNote:
941
1026
  })
942
1027
  }
943
1028
 
944
- /** The status word text renderers print: `waiting` for a build whose only
945
- * open escalation is its ticket wait, else the reducer status. */
946
- function summaryStatus(summary: BuildSummary): string {
947
- return summary.waitOnly ? 'waiting' : summary.status
1029
+ /** A summary's slot state in neutral raw terms, or undefined for a `done`
1030
+ * build. An absent value on any other build is `unknown`, never `none`. */
1031
+ function slotText(
1032
+ summary: BuildSummary,
1033
+ marked = (text: string, level: MarkedPriority) => `${text} ${level}`,
1034
+ ) {
1035
+ if (summary.status === 'done') return undefined
1036
+ const slot = summary.slot
1037
+ if (slot === undefined) return 'unknown'
1038
+ if (slot.state !== 'requested') return slot.state
1039
+ const text = `requested ${slot.request}`
1040
+ return slot.priority !== undefined ? marked(text, slot.priority) : text
1041
+ }
1042
+
1043
+ /** The status word text renderers print with its note (SPEC §14 "Status
1044
+ * words"), or a `done` build's reducer status. A summary from an older server
1045
+ * carries no `statusWord`; its word is chosen from the fields it does carry. */
1046
+ function summaryStatusText(summary: BuildSummary): BuildSummary['statusWord'] | undefined {
1047
+ if (summary.statusWord !== undefined) return summary.statusWord
1048
+ const status: EffectiveStatus | undefined = summary.waitOnly
1049
+ ? 'waiting'
1050
+ : summary.status === 'aborted'
1051
+ ? 'cleaning'
1052
+ : summary.status === 'done'
1053
+ ? undefined
1054
+ : summary.status
1055
+ if (status === undefined) return undefined
1056
+ const text = buildStatusText({
1057
+ status,
1058
+ ...(summary.slot !== undefined ? { slot: summary.slot } : {}),
1059
+ })
1060
+ return {
1061
+ word: text.word,
1062
+ tone: text.tone,
1063
+ ...(text.note !== undefined ? { note: text.note } : {}),
1064
+ }
1065
+ }
1066
+
1067
+ /** The STATUS text: the word painted in its tone on a color terminal, its
1068
+ * note dim, and `suffix` plain. */
1069
+ function statusCell(summary: BuildSummary, suffix: string, color = false): Cell {
1070
+ const word = summaryStatusText(summary)
1071
+ if (word === undefined) return `${summary.status}${suffix}`
1072
+ const note = word.note !== undefined ? ` (${word.note})` : ''
1073
+ return {
1074
+ plain: `${word.word}${note}${suffix}`,
1075
+ painted: `${paintTone(word.word, word.tone, color)}${paint(note, 'dim', color && note !== '')}${suffix}`,
1076
+ }
1077
+ }
1078
+
1079
+ /** Whether `ab builds` and `ab build status` color the status word: only on
1080
+ * an interactive terminal, and never under `--json`. */
1081
+ export function statusColor(
1082
+ terminal: Pick<TerminalOut, 'interactive'> | undefined,
1083
+ json: boolean,
1084
+ ): boolean {
1085
+ return terminal?.interactive === true && !json
948
1086
  }
949
1087
 
950
1088
  /** Labeled sections, each omitted when absent ("when each is available"). */
951
- export function renderDetail(d: BuildDetail, now: Date): string[] {
1089
+ export function renderDetail(d: BuildDetail, now: Date, opts: { color?: boolean } = {}): string[] {
952
1090
  const lines: string[] = [`build ${d.slug}`]
953
1091
  if (d.nodePolling)
954
1092
  lines.push(
@@ -1035,13 +1173,16 @@ export function renderDetail(d: BuildDetail, now: Date): string[] {
1035
1173
  lines.push(` unsafe merge ${proof.sha}: ${proof.missing.join(', ') || proof.build}`)
1036
1174
  }
1037
1175
  }
1038
- lines.push(` status: ${summaryStatus(d)}${d.outcome !== undefined ? ` (${d.outcome})` : ''}`)
1176
+ const status = statusCell(d, d.outcome !== undefined ? ` (${d.outcome})` : '', opts.color)
1177
+ lines.push(` status: ${typeof status === 'string' ? status : status.painted}`)
1178
+ const slot = slotText(d, (text, level) => `${text} (${level})`)
1179
+ if (slot !== undefined) lines.push(` slot: ${slot}`)
1039
1180
  lines.push(` phase: ${phaseCell(d)}`)
1040
1181
  if (d.reopened !== undefined)
1041
1182
  lines.push(
1042
1183
  ` reopened: ${safeStatusText(reopenedText(d.reopened).replace(/^reopened /, ''))} (${d.reopened.at})`,
1043
1184
  )
1044
- if (d.priority === 'urgent') lines.push(' priority: urgent')
1185
+ if (d.priority !== undefined) lines.push(` priority: ${d.priority}`)
1045
1186
  if (d.reviewRoundCeilings !== undefined) {
1046
1187
  const ceilings = [
1047
1188
  ...(d.reviewRoundCeilings.plan !== undefined ? [`plan ${d.reviewRoundCeilings.plan}`] : []),
@@ -1317,6 +1458,8 @@ export function statusFilter(all?: boolean, queued?: boolean): BuildStatus[] {
1317
1458
  export interface AbBuildsOpts extends StatusOpts {
1318
1459
  queued?: boolean
1319
1460
  all?: boolean
1461
+ /** Color the status word with its tone (`statusColor`); default plain. */
1462
+ color?: boolean
1320
1463
  }
1321
1464
 
1322
1465
  /** `ab builds` — this repo's builds, active by default. Read-only. */
@@ -1372,21 +1515,7 @@ export async function abBuilds(opts: AbBuildsOpts): Promise<void> {
1372
1515
  // exactly — so it keeps its per-build history read (correct, just not
1373
1516
  // accelerated).
1374
1517
  const facts = (await readBuildFacts(store, record.slug)).value
1375
- const summary = summarizeFrom(
1376
- record,
1377
- facts.state,
1378
- now,
1379
- slotRequest(
1380
- {
1381
- record,
1382
- state: facts.state,
1383
- workspace: facts.workspace !== null,
1384
- provisioning: facts.provisionMarker !== undefined,
1385
- restackDue: landingRestackDue(facts.state, facts.log),
1386
- },
1387
- now,
1388
- ),
1389
- )
1518
+ const summary = summarizeFrom(record, facts.state, now, capacityBuildFromFacts(record, facts))
1390
1519
  if (wanted.has(summary.status)) summaries.push(summary)
1391
1520
  }
1392
1521
  summaries.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt))
@@ -1406,7 +1535,9 @@ export async function abBuilds(opts: AbBuildsOpts): Promise<void> {
1406
1535
  : 'active builds'
1407
1536
  const hint =
1408
1537
  opts.all === true ? '' : opts.queued === true ? ' — try --all' : ' — try --queued or --all'
1409
- for (const line of renderSummaries(summaries, now, `no ${scope} for ${repo}${hint}`)) {
1538
+ for (const line of renderSummaries(summaries, now, `no ${scope} for ${repo}${hint}`, {
1539
+ color: opts.color === true,
1540
+ })) {
1410
1541
  opts.stdout(line)
1411
1542
  }
1412
1543
  })
@@ -1415,6 +1546,8 @@ export async function abBuilds(opts: AbBuildsOpts): Promise<void> {
1415
1546
  export interface AbBuildStatusOpts extends StatusOpts {
1416
1547
  slug: string
1417
1548
  events?: number
1549
+ /** Color the status word with its tone (`statusColor`); default plain. */
1550
+ color?: boolean
1418
1551
  }
1419
1552
 
1420
1553
  function _openWorkspacePath(events: AbEvent[]): string | undefined {
@@ -1612,7 +1745,15 @@ export async function abBuildStatus(opts: AbBuildStatusOpts): Promise<void> {
1612
1745
  } catch {
1613
1746
  streams = undefined
1614
1747
  }
1615
- const projected = detailFromFacts(record, facts, now, events, decision, streams)
1748
+ const projected = detailFromFacts(
1749
+ record,
1750
+ facts,
1751
+ now,
1752
+ events,
1753
+ decision,
1754
+ streams,
1755
+ capacityBuildFromFacts(record, facts),
1756
+ )
1616
1757
  // Operator visibility (SPEC §16.1): which autobuild.toml the build's
1617
1758
  // pinned pipeline came from, alongside the effective-config revision.
1618
1759
  const configArtifact = await context.store.getArtifact(
@@ -1665,7 +1806,7 @@ export async function abBuildStatus(opts: AbBuildStatusOpts): Promise<void> {
1665
1806
  opts.stdout(JSON.stringify(d, null, 2))
1666
1807
  return
1667
1808
  }
1668
- for (const line of renderDetail(d, now)) opts.stdout(line)
1809
+ for (const line of renderDetail(d, now, { color: opts.color === true })) opts.stdout(line)
1669
1810
  })
1670
1811
  }
1671
1812
 
@@ -1,4 +1,3 @@
1
- import { AccountRedactor, redactAccountStore } from '../store/account-redaction'
2
1
  import { untilDeadline } from './watch-lifetime'
3
2
  /**
4
3
  * Production BuildStore composition for CLI commands.
@@ -8,48 +7,46 @@ import { untilDeadline } from './watch-lifetime'
8
7
  * joins those seams to the production remote adapter and owns finite-command
9
8
  * store lifecycle.
10
9
  */
11
- import { projectToken } from './project-credentials'
12
- import { isRemoteStoreRef } from './repo-state'
10
+ import {
11
+ composeProductionStore,
12
+ openStoreForRepoStateWith,
13
+ type OpenedStoreContext,
14
+ type OpenStoreForRepoStateOpts,
15
+ type StoreOpener,
16
+ } from './production-store'
13
17
  import type { Exec } from '../ports/workspace/git-worktree'
14
18
  import { RemoteBuildStore } from '../store/remote/client'
15
19
  import { scopeLocalStoreToPhaseSession } from '../store/phase-session'
16
20
  import type { BuildStore } from '../store/types'
17
21
  import {
18
- InvalidAmbientContextError,
19
22
  resolveAmbientReadSession,
20
23
  type AmbientReadSession,
21
24
  type CliEnv,
22
25
  type HarvestCliEnv,
23
26
  } from './env'
24
27
  import { resolveRepoState, type RepoStatePaths } from './repo-state'
25
- import { resolveStore } from './store-ref'
26
-
27
- /** Shared injection seam used by every command that opens a BuildStore. */
28
- export type StoreOpener = (ref: string, token?: string) => BuildStore
29
28
 
30
- function optionalToken(value: string | undefined): string | undefined {
31
- // Bearer credentials are opaque. Only absence and the exact empty value mean
32
- // "no token"; nonempty values are forwarded byte-for-byte.
33
- return value !== undefined && value !== '' ? value : undefined
34
- }
29
+ export type { StoreOpener } from './production-store'
35
30
 
36
31
  /** Production local/remote composition. The low-level parser stays injectable
37
32
  * and does not import the HTTP adapter. */
38
- export const openProductionStore: StoreOpener = (ref, token) => {
39
- const forwardedToken = optionalToken(token)
40
- const store = resolveStore(ref, {
41
- remoteFactory: (url, remoteToken) => new RemoteBuildStore({ url, token: remoteToken }),
42
- ...(forwardedToken !== undefined ? { token: forwardedToken } : {}),
43
- })
44
- const raw = process.env.AB_ACCOUNT_CREDENTIAL_ENVS
45
- if (!raw) return store
46
- const names: unknown = JSON.parse(raw)
47
- if (!Array.isArray(names) || !names.every((name) => typeof name === 'string'))
48
- throw new Error('Invalid account credential variable inventory')
49
- return redactAccountStore(
50
- store,
51
- new AccountRedactor(() => names.map((name) => process.env[name])),
33
+ export const openProductionStore: StoreOpener = (ref, token) =>
34
+ composeProductionStore(
35
+ ref,
36
+ token,
37
+ (url, remoteToken) => new RemoteBuildStore({ url, token: remoteToken }),
52
38
  )
39
+
40
+ /** Production composition for a bounded invocation: every remote Store
41
+ * request goes through `fetchFn` (normally `budgetedFetch()`), so it is
42
+ * cancelled at the current invocation phase's deadline. */
43
+ export function budgetedProductionStore(fetchFn: typeof fetch): StoreOpener {
44
+ return (ref, token) =>
45
+ composeProductionStore(
46
+ ref,
47
+ token,
48
+ (url, remoteToken) => new RemoteBuildStore({ url, token: remoteToken, fetchFn }),
49
+ )
53
50
  }
54
51
 
55
52
  /** Apply validated ambient authority to a selected Store handle. Remote
@@ -74,20 +71,7 @@ export function openProductionSessionStore(env: CliEnv | HarvestCliEnv): BuildSt
74
71
  return scopeSelectedStoreToPhaseSession(openProductionStore(env.store, env.token), env.store, env)
75
72
  }
76
73
 
77
- export interface OpenedStoreContext extends RepoStatePaths {
78
- store: BuildStore
79
- token?: string
80
- /** The validated ambient phase/Harvest identity this invocation carries, if
81
- * any — the same value that scoped `store`. Exposed for commands whose
82
- * repository selection also depends on ambient own-build authority. */
83
- ambient?: AmbientReadSession
84
- }
85
-
86
- export interface OpenStoreForRepoStateOpts {
87
- env: Record<string, string | undefined>
88
- openStore?: StoreOpener
89
- useProjectCredential?: boolean
90
- }
74
+ export type { OpenedStoreContext, OpenStoreForRepoStateOpts } from './production-store'
91
75
 
92
76
  /** Open from an already canonicalized state selection. Dispatch uses this form
93
77
  * so repository topology and relative overrides are decided exactly once. */
@@ -95,22 +79,7 @@ export function openStoreForRepoState(
95
79
  state: RepoStatePaths,
96
80
  opts: OpenStoreForRepoStateOpts,
97
81
  ): OpenedStoreContext {
98
- // A judge session's only store authority is its one preference.
99
- if (opts.env.AB_JUDGE !== undefined)
100
- throw new InvalidAmbientContextError('a judge session has no read authority')
101
- const token =
102
- opts.useProjectCredential !== false && isRemoteStoreRef(state.storeRef)
103
- ? projectToken(state.storeRef, state.repo, opts.env)
104
- : optionalToken(opts.env.AB_TOKEN)
105
- if (!token && isRemoteStoreRef(state.storeRef) && state.configStore === state.storeRef) {
106
- throw new Error('No project credential for this service; run ab connect')
107
- }
108
- const store = (opts.openStore ?? openProductionStore)(state.storeRef, token)
109
- return {
110
- ...state,
111
- store,
112
- ...(token !== undefined ? { token } : {}),
113
- }
82
+ return openStoreForRepoStateWith(state, opts, opts.openStore ?? openProductionStore)
114
83
  }
115
84
 
116
85
  export interface SessionlessStoreOpts extends OpenStoreForRepoStateOpts {
@@ -8,7 +8,12 @@
8
8
  */
9
9
  import { openLocalStore } from '../store/local/store'
10
10
  import type { BuildStore } from '../store/types'
11
- import { isRemoteStoreRef } from './repo-state'
11
+
12
+ /** An http(s) reference names the remote HTTP adapter; anything else is a
13
+ * local filesystem path. */
14
+ export function isRemoteStoreRef(ref: string): boolean {
15
+ return /^https?:\/\//i.test(ref)
16
+ }
12
17
 
13
18
  export interface ResolveStoreOpts {
14
19
  /** Constructs the remote HTTP store (§7.2.2); production wiring is external. */
@@ -1,17 +1,17 @@
1
- import type { TicketStartPriority } from '../events/repository'
1
+ import type { StartTier } from '../ports/tickets/priority'
2
2
  import { cancelTicketStart, requestTicketStart } from '../operator/ticket-start'
3
3
  import type { TicketSource } from '../ports/types'
4
4
  import { buildControlUser } from './build-control'
5
5
  import { withSessionlessStore, type SessionlessStoreOpts } from './store-opening'
6
6
 
7
- /** `ab start <ticket-id> [--priority manual|urgent|normal] [--cancel]`: record
7
+ /** `ab start <ticket-id> [--priority manual|urgent|high|normal|low] [--cancel]`: record
8
8
  * or cancel a durable request that the running dispatcher start one ticket,
9
9
  * even while intake is off. */
10
10
  export async function abTicketStart(
11
11
  opts: SessionlessStoreOpts & {
12
12
  id: string
13
13
  cancel?: boolean
14
- priority?: TicketStartPriority
14
+ priority?: StartTier
15
15
  json?: boolean
16
16
  stdout: (line: string) => void
17
17
  ticketSource: () => Promise<TicketSource>