@defrex/autobuild 1.6.0 → 1.8.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 (165) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +423 -57
  3. package/docs/agent-runtimes.md +1 -1
  4. package/docs/answering-blocked-builds.md +44 -3
  5. package/docs/architecture.md +124 -29
  6. package/docs/cli.md +1 -0
  7. package/docs/configuration-overview.md +11 -1
  8. package/docs/configuration.md +334 -14
  9. package/docs/dispatcher.md +1 -1
  10. package/docs/forges.md +1 -0
  11. package/docs/integration-overview.md +2 -2
  12. package/docs/integration-tree.md +7 -4
  13. package/docs/merge-policy.md +78 -6
  14. package/docs/migration-1.0.md +4 -2
  15. package/docs/operating.md +3 -2
  16. package/docs/operator-api.md +45 -13
  17. package/docs/operator-surfaces.md +16 -3
  18. package/docs/plugin-authoring.md +45 -7
  19. package/docs/remote-store-protocol.md +28 -7
  20. package/docs/restacking.md +35 -11
  21. package/docs/ticket-dependencies.md +9 -4
  22. package/docs/ticket-sources.md +34 -6
  23. package/docs/tickets.md +7 -1
  24. package/docs/troubleshooting.md +1 -1
  25. package/docs/workspaces.md +1 -1
  26. package/package.json +3 -3
  27. package/packages/core/src/cli/attention.ts +2 -0
  28. package/packages/core/src/cli/binary-direct.ts +1 -0
  29. package/packages/core/src/cli/build-control.ts +65 -7
  30. package/packages/core/src/cli/context.ts +55 -14
  31. package/packages/core/src/cli/dashboard/actions.ts +13 -4
  32. package/packages/core/src/cli/dashboard/landing-display.ts +32 -8
  33. package/packages/core/src/cli/dashboard/model.ts +61 -8
  34. package/packages/core/src/cli/dashboard/render.ts +28 -3
  35. package/packages/core/src/cli/dashboard/tree.ts +9 -1
  36. package/packages/core/src/cli/dispatch-frontend.ts +10 -14
  37. package/packages/core/src/cli/dispatch-preflight.ts +1 -0
  38. package/packages/core/src/cli/dispatch-repository-feed.ts +145 -109
  39. package/packages/core/src/cli/dispatch.ts +9 -3
  40. package/packages/core/src/cli/help.ts +80 -11
  41. package/packages/core/src/cli/init-validation.ts +14 -1
  42. package/packages/core/src/cli/landings.ts +1 -1
  43. package/packages/core/src/cli/main.ts +60 -9
  44. package/packages/core/src/cli/publication-settlement.ts +10 -0
  45. package/packages/core/src/cli/repository-status.ts +37 -2
  46. package/packages/core/src/cli/status.ts +186 -12
  47. package/packages/core/src/cli/terminals.ts +197 -4
  48. package/packages/core/src/cli/ticket.ts +22 -4
  49. package/packages/core/src/cli/wait.ts +1 -0
  50. package/packages/core/src/cli/watch.ts +73 -0
  51. package/packages/core/src/config/landing.ts +12 -0
  52. package/packages/core/src/config/live.ts +4 -0
  53. package/packages/core/src/config/path-selectors.ts +68 -0
  54. package/packages/core/src/config/profiles.ts +96 -0
  55. package/packages/core/src/config/ready-assignee.ts +43 -11
  56. package/packages/core/src/config/roles.ts +33 -10
  57. package/packages/core/src/config/schema.ts +205 -81
  58. package/packages/core/src/events/catalog.ts +17 -3
  59. package/packages/core/src/events/compatibility.ts +4 -1
  60. package/packages/core/src/events/forge-degradation-policy.ts +16 -2
  61. package/packages/core/src/events/head-paths-limits.ts +25 -0
  62. package/packages/core/src/events/payloads.ts +323 -20
  63. package/packages/core/src/events/policy.ts +22 -0
  64. package/packages/core/src/events/repository.ts +47 -1
  65. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +320 -130
  66. package/packages/core/src/kernel/build-creation.ts +29 -0
  67. package/packages/core/src/kernel/consent-revocation.ts +72 -0
  68. package/packages/core/src/kernel/dispatch-capacity.ts +19 -8
  69. package/packages/core/src/kernel/engine.ts +48 -8
  70. package/packages/core/src/kernel/forge-health.ts +47 -0
  71. package/packages/core/src/kernel/guarded-forge.ts +76 -18
  72. package/packages/core/src/kernel/head-paths-state.ts +63 -0
  73. package/packages/core/src/kernel/head-paths.ts +401 -0
  74. package/packages/core/src/kernel/landing-policy-identity.ts +20 -0
  75. package/packages/core/src/kernel/landing-policy.ts +55 -2
  76. package/packages/core/src/kernel/landing-readiness.ts +104 -9
  77. package/packages/core/src/kernel/landing-state.ts +44 -4
  78. package/packages/core/src/kernel/leaf-restack-state.ts +50 -2
  79. package/packages/core/src/kernel/log-index.ts +27 -1
  80. package/packages/core/src/kernel/node-parent.ts +2 -0
  81. package/packages/core/src/kernel/node-polling.ts +13 -3
  82. package/packages/core/src/kernel/node-restack-state.ts +8 -1
  83. package/packages/core/src/kernel/node-restack-transaction.ts +45 -0
  84. package/packages/core/src/kernel/read-deferrals.ts +3 -1
  85. package/packages/core/src/kernel/read-facts.ts +37 -2
  86. package/packages/core/src/kernel/reducer-registry.ts +22 -1
  87. package/packages/core/src/kernel/reducer.ts +332 -16
  88. package/packages/core/src/kernel/target-observation.ts +2 -5
  89. package/packages/core/src/kernel/terminal-guard.ts +52 -3
  90. package/packages/core/src/kernel/ticket-handbacks.ts +40 -0
  91. package/packages/core/src/kernel/ticket-preparation.ts +15 -1
  92. package/packages/core/src/kernel/ticket-wait.ts +345 -0
  93. package/packages/core/src/kernel/verify-applicability.ts +9 -19
  94. package/packages/core/src/ontology.ts +1 -0
  95. package/packages/core/src/operator/annotations.ts +6 -0
  96. package/packages/core/src/operator/index.ts +3 -0
  97. package/packages/core/src/operator/protocol.ts +25 -2
  98. package/packages/core/src/operator/query.ts +1 -1
  99. package/packages/core/src/operator/registry.ts +122 -10
  100. package/packages/core/src/operator/repository-events.ts +67 -0
  101. package/packages/core/src/operator/sandbox-host.ts +3 -0
  102. package/packages/core/src/operator/tickets.ts +15 -3
  103. package/packages/core/src/plugin-sdk/index.ts +4 -0
  104. package/packages/core/src/ports/forge/create.ts +6 -0
  105. package/packages/core/src/ports/forge/github-transport.ts +40 -3
  106. package/packages/core/src/ports/forge/github.ts +12 -1
  107. package/packages/core/src/ports/forge/workspace-ancestry.ts +60 -0
  108. package/packages/core/src/ports/forge-failure.ts +31 -2
  109. package/packages/core/src/ports/runner/routing.ts +66 -5
  110. package/packages/core/src/ports/tickets/assignees.ts +54 -0
  111. package/packages/core/src/ports/tickets/contract.ts +164 -4
  112. package/packages/core/src/ports/tickets/create.ts +17 -3
  113. package/packages/core/src/ports/tickets/fake.ts +5 -0
  114. package/packages/core/src/ports/tickets/github-fake.ts +18 -2
  115. package/packages/core/src/ports/tickets/github.ts +247 -29
  116. package/packages/core/src/ports/tickets/hosted-index.ts +1 -0
  117. package/packages/core/src/ports/tickets/operations.ts +6 -1
  118. package/packages/core/src/ports/tickets/tree.ts +12 -2
  119. package/packages/core/src/ports/tickets/update.ts +6 -2
  120. package/packages/core/src/ports/types.ts +36 -5
  121. package/packages/core/src/ports/workspace/vercel-sandbox.ts +9 -0
  122. package/packages/core/src/processes/build-child.ts +28 -7
  123. package/packages/core/src/processes/build-execution-state.ts +34 -2
  124. package/packages/core/src/processes/build-runner.ts +165 -19
  125. package/packages/core/src/processes/dispatcher.ts +837 -115
  126. package/packages/core/src/processes/execution-no-progress.ts +22 -2
  127. package/packages/core/src/processes/harvest-child.ts +4 -0
  128. package/packages/core/src/processes/harvest-runner.ts +5 -0
  129. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  130. package/packages/core/src/processes/publication-state.ts +6 -1
  131. package/packages/core/src/processes/repo-view.ts +2 -0
  132. package/packages/core/src/scenarios/harness.ts +15 -1
  133. package/packages/core/src/store/digest.ts +41 -2
  134. package/packages/core/src/store/reduced-reads.ts +4 -1
  135. package/packages/core/src/store/reducer-value-shapes.json +10310 -8441
  136. package/packages/core/src/store/remote/client.ts +49 -10
  137. package/packages/core/src/store/remote/index.ts +4 -0
  138. package/packages/core/src/store/remote/protocol.ts +18 -1
  139. package/packages/core/src/store/remote/released-clients.json +22 -0
  140. package/packages/core/src/store/remote/released-reducer-values/1.7.0.json +27366 -0
  141. package/packages/core/src/store/remote/released-reducer-values/1.8.0.json +29043 -0
  142. package/packages/core/src/store/remote/released-reducer-values/index.ts +4 -0
  143. package/packages/core/src/store/repo-state-events.ts +3 -0
  144. package/packages/core/src/store/types.ts +27 -0
  145. package/packages/core/src/testing/dispatch-read-budget.ts +84 -58
  146. package/packages/core/src/testing/index.ts +2 -0
  147. package/packages/core/src/testing/reduced-read-budget.ts +419 -9
  148. package/skills/code-review/SKILL.md +8 -0
  149. package/skills/finalize/SKILL.md +4 -0
  150. package/skills/guide/SKILL.md +241 -47
  151. package/skills/guide/references/integration-tree.md +7 -4
  152. package/skills/guide/references/merge-policy.md +78 -6
  153. package/skills/guide/references/migration-1.0.md +4 -2
  154. package/skills/guide/references/operator-api.md +45 -13
  155. package/skills/guide/references/plugin-authoring.md +45 -7
  156. package/skills/guide/references/remote-store-protocol.md +28 -7
  157. package/skills/guide/references/restacking.md +35 -11
  158. package/skills/guide/references/ticket-dependencies.md +9 -4
  159. package/skills/implement/SKILL.md +15 -1
  160. package/skills/operate/SKILL.md +133 -16
  161. package/skills/plan/SKILL.md +17 -2
  162. package/skills/plan-review/SKILL.md +8 -0
  163. package/skills/reconcile/SKILL.md +21 -5
  164. package/skills/tickets/SKILL.md +23 -6
  165. package/templates/hosted-service/package.json +2 -2
