@defrex/autobuild 0.13.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 (210) hide show
  1. package/README.md +5 -3
  2. package/SPEC.md +673 -99
  3. package/bin/ab-dispatch-kernel.ts +4 -6
  4. package/docs/architecture.md +322 -75
  5. package/docs/assets/headline-wide.png +0 -0
  6. package/docs/configuration.md +112 -12
  7. package/docs/hosted-service.md +20 -2
  8. package/docs/integration-tree.md +117 -0
  9. package/docs/landing-policy.md +150 -0
  10. package/docs/mcp.md +24 -0
  11. package/docs/migration-1.0.md +68 -0
  12. package/docs/operator-api.md +20 -9
  13. package/docs/remote-store-protocol.md +114 -9
  14. package/docs/remote-ticket-protocol.md +26 -5
  15. package/docs/restacking.md +79 -0
  16. package/docs/setup.md +49 -6
  17. package/docs/ticket-dependencies.md +69 -0
  18. package/docs/ticket-migration.md +8 -0
  19. package/package.json +4 -3
  20. package/packages/core/src/cli/attention.ts +40 -163
  21. package/packages/core/src/cli/build-control.ts +75 -55
  22. package/packages/core/src/cli/bulk-control.ts +3 -2
  23. package/packages/core/src/cli/context.ts +68 -78
  24. package/packages/core/src/cli/dashboard/actions.ts +6 -3
  25. package/packages/core/src/cli/dashboard/landing-display.ts +6 -0
  26. package/packages/core/src/cli/dashboard/live.ts +5 -0
  27. package/packages/core/src/cli/dashboard/model.ts +178 -40
  28. package/packages/core/src/cli/dashboard/poll.ts +15 -9
  29. package/packages/core/src/cli/dashboard/refresh.ts +176 -0
  30. package/packages/core/src/cli/dashboard/render.ts +78 -28
  31. package/packages/core/src/cli/dashboard/repository-poll.ts +57 -0
  32. package/packages/core/src/cli/dashboard/selection.ts +7 -1
  33. package/packages/core/src/cli/dashboard/tree.ts +107 -0
  34. package/packages/core/src/cli/dispatch-frontend.ts +173 -169
  35. package/packages/core/src/cli/dispatch-process.ts +14 -7
  36. package/packages/core/src/cli/dispatch-repository-feed.ts +196 -0
  37. package/packages/core/src/cli/dispatch.ts +397 -214
  38. package/packages/core/src/cli/dispatcher-liveness.ts +41 -21
  39. package/packages/core/src/cli/harvest.ts +71 -39
  40. package/packages/core/src/cli/help.ts +49 -32
  41. package/packages/core/src/cli/historical-build-state.ts +27 -0
  42. package/packages/core/src/cli/init-validation.ts +43 -2
  43. package/packages/core/src/cli/keyboard.ts +6 -0
  44. package/packages/core/src/cli/landings.ts +18 -0
  45. package/packages/core/src/cli/main.ts +52 -18
  46. package/packages/core/src/cli/mcp.ts +9 -0
  47. package/packages/core/src/cli/pr-attachments.ts +10 -13
  48. package/packages/core/src/cli/pr-summary-publication.ts +27 -60
  49. package/packages/core/src/cli/pr-summary.ts +43 -13
  50. package/packages/core/src/cli/publication-settlement.ts +177 -21
  51. package/packages/core/src/cli/repository-status.ts +49 -2
  52. package/packages/core/src/cli/status.ts +133 -36
  53. package/packages/core/src/cli/terminal-restore.ts +54 -0
  54. package/packages/core/src/cli/terminal.ts +16 -2
  55. package/packages/core/src/cli/terminals.ts +121 -219
  56. package/packages/core/src/cli/ticket-editor.ts +10 -3
  57. package/packages/core/src/cli/ticket.ts +115 -20
  58. package/packages/core/src/cli/upgrade-commit.ts +4 -0
  59. package/packages/core/src/cli/upgrade-compatibility.ts +2 -2
  60. package/packages/core/src/cli/upgrade-landing.ts +69 -0
  61. package/packages/core/src/cli/upgrade.ts +16 -0
  62. package/packages/core/src/cli/wait.ts +194 -91
  63. package/packages/core/src/cli/watch.ts +111 -109
  64. package/packages/core/src/config/landing.ts +22 -0
  65. package/packages/core/src/config/live.ts +1 -0
  66. package/packages/core/src/config/pipeline-source.ts +4 -3
  67. package/packages/core/src/config/schema.ts +3 -0
  68. package/packages/core/src/events/catalog.ts +48 -3
  69. package/packages/core/src/events/payloads.ts +295 -6
  70. package/packages/core/src/events/repository.ts +38 -3
  71. package/packages/core/src/integration/harness.ts +11 -2
  72. package/packages/core/src/kernel/__snapshots__/reducer-registry.test.ts.snap +3330 -119
  73. package/packages/core/src/kernel/auto-merge-default.ts +1 -0
  74. package/packages/core/src/kernel/auto-merge.ts +29 -4
  75. package/packages/core/src/kernel/build-identity.ts +94 -0
  76. package/packages/core/src/kernel/change-presence.ts +179 -0
  77. package/packages/core/src/kernel/dispatch-status.ts +17 -1
  78. package/packages/core/src/kernel/dispatcher-liveness.ts +10 -4
  79. package/packages/core/src/kernel/engine.ts +89 -2
  80. package/packages/core/src/kernel/generators/build-log.ts +23 -0
  81. package/packages/core/src/kernel/generators/leaf-restack-log.ts +110 -0
  82. package/packages/core/src/kernel/generators/node-restack-log.ts +94 -0
  83. package/packages/core/src/kernel/generators/repository-journals.ts +25 -3
  84. package/packages/core/src/kernel/harvest.ts +25 -23
  85. package/packages/core/src/kernel/integration-completeness.ts +81 -0
  86. package/packages/core/src/kernel/integration-landing.ts +263 -0
  87. package/packages/core/src/kernel/integration-stack.ts +36 -0
  88. package/packages/core/src/kernel/integration-state.ts +135 -0
  89. package/packages/core/src/kernel/landing-policy.ts +47 -0
  90. package/packages/core/src/kernel/landing-publication.ts +41 -0
  91. package/packages/core/src/kernel/landing-readiness.ts +67 -0
  92. package/packages/core/src/kernel/landing-state.ts +96 -0
  93. package/packages/core/src/kernel/leaf-restack-completion.ts +24 -0
  94. package/packages/core/src/kernel/leaf-restack-state.ts +73 -0
  95. package/packages/core/src/kernel/log-index-value.ts +38 -0
  96. package/packages/core/src/kernel/log-index.ts +35 -5
  97. package/packages/core/src/kernel/node-landing.ts +439 -0
  98. package/packages/core/src/kernel/node-parent.ts +184 -0
  99. package/packages/core/src/kernel/node-restack-state.ts +191 -0
  100. package/packages/core/src/kernel/node-restack-transaction.ts +210 -0
  101. package/packages/core/src/kernel/node-restack.ts +274 -0
  102. package/packages/core/src/kernel/read-facts.ts +704 -0
  103. package/packages/core/src/kernel/reconcile-head.ts +51 -0
  104. package/packages/core/src/kernel/reconcile-restack.ts +560 -0
  105. package/packages/core/src/kernel/reducer-registry.ts +153 -3
  106. package/packages/core/src/kernel/reducer.ts +121 -6
  107. package/packages/core/src/kernel/repository-attention.ts +179 -0
  108. package/packages/core/src/kernel/service-facts.ts +135 -0
  109. package/packages/core/src/kernel/snapshot-parent.ts +33 -0
  110. package/packages/core/src/kernel/terminal-guard.ts +133 -0
  111. package/packages/core/src/ontology.ts +9 -1
  112. package/packages/core/src/operator/annotations.ts +12 -0
  113. package/packages/core/src/operator/control.ts +11 -6
  114. package/packages/core/src/operator/index.ts +6 -0
  115. package/packages/core/src/operator/landings.ts +35 -0
  116. package/packages/core/src/operator/presentation.ts +1 -0
  117. package/packages/core/src/operator/protocol.ts +12 -3
  118. package/packages/core/src/operator/query.ts +40 -21
  119. package/packages/core/src/operator/read-view.ts +4 -13
  120. package/packages/core/src/operator/registry.ts +48 -19
  121. package/packages/core/src/operator/requests.ts +3 -22
  122. package/packages/core/src/operator/sandbox.ts +10 -9
  123. package/packages/core/src/operator/tickets.ts +57 -11
  124. package/packages/core/src/plugin-sdk/index.ts +13 -0
  125. package/packages/core/src/ports/forge/contract.ts +91 -3
  126. package/packages/core/src/ports/forge/fake.ts +142 -4
  127. package/packages/core/src/ports/forge/git-rewrite.ts +232 -0
  128. package/packages/core/src/ports/forge/github-readiness.ts +421 -0
  129. package/packages/core/src/ports/forge/github.ts +631 -35
  130. package/packages/core/src/ports/forge/local-git.ts +119 -5
  131. package/packages/core/src/ports/forge/readiness.ts +99 -0
  132. package/packages/core/src/ports/tickets/contract.ts +41 -0
  133. package/packages/core/src/ports/tickets/create.ts +8 -1
  134. package/packages/core/src/ports/tickets/fake.ts +32 -1
  135. package/packages/core/src/ports/tickets/file-codec.ts +7 -0
  136. package/packages/core/src/ports/tickets/file.ts +18 -1
  137. package/packages/core/src/ports/tickets/hosted-index.ts +2 -0
  138. package/packages/core/src/ports/tickets/linear.ts +124 -4
  139. package/packages/core/src/ports/tickets/migration.ts +25 -1
  140. package/packages/core/src/ports/tickets/operations.ts +7 -2
  141. package/packages/core/src/ports/tickets/remote-protocol.ts +19 -0
  142. package/packages/core/src/ports/tickets/remote.ts +10 -1
  143. package/packages/core/src/ports/tickets/revision.ts +3 -1
  144. package/packages/core/src/ports/tickets/tree.ts +148 -0
  145. package/packages/core/src/ports/tickets/update.ts +15 -2
  146. package/packages/core/src/ports/types.ts +135 -5
  147. package/packages/core/src/ports/workspace/git-worktree.ts +2 -1
  148. package/packages/core/src/ports/workspace/provider-capabilities.ts +1 -1
  149. package/packages/core/src/ports/workspace/vercel-sandbox.ts +60 -3
  150. package/packages/core/src/processes/build-child.ts +6 -6
  151. package/packages/core/src/processes/build-runner.ts +586 -87
  152. package/packages/core/src/processes/dispatch-failure-budget.ts +5 -4
  153. package/packages/core/src/processes/dispatcher-selectors.ts +15 -9
  154. package/packages/core/src/processes/dispatcher.ts +2239 -357
  155. package/packages/core/src/processes/execution-no-progress.ts +46 -1
  156. package/packages/core/src/processes/harvest-execution-state.ts +15 -9
  157. package/packages/core/src/processes/harvest-runner.ts +34 -70
  158. package/packages/core/src/processes/harvest.ts +38 -15
  159. package/packages/core/src/processes/infrastructure-failure-budget.ts +13 -15
  160. package/packages/core/src/processes/orchestrator-tick.ts +2 -2
  161. package/packages/core/src/processes/publication-loss.ts +35 -21
  162. package/packages/core/src/processes/publication-state.ts +30 -5
  163. package/packages/core/src/processes/repo-view.ts +244 -1130
  164. package/packages/core/src/processes/tick-publication.ts +110 -0
  165. package/packages/core/src/store/adapter.ts +23 -0
  166. package/packages/core/src/store/build-scope.ts +35 -0
  167. package/packages/core/src/store/contract.ts +909 -0
  168. package/packages/core/src/store/digest.ts +52 -4
  169. package/packages/core/src/store/local/schema.ts +26 -13
  170. package/packages/core/src/store/local/store.ts +296 -55
  171. package/packages/core/src/store/memory.ts +181 -30
  172. package/packages/core/src/store/phase-session.ts +34 -0
  173. package/packages/core/src/store/reduced-reads.ts +240 -0
  174. package/packages/core/src/store/reducer-value-shapes.json +18323 -0
  175. package/packages/core/src/store/reducer-value-validation.ts +96 -0
  176. package/packages/core/src/store/reducer-values.ts +145 -0
  177. package/packages/core/src/store/remote/client.ts +85 -0
  178. package/packages/core/src/store/remote/compatibility.ts +21 -9
  179. package/packages/core/src/store/remote/index.ts +19 -0
  180. package/packages/core/src/store/remote/protocol.ts +27 -0
  181. package/packages/core/src/store/remote/version.ts +3 -1
  182. package/packages/core/src/store/repo-state-events.ts +3 -1
  183. package/packages/core/src/store/repo-tick.ts +72 -0
  184. package/packages/core/src/store/session-handle.ts +34 -0
  185. package/packages/core/src/store/snapshots.ts +10 -0
  186. package/packages/core/src/store/subscribe.ts +1 -1
  187. package/packages/core/src/store/ticket-assets.ts +4 -4
  188. package/packages/core/src/store/types.ts +71 -6
  189. package/packages/core/src/testing/dispatch-read-budget.ts +215 -0
  190. package/packages/core/src/testing/index.ts +10 -0
  191. package/packages/core/src/testing/reduced-read-budget.ts +502 -0
  192. package/packages/core/src/testing/refresh-scheduler.ts +32 -0
  193. package/skills/guide/SKILL.md +116 -62
  194. package/skills/guide/references/integration-tree.md +117 -0
  195. package/skills/guide/references/landing-policy.md +150 -0
  196. package/skills/guide/references/migration-1.0.md +68 -0
  197. package/skills/guide/references/operator-api.md +13 -6
  198. package/skills/guide/references/plugin-authoring.md +34 -0
  199. package/skills/guide/references/remote-store-protocol.md +114 -9
  200. package/skills/guide/references/remote-ticket-protocol.md +26 -5
  201. package/skills/guide/references/restacking.md +79 -0
  202. package/skills/guide/references/setup.md +49 -6
  203. package/skills/guide/references/ticket-dependencies.md +69 -0
  204. package/skills/guide/references/ticket-migration.md +8 -0
  205. package/skills/operate/SKILL.md +55 -5
  206. package/skills/reconcile/SKILL.md +55 -48
  207. package/skills/spec/SKILL.md +67 -1
  208. package/skills/tickets/SKILL.md +55 -2
  209. package/templates/autobuild.toml +3 -0
  210. package/templates/hosted-service/package.json +2 -2
