@defrex/autobuild 1.0.0-beta.4 → 1.0.1

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 (54) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +45 -36
  3. package/docs/agent-runtimes.md +157 -0
  4. package/docs/build-store.md +123 -0
  5. package/docs/builds.md +82 -0
  6. package/docs/cli.md +48 -0
  7. package/docs/configuration-overview.md +93 -0
  8. package/docs/configuration.md +1626 -204
  9. package/docs/dispatcher-hosting.md +115 -0
  10. package/docs/dispatcher.md +59 -0
  11. package/docs/forges.md +121 -0
  12. package/docs/getting-started.md +60 -0
  13. package/docs/glossary.md +60 -0
  14. package/docs/hosted-service.md +2 -2
  15. package/docs/intake.md +48 -0
  16. package/docs/integration-overview.md +81 -0
  17. package/docs/operating.md +114 -0
  18. package/docs/operator-api.md +6 -6
  19. package/docs/operator-surfaces.md +90 -0
  20. package/docs/overview.md +49 -0
  21. package/docs/plugin-authoring.md +426 -0
  22. package/docs/remote-store-protocol.md +8 -8
  23. package/docs/seams.md +66 -0
  24. package/docs/setup.md +8 -6
  25. package/docs/skills.md +119 -0
  26. package/docs/ticket-sources.md +132 -0
  27. package/docs/tickets.md +69 -0
  28. package/docs/troubleshooting.md +111 -0
  29. package/docs/upgrading.md +50 -0
  30. package/docs/verification.md +146 -0
  31. package/docs/website.md +47 -5
  32. package/docs/workspaces.md +152 -0
  33. package/package.json +5 -4
  34. package/packages/core/src/cli/env.ts +1 -1
  35. package/packages/core/src/cli/help.ts +4 -2
  36. package/packages/core/src/config/landing.ts +8 -0
  37. package/packages/core/src/config/reference-metadata.ts +31 -0
  38. package/packages/core/src/config/reference.ts +342 -0
  39. package/packages/core/src/config/roles.ts +1 -1
  40. package/packages/core/src/config/schema.ts +344 -6
  41. package/packages/core/src/ontology.ts +2 -2
  42. package/packages/core/src/open-map.ts +3 -1
  43. package/skills/finalize/SKILL.md +3 -1
  44. package/skills/guide/SKILL.md +42 -25
  45. package/skills/guide/references/operator-api.md +18 -10
  46. package/skills/guide/references/plugin-authoring.md +227 -303
  47. package/skills/guide/references/remote-store-protocol.md +8 -8
  48. package/skills/guide/references/setup.md +8 -6
  49. package/skills/implement/SKILL.md +4 -2
  50. package/skills/operate/SKILL.md +26 -27
  51. package/skills/plan/SKILL.md +12 -4
  52. package/skills/spec/SKILL.md +1 -1
  53. package/skills/tickets/SKILL.md +1 -1
  54. package/templates/hosted-service/package.json +2 -2
@@ -1,96 +1,111 @@
1
- # Authoring Autobuild plugins
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
+ ---
2
8
 
3
- Install Autobuild in the target repository with `bun add -d --exact @defrex/autobuild`.
4
- Here, `ab <command>` means the repository-installed CLI; run it as
5
- `bun ab <command>`, for example `bun ab init`.
9
+ # Writing a plugin
6
10
 
7
- Use this reference when asked to connect Autobuild to another ticket tracker,
8
- agent runtime, workspace system, or forge. A plugin is a trusted Bun module
9
- loaded in-process from the consuming repository. **Definition of done for an
10
- adapter: the unchanged shared contract suite for its port passes.** Interface
11
- conformance or a successful `ab plugin doctor` alone is not certification.
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.
12
16
 
13
17
  ## 1. Choose the port and preserve its semantics
14
18
 
15
- Import public types only from `@defrex/autobuild/plugin-sdk`; package-internal module
16
- paths are not API.
19
+ Import public types only from `@defrex/autobuild/plugin-sdk`; internal module paths are not API.
17
20
 
18
- | CLI port | Manifest map | Factory result | Required semantics |
21
+ | Port | Manifest map | Factory returns | Selected by |
19
22
  |---|---|---|---|
