@defrex/autobuild 1.0.0-beta.3 → 1.0.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 (168) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +362 -56
  3. package/bin/ab-dispatch-generation.ts +93 -0
  4. package/docs/agent-runtimes.md +157 -0
  5. package/docs/answering-blocked-builds.md +21 -3
  6. package/docs/architecture.md +166 -7
  7. package/docs/build-store.md +123 -0
  8. package/docs/builds.md +82 -0
  9. package/docs/cli.md +48 -0
  10. package/docs/configuration-overview.md +93 -0
  11. package/docs/configuration.md +1778 -188
  12. package/docs/dispatcher-hosting.md +115 -0
  13. package/docs/dispatcher.md +59 -0
  14. package/docs/forges.md +121 -0
  15. package/docs/getting-started.md +60 -0
  16. package/docs/glossary.md +60 -0
  17. package/docs/hosted-service.md +2 -2
  18. package/docs/intake.md +48 -0
  19. package/docs/integration-overview.md +81 -0
  20. package/docs/integration-tree.md +87 -2
  21. package/docs/integration.md +54 -0
  22. package/docs/operating.md +114 -0
  23. package/docs/operator-api.md +64 -11
  24. package/docs/operator-surfaces.md +90 -0
  25. package/docs/overview.md +49 -0
  26. package/docs/plugin-authoring.md +426 -0
  27. package/docs/remote-store-protocol.md +12 -9
  28. package/docs/restacking.md +4 -1
  29. package/docs/seams.md +66 -0
  30. package/docs/setup.md +28 -6
  31. package/docs/skills.md +119 -0
  32. package/docs/spec-standard.md +23 -5
  33. package/docs/ticket-sources.md +132 -0
  34. package/docs/tickets.md +69 -0
  35. package/docs/troubleshooting.md +111 -0
  36. package/docs/upgrading.md +50 -0
  37. package/docs/verification.md +146 -0
  38. package/docs/website.md +47 -5
  39. package/docs/workspaces.md +152 -0
  40. package/package.json +5 -4
  41. package/packages/core/src/cli/artifact.ts +5 -4
  42. package/packages/core/src/cli/attention.ts +2 -0
  43. package/packages/core/src/cli/binary-direct.ts +190 -0
  44. package/packages/core/src/cli/binary-lifecycle.ts +46 -0
  45. package/packages/core/src/cli/binary.ts +24 -210
  46. package/packages/core/src/cli/build-control.ts +105 -2
  47. package/packages/core/src/cli/context.ts +41 -1
  48. package/packages/core/src/cli/dashboard/hand-pushed.ts +24 -0
  49. package/packages/core/src/cli/dashboard/handoff.ts +64 -0
  50. package/packages/core/src/cli/dashboard/integration-detail.ts +3 -0
  51. package/packages/core/src/cli/dashboard/model.ts +34 -10
  52. package/packages/core/src/cli/dashboard/render.ts +24 -2
  53. package/packages/core/src/cli/dashboard/rollback.ts +30 -0
  54. package/packages/core/src/cli/dispatch-args.ts +53 -0
  55. package/packages/core/src/cli/dispatch-crash-budget.ts +15 -0
  56. package/packages/core/src/cli/dispatch-frontend.ts +52 -5
  57. package/packages/core/src/cli/dispatch-handoff.ts +276 -0
  58. package/packages/core/src/cli/dispatch-launch-contract.ts +170 -0
  59. package/packages/core/src/cli/dispatch-launcher.ts +580 -0
  60. package/packages/core/src/cli/dispatch-parent-watch.ts +44 -0
  61. package/packages/core/src/cli/dispatch-preflight.ts +272 -0
  62. package/packages/core/src/cli/dispatch-presentation-job.ts +46 -0
  63. package/packages/core/src/cli/dispatch-presentation-ownership.ts +9 -0
  64. package/packages/core/src/cli/dispatch-process.ts +22 -90
  65. package/packages/core/src/cli/dispatch-readiness.ts +47 -0
  66. package/packages/core/src/cli/dispatch-repository-feed.ts +5 -1
  67. package/packages/core/src/cli/dispatch-runtime-cache.ts +522 -0
  68. package/packages/core/src/cli/dispatch-runtime-dependencies.ts +291 -0
  69. package/packages/core/src/cli/dispatch-runtime-use.ts +336 -0
  70. package/packages/core/src/cli/dispatch-upgrade-controller.ts +221 -0
  71. package/packages/core/src/cli/dispatch-upgrade-install.ts +258 -0
  72. package/packages/core/src/cli/dispatch-upgrade-source.ts +309 -0
  73. package/packages/core/src/cli/dispatch-upgrade-target.ts +190 -0
  74. package/packages/core/src/cli/dispatch.ts +604 -60
  75. package/packages/core/src/cli/dispatcher-liveness.ts +1 -1
  76. package/packages/core/src/cli/env.ts +1 -1
  77. package/packages/core/src/cli/harvest.ts +28 -11
  78. package/packages/core/src/cli/help.ts +10 -5
  79. package/packages/core/src/cli/installation.ts +5 -3
  80. package/packages/core/src/cli/main-checkout.ts +59 -0
  81. package/packages/core/src/cli/main.ts +15 -45
  82. package/packages/core/src/cli/node-verification-provenance.ts +97 -0
  83. package/packages/core/src/cli/repo-state.ts +3 -58
  84. package/packages/core/src/cli/repository-status.ts +67 -3
  85. package/packages/core/src/cli/runtime-spawn.ts +16 -0
  86. package/packages/core/src/cli/status.ts +57 -3
  87. package/packages/core/src/cli/upgrade-followup.ts +25 -0
  88. package/packages/core/src/cli/wait.ts +3 -0
  89. package/packages/core/src/cli/watch.ts +7 -0
  90. package/packages/core/src/config/landing.ts +8 -0
  91. package/packages/core/src/config/live.ts +1 -0
  92. package/packages/core/src/config/reference-metadata.ts +31 -0
  93. package/packages/core/src/config/reference.ts +342 -0
  94. package/packages/core/src/config/roles.ts +1 -1
  95. package/packages/core/src/config/schema.ts +352 -10
  96. package/packages/core/src/distribution-packaging.ts +116 -0
  97. package/packages/core/src/events/catalog.ts +6 -0
  98. package/packages/core/src/events/payloads.ts +53 -9
  99. package/packages/core/src/events/policy.ts +25 -0
  100. package/packages/core/src/events/repository.ts +184 -4
  101. package/packages/core/src/events/runtime.ts +16 -0
  102. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +2515 -78
  103. package/packages/core/src/kernel/dispatch-drain-recovery.ts +121 -0
  104. package/packages/core/src/kernel/dispatch-status.ts +4 -2
  105. package/packages/core/src/kernel/dispatch-upgrade.ts +171 -0
  106. package/packages/core/src/kernel/dispatcher-liveness.ts +7 -0
  107. package/packages/core/src/kernel/generators/repository-journals.ts +82 -0
  108. package/packages/core/src/kernel/guarded-forge.ts +1 -1
  109. package/packages/core/src/kernel/harvest.ts +98 -4
  110. package/packages/core/src/kernel/integration-attention.ts +20 -0
  111. package/packages/core/src/kernel/integration-state.ts +80 -11
  112. package/packages/core/src/kernel/landing-readiness.ts +6 -1
  113. package/packages/core/src/kernel/mixed-version.ts +34 -0
  114. package/packages/core/src/kernel/node-polling.ts +160 -0
  115. package/packages/core/src/kernel/read-facts.ts +40 -5
  116. package/packages/core/src/kernel/reducer-registry.ts +3 -0
  117. package/packages/core/src/kernel/reducer.ts +75 -14
  118. package/packages/core/src/kernel/service-facts.ts +11 -4
  119. package/packages/core/src/ontology.ts +2 -2
  120. package/packages/core/src/open-map.ts +3 -1
  121. package/packages/core/src/operator/presentation.ts +7 -0
  122. package/packages/core/src/operator/query.ts +6 -2
  123. package/packages/core/src/operator/registry.ts +1 -1
  124. package/packages/core/src/plugins/load.ts +4 -1
  125. package/packages/core/src/plugins/runtime-snapshot.ts +128 -0
  126. package/packages/core/src/ports/forge/contract.ts +29 -0
  127. package/packages/core/src/ports/forge/github.ts +189 -61
  128. package/packages/core/src/ports/forge-failure.ts +1 -0
  129. package/packages/core/src/ports/forge-telemetry.ts +3 -0
  130. package/packages/core/src/ports/runner/session-env.ts +1 -0
  131. package/packages/core/src/ports/types.ts +10 -0
  132. package/packages/core/src/ports/workspace/distribution-archive.ts +22 -149
  133. package/packages/core/src/ports/workspace/distribution-release.ts +56 -0
  134. package/packages/core/src/ports/workspace/git-worktree.ts +2 -1
  135. package/packages/core/src/ports/workspace/local-build-execution.ts +37 -17
  136. package/packages/core/src/processes/build-child-exit.ts +5 -26
  137. package/packages/core/src/processes/build-runner.ts +81 -11
  138. package/packages/core/src/processes/dispatcher.ts +254 -23
  139. package/packages/core/src/processes/execution-no-progress.ts +6 -0
  140. package/packages/core/src/processes/execution-relaunch.ts +30 -0
  141. package/packages/core/src/processes/execution-settlement.ts +16 -7
  142. package/packages/core/src/processes/harvest-runner.ts +328 -292
  143. package/packages/core/src/processes/process-group-reaper.ts +17 -10
  144. package/packages/core/src/runtime-identity.ts +22 -3
  145. package/packages/core/src/store/contract.ts +153 -0
  146. package/packages/core/src/store/local/store.ts +197 -72
  147. package/packages/core/src/store/reduced-reads.ts +8 -0
  148. package/packages/core/src/store/reducer-value-shapes.json +5783 -3305
  149. package/packages/core/src/store/remote/client.ts +43 -0
  150. package/packages/core/src/store/repo-state-events.ts +20 -3
  151. package/packages/core/src/store/types.ts +7 -0
  152. package/skills/finalize/SKILL.md +3 -1
  153. package/skills/guide/SKILL.md +273 -48
  154. package/skills/guide/references/integration-tree.md +87 -2
  155. package/skills/guide/references/operator-api.md +71 -14
  156. package/skills/guide/references/plugin-authoring.md +231 -266
  157. package/skills/guide/references/remote-store-protocol.md +12 -9
  158. package/skills/guide/references/restacking.md +4 -1
  159. package/skills/guide/references/setup.md +28 -6
  160. package/skills/guide/references/spec-standard.md +23 -5
  161. package/skills/harvest/SKILL.md +4 -0
  162. package/skills/harvest-review/SKILL.md +4 -0
  163. package/skills/implement/SKILL.md +4 -2
  164. package/skills/operate/SKILL.md +104 -35
  165. package/skills/plan/SKILL.md +12 -4
  166. package/skills/spec/SKILL.md +20 -2
  167. package/skills/tickets/SKILL.md +20 -1
  168. package/templates/hosted-service/package.json +2 -2