@@ -11,6 +11,7 @@
11
11
  * blobs, never code (D3: code travels through the Forge; events carry SHAs).
12
12
  */
13
13
  import { z } from 'zod'
14
+ import { landingRuleSchema } from '../config/landing'
14
15
  import {
15
16
  artifactRefSchema,
16
17
  buildOutcomeSchema,
@@ -34,6 +35,60 @@ import {
34
35
  type VerifyOutcome,
35
36
  } from '../ontology'
36
37
 
38
+ const gitOid = z.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/)
39
+ export const reconcileTransactionSchema = z.strictObject({
40
+ id: z.string().min(1),
41
+ attempt: z.number().int().positive(),
42
+ restackId: z.string().min(1).optional(),
43
+ branch: z.string().min(1),
44
+ oldHead: gitOid,
45
+ oldBase: gitOid,
46
+ targetBase: gitOid,
47
+ changeSha: gitOid,
48
+ workspaceHead: gitOid,
49
+ localBranchHead: gitOid,
50
+ })
51
+ export const leafRestackSchema = reconcileTransactionSchema.omit({ attempt: true }).extend({
52
+ trigger: z.enum(['verify-entry', 'awaiting-landing']),
53
+ cycle: z.number().int().nonnegative(),
54
+ observation: z.number().int().positive(),
55
+ message: z.string().min(1),
56
+ })
57
+ const archiveEntry = z.strictObject({
58
+ ref: z.string().startsWith('refs/autobuild/archive/'),
59
+ sha: gitOid,
60
+ })
61
+
62
+ export const landingCandidateSchema = z.strictObject({
63
+ head: z.string().min(1),
64
+ parent: z.string().min(1),
65
+ cycle: z.string().min(1),
66
+ })
67
+ const landingDecision = z.strictObject({
68
+ candidate: landingCandidateSchema,
69
+ from: z.enum(['leaf', 'node']),
70
+ into: z.discriminatedUnion('kind', [
71
+ z.strictObject({ kind: z.literal('root') }),
72
+ z.strictObject({ kind: z.literal('node'), ticket: z.string().min(1) }),
73
+ ]),
74
+ labels: z.array(z.string()),
75
+ mode: z.enum(['auto', 'consent']),
76
+ rule: z.union([
77
+ z.strictObject({ index: z.number().int().nonnegative(), snapshot: landingRuleSchema }),
78
+ z.strictObject({ default: z.literal(true) }),
79
+ ]),
80
+ })
81
+ const nodeParent = z.strictObject({
82
+ target: z.strictObject({ ticket: ticketRefSchema, build: z.string().min(1) }).nullable(),
83
+ branch: z.string().min(1),
84
+ })
85
+ const parentChange = z.strictObject({
86
+ id: z.string().min(1),
87
+ old: nodeParent,
88
+ next: nodeParent,
89
+ revision: z.string(),
90
+ })
91
+
37
92
  const empty = z.strictObject({})
