@defrex/autobuild 1.0.0-beta.2 → 1.0.0-beta.4

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 (145) hide show
  1. package/SPEC.md +342 -23
  2. package/bin/ab-dispatch-generation.ts +93 -0
  3. package/docs/answering-blocked-builds.md +21 -3
  4. package/docs/architecture.md +170 -7
  5. package/docs/configuration.md +173 -5
  6. package/docs/integration-tree.md +91 -4
  7. package/docs/integration.md +54 -0
  8. package/docs/operator-api.md +58 -5
  9. package/docs/remote-store-protocol.md +9 -1
  10. package/docs/remote-ticket-protocol.md +5 -0
  11. package/docs/restacking.md +4 -1
  12. package/docs/setup.md +24 -0
  13. package/docs/spec-standard.md +94 -5
  14. package/docs/ticket-migration.md +50 -4
  15. package/package.json +3 -3
  16. package/packages/core/src/cli/artifact.ts +5 -4
  17. package/packages/core/src/cli/attention.ts +2 -0
  18. package/packages/core/src/cli/binary-direct.ts +190 -0
  19. package/packages/core/src/cli/binary-lifecycle.ts +46 -0
  20. package/packages/core/src/cli/binary.ts +24 -210
  21. package/packages/core/src/cli/build-control.ts +108 -5
  22. package/packages/core/src/cli/context.ts +41 -1
  23. package/packages/core/src/cli/dashboard/hand-pushed.ts +24 -0
  24. package/packages/core/src/cli/dashboard/handoff.ts +64 -0
  25. package/packages/core/src/cli/dashboard/integration-detail.ts +11 -6
  26. package/packages/core/src/cli/dashboard/integration-row.ts +15 -8
  27. package/packages/core/src/cli/dashboard/model.ts +41 -10
  28. package/packages/core/src/cli/dashboard/render.ts +24 -2
  29. package/packages/core/src/cli/dashboard/rollback.ts +30 -0
  30. package/packages/core/src/cli/dispatch-args.ts +53 -0
  31. package/packages/core/src/cli/dispatch-crash-budget.ts +15 -0
  32. package/packages/core/src/cli/dispatch-frontend.ts +57 -5
  33. package/packages/core/src/cli/dispatch-handoff.ts +276 -0
  34. package/packages/core/src/cli/dispatch-launch-contract.ts +170 -0
  35. package/packages/core/src/cli/dispatch-launcher.ts +580 -0
  36. package/packages/core/src/cli/dispatch-parent-watch.ts +44 -0
  37. package/packages/core/src/cli/dispatch-preflight.ts +272 -0
  38. package/packages/core/src/cli/dispatch-presentation-job.ts +46 -0
  39. package/packages/core/src/cli/dispatch-presentation-ownership.ts +9 -0
  40. package/packages/core/src/cli/dispatch-process.ts +22 -90
  41. package/packages/core/src/cli/dispatch-readiness.ts +47 -0
  42. package/packages/core/src/cli/dispatch-repository-feed.ts +6 -1
  43. package/packages/core/src/cli/dispatch-runtime-cache.ts +522 -0
  44. package/packages/core/src/cli/dispatch-runtime-dependencies.ts +291 -0
  45. package/packages/core/src/cli/dispatch-runtime-use.ts +336 -0
  46. package/packages/core/src/cli/dispatch-upgrade-controller.ts +221 -0
  47. package/packages/core/src/cli/dispatch-upgrade-install.ts +258 -0
  48. package/packages/core/src/cli/dispatch-upgrade-source.ts +309 -0
  49. package/packages/core/src/cli/dispatch-upgrade-target.ts +190 -0
  50. package/packages/core/src/cli/dispatch.ts +609 -60
  51. package/packages/core/src/cli/dispatcher-liveness.ts +1 -1
  52. package/packages/core/src/cli/harvest.ts +28 -11
  53. package/packages/core/src/cli/help.ts +7 -3
  54. package/packages/core/src/cli/installation.ts +5 -3
  55. package/packages/core/src/cli/main-checkout.ts +59 -0
  56. package/packages/core/src/cli/main.ts +26 -53
  57. package/packages/core/src/cli/node-verification-provenance.ts +97 -0
  58. package/packages/core/src/cli/repo-state.ts +3 -58
  59. package/packages/core/src/cli/repository-status.ts +74 -4
  60. package/packages/core/src/cli/runtime-spawn.ts +16 -0
  61. package/packages/core/src/cli/status.ts +57 -3
  62. package/packages/core/src/cli/ticket.ts +35 -11
  63. package/packages/core/src/cli/upgrade-followup.ts +25 -0
  64. package/packages/core/src/cli/wait.ts +3 -0
  65. package/packages/core/src/cli/watch.ts +7 -0
  66. package/packages/core/src/config/live.ts +1 -0
  67. package/packages/core/src/config/schema.ts +8 -4
  68. package/packages/core/src/distribution-packaging.ts +116 -0
  69. package/packages/core/src/events/catalog.ts +6 -0
  70. package/packages/core/src/events/payloads.ts +55 -9
  71. package/packages/core/src/events/policy.ts +26 -0
  72. package/packages/core/src/events/repository.ts +205 -4
  73. package/packages/core/src/events/runtime.ts +16 -0
  74. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +6537 -4053
  75. package/packages/core/src/kernel/change-presence.ts +7 -1
  76. package/packages/core/src/kernel/dispatch-capacity.ts +12 -4
  77. package/packages/core/src/kernel/dispatch-drain-recovery.ts +121 -0
  78. package/packages/core/src/kernel/dispatch-status.ts +4 -2
  79. package/packages/core/src/kernel/dispatch-upgrade.ts +171 -0
  80. package/packages/core/src/kernel/dispatcher-liveness.ts +7 -0
  81. package/packages/core/src/kernel/generators/repository-journals.ts +82 -0
  82. package/packages/core/src/kernel/guarded-forge.ts +1 -1
  83. package/packages/core/src/kernel/harvest.ts +98 -4
  84. package/packages/core/src/kernel/integration-attention.ts +20 -0
  85. package/packages/core/src/kernel/integration-completeness.ts +54 -16
  86. package/packages/core/src/kernel/integration-state.ts +80 -11
  87. package/packages/core/src/kernel/landing-readiness.ts +6 -1
  88. package/packages/core/src/kernel/mixed-version.ts +34 -0
  89. package/packages/core/src/kernel/node-parent.ts +35 -10
  90. package/packages/core/src/kernel/node-polling.ts +160 -0
  91. package/packages/core/src/kernel/read-facts.ts +47 -5
  92. package/packages/core/src/kernel/reducer-registry.ts +6 -0
  93. package/packages/core/src/kernel/reducer.ts +75 -14
  94. package/packages/core/src/kernel/service-facts.ts +11 -4
  95. package/packages/core/src/kernel/ticket-migrations.ts +139 -0
  96. package/packages/core/src/operator/presentation.ts +7 -0
  97. package/packages/core/src/operator/query.ts +13 -3
  98. package/packages/core/src/operator/registry.ts +1 -1
  99. package/packages/core/src/operator/tickets.ts +30 -26
  100. package/packages/core/src/plugins/load.ts +4 -1
  101. package/packages/core/src/plugins/runtime-snapshot.ts +128 -0
  102. package/packages/core/src/ports/forge/contract.ts +29 -0
  103. package/packages/core/src/ports/forge/github.ts +189 -61
  104. package/packages/core/src/ports/forge-failure.ts +1 -0
  105. package/packages/core/src/ports/forge-telemetry.ts +3 -0
  106. package/packages/core/src/ports/runner/session-env.ts +1 -0
  107. package/packages/core/src/ports/tickets/linear.ts +180 -12
  108. package/packages/core/src/ports/tickets/migration.ts +92 -9
  109. package/packages/core/src/ports/types.ts +17 -0
  110. package/packages/core/src/ports/workspace/distribution-archive.ts +22 -149
  111. package/packages/core/src/ports/workspace/distribution-release.ts +56 -0
  112. package/packages/core/src/ports/workspace/git-worktree.ts +2 -1
  113. package/packages/core/src/ports/workspace/local-build-execution.ts +37 -17
  114. package/packages/core/src/processes/build-child-exit.ts +5 -26
  115. package/packages/core/src/processes/build-runner.ts +81 -11
  116. package/packages/core/src/processes/dispatcher.ts +418 -59
  117. package/packages/core/src/processes/execution-no-progress.ts +6 -0
  118. package/packages/core/src/processes/execution-relaunch.ts +30 -0
  119. package/packages/core/src/processes/execution-settlement.ts +16 -7
  120. package/packages/core/src/processes/harvest-runner.ts +328 -292
  121. package/packages/core/src/processes/process-group-reaper.ts +17 -10
  122. package/packages/core/src/runtime-identity.ts +22 -3
  123. package/packages/core/src/store/contract.ts +183 -0
  124. package/packages/core/src/store/local/store.ts +197 -72
  125. package/packages/core/src/store/reduced-reads.ts +8 -0
  126. package/packages/core/src/store/reducer-value-shapes.json +8915 -6344
  127. package/packages/core/src/store/remote/client.ts +43 -0
  128. package/packages/core/src/store/repo-state-events.ts +21 -3
  129. package/packages/core/src/store/types.ts +7 -0
  130. package/packages/core/src/testing/dispatch-read-budget.ts +3 -2
  131. package/skills/guide/SKILL.md +234 -24
  132. package/skills/guide/references/integration-tree.md +91 -4
  133. package/skills/guide/references/operator-api.md +53 -4
  134. package/skills/guide/references/plugin-authoring.md +45 -4
  135. package/skills/guide/references/remote-store-protocol.md +9 -1
  136. package/skills/guide/references/remote-ticket-protocol.md +5 -0
  137. package/skills/guide/references/restacking.md +4 -1
  138. package/skills/guide/references/setup.md +24 -0
  139. package/skills/guide/references/spec-standard.md +94 -5
  140. package/skills/guide/references/ticket-migration.md +50 -4
  141. package/skills/harvest/SKILL.md +4 -0
  142. package/skills/harvest-review/SKILL.md +4 -0
  143. package/skills/operate/SKILL.md +78 -8
  144. package/skills/spec/SKILL.md +35 -5
  145. package/skills/tickets/SKILL.md +19 -0