@@ -0,0 +1,426 @@
1
+ ---
2
+ title: "Writing a plugin"
3
+ group: "guides"
4
+ description: "Build, contract-test, package, and publish an Autobuild infrastructure adapter."
5
+ label: "Plugins"
6
+ order: 7
7
+ ---
8
+
9
+ # Writing a plugin
10
+
11
+ A plugin is a trusted Bun module, loaded in-process from the consuming repository, that connects Autobuild to another ticket tracker, agent runtime, workspace system or forge.
12
+
13
+ Install Autobuild in the target repository with `bun add -d --exact @defrex/autobuild`; `ab <command>` below means `bun ab <command>` there.
14
+
15
+ **Definition of done for an adapter: the unchanged shared contract suite for its port passes.** Interface conformance or a clean `ab plugin doctor` is not enough.
16
+
17
+ ## 1. Choose the port and preserve its semantics
18
+
19
+ Import public types only from `@defrex/autobuild/plugin-sdk`; internal module paths are not API.
20
+
21
+ | Port | Manifest map | Factory returns | Selected by |
22
+ |---|---|---|---|
23
+ | `ticket-source` | `ticketSources` | `TicketSource` | `[tickets].source` |
24
+ | `agent-runtime` | `agentRuntimes` | `RuntimeRegistration` | `[roles.*].runtime` |
25
+ | `workspace-provider` | `workspaceProviders` | `WorkspaceProvider` | `[workspace].provider` |
26
+ | `forge` | `forges` | `Forge` | root `forge` key |
27
+
28
+ All four manifest maps have production selectors. Omitted forge and workspace selectors default to builtin `github` and `git-worktree`; roles keep normal runtime inheritance.
29
+
30
+ `BuildStore` and `BlobStore` contract types are exported for remote-server authors, but BuildStore is **not** an in-process manifest map: implement the language-neutral remote store protocol and run its conformance path. `TelemetrySource` is a frozen port type with no plugin registration surface in this release.
31
+
32
+ ### `ticket-source`
33
+
34
+ Lists, gets and claims tickets to start builds; receives comments, transitions, creates and updates. Owns lifecycle names, dependency completion, idempotent creation with a stable external creation-key projection, and partial-list diagnostics. Never consulted mid-build; not artifact storage.
35
+
36
+ ### `agent-runtime`
37
+
38
+ Wrap an `AgentRunner` that supports:
39
+
40
+ - start, continue and end, with complete transcripts and usage
41
+ - per-turn environment refresh, and cancellation that keeps an endable handle for transcript deposition
42
+ - typed failures: verbatim message, retry-compatible `permanent` bit, optional `cause: availability | exhaustion | credentials | configuration` routing evidence
43
+ - the distribution-managed `ab` launcher
44
+
45
+ Declare served model prefixes and a default. Optional tool-free `oneShot` sits beside the runner interface.
46
+
47
+ ### `workspace-provider`
48
+
49
+ - Provision an absolute, writable working copy for the requested branch; return durable base evidence.
50
+ - Resume an intact branch non-destructively, never silently re-cut from a newer base. Rematerialize a lost copy. Make release idempotent.
51
+ - Optional `provision.publication` supplies a durable confirmed SHA and known cache tips for authoritative readback and cache repair. Preserve unknown unpublished work.
52
+
53
+ ### `forge`
54
+
55
+ - Kernel-owned regular pushes, idempotent PR opening, PR-state projection, gated and ungated auto-merge, head-guarded squash merge, and comments. Agents never receive forge credentials or push.
56
+ - API 1.2: optional idempotent `closePr` and `deleteBranch` for abort cleanup. `closePr` must preserve a racing merge. Without them, cleanup stays visibly pending.
57
+ - Optional `prAttachments` hosts images; the text-only path must work without it.
58
+
59
+ ### Reconcile rewrites
60
+
61
+ Reconcile requires the optional grouped `Forge.rewrite` capability:
62
+
63
+ 1. Snapshot the actual build branch into a build-private ref.
64
+ 2. Publish immutable exact-SHA refs under `refs/autobuild/archive/<slug>/<sha>`.
65
+ 3. Replace the explicit branch, leased on an explicit expected remote head.
66
+
67
+ - Return `lease-mismatch` separately from transport, auth and policy failures.
68
+ - If the CAS succeeds but another writer advances the branch before readback, return `lease-mismatch` with `rewritten: true` and the observed `actual` head. The kernel records the write and retries without claiming completion.
69
+ - After an acknowledged replacement, reattach the matching detached workspace HEAD to the build branch so later publication works.
70
+ - Never overwrite unknown work or fall back to merging, ordinary pushes, archive branches or tags.
71
+ - Older forge plugins still load; reconcile refuses them actionably.
72
+ - Remote workspace providers also need trusted `WorkspacePublication.rewrite` after guest teardown; ordinary `publish` can't publish a restack.
73
+
74
+ ### Publication readback
75
+
76
+ Publication succeeds only when an authoritative branch-head readback equals the frozen intended SHA, including recovery after a failed push. Unconfirmed candidate ancestry never proves publication.
77
+
78
+ - `pushBranch(workspacePath, branch, sha?)` receives the frozen SHA from kernel callers and stays fast-forward only. Legacy callers may omit the SHA to select HEAD.
79
+ - `confirmPublication` inspects the authoritative head and refreshes caches only on an exact SHA match. Kernel callers refuse adapters lacking it before pushing.
80
+ - Remote-backed local refs are caches: set them unconditionally after confirmation, fetching the advertised ref if objects are missing, without resetting checkout files. `localExpected` is historical input only. Local-git's shared ref database stays authoritative and keeps CAS.
81
+ - Hosted `WorkspacePublication` must provide authoritative `isPublished`, and confirm after writing and before retrying.
82
+ - Remote inspection must not resume a stopped guest or run commands in it; refresh the guest cache inside trusted publication before stopping it. Missing inspection fails actionably.
83
+
84
+ ### Forge failures and request accounting
85
+
86
+ API 1.8 adds optional forge failure classification. Import `ForgeFailure` and `isForgeFailure`, plus the types `ForgeFailureDetails`, `ForgeRequestObserver` and `ForgeRequestContext`, from `@defrex/autobuild/plugin-sdk`.
87
+
88
+ ```ts
89
+ // Rate limit, with a valid ISO reset timestamp:
90
+ throw new ForgeFailure(message, { kind: 'rate-limited', resetAt })
91
+ // Retryable transport error:
92
+ throw new ForgeFailure(message, { kind: 'transient', retry: 'retryable' })
93
+ ```
94
+
95
+ - Don't classify ordinary policy and permission refusals; they remain deferrals. Never include credentials.
96
+ - The `forgeFailure: 'autobuild.forge-failure.v1'` discriminant and validated details work across separately loaded SDK copies. Arbitrary legacy errors aren't classified.
97
+
98
+ Optional `Forge.observeRequests(observer): () => void` returns a disposer and calls each observer once per wire request, including failures and pagination.
99
+
100
+ - Pass `ForgeRequestContext` with the build slug, or `{}` when unknown; the host fills missing attribution from its current build-scoped operation, else the request is repository/unattributed. Capture context before awaiting transport; notify after the outcome.
101
+ - Credential discovery and skipped calls are not provider requests.
102
+
103
+ | `outcome` | Request |
104
+ |---|---|
105
+ | `restPrimary` | REST HTTP response other than 304 |
106
+ | `restNotModified` | REST 304 |
107
+ | `graphql` | GraphQL call, including failures |
108
+ | omitted | network failure (no proven REST debit) |
109
+
110
+ ```ts
111
+ observeRequests(observer: ForgeRequestObserver) {
112
+ this.observers.add(observer)
113
+ return () => { this.observers.delete(observer) }
114
+ }
115
+ // Capture context before awaiting the transport. After response/failure:
116
+ for (const observer of this.observers) {
117
+ observer({ build: context.build, ...(outcome ? { outcome } : {}) })
118
+ }
119
+ ```
120
+
121
+ Declare `apiVersion: '^1.8.0'` for these capabilities. Legacy 1.x plugins load without observers and show unavailable counts.
122
+
123
+ ### Read scopes
124
+
125
+ Forge optimizations that don't change the required plugin API version:
126
+
127
+ - **`withReadScope(work)`** wraps a dispatcher tick, sharing promises and observations across builds; tears down on rejection too. Operations outside the scope stay independent.
128
+ - **`primeNodeReads({workspacePath, parent, head, prNumber?})`** seeds opened-node facts. Non-cooldown failures emit a diagnostic and fall through to ordinary stage reads, preserving recovery when the previous parent disappeared.
129
+
130
+ Invalidate observations before writes, including uncertain writes and Git pushes. Acknowledgement and readiness reads stay fresh. Branch and ref endpoints share normalized facts, never HTTP validators.
131
+
132
+ ### API versions
133
+
134
+ A plugin relying on a capability declares an `apiVersion` range containing its version (for example `^1.5.0`). Legacy plugins without newer fields keep working.
135
+
136
+ - **1.2** Forge `closePr` and `deleteBranch`.
137
+ - **1.3** `AgentRunner` failure `cause` and the `exhaustion-failure` contract scenario. Without `cause`, `permanent: false` is eligible for a configured alternate; `permanent: true` stops the chain.
138
+ - **1.4** Optional `Ticket.creationKey`: the stable external create/adoption key, projected from `create`, `get` and `listReady`, correlating ready tickets with durable Harvest reservations while blocker recording is unfinished. Legacy tickets may omit it.
139
+ - **1.5** `path` is the path in the workspace environment; set optional `localPath` only when the dispatcher can reach that same copy directly. Workspace-owned executors receive the durable provider locator as `BuildExecutionStart.workspaceRef`; local PID supervision stays host-owned.
140
+ - **1.7** Workspace factory seams.
141
+ - **1.8** Forge failure classification and request observers.
142
+
143
+ ## 2. Create a repository-local module
144
+
145
+ ```text
146
+ my-repository/
147
+ ├── autobuild.toml
148
+ └── autobuild-plugin.ts
149
+ ```
150
+
151
+ Use `import type` for SDK symbols that are only types:
152
+
153
+ ```ts
154
+ import type {
155
+ AutobuildPluginManifest,
156
+ ForgePluginFactory,
157
+ } from '@defrex/autobuild/plugin-sdk'
158
+ import { AcmeForge } from '@acme/forge-client'
159
+
160
+ const createForge: ForgePluginFactory = ({ config, env, repoRoot }) => {
161
+ const token = env.ACME_FORGE_TOKEN
162
+ if (!token) throw new Error('ACME_FORGE_TOKEN is required')
163
+ return new AcmeForge({ token, config, repoRoot })
164
+ }
165
+
166
+ export default {
167
+ name: 'acme-forge',
168
+ apiVersion: '^1.2.0',
169
+ forges: { acme: createForge },
170
+ } satisfies AutobuildPluginManifest
171
+ ```
172
+
173
+ ### The manifest
174
+
175
+ Every module default-exports one strict `AutobuildPluginManifest`:
176
+
177
+ - **`name`** Nonblank diagnostic and ownership identity; need not equal the npm package name.
178
+ - **`apiVersion`** A semver **range accepted by the plugin**, not its package version: the narrowest range containing the host plugin API you ran contracts against. `ab plugin list` reports it beside the host version; invalid or incompatible ranges fail loading.
179
+ - **Registration keys** Only `ticketSources`, `agentRuntimes`, `workspaceProviders` and `forges`; unknown fields fail validation.
180
+ - **Adapter names** Register verbatim. Declare `__proto__` computed, `{ ['__proto__']: factory }`; a plain `__proto__:` key sets the prototype. Parsed maps have a null prototype, so undeclared names read `undefined`. Blank or whitespace-only names are rejected.
181
+ - **Registrations** A bare adapter factory, or `{ factory, contract: { factory, live? } }` whose contract factory returns that port suite's fixture factory. Ticket-source descriptors may declare a deduplicated `requiredEnv` list; the host rejects missing or empty credentials before invoking the selected factory.
182
+
183
+ ### Factory context
184
+
185
+ Every adapter and contract factory receives `{ config, env, repoRoot }`: read-only `config`, the process `env`, and `repoRoot`, the absolute consuming-repository root.
186
+
187
+ | Port | `config` |
188
+ |---|---|
189
+ | ticket-source | the existing strict `[tickets]` fields; no untyped plugin-options table |
190
+ | workspace-provider | the open `[workspace.config]` table, the only place for adapter-owned settings |
191
+ | agent-runtime, forge | an empty object |
192
+
193
+ Workspace-provider factories also receive optional host-derived seams (API 1.7), absent when the call site has none; ignoring them changes nothing.
194
+
195
+ - **`storeRef`, `delegateCredential`** Store URL and credential-exchange callback; guaranteed when the registration declares `capabilities.storeRequirements`.
196
+ - **`runtimeReferences`** The host's effective runtime routes.
197
+ - **`origin`, `remoteBranchHead`** Checkout-less readers; when absent, fall back to host `git` from `repoRoot`.
198
+
199
+ Remote workspace factories must call `delegateCredential(storeRef, undefined, target)` for per-resource grants before provisioning or launching guests; parent authority stays in host composition.
200
+
201
+ - `storeToken` is retired and never supplied; factory environments exclude `AB_TOKEN`. Plugins that forwarded it must migrate to the callback and fail closed without it.
202
+ - Launch credentials travel through the separate transient execution-auth argument, never serialized execution identity.
203
+
204
+ ### Configure and resolve
205
+
206
+ List module specifiers at the TOML root, before any table, and select adapters:
207
+
208
+ ```toml
209
+ plugins = ["./autobuild-plugin.ts"]
210
+ forge = "acme"
211
+
212
+ [tickets]
213
+ source = "file"
214
+ readyState = "ready"
215
+ ```
216
+
217
+ - Repository-path specifiers resolve from the config-bearing root, which is the immutable build worktree in scoped phases.
218
+ - npm package specifiers resolve from the consuming main checkout's installed dependencies first, then from the Autobuild installation the CLI runs from.
219
+ - Install extensions in the consuming repository with `bun add -d --exact @defrex/autobuild-<extension>`; a repository copy wins over an installed one, and missing packages fail and are never installed automatically.
220
+ - Specifiers must be unique: an exact repeat fails config validation before any plugin loads, naming the value and both positions.
221
+
222
+ ### Loading rules
223
+
224
+ - Modules load in declaration order; registration is atomic per manifest.
225
+ - Resolution or evaluation failure, a missing or malformed default export, an incompatible API range, or a collision fails before any claims or builds.
226
+ - Within one port, builtin and earlier-plugin names can't be shadowed; a collision names the adapter and both owners. Different ports may share a name.
227
+ - Plugins are trusted like configured shell commands: Bun evaluates them in-process with repository authority and no sandbox.
228
+
229
+ ### Cached dispatcher generations
230
+
231
+ In a cached dispatcher generation, selection uses the same roots, but selected external plugin code and its installed dependency closure are copied into an immutable auxiliary snapshot.
232
+
233
+ - ESM, CommonJS `require`, delayed imports, export-from and module-anchored `createRequire` all resolve the core package, SDK values and classes included, to the same frozen runtime, without loader hooks or source transforms.
234
+ - Repo-path modules copy their literal import closure and literal `new URL(..., import.meta.url)` assets, not the checkout or unused dev dependencies. Packaged plugins keep their package's assets and dependency graph.
235
+ - Package-relative assets stay beside copied modules. `import.meta.url` and filenames name the snapshot; cwd and factory `repoRoot` remain the consuming checkout. Explicit absolute paths stay plugin-controlled external resources.
236
+ - Snapshots use neutral compiler boundaries; cached Bun entrypoints pin the core config with `--no-install --tsconfig-override`. Autobuild-owned compiler chains can't escape the runtime; installed third-party development configs are preserved byte-for-byte.
237
+ - New selections can prepare new snapshots without changing the generation's core identity. Live plugin processes keep their core runtime independently of Store leases.
238
+ - Plugin-loading CLI calls reclaim dead snapshots, so edits between phase commands don't pile up checkout-sized copies.
239
+
240
+ Noncached consumers follow the separately loaded SDK compatibility rules in section 1.
241
+
242
+ ## 3. Keep secrets out of source and config
243
+
244
+ - Never put credentials in `autobuild.toml`, the manifest, committed fixtures or contract output.
245
+ - Read them from the factory's `env` (for example `env.ACME_FORGE_TOKEN`), document the required environment variables, and keep local values in ignored env files or a secret manager.
246
+ - Validate credentials when the selected adapter or live fixture is created, not at module top level, so registration stays lazy and diagnostics can inspect unrelated adapters. Ticket-source descriptors should declare `requiredEnv`; other ports check in their factories.
247
+
248
+ ## 4. Add the contract harness first
249
+
250
+ A contract-bearing registration:
251
+
252
+ ```ts
253
+ const manifest = {
254
+ name: 'acme',
255
+ apiVersion: '^1.2.0',
256
+ ticketSources: {
257
+ acme: {
258
+ factory: createAcmeTicketSource,
259
+ contract: { factory: createAcmeTicketContract },
260
+ },
261
+ },
262
+ } satisfies AutobuildPluginManifest
263
+ ```
264
+
265
+ The contract factory returns a `TicketSourceContractFactory`, `AgentRunnerContractFactory`, `WorkspaceProviderContractFactory` or `ForgeContractFactory` (harness types from `@defrex/autobuild/plugin-sdk`). The host runs the unchanged shared suite; don't copy, wrap, skip or weaken its assertions.
266
+
267
+ Contract fixtures must:
268
+
269
+ - isolate resources (UUID-namespaced records, branches, PRs, sessions or workspaces)
270
+ - expose the independent controls and probes their harness type requires
271
+ - clean up in `cleanup`, even after an assertion failure
272
+ - make retries and release idempotent where the port requires it
273
+
274
+ A fixture that contacts a provider or mutates external resources must declare `contract: { factory, live: true }` and runs only with an explicit opt-in:
275
+
276
+ ```sh
277
+ AB_RUN_LIVE_PORT_CONTRACTS=1 ab plugin test forge acme
278
+ ```
279
+
280
+ Author loop:
281
+
282
+ ```sh
283
+ ab plugin list
284
+ ab plugin doctor
285
+ ab plugin test ticket-source acme
286
+ ```
287
+
288
+ | Command | Does |
289
+ |---|---|
290
+ | `list` | builtins and configured registrations: provenance, resolution, API compatibility, contract availability |
291
+ | `doctor` | loads every configured module, nonzero if any fail; not a semantics check |
292
+ | `test` | runs the unchanged suite for one port and adapter, forwards per-test output, returns its exit status |
293
+
294
+ Repeat after every adapter change until the suite is green, with the live opt-in when applicable.
295
+
296
+ ## 5. Zero-network wiring walkthrough
297
+
298
+ This scratch example proves module resolution, manifest spelling, configuration and the TicketSource contract bridge offline. It uses Autobuild's reference fake, so it is **only a wiring exercise**; your real adapter's harness must still pass the same suite.
299
+
300
+ Create `autobuild-plugin.ts`:
301
+
302
+ <!-- plugin-authoring-walkthrough-module:start -->
303
+ ```ts
304
+ import { FakeTicketSource } from '@defrex/autobuild/plugin-sdk'
305
+ import type {
306
+ AutobuildPluginManifest,
307
+ TicketSourceContractFactory,
308
+ TicketSourcePluginFactory,
309
+ } from '@defrex/autobuild/plugin-sdk'
310
+
311
+ const createSource: TicketSourcePluginFactory = () => new FakeTicketSource()
312
+
313
+ const ticketContract: TicketSourceContractFactory = async () => ({
314
+ source: new FakeTicketSource([], {
315
+ createState: 'Triage',
316
+ doneState: 'Done',
317
+ }),
318
+ states: { ready: 'Ready', claimed: 'Doing', completed: 'Done' },
319
+ editableLabel: 'contract',
320
+ })
321
+
322
+ export default {
323
+ name: 'walkthrough',
324
+ apiVersion: '^1.2.0',
325
+ ticketSources: {
326
+ walkthrough: {
327
+ factory: createSource,
328
+ contract: { factory: () => ticketContract },
329
+ },
330
+ },
331
+ } satisfies AutobuildPluginManifest
332
+ ```
333
+ <!-- plugin-authoring-walkthrough-module:end -->
334
+
335
+ Create `autobuild.toml`:
336
+
337
+ <!-- plugin-authoring-walkthrough-config:start -->
338
+ ```toml
339
+ plugins = ["./autobuild-plugin.ts"]
340
+
341
+ [tickets]
342
+ source = "walkthrough"
343
+ readyState = "ready"
344
+ ```
345
+ <!-- plugin-authoring-walkthrough-config:end -->
346
+
347
+ Then run:
348
+
349
+ ```sh
350
+ ab init
351
+ ab plugin doctor
352
+ ab plugin list
353
+ ab plugin test ticket-source walkthrough
354
+ ```
355
+
356
+ `ab init` keeps the existing config and vendors this guide. Doctor and list show the `walkthrough` plugin and adapter; the contract run exits zero.
357
+
358
+ ## 6. Package and publish when reuse warrants it
359
+
360
+ A repository-local module needs no packaging. An npm plugin needs one public module plus ordinary test and typecheck setup:
361
+
362
+ ```text
363
+ acme-autobuild-plugin/
364
+ ├── src/index.ts
365
+ ├── package.json
366
+ ├── tsconfig.json
367
+ └── bun.lock
368
+ ```
369
+
370
+ This manifest declares only the tested host release (`1.0.0-beta.2`); widen it only after the unchanged contracts pass on each added host.
371
+
372
+ ```json
373
+ {
374
+ "name": "@acme/autobuild-plugin",
375
+ "version": "1.0.0",
376
+ "type": "module",
377
+ "exports": { ".": "./src/index.ts" },
378
+ "files": ["src", "README.md"],
379
+ "scripts": {
380
+ "typecheck": "tsc --noEmit",
381
+ "test": "bun test",
382
+ "prepublishOnly": "bun run typecheck && bun test"
383
+ },
384
+ "devDependencies": { "@defrex/autobuild": "1.0.0-beta.2", "typescript": "5.9.3" },
385
+ "peerDependencies": { "@defrex/autobuild": "1.0.0-beta.2" },
386
+ "peerDependenciesMeta": { "@defrex/autobuild": { "optional": true } }
387
+ }
388
+ ```
389
+
390
+ - **Dependencies.** Type-only SDK imports erase, so Autobuild is a dev dependency, not a runtime `dependencies` entry. The optional peer names the tested host without loading a second Autobuild copy. Runtime imports, such as the reference fake, need a runtime dependency; never ship the fake as a production adapter.
391
+ - **Versions.** Package semver is independent of the host range and `apiVersion`. On an incompatible host plugin API, update adapter and contracts, change the range once they pass, and version the package by the user-visible compatibility change.
392
+
393
+ Before publishing:
394
+
395
+ ```sh
396
+ bun run typecheck
397
+ bun test
398
+ npm pack --dry-run
399
+ npm pack
400
+ # inspect the tarball, then install that exact .tgz in a scratch consumer
401
+ npm publish --access public
402
+ ```
403
+
404
+ 1. Check the dry-run and tarball file lists for source, secrets, local fixtures and missing exports.
405
+ 2. Install the tarball in a scratch consuming repository with `plugins = ["@acme/autobuild-plugin"]`.
406
+ 3. Rerun `ab plugin doctor`, `ab plugin list` and the contract command.
407
+
408
+ Drop `--access public` when the registry or access policy says otherwise.
409
+
410
+ Official npm references: [`package.json` fields](https://docs.npmjs.com/cli/v11/configuring-npm/package-json),
411
+ [`npm pack`](https://docs.npmjs.com/cli/v11/commands/npm-pack), and
412
+ [`npm publish`](https://docs.npmjs.com/cli/v11/commands/npm-publish).
413
+
414
+ ## Optional ticket tree capability
415
+
416
+ Existing ticket sources stay compatible unchanged. Raw `Ticket.kind` is optional; public projections normalize it to `work`.
417
+
418
+ An adapter opts in with `integrationTree: true` and must:
419
+
420
+ - implement `listAll(): Promise<TicketListing>` over every state, ignoring ready filters, exhausting pagination and propagating infrastructure failures
421
+ - persist `kind?: 'work' | 'node'` and `target?: string | null` on drafts and updates: omitted preserves or defaults, explicit `work` resets kind, `null` clears target
422
+ - read targets as source-local canonical ticket ids
423
+ - before writing any mixed patch, including revision-checked writes, validate same-source existence, node kind, self and ancestor cycles, corrupt chains, and demotion of a node with children
424
+ - expose kind and target in revisions
425
+
426
+ Don't opt in unless the source preserves these semantics. Legacy sources get ordinary CRUD; the compatibility facade refuses metadata writes before legacy methods run, and unsupported sources should also refuse metadata at their own write boundary.
@@ -62,7 +62,7 @@ headers, or available backend.
62
62
  `Date.toISOString()` form, for example `2026-07-15T12:00:00.000Z`.
63
63
  - Event sequence numbers and artifact revisions are integers assigned by the
64
64
  server. Clients must not assign either except for the negative deposit
65
- placeholders described in [Atomic deposits](#7-atomic-deposits).
65
+ placeholders described in [Atomic deposits](#8-atomic-deposits).
66
66
  - Optional object members are omitted, not represented as `null`, unless a
67
67
  response below explicitly specifies JSON `null`.
68
68
  - The server owns durability. Events and artifact metadata visible in a
@@ -144,8 +144,8 @@ An actor is exactly one of:
144
144
 
145
145
  `role`, `session`, `user`, and `source` are nonempty strings. A human actor may
146
146
  carry an optional `via` marker naming the delegate that performed the write on
147
- the person's behalf: `{ "kind": "session", "id": nonempty }` (an operator's
148
- orchestrator session) or `{ "kind": "mcp", "client": nonempty }` (an MCP
147
+ the person's behalf: `{ "kind": "session", "id": nonempty }` (a human account's
148
+ operator-agent session) or `{ "kind": "mcp", "client": nonempty }` (an MCP
149
149
  client). `via` is valid only on `human` actors and only on build and
150
150
  repository events — session events are the delegate's own log — and a `via`
151
151
  key on any other actor variant is a validation failure. These are the
@@ -497,7 +497,7 @@ without a journal record, or a repository without builds.
497
497
  | `getRepo` | `GET /repos/{repo}` | none | `200` + `RepositoryRecord`; absent is `404` (the shipped client maps this to `null`) |
498
498
  | `appendRepo` | `POST /repos/{repo}/events` | event write | `201` + repository event envelope |
499
499
  | `getRepoEvents` | `GET /repos/{repo}/events?since={n}&wait={s}` | optional `since` query value, parsed as in section 3; absence defaults to `0`. Optional `wait` in whole seconds, per the event-wait rules of section 3 | `200` + envelopes with `seq >` parsed `since`, in increasing sequence order |
500
- | `getRepoStateEvents` | `GET /repos/{repo}/state-events` | none | `200` + the bounded repository-journal subset (AUT-489): every durable event type (`harvest.*`, `orchestrator.sandbox.*`, the three dispatcher setting types) plus, when the journal has one, the tail from the latest `dispatcher.run-started`, in increasing sequence order; served inside the repository-existence gate like `GET events`, so an unknown repository is `404` |
500
+ | `getRepoStateEvents` | `GET /repos/{repo}/state-events` | none | `200` + the bounded repository-journal subset (AUT-489): every durable event type (`harvest.*`, `orchestrator.sandbox.*`, the three dispatcher setting types, and cross-generation handoff correlation facts: target-prepared, yield-requested, upgrade-failed, handoff-started, terminal-released, takeover, drain-deadline, drain-settled and handoff-completed) plus, when the journal has one, the tail from the latest `dispatcher.run-started`, in increasing sequence order; served inside the repository-existence gate like `GET events`, so an unknown repository is `404` |
501
501
  | `getReducerSnapshot` (repo scope) | `GET /repos/{repo}/snapshots/{reducer}?version={n}` | required `version` query value, a positive integer; `reducer` is a registry name (`^[A-Za-z][A-Za-z0-9._-]{0,63}$`) | `200` + `{"version", "cursor", "state"}` or `200 null` when absent, written by another reducer version, ahead of the journal's tail, or the repository has no journal record; an unknown repository is `404`, which the shipped client also maps to `null` |
502
502
  | `putReducerSnapshot` (repo scope) | `PUT /repos/{repo}/snapshots/{reducer}` | `{"version": int >= 1, "cursor": int >= 0, "state": JSON}`, at most 16 MiB (`413` above) | `200 {"written": boolean}`; the stored cursor never decreases, so a write at an equal or lower cursor (or an equal cursor at an equal or lower version) and one past the journal's tail answer `written: false` |
503
503
  | `appendRepoWithArtifacts` | `POST /repos/{repo}/deposits` | atomic deposit request | `201` + `{event, artifacts}` using repository shapes |
@@ -688,7 +688,7 @@ authority:
688
688
  ## 5. Operator-session operations
689
689
 
690
690
  Operator sessions are a third resource kind: durable orchestrator-conversation
691
- state keyed by repository and operator. They are hosted-only — local installs
691
+ state keyed by repository and session owner (the human account in `operator`). They are hosted-only — local installs
692
692
  interact through the CLI and dashboard and never create one — but the resource
693
693
  contract is uniform, and a conforming server implements it the same way it
694
694
  implements the repository journal. A session record is:
@@ -698,7 +698,7 @@ implements the repository journal. A session record is:
698
698
  {
699
699
  "id": "os_9f2c…", // server-assigned, `os_`-prefixed
700
700
  "repo": "acme/autobuild",
701
- "operator": "alice", // trimmed nonblank operator identity
701
+ "operator": "alice", // trimmed nonblank session-owner identity
702
702
  "title": "fix the login flow", // optional
703
703
  "createdAt": "2026-07-15T12:00:00.000Z",
704
704
  "updatedAt": "2026-07-15T12:03:00.000Z"
@@ -707,13 +707,13 @@ implements the repository journal. A session record is:
707
707
 
708
708
  Creating a session makes the record and its first event visible together: the
709
709
  record's creation atomically appends a `session.created` event as sequence 1
710
- with the operator as a human actor. The session event catalog is closed and
710
+ with the session owner as a `human` actor. The session event catalog is closed and
711
711
  separate from the build and repository catalogs (`session.created`,
712
712
  `message.posted`, `session.wake-set`, `turn.started`, `turn.suspended`,
713
713
  `turn.resumed`, `approval.requested`, `approval.answered`, `turn.completed`,
714
714
  `turn.failed`, `session.archived`), with its own per-session sequence starting
715
715
  at 1 and its own actor-per-type rules. A `via` member is never valid on a
716
- session event: session events are the delegate's own log, and the operator's
716
+ session event: session events are the delegate's own log, and the session owner's
717
717
  identity is already the actor.
718
718
 
719
719
  | BuildStore operation | HTTP route | Request | Success |
@@ -967,7 +967,7 @@ project; phase CLI scoped handles still constrain build and session access.
967
967
  Authenticated raw writes cannot claim a delegated `via`. Owner-project
968
968
  credentials also use their recorded creator for operator writes. Dispatcher
969
969
  credentials have an immutable server-side purpose: raw store and tickets only,
970
- never human operator controls. The hosted dispatcher issues one per project
970
+ never operator controls. The hosted dispatcher issues one per project
971
971
  invocation, expiring at its configured TTL, and does not revoke at tick return
972
972
  for dispatcher plumbing. Spawned builds receive independent delegated grants. Shared content-addressed blobs
973
973
  remain deduplicated; this is resource authorization, not blob partitioning.
@@ -1006,6 +1006,9 @@ Build grants live until 60 seconds after durable build termination. Phase grants
1006
1006
  also retire 60 seconds after their own session ends, whichever comes first.
1007
1007
  Harvest grants retire 60 seconds after their run stops or their authorized
1008
1008
  execution ends/releases; harvest phases additionally retire on session end.
1009
+ Durable harvest suspension immediately closes the phase grant, without a grace interval.
1010
+ A resumed local harvest turn opens a new bracket and receives fresh credentials;
1011
+ the predecessor grant stays closed.
1009
1012
  The boundary is exclusive: at `end + 60_000ms` the credential is refused. This
1010
1013
  window permits final transcripts, diagnostics, deposits and stream closure.
1011
1014
  Pause/escalation of a build and lease expiry do not end authority. Active grants
@@ -33,6 +33,9 @@ need their own demand. Existing frozen transactions, including ones reserved
33
33
  before upgrade, finish first; later demand coalesces onto the latest parent.
34
34
  Leaves keep verify-entry and awaiting-landing restacks for every target.
35
35
 
36
+ For observation cadence, durable wakes and last-check evidence, see
37
+ [node polling and status](integration-tree.md#polling-and-status).
38
+
36
39
  Presence demand uses change identities, never ticket resolution alone. It follows
37
40
  only the path from the nearest proven ancestor source down to the dependent's
38
41
  actual destination, processing ancestors first. Unrelated siblings stay idle;
@@ -82,7 +85,7 @@ archives, changes and merge proofs. Lease expiry recovers the same operation,
82
85
  not a competing one. Prepared/conflicted/replayed item receipts, publication
83
86
  intent, proven replacement and settlement distinguish each recovery boundary.
84
87
  Inventory retains its sampled source boundary even while the confirmed parent
85
- boundary stays unchanged. It exposes source identities, node-owned foreign commits, active operation,
88
+ boundary stays unchanged. It exposes source identities, hand-pushed changes (node-owned foreign commits), active operation,
86
89
  conflict item and unsafe merge evidence.
87
90
 
88
91
  Only a conflicted item attaches a reconcile runner. It receives the original
package/docs/seams.md ADDED
@@ -0,0 +1,66 @@
1
+ ---
2
+ title: "Infrastructure seams"
3
+ group: "reference"
4
+ description: "Choose stores, agent runtimes, forges, workspaces, and ticket sources, and understand where local and remote execution run."
5
+ label: "Seams"
6
+ order: 7
7
+ ---
8
+
9
+ # Infrastructure seams
10
+
11
+ Adapters supply storage, agent execution, code publication, workspaces and tickets. You choose each independently: a remote database doesn't move computation to a remote machine.
12
+
13
+
14
+ ## Storage and tickets
15
+
16
+ - **BuildStore.** Local SQLite with filesystem artifacts by default; a Postgres adapter, exposed over the network by the hosted HTTP service.
17
+ - **Tickets.** Local files, Linear, or hosted tickets. A hosted Store doesn't require hosted tickets.
18
+
19
+ See [Build store](build-store.md) and [Tickets](ticket-sources.md).
20
+
21
+
22
+ ## Agents, code, and workspaces
23
+
24
+ - **Agent runtimes.** Claude Code, Codex and Pi. Roles choose runtime and model.
25
+ - **Forges.** GitHub and local git. Remote setups need GitHub.
26
+ - **Workspaces.** Local git worktrees, or Vercel Sandbox machines for runners, agents and checks.
27
+
28
+ Every environment needs the runtime, tools, dependencies and credentials; remote ones also need reproducible provisioning. See [Workspaces](workspaces.md).
29
+
30
+
31
+ ## What runs where
32
+
33
+ | Piece | All local | All remote |
34
+ |---|---|---|
35
+ | Dispatcher | your machine | hosted, scheduled, origin-mode configuration |
36
+ | Build runners, agents, checks | your machine, in git worktrees | Vercel Sandbox |
37
+ | Store | local SQLite | hosted Store on Postgres |
38
+ | Tickets | file or any other source | a remote ticket source |
39
+ | Forge | local git or GitHub | GitHub |
40
+ | Operator access | terminal dashboard and local CLI | browser or MCP connector |
41
+
42
+ - File tickets and local git make all-local independent of GitHub.
43
+ - The operator agent is external in both.
44
+ - Choosing Postgres alone doesn't make anything remote.
45
+ - Mixed deployments work within adapter constraints, e.g. a local dispatcher with a hosted Store and remote sandboxes.
46
+
47
+ See [Dispatcher hosting](dispatcher-hosting.md).
48
+
49
+
50
+ ## Extend the boundaries
51
+
52
+ - **Plugin modules** register ticket sources, agent runtimes, workspace providers and forges. See [Writing a plugin](plugin-authoring.md).
53
+ - **BuildStores** implement the storage or remote protocol contract, not a plugin registration.
54
+ - **Verify and finalize steps** and editable skills extend repository behavior; the phases stay fixed. See [Configuration](configuration-overview.md).
55
+ - **Hosting and operator surfaces** are deployment choices, not plugin ports.
56
+
57
+ ## Seam guides
58
+
59
+ - [Tickets](ticket-sources.md): file, Linear, hosted, ticket trees.
60
+ - [Agent runtimes](agent-runtimes.md): Claude Code, Codex, Pi, models.
61
+ - [Workspaces](workspaces.md): git worktree, Vercel Sandbox, provisioning.
62
+ - [Forges](forges.md): GitHub, local git, publication adapters.
63
+ - [Build store](build-store.md): SQLite, Postgres, HTTP, contracts.
64
+ - [Dispatcher hosting](dispatcher-hosting.md): local processes, scheduled hosted ticks.
65
+ - [Operator surfaces](operator-surfaces.md): terminal, web, CLI, MCP.
66
+ - [Writing a plugin](plugin-authoring.md): modules, contracts, packaging, publishing.