38
93
  const reasonOnly = z.strictObject({ reason: z.string().optional() })
39
94
  /** Fan-out provenance shared by the auto-merge command facts: the repository
@@ -41,6 +96,7 @@ const reasonOnly = z.strictObject({ reason: z.string().optional() })
41
96
  * when one did. Per-build commands omit it. `{}` stays valid, so existing
42
97
  * producers and logs replay unchanged. */
43
98
  const autoMergeCommand = z.strictObject({
99
+ integrationConsent: z.literal(true).optional(),
44
100
  defaultSeq: z.number().int().positive().optional(),
45
101
  })
46
102
  /** A fan-out reconciliation marker: the repository seq of the newest
@@ -55,7 +111,7 @@ const autoMergeDefaultObserved = z.strictObject({
55
111
  })
56
112
  const round = z.number().int().positive()
57
113
  const attempt = z.number().int().positive()
58
- const dispatchStage = z.enum(['create', 'workspace', 'spec', 'comment', 'launch'])
114
+ const dispatchStage = z.enum(['create', 'workspace', 'spec', 'comment', 'branch', 'launch'])
59
115
  const infrastructureOperation = z.enum([
60
116
  'provision',
61
117
  'start',
@@ -142,6 +198,9 @@ const verifyStepSelectionSchema = z
142
198
  })
143
199
 
144
200
  const verifyCompletionBase = {
201
+ baseSha: gitOid.optional(),
202
+ headSha: gitOid.optional(),
203
+ restackId: z.string().min(1).optional(),
145
204
  step: z.string().min(1),
146
205
  attempt,
147
206
  }
@@ -229,6 +288,8 @@ export const eventPayloadSchemas = {
229
288
  ticket: ticketRefSchema,
230
289
  repo: z.string().min(1),
231
290
  baseBranch: z.string().min(1),
291
+ kind: z.enum(['work', 'node']).optional(),
292
+ target: z.strictObject({ ticket: ticketRefSchema, build: z.string().min(1) }).optional(),
232
293
  /** Claim-time auto-merge intent retained across dispatch recovery until the
233
294
  * ordinary human-authored command fact can be materialized. */
