@defrex/autobuild 1.1.0 → 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 (114) hide show
  1. package/README.md +5 -13
  2. package/SPEC.md +140 -10
  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/architecture.md +107 -8
  7. package/docs/build-store.md +3 -41
  8. package/docs/cli.md +14 -0
  9. package/docs/configuration-overview.md +111 -0
  10. package/docs/configuration.md +260 -141
  11. package/docs/dispatcher-hosting.md +18 -33
  12. package/docs/intake.md +2 -0
  13. package/docs/merge-policy.md +1 -3
  14. package/docs/operating.md +1 -2
  15. package/docs/operator-api.md +100 -47
  16. package/docs/operator-surfaces.md +3 -20
  17. package/docs/overview.md +1 -1
  18. package/docs/plugin-authoring.md +21 -0
  19. package/docs/remote-store-protocol.md +198 -89
  20. package/docs/remote-ticket-protocol.md +29 -49
  21. package/docs/seams.md +8 -8
  22. package/docs/setup.md +34 -129
  23. package/docs/ticket-sources.md +18 -0
  24. package/docs/troubleshooting.md +7 -11
  25. package/docs/upgrading.md +1 -1
  26. package/docs/workspaces.md +4 -4
  27. package/package.json +14 -5
  28. package/packages/core/src/accounts/chatgpt-oauth.ts +216 -0
  29. package/packages/core/src/accounts/chatgpt-state.ts +41 -0
  30. package/packages/core/src/accounts/local-credentials.ts +194 -0
  31. package/packages/core/src/accounts/local-inference.ts +106 -0
  32. package/packages/core/src/accounts/local-owner.ts +123 -0
  33. package/packages/core/src/accounts/sensitive.ts +2 -0
  34. package/packages/core/src/cli/accounts.ts +147 -0
  35. package/packages/core/src/cli/binary.ts +3 -1
  36. package/packages/core/src/cli/connect.ts +3 -3
  37. package/packages/core/src/cli/dispatch-handoff.ts +125 -44
  38. package/packages/core/src/cli/dispatch-launch-contract.ts +187 -0
  39. package/packages/core/src/cli/dispatch-launcher.ts +54 -21
  40. package/packages/core/src/cli/dispatch-preflight.ts +6 -1
  41. package/packages/core/src/cli/dispatch.ts +71 -2
  42. package/packages/core/src/cli/help.ts +16 -0
  43. package/packages/core/src/cli/init-readiness-remote.ts +22 -1
  44. package/packages/core/src/cli/init-readiness-shared.ts +5 -1
  45. package/packages/core/src/cli/init-validation.ts +160 -18
  46. package/packages/core/src/cli/main.ts +44 -0
  47. package/packages/core/src/cli/publication-settlement.ts +4 -1
  48. package/packages/core/src/cli/secrets.ts +173 -0
  49. package/packages/core/src/cli/store-opening.ts +11 -1
  50. package/packages/core/src/cli/upgrade-agent.ts +9 -1
  51. package/packages/core/src/cli/watch.ts +3 -1
  52. package/packages/core/src/config/accounts.ts +101 -0
  53. package/packages/core/src/config/live.ts +14 -1
  54. package/packages/core/src/config/roles.ts +54 -3
  55. package/packages/core/src/config/schema.ts +60 -0
  56. package/packages/core/src/events/compatibility.ts +2 -1
  57. package/packages/core/src/events/payloads.ts +3 -0
  58. package/packages/core/src/events/repository.ts +2 -0
  59. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +3 -0
  60. package/packages/core/src/kernel/reducer.ts +4 -1
  61. package/packages/core/src/operator/index.ts +2 -0
  62. package/packages/core/src/operator/protocol.ts +6 -0
  63. package/packages/core/src/operator/registry.ts +22 -1
  64. package/packages/core/src/operator/tickets.ts +25 -4
  65. package/packages/core/src/plugins/manifest.ts +2 -1
  66. package/packages/core/src/ports/runner/account-env.ts +88 -0
  67. package/packages/core/src/ports/runner/chatgpt-provider.ts +85 -0
  68. package/packages/core/src/ports/runner/claude.ts +26 -2
  69. package/packages/core/src/ports/runner/codex.ts +63 -31
  70. package/packages/core/src/ports/runner/one-shot.ts +2 -0
  71. package/packages/core/src/ports/runner/provider-error.ts +5 -0
  72. package/packages/core/src/ports/runner/routing.ts +35 -4
  73. package/packages/core/src/ports/tickets/contract.ts +58 -0
  74. package/packages/core/src/ports/tickets/tree.ts +1 -1
  75. package/packages/core/src/ports/types.ts +28 -7
  76. package/packages/core/src/ports/workspace/account-policy.ts +72 -0
  77. package/packages/core/src/ports/workspace/build-execution.ts +6 -1
  78. package/packages/core/src/ports/workspace/builtin-capabilities.ts +1 -0
  79. package/packages/core/src/ports/workspace/create.ts +2 -0
  80. package/packages/core/src/ports/workspace/git-worktree.ts +6 -1
  81. package/packages/core/src/ports/workspace/provider-capabilities.ts +1 -0
  82. package/packages/core/src/ports/workspace/vercel-sandbox.ts +125 -35
  83. package/packages/core/src/processes/build-runner.ts +32 -1
  84. package/packages/core/src/processes/dispatcher.ts +23 -0
  85. package/packages/core/src/processes/execution-settlement.ts +21 -3
  86. package/packages/core/src/processes/harvest-runner.ts +68 -8
  87. package/packages/core/src/project-secrets.ts +105 -0
  88. package/packages/core/src/secret-name.ts +41 -0
  89. package/packages/core/src/store/account-redaction.ts +156 -0
  90. package/packages/core/src/store/contract.ts +3 -1
  91. package/packages/core/src/store/reducer-value-shapes.json +2889 -2781
  92. package/packages/core/src/store/remote/client.ts +42 -47
  93. package/packages/core/src/store/remote/compatibility.ts +18 -0
  94. package/packages/core/src/testing/dispatch-read-budget.ts +122 -0
  95. package/packages/core/src/testing/index.ts +1 -0
  96. package/packages/core/src/testing/reduced-read-budget.ts +47 -0
  97. package/skills/guide/SKILL.md +120 -30
  98. package/skills/guide/references/accounts.md +119 -0
  99. package/skills/guide/references/merge-policy.md +1 -3
  100. package/skills/guide/references/operator-api.md +100 -47
  101. package/skills/guide/references/plugin-authoring.md +21 -0
  102. package/skills/guide/references/remote-store-protocol.md +198 -89
  103. package/skills/guide/references/remote-ticket-protocol.md +29 -49
  104. package/skills/guide/references/setup.md +34 -129
  105. package/skills/harvest/SKILL.md +3 -1
  106. package/skills/harvest-review/SKILL.md +3 -1
  107. package/skills/operate/SKILL.md +5 -6
  108. package/skills/spec/SKILL.md +1 -1
  109. package/skills/tickets/SKILL.md +3 -2
  110. package/templates/hosted-service/package.json +2 -2
  111. package/docs/hosted-dispatcher-cutover-validation.md +0 -178
  112. package/docs/hosted-dispatcher.md +0 -278
  113. package/docs/hosted-service.md +0 -304
  114. package/docs/mcp.md +0 -150
