@defrex/autobuild 1.0.1 → 1.2.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 (247) hide show
  1. package/README.md +10 -18
  2. package/SPEC.md +499 -238
  3. package/bin/ab-dispatch-generation.ts +11 -2
  4. package/docs/accounts.md +119 -0
  5. package/docs/agent-runtimes.md +4 -4
  6. package/docs/answering-blocked-builds.md +2 -2
  7. package/docs/architecture.md +262 -53
  8. package/docs/assets/headline-wide.png +0 -0
  9. package/docs/build-store.md +3 -41
  10. package/docs/builds.md +4 -4
  11. package/docs/cli.md +18 -4
  12. package/docs/configuration-overview.md +115 -4
  13. package/docs/configuration.md +488 -334
  14. package/docs/dispatcher-hosting.md +19 -34
  15. package/docs/dispatcher.md +1 -1
  16. package/docs/forges.md +5 -5
  17. package/docs/getting-started.md +2 -2
  18. package/docs/glossary.md +6 -6
  19. package/docs/intake.md +2 -0
  20. package/docs/integration-overview.md +15 -15
  21. package/docs/integration-tree.md +45 -38
  22. package/docs/integration.md +6 -6
  23. package/{skills/guide/references/landing-policy.md → docs/merge-policy.md} +40 -24
  24. package/docs/migration-1.0.md +17 -13
  25. package/docs/operating.md +41 -19
  26. package/docs/operator-api.md +180 -51
  27. package/docs/operator-surfaces.md +5 -18
  28. package/docs/overview.md +3 -3
  29. package/docs/plugin-authoring.md +21 -0
  30. package/docs/remote-store-protocol.md +242 -68
  31. package/docs/remote-ticket-protocol.md +30 -50
  32. package/docs/restacking.md +54 -15
  33. package/docs/seams.md +8 -8
  34. package/docs/setup.md +59 -119
  35. package/docs/skills.md +1 -1
  36. package/docs/spec-standard.md +6 -6
  37. package/docs/ticket-dependencies.md +7 -7
  38. package/docs/ticket-sources.md +18 -0
  39. package/docs/tickets.md +8 -2
  40. package/docs/troubleshooting.md +8 -12
  41. package/docs/upgrading.md +9 -4
  42. package/docs/verification.md +60 -14
  43. package/docs/workspaces.md +4 -4
  44. package/package.json +17 -6
  45. package/packages/core/src/accounts/chatgpt-oauth.ts +216 -0
  46. package/packages/core/src/accounts/chatgpt-state.ts +41 -0
  47. package/packages/core/src/accounts/local-credentials.ts +194 -0
  48. package/packages/core/src/accounts/local-inference.ts +106 -0
  49. package/packages/core/src/accounts/local-owner.ts +123 -0
  50. package/packages/core/src/accounts/sensitive.ts +2 -0
  51. package/packages/core/src/cli/accounts.ts +147 -0
  52. package/packages/core/src/cli/binary-direct.ts +13 -1
  53. package/packages/core/src/cli/binary-lifecycle.ts +65 -2
  54. package/packages/core/src/cli/binary.ts +3 -1
  55. package/packages/core/src/cli/build-control.ts +83 -28
  56. package/packages/core/src/cli/connect.ts +3 -3
  57. package/packages/core/src/cli/context.ts +81 -38
  58. package/packages/core/src/cli/dashboard/facts.ts +2 -1
  59. package/packages/core/src/cli/dashboard/integration-detail.ts +8 -8
  60. package/packages/core/src/cli/dashboard/integration-row.ts +40 -13
  61. package/packages/core/src/cli/dashboard/landing-display.ts +25 -0
  62. package/packages/core/src/cli/dashboard/model.ts +56 -33
  63. package/packages/core/src/cli/dashboard/poll.ts +9 -3
  64. package/packages/core/src/cli/dashboard/render.ts +59 -37
  65. package/packages/core/src/cli/dashboard/target-distance.ts +14 -0
  66. package/packages/core/src/cli/dashboard/tree.ts +3 -2
  67. package/packages/core/src/cli/dispatch-args.ts +1 -1
  68. package/packages/core/src/cli/dispatch-frontend.ts +6 -3
  69. package/packages/core/src/cli/dispatch-handoff.ts +125 -44
  70. package/packages/core/src/cli/dispatch-launch-contract.ts +187 -0
  71. package/packages/core/src/cli/dispatch-launcher.ts +54 -21
  72. package/packages/core/src/cli/dispatch-preflight.ts +6 -1
  73. package/packages/core/src/cli/dispatch.ts +106 -11
  74. package/packages/core/src/cli/env.ts +4 -0
  75. package/packages/core/src/cli/help.ts +46 -23
  76. package/packages/core/src/cli/init-readiness-remote.ts +22 -1
  77. package/packages/core/src/cli/init-readiness-shared.ts +5 -1
  78. package/packages/core/src/cli/init-validation.ts +160 -18
  79. package/packages/core/src/cli/main.ts +68 -8
  80. package/packages/core/src/cli/node-verification-provenance.ts +1 -97
  81. package/packages/core/src/cli/publication-settlement.ts +47 -21
  82. package/packages/core/src/cli/repository-status.ts +20 -9
  83. package/packages/core/src/cli/secrets.ts +173 -0
  84. package/packages/core/src/cli/status.ts +42 -5
  85. package/packages/core/src/cli/store-opening.ts +17 -2
  86. package/packages/core/src/cli/terminal.ts +22 -1
  87. package/packages/core/src/cli/terminals.ts +14 -10
  88. package/packages/core/src/cli/upgrade-agent.ts +9 -1
  89. package/packages/core/src/cli/upgrade-landing.ts +70 -30
  90. package/packages/core/src/cli/upgrade.ts +3 -1
  91. package/packages/core/src/cli/wait.ts +15 -7
  92. package/packages/core/src/cli/watch-lifetime.ts +111 -0
  93. package/packages/core/src/cli/watch.ts +635 -510
  94. package/packages/core/src/config/accounts.ts +101 -0
  95. package/packages/core/src/config/effective-artifact.fixture.ts +27 -0
  96. package/packages/core/src/config/effective-artifact.ts +13 -0
  97. package/packages/core/src/config/landing.ts +1 -1
  98. package/packages/core/src/config/live.ts +14 -1
  99. package/packages/core/src/config/load.ts +21 -1
  100. package/packages/core/src/config/pipeline-source.ts +28 -0
  101. package/packages/core/src/config/reference-metadata.ts +2 -0
  102. package/packages/core/src/config/reference.ts +22 -7
  103. package/packages/core/src/config/roles.ts +54 -3
  104. package/packages/core/src/config/schema.ts +146 -162
  105. package/packages/core/src/context-directory.ts +26 -0
  106. package/packages/core/src/distribution-packaging.ts +26 -5
  107. package/packages/core/src/events/catalog.ts +10 -2
  108. package/packages/core/src/events/compatibility.ts +2 -1
  109. package/packages/core/src/events/globs.ts +1 -1
  110. package/packages/core/src/events/payloads.ts +73 -1
  111. package/packages/core/src/events/policy.ts +7 -0
  112. package/packages/core/src/events/repository.ts +4 -4
  113. package/packages/core/src/events/sessions.ts +6 -6
  114. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +574 -0
  115. package/packages/core/src/kernel/auto-merge.ts +2 -2
  116. package/packages/core/src/kernel/engine.ts +255 -26
  117. package/packages/core/src/kernel/generators/leaf-restack-log.ts +10 -0
  118. package/packages/core/src/kernel/integration-landing.ts +3 -3
  119. package/packages/core/src/kernel/integration-state.ts +27 -4
  120. package/packages/core/src/kernel/leaf-restack-state.ts +28 -3
  121. package/packages/core/src/kernel/log-index.ts +13 -1
  122. package/packages/core/src/kernel/node-landing.ts +8 -8
  123. package/packages/core/src/kernel/node-parent.ts +2 -2
  124. package/packages/core/src/kernel/node-restack-transaction.ts +1 -1
  125. package/packages/core/src/kernel/node-verification-context.ts +216 -0
  126. package/packages/core/src/kernel/phases.ts +1 -1
  127. package/packages/core/src/kernel/plan-verify-selection.ts +16 -0
  128. package/packages/core/src/kernel/publication-retry.ts +168 -0
  129. package/packages/core/src/kernel/reconcile-restack.ts +29 -1
  130. package/packages/core/src/kernel/reducer.ts +85 -5
  131. package/packages/core/src/kernel/target-distance.ts +45 -0
  132. package/packages/core/src/kernel/terminal-guard.ts +10 -1
  133. package/packages/core/src/kernel/verify-stage-state.ts +123 -0
  134. package/packages/core/src/kernel/verify-stages.ts +39 -0
  135. package/packages/core/src/ontology.ts +1 -0
  136. package/packages/core/src/operator/annotations.ts +6 -0
  137. package/packages/core/src/operator/control.ts +1 -1
  138. package/packages/core/src/operator/index.ts +3 -7
  139. package/packages/core/src/operator/landings.ts +5 -1
  140. package/packages/core/src/operator/presentation.ts +6 -1
  141. package/packages/core/src/operator/protocol.ts +6 -0
  142. package/packages/core/src/operator/query.ts +14 -18
  143. package/packages/core/src/operator/registry.ts +39 -7
  144. package/packages/core/src/operator/sandbox-host.ts +64 -40
  145. package/packages/core/src/operator/sandbox.ts +3 -0
  146. package/packages/core/src/operator/ticket-source-backend.ts +3 -12
  147. package/packages/core/src/operator/tickets.ts +25 -4
  148. package/packages/core/src/plugins/manifest.ts +2 -1
  149. package/packages/core/src/ports/forge/contract.ts +2 -2
  150. package/packages/core/src/ports/forge/git-rewrite.ts +25 -2
  151. package/packages/core/src/ports/forge/github-readiness.ts +2 -2
  152. package/packages/core/src/ports/forge/github.ts +26 -7
  153. package/packages/core/src/ports/forge/local-git.ts +4 -4
  154. package/packages/core/src/ports/forge/readiness.ts +1 -1
  155. package/packages/core/src/ports/forge-failure.ts +24 -0
  156. package/packages/core/src/ports/runner/account-env.ts +88 -0
  157. package/packages/core/src/ports/runner/chatgpt-provider.ts +85 -0
  158. package/packages/core/src/ports/runner/claude.ts +26 -2
  159. package/packages/core/src/ports/runner/codex.ts +63 -31
  160. package/packages/core/src/ports/runner/one-shot.ts +2 -0
  161. package/packages/core/src/ports/runner/provider-error.ts +5 -0
  162. package/packages/core/src/ports/runner/routing.ts +35 -4
  163. package/packages/core/src/ports/tickets/contract.ts +58 -0
  164. package/packages/core/src/ports/tickets/tree.ts +1 -1
  165. package/packages/core/src/ports/types.ts +28 -7
  166. package/packages/core/src/ports/workspace/account-policy.ts +72 -0
  167. package/packages/core/src/ports/workspace/build-execution.ts +9 -2
  168. package/packages/core/src/ports/workspace/builtin-capabilities.ts +1 -0
  169. package/packages/core/src/ports/workspace/create.ts +2 -0
  170. package/packages/core/src/ports/workspace/git-worktree.ts +6 -1
  171. package/packages/core/src/ports/workspace/phase-scratch.ts +4 -3
  172. package/packages/core/src/ports/workspace/provider-capabilities.ts +1 -0
  173. package/packages/core/src/ports/workspace/vercel-sandbox.ts +182 -72
  174. package/packages/core/src/processes/build-child.ts +6 -8
  175. package/packages/core/src/processes/build-execution-state.ts +8 -5
  176. package/packages/core/src/processes/build-runner.ts +554 -99
  177. package/packages/core/src/processes/dispatcher.ts +209 -101
  178. package/packages/core/src/processes/execution-no-progress.ts +8 -1
  179. package/packages/core/src/processes/execution-settlement.ts +21 -3
  180. package/packages/core/src/processes/harvest-runner.ts +68 -8
  181. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  182. package/packages/core/src/processes/publication-loss.ts +8 -2
  183. package/packages/core/src/processes/publication-state.ts +42 -4
  184. package/packages/core/src/processes/repo-view.ts +14 -0
  185. package/packages/core/src/processes/verify-cycle-config.ts +96 -0
  186. package/packages/core/src/project-secrets.ts +105 -0
  187. package/packages/core/src/{integration → scenarios}/harness.ts +330 -317
  188. package/packages/core/src/secret-name.ts +41 -0
  189. package/packages/core/src/store/account-redaction.ts +156 -0
  190. package/packages/core/src/store/adapter.ts +1 -0
  191. package/packages/core/src/store/build-scope.ts +9 -0
  192. package/packages/core/src/store/contract.ts +116 -2
  193. package/packages/core/src/store/local/schema.ts +13 -0
  194. package/packages/core/src/store/local/store.ts +42 -0
  195. package/packages/core/src/store/memory.ts +47 -0
  196. package/packages/core/src/store/operator-presence.ts +21 -0
  197. package/packages/core/src/store/phase-session.ts +10 -0
  198. package/packages/core/src/store/reducer-value-shapes.json +5185 -4156
  199. package/packages/core/src/store/remote/client.ts +89 -48
  200. package/packages/core/src/store/remote/compatibility.ts +20 -0
  201. package/packages/core/src/store/remote/protocol.ts +4 -0
  202. package/packages/core/src/store/remote/version.ts +3 -1
  203. package/packages/core/src/store/retention.ts +2 -3
  204. package/packages/core/src/store/session-handle.ts +9 -0
  205. package/packages/core/src/store/streams/session-writer.ts +1 -1
  206. package/packages/core/src/store/types.ts +12 -2
  207. package/packages/core/src/testing/dispatch-read-budget.ts +122 -0
  208. package/packages/core/src/testing/index.ts +12 -1
  209. package/packages/core/src/testing/reduced-read-budget.ts +47 -0
  210. package/packages/core/src/testing/temp-directories.ts +58 -0
  211. package/skills/code-review/SKILL.md +23 -9
  212. package/skills/finalize/SKILL.md +15 -7
  213. package/skills/guide/SKILL.md +373 -148
  214. package/skills/guide/references/accounts.md +119 -0
  215. package/skills/guide/references/integration-tree.md +45 -38
  216. package/{docs/landing-policy.md → skills/guide/references/merge-policy.md} +40 -24
  217. package/skills/guide/references/migration-1.0.md +17 -13
  218. package/skills/guide/references/operator-api.md +180 -51
  219. package/skills/guide/references/plugin-authoring.md +21 -0
  220. package/skills/guide/references/remote-store-protocol.md +242 -68
  221. package/skills/guide/references/remote-ticket-protocol.md +30 -50
  222. package/skills/guide/references/restacking.md +54 -15
  223. package/skills/guide/references/setup.md +59 -119
  224. package/skills/guide/references/spec-standard.md +6 -6
  225. package/skills/guide/references/ticket-dependencies.md +7 -7
  226. package/skills/harvest/SKILL.md +3 -1
  227. package/skills/harvest-review/SKILL.md +3 -1
  228. package/skills/implement/SKILL.md +43 -17
  229. package/skills/operate/SKILL.md +118 -118
  230. package/skills/plan/SKILL.md +39 -13
  231. package/skills/plan-review/SKILL.md +15 -10
  232. package/skills/reconcile/SKILL.md +22 -3
  233. package/skills/spec/SKILL.md +20 -20
  234. package/skills/tickets/SKILL.md +12 -9
  235. package/templates/autobuild.toml +1 -1
  236. package/templates/hosted-service/package.json +2 -2
  237. package/docs/hosted-dispatcher-cutover-validation.md +0 -178
  238. package/docs/hosted-dispatcher.md +0 -275
  239. package/docs/hosted-service.md +0 -293
  240. package/docs/mcp.md +0 -149
  241. package/packages/core/src/orchestrator/approvals.ts +0 -115
  242. package/packages/core/src/orchestrator/conversation.ts +0 -167
  243. package/packages/core/src/orchestrator/model.ts +0 -86
  244. package/packages/core/src/orchestrator/prompt.ts +0 -63
  245. package/packages/core/src/orchestrator/tools.ts +0 -117
  246. package/packages/core/src/orchestrator/turn-runner.ts +0 -457
  247. package/packages/core/src/processes/orchestrator-tick.ts +0 -360