20
- | `ticket-source` | `ticketSources` | `TicketSource` | Initiates a build by listing/getting/claiming tickets and receives comments/transitions/creates/updates. It owns lifecycle names, dependency completion, idempotent creation, stable external creation-key projection, and partial-list diagnostics. It is never consulted mid-build and is not artifact storage. |
21
- | `agent-runtime` | `agentRuntimes` | `RuntimeRegistration` | Wrap an `AgentRunner` that supports start/continue/end, complete transcripts and usage, per-turn environment refresh and cancellation, typed failures with verbatim messages, the retry-compatible `permanent` bit, and optional `cause: availability | exhaustion | credentials | configuration` routing evidence, plus the distribution-managed `ab` launcher. A cancelled turn must retain an endable handle for transcript deposition. Declare served model prefixes/default; optional tool-free `oneShot` is a capability beside the runner interface. |
22
- | `workspace-provider` | `workspaceProviders` | `WorkspaceProvider` | Provision an absolute, writable working copy for the requested branch, return durable base evidence, resume an intact branch non-destructively, rematerialize a lost copy, and make release idempotent. Never silently re-cut resumed work from a newer base. Optional `provision.publication` supplies a durable confirmed SHA and known cache tips for authoritative readback and cache repair; preserve unknown unpublished work. |
23
- | `forge` | `forges` | `Forge` | Implement kernel-owned regular pushes, idempotent PR opening, PR-state projection, gated/ungated auto-merge behavior, head-guarded squash merge, and comments. API 1.2 adds optional idempotent `closePr` and `deleteBranch` abort-cleanup capabilities; `closePr` must preserve a racing merge. Without them abort cleanup remains visibly pending. Agents never receive forge credentials or push. `prAttachments` is an optional image-hosting capability; absence must preserve the supported text-only path. Optional API 1.8 failure classification and request observers are described below. |
24
-
25
- Reconcile requires the optional grouped `Forge.rewrite` capability: snapshot the
26
- actual build branch into a build-private ref, publish immutable exact-SHA refs
27
- under `refs/autobuild/archive/<slug>/<sha>`, and replace the explicit branch with
28
- an explicit expected remote head. Return `lease-mismatch` separately from
29
- transport, auth and policy failures. If the CAS succeeds but another writer
30
- advances it before readback, return `lease-mismatch` with `rewritten: true` and the
31
- observed `actual` head. The kernel records that write and retries the observed
32
- history without claiming completion. After an acknowledged replacement, reattach
33
- the matching detached workspace HEAD to the build branch so later implementation
34
- publication remains usable. Never overwrite unknown work or silently
35
- fall back to merging, ordinary pushes, archive branches or tags. Older forge
36
- plugins remain loadable and receive an actionable refusal at reconcile time.
37
- Remote workspace providers additionally need trusted `WorkspacePublication.rewrite`
38
- after guest execution teardown; ordinary `publish` cannot publish a restack.
39
- Every publication succeeds only after authoritative branch-head readback equals
40
- its frozen intended SHA, including recovery after a failed push. Remote-backed
41
- local refs are caches: set them unconditionally after confirmation, fetching the
42
- advertised ref if objects are missing, without resetting checkout files.
43
- `localExpected` is historical input only. Local-git's shared ref database remains
44
- authoritative and keeps CAS. Ordinary `pushBranch(workspacePath, branch, sha?)`
45
- receives the frozen SHA from kernel callers and remains fast-forward only;
46
- legacy callers may omit SHA to select HEAD. Implement `confirmPublication`
47
- to inspect the authoritative head and refresh caches only on an exact SHA match;
48
- kernel callers refuse adapters without it before attempting a push. Hosted `WorkspacePublication` must
49
- provide authoritative `isPublished` and confirm after writing, as well as before
50
- retrying. Remote inspection must not resume a stopped guest or run commands in
51
- it: refresh the guest cache inside trusted publication before stopping it. Missing inspection fails actionably. Unconfirmed candidate ancestry
52
- never proves publication.
53
-
54
- Plugin API 1.3 adds the optional AgentRunner failure `cause` and the
55
- `exhaustion-failure` shared-contract scenario. Legacy failures without `cause`
56
- remain supported: `permanent: false` is eligible for a configured alternate,
57
- while `permanent: true` stops the chain. A runtime plugin that emits/depends on
58
- the richer cause should declare an API range containing `^1.3.0`.
59
-
60
- Plugin API 1.4 adds optional `Ticket.creationKey`. Ticket-source plugins should
61
- project the stable external create/adoption key from `create`, `get`, and
62
- `listReady`; Autobuild uses it to correlate ready tickets with durable Harvest
63
- reservations while blocker recording is unfinished. Legacy tickets may omit the
64
- field and continue to dispatch normally. A plugin relying on this host gate
65
- should declare an API range containing `^1.4.0`.
66
-
67
- Plugin API 1.5 makes remote workspace locations explicit. `path` is the path in
68
- the workspace environment; set optional `localPath` only when that same working
69
- copy is directly reachable by the dispatcher. Workspace-owned executors receive
70
- the durable provider locator as `BuildExecutionStart.workspaceRef`; local PID
71
- supervision remains host-owned. A workspace plugin relying on these fields
72
- should declare an API range containing `^1.5.0`.
73
-
74
- Plugin API 1.8 adds optional forge failure classification and request accounting.
75
- Import the runtime `ForgeFailure` constructor and `isForgeFailure`, plus types
76
- `ForgeFailureDetails`, `ForgeRequestObserver`, and `ForgeRequestContext` from
77
- `@defrex/autobuild/plugin-sdk`. Throw
78
- `new ForgeFailure(message, { kind: 'rate-limited', resetAt })` with a valid ISO
79
- reset timestamp, or `{ kind: 'transient', retry: 'retryable' }` for retryable
80
- transport errors. Ordinary policy/permission refusals remain deferrals. Never
81
- include credentials. The `forgeFailure: 'autobuild.forge-failure.v1'` discriminant
82
- and validated details work across separately loaded SDK copies.
83
-
84
- Optionally implement `Forge.observeRequests(observer): () => void`; return a
85
- disposer and call registered observers once per wire request, including failed
86
- requests and pagination. Pass `ForgeRequestContext` with the build slug when
87
- known, or `{}` when unknown. Capture attribution before awaiting transport and
88
- notify after its outcome is known. Optional `outcome` is `restPrimary` for REST
89
- HTTP responses other than 304, `restNotModified` for REST 304, or `graphql` for
90
- GraphQL calls (including failures). Network failures have no proven REST debit
91
- and omit the category. The host fills missing build attribution from its
92
- current build-scoped operation; otherwise the request is repository/unattributed.
93
- Credential discovery and skipped calls are not provider requests. For example:
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) |
94
109
 