@@ -1,3 +1,4 @@
1
+ import { accountPolicy, accountGuestEnvironment } from './account-policy'
1
2
  import { gitRewrite, parseRemoteHead } from '../forge/git-rewrite'
2
3
  import { delegateCredential } from '../../store/remote/credentials'
3
4
  import type { ExecutionLaunchAuth } from './build-execution'
@@ -741,6 +742,7 @@ async function preflightBun(sandbox: VercelSandboxHandle, image: string): Promis
741
742
  }
742
743
 
743
744
  export interface VercelReadinessOptions {
745
+ accounts?: import('../../config/accounts').Accounts
744
746
  config: VercelSandboxConfig
745
747
  env: Record<string, string | undefined>
746
748
  storeRef: string
@@ -838,6 +840,9 @@ export async function validateVercelSandbox(
838
840
  if (facade.createFresh === undefined) {
839
841
  throw new Error('the configured Vercel SDK facade does not support fresh validation sandboxes')
840
842
  }
843
+ const readinessAccountPolicy = accountPolicy('allow-all', options.accounts ?? {}, options.env)
844
+ if (readinessAccountPolicy.missing.length)
845
+ throw new Error(`Missing credentials: ${readinessAccountPolicy.missing.join('; ')}`)
841
846
  const sandbox = await facade.createFresh({
842
847
  source: {
843
848
  type: 'git',
@@ -853,7 +858,7 @@ export async function validateVercelSandbox(
853
858
  ...(config.snapshotExpirationSeconds === undefined
854
859
  ? {}
855
860
  : { snapshotExpiration: config.snapshotExpirationSeconds * 1000 }),
856
- networkPolicy: 'allow-all',
861
+ networkPolicy: readinessAccountPolicy.policy,
857
862
  keepLastSnapshots: { count: VERCEL_KEEP_LAST_SNAPSHOTS, deleteEvicted: true },
858
863
  ...(options.signal === undefined ? {} : { signal: options.signal }),
859
864
  })
@@ -930,7 +935,11 @@ export async function validateVercelSandbox(
930
935
  await bootstrapRuntimes(
931
936
  sandbox,
932
937
  config,
933
- runtimeEnvironment(config, options.env),
938
+ accountGuestEnvironment(
939
+ runtimeEnvironment(config, options.env),
940
+ options.accounts ?? {},
941
+ options.env,
942
+ ),
934
943
  options.runtimeReferences ?? [],
935
944
  true,
936
945
  options.signal,
@@ -944,13 +953,18 @@ export async function validateVercelSandbox(
944
953
  `PATH=${VERCEL_BUN_BIN_PATH}:$PATH exec ${VERCEL_BUN_EXECUTABLE} ${VERCEL_AUTOBUILD_PATH}/bin/ab-init-probe.ts`,
945
954
  ],
946
955
  cwd: VERCEL_WORKSPACE_PATH,
947
- env: Object.fromEntries([
948
- ['AB_STORE', options.storeRef],
949
- ['AB_TOKEN', options.storeToken],
950
- ...config.environmentVariables
951
- .filter((name) => !['AB_TOKEN', 'AB_TICKET_URL', 'AB_TICKET_TOKEN'].includes(name))
952
- .map((name) => [name, requireVercelEnvironmentValue(options.env, name)]),
953
- ]),
956
+ env: {
957
+ ...accountGuestEnvironment(
958
+ runtimeEnvironment(config, options.env),
959
+ options.accounts ?? {},
960
+ options.env,
961
+ ),
962
+ AB_STORE: options.storeRef,
963
+ AB_TOKEN: options.storeToken,
964
+ ...(options.env.AB_CHATGPT_HOSTED_READINESS
965
+ ? { AB_CHATGPT_HOSTED_READINESS: options.env.AB_CHATGPT_HOSTED_READINESS }
966
+ : {}),
967
+ },
954
968
  }),
955
969
  )
956
970
  readiness = {
@@ -1122,6 +1136,7 @@ export interface VercelSandboxProviderOptions {
1122
1136
  facade?: VercelSandboxFacade
1123
1137
  exec?: Exec
1124
1138
  packageArchive?: () => Promise<Uint8Array>
1139
+ accounts?: () => import('../../config/accounts').Accounts
1125
1140
  runtimeReferences?: RuntimeReferencesSource
1126
1141
  /** Checkout-less seam: the repository's HTTPS GitHub origin. Default reads
1127
1142
  * `git remote get-url origin` from `repo` on the host. */
@@ -1168,6 +1183,25 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1168
1183
  private readonly facade: VercelSandboxFacade
1169
1184
  private readonly exec: Exec
1170
1185
  private readonly active = new Set<string>()
1186
+ private readonly policyLocks = new Map<string, Promise<void>>()
1187
+
1188
+ private async withPolicyLock<T>(ref: string, action: () => Promise<T>): Promise<T> {
1189
+ const previous = this.policyLocks.get(ref) ?? Promise.resolve()
1190
+ let release!: () => void
1191
+ const held = new Promise<void>((resolve) => {
1192
+ release = resolve
1193
+ })
1194
+ const queued = previous.then(() => held)
1195
+ this.policyLocks.set(ref, queued)
1196
+ await previous
1197
+ try {
1198
+ return await action()
1199
+ } finally {
1200
+ release()
1201
+ if (this.policyLocks.get(ref) === queued) this.policyLocks.delete(ref)
1202
+ }
1203
+ }
1204
+
1171
1205
  /** A failed stop leaves execution state unknown until a later stop/delete succeeds. */
1172
1206
  private readonly uncertain = new Set<string>()
1173
1207
  private readonly origins = new Map<string, ReturnType<typeof cleanGithubOrigin>>()
@@ -1204,11 +1238,13 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1204
1238
  this.observeWaitMs = options.observeWaitMs ?? VERCEL_OBSERVE_WAIT_MS
1205
1239
  this.buildExecution = {
1206
1240
  start: (input, auth) => this.start(input, auth),
1207
- observe: (identity) => this.observeExecution(identity),
1241
+ observe: (identity) =>
1242
+ this.withPolicyLock(identity.workspaceRef, () => this.observeExecution(identity)),
1208
1243
  }
1209
1244
  this.harvestExecution = {
1210
1245
  start: (input, auth) => this.startHarvestExecution(input, auth),
1211
- observe: (identity) => this.observeExecution(identity),
1246
+ observe: (identity) =>
1247
+ this.withPolicyLock(identity.workspaceRef, () => this.observeExecution(identity)),
1212
1248
  }
1213
1249
  this.orchestratorSandbox = {
1214
1250
  describe: (input) => this.describeOperatorSandbox(input),
@@ -1233,9 +1269,10 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1233
1269
  }
1234
1270
  this.publication = {
1235
1271
  rewrite: (input: Parameters<NonNullable<WorkspacePublication['rewrite']>>[0]) =>
1236
- this.publish(input),
1272
+ this.withPolicyLock(input.ref, () => this.publish(input)),
1237
1273
  isPublished: (input: { sha: string; branch: string }) => this.isPublished(input),
1238
- publish: (input: { ref: string; sha: string; branch: string }) => this.publish(input),
1274
+ publish: (input: { ref: string; sha: string; branch: string }) =>
1275
+ this.withPolicyLock(input.ref, () => this.publish(input)),
1239
1276
  }
1240
1277
  // The operator-sandbox publication path reuses the SAME capability: its
1241
1278
  // publish pushes an exact sha from any sandbox ref, including an operator
@@ -1353,7 +1390,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1353
1390
  ...(this.options.config.snapshotExpirationSeconds === undefined
1354
1391
  ? {}
1355
1392
  : { snapshotExpiration: this.options.config.snapshotExpirationSeconds * 1000 }),
1356
- networkPolicy: uploadPackPolicy(origin, readAuth),
1393
+ networkPolicy: this.billingPolicy(uploadPackPolicy(origin, readAuth)),
1357
1394
  keepLastSnapshots: { count: VERCEL_KEEP_LAST_SNAPSHOTS, deleteEvicted: true },
1358
1395
  signal: this.operationSignal(),
1359
1396
  })
@@ -1400,7 +1437,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1400
1437
  await bootstrapRuntimes(
1401
1438
  sandbox,
1402
1439
  this.options.config,
1403
- { ...runtimeEnvironment(this.options.config, this.options.env), AB_TOKEN: scopedToken },
1440
+ { ...this.guestEnvironment(), AB_TOKEN: scopedToken },
1404
1441
  currentRuntimeReferences(this.options.runtimeReferences),
1405
1442
  true,
1406
1443
  )
@@ -1519,6 +1556,21 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1519
1556
  this.origins.delete(ref)
1520
1557
  }
1521
1558
 
1559
+ private guestEnvironment(): Record<string, string> {
1560
+ return accountGuestEnvironment(
1561
+ runtimeEnvironment(this.options.config, this.options.env),
1562
+ this.options.accounts?.() ?? {},
1563
+ this.options.env,
1564
+ )
1565
+ }
1566
+
1567
+ private billingPolicy(base: NetworkPolicy, ref?: string): NetworkPolicy {
1568
+ if (ref?.startsWith('autobuild-sandbox-')) return base
1569
+ const result = accountPolicy(base, this.options.accounts?.() ?? {}, this.options.env)
1570
+ if (result.missing.length) throw new Error(`Missing credentials: ${result.missing.join('; ')}`)
1571
+ return result.policy
1572
+ }
1573
+
1522
1574
  private async normalNetworkPolicy(ref: string): Promise<{
1523
1575
  origin: ReturnType<typeof cleanGithubOrigin>
1524
1576
  policy: NetworkPolicy
@@ -1527,11 +1579,14 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1527
1579
  this.origins.set(ref, origin)
1528
1580
  return {
1529
1581
  origin,
1530
- policy: uploadPackPolicy(
1531
- origin,
1532
- this.options.config.gitPasswordEnv === undefined
1533
- ? undefined
1534
- : `Basic ${Buffer.from(`${requireVercelEnvironmentValue(this.options.env, this.options.config.gitUsernameEnv!)}:${requireVercelEnvironmentValue(this.options.env, this.options.config.gitPasswordEnv)}`).toString('base64')}`,
1582
+ policy: this.billingPolicy(
1583
+ uploadPackPolicy(
1584
+ origin,
1585
+ this.options.config.gitPasswordEnv === undefined
1586
+ ? undefined
1587
+ : `Basic ${Buffer.from(`${requireVercelEnvironmentValue(this.options.env, this.options.config.gitUsernameEnv!)}:${requireVercelEnvironmentValue(this.options.env, this.options.config.gitPasswordEnv)}`).toString('base64')}`,
1588
+ ),
1589
+ ref,
1535
1590
  ),
1536
1591
  }
1537
1592
  }
@@ -1591,7 +1646,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1591
1646
  await bootstrapRuntimes(
1592
1647
  sandbox,
1593
1648
  this.options.config,
1594
- { ...runtimeEnvironment(this.options.config, this.options.env), AB_TOKEN: scopedToken },
1649
+ { ...this.guestEnvironment(), AB_TOKEN: scopedToken },
1595
1650
  currentRuntimeReferences(this.options.runtimeReferences),
1596
1651
  false,
1597
1652
  )
@@ -1604,9 +1659,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1604
1659
  supervision: { kind: 'environment' },
1605
1660
  }),
1606
1661
  }