234
295
  autoMergeRequestedBy: z.string().min(1).optional(),
@@ -247,6 +308,148 @@ export const eventPayloadSchemas = {
247
308
  * and in historical logs. */
248
309
  assets: z.array(pinnedAssetSchema).optional(),
249
310
  }),
311
+ 'node.opening': z.strictObject({
312
+ branch: z.string().min(1),
313
+ parent: z.string().min(1),
314
+ sha: z.string().min(1),
315
+ }),
316
+ 'node.parent-requested': parentChange,
317
+ 'node.parent-accepted': parentChange,
318
+ 'node.parent-pr-retargeted': z.strictObject({ id: z.string().min(1), base: z.string().min(1) }),
319
+ 'node.parent-completed': z.strictObject({ id: z.string().min(1) }),
320
+ 'node.parent-cancelled': z.strictObject({ id: z.string().min(1), reason: z.string() }),
321
+ 'node.parent-rejection-cleared': z.strictObject({
322
+ revision: z.string(),
323
+ target: z.string().nullable(),
324
+ }),
325
+ 'node.parent-rejected': z.strictObject({
326
+ revision: z.string(),
327
+ target: z.string().nullable(),
328
+ reason: z.string(),
329
+ }),
330
+ 'node.opened': z.strictObject({ sha: z.string().min(1) }),
331
+ 'node.writer-reserved': z.strictObject({
332
+ id: z.string().min(1),
333
+ operation: z.enum(['restack', 'landing']),
334
+ expected: z.string().min(1),
335
+ parent: z.string().min(1),
336
+ oldBase: z.string().min(1),
337
+ source: z.string().min(1).optional(),
338
+ archive: z.string().min(1),
339
+ changes: z.array(
340
+ z.strictObject({
341
+ sha: z.string().min(1),
342
+ build: z.string().min(1).optional(),
343
+ mainline: z.literal(1).optional(),
344
+ }),
345
+ ),
346
+ upstreamBuilds: z.array(z.string()),
347
+ merges: z.array(
348
+ z.strictObject({
349
+ sha: z.string().min(1),
350
+ parent: z.string().min(1),
351
+ identities: z.array(z.string()),
352
+ build: z.string().optional(),
353
+ missing: z.array(z.string()),
354
+ }),
355
+ ),
356
+ }),
357
+ 'node.item-prepared': z.strictObject({
358
+ id: z.string().min(1),
359
+ index: z.number().int().nonnegative(),
360
+ base: z.string().min(1),
361
+ }),
362
+ 'node.item-replayed': z.strictObject({
363
+ id: z.string().min(1),
364
+ index: z.number().int().nonnegative(),
365
+ base: z.string().min(1),
366
+ head: z.string().min(1),
367
+ dropped: z.boolean(),
368
+ dropReason: z.enum(['upstream-identity', 'upstream-commit']).optional(),
369
+ }),
370
+ 'node.item-conflicted': z.strictObject({
371
+ id: z.string().min(1),
372
+ index: z.number().int().nonnegative(),
373
+ base: z.string().min(1),
374
+ }),
375
+ 'node.publish-intended': z.strictObject({ id: z.string().min(1), head: z.string().min(1) }),
376
+ 'node.rewritten': z.strictObject({
377
+ id: z.string().min(1),
378
+ previous: z.string().min(1),
379
+ head: z.string().min(1),
380
+ }),
381
+ 'node.writer-settled': z.strictObject({
382
+ id: z.string().min(1),
383
+ outcome: z.enum(['completed', 'contended', 'abandoned']),
384
+ actual: z.string().nullable().optional(),
385
+ }),
386
+ 'node.contribution-recorded': z.strictObject({
387
+ landing: z.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/),
388
+ head: z.string().min(1),
389
+ base: z.string().min(1),
390
+ identities: z.array(
391
+ z.string().regex(/^(?:build:[a-z0-9][a-z0-9-]*|foreign:[0-9a-f]{40}(?:[0-9a-f]{24})?)$/),
392
+ ),
393
+ }),
394
+ 'node.inventory': z.strictObject({
395
+ head: z.string().min(1),
396
+ builds: z.array(z.string()),
397
+ contributions: z.array(z.string()).optional(),
398
+ foreign: z.array(z.string()),
399
+ }),
400
+ 'integration.abandoned': z.strictObject({ id: z.string().min(1), reason: z.string().min(1) }),
401
+ 'integration.observed': z.strictObject({
402
+ openChildren: z.array(z.string()),
403
+ diagnostics: z.array(z.string()),
404
+ contributions: z.array(z.string()),
405
+ }),
406
+ 'integration.prepared': z.strictObject({
407
+ id: z.string().min(1),
408
+ head: z.string().min(1),
409
+ parent: z.string().min(1),
410
+ config: z.string().min(1),
411
+ }),
412
+ 'integration.landing-intended': z
413
+ .strictObject({
414
+ id: z.string().min(1),
415
+ cycle: z.string().min(1),
416
+ head: z.string().min(1),
417
+ parent: z.string().min(1),
418
+ commandSeq: z.number().int().positive().optional(),
419
+ decisionSeq: z.number().int().positive().optional(),
420
+ fenced: z.boolean(),
421
+ evidence: z.array(z.string()),
422
+ })
423
+ .refine(
424
+ (value) => value.commandSeq !== undefined || value.decisionSeq !== undefined,
425
+ 'landing intent requires decisionSeq or legacy commandSeq',
426
+ ),
427
+ 'integration.landed': z.strictObject({
428
+ operation: z.string().optional(),
429
+ head: z.string().min(1),
430
+ landed: z.string().min(1),
431
+ provenance: z.enum(['kernel', 'human']),
432
+ verified: z.boolean(),
433
+ fenced: z.boolean(),
434
+ }),
435
+ 'integration.audited': z.strictObject({
436
+ operation: z.string().min(1),
437
+ verifiedTree: z.string().min(1),
438
+ landedTree: z.string().min(1),
439
+ identities: z.array(z.string()),
440
+ }),
441
+ 'node.compared': z.strictObject({
442
+ parentSha: z.string().min(1),
443
+ headSha: z.string().min(1),
444
+ ahead: z.number().int().nonnegative(),
445
+ }),
446
+ 'pr.opened': z.strictObject({
447
+ pr: z.strictObject({
448
+ number: z.number().int().positive(),
449
+ url: z.string().min(1),
450
+ headSha: z.string().min(1),
451
+ }),
452
+ }),
250
453
  'build.completed': z.strictObject({ outcome: buildOutcomeSchema }),
