@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
@@ -1,134 +1,146 @@
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. The host fills missing build attribution from its
88
- current build-scoped operation; otherwise the request is repository/unattributed.
89
- 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) |
90
109
 
91
110
  ```ts
92
111
  observeRequests(observer: ForgeRequestObserver) {
93
112
  this.observers.add(observer)
94
113
  return () => { this.observers.delete(observer) }
95
114
  }
96
- // At the actual transport boundary:
97
- for (const observer of this.observers) observer({ build: context.build })
98
- return transport(method, path, options)
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
+ }
99
119
  ```
100
120
 
101
- Declare `apiVersion: '^1.8.0'` when using these capabilities. Compatible legacy
102
- 1.x plugins still load without observers and show unavailable counts. Arbitrary
103
- legacy errors are not classified automatically.
104
-
105
- Plugin API 1.7 extends the workspace-provider factory context with the
106
- host-derived seams a store-requiring remote provider needs. Workspace-provider
107
- factories additionally receive `storeRef` and `delegateCredential` (guaranteed present
108
- when the registration declares `capabilities.storeRequirements`),
109
- `runtimeReferences` (the host's effective runtime routes; absent at call sites
110
- that reference no runtimes), and the checkout-less `origin` and
111
- `remoteBranchHead` readers (absent means fall back to host `git` from
112
- `repoRoot`). All five are optional, and a factory that ignores them changes
113
- nothing. A plugin reading the new seams should declare an API range containing
114
- `^1.7.0`.
115
-
116
- `BuildStore` and `BlobStore` contract types are exported for remote-server
117
- authors, but BuildStore is **not** an in-process manifest map. Implement the
118
- colocated language-neutral
119
- [remote store protocol](remote-store-protocol.md) and run its conformance path
120
- instead. `TelemetrySource` is a frozen port type with no plugin registration
121
- surface in this release.
122
-
123
- All four manifest maps have production selectors. Use `[tickets].source` for a
124
- ticket source, the root `forge` key for a forge, `[workspace].provider` for a
125
- workspace provider, and `[roles.*].runtime` for an agent runtime. Omitted forge
126
- and workspace selectors retain the builtin `github` and `git-worktree` defaults;
127
- 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.
128
122
 
129
- ## 2. Create a repository-local module
123
+ ### Read scopes
130
124
 
131
- Start in the consuming repository, for example:
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
132
144
 
133
145
  ```text
134
146
  my-repository/
@@ -136,8 +148,7 @@ my-repository/
136
148
  └── autobuild-plugin.ts
137
149
  ```
138
150
 
139
- Use erased imports in real adapter production code whenever the SDK symbols are
140
- only types:
151
+ Use `import type` for SDK symbols that are only types:
141
152
 
142
153
  ```ts
143
154
  import type {
@@ -159,50 +170,40 @@ export default {
159
170
  } satisfies AutobuildPluginManifest
160
171
  ```
161
172
 
162
- Every module must default-export one strict `AutobuildPluginManifest`:
163
-
164
- - `name` is a nonblank diagnostic/ownership identity; it need not equal the npm
165
- package name.
166
- - `apiVersion` is a semver **range accepted by the plugin**, not the plugin's
167
- package version. Choose the narrowest range containing the host plugin API
168
- against which you ran contracts. `ab plugin list` reports the declared range
169
- and host version; invalid or incompatible ranges fail loading.
170
- - The only registration keys are `ticketSources`, `agentRuntimes`,
171
- `workspaceProviders`, and `forges`. Unknown manifest fields fail validation.
172
- Adapter names are yours to choose: every declared name is registered
173
- verbatim, including one such as `__proto__` that collides with an inherited
174
- object property — declare that one computed, `{ ['__proto__']: factory }`,
175
- since a plain `__proto__:` key in an object literal sets the prototype
176
- instead of declaring an adapter. The parsed maps have a null prototype, so
177
- reading an undeclared name answers `undefined` rather than an inherited
178
- member. A blank or whitespace-only name is rejected: an adapter is selected
179
- from configuration by name.
180
- - A registration may be a bare adapter factory, or
181
- `{ factory, contract: { factory, live? } }`. The first factory returns the
182
- adapter; the contract factory returns that port suite's fixture factory.
183
- Ticket-source descriptors may additionally declare a deduplicated
184
- `requiredEnv` list; the host rejects missing or empty credentials before
185
- invoking that selected factory.
186
- - Every adapter and contract factory receives `{ config, env, repoRoot }`:
187
- adapter-specific read-only `config`, the process `env`, and `repoRoot` as the
188
- absolute consuming-repository root. Ticket sources receive the existing
189
- `[tickets]` fields, workspace providers receive `[workspace.config]`, and
190
- runtime and forge factories currently receive an empty `config` object.
191
- Workspace providers additionally receive the host-derived seams (API 1.7):
192
- `storeRef` and `delegateCredential` — guaranteed URL and exchange callback when the registration
193
- declares `capabilities.storeRequirements` — plus `runtimeReferences`,
194
- `origin`, and `remoteBranchHead`. Each seam is optional and absent when the
195
- host call site supplies no such value; absent `origin`/`remoteBranchHead`
196
- fall back to host `git` from `repoRoot`.
197
-
198
- Add the module specifier at the TOML root, before any table. Repository-path
199
- specifiers resolve from the config-bearing root, which is the immutable build
200
- worktree in scoped phases. npm package specifiers resolve from the consuming
201
- main checkout's installed dependencies first, then from the Autobuild
202
- installation the CLI runs from as a fallback. Install extensions in the
203
- consuming repository with `bun add -d --exact @defrex/autobuild-<extension>`;
204
- a repository copy wins over an installed one, and missing packages fail and
205
- 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:
206
207
 