1607
- for (const name of this.options.config.environmentVariables)
1608
- if (!['AB_TOKEN', 'AB_TICKET_URL', 'AB_TICKET_TOKEN'].includes(name))
1609
- env[name] = requireVercelEnvironmentValue(this.options.env, name)
1662
+ Object.assign(env, this.guestEnvironment())
1610
1663
  const command = (await sandbox.runCommand({
1611
1664
  cmd: 'sh',
1612
1665
  args: [
@@ -1814,7 +1867,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1814
1867
  ...(this.options.config.snapshotExpirationSeconds === undefined
1815
1868
  ? {}
1816
1869
  : { snapshotExpiration: this.options.config.snapshotExpirationSeconds * 1000 }),
1817
- networkPolicy: uploadPackPolicy(origin, readAuth),
1870
+ networkPolicy: this.billingPolicy(uploadPackPolicy(origin, readAuth)),
1818
1871
  keepLastSnapshots: { count: VERCEL_KEEP_LAST_SNAPSHOTS, deleteEvicted: true },
1819
1872
  signal: this.operationSignal(),
1820
1873
  })
@@ -1855,7 +1908,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1855
1908
  await bootstrapRuntimes(
1856
1909
  sandbox,
1857
1910
  this.options.config,
1858
- { ...runtimeEnvironment(this.options.config, this.options.env), AB_TOKEN: scopedToken },
1911
+ { ...this.guestEnvironment(), AB_TOKEN: scopedToken },
1859
1912
  currentRuntimeReferences(this.options.runtimeReferences),
1860
1913
  true,
1861
1914
  )
@@ -1892,7 +1945,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1892
1945
  await bootstrapRuntimes(
1893
1946
  sandbox,
1894
1947
  this.options.config,
1895
- { ...runtimeEnvironment(this.options.config, this.options.env), AB_TOKEN: scopedToken },
1948
+ { ...this.guestEnvironment(), AB_TOKEN: scopedToken },
1896
1949
  currentRuntimeReferences(this.options.runtimeReferences),
1897
1950
  false,
1898
1951
  )
@@ -1915,9 +1968,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1915
1968
  : {}),
1916
1969
  [HARVEST_RUNNER_OPTIONS_ENV]: JSON.stringify(envelope),
1917
1970
  }