95
110
  ```ts
96
111
  observeRequests(observer: ForgeRequestObserver) {
@@ -103,48 +118,29 @@ for (const observer of this.observers) {
103
118
  }
104
119
  ```
105
120
 
106
- Optional `withReadScope(work)` wraps a complete dispatcher tick, sharing promises
107
- and observations across builds, and tears down on rejection too. Keep concurrent
108
- operations outside that scope independent. Optional `primeNodeReads({workspacePath,
109
- parent, head, prNumber?})` seeds opened-node facts. Priming is an optimization:
110
- non-cooldown failures produce a diagnostic and fall through to ordinary stage
111
- reads, preserving parent recovery when the previous parent disappeared.
112
- Neither capability changes the
113
- plugin API version requirement. Invalidate observations before writes, including
114
- uncertain writes and Git pushes; acknowledgement and readiness reads must stay
115
- fresh. Branch and ref endpoints share normalized facts, never HTTP validators.
116
-
117
- Declare `apiVersion: '^1.8.0'` when using these capabilities. Compatible legacy
118
- 1.x plugins still load without observers and show unavailable counts. Arbitrary
119
- legacy errors are not classified automatically.
120
-
121
- Plugin API 1.7 extends the workspace-provider factory context with the
122
- host-derived seams a store-requiring remote provider needs. Workspace-provider
123
- factories additionally receive `storeRef` and `delegateCredential` (guaranteed present
124
- when the registration declares `capabilities.storeRequirements`),
125
- `runtimeReferences` (the host's effective runtime routes; absent at call sites
126
- that reference no runtimes), and the checkout-less `origin` and
127
- `remoteBranchHead` readers (absent means fall back to host `git` from
128
- `repoRoot`). All five are optional, and a factory that ignores them changes
129
- nothing. A plugin reading the new seams should declare an API range containing
130
- `^1.7.0`.
131
-
132
- `BuildStore` and `BlobStore` contract types are exported for remote-server
133
- authors, but BuildStore is **not** an in-process manifest map. Implement the
134
- colocated language-neutral
135
- [remote store protocol](remote-store-protocol.md) and run its conformance path
136
- instead. `TelemetrySource` is a frozen port type with no plugin registration
137
- surface in this release.
138
-
139
- All four manifest maps have production selectors. Use `[tickets].source` for a
140
- ticket source, the root `forge` key for a forge, `[workspace].provider` for a
141
- workspace provider, and `[roles.*].runtime` for an agent runtime. Omitted forge
142
- and workspace selectors retain the builtin `github` and `git-worktree` defaults;
143
- role inheritance retains its normal runtime fallback.
121
+ Declare `apiVersion: '^1.8.0'` for these capabilities. Legacy 1.x plugins load without observers and show unavailable counts.
144
122
 
