@defrex/autobuild 1.4.2 → 1.6.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 (218) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +512 -101
  3. package/bin/ab-dispatch-kernel.ts +1 -0
  4. package/docs/accounts.md +9 -0
  5. package/docs/agent-runtimes.md +1 -0
  6. package/docs/answering-blocked-builds.md +7 -3
  7. package/docs/architecture.md +313 -130
  8. package/docs/assets/headline-wide.png +0 -0
  9. package/docs/build-store.md +33 -3
  10. package/docs/cli.md +2 -1
  11. package/docs/configuration-overview.md +9 -0
  12. package/docs/configuration.md +217 -106
  13. package/docs/dispatcher-hosting.md +19 -3
  14. package/docs/dispatcher.md +11 -6
  15. package/docs/glossary.md +1 -1
  16. package/docs/integration-overview.md +2 -2
  17. package/docs/integration-tree.md +91 -28
  18. package/docs/merge-policy.md +28 -9
  19. package/docs/operating.md +1 -1
  20. package/docs/operator-api.md +57 -20
  21. package/docs/operator-surfaces.md +1 -1
  22. package/docs/plugin-authoring.md +89 -8
  23. package/docs/remote-store-protocol.md +39 -11
  24. package/docs/remote-ticket-protocol.md +126 -12
  25. package/docs/restacking.md +24 -6
  26. package/docs/seams.md +2 -2
  27. package/docs/setup.md +19 -13
  28. package/docs/spec-standard.md +2 -1
  29. package/docs/ticket-dependencies.md +26 -8
  30. package/docs/ticket-migration.md +70 -7
  31. package/docs/ticket-sources.md +82 -5
  32. package/docs/tickets.md +34 -2
  33. package/docs/troubleshooting.md +3 -3
  34. package/docs/verification.md +5 -5
  35. package/docs/website.md +8 -0
  36. package/docs/workspaces.md +1 -1
  37. package/package.json +4 -3
  38. package/packages/core/src/accounts/hosted-readiness.ts +21 -0
  39. package/packages/core/src/cli/attention.ts +3 -0
  40. package/packages/core/src/cli/build-control.ts +36 -12
  41. package/packages/core/src/cli/connect.ts +9 -18
  42. package/packages/core/src/cli/context.ts +44 -0
  43. package/packages/core/src/cli/dashboard/configuration.ts +11 -0
  44. package/packages/core/src/cli/dashboard/model.ts +51 -11
  45. package/packages/core/src/cli/dashboard/poll.ts +14 -0
  46. package/packages/core/src/cli/dashboard/queue.ts +21 -0
  47. package/packages/core/src/cli/dashboard/render.ts +43 -22
  48. package/packages/core/src/cli/dispatch-frontend.ts +63 -30
  49. package/packages/core/src/cli/dispatch-mode.ts +35 -16
  50. package/packages/core/src/cli/dispatch-preflight.ts +4 -1
  51. package/packages/core/src/cli/dispatch-repository-feed.ts +40 -11
  52. package/packages/core/src/cli/dispatch-tickets.ts +47 -0
  53. package/packages/core/src/cli/dispatch-upgrade-controller.ts +3 -0
  54. package/packages/core/src/cli/dispatch.ts +522 -145
  55. package/packages/core/src/cli/help.ts +63 -24
  56. package/packages/core/src/cli/init-hosted-accounts.ts +54 -0
  57. package/packages/core/src/cli/init-readiness-remote.ts +16 -3
  58. package/packages/core/src/cli/init-validation.ts +144 -42
  59. package/packages/core/src/cli/issue-links.ts +67 -0
  60. package/packages/core/src/cli/main.ts +32 -15
  61. package/packages/core/src/cli/pr-summary-publication.ts +38 -7
  62. package/packages/core/src/cli/publication-settlement.ts +36 -24
  63. package/packages/core/src/cli/repo-lease.ts +225 -0
  64. package/packages/core/src/cli/repository-status.ts +203 -49
  65. package/packages/core/src/cli/status.ts +42 -4
  66. package/packages/core/src/cli/terminals.ts +37 -2
  67. package/packages/core/src/cli/ticket-editor.ts +20 -6
  68. package/packages/core/src/cli/ticket.ts +264 -46
  69. package/packages/core/src/cli/triage-count-sampler.ts +59 -0
  70. package/packages/core/src/cli/wait.ts +4 -1
  71. package/packages/core/src/cli/watch.ts +19 -4
  72. package/packages/core/src/config/live.ts +45 -4
  73. package/packages/core/src/config/load.ts +9 -0
  74. package/packages/core/src/config/pipeline-source.ts +6 -2
  75. package/packages/core/src/config/ready-assignee.ts +86 -0
  76. package/packages/core/src/config/schema.ts +202 -38
  77. package/packages/core/src/distribution-packaging.ts +1 -1
  78. package/packages/core/src/events/catalog.ts +7 -0
  79. package/packages/core/src/events/compatibility.ts +2 -1
  80. package/packages/core/src/events/payloads.ts +85 -0
  81. package/packages/core/src/events/policy.ts +10 -0
  82. package/packages/core/src/events/repository.ts +93 -28
  83. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +237 -230
  84. package/packages/core/src/kernel/build-identity.ts +12 -0
  85. package/packages/core/src/kernel/change-presence.ts +139 -6
  86. package/packages/core/src/kernel/dispatch-capacity.ts +189 -19
  87. package/packages/core/src/kernel/dispatch-status.ts +10 -1
  88. package/packages/core/src/kernel/dispatch-upgrade.ts +104 -5
  89. package/packages/core/src/kernel/engine.ts +17 -8
  90. package/packages/core/src/kernel/finalize-pr-rejection.ts +95 -0
  91. package/packages/core/src/kernel/generators/build-log.ts +9 -0
  92. package/packages/core/src/kernel/generators/repository-journals.ts +15 -1
  93. package/packages/core/src/kernel/harvest.ts +4 -1
  94. package/packages/core/src/kernel/incremental-fixtures.ts +1 -0
  95. package/packages/core/src/kernel/integration-completeness.ts +104 -17
  96. package/packages/core/src/kernel/integration-landing.ts +17 -0
  97. package/packages/core/src/kernel/integration-state.ts +17 -0
  98. package/packages/core/src/kernel/issue-keywords.ts +202 -0
  99. package/packages/core/src/kernel/janitor-failure.ts +96 -5
  100. package/packages/core/src/kernel/kernel-git.ts +87 -0
  101. package/packages/core/src/kernel/landing-readiness.ts +25 -17
  102. package/packages/core/src/kernel/leaf-restack-state.ts +4 -2
  103. package/packages/core/src/kernel/log-index.ts +1 -1
  104. package/packages/core/src/kernel/node-issue-links.ts +142 -0
  105. package/packages/core/src/kernel/node-landing.ts +2 -1
  106. package/packages/core/src/kernel/node-parent.ts +6 -0
  107. package/packages/core/src/kernel/node-restack-transaction.ts +2 -0
  108. package/packages/core/src/kernel/pr-summary.ts +24 -0
  109. package/packages/core/src/kernel/read-deferrals.ts +75 -12
  110. package/packages/core/src/kernel/read-facts.ts +32 -1
  111. package/packages/core/src/kernel/reconcile-restack.ts +1 -1
  112. package/packages/core/src/kernel/reducer-registry.ts +37 -2
  113. package/packages/core/src/kernel/reducer.ts +147 -5
  114. package/packages/core/src/kernel/ticket-preparation.ts +16 -0
  115. package/packages/core/src/kernel/verify-budget.ts +43 -0
  116. package/packages/core/src/operator/index.ts +3 -1
  117. package/packages/core/src/operator/presentation.ts +3 -0
  118. package/packages/core/src/operator/protocol.ts +38 -2
  119. package/packages/core/src/operator/query.ts +69 -29
  120. package/packages/core/src/operator/registry.ts +47 -26
  121. package/packages/core/src/operator/tickets.ts +77 -10
  122. package/packages/core/src/plugin-sdk/index.ts +13 -0
  123. package/packages/core/src/plugins/manifest.ts +1 -1
  124. package/packages/core/src/plugins/registry.ts +1 -0
  125. package/packages/core/src/ports/forge/contract.ts +69 -0
  126. package/packages/core/src/ports/forge/create.ts +5 -0
  127. package/packages/core/src/ports/forge/fake.ts +184 -3
  128. package/packages/core/src/ports/forge/git-rewrite.ts +4 -2
  129. package/packages/core/src/ports/forge/github.ts +175 -38
  130. package/packages/core/src/ports/forge/local-git.ts +14 -0
  131. package/packages/core/src/ports/forge/readiness.ts +10 -0
  132. package/packages/core/src/ports/forge-failure.ts +43 -0
  133. package/packages/core/src/ports/runner/claude.ts +7 -1
  134. package/packages/core/src/ports/runner/codex.ts +7 -2
  135. package/packages/core/src/ports/runner/native-cli-fixture.ts +2 -1
  136. package/packages/core/src/ports/runner/pi.ts +7 -1
  137. package/packages/core/src/ports/runner/runtime.ts +3 -0
  138. package/packages/core/src/ports/runner/start-prompt.ts +37 -0
  139. package/packages/core/src/ports/tickets/contract.ts +320 -7
  140. package/packages/core/src/ports/tickets/create.ts +89 -20
  141. package/packages/core/src/ports/tickets/fake.ts +18 -0
  142. package/packages/core/src/ports/tickets/file-codec.ts +20 -0
  143. package/packages/core/src/ports/tickets/file.ts +43 -1
  144. package/packages/core/src/ports/tickets/github-fake.ts +1123 -0
  145. package/packages/core/src/ports/tickets/github-issues.ts +431 -0
  146. package/packages/core/src/ports/tickets/github-validators.ts +194 -0
  147. package/packages/core/src/ports/tickets/github.ts +2029 -0
  148. package/packages/core/src/ports/tickets/hosted-index.ts +34 -3
  149. package/packages/core/src/ports/tickets/issue-links.ts +86 -0
  150. package/packages/core/src/ports/tickets/lifecycle.ts +60 -4
  151. package/packages/core/src/ports/tickets/linear.ts +66 -6
  152. package/packages/core/src/ports/tickets/migration.ts +290 -68
  153. package/packages/core/src/ports/tickets/operations.ts +98 -12
  154. package/packages/core/src/ports/tickets/priority.ts +55 -0
  155. package/packages/core/src/ports/tickets/remote-protocol.ts +195 -29
  156. package/packages/core/src/ports/tickets/remote.ts +188 -13
  157. package/packages/core/src/ports/tickets/revision.ts +22 -1
  158. package/packages/core/src/ports/tickets/states.ts +43 -0
  159. package/packages/core/src/ports/tickets/tree.ts +58 -12
  160. package/packages/core/src/ports/tickets/update.ts +12 -2
  161. package/packages/core/src/ports/types.ts +194 -9
  162. package/packages/core/src/ports/workspace/commit-preservation.ts +163 -25
  163. package/packages/core/src/ports/workspace/git-worktree.ts +6 -2
  164. package/packages/core/src/ports/workspace/harvest-execution.ts +4 -2
  165. package/packages/core/src/ports/workspace/vercel-sandbox.ts +121 -27
  166. package/packages/core/src/processes/build-runner.ts +101 -22
  167. package/packages/core/src/processes/dispatcher.ts +1046 -372
  168. package/packages/core/src/processes/execution-no-progress.ts +7 -0
  169. package/packages/core/src/processes/harvest-child.ts +4 -2
  170. package/packages/core/src/processes/harvest-execution-state.ts +104 -0
  171. package/packages/core/src/processes/harvest-runner.ts +263 -25
  172. package/packages/core/src/processes/harvest.ts +5 -8
  173. package/packages/core/src/processes/tick-publication.ts +12 -2
  174. package/packages/core/src/processes/ticket-scan-schedule.ts +78 -0
  175. package/packages/core/src/processes/workspace-preservation.ts +36 -1
  176. package/packages/core/src/runtime-identity.ts +10 -2
  177. package/packages/core/src/scenarios/harness.ts +149 -35
  178. package/packages/core/src/store/adapter.ts +7 -1
  179. package/packages/core/src/store/contract.ts +83 -2
  180. package/packages/core/src/store/digest.ts +32 -1
  181. package/packages/core/src/store/reduced-reads.ts +10 -0
  182. package/packages/core/src/store/reducer-value-shapes.json +4471 -3427
  183. package/packages/core/src/store/remote/protocol.ts +2 -0
  184. package/packages/core/src/store/remote/released-clients.json +22 -0
  185. package/packages/core/src/store/remote/released-reducer-values/1.5.0.json +26924 -0
  186. package/packages/core/src/store/remote/released-reducer-values/1.6.0.json +27173 -0
  187. package/packages/core/src/store/remote/released-reducer-values/index.ts +4 -0
  188. package/packages/core/src/store/repo-state-events.ts +2 -0
  189. package/packages/core/src/store/types.ts +5 -0
  190. package/packages/core/src/testing/dispatch-read-budget.ts +729 -123
  191. package/packages/core/src/testing/index.ts +18 -1
  192. package/packages/core/src/testing/presence-history.ts +79 -0
  193. package/packages/core/src/testing/reduced-read-budget.ts +1424 -33
  194. package/packages/core/src/testing/upgrade-generations.ts +77 -0
  195. package/skills/code-review/SKILL.md +4 -3
  196. package/skills/finalize/SKILL.md +18 -2
  197. package/skills/guide/SKILL.md +417 -143
  198. package/skills/guide/references/accounts.md +9 -0
  199. package/skills/guide/references/integration-tree.md +91 -28
  200. package/skills/guide/references/merge-policy.md +28 -9
  201. package/skills/guide/references/operator-api.md +57 -20
  202. package/skills/guide/references/plugin-authoring.md +89 -8
  203. package/skills/guide/references/remote-store-protocol.md +39 -11
  204. package/skills/guide/references/remote-ticket-protocol.md +126 -12
  205. package/skills/guide/references/restacking.md +24 -6
  206. package/skills/guide/references/setup.md +19 -13
  207. package/skills/guide/references/spec-standard.md +2 -1
  208. package/skills/guide/references/ticket-dependencies.md +26 -8
  209. package/skills/guide/references/ticket-migration.md +70 -7
  210. package/skills/harvest-review/SKILL.md +4 -3
  211. package/skills/implement/SKILL.md +20 -1
  212. package/skills/operate/SKILL.md +149 -35
  213. package/skills/plan/SKILL.md +1 -1
  214. package/skills/reconcile/SKILL.md +5 -4
  215. package/skills/spec/SKILL.md +15 -2
  216. package/skills/tickets/SKILL.md +116 -37
  217. package/templates/autobuild.toml +5 -0
  218. package/templates/hosted-service/package.json +2 -2