1918
- for (const envName of this.options.config.environmentVariables)
1919
- if (!['AB_TOKEN', 'AB_TICKET_URL', 'AB_TICKET_TOKEN'].includes(envName))
1920
- env[envName] = requireVercelEnvironmentValue(this.options.env, envName)
1971
+ Object.assign(env, this.guestEnvironment())
1921
1972
  const command = (await sandbox.runCommand({
1922
1973
  cmd: 'sh',
1923
1974
  args: [
@@ -1988,6 +2039,39 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1988
2039
  )
1989
2040
  }
1990
2041
  }
2042
+ let attention: string | undefined
2043
+ const accounts = this.options.accounts?.() ?? {}
2044
+ // Preserve legacy observation: without accounts there is no credential
2045
+ // policy to refresh, and no additional provider write or failure point.
2046
+ if (Object.keys(accounts).length) {
2047
+ const origin =
2048
+ this.origins.get(identity.workspaceRef) ?? cleanGithubOrigin(await this.origin())
2049
+ const base = uploadPackPolicy(
2050
+ origin,
2051
+ this.options.config.gitPasswordEnv === undefined
2052
+ ? undefined
2053
+ : `Basic ${Buffer.from(`${requireVercelEnvironmentValue(this.options.env, this.options.config.gitUsernameEnv!)}:${requireVercelEnvironmentValue(this.options.env, this.options.config.gitPasswordEnv)}`).toString('base64')}`,
2054
+ )
2055
+ const refreshed = accountPolicy(base, accounts, this.options.env)
2056
+ try {
2057
+ await sandbox.update(
2058
+ { networkPolicy: refreshed.policy },
2059
+ { signal: this.operationSignal() },
2060
+ )
2061
+ } catch {
2062
+ await sandbox.stop({ signal: this.operationSignal() })
2063
+ return { state: 'lost', attention: 'Account policy renewal failed; sandbox stopped' }
2064
+ }
2065
+ if (refreshed.missing.length) {
2066
+ attention = `Missing credentials: ${refreshed.missing.join('; ')}`
2067
+ // The updated policy fences the missing account by removing its bearer
2068
+ // transform. Its next request fails authentication through the runtime's
2069
+ // account-specific recovery path. Keep other routes in this guest alive:
2070
+ // declarations include unused accounts and do not identify active sessions.
2071
+ }
2072
+ }
2073
+ const diagnosed = (observation: ExecutionObservation): ExecutionObservation =>
2074
+ attention === undefined ? observation : { ...observation, attention }
1991
2075
  let observation: ExecutionObservation
1992
2076
  try {
1993
2077
  const command = await sandbox.getCommand(identity.commandId, {
@@ -2006,7 +2090,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
2006
2090
  observation = { state: 'ended', exitCode: finished.exitCode }
2007
2091
  } catch (error) {
2008
2092
  if (isMissingVercelSandbox(error)) observation = { state: 'lost' }
2009
- else if (isInterruptedLongPoll(error)) return { state: 'running' }
2093
+ else if (isInterruptedLongPoll(error)) return diagnosed({ state: 'running' })
2010
2094
  else throw error
2011
2095
  }
2012
2096
  }
@@ -2017,7 +2101,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
2017
2101
  // Deliberately outside the lookup/wait catch: an ambiguous stop must not
2018
2102
  // become proof of loss or command exit, even when its error resembles a
2019
2103
  // transport interruption.
2020
- return settled(observation)
2104
+ return settled(diagnosed(observation))
2021
2105
  }
2022
2106
 
2023
2107
  // ── Operator sandbox capability (AUT-340) ─────────────────────────
@@ -2581,7 +2665,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
2581
2665
  if (!token) {
2582
2666
  throw new Error('vercel-sandbox publication requires GITHUB_TOKEN or GH_TOKEN')
2583
2667
  }
2584
- const { origin, policy: normal } = await this.normalNetworkPolicy(input.ref)
2668
+ const { origin } = await this.normalNetworkPolicy(input.ref)
2585
2669
  const sandbox =
2586
2670
  this.sessions.get(input.ref) ?? (await this.facade.get(input.ref, this.operationSignal()))
2587
2671
  if (sandbox === null) throw new Error(`unknown sandbox ${input.ref}`)
@@ -2633,7 +2717,10 @@ export class VercelSandboxProvider implements WorkspaceProvider {
2633
2717
  },
2634
2718
  }
