@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
@@ -266,9 +266,9 @@ const buildControlInput = z.strictObject({
266
266
  repo: repoField,
267
267
  slug: slugField,
268
268
  action: z
269
- .enum(['pause', 'cancel-pause', 'resume', 'land', 'hold', 'abort', 'discard'])
269
+ .enum(['pause', 'cancel-pause', 'resume', 'merge', 'land', 'hold', 'abort', 'discard'])
270
270
  .describe(
271
- 'Control to request: "pause" (or "cancel-pause" to revoke a pending pause), "resume" a paused build, "land" for landing consent or "hold" to withdraw consent — or the destructive "abort" (cancels the build, cleans up its PR and workspace, returns the ticket to triage) and "discard" (dequeue a queued build).',
271
+ 'Control to request: "pause" (or "cancel-pause" to revoke a pending pause), "resume" a paused build, "merge" (deprecated alias "land") for merge consent or "hold" to withdraw consent — or the destructive "abort" (cancels the build, cleans up its PR and workspace, returns the ticket to triage) and "discard" (dequeue a queued build).',
272
272
  ),
273
273
  })
274
274
 
@@ -311,6 +311,18 @@ const ticketsListInput = z.strictObject({
311
311
  .array(z.string().min(1))
312
312
  .optional()
313
313
  .describe('Narrow the list to tickets carrying every named label.'),
314
+ limit: z
315
+ .number()
316
+ .int()
317
+ .min(0)
318
+ .max(200)
319
+ .optional()
320
+ .describe('Return at most this many tickets; `total` still counts every match.'),
321
+ offset: z.number().int().min(0).optional().describe('Skip this many tickets first.'),
322
+ order: z
323
+ .enum(['oldest', 'newest'])
324
+ .optional()
325
+ .describe('Oldest first (the source order, the default) or newest first.'),
314
326
  })
315
327
 
316
328
  const ticketsCreateInput = ticketCreateRequestSchema.extend({ repo: repoField })