@@ -26,7 +26,8 @@ import { selectAccount, type SelectedAccount } from './accounts'
26
26
  * never requested on the other.
27
27
  */
28
28
  import { CORE_PHASES } from '../ontology'
29
- import type { Config } from './schema'
29
+ import { profileRoles } from './profiles'
30
+ import type { Config, RoleConfig } from './schema'
30
31
 
31
32
  // ── Vocabulary ───────────────────────────────────────────────────────────────
32
33
 
@@ -100,7 +101,8 @@ export interface RuntimeReferenceGroup {
100
101
  * bootstrap share one source of truth.
101
102
  */
102
103
  export function effectiveRuntimeReferences(
103
- config: Pick<Config, 'roles' | 'verify' | 'finalize'> & Partial<Pick<Config, 'accounts'>>,
104
+ config: Pick<Config, 'roles' | 'verify' | 'finalize'> &
105
+ Partial<Pick<Config, 'accounts' | 'profiles'>>,
104
106
  options: { includeUnusedAccounts?: boolean } = {},
105
107
  ): RuntimeReferenceGroup[] {
106
108
  const defaultSpec = config.roles.default ?? {}
@@ -130,12 +132,18 @@ export function effectiveRuntimeReferences(
130
132
  string,
131
133
  { references: Set<string>; models: Set<string>; usesRuntimeDefaultModel: boolean }
132
134
  >()
133
- const declaredSpec = (role: string, aliases: readonly string[] = []) => {
135
+ // MUST mirror the resolver's candidate walk (src/ports/runner/routing.ts).
136
+ // `selected` is the declared key that won, or undefined for the fallback.
137
+ const declaredSpec = (
138
+ roles: Record<string, RoleConfig>,
139
+ role: string,
140
+ aliases: readonly string[] = [],
141
+ ): { spec: RoleConfig; selected?: string } => {
134
142
  for (const key of [role, ...aliases]) {
135
- if (key === RESERVED_ROLE) return defaultSpec
136
- if (Object.hasOwn(config.roles, key)) return config.roles[key]!
143
+ if (key === RESERVED_ROLE) return { spec: defaultSpec }
144
+ if (Object.hasOwn(roles, key)) return { spec: roles[key]!, selected: key }
137
145
  }
138
- return defaultSpec
146
+ return { spec: defaultSpec }
139
147
  }
140
148
  const add = (
141
149
  runtime: string | undefined,
@@ -170,22 +178,37 @@ export function effectiveRuntimeReferences(
170
178
  grouped.set(runtime, group)
171
179
  }
172
180
 
173
- for (const route of routes) {
174
- const spec = declaredSpec(route.role, route.aliases)
181
+ const addRoute = (spec: RoleConfig, label: string) => {
175
182
  const runtime = spec.runtime ?? defaultSpec.runtime
176
183
  const model = spec.model ?? defaultSpec.model
177
- add(runtime, model, `${route.label} primary`, spec.account ?? defaultSpec.account)
184
+ add(runtime, model, `${label} primary`, spec.account ?? defaultSpec.account)
178
185
  const alternates = spec.alternates ?? defaultSpec.alternates ?? []
179
186
  alternates.forEach((alternate, index) => {
180
187
  add(
181
188
  alternate.runtime ?? runtime,
182
189
  alternate.model ?? model,
183
- `${route.label} alternate[${index}]`,
190
+ `${label} alternate[${index}]`,
184
191
  alternate.account ?? spec.account ?? defaultSpec.account,
185
192
  )
186
193
  })
187
194
  }
188
195
 
196
+ for (const route of routes)
197
+ addRoute(declaredSpec(config.roles, route.role, route.aliases).spec, route.label)
198
+
199
+ // A profile can select a runtime, model or account no repository route
200
+ // does. Only routes whose winning key is a profile entry add anything new.
201
+ const profiles = config.profiles ?? {}
202
+ for (const name of Object.keys(profiles)) {
203
+ const entries = profiles[name]!.roles
204
+ const overlaid = profileRoles(config.roles, entries)
205
+ for (const route of routes) {
206
+ const { spec, selected } = declaredSpec(overlaid, route.role, route.aliases)
207
+ if (selected === undefined || !Object.hasOwn(entries, selected)) continue
208
+ addRoute(spec, `profile ${displayName(name)} ${route.label}`)
209
+ }
210
+ }
211
+
189
212
  // Unused accounts still require their actual runtime for readiness.
190
213
  for (const [name, descriptor] of Object.entries(
191
214
  options.includeUnusedAccounts === false ? {} : (config.accounts ?? {}),
@@ -16,6 +16,7 @@ import { isSafeStepName } from '../context-directory'
16
16
  import { z } from 'zod'
17
17
  import { documentSchema, documentFields } from './reference-metadata'
18
18
  import { landingRuleSchema } from './landing'
19
+ import { pathSelectorSchema } from './path-selectors'
19
20
  export { landingRuleSchema, type LandingRule } from './landing'
20
21
  import { normalizeServiceURL } from '../connection'
21
22
  import { holdsState, ticketLifecycle } from '../ports/tickets/lifecycle'
@@ -28,8 +29,11 @@ import {
28
29
  } from '../ports/workspace/provider-capabilities'
29
30
  import { defineEntry, openMap, ownEntries, parseEntry } from '../open-map'
30
31
  import { forwardIssues } from '../zod-issues'
31
- import { effectiveRuntimeReferences } from './roles'
32
+ import { displayName, effectiveRuntimeReferences, RESERVED_ROLE } from './roles'
33
+ import { normalizeProfileLabel, profileRoles } from './profiles'
32
34
  import {
35
+ createAssigneeUnsupported,
36
+ GITHUB_CREATE_ASSIGNEE,
33
37
  GITHUB_READY_ASSIGNEE,
34
38
  LINEAR_READY_ASSIGNEE,
35
39
  readyAssigneeUnsupported,
@@ -438,67 +442,28 @@ export const BUILTIN_WORKSPACE_PROVIDER_CONFIG: ReadonlyMap<
438
442
 
439
443
  export const commandsSchema = openMap(
440
444
  '[commands]',
441
- documentSchema(z.string().min(1), { description: 'Named deterministic shell command.' }),
445
+ documentSchema(z.string().min(1), {
446
+ description: 'Named deterministic shell command.',
447
+ }),
442
448
  )
443
449
  export type Commands = z.infer<typeof commandsSchema>
444
450
 
445
451
  // ── [verify.<step>] ──────────────────────────────────────────────────────────
446
452
 
447
- /**
448
- * The intentionally small path-selector grammar (§16.1): positive,
449
- * repository-relative globs with literal characters, `*`, `?`, and `**` only
450
- * as a complete path segment. Reject every ambiguous/unsafe form at config
451
- * load rather than allowing a typo to become a never-running safety gate.
452
- */
453
- export function verifyPathGlobError(pattern: string): string | undefined {
454
- if (pattern.length === 0) return 'path selectors must be nonempty'
455
- if (pattern.includes('\0')) return 'path selectors must not contain NUL bytes'
456
- if (pattern.startsWith('/') || /^[A-Za-z]:\//.test(pattern)) {
457
- return 'path selectors must be repository-relative, not absolute'
458
- }
459
- if (pattern.includes('\\')) {
460
- return 'path selectors use Git-style "/" separators; backslashes and escapes are unsupported'
461
- }
462
- if (pattern.startsWith('!')) {
463
- return 'path selectors are positive globs; negation is unsupported'
464
- }
465
- if (/[[\]{}]/.test(pattern)) {
466
- return 'path selectors support only literal characters, *, ?, and whole-segment **; character classes and brace expansion are unsupported'
467
- }
468
- if (/[?*+@!]\(/.test(pattern)) {
469
- return 'path selectors support only literal characters, *, ?, and whole-segment **; extglobs are unsupported'
470
- }
471
-
472
- const segments = pattern.split('/')
473
- if (segments.some((segment) => segment.length === 0)) {
474
- return 'path selectors must not contain empty path segments'
475
- }
476
- if (segments.some((segment) => segment === '.' || segment === '..')) {
477
- return 'path selectors must not contain "." or ".." traversal segments'
478
- }
479
- if (segments.some((segment) => segment.includes('**') && segment !== '**')) {
480
- return 'the ** wildcard must occupy a complete path segment'
481
- }
482
- return undefined
483
- }
484
-
485
- export const verifyPathGlobSchema = z.string().superRefine((pattern, ctx) => {
486
- const message = verifyPathGlobError(pattern)
487
- if (message !== undefined) ctx.addIssue({ code: 'custom', message })
488
- })
489
-
490
- documentSchema(verifyPathGlobSchema, {
491
- constraints:
492
- 'Positive repository-relative globs with literal characters, *, ?, and whole-segment ** only. No NUL, absolute paths, backslashes, negation, empty or traversal segments, character classes, brace expansion or extglobs.',
493
- })
453
+ export {
454
+ pathSelectorError as verifyPathGlobError,
455
+ pathSelectorSchema as verifyPathGlobSchema,
456
+ } from './path-selectors'
494
457
 
495
458
  const verifyApplicabilityShape = {
496
459
  /** Absence preserves historical serialized configuration identity. */
497
- failFast: documentSchema(z.boolean().optional(), { default: 'false (omission is preserved)' }),
460
+ failFast: documentSchema(z.boolean().optional(), {
461
+ default: 'false (omission is preserved)',
462
+ }),
498
463
  afterReconcile: z.boolean().optional(),
499
464
  /** Any-match positive path selectors; absent means unconditional. */
500
465
  paths: z
501
- .array(verifyPathGlobSchema)
466
+ .array(pathSelectorSchema)
502
467
  .min(1, 'paths must contain at least one repository-relative glob')
503
468
  .optional(),
504
469
  /** Explicit mandatory-gate guard: true takes precedence over paths and a
@@ -582,7 +547,9 @@ export const verifySectionSchema = stepSection(
582
547
  stepConfigs,
583
548
  afterReconcile,
584
549
  ...(entries.some(Array.isArray)
585
- ? { stages: entries.map((entry) => (typeof entry === 'string' ? [entry] : entry)) }
550
+ ? {
551
+ stages: entries.map((entry) => (typeof entry === 'string' ? [entry] : entry)),
552
+ }
586
553
  : {}),
587
554
  }),
588
555
  true,
@@ -727,6 +694,51 @@ documentSchema(roleSchema.shape.alternates, {
727
694
  })
728
695
  export type RoleConfig = z.infer<typeof roleSchema>
729
696
 
697
+ // ── [profiles] ───────────────────────────────────────────────────────────────
698
+ //
699
+ // Open map: profile → one ticket label plus role entries (SPEC §9). A build
700
+ // whose ticket carries the label at claim resolves its roles through this
701
+ // overlay. Label uniqueness, nonblank labels, the refused `default` entry and
702
+ // overlaid account selection are cross-validated in configSchema below;
703
+ // runtime and model compatibility is checked by the eager resolver.
704
+
705
+ const profileRoleSchema = roleSchema.extend({
706
+ // A distinct field schema so its reference names the profile inheritance
707
+ // order; the repository role's own budget sits between the entry and default.
708
+ sessionBudgetSeconds: z.number().int().positive().optional(),
709
+ })
710
+ documentSchema(profileRoleSchema.shape.sessionBudgetSeconds, {
711
+ description:
712
+ 'Active-time budget for each build phase session routed through this role in a profiled build. Suspended intervals are excluded; native continuation retains the original ceiling and accumulated active time. One budget covers the primary and every alternate target.',
713
+ constraints:
714
+ 'Omission inherits roles.<role>.sessionBudgetSeconds, then roles.default.sessionBudgetSeconds, otherwise policy.sessionBudgetSeconds.',
715
+ })
716
+ documentSchema(profileRoleSchema, {
717
+ description:
718
+ "Role override for builds whose ticket carries the profile's label. Omitted fields inherit `[roles.<role>]`, then `[roles.default]`; a declared alternates list, including [], replaces the inherited list.",
719
+ })
720
+
721
+ const profileSchema = z.strictObject({
722
+ label: z.string(),
723
+ roles: openMap('[profiles.<name>.roles]', profileRoleSchema),
724
+ })
725
+ documentFields(profileSchema, {
726
+ label:
727
+ "Ticket label that selects this profile, matched case-insensitively after trimming. A ticket carrying two profiles' labels is not claimed.",
728
+ roles:
729
+ 'Role entries this profile overrides. Any role name is accepted except the reserved default.',
730
+ })
731
+ documentSchema(profileSchema.shape.label, {
732
+ constraints: 'Nonblank; unique across profiles after trimming and case folding.',
733
+ })
734
+ documentSchema(profileSchema.shape.roles, {
735
+ constraints: 'An entry named default is refused',
736
+ })
737
+ documentSchema(profileSchema, {
738
+ description:
739
+ "Named role profile. The build's profile is fixed when its ticket is claimed; the profile's contents are read at each session boundary.",
740
+ })
741
+
730
742
  // ── [policy] ─────────────────────────────────────────────────────────────────
731
743
 
732
744
  const DISPATCH_LEASE_PAIR_MESSAGE =
@@ -871,6 +883,21 @@ export const ticketsInputSchema = z.strictObject({
871
883
  '[tickets].readyAssignee must be a nonblank value with no surrounding whitespace',
872
884
  )
873
885
  .optional(),
886
+ /**
887
+ * Assigns every ticket Autobuild creates (`ab ticket create`, operator
888
+ * `tickets.create`, harvest proposals) to one user unless the create names
889
+ * its own assignees. A ticket-source capability: the source must declare
890
+ * `assignees`. github takes `"me"` (the owner of the creating credential —
891
+ * for harvest, the filing dispatcher's) or a username. Absent sends no
892
+ * assignee.
893
+ */
894
+ createAssignee: z
895
+ .string()
896
+ .refine(
897
+ (s) => s.trim().length > 0 && s === s.trim(),
898
+ '[tickets].createAssignee must be a nonblank value with no surrounding whitespace',
899
+ )
900
+ .optional(),
874
901
  /** Backend team key (e.g. "ENG") — required for linear and hosted;
875
902
  * forbidden for github. */
876
903
  teamKey: z.string().min(1).optional(),
@@ -946,11 +973,14 @@ documentFields(ticketsInputSchema, {
946
973
  readyState: 'The one workflow state eligible for dispatch.',
947
974
  readyAssignee:
948
975
  'Require the ticket to be assigned to one user, in addition to the state and label gates.',
976
+ createAssignee:
977
+ 'Assign every ticket Autobuild creates (`ab ticket create`, operator `tickets.create`, harvest proposals) to one user unless the create names its own assignees.',
949
978
  teamKey: 'Backend team key such as `"ENG"`, or an existing plugin config field.',
950
979
  claimedState: 'Workflow state entered when a ticket is claimed.',
951
980
  doneState: 'Project completion state and merged-ticket transition.',
952
981
  createState: 'Default state for newly created tickets when `ab ticket create` omits `--state`.',
953
- triageState: 'State used for spec-gate bounces, aborts, and closed-unmerged PRs.',
982
+ triageState:
983
+ 'State used for spec-gate bounces, aborts (unless `ab abort --to ready` with a ticket that meets the spec standard), and closed-unmerged PRs.',
954
984
  proposalState:
955
985
  'State harvest files its synthesized proposals into. Setting it to `readyState` waives the human grooming gate, not dependency eligibility.',
956
986
  backlogState:
@@ -970,7 +1000,9 @@ documentSchema(ticketsInputSchema.shape.readyState, {
970
1000
  documentSchema(ticketsInputSchema.shape.teamKey, {
971
1001
  required: 'Required for linear and hosted; forbidden for file and github; optional for plugins.',
972
1002
  })
973
- documentSchema(ticketsInputSchema.shape.claimedState, { constraints: 'Forbidden for file.' })
1003
+ documentSchema(ticketsInputSchema.shape.claimedState, {
1004
+ constraints: 'Forbidden for file.',
1005
+ })
974
1006
  documentSchema(ticketsInputSchema.shape.dir, {
975
1007
  constraints: 'Forbidden for linear, hosted and github.',
976
1008
  })
@@ -978,6 +1010,10 @@ documentSchema(ticketsInputSchema.shape.readyAssignee, {
978
1010
  constraints:
979
1011
  '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
1012
  })
1013
+ documentSchema(ticketsInputSchema.shape.createAssignee, {
1014
+ constraints:
1015
+ 'Allowed for github ("me" or a GitHub username) and plugin sources that declare assignees. Refused for file, hosted and linear.',
1016
+ })
981
1017
  documentSchema(ticketsInputSchema.shape.readyLabels, {
982
1018
  constraints:
983
1019
  'Omission uses source readiness defaults (Linear and GitHub: autobuild label; file: none). Explicit [] disables label gating.',
@@ -1035,7 +1071,10 @@ const DISPATCHER_ROLES = [
1035
1071
  * never claims from, moves into, or files proposals into them, whatever the
1036
1072
  * other lifecycle names say, and the two may not share a state. */
1037
1073
  function refuseOptionalRoleOverlap(tickets: TicketsConfig, ctx: z.RefinementCtx): void {
1038
- const names = ticketLifecycle({ ...tickets, readyState: tickets.readyState ?? 'ready' })
1074
+ const names = ticketLifecycle({
1075
+ ...tickets,
1076
+ readyState: tickets.readyState ?? 'ready',
1077
+ })
1039
1078
  // The file source ignores claimedState and doneState: claims always move
1040
1079
  // into doing and completion is Done. Check the states it actually uses as
1041
1080
  // well as the configured spellings.
@@ -1071,7 +1110,11 @@ export const ticketsSchema = ticketsInputSchema
1071
1110
  try {
1072
1111
  normalizeServiceURL(tickets.url, 'tickets.url')
1073
1112
  } catch (error) {
1074
- ctx.addIssue({ code: 'custom', path: ['url'], message: (error as Error).message })
1113
+ ctx.addIssue({
1114
+ code: 'custom',
1115
+ path: ['url'],
1116
+ message: (error as Error).message,
1117
+ })
1075
1118
  }
1076
1119
  }
1077
1120
  if (!['hosted', 'github'].includes(tickets.source) && tickets.readyState === undefined)
@@ -1202,6 +1245,7 @@ export const configRootSchema = z.strictObject({
1202
1245
  // therefore include the complete materialized runtime list in its diagnostic.
1203
1246
  accounts: openMap('[accounts]', accountSchema).default({}),
1204
1247
  roles: openMap('[roles]', roleSchema),
1248
+ profiles: openMap('[profiles]', profileSchema),
1205
1249
  policy: policySchema.prefault({}),
1206
1250
  orchestrator: orchestratorSchema.prefault({}),
1207
1251
  // An absent [tickets] table must NOT silently default past the mandatory
@@ -1219,7 +1263,7 @@ documentFields(configRootSchema, {
1219
1263
  upgrade: 'Automatic dispatcher runtime target checks and adoption.',
1220
1264
  baseBranch: 'Branch used to cut builds, target PRs, and merge during reconciliation.',
1221
1265
  capacity:
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).',
1266
+ 'Builds running work at once for this repository. A build that finished its pipeline holds no slot while it waits for a merge decision, nor does a build waiting on other tickets; either is admitted ahead of new claims when it must run again. Other 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).',
1223
1267
  ticketScanIntervalSeconds:
1224
1268
  'Ticket-source ready scan cadence; tick spacing is the effective minimum.',
1225
1269
  forge:
@@ -1238,6 +1282,8 @@ documentFields(configRootSchema, {
1238
1282
  accounts:
1239
1283
  'Named Claude subscription, Kimi Code, or ChatGPT subscription billing accounts. Descriptors contain credential variable names only.',
1240
1284
  roles: 'Named agent roles. The reserved default role provides inherited runtime axes.',
1285
+ profiles:
1286
+ 'Named role profiles selected by ticket label. A profile overrides only the role fields it declares, for the builds that selected it.',
1241
1287
  policy: 'Lifecycle budgets, retries, convergence and harvest limits.',
1242
1288
  orchestrator:
1243
1289
  'Operator-agent sandbox settings. This table does not start or host an operator agent.',
@@ -1315,31 +1361,83 @@ export const configSchema = normalizedConfigSchema.superRefine((config, ctx) =>
1315
1361
  path: ['orchestrator', 'sandbox', 'environmentVariables'],
1316
1362
  message: `Account credential variable ${JSON.stringify(name)} cannot enter an operator sandbox`,
1317
1363
  })
1318
- const defaults = config.roles.default ?? {}
1319
- for (const [role, spec] of Object.entries(config.roles)) {
1320
- const primary = {
1321
- runtime: spec.runtime ?? defaults.runtime,
1322
- account: spec.account ?? defaults.account,
1323
- }
1324
- const targets = [
1325
- primary,
1326
- ...(spec.alternates ?? defaults.alternates ?? []).map((alt) => ({
1327
- runtime: alt.runtime ?? primary.runtime,
1328
- account: alt.account ?? primary.account,
1329
- })),
1330
- ]
1331
- targets.forEach((target, index) => {
1332
- try {
1333
- selectAccount(
1334
- config.accounts,
1335
- target.runtime,
1336
- target.account,
1337
- `role ${JSON.stringify(role)}${index ? ` alternate[${index - 1}]` : ''}`,
1338
- )
1339
- } catch (error) {
1340
- ctx.addIssue({ code: 'custom', path: ['roles', role], message: (error as Error).message })
1364
+ const checkRoleAccounts = (
1365
+ roles: Record<string, RoleConfig>,
1366
+ keys: readonly string[],
1367
+ path: (role: string) => (string | number)[],
1368
+ label: (role: string) => string,
1369
+ ) => {
1370
+ const defaults = roles.default ?? {}
1371
+ for (const role of keys) {
1372
+ const spec = roles[role]!
1373
+ const primary = {
1374
+ runtime: spec.runtime ?? defaults.runtime,
1375
+ account: spec.account ?? defaults.account,
1341
1376
  }
1377
+ const targets = [
1378
+ primary,
1379
+ ...(spec.alternates ?? defaults.alternates ?? []).map((alt) => ({
1380
+ runtime: alt.runtime ?? primary.runtime,
1381
+ account: alt.account ?? primary.account,
1382
+ })),
1383
+ ]
1384
+ targets.forEach((target, index) => {
1385
+ try {
1386
+ selectAccount(
1387
+ config.accounts,
1388
+ target.runtime,
1389
+ target.account,
1390
+ `${label(role)}${index ? ` alternate[${index - 1}]` : ''}`,
1391
+ )
1392
+ } catch (error) {
1393
+ ctx.addIssue({
1394
+ code: 'custom',
1395
+ path: path(role),
1396
+ message: (error as Error).message,
1397
+ })
1398
+ }
1399
+ })
1400
+ }
1401
+ }
1402
+ checkRoleAccounts(
1403
+ config.roles,
1404
+ Object.keys(config.roles),
1405
+ (role) => ['roles', role],
1406
+ (role) => `role ${JSON.stringify(role)}`,
1407
+ )
1408
+
1409
+ const profileLabels = new Map<string, string>()
1410
+ for (const [name, profile] of Object.entries(config.profiles ?? {})) {
1411
+ const normalized = normalizeProfileLabel(profile.label)
1412
+ if (normalized.length === 0) {
1413
+ ctx.addIssue({
1414
+ code: 'custom',
1415
+ path: ['profiles', name, 'label'],
1416
+ message: `profile ${displayName(name)} needs a nonblank label`,
1417
+ })
1418
+ } else if (profileLabels.has(normalized)) {
1419
+ ctx.addIssue({
1420
+ code: 'custom',
1421
+ path: ['profiles', name, 'label'],
1422
+ message: `profiles ${displayName(profileLabels.get(normalized)!)} and ${displayName(name)} both declare label ${displayName(profile.label.trim())}; each profile needs its own label`,
1423
+ })
1424
+ } else profileLabels.set(normalized, name)
1425
+ const keys = Object.keys(profile.roles).filter((role) => {
1426
+ if (role !== RESERVED_ROLE) return true
1427
+ ctx.addIssue({
1428
+ code: 'custom',
1429
+ path: ['profiles', name, 'roles', role],
1430
+ message: `profile ${displayName(name)} cannot override the reserved default role; name each role it changes`,
1431
+ })
1432
+ return false
1342
1433
  })
1434
+ if (config.roles !== undefined)
1435
+ checkRoleAccounts(
1436
+ profileRoles(config.roles, profile.roles),
1437
+ keys,
1438
+ (role) => ['profiles', name, 'roles', role],
1439
+ (role) => `profile ${displayName(name)} role ${JSON.stringify(role)}`,
1440
+ )
1343
1441
  }
1344
1442
 
1345
1443
  for (const kind of ['verify', 'finalize'] as const) {
@@ -1554,7 +1652,33 @@ export const configSchema = normalizedConfigSchema.superRefine((config, ctx) =>
1554
1652
  assignee === assignee.trim() &&
1555
1653
  !form.accepts(assignee)
1556
1654
  ) {
1557
- ctx.addIssue({ code: 'custom', path: ['tickets', 'readyAssignee'], message: form.message })
1655
+ ctx.addIssue({
1656
+ code: 'custom',
1657
+ path: ['tickets', 'readyAssignee'],
1658
+ message: form.message,
1659
+ })
1660
+ }
1661
+ }
1662
+ // createAssignee is the `assignees` capability, checked the same way.
1663
+ const createAssignee = tickets.createAssignee
1664
+ if (createAssignee !== undefined) {
1665
+ if (tickets.source === 'file' || tickets.source === 'hosted' || tickets.source === 'linear') {
1666
+ ctx.addIssue({
1667
+ code: 'custom',
1668
+ path: ['tickets', 'createAssignee'],
1669
+ message: createAssigneeUnsupported(tickets.source),
1670
+ })
1671
+ } else if (
1672
+ tickets.source === 'github' &&
1673
+ createAssignee.trim().length > 0 &&
1674
+ createAssignee === createAssignee.trim() &&
1675
+ !GITHUB_CREATE_ASSIGNEE.accepts(createAssignee)
1676
+ ) {
1677
+ ctx.addIssue({
1678
+ code: 'custom',
1679
+ path: ['tickets', 'createAssignee'],
1680
+ message: GITHUB_CREATE_ASSIGNEE.message,
1681
+ })
1558
1682
  }
1559
1683
  }
1560
1684
  // Plugin sources receive the existing ticket lifecycle/configuration fields
@@ -50,6 +50,8 @@ export const allowedActorKinds: Record<EventType, readonly ActorKind[]> = {
50
50
  'build.janitor-escalated': ['dispatcher'],
51
51
  'landing.application-failed': ['dispatcher', 'kernel'],
52
52
  'landing.decided': ['dispatcher', 'kernel'],
53
+ 'landing.deferred': ['dispatcher'],
54
+ 'landing.consent-revoked': ['kernel'],
53
55
  'build.hold-requested': ['human'],
54
56
  'build.land-requested': ['human'],
55
57
  'landing.command-acknowledged': ['dispatcher', 'kernel'],
@@ -61,12 +63,14 @@ export const allowedActorKinds: Record<EventType, readonly ActorKind[]> = {
61
63
  'target.rewritten': ['dispatcher', 'kernel'],
62
64
  'target.rewrite-cleared': ['dispatcher', 'kernel'],
63
65
  'target.moved': ['dispatcher', 'kernel'],
66
+ 'head.paths-recorded': ['kernel', 'dispatcher'],
64
67
  'restack.prepared': ['kernel', 'dispatcher'],
65
68
  'restack.replayed': ['kernel', 'dispatcher'],
66
69
  'restack.publish-intended': ['kernel', 'dispatcher'],
67
70
  'restack.rewritten': ['kernel', 'dispatcher'],
68
71
  'restack.contended': ['kernel', 'dispatcher'],
69
72
  'restack.completed': ['kernel', 'dispatcher'],
73
+ 'restack.advanced': ['kernel'],
70
74
  'integration.abandoned': ['kernel', 'dispatcher'],
71
75
  'integration.observed': ['kernel', 'dispatcher'],
72
76
  'integration.prepared': ['kernel', 'dispatcher'],
@@ -135,6 +139,7 @@ export const allowedActorKinds: Record<EventType, readonly ActorKind[]> = {
135
139
  'abort.remote-branch-deleted': ['dispatcher'],
136
140
  'abort.local-branch-deleted': ['dispatcher'],
137
141
  'abort.ticket-returned': ['dispatcher'],
142
+ 'build.ticket-returned': ['dispatcher'],
138
143
  'dispatch.failed': ['dispatcher'],
139
144
  'dispatch.comment-posted': ['dispatcher'],
140
145
 
@@ -197,6 +202,7 @@ export const allowedActorKinds: Record<EventType, readonly ActorKind[]> = {
197
202
  'reconcile.publish-intended': ['kernel'],
198
203
  'reconcile.rewritten': ['kernel', 'dispatcher'],
199
204
  'reconcile.completed': ['agent', 'dispatcher', 'kernel'],
205
+ 'reconcile.superseded': ['kernel'],
200
206
 
201
207
  'issue-link.downgraded': ['agent'],
202
208
  'issue-links.sealed': ['kernel'],
@@ -211,6 +217,11 @@ export const allowedActorKinds: Record<EventType, readonly ActorKind[]> = {
211
217
  'session.build-read-recovered': ['kernel'],
212
218
  'phase.deferred': ['kernel'],
213
219
  'phase.deferral-escalated': ['kernel'],
220
+ 'wait.requested': ['agent'],
221
+ 'wait.refused': ['dispatcher'],
222
+ 'wait.entered': ['dispatcher'],
223
+ 'wait.ended': ['dispatcher', 'kernel', 'human'],
224
+ 'wait.published': ['dispatcher'],
214
225
  }
215
226
 
216
227
  /**
@@ -279,10 +290,11 @@ export function validateEventWrite(input: {
279
290
  (escalation.policyCause !== 'infrastructure-failure-limit' &&
280
291
  escalation.policyCause !== 'dispatch-failure-limit' &&
281
292
  escalation.policyCause !== 'execution-no-progress' &&
282
- escalation.policyCause !== 'publication-retry-limit'))
293
+ escalation.policyCause !== 'publication-retry-limit' &&
294
+ escalation.policyCause !== 'wait-unresolvable'))
283
295
  ) {
284
296
  throw new EventValidationError(
285
- 'invalid dispatcher escalation: only policy/infrastructure-failure-limit or policy/dispatch-failure-limit or policy/execution-no-progress or policy/publication-retry-limit may be raised outside the kernel',
297
+ 'invalid dispatcher escalation: only policy/infrastructure-failure-limit or policy/dispatch-failure-limit or policy/execution-no-progress or policy/publication-retry-limit or policy/wait-unresolvable may be raised outside the kernel',
286
298
  )
287
299
  }
288
300
  if (escalation.source === 'policy' && escalation.policyCause === undefined) {
@@ -299,7 +311,9 @@ export function validateEventWrite(input: {
299
311
  return {
300
312
  ...(input.compatibility === undefined
301
313
  ? {}
302
- : { compatibility: stampCompatibility(buildEventPolicy[input.type], input.compatibility) }),
314
+ : {
315
+ compatibility: stampCompatibility(buildEventPolicy[input.type], input.compatibility),
316
+ }),
303
317
  actor,
304
318
  type: input.type,
305
319
  payload: payloadResult.data,
@@ -25,7 +25,10 @@ export interface StoredEvent {
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
27
  // Revision 4 retains the optional effective prompt in session projections.
28
- export const READ_DECODER_REVISION = 4
28
+ // Revision 5 retains the optional preparation creation key.
29
+ // Revision 6 retains the optional role profile on build creation and session starts.
30
+ // Revision 7 retains the optional abort destination and hand-back report fields.
31
+ export const READ_DECODER_REVISION = 7
29
32
  export function catalogIdentity(
30
33
  build: Record<string, string> = buildEventPolicy,
31
34
  repository: Record<string, string> = repositoryEventPolicy,
@@ -3,9 +3,23 @@ import { forgeHealthEventPayloadSchemas } from './repository'
3
3
  /** Hosted admission horizon; never applied to historical event decoding. */
4
4
  export const MAX_FORGE_DEGRADATION_MS = 24 * 60 * 60 * 1000
5
5
 
6
- export function validateForgeDegradation(payload: unknown, now: Date): void {
7
- const parsed = forgeHealthEventPayloadSchemas['dispatcher.forge-degraded'].parse(payload)
6
+ /** Forge-health facts whose `resetAt` hosted admission bounds. */
7
+ export const FORGE_RESET_EVENT_TYPES = [
8
+ 'dispatcher.forge-degraded',
9
+ 'forge.credential-limited',
10
+ ] as const
11
+
12
+ export function validateForgeResetHorizon(
13
+ type: (typeof FORGE_RESET_EVENT_TYPES)[number],
14
+ payload: unknown,
15
+ now: Date,
16
+ ): void {
17
+ const parsed = forgeHealthEventPayloadSchemas[type].parse(payload)
8
18
  const deadline = Date.parse(parsed.resetAt)
9
19
  if (!Number.isFinite(deadline) || deadline > now.getTime() + MAX_FORGE_DEGRADATION_MS)
10
20
  throw new Error('forge resetAt must be a finite ISO deadline within 24 hours of server time')
11
21
  }
22
+
23
+ export function validateForgeDegradation(payload: unknown, now: Date): void {
24
+ validateForgeResetHorizon('dispatcher.forge-degraded', payload, now)
25
+ }
@@ -0,0 +1,25 @@
1
+ /** Bounds of the `head.paths-recorded` summary. A leaf module so the payload
2
+ * schema and `kernel/head-paths.ts` share them without an import cycle. */
3
+
4
+ /** The most changed (or resolution) paths an event or build state carries.
5
+ * The complete sets live in the `head-paths` artifact. */
6
+ export const HEAD_PATHS_PREVIEW = 100
7
+
8
+ /** The most matched paths a `landing.decided` event carries for a merge rule
9
+ * with path predicates; the exact total travels beside them. */
10
+ export const LANDING_MATCHED_PATHS_PREVIEW = 20
11
+
12
+ /** The most per-head summaries build state keeps, newest last. */
13
+ export const HEAD_PATHS_RECORDS = 4
14
+
15
+ /** The build artifact kind holding a head's complete path sets. */
16
+ export const HEAD_PATHS_ARTIFACT = 'head-paths'
17
+
18
+ export const HEAD_PATHS_SOURCES = [
19
+ 'finalize',
20
+ 'finalize-step',
21
+ 'restack',
22
+ 'reconcile',
23
+ 'node-rewrite',
24
+ 'integration',
25
+ ] as const