145
- ## 2. Create a repository-local module
123
+ ### Read scopes
124
+
125
+ Forge optimizations that don't change the required plugin API version:
146
126
 
147
- Start in the consuming repository, for example:
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
148
144
 
149
145
  ```text
150
146
  my-repository/
@@ -152,8 +148,7 @@ my-repository/
152
148
  └── autobuild-plugin.ts
153
149
  ```
154
150
 
155
- Use erased imports in real adapter production code whenever the SDK symbols are
156
- only types:
151
+ Use `import type` for SDK symbols that are only types:
157
152
 
158
153
  ```ts
159
154
  import type {
@@ -175,50 +170,40 @@ export default {
175
170
  } satisfies AutobuildPluginManifest
176
171
  ```
177
172
 
178
- Every module must default-export one strict `AutobuildPluginManifest`:
179
-
180
- - `name` is a nonblank diagnostic/ownership identity; it need not equal the npm
181
- package name.
182
- - `apiVersion` is a semver **range accepted by the plugin**, not the plugin's
183
- package version. Choose the narrowest range containing the host plugin API
184
- against which you ran contracts. `ab plugin list` reports the declared range
185
- and host version; invalid or incompatible ranges fail loading.
186
- - The only registration keys are `ticketSources`, `agentRuntimes`,
187
- `workspaceProviders`, and `forges`. Unknown manifest fields fail validation.
188
- Adapter names are yours to choose: every declared name is registered
189
- verbatim, including one such as `__proto__` that collides with an inherited
190
- object property — declare that one computed, `{ ['__proto__']: factory }`,
191
- since a plain `__proto__:` key in an object literal sets the prototype
192
- instead of declaring an adapter. The parsed maps have a null prototype, so
193
- reading an undeclared name answers `undefined` rather than an inherited
194
- member. A blank or whitespace-only name is rejected: an adapter is selected
195
- from configuration by name.
196
- - A registration may be a bare adapter factory, or
197
- `{ factory, contract: { factory, live? } }`. The first factory returns the
198
- adapter; the contract factory returns that port suite's fixture factory.
199
- Ticket-source descriptors may additionally declare a deduplicated
200
- `requiredEnv` list; the host rejects missing or empty credentials before
201
- invoking that selected factory.
202
- - Every adapter and contract factory receives `{ config, env, repoRoot }`:
203
- adapter-specific read-only `config`, the process `env`, and `repoRoot` as the
204
- absolute consuming-repository root. Ticket sources receive the existing
205
- `[tickets]` fields, workspace providers receive `[workspace.config]`, and
206
- runtime and forge factories currently receive an empty `config` object.
207
- Workspace providers additionally receive the host-derived seams (API 1.7):
208
- `storeRef` and `delegateCredential` — guaranteed URL and exchange callback when the registration
209
- declares `capabilities.storeRequirements` — plus `runtimeReferences`,
210
- `origin`, and `remoteBranchHead`. Each seam is optional and absent when the
211
- host call site supplies no such value; absent `origin`/`remoteBranchHead`
212
- fall back to host `git` from `repoRoot`.
213
-
214
- Add the module specifier at the TOML root, before any table. Repository-path
215
- specifiers resolve from the config-bearing root, which is the immutable build
216
- worktree in scoped phases. npm package specifiers resolve from the consuming
217
- main checkout's installed dependencies first, then from the Autobuild
218
- installation the CLI runs from as a fallback. Install extensions in the
219
- consuming repository with `bun add -d --exact @defrex/autobuild-<extension>`;
220
- a repository copy wins over an installed one, and missing packages fail and
221
- are never installed automatically:
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:
222
207
 