207
208
  ```toml
208
209
  plugins = ["./autobuild-plugin.ts"]
@@ -213,42 +214,40 @@ source = "file"
213
214
  readyState = "ready"
214
215
  ```
215
216
 
216
- Each configured specifier string must be unique. An exact repeat fails config
217
- validation before Bun resolves or evaluates any plugin, identifies the repeated
218
- value and both list positions, and tells the operator to remove or deduplicate
219
- the entry. Distinct specifiers remain separate declarations.
220
-
221
- Select only the adapters the repository uses. Set `forge = "acme"` for the
222
- example forge above; set `[tickets].source`, `[workspace].provider`, or a
223
- `[roles.*].runtime` to the matching registration name for the other ports.
224
- Ticket plugins receive the existing strict `[tickets]` fields—there is no
225
- untyped plugin-options table. Workspace plugins put adapter-owned settings only
226
- under the open `[workspace.config]` table.
227
-
228
- Plugin modules load in declaration order. Resolution/evaluation failure, a
229
- missing or malformed default export, incompatible API range, or collision
230
- fails before claims/builds. Builtin and earlier-plugin names cannot be
231
- shadowed within one port; a collision between distinct plugins identifies the
232
- adapter and both owners. The same adapter name may exist on different ports.
233
- Registration is atomic per manifest. Plugins are trusted like configured shell
234
- commands: Bun evaluates them in-process with repository authority and no
235
- 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.
236
241
 
237
242
  ## 3. Keep secrets out of source and config
238
243
 
239
- Never put credentials in `autobuild.toml`, the manifest, committed fixtures, or
240
- contract output. Read them from the factory's `env` (for example
241
- `env.ACME_FORGE_TOKEN`) and document the required environment variables. Keep
242
- local values in ignored environment files or the process secret manager.
243
- Validate missing credentials when the selected adapter or live fixture is
244
- created, not at module top level, so registration remains lazy and diagnostics
245
- can inspect unrelated adapters. Ticket-source descriptors should declare
246
- `requiredEnv` when the host can enforce the credential names before factory
247
- 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.
248
247
 
249
248
  ## 4. Add the contract harness first
250
249
 
251
- A contract-bearing registration has this shape:
250
+ A contract-bearing registration:
252
251
 
253
252
  ```ts
254
253
  const manifest = {
@@ -263,25 +262,22 @@ const manifest = {
263
262
  } satisfies AutobuildPluginManifest
264
263
  ```
265
264
 
266
- The descriptor's factory returns a `TicketSourceContractFactory`,
267
- `AgentRunnerContractFactory`, `WorkspaceProviderContractFactory`, or
268
- `ForgeContractFactory` as appropriate. Use the matching harness types exported
269
- by `@defrex/autobuild/plugin-sdk`. The host invokes the unchanged shared suite; do not
270
- 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.
271
266
 
272
- Contract fixtures must isolate resources (UUID-namespaced records, branches,
273
- PRs, sessions, or workspaces), expose the independent controls/probes required
274
- by their harness type, clean up in `cleanup` even after assertion failure, and
275
- make retries/release idempotent where the port requires it. A fixture that
276
- contacts a provider or mutates external resources must declare
277
- `contract: { factory, live: true }`. Autobuild refuses to launch it unless the
278
- operator explicitly sets:
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:
279
275
 
280
276
  ```sh
281
277
  AB_RUN_LIVE_PORT_CONTRACTS=1 ab plugin test forge acme
282
278
  ```
283
279
 
284
- Run the author loop from the consuming repository:
280
+ Author loop:
285
281
 
286
282
  ```sh
287
283
  ab plugin list
@@ -289,25 +285,19 @@ ab plugin doctor
289
285
  ab plugin test ticket-source acme
290
286
  ```
291
287
 
292
- - `list` shows builtins and configured registrations, provenance, module
293
- resolution, plugin API compatibility, and contract availability.
294
- - `doctor` attempts every configured module and exits nonzero if any fail. It
295
- checks loading/registration, not adapter semantics.
296
- - `test` launches Bun's unchanged suite for exactly one port/adapter, forwards
297
- 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 |
298
293
 
299
- Repeat after every adapter change. The adapter is done only when that command's
300
- 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.
301
295
 
302
296
  ## 5. Zero-network wiring walkthrough