2635
2719
  try {
2636
- await sandbox.update({ networkPolicy: publicationPolicy }, { signal: this.operationSignal() })
2720
+ await sandbox.update(
2721
+ { networkPolicy: this.billingPolicy(publicationPolicy, input.ref) },
2722
+ { signal: this.operationSignal() },
2723
+ )
2637
2724
  if (input.expected !== undefined) {
2638
2725
  const capability = gitRewrite(async (cmd) => {
2639
2726
  const result = await sandbox.runCommand({
@@ -2685,7 +2772,10 @@ export class VercelSandboxProvider implements WorkspaceProvider {
2685
2772
  await sandbox.stop({ signal: this.operationSignal() })
2686
2773
  } finally {
2687
2774
  try {
2688
- await sandbox.update({ networkPolicy: normal }, { signal: this.operationSignal() })
2775
+ await sandbox.update(
2776
+ { networkPolicy: (await this.normalNetworkPolicy(input.ref)).policy },
2777
+ { signal: this.operationSignal() },
2778
+ )
2689
2779
  } finally {
2690
2780
  await sandbox.stop({ signal: this.operationSignal() })
2691
2781
  }
@@ -1,3 +1,4 @@
1
+ import { accountRedactor, redactAccountStore } from '../store/account-redaction'
1
2
  import {
2
3
  capturedBuildConfig,
3
4
  refreshVerifyCycle,
@@ -755,6 +756,7 @@ export class BuildRunner {
755
756
  runtime: old.runner,
756
757
  model: old.model,
757
758
  args: old.args ?? [],
759
+ account: old.account,
758
760
  sessionBudgetSeconds: (old.budgetMs ?? resolved.sessionBudgetSeconds * 1000) / 1000,
759
761
  }
760
762
  }
@@ -908,6 +910,15 @@ export class BuildRunner {
908
910
  private boundaryResolver: RuntimeResolver
909
911
 
910
912
  constructor(private readonly deps: BuildRunnerDeps) {
913
+ const redactor = accountRedactor(
914
+ () => this.boundaryConfig?.accounts ?? deps.config.accounts,
915
+ () => ({
916
+ ...process.env,
917
+ ...deps.sessionEnv,
918
+ }),
919
+ )
920
+ deps.store = redactAccountStore(deps.store, redactor)
921
+
911
922
  this.deps = {
912
923
  ...deps,
913
924
  store: withDrainingExecution(
@@ -926,6 +937,7 @@ export class BuildRunner {
926
937
  deps.runtimes,
927
938
  deps.config.roles,
928
939
  deps.config.policy.sessionBudgetSeconds,
940
+ deps.config.accounts,
929
941
  )
930
942
  }
931
943
 
@@ -938,6 +950,7 @@ export class BuildRunner {
938
950
  this.deps.runtimes,
939
951
  config.roles,
940
952
  config.policy.sessionBudgetSeconds,
953
+ config.accounts,
941
954
  )
942
955
  return config
943
956
  }
@@ -2722,6 +2735,7 @@ export class BuildRunner {
2722
2735
  session,
2723
2736
  role: step,
2724
2737
  runner: target.runtime,
2738
+ ...(target.account === undefined ? {} : { account: target.account }),
2725
2739
  ...(target.model !== undefined ? { model: target.model } : {}),
2726
2740
  phase: 'finalize',
2727
2741
  round: 1,
@@ -2734,6 +2748,7 @@ export class BuildRunner {
2734
2748
  session,
2735
2749
  role: step,
2736
2750
  runner: target.runtime,
2751
+ ...(target.account === undefined ? {} : { account: target.account }),
2737
2752
  ...(target.model !== undefined ? { model: target.model } : {}),
2738
2753
  args: [...target.args],
2739
2754
  phase: 'finalize',
@@ -2757,6 +2772,7 @@ export class BuildRunner {
2757
2772
  invocation: slug,
2758
2773
  buildSlug: slug,
2759
2774
  workspacePath,
2775
+ ...(target.account === undefined ? {} : { account: target.account }),
2760
2776
  ...(target.model !== undefined ? { model: target.model } : {}),
2761
2777
  ...(target.args !== undefined ? { args: target.args } : {}),
2762
2778
  env: await this.sessionEnvFor('finalize@1', session, step),
@@ -2835,6 +2851,7 @@ export class BuildRunner {
2835
2851
  index,
2836
2852
  session,
2837
2853
  runner: target.runtime,
2854
+ ...(target.account === undefined ? {} : { account: target.account }),
2838
2855
  ...(target.model !== undefined ? { model: target.model } : {}),
2839
2856
  error: failure.message,
2840
2857
  ...(failure.cause !== undefined ? { cause: failure.cause } : {}),
@@ -2872,6 +2889,7 @@ export class BuildRunner {
2872
2889
  session,
2873
2890
  role: step,
2874
2891
  runner: runnerName,
2892
+ ...(resolved.account === undefined ? {} : { account: resolved.account }),
2875
2893
  ...(model !== undefined ? { model } : {}),
2876
2894
  phase: 'finalize',
2877
2895
  round: 1,
@@ -2885,6 +2903,7 @@ export class BuildRunner {
2885
2903
  session,
2886
2904
  role: step,
2887
2905
  runner: runnerName,
2906
+ ...(resolved.account === undefined ? {} : { account: resolved.account }),
2888
2907
  ...(model !== undefined ? { model } : {}),
2889
2908
  args: [...args],
2890
2909
  phase: 'finalize',
@@ -2905,6 +2924,7 @@ export class BuildRunner {
2905
2924
  invocation: slug,
2906
2925
  buildSlug: slug,
2907
2926
  workspacePath,
2927
+ ...(resolved.account === undefined ? {} : { account: resolved.account }),
2908
2928
  ...(model !== undefined ? { model } : {}),
2909
2929
  ...(args !== undefined ? { args } : {}),
2910
2930
  env: await this.sessionEnvFor('finalize@1', session, step),
@@ -3482,6 +3502,7 @@ export class BuildRunner {
3482
3502
  runtime: primary.runtime,
3483
3503
  model: primary.model,
3484
3504
  args: primary.args,
3505
+ account: primary.account,
3485
3506
  })
3486
3507
  let primaryLive =
3487
3508
  spec.producerPhase !== undefined ? this.producerSessions.get(spec.producerPhase) : undefined
@@ -3507,6 +3528,7 @@ export class BuildRunner {
3507
3528
  session,
3508
3529
  role: spec.role,
3509
3530
  runner: target.runtime,
3531
+ ...(target.account === undefined ? {} : { account: target.account }),
3510
3532
  ...(target.model !== undefined ? { model: target.model } : {}),
3511
3533
  phase: spec.phase,
3512
3534
  round: spec.round,
@@ -3519,6 +3541,7 @@ export class BuildRunner {
3519
3541
  session,
3520
3542
  role: spec.role,
3521
3543
  runner: target.runtime,
3544
+ ...(target.account === undefined ? {} : { account: target.account }),
3522
3545
  ...(target.model !== undefined ? { model: target.model } : {}),
3523
3546
  args: [...target.args],
3524
3547
  phase: spec.phase,
@@ -3554,6 +3577,7 @@ export class BuildRunner {
3554
3577
  invocation: slug,
3555
3578
  buildSlug: slug,
3556
3579
  workspacePath,
3580
+ ...(target.account === undefined ? {} : { account: target.account }),
3557
3581
  ...(target.model !== undefined ? { model: target.model } : {}),
3558
3582
  ...(target.args !== undefined ? { args: target.args } : {}),
3559
3583
  env: await this.sessionEnvFor(spec.abPhase, session),
@@ -3747,6 +3771,7 @@ export class BuildRunner {
3747
3771
  index,
3748
3772
  session,
3749
3773
  runner: target.runtime,
3774
+ ...(target.account === undefined ? {} : { account: target.account }),
3750
3775
  ...(target.model !== undefined ? { model: target.model } : {}),
3751
3776
  error: failure.message,
3752
3777
  ...(failure.cause !== undefined ? { cause: failure.cause } : {}),
@@ -3785,13 +3810,14 @@ export class BuildRunner {
3785
3810
  // the runtime/model on the same payload say what was resolved.
3786
3811
  const resolved = this.resolveSessionRole(spec.role, ...(spec.roleAliases ?? []))
3787
3812
  const { runner, runtime: runnerName, model, args, sessionBudgetSeconds } = resolved
3788
- const route = JSON.stringify({ runtime: runnerName, model, args })
3813
+ const route = JSON.stringify({ runtime: runnerName, model, args, account: resolved.account })
3789
3814
  // SPEC §9: the stream opens before the bracket's first turn — its id is
3790
3815
  // already known when `session.started` appends.
3791
3816
  const streamBracket = await this.openSessionStream(resolved, {
3792
3817
  session,
3793
3818
  role: spec.role,
3794
3819
  runner: runnerName,
3820
+ ...(resolved.account === undefined ? {} : { account: resolved.account }),
3795
3821
  ...(model !== undefined ? { model } : {}),
3796
3822
  phase: spec.phase,
3797
3823
  round: spec.round,
@@ -3818,6 +3844,7 @@ export class BuildRunner {
3818
3844
  session,
3819
3845
  role: spec.role,
3820
3846
  runner: runnerName,
3847
+ ...(resolved.account === undefined ? {} : { account: resolved.account }),
3821
3848
  ...(model !== undefined ? { model } : {}),
3822
3849
  args: [...args],
3823
3850
  phase: spec.phase,
@@ -3857,6 +3884,7 @@ export class BuildRunner {
3857
3884
  invocation: slug,
3858
3885
  buildSlug: slug,
3859
3886
  workspacePath,
3887
+ ...(resolved.account === undefined ? {} : { account: resolved.account }),
3860
3888
  ...(model !== undefined ? { model } : {}),
3861
3889
  ...(args !== undefined ? { args } : {}),
3862
3890
  env: await this.sessionEnvFor(spec.abPhase, session),
@@ -4229,6 +4257,9 @@ export class BuildRunner {
4229
4257
  )
4230
4258
  : undefined
4231
4259
  return {
4260
+ AB_ACCOUNT_CREDENTIAL_ENVS: JSON.stringify(
4261
+ Object.values(this.boundaryConfig.accounts).map((account) => account.credentialEnv),
4262
+ ),
4232
4263
  AB_STORE: 'local',
4233
4264
  ...this.deps.sessionEnv,
4234
4265
  ...(token ? { AB_TOKEN: token } : {}),
@@ -551,6 +551,8 @@ export interface TickOpts {
551
551
  * resume, lease sweep, and in-flight runners continue. Absent defaults true.
552
552
  */
553
553
  acceptNewWork?: boolean
554
+ /** Repair/settle active execution policies only; suppress all intake and launches. */
555
+ observationOnly?: boolean
554
556
  /**
555
557
  * Repository-derived claim-time default supplied by the CLI for this tick.
556
558
  * True records the existing durable auto-merge request only on builds
@@ -980,6 +982,7 @@ export class Dispatcher {
980
982
  await this.settleHarvestExecutions(opts)
981
983
  if (this.outOfBudget(opts)) return report
982
984
  await this.settleOrchestratorSandboxes(report, opts)
985
+ if (opts.observationOnly) return report
983
986
  if (this.outOfBudget(opts)) return report
984
987
  // The default fan-out runs before the janitor so one tick both records the
985
988
  // consent and lets the janitor act on it (the janitor reduces a fresh read
@@ -1387,6 +1390,7 @@ export class Dispatcher {
1387
1390
  {
1388
1391
  store: this.store,
1389
1392
  execution,
1393
+ ids: this.deps.ids,
1390
1394
  ...(this.settlePublication !== undefined
1391
1395
  ? { settlePublication: this.settlePublication }
1392
1396
  : {}),
@@ -1437,6 +1441,25 @@ export class Dispatcher {
1437
1441
  ...(execution.sessionId !== undefined ? { sessionId: execution.sessionId } : {}),
1438
1442
  commandId: execution.commandId,
1439
1443
  })
1444
+ if (observation.attention) {
1445
+ const current = this.store.repositoryFacts()
1446
+ const authorization = current.harvestAuthorizations[JSON.stringify(execution.execution)]
1447
+ const run = current.harvest.runs.find((run) => run.run === authorization?.payload.run)
1448
+ // A model session has a durable run authorization. Escalation is
1449
+ // terminal and deduplicates across ticks and dispatcher restarts;
1450
+ // the execution itself remains observable until its command exits.
1451
+ if (run?.status === 'running')
1452
+ await this.store.appendRepo(this.deps.repo, {
1453
+ actor: KERNEL,
1454
+ type: 'harvest.escalated',
1455
+ payload: {
1456
+ run: run.run,
1457
+ source: 'policy',
1458
+ reason: observation.attention,
1459
+ observations: run.observations,
1460
+ },
1461
+ })
1462
+ }
1440
1463
  // Conservatism: an unresolvable observation (provider error) throws
1441
1464
  // and is contained below — it never reaps.
1442
1465
  if (observation.state === 'running') continue
@@ -1,3 +1,4 @@
1
+ import { randomIds, type IdSource } from '../ids'
1
2
  /**
2
3
  * Settlement of foreign build executions from durable facts plus provider
3
4
  * liveness (AUT-301). Today's completion handling hangs off the in-memory
@@ -11,7 +12,7 @@
11
12
  * is treated as `running`. Supervision decisions reap or settle only on
12
13
  * provider proof, never on an unknown.
13
14
  */
14
- import { DISPATCHER } from '../events/envelope'
15
+ import { DISPATCHER, KERNEL } from '../events/envelope'
15
16
  import type { AbEvent, EventWrite } from '../events/catalog'
16
17
  import type {
17
18
  BuildExecution,
@@ -121,11 +122,12 @@ function observationIdentity(open: {
121
122
  * a recorded completion was written and publication was settled; `lost` means
122
123
  * the provider proved the execution gone without an exit code (publication is
123
124
  * deliberately left to the existing abandonment flow); `running` means the
124
- * guest is alive or unknowable — no writes. */
125
+ * guest is alive or unknowable. Independent host attention may still be recorded. */
125
126
  export type ExecutionSettlement = 'running' | 'settled' | 'lost'
126
127
 
127
128
  export interface ExecutionSettlementDeps {
128
129
  store: BuildStore
130
+ ids?: IdSource
129
131
  /** The observing provider's executor. Settlement requires the `observe`
130
132
  * capability; without it the caller supervises as before. */
131
133
  execution: BuildExecution
@@ -163,7 +165,7 @@ export function settleExecution(
163
165
  /** `settleExecution` over an already-derived open execution, for callers that
164
166
  * hold the projection (a reducer snapshot advanced to the log tail) and so
165
167
  * never need the event array. A `running` result or an observation error
166
- * touches no event rows. */
168
+ * touches no event rows unless the provider also reports actionable attention. */
167
169
  export async function settleOpenExecution(
168
170
  deps: ExecutionSettlementDeps,
169
171
  slug: string,
@@ -177,6 +179,22 @@ export async function settleOpenExecution(
177
179
  } catch {
178
180
  return 'running'
179
181
  }
182
+ if (observation.attention) {
183
+ const state = (await readBuildFacts(deps.store, slug)).value.state
184
+ if (!state.openEscalations.some((entry) => entry.question === observation.attention))
185
+ await deps.store.append(slug, {
186
+ actor: KERNEL,
187
+ type: 'escalation.raised',
188
+ payload: {
189
+ id: (deps.ids ?? randomIds())('esc'),
190
+ phase: state.phase ?? 'setup',
191
+ ...(state.round > 0 ? { round: state.round } : {}),
192
+ source: 'policy',
193
+ policyCause: 'non-retryable-phase-failure',
194
+ question: observation.attention,
195
+ },
196
+ })
197
+ }
180
198
  if (observation.state === 'running') return 'running'
181
199
 
182
200
  const request = (await readBuildFacts(deps.store, slug)).value.state.drainingExecutions?.[