223
208
  ```toml
224
209
  plugins = ["./autobuild-plugin.ts"]
@@ -229,67 +214,40 @@ source = "file"
229
214
  readyState = "ready"
230
215
  ```
231
216
 
232
- Inside a cached dispatcher generation, selection still uses those roots, but
233
- selected external plugin code and its installed dependency closure are copied
234
- into an immutable auxiliary snapshot. Native ESM, CommonJS `require`, delayed
235
- imports, export-from and module-anchored `createRequire` all resolve the core
236
- package to the same canonical frozen runtime, including SDK values and classes.
237
- There are no loader hooks or source transforms. Repo-path modules in a consuming
238
- repository use their literal import closure and literal `new URL(..., import.meta.url)`
239
- assets, rather than copying the checkout or its unused dev dependencies. Plugins
240
- with their own package boundary retain that package’s assets and dependency graph.
241
- Package-relative assets remain
242
- beside copied modules; `import.meta.url` and filenames name the snapshot, while
243
- cwd and factory `repoRoot` remain the consuming checkout. Explicit absolute
244
- paths remain plugin-controlled external resources.
245
-
246
- Auxiliary snapshots use neutral compiler boundaries and cached Bun entrypoints
247
- pin the core config with `--no-install --tsconfig-override` before JavaScript
248
- runs. Autobuild-owned compiler chains cannot escape the runtime; installed
249
- third-party development configs are preserved byte-for-byte. New selections
250
- can prepare new snapshots without changing the generation's core identity.
251
- Live plugin processes retain their core runtime independently of Store leases.
252
- Plugin-loading CLI calls reclaim dead auxiliary snapshots during the generation,
253
- so edits between phase commands do not accumulate checkout-sized copies.
254
- Ordinary noncached consumers retain the separately loaded SDK compatibility
255
- rules described above.
256
-
257
- Each configured specifier string must be unique. An exact repeat fails config
258
- validation before Bun resolves or evaluates any plugin, identifies the repeated
259
- value and both list positions, and tells the operator to remove or deduplicate
260
- the entry. Distinct specifiers remain separate declarations.
261
-
262
- Select only the adapters the repository uses. Set `forge = "acme"` for the
263
- example forge above; set `[tickets].source`, `[workspace].provider`, or a
264
- `[roles.*].runtime` to the matching registration name for the other ports.
265
- Ticket plugins receive the existing strict `[tickets]` fields—there is no
266
- untyped plugin-options table. Workspace plugins put adapter-owned settings only
267
- under the open `[workspace.config]` table.
268
-
269
- Plugin modules load in declaration order. Resolution/evaluation failure, a
270
- missing or malformed default export, incompatible API range, or collision
271
- fails before claims/builds. Builtin and earlier-plugin names cannot be
272
- shadowed within one port; a collision between distinct plugins identifies the
273
- adapter and both owners. The same adapter name may exist on different ports.
274
- Registration is atomic per manifest. Plugins are trusted like configured shell
275
- commands: Bun evaluates them in-process with repository authority and no
276
- sandbox.
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.
277
241
 
278
242
  ## 3. Keep secrets out of source and config
279
243
 