@@ -0,0 +1,101 @@
1
+ import { z } from 'zod'
2
+ import { documentSchema, documentFields } from './reference-metadata'
3
+
4
+ const accountCredentialEnvSchema = z
5
+ .string()
6
+ .regex(/^[A-Za-z_][A-Za-z0-9_]*$/)
7
+ .refine(
8
+ (name) => !name.startsWith('AB_'),
9
+ 'Autobuild control variables cannot hold account credentials',
10
+ )
11
+ export const accountSchema = z.discriminatedUnion('kind', [
12
+ z.strictObject({
13
+ kind: z.literal('chatgpt-subscription'),
14
+ credentialEnv: accountCredentialEnvSchema,
15
+ }),
16
+ z.strictObject({
17
+ kind: z.literal('claude-subscription'),
18
+ credentialEnv: accountCredentialEnvSchema,
19
+ }),
20
+ z.strictObject({
21
+ kind: z.literal('kimi-code'),
22
+ credentialEnv: accountCredentialEnvSchema,
23
+ region: z.enum(['overseas', 'china']).default('overseas'),
24
+ }),
25
+ ])
26
+
27
+ documentSchema(accountSchema, { description: 'Named nonsecret billing account descriptor.' })
28
+ documentSchema(accountCredentialEnvSchema, {
29
+ constraints: 'Portable environment variable identifier; AB_ control variables are reserved.',
30
+ })
31
+ for (const branch of accountSchema.options)
32
+ documentFields(branch, {
33
+ kind: 'Claude subscription, Kimi Code membership, or ChatGPT subscription (Codex only).',
34
+ credentialEnv:
35
+ 'Host credential variable name; ChatGPT names a host-resolved access-token slot, never a credential value.',
36
+ ...(branch.shape.kind.value === 'kimi-code'
37
+ ? {
38
+ region:
39
+ 'Membership region: overseas (default) or china. Selects the base URL and exact egress host together.',
40
+ }
41
+ : {}),
42
+ })
43
+
44
+ /** Nonsecret billing descriptors. Credential values are resolved only at execution boundaries. */
45
+ export type Account =
46
+ | { kind: 'claude-subscription'; credentialEnv: string }
47
+ | { kind: 'chatgpt-subscription'; credentialEnv: string }
48
+ | { kind: 'kimi-code'; credentialEnv: string; region: 'overseas' | 'china' }
49
+ export type Accounts = Readonly<Record<string, Account>>
50
+ export const selectedAccountSchema = z.strictObject({
51
+ name: z.string().min(1),
52
+ descriptor: accountSchema,
53
+ })
54
+ export type SelectedAccount = z.infer<typeof selectedAccountSchema>
55
+
56
+ export function kimiEndpoint(region: 'overseas' | 'china'): { baseUrl: string; host: string } {
57
+ return region === 'china'
58
+ ? { baseUrl: 'https://api.kimi.com/coding/', host: 'api.kimi.com' }
59
+ : { baseUrl: 'https://api.kimi.ai/coding/', host: 'api.kimi.ai' }
60
+ }
61
+
62
+ export function selectAccount(
63
+ accounts: Accounts,
64
+ runtime: string | undefined,
65
+ name: string | undefined,
66
+ label: string,
67
+ ): SelectedAccount | undefined {
68
+ if (name === undefined && runtime === 'claude') {
69
+ const defaults = Object.entries(accounts).filter(
70
+ ([, account]) => account.kind === 'claude-subscription',
71
+ )
72
+ if (defaults.length > 1)
73
+ throw new Error(`${label}: ambiguous Claude subscription account; select account explicitly`)
74
+ name = defaults[0]?.[0]
75
+ }
76
+ if (name === undefined) return undefined
77
+ if (!Object.hasOwn(accounts, name))
78
+ throw new Error(`${label}: unknown account ${JSON.stringify(name)}`)
79
+ const requiredRuntime = accounts[name]!.kind === 'chatgpt-subscription' ? 'codex' : 'claude'
80
+ if (runtime !== requiredRuntime)
81
+ throw new Error(
82
+ `${label}: account ${JSON.stringify(name)} requires runtime "${requiredRuntime}"`,
83
+ )
84
+ return { name, descriptor: accounts[name]! }
85
+ }
86
+
87
+ export function accountRemedy(account: SelectedAccount): string {
88
+ return (
89
+ `account ${JSON.stringify(account.name)} (${account.descriptor.credentialEnv}): ` +
90
+ (account.descriptor.kind === 'chatgpt-subscription'
91
+ ? `sign in again with ab accounts login ${JSON.stringify(account.name)} (--local for the local dispatcher or --project for the connected project)`
92
+ : account.descriptor.kind === 'claude-subscription'
93
+ ? 'renew with claude setup-token and set the dispatcher credential variable'
94
+ : 'replace the Kimi Code membership key in the dispatcher credential variable')
95
+ )
96
+ }
97
+
98
+ /** Encodes arbitrary names injectively; never a credential. */
99
+ export function accountPlaceholder(name: string): string {
100
+ return `autobuild-account-${Buffer.from(name).toString('hex')}`
101
+ }
@@ -0,0 +1,27 @@
1
+ import { parseConfig } from './load'
2
+ import { effectiveBuildConfigContent } from '../processes/build-execution-state'
3
+
4
+ /** Pre-removal normalized snapshot, including defaults written while disabled. */
5
+ export function historicalEffectiveConfig(enabled = false): Record<string, unknown> {
6
+ const config = JSON.parse(
7
+ effectiveBuildConfigContent(
8
+ parseConfig(`
9
+ [tickets]
10
+ source = "file"
11
+ readyState = "ready"
12
+ [orchestrator]
13
+ enabled = ${enabled}
14
+ [orchestrator.sandbox]
15
+ idleMinutes = 7
16
+ environmentVariables = ["CUSTOM_TOOL"]
17
+ `),
18
+ ),
19
+ )
20
+ config.orchestrator = {
21
+ ...config.orchestrator,
22
+ invocationBudgetSeconds: 240,
23
+ approvals: ['sandbox.publish'],
24
+ ...(enabled ? { model: 'test/historical', wake: ['escalation.*'] } : {}),
25
+ }
26
+ return config
27
+ }
@@ -0,0 +1,13 @@
1
+ /** Read compatibility for immutable pre-removal effective-config artifacts only.
2
+ * New TOML must pass the current strict schema without this conversion. */
3
+ export function normalizeEffectiveConfigArtifact(value: unknown): unknown {
4
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) return value
5
+ const config = value as Record<string, unknown>
6
+ const previous = config.orchestrator
7
+ if (previous === null || typeof previous !== 'object' || Array.isArray(previous)) return value
8
+ const orchestrator = { ...previous } as Record<string, unknown>
9
+ for (const key of ['model', 'invocationBudgetSeconds', 'approvals', 'wake']) {
10
+ delete orchestrator[key]
11
+ }
12
+ return { ...config, orchestrator }
13
+ }
@@ -26,5 +26,5 @@ documentFields(landingRuleSchema, {
26
26
  into: 'Optional destination: `root`, any `node`, or an exact frozen destination node ticket id.',
27
27
  from: 'Restrict this rule to one source build kind; omission matches all kinds.',
28
28
  label: 'Optional exact, case-sensitive label on the source ticket. Blank labels are invalid.',
29
- mode: 'Choose automatic landing or require recorded consent.',
29
+ mode: 'Choose automatic merge or require recorded consent.',
30
30
  })