303
297
 
304
- This executable scratch example proves module resolution, manifest spelling,
305
- configuration, and the TicketSource contract bridge without network access. It
306
- uses Autobuild's reference fake and is **only a wiring exercise**. Replace the
307
- fake and fixture with the real provider implementation; certification means the
308
- 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.
309
299
 
310
- Create `autobuild-plugin.ts` with the exact block below.
300
+ Create `autobuild-plugin.ts`:
311
301
 
312
302
  <!-- plugin-authoring-walkthrough-module:start -->
313
303
  ```ts
@@ -363,14 +353,11 @@ ab plugin list
363
353
  ab plugin test ticket-source walkthrough
364
354
  ```
365
355
 
366
- `ab init` preserves the existing config and vendors this guide. Doctor and list
367
- must show the `walkthrough` plugin/adapter, and the final command must exit zero
368
- 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.
369
357
 
370
358
  ## 6. Package and publish when reuse warrants it
371
359
 
372
- A repository-local module is the shortest path and needs no packaging. For an
373
- 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:
374
361
 
375
362
  ```text
376
363
  acme-autobuild-plugin/
@@ -380,7 +367,7 @@ acme-autobuild-plugin/
380
367
  └── bun.lock
381
368
  ```
382
369
 
383
- 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.
384
371
 
385
372
  ```json
386
373
  {
@@ -394,24 +381,14 @@ A representative package manifest is:
394
381
  "test": "bun test",
395
382
  "prepublishOnly": "bun run typecheck && bun test"
396
383
  },
397
- "devDependencies": { "autobuild": "^2.0.0", "typescript": "^7.0.0" },
398
- "peerDependencies": { "autobuild": "^2.0.0" },
399
- "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 } }
400
387
  }
401
388
  ```
402
389
 
403
- When production code imports only SDK types, those imports erase: Autobuild is
404
- an authoring/test dev dependency, not a runtime `dependencies` entry. An
405
- optional peer declaration communicates tested host-package compatibility to
406
- package consumers without making plugin execution depend on a second Autobuild
407
- copy. Runtime imports (for example importing a reference fake in the scratch
408
- walkthrough) are different and require a runtime dependency; do not ship the
409
- fake walkthrough as a production adapter.
410
-
411
- Keep the package's own semver independent from the manifest's `apiVersion`
412
- range. On an incompatible host plugin API, update the adapter and contracts,
413
- change the range only after they pass against that host, and release the
414
- 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.
415
392
 
416
393
  Before publishing:
417
394
 
@@ -424,38 +401,26 @@ npm pack
424
401
  npm publish --access public
425
402
  ```
426
403
 
427
- Inspect the dry-run/tarball file list for source, secrets, local fixtures, and
428
- missing exports. Install the generated tarball in a scratch consuming
429
- repository, configure `plugins = ["@acme/autobuild-plugin"]`, and rerun
430
- `ab plugin doctor`, `ab plugin list`, and the contract command before publish.
431
- Use `--access public` for a public scoped package; omit it when registry/access
432
- 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.
433
409
 
434
410
  Official npm references: [`package.json` fields](https://docs.npmjs.com/cli/v11/configuring-npm/package-json),
435
411
  [`npm pack`](https://docs.npmjs.com/cli/v11/commands/npm-pack), and
436
412
  [`npm publish`](https://docs.npmjs.com/cli/v11/commands/npm-publish).
437
413
 
438
- Remote workspace factories must use `delegateCredential(storeRef, undefined,
439
- target)` to obtain per-resource grants before provisioning or launching guests.
440
- The callback keeps parent authority in host composition. `storeToken` is retired
441
- and is never supplied; factory environments also exclude `AB_TOKEN`. Launch
442
- credentials travel through the separate transient execution-auth argument, never
443
- through serialized execution identity. Existing plugins that forwarded
444
- `storeToken` must migrate to this callback and fail closed if it is unavailable.
445
-
446
414
  ## Optional ticket tree capability
447
415
 
448
- Existing ticket-source factories remain compatible without new methods or fields.
449
- Raw `Ticket.kind` is optional for source compatibility; public projections normalize
450
- it to `work`. An adapter opts in with `integrationTree: true` and implements
451
- `listAll(): Promise<TicketListing>` over every state, independently of ready filters.
452
- It must persist `kind?: 'work' | 'node'` and `target?: string | null` on drafts
453
- and updates: omitted preserves/defaults, explicit work resets kind, null clears
454
- target. Read targets are source-local canonical ticket ids. Validate same-source
455
- existence, node kind, self/ancestor cycles, corrupt chains and demotion with any
456
- children before writing any mixed patch, including revision-checked writes.
457
- Expose kind/target in revisions. Exhaust provider pagination and propagate
458
- infrastructure failures. Do not opt in if the source cannot preserve these semantics.
459
- Legacy sources receive ordinary CRUD unchanged; metadata writes are refused by
460
- the compatibility facade before legacy methods run. Unsupported sources should
461
- 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.