280
- Never put credentials in `autobuild.toml`, the manifest, committed fixtures, or
281
- contract output. Read them from the factory's `env` (for example
282
- `env.ACME_FORGE_TOKEN`) and document the required environment variables. Keep
283
- local values in ignored environment files or the process secret manager.
284
- Validate missing credentials when the selected adapter or live fixture is
285
- created, not at module top level, so registration remains lazy and diagnostics
286
- can inspect unrelated adapters. Ticket-source descriptors should declare
287
- `requiredEnv` when the host can enforce the credential names before factory
288
- invocation; other ports validate their environment in their factories.
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.
289
247
 
290
248
  ## 4. Add the contract harness first
291
249
 
292
- A contract-bearing registration has this shape:
250
+ A contract-bearing registration:
293
251
 
294
252
  ```ts
295
253
  const manifest = {
@@ -304,25 +262,22 @@ const manifest = {
304
262
  } satisfies AutobuildPluginManifest
305
263
  ```
306
264
 
307
- The descriptor's factory returns a `TicketSourceContractFactory`,
308
- `AgentRunnerContractFactory`, `WorkspaceProviderContractFactory`, or
309
- `ForgeContractFactory` as appropriate. Use the matching harness types exported
310
- by `@defrex/autobuild/plugin-sdk`. The host invokes the unchanged shared suite; do not
311
- copy, wrap, skip, or weaken its assertions.
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:
312
268
 
313
- Contract fixtures must isolate resources (UUID-namespaced records, branches,
314
- PRs, sessions, or workspaces), expose the independent controls/probes required
315
- by their harness type, clean up in `cleanup` even after assertion failure, and
316
- make retries/release idempotent where the port requires it. A fixture that
317
- contacts a provider or mutates external resources must declare
318
- `contract: { factory, live: true }`. Autobuild refuses to launch it unless the
319
- operator explicitly sets:
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:
320
275
 
321
276
  ```sh
322
277
  AB_RUN_LIVE_PORT_CONTRACTS=1 ab plugin test forge acme
323
278
  ```
324
279
 
325
- Run the author loop from the consuming repository:
280
+ Author loop:
326
281
 
327
282
  ```sh
328
283
  ab plugin list
@@ -330,25 +285,19 @@ ab plugin doctor
330
285
  ab plugin test ticket-source acme
331
286
  ```
332
287
 
333
- - `list` shows builtins and configured registrations, provenance, module
334
- resolution, plugin API compatibility, and contract availability.
335
- - `doctor` attempts every configured module and exits nonzero if any fail. It
336
- checks loading/registration, not adapter semantics.
337
- - `test` launches Bun's unchanged suite for exactly one port/adapter, forwards
338
- per-test output, and returns its exit status.
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 |
339
293
 
340
- Repeat after every adapter change. The adapter is done only when that command's
341
- shared suite is green (with the explicit live opt-in when applicable).
294
+ Repeat after every adapter change until the suite is green, with the live opt-in when applicable.
342
295
 
343
296
  ## 5. Zero-network wiring walkthrough
344
297
 
345
- This executable scratch example proves module resolution, manifest spelling,
346
- configuration, and the TicketSource contract bridge without network access. It
347
- uses Autobuild's reference fake and is **only a wiring exercise**. Replace the
348
- fake and fixture with the real provider implementation; certification means the
349
- real adapter's harness passes the same unchanged suite.
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.
350
299
 
351
- Create `autobuild-plugin.ts` with the exact block below.
300
+ Create `autobuild-plugin.ts`:
352
301
 
353
302
  <!-- plugin-authoring-walkthrough-module:start -->
354
303
  ```ts
@@ -404,14 +353,11 @@ ab plugin list
404
353
  ab plugin test ticket-source walkthrough
405
354
  ```
406
355
 
407
- `ab init` preserves the existing config and vendors this guide. Doctor and list
408
- must show the `walkthrough` plugin/adapter, and the final command must exit zero
409
- with the TicketSource contract tests.
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.
410
357
 
411
358
  ## 6. Package and publish when reuse warrants it
412
359
 
413
- A repository-local module is the shortest path and needs no packaging. For an
414
- npm plugin, keep one public module and an ordinary test/typecheck setup:
360
+ A repository-local module needs no packaging. An npm plugin needs one public module plus ordinary test and typecheck setup:
415
361
 