@@ -478,9 +490,16 @@ function defineTool(
478
490
  * here and a row in `operator/annotations.ts`; the contract suite proves the
479
491
  * two stay in lockstep. */
480
492
  export const TOOLS: readonly ToolEntry[] = [
493
+ defineTool(
494
+ 'merges.list',
495
+ 'List ready merges awaiting consent or held, with frozen effective targets and verification evidence.',
496
+ repositoryStatusInput,
497
+ 'JSON array ordered by slug: kind, target, branch, candidate, reason, verification and node completeness.',
498
+ async (raw, ctx) => listOperatorLandings({ store: ctx.store, ...(raw as { repo: string }) }),
499
+ ),
481
500
  defineTool(
482
501
  'landings.list',
483
- 'List ready landings awaiting consent or held, with frozen effective targets and verification evidence.',
502
+ 'Deprecated alias for merges.list. List ready merges awaiting consent or held, with frozen effective targets and verification evidence.',
484
503
  repositoryStatusInput,
485
504
  'JSON array ordered by slug: kind, target, branch, candidate, reason, verification and node completeness.',
486
505
  async (raw, ctx) => listOperatorLandings({ store: ctx.store, ...(raw as { repo: string }) }),
@@ -591,11 +610,15 @@ export const TOOLS: readonly ToolEntry[] = [
591
610
  ),
592
611
  defineTool(
593
612
  'builds.control',
594
- 'Pause immediately suspends a live agent session. Resume continues where stopped when supported; remote and unsupported sessions rerun fresh. Request a durable control for one active build: pause/cancel-pause, resume, hold or land — or the destructive abort and discard. Land requires a ready candidate; hold withdraws landing consent.',
613
+ 'Pause immediately suspends a live agent session. Resume continues where stopped when supported; remote and unsupported sessions rerun fresh. Request a durable control for one active build: pause/cancel-pause, resume, hold or merge — or the destructive abort and discard. Merge requires a ready candidate; hold withdraws merge consent.',
595
614
  buildControlInput,
596
615
  'Either {kind: "command", slug, command, event} for an accepted control, or {kind: "answer-required", slug, escalationIds} when a resume needs its open escalations answered first.',
597
616
  async (raw, ctx) => {
598
- const input = raw as z.infer<typeof buildControlInput>
617
+ const received = raw as z.infer<typeof buildControlInput>
618
+ const input = {
619
+ ...received,
620
+ action: received.action === 'merge' ? ('land' as const) : received.action,
621
+ }
599
622
  await controlPrechecks(ctx.store, input.repo, input.slug, input.action)
600
623
  // The route maps BOTH pause and cancel-pause to `dashboard-pause`:
601
624
  // on a running build it requests a pause, and on a build with a pending
@@ -695,7 +718,7 @@ export const TOOLS: readonly ToolEntry[] = [
695
718
  'repository.bulk_control',
696
719
  'Pause or resume the whole repository: hold queued builds, set intake, and request per-build pause/resume in one walk.',
697
720
  bulkControlInput,
698
- '{direction, slugs, paused, intake}: the direction, the slugs that received a durable request, and the repository-wide hold/intake values written. A partial walk surfaces as a refusal with code "bulk-partial" and a progress object naming what landed.',
721
+ '{direction, slugs, paused, intake}: the direction, the slugs that received a durable request, and the repository-wide hold/intake values written. A partial walk surfaces as a refusal with code "bulk-partial" and a progress object naming what merged.',
699
722
  async (raw, ctx) => {
700
723
  const input = raw as z.infer<typeof bulkControlInput>
701
724
  return bulkControlRepository({
@@ -772,7 +795,7 @@ export const TOOLS: readonly ToolEntry[] = [
772
795
  'tickets.list',
773
796
  'List the repository’s ticket grooming queue from the configured ticket source.',
774
797
  ticketsListInput,
775
- '{states, tickets, diagnostics, criteria, triageState, readyState}: the queue listing, the effective lifecycle names, and the criteria actually applied.',
798
+ '{states, tickets, diagnostics, criteria, triageState, readyState, doneState, total}: the queue listing (one page when `limit` is set), the effective lifecycle names, the criteria actually applied, and the match count before paging.',
776
799
  async (raw, ctx) => {
777
800
  const input = raw as z.infer<typeof ticketsListInput>
778
801
  return listOperatorTickets({
@@ -781,6 +804,15 @@ export const TOOLS: readonly ToolEntry[] = [
781
804
  backend: ticketsOf(ctx),
782
805
  ...(input.state !== undefined ? { state: input.state } : {}),
783
806
  ...(input.labels !== undefined ? { labels: input.labels } : {}),
807
+ ...(input.limit !== undefined
808
+ ? {
809
+ page: {
810
+ limit: input.limit,
811
+ ...(input.offset !== undefined ? { offset: input.offset } : {}),
812
+ ...(input.order !== undefined ? { order: input.order } : {}),
813
+ },
814
+ }
815
+ : {}),
784
816
  })
785
817
  },
786
818
  ),
@@ -14,7 +14,7 @@
14
14
  * a broken or unsupported config degrades the sandbox tools of one binding,
15
15
  * never the orchestrator itself.
16
16
  */
17
- import { mkdtemp } from 'node:fs/promises'
17
+ import { mkdtemp, rm } from 'node:fs/promises'
18
18
  import { tmpdir } from 'node:os'
19
19
  import { join } from 'node:path'
20
20
  import type { Config } from '../config/schema'
@@ -52,7 +52,8 @@ export interface HostedOperatorSandboxOptions {
52
52
  storeToken: string
53
53
  /** Scratch root for the composition's filesystem seams (worktree root,
54
54
  * repo root, sandbox root). Default: a fresh `mkdtemp` under the OS temp
55
- * directory. The builtin providers only touch these paths through host-git
55
+ * directory, removed on construction failure or dispose(). A supplied root
56
+ * remains caller-owned. The builtin providers only touch these paths through host-git
56
57
  * or local-scratch paths the injected seams bypass; a plugin-provider config
57
58
  * fails construction before any path use. */
58
59
  scratchRoot?: string
@@ -88,6 +89,10 @@ export function remoteBranchHeadFromForge(
88
89
  }
89
90
  }
90
91
 
92
+ export interface HostedOperatorSandboxService extends OperatorSandboxService {
93
+ dispose(): Promise<void>
94
+ }
95
+
91
96
  /** Build the hosted operator-sandbox backend from the effective config and
92
97
  * injected seams. Throws on every construction failure (unknown provider or
93
98
  * forge, missing Vercel SDK credential, forbidden forwarded env name,
@@ -95,46 +100,65 @@ export function remoteBranchHeadFromForge(
95
100
  * contains and degrades to serving without the sandbox tools. */
96
101
  export async function createHostedOperatorSandboxService(
97
102
  options: HostedOperatorSandboxOptions,
98
- ): Promise<OperatorSandboxService> {
103
+ ): Promise<HostedOperatorSandboxService> {
104
+ const ownsScratch = options.scratchRoot === undefined
99
105
  const scratch = options.scratchRoot ?? (await mkdtemp(join(tmpdir(), 'autobuild-sandbox-host-')))
100
- const forge =
101
- options.forge ??
102
- (await createForge({
103
- name: options.config.forge,
106
+ let disposal: Promise<void> | undefined
107
+ const dispose = () => {
108
+ disposal ??= ownsScratch ? rm(scratch, { recursive: true, force: true }) : Promise.resolve()
109
+ return disposal
110
+ }
111
+ try {
112
+ const forge =
113
+ options.forge ??
114
+ (await createForge({
115
+ name: options.config.forge,
116
+ registry: createPluginRegistry(),
117
+ env: options.env,
118
+ repoRoot: scratch,
119
+ repository: options.repo,
120
+ }))
121
+ if (forge.remoteBranchSha === undefined) {
122
+ throw new Error(
123
+ `the configured forge "${options.config.forge}" does not resolve remote branch heads; ` +
124
+ 'the hosted sandbox backend has no checkout to resolve base heads against',
125
+ )
126
+ }
127
+ // Builtin-only registry: a plugin-provider config fails construction here
128
+ // (unknown provider in the empty registry) and the caller contains it.
129
+ const provider = await createWorkspaceProvider(options.config.workspace, {
104
130
  registry: createPluginRegistry(),
105
- env: options.env,
131
+ worktreeRoot: scratch,
106
132
  repoRoot: scratch,
107
- repository: options.repo,
108
- }))
109
- if (forge.remoteBranchSha === undefined) {
110
- throw new Error(
111
- `the configured forge "${options.config.forge}" does not resolve remote branch heads; ` +
112
- 'the hosted sandbox backend has no checkout to resolve base heads against',
113
- )
133
+ env: options.env,
134
+ storeRef: options.storeRef,
135
+ storeToken: options.storeToken,
136
+ origin: async () => options.repo,
137
+ remoteBranchHead: remoteBranchHeadFromForge(forge),
138
+ sandboxSetupCommand: options.config.commands.setup,
139
+ sandboxRoot: join(scratch, 'orchestrator-sandboxes'),
140
+ sandboxEnvironmentVariables: options.config.orchestrator.sandbox.environmentVariables,
141
+ orchestratorSandboxEnabled: true,
142
+ })
143
+ const service = await createOperatorSandboxService({
144
+ store: options.store,
145
+ repo: options.repo,
146
+ provider,
147
+ sandbox: options.config.orchestrator.sandbox,
148
+ baseBranch: options.config.baseBranch,
149
+ forge,
150
+ ...(options.clock !== undefined ? { clock: options.clock } : {}),
151
+ })
152
+ return Object.assign(service, { dispose })
153
+ } catch (error) {
154
+ try {
155
+ await dispose()
156
+ } catch (cleanupError) {
157
+ throw new AggregateError(
158
+ [error, cleanupError],
159
+ 'Hosted sandbox construction and cleanup failed',
160
+ )
161
+ }
162
+ throw error
114
163
  }
115
- // Builtin-only registry: a plugin-provider config fails construction here
116
- // (unknown provider in the empty registry) and the caller contains it.
117
- const provider = await createWorkspaceProvider(options.config.workspace, {
118
- registry: createPluginRegistry(),
119
- worktreeRoot: scratch,
120
- repoRoot: scratch,
121
- env: options.env,
122
- storeRef: options.storeRef,
123
- storeToken: options.storeToken,
124
- origin: async () => options.repo,
125
- remoteBranchHead: remoteBranchHeadFromForge(forge),
126
- sandboxSetupCommand: options.config.commands.setup,
127
- sandboxRoot: join(scratch, 'orchestrator-sandboxes'),
128
- sandboxEnvironmentVariables: options.config.orchestrator.sandbox.environmentVariables,
129
- orchestratorSandboxEnabled: true,
130
- })
131
- return createOperatorSandboxService({
132
- store: options.store,
133
- repo: options.repo,
134
- provider,
135
- sandbox: options.config.orchestrator.sandbox,
136
- baseBranch: options.config.baseBranch,
137
- forge,
138
- ...(options.clock !== undefined ? { clock: options.clock } : {}),
139
- })
140
164
  }
@@ -142,6 +142,9 @@ export interface OperatorSandboxConfig {
142
142
  }
143
143
 
144
144
  export interface OperatorSandboxService {
145
+ /** Dispose local composition resources only; separate from release(identity, repo).
146
+ * Caller-owned static services retain their lifetime across requests. */
147
+ dispose?(): Promise<void>
145
148
  /** True when both a forge and the provider's sandbox publication
146
149
  * capability are present, i.e. `publish` is callable. */
147
150
  readonly canPublish: boolean
@@ -1,16 +1,7 @@
1
1
  import { ticketLifecycle } from '../ports/tickets/lifecycle'
2
- /**
3
- * A dispatcher ticket source as the registry's ticket backend (AUT-342):
4
- * the tick's turn runner takes an `OperatorToolRegistry`, and
5
- * `buildRegistry`'s ticket tools require an `OperatorTicketBackend` — but
6
- * the dispatcher's wiring holds a `TicketSource`, not a backend, and
7
- * `buildMcpTicketBackend` reads a checkout's autobuild.toml, which cannot
8
- * run in origin mode. This adapter hands the dispatcher's
9
- * already-constructed source straight through (it was built by
10
- * `createTicketSource` from the same effective `[tickets]` config the
11
- * `OperatorTicketContext` would derive, for the same repository) and derives
12
- * the workflow-state list from the effective config's lifecycle names.
13
- */
2
+ /** Adapt an already-constructed ticket source to the registry backend without
3
+ * reading a checkout's configuration. Lifecycle names come from the same
4
+ * effective configuration used to construct that source. */
14
5
  import type { Config } from '../config/schema'
15
6
  import type { OperatorTicketBackend, OperatorTicketContext } from './tickets'
16
7
  import type { TicketSource } from '../ports/types'
@@ -17,7 +17,14 @@ import {
17
17
  requireTicket,
18
18
  updateTicket,
19
19
  } from '../ports/tickets/operations'
20
- import type { DependencyState, Ticket, TicketSource, TicketUpdate } from '../ports/types'
20
+ import type {
21
+ DependencyState,
22
+ Ticket,
23
+ TicketSource,
24
+ TicketUpdate,
25
+ TicketPage,
26
+ TicketPageListing,
27
+ } from '../ports/types'
21
28
  import type { BuildStore } from '../store/types'
22
29
  import { ticketLifecycle } from '../ports/tickets/lifecycle'
23
30
  import { effectiveConfig } from './query'
@@ -47,8 +54,14 @@ export interface OperatorTicketQueue {
47
54
  /** Effective repository lifecycle names; clients must not invent provider states. */
48
55
  triageState: string
49
56
  readyState: string
57
+ doneState: string
58
+ /** Tickets matching the criteria before `page` sliced them. */
59
+ total: number
50
60
  }
51
61
 
62
+ /** A window over a listing. `newest` reverses the source's oldest-first order. */
63
+ export type OperatorTicketPage = TicketPage
64
+
52
65
  export interface OperatorTicketBuild {
53
66
  slug: string
54
67
  status: string
@@ -91,9 +104,11 @@ export async function listOperatorTickets(opts: {
91
104
  backend: OperatorTicketBackend
92
105
  state?: string
93
106
  labels?: string[]
107
+ page?: OperatorTicketPage
94
108
  }): Promise<OperatorTicketQueue> {
95
109
  const { context, source } = await openOperatorTickets(opts)
96
- const triageState = ticketLifecycle(context.tickets).triage
110
+ const lifecycle = ticketLifecycle(context.tickets)
111
+ const triageState = lifecycle.triage
97
112
  const readyState = context.tickets.readyState
98
113
  // The operator surface is a grooming queue. Unlike the CLI's ticket list,
99
114
  // labels narrow the default state instead of replacing its lifecycle gate.
@@ -101,17 +116,23 @@ export async function listOperatorTickets(opts: {
101
116
  state: opts.state ?? triageState,
102
117
  ...(opts.labels !== undefined ? { labels: opts.labels } : {}),
103
118
  }
119
+ const nativePage = opts.page !== undefined && source.listPage !== undefined
104
120
  const [listing, states] = await Promise.all([
105
- source.listReady(criteria),
121
+ nativePage ? source.listPage!(criteria, opts.page!) : source.listReady(criteria),
106
122
  opts.backend.statesFor(context, source),
107
123
  ])
124
+ const ordered =
125
+ !nativePage && opts.page?.order === 'newest' ? [...listing.tickets].reverse() : listing.tickets
126
+ const offset = opts.page?.offset ?? 0
108
127
  return {
109
128
  states,
110
- tickets: listing.tickets,
129
+ tickets: opts.page && !nativePage ? ordered.slice(offset, offset + opts.page.limit) : ordered,
111
130
  diagnostics: listing.diagnostics,
112
131
  criteria,
113
132
  triageState,
114
133
  readyState,
134
+ doneState: lifecycle.done,
135
+ total: nativePage ? (listing as TicketPageListing).total : listing.tickets.length,
115
136
  }
116
137
  }
117
138
 
@@ -15,7 +15,7 @@ import type {
15
15
  } from '../ports/workspace/provider-capabilities'
16
16
 
17
17
  /** Version of the in-process plugin contract exposed by `@defrex/autobuild/plugin-sdk`. */
18
- export const PLUGIN_API_VERSION = '1.8.0' as const
18
+ export const PLUGIN_API_VERSION = '1.9.0' as const
19
19
 
20
20
  /** Context supplied when a registered adapter or contract fixture is selected. */
21
21
  export interface PluginFactoryContext<Config = Record<string, unknown>> {
@@ -59,6 +59,7 @@ export interface WorkspaceProviderPluginFactoryContext<Config = Record<string, u
59
59
  /** Host-derived effective runtime routes (the referenced runtimes and their
60
60
  * selection provenance). Absent at call sites that reference no runtimes
61
61
  * (for example the MCP server), which never construct a workspace. */
62
+ accounts?: () => import('../config/accounts').Accounts
62
63
  runtimeReferences?: RuntimeReferencesSource
63
64
  /** Checkout-less seam: the repository's HTTPS origin. When absent the
64
65
  * provider falls back to host `git` from `repoRoot` — the same default the
@@ -265,7 +265,7 @@ export function describeForgeContract(name: string, factory: ForgeContractFactor
265
265
  })
266
266
  })
267
267
 
268
- test('getPrState discriminates a merged PR with its independently observed landing SHA', async () => {
268
+ test('getPrState discriminates a merged PR with its independently observed merge SHA', async () => {
269
269
  await withForge(factory, undefined, async (harness) => {
270
270
  const { pr } = await pushAndOpen(harness)
271
271
  await harness.controls.prepareMergeable(pr.number)
@@ -280,7 +280,7 @@ export function describeForgeContract(name: string, factory: ForgeContractFactor
280
280
  })
281
281
  })
282
282
 
283
- test('identity-aware squash exposes the actual landed trailer when inspection is supported', async () => {
283
+ test('identity-aware squash exposes the actual merged trailer when inspection is supported', async () => {
284
284
  await withForge(factory, undefined, async (harness) => {
285
285
  const { pr } = await pushAndOpen(harness)
286
286
  await harness.controls.prepareMergeable(pr.number)
@@ -1,3 +1,4 @@
1
+ import { classifyGitNetworkFailure } from '../forge-failure'
1
2
  import type { ForgeRewrite, RewriteResult } from '../types'
2
3
  import type { Exec } from '../workspace/git-worktree'
3
4
  import { isValidGitBranchName } from '../../kernel/origin'
@@ -16,7 +17,18 @@ function branchRef(branch: string): string {
16
17
  * never consults a remote, even when the repository happens to have one. */
17
18
  export function gitRewrite(exec: Exec, local: boolean): ForgeRewrite {
18
19
  async function git(cwd: string, args: string[], allowFailure = false) {
19
- const result = await exec(['git', ...args], { cwd })
20
+ const network = !local && ['push', 'fetch', 'ls-remote'].includes(args[0] ?? '')
21
+ let result: Awaited<ReturnType<Exec>>
22
+ try {
23
+ result = await exec(['git', ...args], { cwd })
24
+ } catch (error) {
25
+ throw network ? classifyGitNetworkFailure(error) : error
26
+ }
27
+ if (network && result.exitCode !== 0) {
28
+ const original = new Error(result.stderr || result.stdout)
29
+ const classified = classifyGitNetworkFailure(original)
30
+ if (classified !== original) throw classified
31
+ }
20
32
  if (!allowFailure && result.exitCode !== 0)
21
33
  throw new Error(
22
34
  `reconcile git ${args.join(' ')} failed: ${result.stderr || result.stdout}; enable refs/autobuild/archive/ publication and guarded build-branch rewrites`,
@@ -224,7 +236,18 @@ export async function refreshBranchCache(
224
236
  object(sha)
225
237
  if (!isValidGitBranchName(branch)) throw new Error('invalid publication branch')
226
238
  const run = async (args: string[]) => {
227
- const result = await exec(['git', ...args], { cwd })
239
+ const network = ['push', 'fetch', 'ls-remote'].includes(args[0] ?? '')
240
+ let result: Awaited<ReturnType<Exec>>
241
+ try {
242
+ result = await exec(['git', ...args], { cwd })
243
+ } catch (error) {
244
+ throw network ? classifyGitNetworkFailure(error) : error
245
+ }
246
+ if (network && result.exitCode !== 0) {
247
+ const original = new Error(result.stderr || result.stdout)
248
+ const classified = classifyGitNetworkFailure(original)
249
+ if (classified !== original) throw classified
250
+ }
228
251
  if (result.exitCode !== 0)
229
252
  throw new Error(`publication cache ${args.join(' ')} failed: ${result.stderr}`)
230
253
  }
@@ -404,8 +404,8 @@ export async function inspectGitHubReadiness(opts: {
404
404
  'root-freshness',
405
405
  rootFence ? 'pass' : 'fail',
406
406
  rootFence
407
- ? `Root ${opts.input.rootBranch} enforces strict nonempty checks for all actors: fenced landing.`
408
- : `Root ${opts.input.rootBranch} does not enforce strict nonempty checks for all actors: best-effort landing.`,
407
+ ? `Root ${opts.input.rootBranch} enforces strict nonempty checks for all actors: fenced merge.`
408
+ : `Root ${opts.input.rootBranch} does not enforce strict nonempty checks for all actors: best-effort merge.`,
409
409
  )
410
410
  } catch {
411
411
  /* No vacuous success on incomplete target or policy reads. */
@@ -1,5 +1,10 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks'
2
- import { isForgeFailure, type ForgeRequestObserver } from '../forge-failure'
2
+ import {
3
+ classifyGitNetworkFailure,
4
+ ForgeFailure,
5
+ isForgeFailure,
6
+ type ForgeRequestObserver,
7
+ } from '../forge-failure'
3
8
  import {
4
9
  forgeRequestContext,
5
10
  guardedForgeRequest,
@@ -621,9 +626,23 @@ export class GitHubForge implements Forge {
621
626
  GIT_CONFIG_VALUE_6: '',
622
627
  },
623
628
  })
624
- return { ...result, stdout: redact(result.stdout), stderr: redact(result.stderr) }
629
+ const safe = { ...result, stdout: redact(result.stdout), stderr: redact(result.stderr) }
630
+ if (
631
+ result.exitCode !== 0 &&
632
+ cmd.some((arg) => ['push', 'fetch', 'ls-remote'].includes(arg))
633
+ ) {
634
+ const original = new Error(safe.stderr || safe.stdout)
635
+ const classified = classifyGitNetworkFailure(original)
636
+ if (classified !== original) throw classified
637
+ }
638
+ return safe
625
639
  } catch (error) {
626
- if (isForgeFailure(error) || error instanceof ForgeRequestDeferred) throw error
640
+ if (error instanceof ForgeRequestDeferred) throw error
641
+ const classified = cmd.some((arg) => ['push', 'fetch', 'ls-remote'].includes(arg))
642
+ ? classifyGitNetworkFailure(error)
643
+ : error
644
+ if (isForgeFailure(classified))
645
+ throw new ForgeFailure(redact(classified.message), classified.details)
627
646
  throw new Error(redact(error instanceof Error ? error.message : String(error)))
628
647
  }
629
648
  }
@@ -1227,7 +1246,7 @@ export class GitHubForge implements Forge {
1227
1246
  base: z.object({ ref: z.string() }),
1228
1247
  head: z.object({ ref: z.string(), sha: z.string() }),
1229
1248
  })
1230
- const pr = this.parse(schema, response, `node landing PR #${number}`)
1249
+ const pr = this.parse(schema, response, `node merge PR #${number}`)
1231
1250
  return {
1232
1251
  base: pr.base.ref,
1233
1252
  head: pr.head.ref,
@@ -1387,7 +1406,7 @@ export class GitHubForge implements Forge {
1387
1406
  }
1388
1407
  if (requireIdentity && parsed.some((rule) => rule.type === 'merge_queue')) {
1389
1408
  return unproven(
1390
- 'GitHub merge queues ignore squash message overrides; land through a human or change the queue policy to preserve Autobuild-Build identity',
1409
+ 'GitHub merge queues ignore squash message overrides; merge through a human or change the queue policy to preserve Autobuild-Build identity',
1391
1410
  )
1392
1411
  }
1393
1412
  rulesetGate =
@@ -1671,7 +1690,7 @@ export class GitHubForge implements Forge {
1671
1690
  }
1672
1691
  if (data.repository.mergeQueue !== null) {
1673
1692
  throw new Error(
1674
- 'GitHub merge queues ignore squash message overrides; land through a human or change the queue policy to preserve Autobuild-Build identity',
1693
+ 'GitHub merge queues ignore squash message overrides; merge through a human or change the queue policy to preserve Autobuild-Build identity',
1675
1694
  )
1676
1695
  }
1677
1696
  return message
@@ -1756,7 +1775,7 @@ export class GitHubForge implements Forge {
1756
1775
  const view = await this.getJson(
1757
1776
  z.object({ commit: z.object({ message: z.string() }) }),
1758
1777
  `repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/commits/${encodeURIComponent(sha)}`,
1759
- 'landed commit message',
1778
+ 'merged commit message',
1760
1779
  )
1761
1780
  return view.commit.message
1762
1781
  }
@@ -357,7 +357,7 @@ export class LocalGitForge implements Forge {
357
357
  )
358
358
  if (result.exitCode === 0) return true
359
359
  if (result.exitCode === 1) return false
360
- throw new Error(`local-git could not compare landing ancestry: ${result.stderr.trim()}`)
360
+ throw new Error(`local-git could not compare merge ancestry: ${result.stderr.trim()}`)
361
361
  }
362
362
 
363
363
  /** Apply Git's two-tree fast-forward operation. It carries index/worktree
@@ -402,7 +402,7 @@ export class LocalGitForge implements Forge {
402
402
  throw new Error(`PR #${number} is no longer open`)
403
403
  await this.updateRecord(workspacePath, number, (current) => {
404
404
  if (current.status !== 'open' || current.pendingLanding)
405
- throw new Error(`PR #${number} is landing or terminal`)
405
+ throw new Error(`PR #${number} is merging or terminal`)
406
406
  return { ...current, base }
407
407
  })
408
408
  if ((await this.inspectLandingPr(workspacePath, number)).base !== base)
@@ -412,7 +412,7 @@ export class LocalGitForge implements Forge {
412
412
  async inspectLandingPr(workspacePath: string, number: number) {
413
413
  const { record } = await this.readRecord(workspacePath, number)
414
414
  if (record.status === 'merged' && !record.mergedHeadSha)
415
- throw new Error('historical local-git landing has no frozen source head')
415
+ throw new Error('historical local-git merge has no frozen source head')
416
416
  return {
417
417
  base: record.base,
418
418
  head: record.head,
@@ -697,7 +697,7 @@ export class LocalGitForge implements Forge {
697
697
  true,
698
698
  )
699
699
  if (moved.exitCode !== 0) {
700
- throw new Error(`local-git base ${baseRef} moved before squash landing`)
700
+ throw new Error(`local-git base ${baseRef} moved before squash merge`)
701
701
  }
702
702
  if (checkout !== undefined) {
703
703
  // A racing operator edit can still appear after preflight. Never roll the
@@ -40,7 +40,7 @@ const inventory: readonly [ReadinessKey, string][] = [
40
40
  ['linear-history', 'Enable Require linear history on protected root and node target branches.'],
41
41
  [
42
42
  'root-freshness',
43
- 'Require branches to be up to date before merging on the root, with nonempty required checks enforced for all actors; otherwise root landing is best-effort rather than fenced.',
43
+ 'Require branches to be up to date before merging on the root, with nonempty required checks enforced for all actors; otherwise root merge is best-effort rather than fenced.',
44
44
  ],
45
45
  ]
46
46
  export function readinessChecks(
@@ -39,3 +39,27 @@ export interface ForgeRequestContext {
39
39
  }
40
40
  /** Called once for each actual provider request, including failed requests. */
41
41
  export type ForgeRequestObserver = (context: ForgeRequestContext) => void
42
+
43
+ /** Git's network diagnostics have no structured HTTP response. Keep this
44
+ * deliberately narrow: policy refusals and local validation never qualify. */
45
+ export function classifyGitNetworkFailure(error: unknown): unknown {
46
+ if (isForgeFailure(error)) return error
47
+ const message = error instanceof Error ? error.message : String(error)
48
+ if (
49
+ /\b(?:401|403|429)\b|authentication failed|permission denied|\[rejected\]|stale info|non-fast-forward/i.test(
50
+ message,
51
+ )
52
+ )
53
+ return error
54
+ const code = error && typeof error === 'object' && 'code' in error ? error.code : undefined
55
+ if (
56
+ ['ECONNRESET', 'ETIMEDOUT', 'ESOCKETTIMEDOUT', 'UND_ERR_CONNECT_TIMEOUT'].includes(
57
+ String(code),
58
+ ) ||
59
+ /\b(?:HTTP(?:\/\S+)?\s+|returned error:\s*|HTTP code[ =]+)5\d\d\b|\bService Unavailable\b|connection reset|ECONNRESET|ETIMEDOUT|connection timed out|operation timed out|request timed out/i.test(
60
+ message,
61
+ )
62
+ )
63
+ return new ForgeFailure(message, { kind: 'transient', retry: 'retryable' })
64
+ return error
65
+ }