@@ -1,3 +1,7 @@
1
+ import {
2
+ collectNodeVerificationProvenance,
3
+ type NodeVerificationIndex,
4
+ } from './node-verification-provenance'
1
5
  import { compatibilityDiagnostic } from '../kernel/mixed-version'
2
6
  import { readBuildFacts, type CurrentBuildFacts } from '../store/reduced-reads'
3
7
  /**
@@ -99,6 +103,7 @@ export interface ContextManifest {
99
103
  commitRange?: CommitRange
100
104
  /** Reconcile: `{baseSha}` freshly recorded by this attempt's phase start (§15.7). */
101
105
  conflict?: { baseSha: string }
106
+ nodeVerification?: Omit<NodeVerificationIndex, 'commits'> & { indexPath: string }
102
107
  nodeChange?: {
103
108
  owner: string
104
109
  transaction: string
@@ -219,12 +224,13 @@ export async function buildContext(deps: ContextDeps): Promise<ContextManifest>
219
224
  phase === 'implement' || phase === 'reconcile' ? locate(`${phase}-notes.md`) : undefined
220
225
  const materialized: Record<string, MaterializedEntry> = {}
221
226
 
222
- async function writeDerived(desiredPath: string, content: string): Promise<void> {
227
+ async function writeDerived(desiredPath: string, content: string): Promise<string> {
223
228
  const relPath = locate(desiredPath)
224
229
  const target = join(abDir, relPath)
225
230
  await mkdir(dirname(target), { recursive: true })
226
231
  await writeFile(target, content)
227
232
  materialized[relPath] = 'derived'
233
+ return `.ab/${relPath}`
228
234
  }
229
235
 
230
236
  /** Latest rev when `rev` omitted; silently skips absent kinds — the tree is
@@ -457,6 +463,40 @@ export async function buildContext(deps: ContextDeps): Promise<ContextManifest>
457
463
  manifest.commitRange = state.implement.commits
458
464
  }
459
465
 
466
+ if (isVerifyPhase(phase) && state.kind === 'node' && state.integration?.cycle) {
467
+ if (!gitWorkspace)
468
+ throw new Error('node verification provenance requires a Git workspace and exec')
469
+ const record = await store.getBuild(build)
470
+ if (!record) throw new Error(`node verification build ${build} is missing`)
471
+ const contributionBase =
472
+ state.nodeRestack?.contributionBoundaries?.[manifest.commitRange!.head] ??
473
+ state.nodeRestack?.contributionBase ??
474
+ state.nodeOpened?.sha
475
+ if (!contributionBase)
476
+ throw new Error(
477
+ `node verification ${build} is missing its durable contribution boundary; restore node opening evidence`,
478
+ )
479
+ const { index, specs } = await collectNodeVerificationProvenance(
480
+ store,
481
+ record.repo,
482
+ manifest.commitRange!,
483
+ { exec: deps.exec!, workspacePath },
484
+ { contributionBase, foreignAliases: state.nodeRestack?.foreignAliases },
485
+ )
486
+ for (const contribution of index.contributions) {
487
+ contribution.specPath = await writeDerived(
488
+ `contributions/${contribution.build}/spec.md`,
489
+ specs.get(contribution.build)!,
490
+ )
491
+ }
492
+ const indexPath = await writeDerived(
493
+ 'node-verification.json',
494
+ `${JSON.stringify(index, null, 2)}\n`,
495
+ )
496
+ const { commits: _commits, ...metadata } = index
497
+ manifest.nodeVerification = { ...metadata, indexPath }
498
+ }
499
+
460
500
  if (phase === 'reconcile' && state.nodeRestack?.conflict) {
461
501
  const node = state.nodeRestack
462
502
  const conflict = node.conflict!
@@ -0,0 +1,24 @@
1
+ import { originalForeign } from '../../kernel/change-presence'
2
+ import type { NodeRestackState } from '../../kernel/node-restack-state'
3
+
4
+ export const handPushedLabel = 'Hand-pushed changes'
5
+ export interface HandPushedChange {
6
+ sha: string
7
+ originalSha: string
8
+ }
9
+ export function projectHandPushed(
10
+ node: NodeRestackState | undefined,
11
+ ): HandPushedChange[] | undefined {
12
+ if (!node?.inventory) return undefined
13
+ const aliases = new Map(Object.entries(node.foreignAliases ?? {}))
14
+ return node.inventory.foreign.map((sha) => ({ sha, originalSha: originalForeign(sha, aliases) }))
15
+ }
16
+ export function handPushedText(changes: HandPushedChange[] | undefined): string {
17
+ return (
18
+ changes
19
+ ?.map(({ sha, originalSha }) =>
20
+ sha === originalSha ? sha : `${sha} (original ${originalSha})`,
21
+ )
22
+ .join(', ') || (changes ? 'none' : 'unknown')
23
+ )
24
+ }
@@ -0,0 +1,64 @@
1
+ import type { RuntimeIdentity } from '../../events/runtime'
2
+ import type { DispatchUpgradeState } from '../../kernel/dispatch-upgrade'
3
+ import type { DashboardBuild } from './model'
4
+ import { displayText } from './cells'
5
+
6
+ export interface DashboardHandoff {
7
+ run: string
8
+ successor?: string
9
+ correlation: string
10
+ from: RuntimeIdentity
11
+ to: RuntimeIdentity
12
+ mode: 'drain' | 'cutover'
13
+ deadline?: string
14
+ }
15
+
16
+ /** Only accepted durable facts determine visibility; takeover and time do not retire a run. */
17
+ export function projectHandoffs(state: DispatchUpgradeState): {
18
+ handoffs: DashboardHandoff[]
19
+ draining: ReadonlySet<string>
20
+ } {
21
+ const runs = Object.values(state.runs)
22
+ .filter((run) => run.handoff && !run.completed)
23
+ .sort(
24
+ (a, b) =>
25
+ a.handoff!.seq - b.handoff!.seq ||
26
+ a.handoff!.payload.run.localeCompare(b.handoff!.payload.run),
27
+ )
28
+ const draining = new Set<string>()
29
+ const handoffs = runs.map((run): DashboardHandoff => {
30
+ const fact = run.handoff!.payload
31
+ const mode = fact.mode ?? 'cutover'
32
+ if (mode === 'drain') for (const slug of Object.keys(run.outstanding)) draining.add(slug)
33
+ return {
34
+ run: fact.run,
35
+ correlation: fact.correlation,
36
+ from: fact.from,
37
+ to: fact.to,
38
+ mode,
39
+ ...(fact.successor !== undefined ? { successor: fact.successor } : {}),
40
+ ...(run.deadline !== undefined ? { deadline: run.deadline } : {}),
41
+ }
42
+ })
43
+ return { handoffs, draining }
44
+ }
45
+
46
+ export function enrichDrainingRow(
47
+ row: DashboardBuild,
48
+ draining: ReadonlySet<string>,
49
+ ): DashboardBuild {
50
+ if (row.draining === undefined && !draining.has(row.slug)) return row
51
+ const { draining: _previous, ...fresh } = row
52
+ return { ...fresh, ...(draining.has(row.slug) ? { draining: true } : {}) }
53
+ }
54
+
55
+ export function handoffRuntime(runtime: RuntimeIdentity): string {
56
+ const version = runtime.version && runtime.version !== 'unknown' ? runtime.version : undefined
57
+ const commit =
58
+ runtime.commit && runtime.commit !== 'unknown' ? runtime.commit.slice(0, 12) : undefined
59
+ return displayText([version, commit].filter(Boolean).join(' ') || 'unknown')
60
+ }
61
+
62
+ export function formatHandoff(handoff: DashboardHandoff): string {
63
+ return `handoff ${handoffRuntime(handoff.from)} to ${handoffRuntime(handoff.to)}; mode ${handoff.mode}; drain deadline ${handoff.deadline ?? 'unknown'}`
64
+ }
@@ -1,3 +1,4 @@
1
+ import { projectHandPushed, type HandPushedChange } from './hand-pushed'
1
2
  import type { Config } from '../../config/schema'
2
3
  import type { BuildRecord } from '../../store/types'
3
4
  import type { BuildState } from '../../kernel/reducer'
@@ -16,10 +17,12 @@ export interface IntegrationChild {
16
17
  id: string
17
18
  title: string
18
19
  builds?: string[]
20
+ claims?: string[]
19
21
  state: string
20
22
  landed: boolean
21
23
  }
22
24
  export interface IntegrationDetail {
25
+ handPushedCommits?: HandPushedChange[]
23
26
  parentDistance?: string
24
27
  destination: string
25
28
  branch: string
@@ -43,13 +46,14 @@ export function projectIntegrationDetail(
43
46
  const row = projectIntegrationRow(record, state, restack, config)
44
47
  if (!row) return undefined
45
48
  const observation = state.integration?.observation
49
+ const membershipSource = observation?.membershipSource ?? record.ticket?.source
46
50
  const open = new Set(observation?.openChildren ?? [])
47
51
  const contributions = new Set(observation?.contributions ?? [])
48
52
  const children: IntegrationChild[] = (observation?.children ?? [])
49
53
  .filter(
50
54
  (c) =>
51
55
  observation!.diagnostics.length ||
52
- (c.source === record.ticket?.source && open.has(c.id)) ||
56
+ (c.source === membershipSource && open.has(c.id)) ||
53
57
  c.builds?.some((b) => contributions.has(b)),
54
58
  )
55
59
  .map((c) => ({
@@ -57,17 +61,17 @@ export function projectIntegrationDetail(
57
61
  title: c.title ?? 'title unavailable',
58
62
  landed:
59
63
  !!c.builds?.some((b) => contributions.has(b)) &&
60
- !(c.source === record.ticket?.source && open.has(c.id)),
64
+ !(c.source === membershipSource && open.has(c.id)),
61
65
  state:
62
66
  c.builds?.some((b) => contributions.has(b)) &&
63
- !(c.source === record.ticket?.source && open.has(c.id))
67
+ !(c.source === membershipSource && open.has(c.id))
64
68
  ? 'landed'
65
69
  : 'queued',
66
70
  }))
67
71
  for (const id of open)
68
- if (!children.some((c) => c.id === id && c.source === record.ticket?.source))
72
+ if (!children.some((c) => c.id === id && c.source === membershipSource))
69
73
  children.push({
70
- source: record.ticket?.source ?? '',
74
+ source: membershipSource ?? '',
71
75
  id,
72
76
  title: 'title unavailable',
73
77
  state: 'queued',
@@ -76,7 +80,7 @@ export function projectIntegrationDetail(
76
80
  for (const contribution of contributions)
77
81
  if (!children.some((c) => c.builds?.includes(contribution)))
78
82
  children.push({
79
- source: record.ticket?.source ?? '',
83
+ source: membershipSource ?? '',
80
84
  id: contribution,
81
85
  builds: [contribution],
82
86
  title: 'title unavailable',
@@ -115,6 +119,7 @@ export function projectIntegrationDetail(
115
119
  (restack.active && restack.replay?.conflicted ? restack.replay : undefined)
116
120
  const mode = nodeLandingPolicyDisplay(state, config.landing)
117
121
  return {
122
+ handPushedCommits: projectHandPushed(state.nodeRestack),
118
123
  parentDistance: row.parentDistance,
119
124
  destination: `${row.destination}${state.target ? '' : ' (the configured base branch)'}`,
120
125
  branch: record.branch ?? state.nodeOpening?.branch ?? 'unknown branch',
@@ -130,7 +130,7 @@ export function enrichIntegrationRows(
130
130
  const list = row.integrationRow
131
131
  const identity = row.collectionIdentity
132
132
  if (!list || !identity) return row
133
- const live = (id: string, source: string) =>
133
+ const live = (id: string, source: string, claims?: string[]) =>
134
134
  rows
135
135
  .filter((child) => {
136
136
  const match = child.collectionIdentity
@@ -138,9 +138,10 @@ export function enrichIntegrationRows(
138
138
  match &&
139
139
  match.repo === identity.repo &&
140
140
  match.targetBuild === row.slug &&
141
- match.targetSource === identity.source &&
142
- match.targetId === identity.id &&
143
- (match.id ? match.source === source && match.id === id : child.slug === id) &&
141
+ (claims?.includes(child.slug) ||
142
+ (match.targetSource === identity.source &&
143
+ match.targetId === identity.id &&
144
+ (match.id ? match.source === source && match.id === id : child.slug === id))) &&
144
145
  match.status !== 'queued' &&
145
146
  match.status !== 'done' &&
146
147
  match.status !== 'aborted'
@@ -152,17 +153,23 @@ export function enrichIntegrationRows(
152
153
  a.collectionIdentity?.createdAt ?? '',
153
154
  ) || b.slug.localeCompare(a.slug),
154
155
  )[0]
155
- const building = list.openChildren.filter((id) => live(id, identity.source ?? '')).length
156
156
  const detail = row.integrationDetail
157
+ const building = list.openChildren.filter((id) => {
158
+ const child = detail?.children.find((entry) => entry.id === id && !entry.landed)
159
+ return live(id, child?.source ?? identity.source ?? '', child?.claims)
160
+ }).length
157
161
  const projected = detail?.children.map((child) => {
158
- const active = child.landed ? undefined : live(child.id, child.source)
162
+ const active = child.landed ? undefined : live(child.id, child.source, child.claims)
159
163
  const historical = child.builds?.length
160
164
  ? records.find((r) => r.repo === identity.repo && child.builds?.includes(r.slug))
161
165
  : undefined
162
166
  return {
163
167
  ...child,
164
- id: historical?.ticket?.id ?? child.id,
165
- source: historical?.ticket?.source ?? child.source,
168
+ id: child.id === historical?.slug ? (historical.ticket?.id ?? child.id) : child.id,
169
+ source:
170
+ child.id === historical?.slug
171
+ ? (historical.ticket?.source ?? child.source)
172
+ : child.source,
166
173
  title:
167
174
  child.title === 'title unavailable'
168
175
  ? (active?.collectionIdentity?.title ?? historical?.ticket?.title ?? child.title)
@@ -1,3 +1,7 @@
1
+ import { migrationIdentity, ticketMigrationsReducer } from '../../kernel/ticket-migrations'
2
+ import { projectRollback, type DashboardRollback } from './rollback'
3
+ import { dispatchUpgradeReducer, type DispatchUpgradeState } from '../../kernel/dispatch-upgrade'
4
+ import { enrichDrainingRow, projectHandoffs, type DashboardHandoff } from './handoff'
1
5
  import { projectIntegrationDetail, type IntegrationDetail } from './integration-detail'
2
6
  import {
3
7
  projectIntegrationRow,
@@ -161,7 +165,7 @@ export interface DashboardHarvest {
161
165
  /** A row always represents this concrete run; the repository gate lives in
162
166
  * the header even when no run exists. */
163
167
  run: string
164
- status: 'running' | 'paused' | 'escalated' | 'failed'
168
+ status: 'running' | 'paused' | 'suspended' | 'escalated' | 'failed'
165
169
  steps: PipelineStep[]
166
170
  observations: number
167
171
  rounds: number
@@ -172,6 +176,7 @@ export interface DashboardHarvest {
172
176
  }
173
177
 
174
178
  export interface DashboardBuild {
179
+ draining?: boolean
175
180
  integrationRow?: IntegrationRow
176
181
  integrationDetail?: IntegrationDetail
177
182
  collectionIdentity?: {
@@ -305,6 +310,8 @@ export interface DashboardCounter {
305
310
  }
306
311
 
307
312
  export interface DashboardModel {
313
+ rollback?: DashboardRollback
314
+ handoffs?: DashboardHandoff[]
308
315
  repo: string
309
316
  /** Ready tickets waiting for a slot — the dispatcher's standing queue depth. */
310
317
  queued: number
@@ -365,6 +372,7 @@ export function effectiveStatus(state: BuildState): EffectiveStatus | BuildState
365
372
  if (state.status === 'done') return 'done'
366
373
  if (state.status === 'aborted') return 'cleaning'
367
374
  if (state.pendingCommands.some((command) => command.command === 'abort')) return 'aborting'
375
+ if (state.kind === 'node' && integrationFailed(state)) return 'blocked'
368
376
  if (
369
377
  (state.status === 'paused' || state.status === 'blocked') &&
370
378
  state.openEscalations.length > 0
@@ -1032,6 +1040,9 @@ export function projectBuildFromFacts(
1032
1040
  ...(setupError !== undefined ? { setupError } : {}),
1033
1041
  blockers: [
1034
1042
  ...state.openEscalations.map((e) => e.question),
1043
+ ...(state.kind === 'node' && integrationFailed(state)
1044
+ ? ['verification failed: file a repair child targeting this node']
1045
+ : []),
1035
1046
  ...(mergeWaitReason !== undefined ? [mergeWaitReason] : []),
1036
1047
  ],
1037
1048
  ...(state.reviewRoundCeilings.plan !== undefined || state.reviewRoundCeilings.code !== undefined
@@ -1127,7 +1138,9 @@ function projectHarvestRun(
1127
1138
  const exhaustion = run.recoveryExhaustion
1128
1139
 
1129
1140
  const occurrences = run.steps
1130
- const stopped = run.status !== 'running'
1141
+ const suspended = run.status === 'running' ? run.sessions.at(-1) : undefined
1142
+ const suspendedAt = suspended?.status === 'suspended' ? suspended.suspendedAt : undefined
1143
+ const stopped = run.status !== 'running' || suspendedAt !== undefined
1131
1144
  const current = (name: string): boolean => {
1132
1145
  if (stopped || state.paused) return false
1133
1146
  const latest = [...occurrences].reverse().find((occurrence) => occurrence.step === name)
@@ -1166,12 +1179,10 @@ function projectHarvestRun(
1166
1179
  // Both durable stop states freeze any open occurrence. A failure normally
1167
1180
  // closes its step immediately afterward, but projecting the boundary itself
1168
1181
  // must never make an errored row look like work is still accumulating time.
1169
- const frozenAt =
1170
- state.pausedAt !== undefined
1171
- ? Date.parse(state.pausedAt)
1172
- : failureStoppedAt !== undefined
1173
- ? Date.parse(failureStoppedAt)
1174
- : undefined
1182
+ const stops = [state.pausedAt, failureStoppedAt, suspendedAt]
1183
+ .filter((at): at is string => at !== undefined)
1184
+ .map((at) => Date.parse(at))
1185
+ const frozenAt = stops.length > 0 ? Math.min(...stops) : undefined
1175
1186
  const steps: PipelineStep[] = [
1176
1187
  step('scan', hasOutcome('scan', 'completed'), current('scan'), {
1177
1188
  qualifier: failedAt('scan') ? 'failed' : undefined,
@@ -1240,7 +1251,8 @@ function projectHarvestRun(
1240
1251
  run: run.run,
1241
1252
  // A paused gate freezes an open run. Attention statuses remain visible as
1242
1253
  // FAILED/ESCALATED because the header now carries the gate state.
1243
- status: state.paused && run.status === 'running' ? 'paused' : run.status,
1254
+ status:
1255
+ state.paused && run.status === 'running' ? 'paused' : suspendedAt ? 'suspended' : run.status,
1244
1256
  steps,
1245
1257
  observations: run.observations.length,
1246
1258
  rounds,
@@ -1302,14 +1314,27 @@ export function buildDashboardFromProjected(
1302
1314
  projectedBuilds: readonly DashboardBuild[],
1303
1315
  header: DashboardHeader,
1304
1316
  repositoryEvents: RepositoryEvent[] | RepositoryReadFacts = [],
1317
+ // Filtered frontend feeds omit operational facts; use the durable reduced read there.
1318
+ upgrades?: DispatchUpgradeState,
1305
1319
  ): DashboardModel {
1306
- const builds = enrichIntegrationRows(projectedBuilds).sort((a, b) => a.slug.localeCompare(b.slug))
1320
+ const upgradeState =
1321
+ upgrades ??
1322
+ (Array.isArray(repositoryEvents)
1323
+ ? dispatchUpgradeReducer.reduce(repositoryEvents)
1324
+ : repositoryEvents.upgrades)
1325
+ const upgrade = projectHandoffs(upgradeState)
1326
+ const rollback = projectRollback(upgradeState)
1327
+ const builds = enrichIntegrationRows(
1328
+ projectedBuilds.map((row) => enrichDrainingRow(row, upgrade.draining)),
1329
+ ).sort((a, b) => a.slug.localeCompare(b.slug))
1307
1330
  const harvestProjection = projectRepositoryHarvest(repositoryEvents)
1308
1331
  const settings = Array.isArray(repositoryEvents)
1309
1332
  ? reduceDispatchSettings(repositoryEvents)
1310
1333
  : repositoryEvents.settings
1311
1334
  return {
1312
1335
  repo: header.repo,
1336
+ ...(rollback ? { rollback } : {}),
1337
+ ...(upgrade.handoffs.length ? { handoffs: upgrade.handoffs } : {}),
1313
1338
  queued: header.queued,
1314
1339
  active: {
1315
1340
  current: header.capacityProjection?.occupied ?? header.activeCount,
@@ -1352,6 +1377,12 @@ export function buildDashboard(
1352
1377
  })),
1353
1378
  config.capacity,
1354
1379
  new Date(),
1380
+ migrationIdentity(
1381
+ Array.isArray(repositoryEvents)
1382
+ ? ticketMigrationsReducer.reduce(repositoryEvents)
1383
+ : repositoryEvents.ticketMigrations,
1384
+ config.tickets.source,
1385
+ ),
1355
1386
  )
1356
1387
  const activeCount = capacityProjection.occupied
1357
1388
  return buildDashboardFromProjected(
@@ -1,3 +1,6 @@
1
+ import { formatRollback } from './rollback'
2
+ import { formatHandoff } from './handoff'
3
+ import { handPushedLabel, handPushedText } from './hand-pushed'
1
4
  import { integrationBarCells } from './integration-row'
2
5
  import { capacityExplanation } from '../../kernel/dispatch-capacity'
3
6
  import { treeVocabulary, consentQueue } from './tree'
@@ -268,6 +271,7 @@ const STATUS_COLOR: Record<DashboardBuild['status'] | DashboardHarvest['status']
268
271
  collecting: 'cyan',
269
272
  pausing: 'yellow',
270
273
  paused: 'yellow',
274
+ suspended: 'yellow',
271
275
  resuming: 'cyan',
272
276
  blocked: 'red',
273
277
  aborting: 'red',
@@ -364,6 +368,7 @@ function renderBuild(
364
368
  }
365
369
  // Blocked overrides paused visually, but the pause is still a fact the
366
370
  // operator needs — so it rides along rather than being overwritten.
371
+ if (build.draining) rightTokens.push(paint('(draining)', 'yellow', color))
367
372
  if (build.alsoPaused) rightTokens.push(paint('(paused)', 'yellow', color))
368
373
  rightTokens.push(
369
374
  paint(build.status.toUpperCase().padStart(widths.status), STATUS_COLOR[build.status], color),
@@ -766,6 +771,7 @@ function detailBody(
766
771
  field('Integration', detail.destination)
767
772
  const progress = integrationProgress(build.integrationRow, color)
768
773
  body.push(...packLines(['Progress', progress.bar, ...progress.counts], width, ' '))
774
+ field(handPushedLabel, handPushedText(detail.handPushedCommits))
769
775
  field('Branch', `${detail.branch} · restack ${detail.restack}`)
770
776
  if (detail.parentDistance) field('Parent', detail.parentDistance.replace(/^parent /, ''))
771
777
  for (const path of detail.conflictFiles ?? []) field('Conflict', path)
@@ -906,6 +912,16 @@ function upgradeNoticeLine(
906
912
  )
907
913
  }
908
914
 
915
+ function runtimeNoticeLines(model: DashboardModel, color: boolean, width: number): string[] {
916
+ const notices = [
917
+ ...(model.rollback ? [formatRollback(model.rollback)] : []),
918
+ ...(model.handoffs ?? []).map(formatHandoff),
919
+ ]
920
+ return notices.flatMap((notice) =>
921
+ wrappedText(notice, width, ' ').map((line) => paint(line, 'yellow', color)),
922
+ )
923
+ }
924
+
909
925
  function detailGeometry(
910
926
  model: DashboardModel,
911
927
  width: number,
@@ -917,7 +933,10 @@ function detailGeometry(
917
933
  if (build === undefined) return undefined
918
934
  const layout = detailBody(build, view, { color: false, width, height, now: 0 })
919
935
  const topLength =
920
- 2 + (model.standby === undefined ? 0 : 1) + (model.availableUpgrade === undefined ? 0 : 1)
936
+ 2 +
937
+ (model.standby === undefined ? 0 : 1) +
938
+ (model.availableUpgrade === undefined ? 0 : 1) +
939
+ runtimeNoticeLines(model, false, width).length
921
940
  const controls =
922
941
  model.resumeInput !== undefined || model.abortConfirmation !== undefined
923
942
  ? dashboardControls(model, false, width, controlsCapacity(height, topLength))
@@ -968,16 +987,18 @@ function renderDetail(model: DashboardModel, opts: RenderOpts): string[] {
968
987
  const build = model.builds.find((candidate) => candidate.slug === view.slug)
969
988
  if (build === undefined) return []
970
989
  const { color, width, height } = opts
990
+ const draining = build.draining ? ` ${paint('(draining)', 'yellow', color)}` : ''
971
991
  const paused = build.alsoPaused ? ' (also paused)' : ''
972
992
  const notice = upgradeNoticeLine(model, color, width)
973
993
  const top = [
974
994
  truncate(`${paint('Build', 'bold', color)} ${displayText(build.slug)}`, width),
975
995
  truncate(
976
- ` status ${paint(build.status.toUpperCase(), STATUS_COLOR[build.status], color)}${paused}`,
996
+ ` status ${paint(build.status.toUpperCase(), STATUS_COLOR[build.status], color)}${paused}${draining}`,
977
997
  width,
978
998
  ),
979
999
  ...standbyLine(model, color, width),
980
1000
  ...(notice === undefined ? [] : [notice]),
1001
+ ...runtimeNoticeLines(model, color, width),
981
1002
  ]
982
1003
  const { body } = detailBody(build, view, opts)
983
1004
  const controls =
@@ -1595,6 +1616,7 @@ function renderDashboardContent(model: DashboardModel, opts: RenderOpts): string
1595
1616
  toggles,
1596
1617
  ...standbyLine(model, color, width),
1597
1618
  ...(upgradeNotice === undefined ? [] : [upgradeNotice]),
1619
+ ...runtimeNoticeLines(model, color, width),
1598
1620
  ...warnings,
1599
1621
  ]
1600
1622
  // Both structural separators are fixed frame chrome: one between the
@@ -0,0 +1,30 @@
1
+ import type { RuntimeIdentity } from '../../events/runtime'
2
+ import type { DispatchUpgradeState } from '../../kernel/dispatch-upgrade'
3
+ import { displayText } from './cells'
4
+ import { handoffRuntime } from './handoff'
5
+
6
+ export interface DashboardRollback {
7
+ correlation: string
8
+ lineage: string
9
+ failed: RuntimeIdentity
10
+ restored: RuntimeIdentity
11
+ ts: string
12
+ }
13
+
14
+ /** Historical holds remain queryable, but only the authoritative lineage is visible. */
15
+ export function projectRollback(state: DispatchUpgradeState): DashboardRollback | undefined {
16
+ const lineage = state.authoritativeRun && state.lineages[state.authoritativeRun]
17
+ const hold = lineage ? state.holds[lineage] : undefined
18
+ if (!hold) return undefined
19
+ return {
20
+ correlation: hold.payload.correlation,
21
+ lineage: hold.payload.lineage,
22
+ failed: hold.payload.failed,
23
+ restored: hold.payload.restored,
24
+ ts: hold.ts,
25
+ }
26
+ }
27
+
28
+ export function formatRollback(rollback: DashboardRollback): string {
29
+ return `rollback: failed ${handoffRuntime(rollback.failed)}; restored ${handoffRuntime(rollback.restored)}; held ${handoffRuntime(rollback.failed)}; at ${displayText(rollback.ts)}`
30
+ }
@@ -0,0 +1,53 @@
1
+ import { parseArgs, stringFlag } from './args'
2
+ export function parseDispatchArgs(
3
+ rest: readonly string[],
4
+ env: Record<string, string | undefined>,
5
+ ) {
6
+ const usage =
7
+ 'usage: ab dispatch [--once] [--interval <seconds>] [--store <ref>] [--repository <origin>] [--plain] [--intake | --no-intake] [--auto-merge | --no-auto-merge] (§3.3)'
8
+ const parsed = parseArgs(
9
+ rest,
10
+ {
11
+ once: 'boolean',
12
+ interval: 'value',
13
+ store: 'value',
14
+ repository: 'value',
15
+ plain: 'boolean',
16
+ intake: 'boolean',
17
+ 'no-intake': 'boolean',
18
+ 'auto-merge': 'boolean',
19
+ 'no-auto-merge': 'boolean',
20
+ },
21
+ usage,
22
+ )
23
+ if (parsed.positionals.length > 0) throw new Error(usage)
24
+
25
+ const once = parsed.flags.has('once')
26
+ const plain = parsed.flags.has('plain')
27
+ const sawIntake = parsed.flags.has('intake')
28
+ const sawNoIntake = parsed.flags.has('no-intake')
29
+ const sawAutoMerge = parsed.flags.has('auto-merge')
30
+ const sawNoAutoMerge = parsed.flags.has('no-auto-merge')
31
+ if (sawIntake && sawNoIntake) {
32
+ throw new Error(`--intake and --no-intake cannot be combined — ${usage}`)
33
+ }
34
+ if (sawAutoMerge || sawNoAutoMerge) {
35
+ throw new Error(`Auto-merge flags are retired; configure [[landing]] policy — ${usage}`)
36
+ }
37
+
38
+ const interval = stringFlag(parsed, 'interval')
39
+ let intervalMs: number | undefined
40
+ if (interval !== undefined) {
41
+ const seconds = Number(interval)
42
+ if (!Number.isFinite(seconds) || seconds <= 0) {
43
+ throw new Error(`--interval requires a positive number of seconds — ${usage}`)
44
+ }
45
+ intervalMs = Math.round(seconds * 1000)
46
+ }
47
+ const storeRef = stringFlag(parsed, 'store')
48
+ const repository = stringFlag(parsed, 'repository') ?? env.AB_REPOSITORY
49
+ const intake = sawIntake ? true : sawNoIntake ? false : undefined
50
+ const defaultAutoMerge = sawAutoMerge ? true : sawNoAutoMerge ? false : undefined
51
+
52
+ return { once, plain, intake, defaultAutoMerge, intervalMs, storeRef, repository }
53
+ }
@@ -0,0 +1,15 @@
1
+ /** Launcher-local supervision, anchored to the original durable takeover. */
2
+ export class DispatchCrashBudget {
3
+ private failures = 0
4
+ private readonly counted = new Set<string>()
5
+ constructor(readonly takeoverAt: string) {}
6
+ withinWindow(now: number): boolean {
7
+ const elapsed = now - Date.parse(this.takeoverAt)
8
+ return Number.isFinite(elapsed) && elapsed >= 0 && elapsed <= 10 * 60_000
9
+ }
10
+ failed(run: string, now: number): 'restart' | 'rollback' | undefined {
11
+ if (!this.withinWindow(now) || this.counted.has(run)) return undefined
12
+ this.counted.add(run)
13
+ return ++this.failures >= 3 ? 'rollback' : 'restart'
14
+ }
15
+ }