@@ -29,6 +29,7 @@ export const CONFIG_RELOAD_CLASSIFICATION = {
29
29
  verify: 'hot',
30
30
  finalize: 'hot',
31
31
  roles: 'hot',
32
+ accounts: 'hot',
32
33
  policy: 'hot',
33
34
  orchestrator: 'restart',
34
35
  tickets: {
@@ -184,7 +185,12 @@ export class LiveConfig {
184
185
  this.acceptedContent = startupContent
185
186
  this.snapshot = {
186
187
  config: startup,
187
- resolver: createRuntimeResolver(runtimes, startup.roles, startup.policy.sessionBudgetSeconds),
188
+ resolver: createRuntimeResolver(
189
+ runtimes,
190
+ startup.roles,
191
+ startup.policy.sessionBudgetSeconds,
192
+ startup.accounts,
193
+ ),
188
194
  revision: 0,
189
195
  }
190
196
  }
@@ -244,10 +250,17 @@ export class LiveConfig {
244
250
  const config = composeReloadedConfig(this.startup, candidate)
245
251
  let resolver: RuntimeResolver
246
252
  try {
253
+ for (const [name, account] of Object.entries(this.snapshot.config.accounts)) {
254
+ if (account.kind === 'chatgpt-subscription' && !same(account, config.accounts[name]))
255
+ throw new Error(
256
+ `ChatGPT account ${JSON.stringify(name)} cannot change while dispatch is active; stop dispatch before replacing its descriptor`,
257
+ )
258
+ }
247
259
  resolver = createRuntimeResolver(
248
260
  this.runtimes,
249
261
  config.roles,
250
262
  config.policy.sessionBudgetSeconds,
263
+ config.accounts,
251
264
  )
252
265
  } catch (error) {
253
266
  const message = error instanceof Error ? error.message : String(error)
@@ -70,7 +70,11 @@ function describeIssue(issue: z.core.$ZodIssue): string {
70
70
  return ` ${formatPath(path)}: ${message}`
71
71
  }
72
72
 
73
- export function parseConfig(tomlText: string, source = 'autobuild.toml'): Config {
73
+ export function parseConfig(
74
+ tomlText: string,
75
+ source = 'autobuild.toml',
76
+ warn: (message: string) => void = console.error,
77
+ ): Config {
74
78
  let table: unknown
75
79
  try {
76
80
  table = parseToml(tomlText)
@@ -81,6 +85,19 @@ export function parseConfig(tomlText: string, source = 'autobuild.toml'): Config
81
85
  throw error
82
86
  }
83
87
 
88
+ if (table && typeof table === 'object' && 'orchestrator' in table) {
89
+ const orchestrator = table.orchestrator
90
+ if (orchestrator && typeof orchestrator === 'object') {
91
+ const removed = ['model', 'invocationBudgetSeconds', 'approvals', 'wake'].filter((key) =>
92
+ Object.hasOwn(orchestrator, key),
93
+ )
94
+ if (removed.length > 0) {
95
+ throw new ConfigError(
96
+ `${source}: [orchestrator].${removed.join(', [orchestrator].')} removed: the embedded runner was removed; operators run externally. Keep only enabled and sandbox settings.`,
97
+ )
98
+ }
99
+ }
100
+ }
84
101
  const result = configSchema.safeParse(table)
85
102
  if (!result.success) {
86
103
  // Expanded for the operator, raw for the payload: the expanded copies carry
@@ -89,6 +106,9 @@ export function parseConfig(tomlText: string, source = 'autobuild.toml'): Config
89
106
  const details = expandIssues(result.error.issues).map(describeIssue).join('\n')
90
107
  throw new ConfigError(`${source}: invalid config\n${details}`, result.error.issues)
91
108
  }
109
+ if (table && typeof table === 'object' && Object.hasOwn(table, 'landing')) {
110
+ warn(`${source}: [[landing]] is deprecated; use [[merge]] instead`)
111
+ }
92
112
  return result.data
93
113
  }
94
114
 
@@ -387,3 +387,31 @@ export async function resolvePipelineSource(
387
387
  }
388
388
  return parsePipeline(baseSha, 'base', baseContent, onFailure)
389
389
  }
390
+
391
+ /** Strict execution-side read. Failures block verification rather than falling back. */
392
+ export async function readVerifyPipeline(
393
+ workspacePath: string,
394
+ exec: Exec,
395
+ ): Promise<PipelineSource & { head: string }> {
396
+ const run = async (args: string[]) => {
397
+ const result = await git(args, workspacePath, exec)
398
+ if (result.exitCode !== 0)
399
+ throw new Error(`verify config: git ${args.join(' ')}: ${result.stderr}`)
400
+ return result.stdout.trim()
401
+ }
402
+ const head = await run(['rev-parse', '--verify', 'HEAD'])
403
+ if (!/^[a-f0-9]{40,64}$/.test(head)) throw new Error('verify config: invalid checkout HEAD')
404
+ const content = await readFile(join(workspacePath, 'autobuild.toml'), 'utf8')
405
+ const [committed, working] = await Promise.all([
406
+ run(['ls-tree', head, '--', 'autobuild.toml']),
407
+ run(['hash-object', '--', 'autobuild.toml']),
408
+ ])
409
+ return {
410
+ head,
411
+ meta:
412
+ committed.split(/\s+/)[2] === working
413
+ ? { ref: 'branch-head', commit: head }
414
+ : { ref: 'worktree-dirty' },
415
+ config: parseConfig(content, `autobuild.toml@${head}`),
416
+ }
417
+ }
@@ -2,6 +2,8 @@ import type { z } from 'zod'
2
2
 
3
3
  /** Documentation describes input semantics; it never participates in validation. */
4
4
  export interface ReferenceMetadata {
5
+ /** Semantic default when omission is intentionally preserved in serialized config. */
6
+ default?: string
5
7
  description?: string
6
8
  constraints?: string
7
9
  required?: string
@@ -37,10 +37,12 @@ function fail(path: string, message: string): never {
37
37
  function metadata(schema: z.ZodType, path: string): ReferenceMetadata {
38
38
  const result = referenceMetadata(schema) ?? {}
39
39
  for (const [key, value] of Object.entries(result)) {
40
- if (!['description', 'constraints', 'required', 'examples', 'structure'].includes(key))
40
+ if (
41
+ !['description', 'constraints', 'required', 'examples', 'structure', 'default'].includes(key)
42
+ )
41
43
  fail(path, `unknown metadata ${key}`)
42
44
  if (
43
- ['description', 'constraints', 'required'].includes(key) &&
45
+ ['description', 'constraints', 'required', 'default'].includes(key) &&
44
46
  (typeof value !== 'string' || !value.trim())
45
47
  )
46
48
  fail(path, `blank or malformed ${key}`)
@@ -155,7 +157,13 @@ function input(schema: z.ZodType, path: string): Input {
155
157
  optional = true
156
158
  fallback = `${JSON.stringify(definition(current).defaultValue)} (input supplied on omission)`
157
159
  }
158
- return { schema: current, metadata: meta, optional, default: fallback, constraints }
160
+ return {
161
+ schema: current,
162
+ metadata: meta,
163
+ optional,
164
+ default: meta.default ?? fallback,
165
+ constraints,
166
+ }
159
167
  }
160
168
  function typeOf(value: Input, path: string): string {
161
169
  if (value.metadata.structure) return 'table'
@@ -177,8 +185,11 @@ function typeOf(value: Input, path: string): string {
177
185
  return Object.values(def.entries!)
178
186
  .map((v) => JSON.stringify(v))
179
187
  .join(' | ')
180
- case 'array':
181
- return `array of ${typeOf(input(def.element!, `${path}[]`), `${path}[]`)}`
188
+ case 'array': {
189
+ const elementInput = input(def.element!, `${path}[]`)
190
+ const element = typeOf(elementInput, `${path}[]`)
191
+ return `array of ${definition(elementInput.schema).type === 'union' ? `(${element})` : element}`
192
+ }
182
193
  case 'union':
183
194
  return def.options!.map((v) => typeOf(input(v, path), path)).join(' | ')
184
195
  default:
@@ -202,7 +213,10 @@ export const DOCUMENTATION_RELOAD_FALLBACK = {
202
213
  'tickets.doneState': 'hot',
203
214
  } as const
204
215
  export function reloadBehavior(path: string): string {
205
- const parts = path.replaceAll('[]', '').split('.')
216
+ const parts = path
217
+ .replace(/^merge(?=\[|\.|$)/, 'landing')
218
+ .replaceAll('[]', '')
219
+ .split('.')
206
220
  let classification: unknown = CONFIG_RELOAD_CLASSIFICATION
207
221
  for (const part of parts) {
208
222
  if (typeof classification === 'string') break
@@ -223,7 +237,7 @@ export function reloadBehavior(path: string): string {
223
237
  ? 'Dispatcher restart required; startup adapters retain their configuration.'
224
238
  : 'Mixed: see individual fields for dispatcher reload behavior.'
225
239
  const owned = BUILD_OWNED_CONFIG_PATHS.some((prefix) => parts[0] === prefix)
226
- return `${dispatcher}${owned ? ' Build-owned pipeline: captured from the build branch; later base-branch edits do not replace it. Workspace provisioning applies at the next build launch.' : ''} A running invocation keeps its captured values.`
240
+ return `${dispatcher}${owned ? ' Build-owned pipeline: captured from the execution checkout each verify cycle; later base-branch edits do not replace it. Workspace provisioning applies at the next build launch.' : ''} A running invocation keeps its captured values.`
227
241
  }
228
242
  export function schemaFields(
229
243
  schema: z.ZodType,
@@ -298,6 +312,7 @@ export function schemaFields(
298
312
  export function configurationReference(): Record<string, ReferenceField[]> {
299
313
  const regions: Record<string, ReferenceField[]> = { root: [] }
300
314
  for (const [key, schema] of Object.entries(configRootSchema.shape)) {
315
+ if (key === 'landing') continue // Deprecated spelling is documented with the canonical merge rules.
301
316
  const fields = schemaFields(schema, key)
302
317
  const type = fields[0]!.type
303
318
  if (!type.includes('table')) regions.root!.push(...fields)
@@ -1,3 +1,4 @@
1
+ import { selectAccount, type SelectedAccount } from './accounts'
1
2
  /**
2
3
  * Role-key consumability diagnostics (SPEC §9).
3
4
  *
@@ -79,6 +80,9 @@ export interface RoleKeyDiagnostics {
79
80
  type StepTable = { kind: 'check' } | { kind: 'agent'; skill: string }
80
81
 
81
82
  export interface RuntimeReferenceGroup {
83
+ /** Account-free routes, retained separately when accounts are declared. */
84
+ legacyAuthentication?: { models: string[]; usesRuntimeDefaultModel: boolean }
85
+ accountTargets?: Array<{ account: SelectedAccount; model?: string; references: string[] }>
82
86
  runtime: string
83
87
  /** Human-readable routes selecting this runtime, including alternates. */
84
88
  references: string[]
@@ -95,7 +99,7 @@ export interface RuntimeReferenceGroup {
95
99
  * bootstrap share one source of truth.
96
100
  */
97
101
  export function effectiveRuntimeReferences(
98
- config: Pick<Config, 'roles' | 'verify' | 'finalize'>,
102
+ config: Pick<Config, 'roles' | 'verify' | 'finalize'> & Partial<Pick<Config, 'accounts'>>,
99
103
  ): RuntimeReferenceGroup[] {
100
104
  const defaultSpec = config.roles.default ?? {}
101
105
  const routes: Array<{ role: string; aliases?: string[]; label: string }> = [
@@ -112,6 +116,14 @@ export function effectiveRuntimeReferences(
112
116
  })),
113
117
  ]
114
118
 
119
+ const legacyAuthentication = new Map<
120
+ string,
121
+ { models: Set<string>; usesRuntimeDefaultModel: boolean }
122
+ >()
123
+ const accountTargets = new Map<
124
+ string,
125
+ Array<{ account: SelectedAccount; model?: string; references: string[] }>
126
+ >()
115
127
  const grouped = new Map<
116
128
  string,
117
129
  { references: Set<string>; models: Set<string>; usesRuntimeDefaultModel: boolean }
@@ -123,8 +135,28 @@ export function effectiveRuntimeReferences(
123
135
  }
124
136
  return defaultSpec
125
137
  }
126
- const add = (runtime: string | undefined, model: string | undefined, reference: string) => {
138
+ const add = (
139
+ runtime: string | undefined,
140
+ model: string | undefined,
141
+ reference: string,
142
+ accountName?: string,
143
+ ) => {
144
+ const account = selectAccount(config.accounts ?? {}, runtime, accountName, reference)
145
+ if (account && runtime) {
146
+ const targets = accountTargets.get(runtime) ?? []
147
+ targets.push({ account, ...(model === undefined ? {} : { model }), references: [reference] })
148
+ accountTargets.set(runtime, targets)
149
+ }
127
150
  if (runtime === undefined || runtime.trim() === '') return
151
+ if (!account) {
152
+ const legacy = legacyAuthentication.get(runtime) ?? {
153
+ models: new Set<string>(),
154
+ usesRuntimeDefaultModel: false,
155
+ }
156
+ if (model === undefined) legacy.usesRuntimeDefaultModel = true
157
+ else legacy.models.add(model)
158
+ legacyAuthentication.set(runtime, legacy)
159
+ }
128
160
  const group = grouped.get(runtime) ?? {
129
161
  references: new Set(),
130
162
  models: new Set(),
@@ -140,21 +172,40 @@ export function effectiveRuntimeReferences(
140
172
  const spec = declaredSpec(route.role, route.aliases)
141
173
  const runtime = spec.runtime ?? defaultSpec.runtime
142
174
  const model = spec.model ?? defaultSpec.model
143
- add(runtime, model, `${route.label} primary`)
175
+ add(runtime, model, `${route.label} primary`, spec.account ?? defaultSpec.account)
144
176
  const alternates = spec.alternates ?? defaultSpec.alternates ?? []
145
177
  alternates.forEach((alternate, index) => {
146
178
  add(
147
179
  alternate.runtime ?? runtime,
148
180
  alternate.model ?? model,
149
181
  `${route.label} alternate[${index}]`,
182
+ alternate.account ?? spec.account ?? defaultSpec.account,
150
183
  )
151
184
  })
152
185
  }
153
186
 
187
+ // Unused accounts still require their actual runtime for readiness.
188
+ for (const [name, descriptor] of Object.entries(config.accounts ?? {}))
189
+ add(
190
+ descriptor.kind === 'chatgpt-subscription' ? 'codex' : 'claude',
191
+ descriptor.kind === 'kimi-code' ? 'kimi-for-coding' : undefined,
192
+ `account ${displayName(name)} readiness`,
193
+ name,
194
+ )
195
+
154
196
  return [...grouped.entries()]
155
197
  .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))
156
198
  .map(([runtime, group]) => ({
157
199
  runtime,
200
+ ...(Object.keys(config.accounts ?? {}).length && legacyAuthentication.has(runtime)
201
+ ? {
202
+ legacyAuthentication: {
203
+ models: [...legacyAuthentication.get(runtime)!.models].sort(),
204
+ usesRuntimeDefaultModel: legacyAuthentication.get(runtime)!.usesRuntimeDefaultModel,
205
+ },
206
+ }
207
+ : {}),
208
+ ...(accountTargets.has(runtime) ? { accountTargets: accountTargets.get(runtime)! } : {}),
158
209
  references: [...group.references].sort(),
159
210
  models: [...group.models].sort(),
160
211
  usesRuntimeDefaultModel: group.usesRuntimeDefaultModel,