@defrex/autobuild 0.14.0 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/README.md +4 -2
  2. package/SPEC.md +654 -98
  3. package/docs/architecture.md +226 -5
  4. package/docs/assets/headline-wide.png +0 -0
  5. package/docs/configuration.md +112 -12
  6. package/docs/hosted-service.md +18 -0
  7. package/docs/integration-tree.md +117 -0
  8. package/docs/landing-policy.md +150 -0
  9. package/docs/mcp.md +24 -0
  10. package/docs/migration-1.0.md +68 -0
  11. package/docs/operator-api.md +19 -8
  12. package/docs/remote-store-protocol.md +30 -7
  13. package/docs/remote-ticket-protocol.md +26 -5
  14. package/docs/restacking.md +79 -0
  15. package/docs/setup.md +49 -6
  16. package/docs/ticket-dependencies.md +69 -0
  17. package/docs/ticket-migration.md +8 -0
  18. package/package.json +3 -3
  19. package/packages/core/src/cli/attention.ts +25 -2
  20. package/packages/core/src/cli/build-control.ts +65 -41
  21. package/packages/core/src/cli/context.ts +54 -2
  22. package/packages/core/src/cli/dashboard/actions.ts +6 -3
  23. package/packages/core/src/cli/dashboard/landing-display.ts +6 -0
  24. package/packages/core/src/cli/dashboard/live.ts +5 -0
  25. package/packages/core/src/cli/dashboard/model.ts +142 -18
  26. package/packages/core/src/cli/dashboard/poll.ts +15 -9
  27. package/packages/core/src/cli/dashboard/refresh.ts +176 -0
  28. package/packages/core/src/cli/dashboard/render.ts +78 -28
  29. package/packages/core/src/cli/dashboard/repository-poll.ts +57 -0
  30. package/packages/core/src/cli/dashboard/selection.ts +7 -1
  31. package/packages/core/src/cli/dashboard/tree.ts +107 -0
  32. package/packages/core/src/cli/dispatch-frontend.ts +156 -109
  33. package/packages/core/src/cli/dispatch.ts +250 -136
  34. package/packages/core/src/cli/dispatcher-liveness.ts +15 -2
  35. package/packages/core/src/cli/help.ts +49 -32
  36. package/packages/core/src/cli/init-validation.ts +43 -2
  37. package/packages/core/src/cli/keyboard.ts +6 -0
  38. package/packages/core/src/cli/landings.ts +18 -0
  39. package/packages/core/src/cli/main.ts +49 -15
  40. package/packages/core/src/cli/mcp.ts +9 -0
  41. package/packages/core/src/cli/publication-settlement.ts +168 -2
  42. package/packages/core/src/cli/repository-status.ts +11 -0
  43. package/packages/core/src/cli/status.ts +72 -5
  44. package/packages/core/src/cli/terminal-restore.ts +54 -0
  45. package/packages/core/src/cli/terminal.ts +16 -2
  46. package/packages/core/src/cli/terminals.ts +98 -79
  47. package/packages/core/src/cli/ticket-editor.ts +10 -3
  48. package/packages/core/src/cli/ticket.ts +113 -18
  49. package/packages/core/src/cli/upgrade-commit.ts +4 -0
  50. package/packages/core/src/cli/upgrade-compatibility.ts +2 -2
  51. package/packages/core/src/cli/upgrade-landing.ts +69 -0
  52. package/packages/core/src/cli/upgrade.ts +16 -0
  53. package/packages/core/src/cli/wait.ts +115 -19
  54. package/packages/core/src/cli/watch.ts +51 -12
  55. package/packages/core/src/config/landing.ts +22 -0
  56. package/packages/core/src/config/live.ts +1 -0
  57. package/packages/core/src/config/schema.ts +3 -0
  58. package/packages/core/src/events/catalog.ts +48 -3
  59. package/packages/core/src/events/payloads.ts +295 -6
  60. package/packages/core/src/events/repository.ts +31 -0
  61. package/packages/core/src/integration/harness.ts +10 -0
  62. package/packages/core/src/kernel/__snapshots__/reducer-registry.test.ts.snap +1030 -239
  63. package/packages/core/src/kernel/auto-merge-default.ts +1 -0
  64. package/packages/core/src/kernel/auto-merge.ts +12 -3
  65. package/packages/core/src/kernel/build-identity.ts +94 -0
  66. package/packages/core/src/kernel/change-presence.ts +179 -0
  67. package/packages/core/src/kernel/dispatch-status.ts +17 -1
  68. package/packages/core/src/kernel/engine.ts +89 -2
  69. package/packages/core/src/kernel/generators/build-log.ts +23 -0
  70. package/packages/core/src/kernel/generators/leaf-restack-log.ts +110 -0
  71. package/packages/core/src/kernel/generators/node-restack-log.ts +94 -0
  72. package/packages/core/src/kernel/generators/repository-journals.ts +11 -0
  73. package/packages/core/src/kernel/integration-completeness.ts +81 -0
  74. package/packages/core/src/kernel/integration-landing.ts +263 -0
  75. package/packages/core/src/kernel/integration-stack.ts +36 -0
  76. package/packages/core/src/kernel/integration-state.ts +135 -0
  77. package/packages/core/src/kernel/landing-policy.ts +47 -0
  78. package/packages/core/src/kernel/landing-publication.ts +41 -0
  79. package/packages/core/src/kernel/landing-readiness.ts +67 -0
  80. package/packages/core/src/kernel/landing-state.ts +96 -0
  81. package/packages/core/src/kernel/leaf-restack-completion.ts +24 -0
  82. package/packages/core/src/kernel/leaf-restack-state.ts +73 -0
  83. package/packages/core/src/kernel/log-index.ts +35 -5
  84. package/packages/core/src/kernel/node-landing.ts +439 -0
  85. package/packages/core/src/kernel/node-parent.ts +184 -0
  86. package/packages/core/src/kernel/node-restack-state.ts +191 -0
  87. package/packages/core/src/kernel/node-restack-transaction.ts +210 -0
  88. package/packages/core/src/kernel/node-restack.ts +274 -0
  89. package/packages/core/src/kernel/read-facts.ts +70 -3
  90. package/packages/core/src/kernel/reconcile-head.ts +51 -0
  91. package/packages/core/src/kernel/reconcile-restack.ts +560 -0
  92. package/packages/core/src/kernel/reducer-registry.ts +16 -0
  93. package/packages/core/src/kernel/reducer.ts +121 -6
  94. package/packages/core/src/kernel/snapshot-parent.ts +33 -0
  95. package/packages/core/src/ontology.ts +9 -1
  96. package/packages/core/src/operator/annotations.ts +12 -0
  97. package/packages/core/src/operator/control.ts +6 -0
  98. package/packages/core/src/operator/index.ts +4 -0
  99. package/packages/core/src/operator/landings.ts +35 -0
  100. package/packages/core/src/operator/presentation.ts +1 -0
  101. package/packages/core/src/operator/protocol.ts +12 -3
  102. package/packages/core/src/operator/query.ts +3 -1
  103. package/packages/core/src/operator/registry.ts +48 -19
  104. package/packages/core/src/operator/requests.ts +1 -8
  105. package/packages/core/src/operator/tickets.ts +55 -9
  106. package/packages/core/src/ports/forge/contract.ts +91 -3
  107. package/packages/core/src/ports/forge/fake.ts +142 -4
  108. package/packages/core/src/ports/forge/git-rewrite.ts +232 -0
  109. package/packages/core/src/ports/forge/github-readiness.ts +421 -0
  110. package/packages/core/src/ports/forge/github.ts +631 -35
  111. package/packages/core/src/ports/forge/local-git.ts +119 -5
  112. package/packages/core/src/ports/forge/readiness.ts +99 -0
  113. package/packages/core/src/ports/tickets/contract.ts +41 -0
  114. package/packages/core/src/ports/tickets/create.ts +8 -1
  115. package/packages/core/src/ports/tickets/fake.ts +32 -1
  116. package/packages/core/src/ports/tickets/file-codec.ts +7 -0
  117. package/packages/core/src/ports/tickets/file.ts +18 -1
  118. package/packages/core/src/ports/tickets/hosted-index.ts +2 -0
  119. package/packages/core/src/ports/tickets/linear.ts +124 -4
  120. package/packages/core/src/ports/tickets/migration.ts +25 -1
  121. package/packages/core/src/ports/tickets/operations.ts +7 -2
  122. package/packages/core/src/ports/tickets/remote-protocol.ts +19 -0
  123. package/packages/core/src/ports/tickets/remote.ts +10 -1
  124. package/packages/core/src/ports/tickets/revision.ts +3 -1
  125. package/packages/core/src/ports/tickets/tree.ts +148 -0
  126. package/packages/core/src/ports/tickets/update.ts +15 -2
  127. package/packages/core/src/ports/types.ts +135 -5
  128. package/packages/core/src/ports/workspace/git-worktree.ts +2 -1
  129. package/packages/core/src/ports/workspace/provider-capabilities.ts +1 -1
  130. package/packages/core/src/ports/workspace/vercel-sandbox.ts +60 -3
  131. package/packages/core/src/processes/build-runner.ts +530 -23
  132. package/packages/core/src/processes/dispatcher-selectors.ts +15 -9
  133. package/packages/core/src/processes/dispatcher.ts +2145 -203
  134. package/packages/core/src/processes/execution-no-progress.ts +46 -1
  135. package/packages/core/src/processes/publication-state.ts +30 -5
  136. package/packages/core/src/processes/repo-view.ts +21 -2
  137. package/packages/core/src/store/build-scope.ts +18 -0
  138. package/packages/core/src/store/contract.ts +658 -0
  139. package/packages/core/src/store/digest.ts +52 -4
  140. package/packages/core/src/store/local/schema.ts +25 -13
  141. package/packages/core/src/store/local/store.ts +117 -1
  142. package/packages/core/src/store/memory.ts +62 -1
  143. package/packages/core/src/store/phase-session.ts +17 -0
  144. package/packages/core/src/store/reduced-reads.ts +2 -1
  145. package/packages/core/src/store/reducer-value-shapes.json +10707 -6440
  146. package/packages/core/src/store/remote/client.ts +44 -0
  147. package/packages/core/src/store/remote/compatibility.ts +19 -9
  148. package/packages/core/src/store/remote/protocol.ts +11 -0
  149. package/packages/core/src/store/repo-state-events.ts +2 -0
  150. package/packages/core/src/store/session-handle.ts +15 -0
  151. package/packages/core/src/store/subscribe.ts +1 -1
  152. package/packages/core/src/store/types.ts +32 -4
  153. package/packages/core/src/testing/index.ts +2 -0
  154. package/packages/core/src/testing/reduced-read-budget.ts +48 -8
  155. package/packages/core/src/testing/refresh-scheduler.ts +32 -0
  156. package/skills/guide/SKILL.md +110 -61
  157. package/skills/guide/references/integration-tree.md +117 -0
  158. package/skills/guide/references/landing-policy.md +150 -0
  159. package/skills/guide/references/migration-1.0.md +68 -0
  160. package/skills/guide/references/operator-api.md +12 -5
  161. package/skills/guide/references/plugin-authoring.md +34 -0
  162. package/skills/guide/references/remote-store-protocol.md +30 -7
  163. package/skills/guide/references/remote-ticket-protocol.md +26 -5
  164. package/skills/guide/references/restacking.md +79 -0
  165. package/skills/guide/references/setup.md +49 -6
  166. package/skills/guide/references/ticket-dependencies.md +69 -0
  167. package/skills/guide/references/ticket-migration.md +8 -0
  168. package/skills/operate/SKILL.md +55 -5
  169. package/skills/reconcile/SKILL.md +55 -48
  170. package/skills/spec/SKILL.md +67 -1
  171. package/skills/tickets/SKILL.md +55 -2
  172. package/templates/autobuild.toml +3 -0