@@ -18,6 +18,7 @@ import { documentSchema, documentFields } from './reference-metadata'
18
18
  import { landingRuleSchema } from './landing'
19
19
  export { landingRuleSchema, type LandingRule } from './landing'
20
20
  import { normalizeServiceURL } from '../connection'
21
+ import { holdsState, ticketLifecycle } from '../ports/tickets/lifecycle'
21
22
  import { prImageHostSchema } from '../ontology'
22
23
  import { SANDBOX_FORBIDDEN_ENV } from '../ports/workspace/operator-sandbox'
23
24
  import {
@@ -28,6 +29,11 @@ import {
28
29
  import { defineEntry, openMap, ownEntries, parseEntry } from '../open-map'
29
30
  import { forwardIssues } from '../zod-issues'
30
31
  import { effectiveRuntimeReferences } from './roles'
32
+ import {
33
+ GITHUB_READY_ASSIGNEE,
34
+ LINEAR_READY_ASSIGNEE,
35
+ readyAssigneeUnsupported,
36
+ } from './ready-assignee'
31
37
 
32
38
  // ── Open maps ────────────────────────────────────────────────────────────────
33
39
 
@@ -380,7 +386,7 @@ export interface WorkspaceProviderConfigDeclaration {
380
386
  * carries EXACTLY ONE of `configSchema` / `configRefusalMessage`: when the
381
387
  * schema is absent, the declaration must carry `configRefusalMessage` for
382
388
  * nonempty provider config to be refused (the neither-key side is pinned by
383
- * the AUT-565 test in config.test.ts), and carrying BOTH is forbidden —
389
+ * the AUT-565 test in config.integration.test.ts), and carrying BOTH is forbidden —
384
390
  * `configSchema`'s superRefine checks `configRefusalMessage` first, so the
385
391
  * refusal branch would win and the schema would silently never apply (the
386
392
  * both-keys side is pinned by its sibling test). Providers absent from
@@ -723,8 +729,23 @@ export type RoleConfig = z.infer<typeof roleSchema>
723
729
 
724
730
  // ── [policy] ─────────────────────────────────────────────────────────────────
725
731
 
732
+ const DISPATCH_LEASE_PAIR_MESSAGE =
733
+ 'policy.dispatchLeaseTimeoutSeconds and policy.dispatchLeaseRenewalSeconds must be positive integers, with dispatchLeaseRenewalSeconds less than dispatchLeaseTimeoutSeconds'
734
+
726
735
  export const policySchema = z.strictObject({
727
736
  upgradeDrainSeconds: z.number().int().positive().default(900),
737
+ /** Repository dispatch lease lifetime without renewal (SPEC §12). */
738
+ dispatchLeaseTimeoutSeconds: z
739
+ .number()
740
+ .int(DISPATCH_LEASE_PAIR_MESSAGE)
741
+ .positive(DISPATCH_LEASE_PAIR_MESSAGE)
742
+ .default(60),
743
+ /** Interval between repository dispatch lease renewals; below the timeout. */
744
+ dispatchLeaseRenewalSeconds: z
745
+ .number()
746
+ .int(DISPATCH_LEASE_PAIR_MESSAGE)
747
+ .positive(DISPATCH_LEASE_PAIR_MESSAGE)
748
+ .default(20),
728
749
  /** Wall-clock bound for an agent phase session; roles may override it. */
729
750
  sessionBudgetSeconds: z.number().int().positive().default(3600),
730
751
  /** Same-finding survival threshold before auto-escalate (§10, §15.4). */
@@ -734,7 +755,7 @@ export const policySchema = z.strictObject({
734
755
  maxDispatchAttempts: z.number().int().positive().default(3),
735
756
  /** Consecutive workspace setup failures before human intervention is required. */
736
757
  maxSetupAttempts: z.number().int().positive().default(3),
737
- /** Consecutive provider lifecycle failures before recovery requires a human retry. */
758
+ /** Consecutive provider lifecycle failures before a setup-targeted escalation; a `retry` answer from any operator, agent or human, re-arms the budget. */
738
759
  maxInfrastructureAttempts: z.number().int().positive().default(3),
739
760
  maxReconcileAttempts: z.number().int().positive().default(3),
740
761
  /** converge's `maxRounds` for the review loops (SPEC §10). */
@@ -743,6 +764,7 @@ export const policySchema = z.strictObject({
743
764
  harvestThreshold: z.number().int().positive().default(5),
744
765
  /** Merged builds after the oldest observation that start harvest; zero disables drift. */
745
766
  janitorFailureAttentionSeconds: z.number().int().positive().default(600),
767
+ janitorFailureEscalationSeconds: z.number().int().positive().default(3600),
746
768
  nodeIdleAfterSeconds: z.number().int().positive().default(600),
747
769
  nodeIdlePollSeconds: z.number().int().positive().default(120),
748
770
  janitorBackoffMaxSeconds: z.number().int().positive().default(300),
@@ -752,26 +774,40 @@ export const policySchema = z.strictObject({
752
774
  documentFields(policySchema, {
753
775
  upgradeDrainSeconds:
754
776
  'Deadline for a retiring generation, relative to handoff start; hot-reloaded during drain.',
777
+ dispatchLeaseTimeoutSeconds:
778
+ "How long the repository dispatch lease survives without renewal. A dispatcher that stalls longer reclaims it on waking unless another run took it; a standby takes over a dead holder within this bound. A change takes effect at the dispatcher's next tick.",
779
+ dispatchLeaseRenewalSeconds:
780
+ 'Interval between repository dispatch lease renewals; adopted together with the timeout.',
755
781
  sessionBudgetSeconds:
756
782
  'Active-time bound for each build agent session unless its logical role overrides it. Native continuation retains the original ceiling; suspension does not consume it.',
757
783
  stallRounds: 'Escalate when the same review finding survives this many rounds.',
758
784
  maxVerifyAttempts: 'Bound failure-driven verify \u2192 implement retry cycles.',
759
- maxDispatchAttempts: 'Bound consecutive dispatch failures before human escalation.',
760
- maxSetupAttempts: 'Bound consecutive workspace setup failures before human escalation.',
785
+ maxDispatchAttempts:
786
+ 'Bound consecutive dispatch failures before a setup-targeted `dispatch-failure-limit` escalation.',
787
+ maxSetupAttempts:
788
+ 'Bound consecutive workspace setup failures before a setup-targeted policy escalation.',
761
789
  maxInfrastructureAttempts:
762
- 'Bound consecutive provision/start/wait/cleanup failures before a setup-targeted policy escalation; a human `retry` answer re-arms this budget.',
790
+ 'Bound consecutive provision/start/wait/cleanup failures before a setup-targeted policy escalation; a `retry` answer from your operator agent or you re-arms this budget.',
763
791
  maxReconcileAttempts:
764
792
  'Bound completed reconciles that leave the PR conflicted against an unchanged authoritative base. Moving-base races do not consume the bound.',
765
793
  maxReviewRounds:
766
794
  'Default bound for each plan/review and implement/review convergence loop. Your agent may replace it for one parked build loop and current spec revision with `ab answer --review-round-ceiling`; other builds are unaffected.',
767
795
  harvestThreshold: 'New unclaimed observation occurrences needed to start one harvest run.',
768
796
  janitorFailureAttentionSeconds: 'Consecutive janitor failure duration before build attention.',
797
+ janitorFailureEscalationSeconds:
798
+ 'Consecutive janitor failure duration before the build raises one escalation; the janitor keeps retrying.',
769
799
  nodeIdleAfterSeconds: 'Quiet period before opened integration nodes enter idle polling.',
770
800
  nodeIdlePollSeconds: 'Interval between idle node checks; durable activity wakes the next tick.',
771
801
  janitorBackoffMaxSeconds: 'Cap on exponential janitor retry delay, starting at 30 seconds.',
772
802
  harvestMaxDrift:
773
803
  'Other builds merged after the oldest unclaimed observation needed to start a run; `0` disables drift.',
774
804
  })
805
+ documentSchema(policySchema.shape.dispatchLeaseTimeoutSeconds, {
806
+ constraints: 'Must be greater than `dispatchLeaseRenewalSeconds`.',
807
+ })
808
+ documentSchema(policySchema.shape.dispatchLeaseRenewalSeconds, {
809
+ constraints: 'Must be less than `dispatchLeaseTimeoutSeconds`.',
810
+ })
775
811
  export type PolicyConfig = z.infer<typeof policySchema>
776
812
 
777
813
  // ── [tickets] ────────────────────────────────────────────────────────────────
@@ -796,8 +832,8 @@ export const ticketsInputSchema = z.strictObject({
796
832
  * (§3.3). A nonempty list is conjunctive: every configured label must be
797
833
  * present. For readyLabels = ["autobuild", "ready"], a ticket carrying only
798
834
  * "autobuild" does not satisfy the label gate. An explicit [] disables the
799
- * label gate; absent uses the ticket source's default (linear: ["autobuild"];
800
- * file: none). Resolved by readyCriteria in src/processes/dispatcher.ts.
835
+ * label gate; absent uses the ticket source's default (linear and github:
836
+ * ["autobuild"]; file: none). Resolved by readyCriteria in src/processes/dispatcher.ts.
801
837
  */
802
838
  readyLabels: z.array(z.string().min(1)).optional(),
803
839
  /**
@@ -819,20 +855,24 @@ export const ticketsInputSchema = z.strictObject({
819
855
  )
820
856
  .optional(),
821
857
  /**
822
- * Narrows readiness to tickets assigned to one Linear user — a third
823
- * conjunctive gate beside readyState and readyLabels. `"me"` is the owner of
824
- * the dispatcher's LINEAR_API_KEY; an email names a specific user (for a
825
- * shared or bot key). Unassigned tickets are never ready while it is set.
826
- * Linear only; absent leaves readiness unchanged.
858
+ * Narrows readiness to tickets assigned to one user — a third conjunctive
859
+ * gate beside readyState and readyLabels. A ticket-source capability: the
860
+ * source must declare `readyAssignee`, and it defines the value's forms.
861
+ * `"me"` is the owner of the source's credential (linear: LINEAR_API_KEY;
862
+ * github: the GitHub token); linear also takes an email, github a username.
863
+ * Unassigned tickets are never ready while it is set. Builtin forms are
864
+ * checked below; plugin declarations at the registry-aware seams
865
+ * (`config/ready-assignee.ts`). Absent leaves readiness unchanged.
827
866
  */
828
867
  readyAssignee: z
829
868
  .string()
830
869
  .refine(
831
- (s) => s === 'me' || (s === s.trim() && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s)),
832
- '[tickets].readyAssignee must be "me" (the owner of the API key) or a user email address (e.g. "person@example.com")',
870
+ (s) => s.trim().length > 0 && s === s.trim(),
871
+ '[tickets].readyAssignee must be a nonblank value with no surrounding whitespace',
833
872
  )
834
873
  .optional(),
835
- /** Backend team key (e.g. "ENG") — required for linear and hosted. */
874
+ /** Backend team key (e.g. "ENG") — required for linear and hosted;
875
+ * forbidden for github. */
836
876
  teamKey: z.string().min(1).optional(),
837
877
  /** Workflow state claim() moves an issue to (§12); Linear and hosted. */
838
878
  claimedState: z
@@ -875,6 +915,22 @@ export const ticketsInputSchema = z.strictObject({
875
915
  .min(1)
876
916
  .refine((value) => value.trim().length > 0, 'state must be nonblank')
877
917
  .optional(),
918
+ /** State that holds deliberately deferred work — the backlog role. Optional
919
+ * with no default: unset means the role does not exist. Never dispatched
920
+ * from, moved into, or harvested into by the dispatcher. */
921
+ backlogState: z
922
+ .string()
923
+ .min(1)
924
+ .refine((value) => value.trim().length > 0, 'state must be nonblank')
925
+ .optional(),
926
+ /** State that holds considered-and-declined work — the rejected role.
927
+ * Optional with no default. A ticket in it never resolves a blocker and
928
+ * never keeps a node incomplete. */
929
+ rejectedState: z
930
+ .string()
931
+ .min(1)
932
+ .refine((value) => value.trim().length > 0, 'state must be nonblank')
933
+ .optional(),
878
934
  /** Directory of state dirs (`triage/ ready/ doing/ done/`) holding `<id>.md`
879
935
  * ticket files; optional — defaults to `.autobuild/tickets`, resolved
880
936
  * relative to the repo. Kept schema-optional (not `.default()`) so the
@@ -889,7 +945,7 @@ documentFields(ticketsInputSchema, {
889
945
  readyLabels: 'Require every listed label in addition to the state gate.',
890
946
  readyState: 'The one workflow state eligible for dispatch.',
891
947
  readyAssignee:
892
- 'Require the ticket to be assigned to one Linear user, in addition to the state and label gates.',
948
+ 'Require the ticket to be assigned to one user, in addition to the state and label gates.',
893
949
  teamKey: 'Backend team key such as `"ENG"`, or an existing plugin config field.',
894
950
  claimedState: 'Workflow state entered when a ticket is claimed.',
895
951
  doneState: 'Project completion state and merged-ticket transition.',
@@ -897,50 +953,118 @@ documentFields(ticketsInputSchema, {
897
953
  triageState: 'State used for spec-gate bounces, aborts, and closed-unmerged PRs.',
898
954
  proposalState:
899
955
  'State harvest files its synthesized proposals into. Setting it to `readyState` waives the human grooming gate, not dependency eligibility.',
956
+ backlogState:
957
+ 'State that holds deliberately deferred work (the backlog role). Optional and recommended; unset means the role does not exist.',
958
+ rejectedState:
959
+ 'State that holds considered-and-declined work (the rejected role). A rejected ticket never resolves a blocker and never keeps a node incomplete. Optional and recommended.',
900
960
  dir: 'Root containing file-source state directories, or an existing plugin config field. Relative file paths resolve from the repository.',
901
961
  })
902
962
  documentSchema(ticketsInputSchema, {
903
963
  constraints:
904
- 'readyState is required except for hosted, which resolves omission to ready. url is forbidden for file and linear; hosted URLs are normalized service URLs.',
964
+ 'readyState is required except for hosted and github, which resolve omission to ready. url is forbidden for file, linear and github; hosted URLs are normalized service URLs.',
905
965
  })
906
966
  documentSchema(ticketsInputSchema.shape.readyState, {
907
- required: 'Required unless source = "hosted"; hosted omission resolves to "ready".',
967
+ required:
968
+ 'Required unless source = "hosted" or "github"; omission there resolves to "ready". GitHub states are `autobuild:<state>` labels.',
908
969
  })
909
970
  documentSchema(ticketsInputSchema.shape.teamKey, {
910
- required: 'Required for linear and hosted; forbidden for file; optional for plugins.',
971
+ required: 'Required for linear and hosted; forbidden for file and github; optional for plugins.',
911
972
  })
912
973
  documentSchema(ticketsInputSchema.shape.claimedState, { constraints: 'Forbidden for file.' })
913
- documentSchema(ticketsInputSchema.shape.dir, { constraints: 'Forbidden for linear and hosted.' })
914
- documentSchema(ticketsInputSchema.shape.readyAssignee, { constraints: 'Allowed only for linear.' })
974
+ documentSchema(ticketsInputSchema.shape.dir, {
975
+ constraints: 'Forbidden for linear, hosted and github.',
976
+ })
977
+ documentSchema(ticketsInputSchema.shape.readyAssignee, {
978
+ constraints:
979
+ 'Allowed for sources that can filter by assignee: linear ("me" or an email), github ("me" or a GitHub username, including managed-user logins such as mona_acme), and plugin sources that declare readyAssignee. Refused for file and hosted.',
980
+ })
915
981
  documentSchema(ticketsInputSchema.shape.readyLabels, {
916
982
  constraints:
917
- 'Omission uses source readiness defaults (Linear: autobuild label; file: none). Explicit [] disables label gating.',
983
+ 'Omission uses source readiness defaults (Linear and GitHub: autobuild label; file: none). Explicit [] disables label gating.',
918
984
  })
919
985
  documentSchema(ticketsInputSchema.shape.url, {
920
986
  constraints:
921
- 'Forbidden for file and linear. Hosted omission uses the selected remote BuildStore URL; with a local BuildStore an explicit hosted URL is required.',
987
+ 'Forbidden for file, linear and github. Hosted omission uses the selected remote BuildStore URL; with a local BuildStore an explicit hosted URL is required.',
922
988
  })
923
989
  documentSchema(ticketsInputSchema.shape.doneState, {
924
- constraints: 'Hosted resolution uses done when omitted.',
990
+ constraints:
991
+ 'Hosted and github resolution uses done when omitted. A github ticket is done when its issue is closed as completed.',
925
992
  })
926
993
  documentSchema(ticketsInputSchema.shape.claimedState, {
927
994
  constraints:
928
- 'Forbidden for file. Resolution uses In Progress for direct Linear, doing for hosted.',
995
+ 'Forbidden for file. Resolution uses In Progress for direct Linear, doing for hosted and github.',
929
996
  })
930
997
  documentSchema(ticketsInputSchema.shape.createState, {
931
- constraints: 'Omission uses the source creation state (Linear team default; file Triage).',
998
+ constraints:
999
+ 'Omission uses the source creation state (Linear team default; file Triage; github triage).',
932
1000
  })
933
1001
  documentSchema(ticketsInputSchema.shape.triageState, {
934
1002
  constraints:
935
- 'Omission resolves to Backlog for Linear, triage for hosted, Triage for file/plugin sources.',
1003
+ 'Omission resolves to Backlog for Linear, triage for hosted and github, Triage for file/plugin sources.',
936
1004
  })
937
1005
  documentSchema(ticketsInputSchema.shape.proposalState, {
938
1006
  constraints: 'Omission uses the resolved triageState.',
939
1007
  })
1008
+ documentSchema(ticketsInputSchema.shape.backlogState, {
1009
+ constraints:
1010
+ 'Optional for every source, no default; `ab init` writes it for new configurations. Must differ from the ready, claimed, done, triage and proposal states and from rejectedState (case-insensitive).',
1011
+ })
1012
+ documentSchema(ticketsInputSchema.shape.rejectedState, {
1013
+ constraints:
1014
+ 'Optional for every source, no default; `ab init` writes it for new configurations. On github it maps to an issue closed as not planned. Must differ from the ready, claimed, done, triage and proposal states and from backlogState (case-insensitive).',
1015
+ })
940
1016
  documentSchema(ticketsInputSchema.shape.dir, {
941
1017
  constraints:
942
- 'Forbidden for linear and hosted. File omission resolves to the selected local state root tickets directory; plugin omission remains omitted.',
1018
+ 'Forbidden for linear, hosted and github. File omission resolves to the selected local state root tickets directory; plugin omission remains omitted.',
943
1019
  })
1020
+ const FILE_CLAIMED_STATE = 'doing'
1021
+ const FILE_DONE_STATE = 'Done'
1022
+ const OPTIONAL_ROLES = [
1023
+ ['backlog', 'backlogState'],
1024
+ ['rejected', 'rejectedState'],
1025
+ ] as const
1026
+ const DISPATCHER_ROLES = [
1027
+ ['ready', 'readyState'],
1028
+ ['claimed', 'claimedState'],
1029
+ ['done', 'doneState'],
1030
+ ['triage', 'triageState'],
1031
+ ['proposal', 'proposalState'],
1032
+ ] as const
1033
+
1034
+ /** The backlog and rejected roles must hold their own states: the dispatcher
1035
+ * never claims from, moves into, or files proposals into them, whatever the
1036
+ * other lifecycle names say, and the two may not share a state. */
1037
+ function refuseOptionalRoleOverlap(tickets: TicketsConfig, ctx: z.RefinementCtx): void {
1038
+ const names = ticketLifecycle({ ...tickets, readyState: tickets.readyState ?? 'ready' })
1039
+ // The file source ignores claimedState and doneState: claims always move
1040
+ // into doing and completion is Done. Check the states it actually uses as
1041
+ // well as the configured spellings.
1042
+ const file = tickets.source === 'file'
1043
+ const resolved: Record<string, (string | undefined)[]> = {
1044
+ ready: [names.ready],
1045
+ claimed: file ? [FILE_CLAIMED_STATE, tickets.claimedState] : [names.doing],
1046
+ done: file ? [FILE_DONE_STATE, tickets.doneState] : [names.done],
1047
+ triage: [names.triage],
1048
+ proposal: [names.proposal],
1049
+ backlog: [names.backlog],
1050
+ rejected: [names.rejected],
1051
+ }
1052
+ for (const [index, [role, key]] of OPTIONAL_ROLES.entries()) {
1053
+ const name = tickets[key]
1054
+ if (name === undefined) continue
1055
+ const others = [...DISPATCHER_ROLES, ...OPTIONAL_ROLES.slice(index + 1)]
1056
+ for (const [other, otherKey] of others) {
1057
+ const held = resolved[other]?.find((state) => holdsState(name, state))
1058
+ if (held === undefined) continue
1059
+ ctx.addIssue({
1060
+ code: 'custom',
1061
+ path: [key],
1062
+ message: `[tickets].${key} "${name}" names the same state as the ${other} role ([tickets].${otherKey} resolves to "${held}"); the ${role} and ${other} roles must name different states`,
1063
+ })
1064
+ }
1065
+ }
1066
+ }
1067
+
944
1068
  export const ticketsSchema = ticketsInputSchema
945
1069
  .superRefine((tickets, ctx) => {
946
1070
  if (tickets.source === 'hosted' && tickets.url !== undefined) {
@@ -950,19 +1074,20 @@ export const ticketsSchema = ticketsInputSchema
950
1074
  ctx.addIssue({ code: 'custom', path: ['url'], message: (error as Error).message })
951
1075
  }
952
1076
  }
953
- if (tickets.source !== 'hosted' && tickets.readyState === undefined)
1077
+ if (!['hosted', 'github'].includes(tickets.source) && tickets.readyState === undefined)
954
1078
  ctx.addIssue({
955
1079
  code: 'custom',
956
1080
  path: ['readyState'],
957
1081
  message:
958
1082
  '[tickets].readyState is required — name the one workflow state a ticket must sit in to be dispatched (e.g. "ready").',
959
1083
  })
960
- if (['file', 'linear'].includes(tickets.source) && tickets.url !== undefined)
1084
+ if (['file', 'linear', 'github'].includes(tickets.source) && tickets.url !== undefined)
961
1085
  ctx.addIssue({
962
1086
  code: 'custom',
963
1087
  path: ['url'],
964
1088
  message: '[tickets].url applies only to source = "hosted"',
965
1089
  })
1090
+ refuseOptionalRoleOverlap(tickets as TicketsConfig, ctx)
966
1091
  })
967
1092
  .transform((tickets) => ({
968
1093
  ...tickets,
@@ -974,7 +1099,7 @@ export const ticketsSchema = ticketsInputSchema
974
1099
 
975
1100
  documentSchema(ticketsSchema, {
976
1101
  constraints:
977
- 'readyState is required except for hosted, whose omitted value resolves to ready. url is forbidden for file and linear; hosted URLs must be absolute HTTPS (loopback HTTP allowed), without credentials, query or fragment, and are normalized.',
1102
+ 'readyState is required except for hosted and github, whose omitted value resolves to ready. url is forbidden for file, linear and github; hosted URLs must be absolute HTTPS (loopback HTTP allowed), without credentials, query or fragment, and are normalized.',
978
1103
  })
979
1104
  export type TicketsConfig = z.infer<typeof ticketsSchema>
980
1105
 
@@ -1094,7 +1219,7 @@ documentFields(configRootSchema, {
1094
1219
  upgrade: 'Automatic dispatcher runtime target checks and adoption.',
1095
1220
  baseBranch: 'Branch used to cut builds, target PRs, and merge during reconciliation.',
1096
1221
  capacity:
1097
- 'Concurrent occupied slots for this repository. Paused and blocked work retains slots. Node reconcile and verification exclude their own blocked/paused descendants at admission; new claims use total occupancy. See [integration capacity](integration-tree.md).',
1222
+ 'Builds running work at once for this repository. A build that finished its pipeline holds no slot while it waits for a merge decision; it is admitted ahead of new claims when it must run again. Unfinished paused and blocked work retains slots. Node reconcile and verification exclude their own blocked/paused descendants at admission; new claims use total occupancy. See [integration capacity](integration-tree.md).',
1098
1223
  ticketScanIntervalSeconds:
1099
1224
  'Ticket-source ready scan cadence; tick spacing is the effective minimum.',
1100
1225
  forge:
@@ -1158,6 +1283,14 @@ const normalizedConfigSchema = configRootSchema.transform((input, ctx) => {
1158
1283
  })
1159
1284
 
1160
1285
  export const configSchema = normalizedConfigSchema.superRefine((config, ctx) => {
1286
+ const { dispatchLeaseTimeoutSeconds: leaseTimeout, dispatchLeaseRenewalSeconds: leaseRenewal } =
1287
+ config.policy
1288
+ if (leaseRenewal >= leaseTimeout)
1289
+ ctx.addIssue({
1290
+ code: 'custom',
1291
+ path: ['policy', 'dispatchLeaseRenewalSeconds'],
1292
+ message: `${DISPATCH_LEASE_PAIR_MESSAGE} (dispatchLeaseRenewalSeconds = ${leaseRenewal}, dispatchLeaseTimeoutSeconds = ${leaseTimeout})`,
1293
+ })
1161
1294
  for (const [name, account] of Object.entries(config.accounts)) {
1162
1295
  if (account.kind !== 'chatgpt-subscription') continue
1163
1296
  if (
@@ -1374,6 +1507,18 @@ export const configSchema = normalizedConfigSchema.superRefine((config, ctx) =>
1374
1507
  message: '[tickets].dir applies only to source = "file" — remove it or set source = "file"',
1375
1508
  })
1376
1509
  }
1510
+ } else if (tickets.source === 'github') {
1511
+ // The forge repository is the tracker: no team or directory. A service
1512
+ // url is refused with the other non-hosted sources in ticketsSchema.
1513
+ for (const key of ['teamKey', 'dir'] as const) {
1514
+ if (tickets[key] !== undefined) {
1515
+ ctx.addIssue({
1516
+ code: 'custom',
1517
+ path: ['tickets', key],
1518
+ message: `[tickets].${key} applies only to source = ${key === 'dir' ? '"file"' : '"linear" or "hosted"'} — remove it for source = "github"`,
1519
+ })
1520
+ }
1521
+ }
1377
1522
  } else if (tickets.source === 'file') {
1378
1523
  // dir is optional for the file source: absent = .autobuild/tickets.
1379
1524
  for (const key of ['teamKey', 'claimedState'] as const) {
@@ -1386,12 +1531,31 @@ export const configSchema = normalizedConfigSchema.superRefine((config, ctx) =>
1386
1531
  }
1387
1532
  }
1388
1533
  }
1389
- if (tickets.source !== 'linear' && tickets.readyAssignee !== undefined) {
1390
- ctx.addIssue({
1391
- code: 'custom',
1392
- path: ['tickets', 'readyAssignee'],
1393
- message: `[tickets].readyAssignee applies only to source = "linear" — remove it or select that source (selected source: "${tickets.source}")`,
1394
- })
1534
+ // readyAssignee is a source capability. Builtins are known here; a plugin
1535
+ // source passes parse and is checked against its declaration once
1536
+ // constructed (createTicketSource, LiveConfig reloads).
1537
+ const assignee = tickets.readyAssignee
1538
+ if (assignee !== undefined) {
1539
+ const form =
1540
+ tickets.source === 'linear'
1541
+ ? LINEAR_READY_ASSIGNEE
1542
+ : tickets.source === 'github'
1543
+ ? GITHUB_READY_ASSIGNEE
1544
+ : undefined
1545
+ if (tickets.source === 'file' || tickets.source === 'hosted') {
1546
+ ctx.addIssue({
1547
+ code: 'custom',
1548
+ path: ['tickets', 'readyAssignee'],
1549
+ message: readyAssigneeUnsupported(tickets.source),
1550
+ })
1551
+ } else if (
1552
+ form !== undefined &&
1553
+ assignee.trim().length > 0 &&
1554
+ assignee === assignee.trim() &&
1555
+ !form.accepts(assignee)
1556
+ ) {
1557
+ ctx.addIssue({ code: 'custom', path: ['tickets', 'readyAssignee'], message: form.message })
1558
+ }
1395
1559
  }
1396
1560
  // Plugin sources receive the existing ticket lifecycle/configuration fields
1397
1561
  // unchanged; adapter-specific validation belongs to their factory.
@@ -46,7 +46,7 @@ async function execOrThrow(
46
46
  * invariant, not a local detail: the `patchedDependencies` rule in
47
47
  * `tools/workspace-manifest-check.ts` rejects a root manifest whose packed
48
48
  * dependency set contains a patched package, and the negative control in
49
- * `packages/core/src/plugin-sdk/package.test.ts` (the packed-distribution
49
+ * `packages/core/src/plugin-sdk/package.integration.test.ts` (the packed-distribution
50
50
  * better-auth canary) pins the consumed-manifest failure shape this strip
51
51
  * guards, so removing the field from this list fails the suite loudly.
52
52
  *
@@ -47,6 +47,7 @@ export const allowedActorKinds: Record<EventType, readonly ActorKind[]> = {
47
47
  'build.janitor-attempt-failed': ['dispatcher'],
48
48
  'build.janitor-recovered': ['dispatcher'],
49
49
  'build.janitor-failing': ['dispatcher'],
50
+ 'build.janitor-escalated': ['dispatcher'],
50
51
  'landing.application-failed': ['dispatcher', 'kernel'],
51
52
  'landing.decided': ['dispatcher', 'kernel'],
52
53
  'build.hold-requested': ['human'],
@@ -56,6 +57,7 @@ export const allowedActorKinds: Record<EventType, readonly ActorKind[]> = {
56
57
  'landing.forge-merged': ['kernel'],
57
58
  'landing.native-applied': ['dispatcher', 'kernel'],
58
59
  'target.distance': ['dispatcher'],
60
+ 'pipeline.settled': ['dispatcher'],
59
61
  'target.rewritten': ['dispatcher', 'kernel'],
60
62
  'target.rewrite-cleared': ['dispatcher', 'kernel'],
61
63
  'target.moved': ['dispatcher', 'kernel'],
@@ -92,6 +94,8 @@ export const allowedActorKinds: Record<EventType, readonly ActorKind[]> = {
92
94
  'node.rewritten': ['kernel', 'dispatcher'],
93
95
  'node.writer-settled': ['kernel', 'dispatcher'],
94
96
  'node.contribution-recorded': ['kernel', 'dispatcher'],
97
+ 'node.issue-links-recorded': ['kernel', 'dispatcher'],
98
+ 'node.issue-links-published': ['kernel', 'dispatcher'],
95
99
  'node.inventory': ['kernel', 'dispatcher'],
96
100
  'node.opened': ['dispatcher'],
97
101
  'node.poll-checked': ['dispatcher'],
@@ -194,6 +198,8 @@ export const allowedActorKinds: Record<EventType, readonly ActorKind[]> = {
194
198
  'reconcile.rewritten': ['kernel', 'dispatcher'],
195
199
  'reconcile.completed': ['agent', 'dispatcher', 'kernel'],
196
200
 
201
+ 'issue-link.downgraded': ['agent'],
202
+ 'issue-links.sealed': ['kernel'],
197
203
  'observation.recorded': ['kernel', 'agent'],
198
204
  'escalation.raised': ['agent', 'kernel', 'dispatcher'],
199
205
  // Answering an escalation is always a deliberate human act. Historical
@@ -202,6 +208,7 @@ export const allowedActorKinds: Record<EventType, readonly ActorKind[]> = {
202
208
  'escalation.answered': ['human'],
203
209
  'phase.failed': ['kernel'],
204
210
  'session.build-read-failed': ['kernel'],
211
+ 'session.build-read-recovered': ['kernel'],
205
212
  'phase.deferred': ['kernel'],
206
213
  'phase.deferral-escalated': ['kernel'],
207
214
  }
@@ -24,7 +24,8 @@ export interface StoredEvent {
24
24
 
25
25
  /** Change this revision whenever projection semantics change without new types. */
26
26
  // Revision 3 retains optional billing-account descriptors in session/attempt projections.
27
- export const READ_DECODER_REVISION = 3
27
+ // Revision 4 retains the optional effective prompt in session projections.
28
+ export const READ_DECODER_REVISION = 4
28
29
  export function catalogIdentity(
29
30
  build: Record<string, string> = buildEventPolicy,
30
31
  repository: Record<string, string> = repositoryEventPolicy,
@@ -16,6 +16,7 @@ import { nativeSessionHandleSchema } from './native-session'
16
16
  */
17
17
  import { z } from 'zod'
18
18
  import { landingRuleSchema } from '../config/landing'
19
+ import { refineUniqueIssues } from '../ports/tickets/issue-links'
19
20
  import {
20
21
  artifactRefSchema,
21
22
  buildOutcomeSchema,
@@ -127,6 +128,8 @@ const autoMergeDefaultObserved = z.strictObject({
127
128
  defaultSeq: z.number().int().positive(),
128
129
  })
129
130
  const round = z.number().int().positive()
131
+ /** A forge issue number, shared by every issue-link fact. */
132
+ const issueNumber = z.number().int().positive().max(Number.MAX_SAFE_INTEGER)
130
133
  const attempt = z.number().int().positive()
131
134
  const dispatchStage = z.enum(['create', 'workspace', 'spec', 'comment', 'branch', 'launch'])
132
135
  const infrastructureOperation = z.enum([
@@ -332,6 +335,18 @@ export const eventPayloadSchemas = {
332
335
  /** Ticket assets frozen at claim time. Omitted when the ticket had none
333
336
  * and in historical logs. */
334
337
  assets: z.array(pinnedAssetSchema).optional(),
338
+ /** The ticket's forge issue links frozen at claim time; later ticket
339
+ * edits never change them. Omitted when the ticket had none and in
340
+ * historical logs. */
341
+ issueLinks: z
342
+ .array(
343
+ z.strictObject({
344
+ issue: issueNumber,
345
+ intent: z.enum(['closes', 'refs']),
346
+ }),
347
+ )
348
+ .superRefine(refineUniqueIssues)
349
+ .optional(),
335
350
  }),
336
351
  'node.opening': z.strictObject({
337
352
  branch: z.string().min(1),
@@ -456,6 +471,30 @@ export const eventPayloadSchemas = {
456
471
  z.string().regex(/^(?:build:[a-z0-9][a-z0-9-]*|foreign:[0-9a-f]{40}(?:[0-9a-f]{24})?)$/),
457
472
  ),
458
473
  }),
474
+ /** A landed child's effective issue links, recorded once per child on its
475
+ * target node: a leaf's links with downgrade provenance, or a nested
476
+ * node's own union. The node's reducer folds them into its union. */
477
+ 'node.issue-links-recorded': z.strictObject({
478
+ build: z.string().min(1),
479
+ issueLinks: z
480
+ .array(
481
+ z.strictObject({
482
+ issue: issueNumber,
483
+ intent: z.enum(['closes', 'refs']),
484
+ downgraded: z.literal(true).optional(),
485
+ }),
486
+ )
487
+ .min(1)
488
+ .superRefine(refineUniqueIssues),
489
+ }),
490
+ /** The root node's PR body was confirmed by readback to carry exactly
491
+ * these keyword lines. */
492
+ 'node.issue-links-published': z.strictObject({
493
+ pr: z.number().int().positive(),
494
+ issueLinks: z
495
+ .array(z.strictObject({ issue: issueNumber, intent: z.enum(['closes', 'refs']) }))
496
+ .superRefine(refineUniqueIssues),
497
+ }),
459
498
  'node.inventory': z.strictObject({
460
499
  head: z.string().min(1),
461
500
  base: z.string().min(1).optional(),
@@ -583,6 +622,12 @@ export const eventPayloadSchemas = {
583
622
  remote: z.boolean().optional(),
584
623
  branch: z.string().min(1),
585
624
  base: workspaceBaseSchema,
625
+ /** Preserved branch heads not restored over the branch: already
626
+ * contained, or superseded by a recorded rewrite in the bounded record. */
627
+ restorationSkipped: z
628
+ .array(z.strictObject({ sha: gitOid, reason: z.enum(['contained', 'superseded']) }))
629
+ .min(1)
630
+ .optional(),
586
631
  }),
587
632
  'workspace.cleanup-required': z.strictObject({
588
633
  provider: z.string().min(1),
@@ -845,6 +890,16 @@ export const eventPayloadSchemas = {
845
890
  nextAttemptAt: z.iso.datetime(),
846
891
  }),
847
892
  'build.janitor-failing': z.strictObject({ message: z.string().min(1) }),
893
+ /** One per janitor failure episode that outlasts the escalation limit. The
894
+ * reducer opens it as a policy escalation and closes it on recovery. */
895
+ 'build.janitor-escalated': z.strictObject({
896
+ id: z.string().min(1),
897
+ operation: z.string().min(1),
898
+ message: z.string().min(1),
899
+ attempt: z.number().int().positive(),
900
+ firstFailureAt: z.iso.datetime(),
901
+ question: z.string().min(1),
902
+ }),
848
903
  'build.janitor-recovered': empty,
849
904
  'landing.application-failed': z.strictObject({
850
905
  candidate: landingCandidateSchema,
@@ -935,6 +990,11 @@ export const eventPayloadSchemas = {
935
990
  stream: z.string().min(1).optional(),
936
991
  /** Present only when this target substituted for the preceding failed one. */
937
992
  substitution: providerSubstitutionSchema.optional(),
993
+ /** Effective first message this bracket sends the model: the runtime's
994
+ * skill invocation for a fresh start, the continuation message for a live
995
+ * continue, the interruption notice for a native resume. Absent on
996
+ * historical events and when the runtime cannot report it. */
997
+ prompt: z.string().min(1).optional(),
938
998
  }),
939
999
  'session.suspended': z.strictObject({
940
1000
  session: z.string().min(1),
@@ -1166,6 +1226,11 @@ export const eventPayloadSchemas = {
1166
1226
  count: z.number().int().nonnegative().nullable(),
1167
1227
  })
1168
1228
  .refine((sample) => sample.count === null || sample.head !== null),
1229
+ /** The dispatcher observed the engine's leaf `wait awaiting-pr` decision:
1230
+ * every verify step and finalize post-step is done for this settlement key
1231
+ * (max of the verify cycle start and finalize completion seqs). Capacity
1232
+ * evidence only; no pipeline decision reads it. */
1233
+ 'pipeline.settled': z.strictObject({ cycle: z.number().int().positive() }),
1169
1234
  'target.rewritten': z.strictObject({
1170
1235
  branch: z.string().min(1),
1171
1236
  previousSha: gitOid,
@@ -1233,6 +1298,15 @@ export const eventPayloadSchemas = {
1233
1298
  ]),
1234
1299
 
1235
1300
  // ── Cross-cutting ──────────────────────────────────────────────────────────
1301
+ /** An agent found the build only partly resolves a linked `closes` issue.
1302
+ * One-way: no fact can express an upgrade. Inert once links are sealed. */
1303
+ 'issue-link.downgraded': z.strictObject({
1304
+ issue: issueNumber,
1305
+ reason: z.string().trim().min(1),
1306
+ }),
1307
+ /** The kernel fixed the build's issue links before its first PR side
1308
+ * effect; later downgrades are inert. */
1309
+ 'issue-links.sealed': z.strictObject({}),
1236
1310
  'observation.recorded': z.strictObject({
1237
1311
  id: z.string().min(1),
1238
1312
  kind: observationKindSchema,
@@ -1272,6 +1346,17 @@ export const eventPayloadSchemas = {
1272
1346
  reason: z.literal('own-build-read'),
1273
1347
  diagnostic: z.string().trim().min(1),
1274
1348
  }),
1349
+ /** A later own-build read in the same session succeeded after `failureSeq`,
1350
+ * the chain's latest classified failure. */
1351
+ 'session.build-read-recovered': z.strictObject({
1352
+ session: z.string().min(1),
1353
+ phase: phaseSchema,
1354
+ round,
1355
+ operation: z.literal('context'),
1356
+ reason: z.literal('own-build-read'),
1357
+ evidenceSeq: z.number().int().positive(),
1358
+ failureSeq: z.number().int().positive(),
1359
+ }),
1275
1360
  'phase.deferred': z.strictObject({
1276
1361
  session: z.string().min(1),
1277
1362
  phase: phaseSchema,