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

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 (162) hide show
  1. package/README.md +9 -4
  2. package/SPEC.md +295 -62
  3. package/bin/ab-build-runner.ts +10 -8
  4. package/docs/architecture.md +179 -25
  5. package/docs/configuration.md +41 -6
  6. package/docs/hosted-service.md +35 -0
  7. package/docs/integration-tree.md +81 -4
  8. package/docs/landing-policy.md +11 -0
  9. package/docs/migration-1.0.md +9 -0
  10. package/docs/operator-api.md +18 -0
  11. package/docs/remote-store-protocol.md +11 -0
  12. package/docs/restacking.md +42 -7
  13. package/docs/setup.md +25 -0
  14. package/docs/ticket-dependencies.md +6 -45
  15. package/package.json +3 -3
  16. package/packages/core/src/cli/attention.ts +4 -1
  17. package/packages/core/src/cli/binary.ts +17 -1
  18. package/packages/core/src/cli/context.ts +53 -1
  19. package/packages/core/src/cli/dashboard/actions.ts +4 -0
  20. package/packages/core/src/cli/dashboard/detail.ts +45 -1
  21. package/packages/core/src/cli/dashboard/facts.ts +7 -2
  22. package/packages/core/src/cli/dashboard/integration-detail.ts +142 -0
  23. package/packages/core/src/cli/dashboard/integration-row.ts +248 -0
  24. package/packages/core/src/cli/dashboard/landing-display.ts +64 -0
  25. package/packages/core/src/cli/dashboard/model.ts +140 -16
  26. package/packages/core/src/cli/dashboard/poll.ts +40 -4
  27. package/packages/core/src/cli/dashboard/refresh.ts +20 -13
  28. package/packages/core/src/cli/dashboard/render.ts +106 -5
  29. package/packages/core/src/cli/dashboard/transcript.ts +2 -1
  30. package/packages/core/src/cli/dispatch-frontend.ts +22 -12
  31. package/packages/core/src/cli/dispatch.ts +59 -25
  32. package/packages/core/src/cli/help.ts +19 -2
  33. package/packages/core/src/cli/main.ts +37 -0
  34. package/packages/core/src/cli/publication-settlement.ts +49 -5
  35. package/packages/core/src/cli/repository-status.ts +97 -2
  36. package/packages/core/src/cli/status.ts +24 -1
  37. package/packages/core/src/cli/terminals.ts +94 -93
  38. package/packages/core/src/cli/wait.ts +11 -2
  39. package/packages/core/src/cli/watch.ts +12 -0
  40. package/packages/core/src/config/schema.ts +3 -0
  41. package/packages/core/src/events/catalog.ts +38 -0
  42. package/packages/core/src/events/compatibility.ts +183 -0
  43. package/packages/core/src/events/native-session.ts +13 -0
  44. package/packages/core/src/events/payloads.ts +148 -2
  45. package/packages/core/src/events/policy.ts +209 -0
  46. package/packages/core/src/events/repository.ts +48 -0
  47. package/packages/core/src/integration/harness.ts +4 -4
  48. package/packages/core/src/kernel/__snapshots__/{reducer-registry.test.ts.snap → reducer-accumulator-shapes.json} +771 -538
  49. package/packages/core/src/kernel/change-presence.ts +4 -2
  50. package/packages/core/src/kernel/dispatch-capacity.ts +119 -0
  51. package/packages/core/src/kernel/dispatcher-liveness.ts +5 -1
  52. package/packages/core/src/kernel/engine.ts +25 -5
  53. package/packages/core/src/kernel/forge-health.ts +19 -0
  54. package/packages/core/src/kernel/generators/build-log.ts +18 -0
  55. package/packages/core/src/kernel/generators/node-restack-log.ts +1 -1
  56. package/packages/core/src/kernel/generators/repository-journals.ts +10 -0
  57. package/packages/core/src/kernel/guarded-forge.ts +159 -0
  58. package/packages/core/src/kernel/incremental.ts +4 -2
  59. package/packages/core/src/kernel/integration-completeness.ts +61 -0
  60. package/packages/core/src/kernel/integration-landing.ts +5 -4
  61. package/packages/core/src/kernel/janitor-failure.ts +36 -0
  62. package/packages/core/src/kernel/landing-publication.ts +35 -15
  63. package/packages/core/src/kernel/landing-state.ts +7 -0
  64. package/packages/core/src/kernel/leaf-restack-state.ts +1 -1
  65. package/packages/core/src/kernel/log-index.ts +12 -1
  66. package/packages/core/src/kernel/mixed-version.ts +52 -0
  67. package/packages/core/src/kernel/node-landing.ts +14 -11
  68. package/packages/core/src/kernel/node-restack-demand.ts +29 -0
  69. package/packages/core/src/kernel/node-restack-state.ts +46 -16
  70. package/packages/core/src/kernel/node-restack-transaction.ts +151 -8
  71. package/packages/core/src/kernel/node-restack.ts +34 -10
  72. package/packages/core/src/kernel/publication.ts +22 -0
  73. package/packages/core/src/kernel/read-deferrals.ts +111 -0
  74. package/packages/core/src/kernel/read-facts.ts +27 -6
  75. package/packages/core/src/kernel/reconcile-restack.ts +23 -2
  76. package/packages/core/src/kernel/reducer-registry.ts +15 -2
  77. package/packages/core/src/kernel/reducer.ts +196 -10
  78. package/packages/core/src/kernel/repository-attention.ts +38 -1
  79. package/packages/core/src/kernel/terminal-guard.ts +11 -4
  80. package/packages/core/src/operator/annotations.ts +6 -0
  81. package/packages/core/src/operator/index.ts +2 -0
  82. package/packages/core/src/operator/presentation.ts +5 -0
  83. package/packages/core/src/operator/query.ts +45 -11
  84. package/packages/core/src/operator/registry.ts +17 -1
  85. package/packages/core/src/operator/restack.ts +51 -0
  86. package/packages/core/src/plugin-sdk/index.ts +10 -0
  87. package/packages/core/src/plugins/load.ts +3 -4
  88. package/packages/core/src/plugins/manifest.ts +1 -1
  89. package/packages/core/src/ports/forge/contract.ts +23 -0
  90. package/packages/core/src/ports/forge/fake.ts +6 -2
  91. package/packages/core/src/ports/forge/git-rewrite.ts +92 -64
  92. package/packages/core/src/ports/forge/github-transport.ts +45 -2
  93. package/packages/core/src/ports/forge/github.ts +56 -17
  94. package/packages/core/src/ports/forge/local-git.ts +7 -2
  95. package/packages/core/src/ports/forge-failure.ts +40 -0
  96. package/packages/core/src/ports/forge-request-context.ts +35 -0
  97. package/packages/core/src/ports/forge-telemetry.ts +16 -0
  98. package/packages/core/src/ports/runner/claude.ts +136 -9
  99. package/packages/core/src/ports/runner/codex.ts +112 -7
  100. package/packages/core/src/ports/runner/contract.ts +78 -0
  101. package/packages/core/src/ports/runner/fake.ts +59 -1
  102. package/packages/core/src/ports/runner/native-cli-fixture.ts +86 -0
  103. package/packages/core/src/ports/runner/native-process-fixture.ts +38 -0
  104. package/packages/core/src/ports/runner/native-session.ts +110 -0
  105. package/packages/core/src/ports/runner/pi-rpc.ts +7 -1
  106. package/packages/core/src/ports/runner/pi.ts +162 -2
  107. package/packages/core/src/ports/types.ts +53 -5
  108. package/packages/core/src/ports/workspace/git-worktree.ts +45 -51
  109. package/packages/core/src/ports/workspace/vercel-sandbox.ts +28 -12
  110. package/packages/core/src/processes/build-child-exit.ts +50 -2
  111. package/packages/core/src/processes/build-child.ts +15 -7
  112. package/packages/core/src/processes/build-runner.ts +909 -213
  113. package/packages/core/src/processes/dispatcher.ts +652 -334
  114. package/packages/core/src/processes/execution-no-progress.ts +15 -0
  115. package/packages/core/src/processes/pause-execution-fixture.ts +37 -0
  116. package/packages/core/src/processes/phase-failure-budget.ts +2 -1
  117. package/packages/core/src/processes/publication-loss.ts +7 -3
  118. package/packages/core/src/processes/repo-view.ts +53 -6
  119. package/packages/core/src/processes/tick-publication.ts +6 -2
  120. package/packages/core/src/runtime-identity.ts +37 -0
  121. package/packages/core/src/store/adapter.ts +4 -2
  122. package/packages/core/src/store/build-scope.ts +9 -0
  123. package/packages/core/src/store/contract.ts +203 -16
  124. package/packages/core/src/store/digest.ts +20 -2
  125. package/packages/core/src/store/local/schema.ts +6 -0
  126. package/packages/core/src/store/local/store.ts +57 -4
  127. package/packages/core/src/store/memory.ts +83 -2
  128. package/packages/core/src/store/new-build.ts +2 -2
  129. package/packages/core/src/store/phase-session.ts +13 -0
  130. package/packages/core/src/store/reduced-reads.ts +43 -4
  131. package/packages/core/src/store/reducer-value-shapes.json +8238 -5764
  132. package/packages/core/src/store/reducer-value-validation.ts +103 -3
  133. package/packages/core/src/store/reducer-values.ts +21 -6
  134. package/packages/core/src/store/remote/client.ts +146 -20
  135. package/packages/core/src/store/remote/compatibility.ts +6 -0
  136. package/packages/core/src/store/remote/index.ts +2 -0
  137. package/packages/core/src/store/remote/protocol.ts +19 -0
  138. package/packages/core/src/store/remote/version.ts +2 -0
  139. package/packages/core/src/store/repo-state-events.ts +3 -1
  140. package/packages/core/src/store/repo-tick.ts +6 -1
  141. package/packages/core/src/store/session-handle.ts +8 -0
  142. package/packages/core/src/store/snapshots.ts +21 -5
  143. package/packages/core/src/store/types.ts +19 -1
  144. package/packages/core/src/testing/dispatch-read-budget.ts +17 -2
  145. package/packages/core/src/testing/index.ts +7 -0
  146. package/packages/core/src/testing/newer-writer.ts +37 -0
  147. package/packages/core/src/testing/reduced-read-budget.ts +3 -0
  148. package/skills/guide/SKILL.md +144 -27
  149. package/skills/guide/references/integration-tree.md +81 -4
  150. package/skills/guide/references/landing-policy.md +11 -0
  151. package/skills/guide/references/migration-1.0.md +9 -0
  152. package/skills/guide/references/operator-api.md +18 -0
  153. package/skills/guide/references/plugin-authoring.md +55 -7
  154. package/skills/guide/references/remote-store-protocol.md +11 -0
  155. package/skills/guide/references/restacking.md +42 -7
  156. package/skills/guide/references/setup.md +25 -0
  157. package/skills/guide/references/ticket-dependencies.md +6 -45
  158. package/skills/implement/SKILL.md +4 -2
  159. package/skills/operate/SKILL.md +63 -6
  160. package/skills/reconcile/SKILL.md +3 -1
  161. package/skills/spec/SKILL.md +49 -39
  162. package/skills/tickets/SKILL.md +15 -43