251
454
  'runner.attached': z.strictObject({
252
455
  instance: z.string().min(1),
@@ -367,6 +570,12 @@ export const eventPayloadSchemas = {
367
570
  * The dispatcher settles the request only after the VM session and execution
368
571
  * lease are gone, then appends the ordinary phase completion fact. */
369
572
  'publication.requested': z.discriminatedUnion('operation', [
573
+ z.strictObject({
574
+ operation: z.literal('restack'),
575
+ branch: z.string().min(1),
576
+ sha: gitOid,
577
+ rewrite: leafRestackSchema.extend({ headSha: gitOid }),
578
+ }),
370
579
  z.strictObject({
371
580
  operation: z.literal('implement'),
372
581
  branch: z.string().min(1),
@@ -377,6 +586,7 @@ export const eventPayloadSchemas = {
377
586
  }),
378
587
  z.strictObject({
379
588
  operation: z.literal('reconcile'),
589
+ rewrite: reconcileTransactionSchema.extend({ conflicted: z.boolean() }).optional(),
380
590
  branch: z.string().min(1),
381
591
  sha: z.string().regex(/^[0-9a-f]{40,64}$/i),
382
592
  artifact: artifactRefSchema,
@@ -406,7 +616,7 @@ export const eventPayloadSchemas = {
406
616
  'publication.lost': z.strictObject({
407
617
  /** seq of the lost `publication.requested` event. */
408
618
  request: z.number().int().positive(),
409
- operation: z.enum(['implement', 'reconcile', 'finalize', 'finalize-step']),
619
+ operation: z.enum(['implement', 'reconcile', 'restack', 'finalize', 'finalize-step']),
410
620
  branch: z.string().min(1),
411
621
  sha: z.string().regex(/^[0-9a-f]{40,64}$/i),
412
622
  reason: z.string().trim().min(1),
@@ -433,6 +643,29 @@ export const eventPayloadSchemas = {
433
643
  'build.resume-requested': reasonOnly,
434
644
  'build.abort-requested': reasonOnly,
435
645
  'build.discard-requested': empty,
646
+ 'landing.decided': landingDecision,
647
+ 'build.hold-requested': empty,
648
+ 'build.land-requested': z.strictObject({ decisionSeq: z.number().int().positive() }),
649
+ 'landing.command-acknowledged': z.strictObject({ commandSeq: z.number().int().positive() }),
650
+ 'landing.native-enable-started': empty,
651
+ 'landing.forge-merged': z.strictObject({
652
+ classification: z.enum(['human', 'possible-stale-enable']),
653
+ overrodeHold: z.boolean(),
654
+ }),
655
+ 'landing.native-applied': z.strictObject({
656
+ retry: z
657
+ .strictObject({
658
+ attempt: z.number().int().positive(),
659
+ after: z.string().datetime(),
660
+ })
661
+ .optional(),
662
+ enableSeq: z.number().int().positive().optional(),
663
+ enabled: z.boolean(),
664
+ candidate: landingCandidateSchema.optional(),
665
+ decisionSeq: z.number().int().positive().optional(),
666
+ commandSeq: z.number().int().positive().optional(),
667
+ operation: z.string().min(1).optional(),
668
+ }),
436
669
  'build.auto-merge-requested': autoMergeCommand,
437
670
  'build.auto-merge-cancelled': autoMergeCommand,
438
671
  'build.auto-merge-default-observed': autoMergeDefaultObserved,
@@ -533,6 +766,9 @@ export const eventPayloadSchemas = {
533
766
 
534
767
  // ── Verify / finalize ──────────────────────────────────────────────────────
535
768
  'verify.started': z.strictObject({
769
+ baseSha: gitOid.optional(),
770
+ headSha: gitOid.optional(),
771
+ restackId: z.string().min(1).optional(),
536
772
  step: z.string().min(1),
537
773
  attempt,
538
774
  /** An answered escalation raised by this agent verifier returns to the
@@ -606,7 +842,10 @@ export const eventPayloadSchemas = {
606
842
  /** seq of the human auto-merge command this forge mutation applied. */
607
843
  commandSeq: z.number().int().positive(),
608
844
  }),
609
- 'pr.merged': z.strictObject({ sha: z.string().min(1) }),
845
+ 'pr.merged': z.strictObject({
846
+ sha: z.string().min(1),
847
+ buildTrailerPresent: z.boolean().optional(),
848
+ }),
610
849
  'pr.closed': empty,
611
850
  'pr.conflicted': z.strictObject({ baseSha: z.string().min(1) }),
612
851
  'reconcile.progress-checked': z.strictObject({
@@ -616,11 +855,49 @@ export const eventPayloadSchemas = {
616
855
  attempt,
617
856
  baseSha: z.string().min(1),
618
857
  }),
619
- 'reconcile.started': z.strictObject({ attempt, baseSha: z.string().min(1) }),
620
- 'reconcile.completed': z.strictObject({
621
- mergeCommit: z.string().min(1),
858
+ 'target.moved': z.strictObject({ branch: z.string().min(1), sha: gitOid }),
859
+ 'restack.prepared': leafRestackSchema,
860
+ 'restack.replayed': z.strictObject({ id: z.string().min(1), conflicted: z.boolean() }),
861
+ 'restack.publish-intended': leafRestackSchema.extend({ headSha: gitOid }),
862
+ 'restack.rewritten': leafRestackSchema.extend({
863
+ headSha: gitOid,
864
+ archives: z.array(archiveEntry),
865
+ observedHead: gitOid.nullable().optional(),
866
+ }),
867
+ 'restack.contended': z.strictObject({
868
+ id: z.string().min(1),
869
+ request: z.number().int().positive(),
870
+ actual: gitOid.nullable(),
871
+ }),
872
+ 'restack.completed': leafRestackSchema.extend({ headSha: gitOid }),
873
+ 'reconcile.started': z.strictObject({
874
+ attempt,
875
+ baseSha: z.string().min(1),
876
+ restackId: z.string().min(1).optional(),
877
+ }),
878
+ 'reconcile.prepared': reconcileTransactionSchema,
879
+ 'reconcile.contended': z.strictObject({
880
+ id: z.string().min(1),
881
+ request: z.number().int().positive(),
882
+ actual: gitOid.nullable(),
883
+ }),
884
+ 'reconcile.replayed': z.strictObject({ id: z.string().min(1), conflicted: z.boolean() }),
885
+ 'reconcile.publish-intended': reconcileTransactionSchema.extend({
886
+ headSha: gitOid,
887
+ conflicted: z.boolean(),
622
888
  artifact: artifactRefSchema,
623
889
  }),
890
+ 'reconcile.rewritten': reconcileTransactionSchema.extend({
891
+ headSha: gitOid,
892
+ /** Later readback when a successful CAS was overtaken before acknowledgement. */
893
+ observedHead: gitOid.nullable().optional(),
894
+ conflicted: z.boolean(),
895
+ archives: z.array(archiveEntry),
896
+ }),
897
+ 'reconcile.completed': z.union([
898
+ z.strictObject({ mergeCommit: z.string().min(1), artifact: artifactRefSchema }),
899
+ z.strictObject({ headSha: gitOid, rewriteId: z.string().min(1), artifact: artifactRefSchema }),
900
+ ]),
624
901
 
625
902
  // ── Cross-cutting ──────────────────────────────────────────────────────────
626
903
  'observation.recorded': z.strictObject({
@@ -673,6 +950,9 @@ export type EventPayload<T extends EventType> = z.infer<(typeof eventPayloadSche
673
950
 
674
951
  /** Canonical read shape shared by the reducer, engine, and query surfaces. */
675
952
  export interface NormalizedVerifyCompletion {
953
+ baseSha?: string
954
+ headSha?: string
955
+ restackId?: string
676
956
  step: string
677
957
  attempt: number
678
958
  outcome: VerifyOutcome
@@ -690,6 +970,9 @@ export function normalizeVerifyCompletion(
690
970
  ): NormalizedVerifyCompletion {
691
971
  if ('pass' in payload) {
692
972
  return {
973
+ baseSha: payload.baseSha,
974
+ headSha: payload.headSha,
975
+ restackId: payload.restackId,
693
976
  step: payload.step,
694
977
  attempt: payload.attempt,
695
978
  outcome: payload.pass ? 'pass' : 'fail',
@@ -698,6 +981,9 @@ export function normalizeVerifyCompletion(
698
981
  }
699
982
  if (payload.outcome === 'skipped') {
700
983
  return {
984
+ baseSha: payload.baseSha,
985
+ headSha: payload.headSha,
986
+ restackId: payload.restackId,
701
987
  step: payload.step,
702
988
  attempt: payload.attempt,
703
989
  outcome: 'skipped',
@@ -706,6 +992,9 @@ export function normalizeVerifyCompletion(
706
992
  }
707
993
  }
708
994
  return {
995
+ baseSha: payload.baseSha,
996
+ headSha: payload.headSha,
997
+ restackId: payload.restackId,
709
998
  step: payload.step,
710
999
  attempt: payload.attempt,
711
1000
  outcome: payload.outcome,
@@ -1,3 +1,4 @@
1
+ import { hardReadinessKeys } from '../ports/forge/readiness'
1
2
  /**
2
3
  * Repository-scoped event catalog. These events deliberately do not enter the
3
4
  * build event union: repository controls and harvest runs are not synthetic
@@ -406,14 +407,25 @@ export const dispatcherStatusEventPayloadSchemas = {
406
407
  run: dispatchRun.optional(),
407
408
  holder: z.string().min(1),
408
409
  }),
410
+ 'dispatcher.forge-readiness-failed': z.strictObject({
411
+ run: dispatchRun,
412
+ forge: z.string().min(1),
413
+ rootBranch: z.string().min(1),
414
+ check: z.enum(hardReadinessKeys),
415
+ detail: z.string().min(1),
416
+ remediation: z.string().min(1),
417
+ }),
409
418
  'dispatcher.config-rejected': z.strictObject({ run: dispatchRun, error: z.string().min(1) }),
410
419
  'dispatcher.config-publication-failed': z.strictObject({
411
420
  run: dispatchRun,
412
421
  error: z.string().min(1),
413
422
  }),
414
- /** Brackets the one unsafe-to-force dispatcher turn. A supervisor may kill
415
- * an unresponsive child only when no started turn remains open. */
416
- 'dispatcher.tick-started': z.strictObject({ run: dispatchRun }),
423
+ /** Recorded boundaries of meaningful turns. The repository tick observation
424
+ * protects active work from forced stop while these facts are buffered. */
425
+ 'dispatcher.tick-started': z.strictObject({
426
+ run: dispatchRun,
427
+ startedAt: z.iso.datetime().optional(),
428
+ }),
417
429
  'dispatcher.tick-completed': z.strictObject({
418
430
  run: dispatchRun,
419
431
  queued: z.number().int().nonnegative(),
@@ -421,6 +433,7 @@ export const dispatcherStatusEventPayloadSchemas = {
421
433
  * dispatcher child transported a display sample in its tick fact. */
422
434
  observations: z.number().int().nonnegative().optional(),
423
435
  counters: tickCountersSchema,
436
+ blockedDiagnostics: boundedDiagnostics.optional(),
424
437
  janitorDiagnostics: boundedDiagnostics,
425
438
  ticketDiagnostics: boundedDiagnostics,
426
439
  creationDiagnostics: boundedDiagnostics.optional(),
@@ -501,7 +514,26 @@ export const ticketSourceHealthEventPayloadSchemas = {
501
514
  }),
502
515
  } as const
503
516
 
517
+ /** Head-bound admission evidence. Historical observations remain append-only. */
518
+ export const changePresenceEventPayloadSchemas = {
519
+ 'change-presence.observed': z.strictObject({
520
+ branch: z.string().min(1),
521
+ destination: z.string().min(1),
522
+ head: z.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/),
523
+ evidence: z.string().min(1),
524
+ identities: z
525
+ .array(
526
+ z.string().regex(/^(?:build:[a-z0-9][a-z0-9-]*|foreign:[0-9a-f]{40}(?:[0-9a-f]{24})?)$/),
527
+ )
528
+ .refine(
529
+ (ids) => ids.every((id, index) => index === 0 || ids[index - 1]! < id),
530
+ 'identities must be sorted and unique',
531
+ ),
532
+ }),
533
+ } as const
534
+
504
535
  export const repositoryEventPayloadSchemas = {
536
+ ...changePresenceEventPayloadSchemas,
505
537
  ...ticketSourceHealthEventPayloadSchemas,
506
538
  ...harvestEventPayloadSchemas,
507
539
  ...orchestratorSandboxEventPayloadSchemas,
@@ -523,6 +555,7 @@ export const REPOSITORY_ATTENTION_EVENTS = [
523
555
  'dispatcher.ticket-source-recovered',
524
556
  'dispatcher.tick-failed',
525
557
  'dispatcher.config-rejected',
558
+ 'dispatcher.forge-readiness-failed',
526
559
  'dispatcher.harvest-runner-failed',
527
560
  ] as const satisfies readonly RepositoryEventType[]
528
561
  export type RepositoryEventPayload<T extends RepositoryEventType> = z.infer<
@@ -561,6 +594,7 @@ export type HarvestEventWrite<T extends HarvestEventType = HarvestEventType> =
561
594
  export const HARVEST_EVENT_TYPES = Object.keys(harvestEventPayloadSchemas) as HarvestEventType[]
562
595
 
563
596
  const allowedActorKinds: Record<RepositoryEventType, readonly ActorKind[]> = {
597
+ 'change-presence.observed': ['dispatcher', 'kernel'],
564
598
  'harvest.pause-requested': ['human'],
565
599
  'harvest.resume-requested': ['human'],
566
600
  'harvest.paused': ['kernel'],
@@ -600,6 +634,7 @@ const allowedActorKinds: Record<RepositoryEventType, readonly ActorKind[]> = {
600
634
  'dispatcher.run-stopped': ['dispatcher'],
601
635
  'dispatcher.tick-yielded': ['dispatcher'],
602
636
  'dispatcher.config-rejected': ['dispatcher'],
637
+ 'dispatcher.forge-readiness-failed': ['dispatcher'],
603
638
  'dispatcher.config-publication-failed': ['dispatcher'],
604
639
  'dispatcher.tick-started': ['dispatcher'],
605
640
  'dispatcher.tick-completed': ['dispatcher'],
@@ -1,3 +1,4 @@
1
+ import { gitRewrite } from '../ports/forge/git-rewrite'
1
2
  /**
2
3
  * End-to-end harness (SPEC §15.6 as LIVE scenarios, §8.7, §12, §15.7):
3
4
  * real components everywhere the seam matters.
@@ -337,7 +338,7 @@ async function repositoryReading(store: BuildStore, repo: string) {
337
338
  builds[slug] = { facts: await plainFacts(view, slug), state: await view.buildState(slug) }
338
339
  }
339
340
  return {
340
- journal: view.recordedJournal(),
341
+ journal: (await store.getRepo(repo)) === null ? [] : await store.getRepoStateEvents(repo),
341
342
  digests: [...(await view.getRepoBuildDigests(repo)).entries()].sort(([a], [b]) =>
342
343
  a.localeCompare(b),
343
344
  ),
@@ -360,7 +361,6 @@ export async function assertSnapshotEquivalence(store: BuildStore, repo: string)
360
361
  if (canonical(got) !== canonical(want)) {
361
362
  throw new Error(`snapshot-restored reading differs from full replay (${round})`)
362
363
  }
363
- await restoredView.persistSnapshots({ force: true })
364
364
  }
365
365
  // The operator routes derive from the same view: each response with
366
366
  // snapshots present equals the response with every snapshot deleted.
@@ -466,10 +466,19 @@ export async function makeHarness(opts: {
466
466
  // Ad-hoc scenario configs predating mandatory runtime defaults stay explicit
467
467
  // at the harness boundary rather than relying on production wiring.
468
468
  config.roles.default ??= { runtime: 'scripted' }
469
+ await git(['config', 'user.name', 'ab-e2e'], origin)
470
+ await git(['config', 'user.email', 'ab-e2e@example.invalid'], origin)
471
+ await git(['config', 'commit.gpgsign', 'false'], origin)
469
472
  const forge = new FakeForge({
470
473
  gatePresence: opts.gatePresence ?? 'present',
471
474
  ...(opts.pluginForge?.prAttachments === true ? { prAttachments: true } : {}),
472
475
  })
476
+ const recordPush = forge.pushBranch.bind(forge)
477
+ forge.pushBranch = async (cwd, branch) => {
478
+ await recordPush(cwd, branch)
479
+ await git(['push', '-q', 'origin', `HEAD:refs/heads/${branch}`], cwd)
480
+ }
481
+ forge.rewrite = gitRewrite(spawnExec, false)
473
482
  let selectedForge: Forge =
474
483
  opts.localGitForge === true ? new LocalGitForge({ repoRoot: origin }) : forge
475
484
  let plugins: PluginRegistry | undefined