@@ -1,3 +1,5 @@
1
+ import { migrateLandingPolicy } from './upgrade-landing'
2
+ import type { StoreOpener } from './store-opening'
1
3
  /**
2
4
  * `ab upgrade` — the classic vendoring problem (SPEC §16.3, D11). `ab init`
3
5
  * recorded the pristine bytes of every distributed skill file; upgrade
@@ -85,6 +87,7 @@ export type UpgradeSkillAction =
85
87
  | 'unknown'
86
88
 
87
89
  export interface UpgradeReport {
90
+ landing?: { changed: boolean; legacyDefault?: boolean }
88
91
  /** Per-skill content outcome, keyed by the namespaced install name. */
89
92
  skills: Array<{ skill: string; action: UpgradeSkillAction; detail?: string }>
90
93
  /** User-owned Claude entries that prevented discovery-link maintenance. */
@@ -537,6 +540,8 @@ export async function abUpgrade(opts: {
537
540
  targetRepo: string
538
541
  distRoot?: string
539
542
  exec?: Exec
543
+ openStore?: StoreOpener
544
+ env?: Record<string, string | undefined>
540
545
  resolveConflict?: ResolveConflict
541
546
  stdout?: (line: string) => void
542
547
  }): Promise<UpgradeReport> {
@@ -545,6 +550,16 @@ export async function abUpgrade(opts: {
545
550
  const stdout = opts.stdout ?? (() => {})
546
551
  const { targetRepo } = opts
547
552
 
553
+ const landing = await migrateLandingPolicy({
554
+ targetRepo,
555
+ exec,
556
+ openStore: opts.openStore,
557
+ env: opts.env,
558
+ })
559
+ if (landing.changed)
560
+ stdout(
561
+ `Landing policy migrated: legacy default ${landing.legacyDefault ? 'ON → leaf auto' : 'OFF → leaf consent'}; nodes consent. Configure [[landing]] rules to change it.`,
562
+ )
548
563
  await migrateLegacyAgentSkills(targetRepo)
549
564
 
550
565
  const skills: UpgradeReport['skills'] = []
@@ -881,6 +896,7 @@ export async function abUpgrade(opts: {
881
896
  }
882
897
 
883
898
  return {
899
+ landing,
884
900
  skills,
885
901
  discoveryConflicts,
886
902
  exitCode: discoveryConflicts.length > 0 ? 1 : 0,
@@ -1,3 +1,6 @@
1
+ import { awaitsConsent } from '../kernel/landing-readiness'
2
+ import { leafRestackReducer, type LeafRestackState } from '../kernel/leaf-restack-state'
3
+ import { consentReady, consentIdentity } from './attention'
1
4
  import { readBuildDigests } from '../store/reduced-reads'
2
5
  import { readBuildStreamSeed } from '../store/reduced-reads'
3
6
  import { buildStreamSeedReducer, type BuildStreamSeed } from '../kernel/read-facts'
@@ -73,13 +76,19 @@ export const WAIT_USAGE =
73
76
  /** Default poll cadence and wait horizon — identical to `ab watch`. */
74
77
  const DEFAULT_TIMEOUT_MS = 30 * 60 * 1000
75
78
 
76
- const NONTERMINAL_STATUSES: readonly BuildStatus[] = ['queued', 'running', 'paused', 'blocked']
79
+ const NONTERMINAL_STATUSES: readonly BuildStatus[] = [
80
+ 'queued',
81
+ 'running',
82
+ 'collecting',
83
+ 'paused',
84
+ 'blocked',
85
+ ]
77
86
  const TERMINAL_STATUSES: readonly BuildStatus[] = ['done', 'aborted']
78
87
 
79
88
  /** The `--for` condition vocabulary, in the order the help documents it. */
80
89
  const CONDITION_VOCABULARY =
81
- 'blocked, paused, running, done, aborted, terminal, pr=open, pr=merged, pr=closed, ' +
82
- 'pr=conflicted, phase=<phase> (a core phase or verify:<step>), attention'
90
+ 'blocked, paused, running, collecting, done, aborted, terminal, pr=open, pr=merged, pr=closed, ' +
91
+ 'consent, node-landed, restack-conflicted, pr=conflicted, phase=<phase> (a core phase or verify:<step>), attention'
83
92
 
84
93
  // ── Conditions ───────────────────────────────────────────────────────────────
85
94
 
@@ -89,6 +98,7 @@ type ConditionBody =
89
98
  | { kind: 'pr'; prState: PrLifecycle }
90
99
  | { kind: 'phase'; phase: Phase }
91
100
  | { kind: 'attention' }
101
+ | { kind: 'consent' | 'node-landed' | 'restack-conflicted' }
92
102
 
93
103
  interface WaitCondition {
94
104
  /** The original `--for` value — what a matching record's `condition` names. */
@@ -124,6 +134,8 @@ export function parseConditions(
124
134
  ` — ${WAIT_USAGE}`,
125
135
  )
126
136
  const conditions = forValues.map((value): WaitCondition => {
137
+ if (value === 'consent' || value === 'node-landed' || value === 'restack-conflicted')
138
+ return { text: value, cond: { kind: value } }
127
139
  if (value === 'terminal') return { text: value, cond: { kind: 'terminal' } }
128
140
  if (value === 'attention') return { text: value, cond: { kind: 'attention' } }
129
141
  if (value.startsWith('pr=')) {
@@ -148,6 +160,7 @@ export function parseConditions(
148
160
  status === 'blocked' ||
149
161
  status === 'paused' ||
150
162
  status === 'running' ||
163
+ status === 'collecting' ||
151
164
  status === 'done' ||
152
165
  status === 'aborted'
153
166
  ) {
@@ -162,7 +175,7 @@ export function parseConditions(
162
175
  }
163
176
 
164
177
  function attentionFrom(
165
- input: AbEvent[] | { state: BuildState; deferral: DeferralLedger },
178
+ input: AbEvent[] | { state: BuildState; deferral: DeferralLedger; restack?: LeafRestackState },
166
179
  state?: BuildState,
167
180
  ) {
168
181
  return Array.isArray(input)
@@ -178,8 +191,13 @@ function attentionFrom(
178
191
  function stateSatisfies(
179
192
  cond: ConditionBody,
180
193
  state: BuildState,
181
- events: AbEvent[] | { state: BuildState; deferral: DeferralLedger } = [],
194
+ events:
195
+ | AbEvent[]
196
+ | { state: BuildState; deferral: DeferralLedger; restack?: LeafRestackState } = [],
182
197
  ): boolean {
198
+ const restack = Array.isArray(events)
199
+ ? leafRestackReducer.reduce(events)
200
+ : (events.restack ?? { gates: {} })
183
201
  switch (cond.kind) {
184
202
  case 'status':
185
203
  return state.status === cond.status
@@ -189,8 +207,20 @@ function stateSatisfies(
189
207
  return state.prState === cond.prState
190
208
  case 'phase':
191
209
  return (state.phase ?? null) === cond.phase
210
+ case 'consent':
211
+ return awaitsConsent(state, restack)
212
+ case 'node-landed':
213
+ return !!state.integration?.landing
214
+ case 'restack-conflicted':
215
+ return !!state.nodeRestack?.conflict || !!(restack.active && restack.replay?.conflicted)
192
216
  case 'attention':
193
- return (state.openEscalations?.length ?? 0) > 0 || attentionFrom(events, state) !== null
217
+ return (
218
+ awaitsConsent(state, restack) ||
219
+ !!state.nodeRestack?.conflict ||
220
+ !!(restack.active && restack.replay?.conflicted) ||
221
+ (state.openEscalations?.length ?? 0) > 0 ||
222
+ attentionFrom(events, state) !== null
223
+ )
194
224
  }
195
225
  }
196
226
 
@@ -202,7 +232,9 @@ function stateSatisfies(
202
232
  export function matchState(
203
233
  conditions: readonly WaitCondition[],
204
234
  state: BuildState,
205
- events: AbEvent[] | { state: BuildState; deferral: DeferralLedger } = [],
235
+ events:
236
+ | AbEvent[]
237
+ | { state: BuildState; deferral: DeferralLedger; restack?: LeafRestackState } = [],
206
238
  ): string | null {
207
239
  for (const { text, cond } of conditions) {
208
240
  if (stateSatisfies(cond, state, events)) return text
@@ -214,15 +246,35 @@ export function matchState(
214
246
  * globs in supply order. Used on a cursor-resumed backlog, where state
215
247
  * conditions must not fire. */
216
248
  export function matchEvent(
217
- event: Pick<AbEvent, 'type'>,
249
+ event: Pick<AbEvent, 'type'> & { payload?: unknown },
218
250
  conditions: readonly WaitCondition[],
219
251
  globs: readonly EventGlob[],
220
- events: AbEvent[] | { state: BuildState; deferral: DeferralLedger } = [],
252
+ events:
253
+ | AbEvent[]
254
+ | { state: BuildState; deferral: DeferralLedger; restack?: LeafRestackState } = [],
221
255
  ): string | null {
222
256
  for (const { text, cond } of conditions) {
257
+ if (cond.kind === 'node-landed' && event.type === 'integration.landed') return text
258
+ if (
259
+ cond.kind === 'restack-conflicted' &&
260
+ (event.type === 'node.item-conflicted' ||
261
+ (event.type === 'restack.replayed' &&
262
+ (event.payload as { conflicted?: boolean })?.conflicted))
263
+ )
264
+ return text
265
+ if (
266
+ cond.kind === 'consent' &&
267
+ !Array.isArray(events) &&
268
+ awaitsConsent(events.state, events.restack ?? { gates: {} })
269
+ )
270
+ return text
223
271
  if (
224
272
  cond.kind === 'attention' &&
225
- (isAttentionEvent(event.type) || attentionFrom(events) !== null)
273
+ (isAttentionEvent(event.type) ||
274
+ (event.type === 'restack.replayed' &&
275
+ !!(event.payload as { conflicted?: boolean })?.conflicted) ||
276
+ (!Array.isArray(events) && stateSatisfies(cond, events.state, events)) ||
277
+ attentionFrom(events) !== null)
226
278
  )
227
279
  return text
228
280
  }
@@ -239,17 +291,37 @@ export function matchEvent(
239
291
  * original string becomes the record's `condition` field.
240
292
  */
241
293
  function matchFirst(
242
- event: Pick<AbEvent, 'type'>,
294
+ event: Pick<AbEvent, 'type'> & { payload?: unknown },
243
295
  state: BuildState,
244
296
  conditions: readonly WaitCondition[],
245
297
  globs: readonly EventGlob[],
246
- events: AbEvent[] | { state: BuildState; deferral: DeferralLedger } = [],
298
+ events:
299
+ | AbEvent[]
300
+ | { state: BuildState; deferral: DeferralLedger; restack?: LeafRestackState } = [],
247
301
  ): string | null {
248
302
  for (const { text, cond } of conditions) {
249
303
  if (stateSatisfies(cond, state, events)) return text
304
+ if (cond.kind === 'node-landed' && event.type === 'integration.landed') return text
305
+ if (
306
+ cond.kind === 'restack-conflicted' &&
307
+ (event.type === 'node.item-conflicted' ||
308
+ (event.type === 'restack.replayed' &&
309
+ (event.payload as { conflicted?: boolean })?.conflicted))
310
+ )
311
+ return text
312
+ if (
313
+ cond.kind === 'consent' &&
314
+ !Array.isArray(events) &&
315
+ awaitsConsent(events.state, events.restack ?? { gates: {} })
316
+ )
317
+ return text
250
318
  if (
251
319
  cond.kind === 'attention' &&
252
- (isAttentionEvent(event.type) || attentionFrom(events) !== null)
320
+ (isAttentionEvent(event.type) ||
321
+ (event.type === 'restack.replayed' &&
322
+ !!(event.payload as { conflicted?: boolean })?.conflicted) ||
323
+ (!Array.isArray(events) && stateSatisfies(cond, events.state, events)) ||
324
+ attentionFrom(events) !== null)
253
325
  )
254
326
  return text
255
327
  }
@@ -375,11 +447,17 @@ export async function abWait(opts: AbWaitOpts): Promise<number> {
375
447
  * exactly one condition-satisfying record; the exit-2 record carries
376
448
  * `condition` null so the caller can see how the build ended. */
377
449
  const finish = (condition: string | null, event: AbEvent, state: BuildState): number => {
450
+ const seed = streams.get(event.build)!.seed
451
+ const consent =
452
+ condition === 'consent' || condition === 'attention' ? consentReady(seed, now()) : null
378
453
  const observation =
379
- condition === 'attention' && event.type !== 'escalation.raised'
380
- ? mergeDecisionFromFacts(state, streams.get(event.build)!.seed.deferral, now())
381
- : null
382
- if (observation) deliveredAttention.add(mergeIdentity(event.build, observation.pr.number))
454
+ consent ??
455
+ (condition === 'attention' && event.type !== 'escalation.raised'
456
+ ? mergeDecisionFromFacts(state, seed.deferral, now())
457
+ : null)
458
+ if (consent) deliveredAttention.add(consentIdentity(event.build, consent.position))
459
+ else if (observation && 'pr' in observation)
460
+ deliveredAttention.add(mergeIdentity(event.build, observation.pr.number))
383
461
  const record = {
384
462
  ...(observation
385
463
  ? projectAttentionRecord(observation, state, encodeCurrent(), { build: event.build })
@@ -411,7 +489,18 @@ export async function abWait(opts: AbWaitOpts): Promise<number> {
411
489
  }
412
490
 
413
491
  const eventConditions = (event: AbEvent, seed: BuildStreamSeed): readonly WaitCondition[] => {
414
- if (event.type === 'escalation.raised') return conditions
492
+ if (
493
+ event.type === 'escalation.raised' ||
494
+ event.type === 'integration.landed' ||
495
+ event.type === 'node.item-conflicted' ||
496
+ (event.type === 'restack.replayed' && event.payload.conflicted)
497
+ )
498
+ return conditions
499
+ if (
500
+ seed.consentEpisode &&
501
+ !deliveredAttention.has(consentIdentity(event.build, seed.consentEpisode.seq))
502
+ )
503
+ return conditions
415
504
  const observation = mergeDecisionFromFacts(
416
505
  buildReducer.finish(seed.build),
417
506
  seed.deferral,
@@ -446,7 +535,11 @@ export async function abWait(opts: AbWaitOpts): Promise<number> {
446
535
  * latest event. Not cursor-relative — `--since` does not suppress it. */
447
536
  const checkRegistrationState = (stream: WaitStream): void => {
448
537
  const state = buildReducer.finish(stream.seed.build)
449
- const condition = matchState(conditions, state, { state, deferral: stream.seed.deferral })
538
+ const condition = matchState(conditions, state, {
539
+ state,
540
+ deferral: stream.seed.deferral,
541
+ restack: stream.seed.restack,
542
+ })
450
543
  if (condition !== null && state.lastEvent !== undefined) {
451
544
  match(state.lastEvent!, state, condition)
452
545
  }
@@ -480,6 +573,7 @@ export async function abWait(opts: AbWaitOpts): Promise<number> {
480
573
  const condition = matchEvent(event, eventConditions(event, stream.seed), globs, {
481
574
  state,
482
575
  deferral: stream.seed.deferral,
576
+ restack: stream.seed.restack,
483
577
  })
484
578
  if (condition !== null) {
485
579
  match(event, state, condition)
@@ -493,6 +587,7 @@ export async function abWait(opts: AbWaitOpts): Promise<number> {
493
587
  const condition = matchState(conditions, latest, {
494
588
  state: latest,
495
589
  deferral: current.value.deferral,
590
+ restack: current.value.restack,
496
591
  })
497
592
  if (condition !== null && latest.lastEvent) {
498
593
  stream.seed = current.value
@@ -545,6 +640,7 @@ export async function abWait(opts: AbWaitOpts): Promise<number> {
545
640
  const condition = matchFirst(event, state, eventConditions(event, stream.seed), globs, {
546
641
  state,
547
642
  deferral: stream.seed.deferral,
643
+ restack: stream.seed.restack,
548
644
  })
549
645
  if (condition !== null) {
550
646
  match(event, state, condition)
@@ -1,3 +1,5 @@
1
+ import { consentReady, consentIdentity, type ConsentReady } from './attention'
2
+ import { formatReadinessFailure } from '../ports/forge/readiness'
1
3
  import { readBuildDigests } from '../store/reduced-reads'
2
4
  import { readBuildStreamSeed, readRepositoryAttention } from '../store/reduced-reads'
3
5
  import { buildStreamSeedReducer, type BuildStreamSeed } from '../kernel/read-facts'
@@ -85,7 +87,13 @@ const DEFAULT_TIMEOUT_MS = 30 * 60 * 1000
85
87
  const REPO_STREAM_KEY = '#repo'
86
88
 
87
89
  /** Statuses a build can still leave; the others are terminal (§15.5). */
88
- const NONTERMINAL_STATUSES: readonly BuildStatus[] = ['queued', 'running', 'paused', 'blocked']
90
+ const NONTERMINAL_STATUSES: readonly BuildStatus[] = [
91
+ 'queued',
92
+ 'running',
93
+ 'collecting',
94
+ 'paused',
95
+ 'blocked',
96
+ ]
89
97
  const TERMINAL_STATUSES: readonly BuildStatus[] = ['done', 'aborted']
90
98
 
91
99
  // ── The default filter: the attention set ────────────────────────────────────
@@ -95,7 +103,11 @@ const TERMINAL_STATUSES: readonly BuildStatus[] = ['done', 'aborted']
95
103
  * a watch emits exactly these — deciding what to do about a blocker or a
96
104
  * merge stays with the caller's skill.
97
105
  */
98
- export const BUILD_ATTENTION_EVENTS = ['escalation.raised'] as const satisfies readonly EventType[]
106
+ export const BUILD_ATTENTION_EVENTS = [
107
+ 'escalation.raised',
108
+ 'integration.landed',
109
+ 'node.item-conflicted',
110
+ ] as const satisfies readonly EventType[]
99
111
 
100
112
  // ── Glob compilation and matching ────────────────────────────────────────────
101
113
 
@@ -140,11 +152,17 @@ function validAttentionIdentity(id: unknown): boolean {
140
152
  const value: unknown = JSON.parse(id)
141
153
  return (
142
154
  Array.isArray(value) &&
143
- value.length === 2 &&
144
- typeof value[0] === 'string' &&
145
- value[0].length > 0 &&
146
- Number.isSafeInteger(value[1]) &&
147
- value[1] > 0
155
+ ((value.length === 3 &&
156
+ value[0] === 'consent' &&
157
+ typeof value[1] === 'string' &&
158
+ value[1].length > 0 &&
159
+ Number.isSafeInteger(value[2]) &&
160
+ value[2] > 0) ||
161
+ (value.length === 2 &&
162
+ typeof value[0] === 'string' &&
163
+ value[0].length > 0 &&
164
+ Number.isSafeInteger(value[1]) &&
165
+ value[1] > 0))
148
166
  )
149
167
  } catch {
150
168
  return false
@@ -299,12 +317,12 @@ export interface AttentionObservationRecord {
299
317
  repo?: string
300
318
  build: string | null
301
319
  state: WatchRecordState | null
302
- observation: MergeDecision | PersistenceObservation
320
+ observation: MergeDecision | PersistenceObservation | ConsentReady
303
321
  cursor: string
304
322
  }
305
323
 
306
324
  export function projectAttentionRecord(
307
- observation: MergeDecision | PersistenceObservation,
325
+ observation: MergeDecision | PersistenceObservation | ConsentReady,
308
326
  state: BuildState | null,
309
327
  cursor: string,
310
328
  scope: { build: string } | { repo: string },
@@ -319,7 +337,7 @@ export function projectAttentionRecord(
319
337
  }
320
338
 
321
339
  export function renderAttentionLine(
322
- observation: MergeDecision | PersistenceObservation,
340
+ observation: MergeDecision | PersistenceObservation | ConsentReady,
323
341
  label: string,
324
342
  ): string {
325
343
  return `${observation.observedAt} ${singleLine(label)} ${observation.type} ${singleLine(JSON.stringify(observation))}`
@@ -434,6 +452,8 @@ export function summarizeEvent(event: AbEvent | RepositoryEvent, state: BuildSta
434
452
  return `ticket source ${event.payload.source} recovered: ${event.payload.cause} (${event.payload.operation})`
435
453
  case 'dispatcher.tick-failed':
436
454
  return `dispatcher tick failed: ${singleLine(event.payload.error)}`
455
+ case 'dispatcher.forge-readiness-failed':
456
+ return singleLine(formatReadinessFailure(event.payload))
437
457
  case 'dispatcher.config-rejected':
438
458
  return `dispatcher config rejected: ${singleLine(event.payload.error)}`
439
459
  case 'dispatcher.harvest-runner-failed':
@@ -650,7 +670,7 @@ export async function abWatch(opts: AbWatchOpts): Promise<void> {
650
670
  }
651
671
 
652
672
  const emitObservation = (
653
- observation: MergeDecision | PersistenceObservation,
673
+ observation: MergeDecision | PersistenceObservation | ConsentReady,
654
674
  state: BuildState | null,
655
675
  scope: { build: string } | { repo: string },
656
676
  identity: string,
@@ -669,6 +689,17 @@ export async function abWatch(opts: AbWatchOpts): Promise<void> {
669
689
  requestStop()
670
690
  }
671
691
  }
692
+ const checkConsent = (stream: BuildStream): void => {
693
+ if (filters.length || stop) return
694
+ const observation = consentReady(stream.seed, now())
695
+ if (observation)
696
+ emitObservation(
697
+ observation,
698
+ buildReducer.finish(stream.seed.build),
699
+ { build: stream.slug },
700
+ consentIdentity(stream.slug, observation.position),
701
+ )
702
+ }
672
703
  const checkPersistence = (): void => {
673
704
  if (filters.length || !attentionInitialized || stop) return
674
705
  for (const { identity, observation } of repositoryAttention.pending(now())) {
@@ -750,7 +781,12 @@ export async function abWatch(opts: AbWatchOpts): Promise<void> {
750
781
  stream.seed = buildStreamSeedReducer.advance(stream.seed, [event])
751
782
  const state = buildReducer.finish(stream.seed.build)
752
783
  stream.status = state.status
753
- if (matchesBuildFilter(event.type, filters)) emit(event, state)
784
+ if (
785
+ matchesBuildFilter(event.type, filters) ||
786
+ (!filters.length && event.type === 'restack.replayed' && event.payload.conflicted)
787
+ )
788
+ emit(event, state)
789
+ checkConsent(stream)
754
790
  if (!filters.length && !stop) {
755
791
  const observation = mergeDecisionFromFacts(state, stream.seed.deferral, now())
756
792
  if (observation)
@@ -809,6 +845,7 @@ export async function abWatch(opts: AbWatchOpts): Promise<void> {
809
845
  if (stop) break
810
846
  }
811
847
  }
848
+ checkConsent(stream)
812
849
  return true
813
850
  }
814
851
 
@@ -851,6 +888,8 @@ export async function abWatch(opts: AbWatchOpts): Promise<void> {
851
888
  streams.set(record.slug, stream)
852
889
  baselineMerge(record.slug, current.value)
853
890
  positions[record.slug] = stream.lastSeq
891
+ checkConsent(stream)
892
+ if (stop) break
854
893
  }
855
894
  }
856
895
 
@@ -0,0 +1,22 @@
1
+ import { z } from 'zod'
2
+
3
+ /** Ordered dispatcher-owned policy; omitted predicates are wildcards. */
4
+ export const landingRuleSchema = z.strictObject({
5
+ into: z
6
+ .string()
7
+ .refine(
8
+ (value) => value.trim().length > 0,
9
+ 'into must be root, node, or a nonblank node ticket id',
10
+ )
11
+ .optional(),
12
+ from: z.enum(['leaf', 'node']).optional(),
13
+ label: z
14
+ .string()
15
+ .refine(
16
+ (value) => value.trim().length > 0,
17
+ 'label must be nonblank (labels match exactly, including case)',
18
+ )
19
+ .optional(),
20
+ mode: z.enum(['auto', 'consent']),
21
+ })
22
+ export type LandingRule = z.infer<typeof landingRuleSchema>
@@ -19,6 +19,7 @@ export const CONFIG_RELOAD_CLASSIFICATION = {
19
19
  forge: 'restart',
20
20
  plugins: 'restart',
21
21
  pr: 'hot',
22
+ landing: 'hot',
22
23
  workspace: {
23
24
  provider: 'restart',
24
25
  config: 'restart',
@@ -12,6 +12,8 @@
12
12
  * validated.
13
13
  */
14
14
  import { z } from 'zod'
15
+ import { landingRuleSchema } from './landing'
16
+ export { landingRuleSchema, type LandingRule } from './landing'
15
17
  import { normalizeServiceURL } from '../connection'
16
18
  import { prImageHostSchema } from '../ontology'
17
19
  import { SANDBOX_FORBIDDEN_ENV } from '../ports/workspace/operator-sandbox'
@@ -825,6 +827,7 @@ const configRootSchema = z.strictObject({
825
827
  .refine((value) => value.trim().length > 0, 'plugin module specifiers must be nonblank'),
826
828
  )
827
829
  .default([]),
830
+ landing: z.array(landingRuleSchema).default([]),
828
831
  pr: prSchema.optional(),
829
832
  workspace: workspaceSchema.prefault({}),
830
833
  commands: commandsSchema,
@@ -40,6 +40,46 @@ export interface EventWrite<T extends EventType = EventType> {
40
40
  * catalog tables in SPEC §15.3.
41
41
  */
42
42
  export const allowedActorKinds: Record<EventType, readonly ActorKind[]> = {
43
+ 'landing.decided': ['dispatcher', 'kernel'],
44
+ 'build.hold-requested': ['human'],
45
+ 'build.land-requested': ['human'],
46
+ 'landing.command-acknowledged': ['dispatcher', 'kernel'],
47
+ 'landing.native-enable-started': ['dispatcher'],
48
+ 'landing.forge-merged': ['kernel'],
49
+ 'landing.native-applied': ['dispatcher', 'kernel'],
50
+ 'target.moved': ['dispatcher', 'kernel'],
51
+ 'restack.prepared': ['kernel', 'dispatcher'],
52
+ 'restack.replayed': ['kernel', 'dispatcher'],
53
+ 'restack.publish-intended': ['kernel', 'dispatcher'],
54
+ 'restack.rewritten': ['kernel', 'dispatcher'],
55
+ 'restack.contended': ['kernel', 'dispatcher'],
56
+ 'restack.completed': ['kernel', 'dispatcher'],
57
+ 'integration.abandoned': ['kernel', 'dispatcher'],
58
+ 'integration.observed': ['kernel', 'dispatcher'],
59
+ 'integration.prepared': ['kernel', 'dispatcher'],
60
+ 'integration.landing-intended': ['kernel', 'dispatcher'],
61
+ 'integration.landed': ['kernel', 'dispatcher'],
62
+ 'integration.audited': ['kernel', 'dispatcher'],
63
+ 'node.parent-requested': ['dispatcher', 'human'],
64
+ 'node.parent-accepted': ['dispatcher', 'human'],
65
+ 'node.parent-pr-retargeted': ['dispatcher', 'human'],
66
+ 'node.parent-completed': ['dispatcher', 'human'],
67
+ 'node.parent-cancelled': ['dispatcher', 'human'],
68
+ 'node.parent-rejection-cleared': ['dispatcher', 'human'],
69
+ 'node.parent-rejected': ['dispatcher', 'human'],
70
+ 'node.opening': ['dispatcher'],
71
+ 'node.writer-reserved': ['kernel', 'dispatcher'],
72
+ 'node.item-prepared': ['kernel', 'dispatcher'],
73
+ 'node.item-replayed': ['kernel', 'dispatcher'],
74
+ 'node.item-conflicted': ['kernel', 'dispatcher'],
75
+ 'node.publish-intended': ['kernel', 'dispatcher'],
76
+ 'node.rewritten': ['kernel', 'dispatcher'],
77
+ 'node.writer-settled': ['kernel', 'dispatcher'],
78
+ 'node.contribution-recorded': ['kernel', 'dispatcher'],
79
+ 'node.inventory': ['kernel', 'dispatcher'],
80
+ 'node.opened': ['dispatcher'],
81
+ 'node.compared': ['dispatcher'],
82
+ 'pr.opened': ['dispatcher'],
43
83
  'build.created': ['dispatcher', 'human'],
44
84
  'build.completed': ['dispatcher'],
45
85
  'runner.attached': ['kernel'],
@@ -73,8 +113,8 @@ export const allowedActorKinds: Record<EventType, readonly ActorKind[]> = {
73
113
  'build.auto-merge-requested': ['human'],
74
114
  'build.auto-merge-cancelled': ['human'],
75
115
  'build.auto-merge-default-observed': ['dispatcher'],
76
- 'build.paused': ['kernel'],
77
- 'build.resumed': ['kernel'],
116
+ 'build.paused': ['kernel', 'dispatcher'],
117
+ 'build.resumed': ['kernel', 'dispatcher'],
78
118
  'build.aborted': ['kernel', 'dispatcher'],
79
119
 
80
120
  'spec.imported': ['dispatcher'],
@@ -111,7 +151,12 @@ export const allowedActorKinds: Record<EventType, readonly ActorKind[]> = {
111
151
  'pr.conflicted': ['dispatcher'],
112
152
  'reconcile.progress-checked': ['kernel'],
113
153
  'reconcile.started': ['kernel'],
114
- 'reconcile.completed': ['agent', 'dispatcher'],
154
+ 'reconcile.prepared': ['kernel'],
155
+ 'reconcile.contended': ['kernel', 'dispatcher'],
156
+ 'reconcile.replayed': ['kernel'],
157
+ 'reconcile.publish-intended': ['kernel'],
158
+ 'reconcile.rewritten': ['kernel', 'dispatcher'],
159
+ 'reconcile.completed': ['agent', 'dispatcher', 'kernel'],
115
160
 
116
161
  'observation.recorded': ['kernel', 'agent'],
117
162
  'escalation.raised': ['agent', 'kernel', 'dispatcher'],