@@ -39,6 +39,7 @@ export class DashboardRefresh {
39
39
  constructor(
40
40
  private readonly refresh: () => Promise<void>,
41
41
  private readonly time: RefreshScheduler = scheduler,
42
+ private readonly networkReads = false,
42
43
  ) {}
43
44
 
44
45
  get painting(): boolean {
@@ -50,7 +51,7 @@ export class DashboardRefresh {
50
51
  }
51
52
 
52
53
  get admitted(): boolean {
53
- return this.active && !this.suspended && (this.focused || this.permit === this.generation)
54
+ return this.active && !this.suspended
54
55
  }
55
56
 
56
57
  activity(live: boolean): void {
@@ -58,10 +59,13 @@ export class DashboardRefresh {
58
59
  }
59
60
 
60
61
  focus(focused: boolean): void {
62
+ if (this.focused === focused) return
61
63
  this.focused = focused
62
- this.generation += 1
63
- this.cancel()
64
64
  if (focused) void this.request()
65
+ else if (this.networkReads) {
66
+ this.cancel()
67
+ if (this.flight === undefined) this.schedule()
68
+ }
65
69
  }
66
70
 
67
71
  interaction(): void {
@@ -77,7 +81,8 @@ export class DashboardRefresh {
77
81
 
78
82
  resume(): void {
79
83
  this.suspended = false
80
- this.focus(true)
84
+ this.focused = true
85
+ void this.request()
81
86
  }
82
87
 
83
88
  stop(): void {
@@ -103,11 +108,10 @@ export class DashboardRefresh {
103
108
  }
104
109
 
105
110
  request(interaction = false): Promise<void> {
106
- if (!this.active || this.suspended || (!this.focused && !interaction)) return Promise.resolve()
111
+ if (!this.active || this.suspended) return Promise.resolve()
107
112
  if (this.flight !== undefined) {
108
- // A focus round trip invalidates an outstanding read. Refresh again after
109
- // it settles, rather than losing the focus-in wakeup.
110
- if (this.permit !== this.generation) this.wake = true
113
+ // Retain an explicit wakeup that arrives during outstanding I/O.
114
+ if (interaction || this.permit !== this.generation) this.wake = true
111
115
  return this.flight
112
116
  }
113
117
  this.cancel()
@@ -121,7 +125,7 @@ export class DashboardRefresh {
121
125
  if (this.flight !== current) return
122
126
  this.flight = undefined
123
127
  this.permit = undefined
124
- if (this.wake && this.active && !this.suspended && this.focused) {
128
+ if (this.wake && this.active && !this.suspended) {
125
129
  this.wake = false
126
130
  void this.request()
127
131
  } else this.schedule()
@@ -137,15 +141,18 @@ export class DashboardRefresh {
137
141
 
138
142
  /** Current admission cadence, also used to bound presentation staleness. */
139
143
  get intervalMs(): number {
144
+ if (this.networkReads && !this.focused) return 5000
140
145
  return this.live || this.time.now() < this.deadline ? 500 : 5000
141
146
  }
142
147
 
143
148
  private schedule(): void {
144
- if (!this.active || this.suspended || !this.focused) return
149
+ if (!this.active || this.suspended) return
145
150
  const interval = this.intervalMs
146
151
  // Slow/failing requests do not spin when their start deadline is overdue.
147
- const remaining = this.started + interval - this.time.now()
148
- const delay = remaining > 0 ? remaining : 50
152
+ const remaining = Number.isFinite(this.started)
153
+ ? this.started + interval - this.time.now()
154
+ : interval
155
+ const delay = remaining > 0 ? remaining : this.networkReads && !this.focused ? interval : 50
149
156
  this.timer = this.time.set(() => {
150
157
  this.timer = undefined
151
158
  void this.request()
@@ -155,7 +162,7 @@ export class DashboardRefresh {
155
162
 
156
163
  /** Guard each asynchronous read stage, including reads inside shared caches.
157
164
  * Operator mutations keep their original store; only presentation readers use
158
- * this facade. A focus loss cannot recall I/O already dispatched. */
165
+ * this facade. Suspension and stop fence subsequent read stages. */
159
166
  export function presentationReader<T extends object>(store: T, admitted: () => boolean): T {
160
167
  return new Proxy(store, {
161
168
  get(target, key, receiver) {
@@ -1,3 +1,5 @@
1
+ import { integrationBarCells } from './integration-row'
2
+ import { capacityExplanation } from '../../kernel/dispatch-capacity'
1
3
  import { treeVocabulary, consentQueue } from './tree'
2
4
  /**
3
5
  * The dashboard's other pure half: model → `string[]`. No terminal, no state,
@@ -29,7 +31,7 @@ import type {
29
31
  PipelineStep,
30
32
  } from './model'
31
33
  import { landingPolicyDisplay } from './landing-display'
32
- import { dashboardBuildControl } from './actions'
34
+ import { dashboardBuildControl, pauseResumeHelp } from './actions'
33
35
  import type { DashboardSession } from './detail'
34
36
  import type { TranscriptPresentation, TranscriptTurn } from './transcript'
35
37
  import { projectSessionDocument, projectSessionParts } from './session-view'
@@ -371,6 +373,34 @@ function renderBuild(
371
373
  // The slug is the sole flexible segment; narrow frames truncate it before
372
374
  // the right-pinned lifecycle status.
373
375
  const lines = [rightPinnedLine(leftPrefix, paint(build.slug, 'bold', color), rightStr, width)]
376
+ if (build.integrationRow) {
377
+ const row = build.integrationRow
378
+ const { bar, counts } = integrationProgress(row, color)
379
+ lines.push(
380
+ ...packLines(
381
+ [
382
+ paint(`integration → ${row.destination}`, 'bold', color),
383
+ bar,
384
+ ...(row.parentDistance ? [paint(row.parentDistance, 'dim', color)] : []),
385
+ ...counts,
386
+ ...(row.verified ? [paint('· verified', 'green', color)] : []),
387
+ ],
388
+ width,
389
+ ' ',
390
+ ),
391
+ )
392
+ lines.push(
393
+ ...packLines(
394
+ row.steps.map((s) => renderStep(s, color, now)),
395
+ width,
396
+ ' ',
397
+ ),
398
+ )
399
+ if (row.alert)
400
+ for (const line of wrappedText(row.alert.text, Math.max(1, width - 4), ''))
401
+ lines.push(paint(` ! ${line}`, row.alert.tone, color))
402
+ return lines
403
+ }
374
404
  if (build.target)
375
405
  lines.push(
376
406
  truncate(
@@ -631,6 +661,9 @@ function sessionLines(session: DashboardSession, selected: boolean, opts: Render
631
661
  `runtime ${session.runtime}`,
632
662
  ...(session.model !== undefined ? [`model ${session.model}`] : []),
633
663
  session.status,
664
+ ...(session.cause ? [`cause ${session.cause}`] : []),
665
+ ...(session.fallbackReason ? [`fresh session: ${session.fallbackReason}`] : []),
666
+ ...(session.predecessor ? [`continued from ${session.predecessor}`] : []),
634
667
  ...(session.stream !== undefined ? [`stream ${session.stream} (${session.streamStatus})`] : []),
635
668
  ...(session.reclaimedBy !== undefined
636
669
  ? [
@@ -667,6 +700,27 @@ interface DetailBodyLayout {
667
700
 
668
701
  export type DetailFocusTarget = 'session' | 'message'
669
702
 
703
+ function integrationProgress(row: NonNullable<DashboardBuild['integrationRow']>, color: boolean) {
704
+ const children = row.children
705
+ let bar = paint('┄'.repeat(22), 'dim', color)
706
+ let counts = [paint('children unknown', 'dim', color)]
707
+ if (children.known) {
708
+ const cells = integrationBarCells(children.landed, children.building, children.queued)
709
+ bar =
710
+ paint('━'.repeat(cells[0]!), 'green', color) +
711
+ paint('━'.repeat(cells[1]!), 'cyan', color) +
712
+ paint('─'.repeat(children.total ? cells[2]! : 22), 'dim', color)
713
+ counts = children.total
714
+ ? [
715
+ paint(`${children.landed}/${children.total} landed`, 'green', color),
716
+ ...(children.building ? [paint(`· ${children.building} building`, 'cyan', color)] : []),
717
+ ...(children.queued ? [paint(`· ${children.queued} queued`, 'dim', color)] : []),
718
+ ]
719
+ : [paint('no children yet', 'dim', color)]
720
+ }
721
+ return { bar, counts }
722
+ }
723
+
670
724
  function detailBody(
671
725
  build: DashboardBuild,
672
726
  view: Extract<NonNullable<DashboardModel['view']>, { kind: 'detail' }>,
@@ -674,12 +728,17 @@ function detailBody(
674
728
  ): DetailBodyLayout {
675
729
  const { color, width } = opts
676
730
  const body: string[] = []
731
+ if (dashboardBuildControl(build.status)) body.push(...wrappedText(pauseResumeHelp, width, ' '))
677
732
  if (build.ticketId !== undefined) body.push(` ticket ${displayText(build.ticketId)}`)
678
- if (build.target)
733
+ if (build.target && !build.integrationDetail)
679
734
  body.push(
680
735
  ` ${build.kind ?? treeVocabulary.work} · ${treeVocabulary.target} ${build.target}${build.integration ? ` · ${build.integration}` : ''}`,
681
736
  )
682
- if (build.tree && (build.kind === 'integration' || build.tree.consent)) {
737
+ if (
738
+ !build.integrationDetail &&
739
+ build.tree &&
740
+ (build.kind === 'integration' || build.tree.consent)
741
+ ) {
683
742
  const tree = build.tree
684
743
  body.push(
685
744
  ` ${treeVocabulary.branch} ${tree.branch ?? 'unknown'} · ${treeVocabulary.restack} ${tree.restack}`,
@@ -700,6 +759,48 @@ function detailBody(
700
759
  ` ${treeVocabulary.landing} ${tree.reason ?? (tree.ready ? treeVocabulary.readyToLand : treeVocabulary.notReady)}`,
701
760
  )
702
761
  }
762
+ if (build.integrationDetail && build.integrationRow) {
763
+ const detail = build.integrationDetail
764
+ const field = (label: string, text: string) =>
765
+ body.push(...wrapDisplay(`${label} ${text}`, width, ' '))
766
+ field('Integration', detail.destination)
767
+ const progress = integrationProgress(build.integrationRow, color)
768
+ body.push(...packLines(['Progress', progress.bar, ...progress.counts], width, ' '))
769
+ field('Branch', `${detail.branch} · restack ${detail.restack}`)
770
+ if (detail.parentDistance) field('Parent', detail.parentDistance.replace(/^parent /, ''))
771
+ for (const path of detail.conflictFiles ?? []) field('Conflict', path)
772
+ body.push(
773
+ ...packLines(
774
+ ['Steps', ...build.integrationRow.steps.map((s) => renderStep(s, color, opts.now))],
775
+ width,
776
+ ' ',
777
+ ),
778
+ )
779
+ const open = detail.children.filter((c) => !c.landed).length
780
+ body.push(
781
+ '',
782
+ paint(
783
+ `Children ${open} open · ${detail.children.length - open} landed${detail.membershipKnown ? '' : ' · membership unknown'}`,
784
+ 'bold',
785
+ color,
786
+ ),
787
+ )
788
+ for (const child of detail.children) {
789
+ const id = displayText(child.id)
790
+ const state = displayText(child.state)
791
+ const tone = child.landed ? 'green' : state === 'queued' ? 'dim' : 'cyan'
792
+ const prefix = ` ${paint(child.landed ? '[x]' : state === 'queued' ? '[ ]' : '[>]', tone, color)} ${paint(id, 'blue', color)} `
793
+ const right = paint(state, tone, color)
794
+ if (visibleLength(prefix) + visibleLength(right) + 2 <= width)
795
+ body.push(rightPinnedLine(prefix, displayText(child.title), right, width))
796
+ else body.push(...packLines([id, right], width, ' '))
797
+ }
798
+ for (const diagnostic of detail.diagnostics) field('Membership', diagnostic)
799
+ body.push('')
800
+ field('Verification', detail.verification)
801
+ for (const result of detail.verifySteps) field(result.step, result.outcome)
802
+ field('Landing', detail.landing)
803
+ }
703
804
  if (build.kind !== 'integration') body.push(` landing ${landingPolicyDisplay(build.landing)}`)
704
805
  const ceiling = reviewRoundCeilingText(build)
705
806
  if (ceiling !== undefined) body.push(` ${ceiling}`)
@@ -723,7 +824,7 @@ function detailBody(
723
824
  body.push(...wrappedText(build.abortProgress, width, ' '))
724
825
  } else if (build.dispatch !== undefined) {
725
826
  body.push('', paint('Dispatch', 'bold', color), ...wrappedText(build.dispatch, width, ' '))
726
- } else {
827
+ } else if (!build.integrationDetail) {
727
828
  body.push('', paint('Pipeline', 'bold', color))
728
829
  body.push(...build.steps.map((item) => ` ${detailStep(item, opts)}`))
729
830
  }
@@ -1464,7 +1565,7 @@ function renderDashboardContent(model: DashboardModel, opts: RenderOpts): string
1464
1565
  paint('Autobuild', 'bold', color),
1465
1566
  displayText(basename(model.repo)),
1466
1567
  paint(
1467
- `queue ${model.queued} | active ${model.active.current}/${model.active.limit} | ` +
1568
+ `queue ${model.queued} | active ${model.active.current}/${model.active.limit}${capacityExplanation(model.capacity)} | ` +
1468
1569
  `observations ${model.observations.current}/${model.observations.limit}`,
1469
1570
  'dim',
1470
1571
  color,
@@ -95,7 +95,8 @@ export function parseTranscript(content: string): TranscriptPresentation {
95
95
  "Producer boundary record: this session was kept live for continuation; only this round's final turn was deposited.",
96
96
  turns: [
97
97
  {
98
- prompt: '(producer round invocation)',
98
+ prompt:
99
+ typeof boundary.prompt === 'string' ? boundary.prompt : '(producer round invocation)',
99
100
  text: boundary.text,
100
101
  ...(usage(boundary.usage) !== undefined ? { usage: usage(boundary.usage)! } : {}),
101
102
  },
@@ -1,3 +1,4 @@
1
+ import { dispatchCapacity } from '../kernel/dispatch-capacity'
1
2
  import { forgeReadinessWarnings } from '../kernel/dispatch-status'
2
3
  import { RepositoryPollCache } from './dashboard/repository-poll'
3
4
  import {
@@ -390,6 +391,11 @@ export class DispatchFrontend {
390
391
  (state) => state.kind !== 'node' && state.status !== 'done' && state.status !== 'aborted',
391
392
  ).length,
392
393
  capacity: config.capacity,
394
+ capacityProjection: dispatchCapacity(
395
+ snapshot.capacityBuilds ?? [],
396
+ config.capacity,
397
+ this.clock(),
398
+ ),
393
399
  observationCount: this.observationCount,
394
400
  observationLimit: config.policy.harvestThreshold,
395
401
  ...(status.availableUpgrade !== undefined
@@ -962,18 +968,22 @@ export class DispatchFrontend {
962
968
 
963
969
  private startPresentation(): void {
964
970
  this.accepting = true
965
- this.refresh = new DashboardRefresh(async () => {
966
- try {
967
- await this.readFrame()
968
- } catch (error) {
969
- if (this.refresh?.admitted)
970
- await this.report(
971
- `dashboard render failed: ${error instanceof Error ? error.message : String(error)}`,
972
- 'warning',
973
- )
974
- throw error
975
- }
976
- }, this.opts.refreshScheduler)
971
+ this.refresh = new DashboardRefresh(
972
+ async () => {
973
+ try {
974
+ await this.readFrame()
975
+ } catch (error) {
976
+ if (this.refresh?.admitted)
977
+ await this.report(
978
+ `dashboard render failed: ${error instanceof Error ? error.message : String(error)}`,
979
+ 'warning',
980
+ )
981
+ throw error
982
+ }
983
+ },
984
+ this.opts.refreshScheduler,
985
+ this.opts.store.networkReads,
986
+ )
977
987
  this.listen()
978
988
  this.opts.terminal.modes.enter(FOCUS_REPORTING_MODE)
979
989
  this.suspension = installPresentationSuspension(
@@ -1,3 +1,8 @@
1
+ import { formatDispatcherError } from '../runtime-identity'
2
+
3
+ import { isDeepStrictEqual } from 'node:util'
4
+ import { guardForge } from '../kernel/guarded-forge'
5
+ import { dispatchCapacity } from '../kernel/dispatch-capacity'
1
6
  import { openTicketSource } from './ticket'
2
7
  import {
3
8
  inspectForgeReadiness,
@@ -824,6 +829,12 @@ class DispatchLoop {
824
829
  repo: this.repoIdentity,
825
830
  resident: opts.once !== true,
826
831
  })
832
+ wiring.forge = guardForge(wiring.forge, {
833
+ store: this.repoView,
834
+ repo: this.repoIdentity,
835
+ name: config.forge,
836
+ now: wiring.clock,
837
+ })
827
838
  this.dispatcher = new Dispatcher({
828
839
  store: this.repoView,
829
840
  tickets: wiring.tickets,
@@ -2930,7 +2941,14 @@ class DispatchLoop {
2930
2941
  events: RepositoryEventWrite[],
2931
2942
  ): Promise<RepoTickFinish | null> {
2932
2943
  try {
2933
- return await this.repoView.finishRepoTick(this.repoIdentity, this.runId, completion, events)
2944
+ // Closing a durable boundary must not depend on a subsequent view read.
2945
+ // The next operational tick refreshes the view before any decisions.
2946
+ return await this.wiring.store.finishRepoTick(
2947
+ this.repoIdentity,
2948
+ this.runId,
2949
+ completion,
2950
+ events,
2951
+ )
2934
2952
  } catch (error) {
2935
2953
  const observation = (await this.wiring.store.getRepo(this.repoIdentity).catch(() => null))
2936
2954
  ?.tick
@@ -2947,13 +2965,13 @@ class DispatchLoop {
2947
2965
  (finished.outcome === 'completed' &&
2948
2966
  completion.outcome === 'completed' &&
2949
2967
  Object.entries(completion.counters).some(
2950
- ([key, value]) => finished.counters[key as keyof typeof finished.counters] !== value,
2968
+ ([key, value]) =>
2969
+ !isDeepStrictEqual(finished.counters[key as keyof typeof finished.counters], value),
2951
2970
  ))
2952
2971
  )
2953
2972
  throw error
2954
- // The failed response bypassed the view's own-write fold. Refresh its
2955
- // cursor from the journal, including any committed boundary pair.
2956
- await this.repoView.refresh()
2973
+ // Metadata confirms the exact committed boundary. The next operational
2974
+ // tick refreshes facts before making decisions.
2957
2975
  return { observation, events: [] }
2958
2976
  }
2959
2977
  }
@@ -2962,20 +2980,27 @@ class DispatchLoop {
2962
2980
  const failed = {
2963
2981
  actor: DISPATCHER,
2964
2982
  type: 'dispatcher.tick-failed' as const,
2965
- payload: { run: this.runId, error: error instanceof Error ? error.message : String(error) },
2983
+ payload: { run: this.runId, error: formatDispatcherError(error) },
2966
2984
  }
2967
2985
  if (this.tickStartedAt === undefined) {
2968
- await this.appendStatus(failed)
2986
+ await this.wiring.store.appendRepo(this.repoIdentity, failed)
2969
2987
  return
2970
2988
  }
2971
- const result = await this.finishTick({ outcome: 'failed', error: failed.payload.error }, [
2989
+ const result = await this.finishTick(
2972
2990
  {
2973
- actor: DISPATCHER,
2974
- type: 'dispatcher.tick-started',
2975
- payload: { run: this.runId, startedAt: this.tickStartedAt },
2991
+ outcome: 'failed',
2992
+ error: failed.payload.error,
2993
+ forgeRequests: this.dispatcher.lastForgeRequests,
2976
2994
  },
2977
- failed,
2978
- ])
2995
+ [
2996
+ {
2997
+ actor: DISPATCHER,
2998
+ type: 'dispatcher.tick-started',
2999
+ payload: { run: this.runId, startedAt: this.tickStartedAt },
3000
+ },
3001
+ failed,
3002
+ ],
3003
+ )
2979
3004
  if (result === null) {
2980
3005
  this.superseded = true
2981
3006
  return
@@ -3638,6 +3663,11 @@ class DispatchLoop {
3638
3663
  (state) => state.kind !== 'node' && state.status !== 'done' && state.status !== 'aborted',
3639
3664
  ).length,
3640
3665
  capacity: configSnapshot.config.capacity,
3666
+ capacityProjection: dispatchCapacity(
3667
+ buildSnapshot.capacityBuilds ?? [],
3668
+ configSnapshot.config.capacity,
3669
+ this.wiring.clock(),
3670
+ ),
3641
3671
  observationCount: this.observationCount,
3642
3672
  observationLimit: configSnapshot.config.policy.harvestThreshold,
3643
3673
  },
@@ -3755,17 +3785,21 @@ class DispatchLoop {
3755
3785
 
3756
3786
  private startRendering(): void {
3757
3787
  if (!this.dashboard || this.refresh !== undefined) return
3758
- this.refresh = new DashboardRefresh(async () => {
3759
- try {
3760
- await this.readFrame()
3761
- } catch (error) {
3762
- if (this.refresh?.isFocused)
3763
- this.warn(
3764
- `dashboard render failed: ${error instanceof Error ? error.message : String(error)}`,
3765
- )
3766
- throw error
3767
- }
3768
- })
3788
+ this.refresh = new DashboardRefresh(
3789
+ async () => {
3790
+ try {
3791
+ await this.readFrame()
3792
+ } catch (error) {
3793
+ if (this.refresh?.painting)
3794
+ this.warn(
3795
+ `dashboard render failed: ${error instanceof Error ? error.message : String(error)}`,
3796
+ )
3797
+ throw error
3798
+ }
3799
+ },
3800
+ undefined,
3801
+ this.presentationStore.networkReads,
3802
+ )
3769
3803
  if (this.opts.once !== true) {
3770
3804
  if (this.opts.input !== undefined) this.opts.terminal?.modes.enter(FOCUS_REPORTING_MODE)
3771
3805
  if (this.opts.terminal !== undefined && this.opts.input !== undefined) {
@@ -4036,7 +4070,7 @@ class DispatchLoop {
4036
4070
  startup = false
4037
4071
  } catch (error) {
4038
4072
  if (this.forgePublicationFailed) throw error
4039
- const message = error instanceof Error ? error.message : String(error)
4073
+ const message = formatDispatcherError(error)
4040
4074
  await this.publishTickFailure(error)
4041
4075
  this.warn(`tick failed: ${message}`)
4042
4076
  }
@@ -346,7 +346,7 @@ These fields describe intent; dispatch and landing behavior are unchanged.`,
346
346
  ' flushed as soon as it is written.',
347
347
  ' --store <ref> Override the BuildStore path or URL.',
348
348
  '',
349
- 'Default filter — actionable attention only. Builds: escalation.raised, integration.landed,',
349
+ 'Default filter — actionable attention only. Builds: escalation.raised, phase.deferral-escalated, integration.landed,',
350
350
  'node.item-conflicted, conflicted restack.replayed, derived build.consent-ready and',
351
351
  'build.merge-decision (a current actionable merge-gate deferral or unsafe forge outcome).',
352
352
  'Consent and held ready landings use only build.consent-ready, once per readiness episode.',
@@ -504,6 +504,9 @@ These fields describe intent; dispatch and landing behavior are unchanged.`,
504
504
  ' ab pause <slug> [--store <ref>]',
505
505
  ' ab pause --all [--store <ref>] [--json]',
506
506
  '',
507
+ 'Pause immediately suspends a live agent session after its bounded stop delay.',
508
+ 'Resume continues where it stopped when supported; remote and unsupported',
509
+ 'sessions rerun fresh. Without a live agent, pause waits for the next boundary.',
507
510
  'Durably request that an active build pause. --store overrides the BuildStore',
508
511
  'path or URL. This command is sessionless; a phase may not control its own build.',
509
512
  '',
@@ -600,6 +603,18 @@ These fields describe intent; dispatch and landing behavior are unchanged.`,
600
603
  'may not control its own build.',
601
604
  ]),
602
605
  },
606
+ {
607
+ name: 'restack',
608
+ audience: 'human',
609
+ summary: 'Request a node restack onto its current parent.',
610
+ detail: page([
611
+ 'Usage: ab restack <node> [--store <ref>]',
612
+ '',
613
+ 'Records durable demand, coalescing repeated pending requests.',
614
+ 'Paused or blocked nodes wait for normal safety gates. Leaves, terminal nodes',
615
+ 'and nodes without an open branch are refused. This command is sessionless.',
616
+ ]),
617
+ },
603
618
  ...(['hold', 'land'] as const).map((name) => ({
604
619
  name,
605
620
  audience: 'human' as const,
@@ -792,7 +807,9 @@ export function renderTopLevelHelp(): string {
792
807
  '`ab` is Autobuild’s human/operator CLI and the agent↔store channel (SPEC §8.2).',
793
808
  '',
794
809
  'Primary human workflow:',
795
- ' Run `ab init` once, groom tickets to Ready, then run `ab dispatch`.',
810
+ ' Install in your repository: bun add -d --exact @defrex/autobuild',
811
+ ' Run `bun ab init` once, groom tickets to Ready, then run `bun ab dispatch`.',
812
+ ' Command notation `ab <command>` denotes the repository-installed CLI.',
796
813
  ' Dispatch drives planning, implementation, review, verification, and merge.',
797
814
  '',
798
815
  'For details, run `ab help <command>` or `ab <command> --help`.',
@@ -1,3 +1,5 @@
1
+ import { requestNodeRestack } from '../operator/restack'
2
+ import { withSessionlessStore } from './store-opening'
1
3
  import { abLandings } from './landings'
2
4
  import { readBuildFacts } from '../store/reduced-reads'
3
5
  import { preparePinnedAssets } from '../store/ticket-assets'
@@ -112,6 +114,7 @@ export const SESSIONLESS_COMMANDS = new Set([
112
114
  'wait',
113
115
  'mcp',
114
116
  'repository',
117
+ 'restack',
115
118
  'pause',
116
119
  'resume',
117
120
  'hold',
@@ -1045,6 +1048,40 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
1045
1048
  })
1046
1049
  }
1047
1050
 
1051
+ case 'restack': {
1052
+ const usage = 'usage: ab restack <node> [--store <ref>]'
1053
+ const parsed = parseArgs(rest, { store: 'value' }, usage)
1054
+ if (parsed.positionals.length !== 1) throw new Error(usage)
1055
+ if (
1056
+ deps.processEnv?.AB_SESSION?.trim() &&
1057
+ deps.processEnv?.AB_BUILD?.trim() === parsed.positionals[0]
1058
+ )
1059
+ throw new Error(
1060
+ 'cannot restack a node from its own phase session (AB_SESSION/AB_BUILD conflict)',
1061
+ )
1062
+ if (!deps.exec) throw new Error('restack requires an exec seam')
1063
+ const result = await withSessionlessStore(
1064
+ {
1065
+ targetRepo: deps.workspacePath,
1066
+ env: deps.processEnv ?? {},
1067
+ exec: deps.exec,
1068
+ ...(stringFlag(parsed, 'store') ? { storeRef: stringFlag(parsed, 'store') } : {}),
1069
+ ...(deps.openStore ? { openStore: deps.openStore } : {}),
1070
+ },
1071
+ ({ store, repo }) =>
1072
+ requestNodeRestack({
1073
+ store,
1074
+ repo,
1075
+ slug: parsed.positionals[0]!,
1076
+ user: deps.processEnv?.USER?.trim() || deps.processEnv?.USERNAME?.trim() || 'operator',
1077
+ }),
1078
+ )
1079
+ deps.stdout(
1080
+ `restack requested for ${result.slug}${result.waiting ? '; waiting for normal safety gates' : ''}`,
1081
+ )
1082
+ return 0
1083
+ }
1084
+
1048
1085
  case 'abort': {
1049
1086
  const usage = 'usage: ab abort <slug> [--store <ref>]'
1050
1087
  const parsed = parseArgs(rest, { store: 'value' }, usage)