416
362
  ```text
417
363
  acme-autobuild-plugin/
@@ -421,7 +367,7 @@ acme-autobuild-plugin/
421
367
  └── bun.lock
422
368
  ```
423
369
 
424
- A representative package manifest is:
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.
425
371
 
426
372
  ```json
427
373
  {
@@ -435,24 +381,14 @@ A representative package manifest is:
435
381
  "test": "bun test",
436
382
  "prepublishOnly": "bun run typecheck && bun test"
437
383
  },
438
- "devDependencies": { "autobuild": "^2.0.0", "typescript": "^7.0.0" },
439
- "peerDependencies": { "autobuild": "^2.0.0" },
440
- "peerDependenciesMeta": { "autobuild": { "optional": true } }
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 } }
441
387
  }
442
388
  ```
443
389
 
444
- When production code imports only SDK types, those imports erase: Autobuild is
445
- an authoring/test dev dependency, not a runtime `dependencies` entry. An
446
- optional peer declaration communicates tested host-package compatibility to
447
- package consumers without making plugin execution depend on a second Autobuild
448
- copy. Runtime imports (for example importing a reference fake in the scratch
449
- walkthrough) are different and require a runtime dependency; do not ship the
450
- fake walkthrough as a production adapter.
451
-
452
- Keep the package's own semver independent from the manifest's `apiVersion`
453
- range. On an incompatible host plugin API, update the adapter and contracts,
454
- change the range only after they pass against that host, and release the
455
- package version according to the user-visible compatibility change.
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.
456
392
 
457
393
  Before publishing:
458
394
 
@@ -465,38 +401,26 @@ npm pack
465
401
  npm publish --access public
466
402
  ```
467
403
 
468
- Inspect the dry-run/tarball file list for source, secrets, local fixtures, and
469
- missing exports. Install the generated tarball in a scratch consuming
470
- repository, configure `plugins = ["@acme/autobuild-plugin"]`, and rerun
471
- `ab plugin doctor`, `ab plugin list`, and the contract command before publish.
472
- Use `--access public` for a public scoped package; omit it when registry/access
473
- policy says otherwise.
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.
474
409
 
475
410
  Official npm references: [`package.json` fields](https://docs.npmjs.com/cli/v11/configuring-npm/package-json),
476
411
  [`npm pack`](https://docs.npmjs.com/cli/v11/commands/npm-pack), and
477
412
  [`npm publish`](https://docs.npmjs.com/cli/v11/commands/npm-publish).
478
413
 
479
- Remote workspace factories must use `delegateCredential(storeRef, undefined,
480
- target)` to obtain per-resource grants before provisioning or launching guests.
481
- The callback keeps parent authority in host composition. `storeToken` is retired
482
- and is never supplied; factory environments also exclude `AB_TOKEN`. Launch
483
- credentials travel through the separate transient execution-auth argument, never
484
- through serialized execution identity. Existing plugins that forwarded
485
- `storeToken` must migrate to this callback and fail closed if it is unavailable.
486
-
487
414
  ## Optional ticket tree capability
488
415
 
489
- Existing ticket-source factories remain compatible without new methods or fields.
490
- Raw `Ticket.kind` is optional for source compatibility; public projections normalize
491
- it to `work`. An adapter opts in with `integrationTree: true` and implements
492
- `listAll(): Promise<TicketListing>` over every state, independently of ready filters.
493
- It must persist `kind?: 'work' | 'node'` and `target?: string | null` on drafts
494
- and updates: omitted preserves/defaults, explicit work resets kind, null clears
495
- target. Read targets are source-local canonical ticket ids. Validate same-source
496
- existence, node kind, self/ancestor cycles, corrupt chains and demotion with any
497
- children before writing any mixed patch, including revision-checked writes.
498
- Expose kind/target in revisions. Exhaust provider pagination and propagate
499
- infrastructure failures. Do not opt in if the source cannot preserve these semantics.
500
- Legacy sources receive ordinary CRUD unchanged; metadata writes are refused by
501
- the compatibility facade before legacy methods run. Unsupported sources should
502
- also refuse metadata explicitly at their own direct write boundary.
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.