@defrex/autobuild 1.1.0 → 1.3.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 (157) hide show
  1. package/README.md +5 -13
  2. package/SPEC.md +249 -15
  3. package/bin/ab-dispatch-generation.ts +11 -2
  4. package/docs/accounts.md +130 -0
  5. package/docs/agent-runtimes.md +4 -4
  6. package/docs/answering-blocked-builds.md +4 -1
  7. package/docs/architecture.md +224 -12
  8. package/docs/build-store.md +3 -41
  9. package/docs/builds.md +2 -0
  10. package/docs/cli.md +14 -0
  11. package/docs/configuration-overview.md +117 -0
  12. package/docs/configuration.md +266 -141
  13. package/docs/dispatcher-hosting.md +18 -33
  14. package/docs/intake.md +2 -0
  15. package/docs/integration-tree.md +16 -5
  16. package/docs/merge-policy.md +1 -3
  17. package/docs/operating.md +1 -2
  18. package/docs/operator-api.md +144 -53
  19. package/docs/operator-surfaces.md +32 -20
  20. package/docs/overview.md +1 -1
  21. package/docs/plugin-authoring.md +27 -1
  22. package/docs/remote-store-protocol.md +259 -91
  23. package/docs/remote-ticket-protocol.md +29 -49
  24. package/docs/restacking.md +45 -0
  25. package/docs/seams.md +8 -8
  26. package/docs/setup.md +34 -129
  27. package/docs/spec-standard.md +4 -2
  28. package/docs/ticket-dependencies.md +8 -0
  29. package/docs/ticket-sources.md +18 -0
  30. package/docs/troubleshooting.md +7 -11
  31. package/docs/upgrading.md +1 -1
  32. package/docs/workspaces.md +4 -4
  33. package/package.json +14 -5
  34. package/packages/core/src/accounts/chatgpt-oauth.ts +216 -0
  35. package/packages/core/src/accounts/chatgpt-state.ts +41 -0
  36. package/packages/core/src/accounts/local-credentials.ts +194 -0
  37. package/packages/core/src/accounts/local-inference.ts +106 -0
  38. package/packages/core/src/accounts/local-owner.ts +123 -0
  39. package/packages/core/src/accounts/sensitive.ts +2 -0
  40. package/packages/core/src/cli/accounts.ts +147 -0
  41. package/packages/core/src/cli/binary.ts +3 -1
  42. package/packages/core/src/cli/connect.ts +3 -3
  43. package/packages/core/src/cli/dispatch-frontend.ts +1 -0
  44. package/packages/core/src/cli/dispatch-handoff.ts +125 -44
  45. package/packages/core/src/cli/dispatch-launch-contract.ts +187 -0
  46. package/packages/core/src/cli/dispatch-launcher.ts +54 -21
  47. package/packages/core/src/cli/dispatch-preflight.ts +6 -1
  48. package/packages/core/src/cli/dispatch-repository-feed.ts +107 -26
  49. package/packages/core/src/cli/dispatch.ts +135 -27
  50. package/packages/core/src/cli/dispatcher-liveness.ts +6 -1
  51. package/packages/core/src/cli/forge-clear.ts +30 -0
  52. package/packages/core/src/cli/help.ts +17 -0
  53. package/packages/core/src/cli/init-readiness-remote.ts +22 -1
  54. package/packages/core/src/cli/init-readiness-shared.ts +5 -1
  55. package/packages/core/src/cli/init-validation.ts +160 -18
  56. package/packages/core/src/cli/main.ts +72 -0
  57. package/packages/core/src/cli/publication-settlement.ts +4 -1
  58. package/packages/core/src/cli/secrets.ts +173 -0
  59. package/packages/core/src/cli/store-opening.ts +11 -1
  60. package/packages/core/src/cli/upgrade-agent.ts +9 -1
  61. package/packages/core/src/cli/watch.ts +12 -14
  62. package/packages/core/src/config/accounts.ts +101 -0
  63. package/packages/core/src/config/live.ts +14 -1
  64. package/packages/core/src/config/roles.ts +54 -3
  65. package/packages/core/src/config/schema.ts +60 -0
  66. package/packages/core/src/events/catalog.ts +1 -0
  67. package/packages/core/src/events/compatibility.ts +2 -1
  68. package/packages/core/src/events/forge-degradation-policy.ts +11 -0
  69. package/packages/core/src/events/payloads.ts +13 -0
  70. package/packages/core/src/events/policy.ts +9 -0
  71. package/packages/core/src/events/repository.ts +75 -2
  72. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +278 -0
  73. package/packages/core/src/kernel/change-presence.ts +74 -8
  74. package/packages/core/src/kernel/engine.ts +8 -0
  75. package/packages/core/src/kernel/generators/node-restack-log.ts +14 -0
  76. package/packages/core/src/kernel/node-polling.ts +40 -7
  77. package/packages/core/src/kernel/node-restack-demand.ts +74 -0
  78. package/packages/core/src/kernel/node-restack-state.ts +5 -1
  79. package/packages/core/src/kernel/node-restack-transaction.ts +33 -1
  80. package/packages/core/src/kernel/read-facts.ts +6 -0
  81. package/packages/core/src/kernel/reducer-registry.ts +3 -0
  82. package/packages/core/src/kernel/reducer.ts +4 -1
  83. package/packages/core/src/kernel/ticket-preparation.ts +66 -0
  84. package/packages/core/src/operator/annotations.ts +6 -0
  85. package/packages/core/src/operator/control.ts +20 -0
  86. package/packages/core/src/operator/index.ts +4 -0
  87. package/packages/core/src/operator/protocol.ts +6 -0
  88. package/packages/core/src/operator/registry.ts +42 -1
  89. package/packages/core/src/operator/tickets.ts +25 -4
  90. package/packages/core/src/plugins/manifest.ts +2 -1
  91. package/packages/core/src/ports/runner/account-env.ts +139 -0
  92. package/packages/core/src/ports/runner/chatgpt-provider.ts +85 -0
  93. package/packages/core/src/ports/runner/claude.ts +70 -42
  94. package/packages/core/src/ports/runner/codex.ts +63 -31
  95. package/packages/core/src/ports/runner/one-shot.ts +2 -0
  96. package/packages/core/src/ports/runner/provider-error.ts +5 -0
  97. package/packages/core/src/ports/runner/routing.ts +35 -4
  98. package/packages/core/src/ports/tickets/contract.ts +58 -0
  99. package/packages/core/src/ports/tickets/tree.ts +1 -1
  100. package/packages/core/src/ports/types.ts +28 -7
  101. package/packages/core/src/ports/workspace/account-policy.ts +72 -0
  102. package/packages/core/src/ports/workspace/build-execution.ts +6 -1
  103. package/packages/core/src/ports/workspace/builtin-capabilities.ts +1 -0
  104. package/packages/core/src/ports/workspace/create.ts +2 -0
  105. package/packages/core/src/ports/workspace/git-worktree.ts +6 -1
  106. package/packages/core/src/ports/workspace/provider-capabilities.ts +1 -0
  107. package/packages/core/src/ports/workspace/vercel-sandbox.ts +125 -35
  108. package/packages/core/src/processes/build-runner.ts +32 -1
  109. package/packages/core/src/processes/dispatcher.ts +493 -121
  110. package/packages/core/src/processes/execution-no-progress.ts +1 -0
  111. package/packages/core/src/processes/execution-settlement.ts +21 -3
  112. package/packages/core/src/processes/harvest-runner.ts +68 -8
  113. package/packages/core/src/processes/harvest.ts +11 -16
  114. package/packages/core/src/processes/repo-view.ts +3 -0
  115. package/packages/core/src/project-secrets.ts +105 -0
  116. package/packages/core/src/secret-name.ts +41 -0
  117. package/packages/core/src/store/account-redaction.ts +156 -0
  118. package/packages/core/src/store/artifact-meta.ts +7 -0
  119. package/packages/core/src/store/contract.ts +60 -1
  120. package/packages/core/src/store/memory.ts +4 -0
  121. package/packages/core/src/store/reducer-value-shapes.json +7389 -6647
  122. package/packages/core/src/store/reducer-value-validation.ts +106 -6
  123. package/packages/core/src/store/remote/client.ts +85 -50
  124. package/packages/core/src/store/remote/compatibility.ts +57 -0
  125. package/packages/core/src/store/remote/index.ts +6 -0
  126. package/packages/core/src/store/remote/protocol.ts +8 -1
  127. package/packages/core/src/store/remote/released-reducer-values/1.2.0.json +8129 -0
  128. package/packages/core/src/store/remote/version.ts +4 -0
  129. package/packages/core/src/store/repo-state-events.ts +4 -2
  130. package/packages/core/src/store/snapshots.ts +16 -3
  131. package/packages/core/src/store/types.ts +2 -0
  132. package/packages/core/src/testing/dispatch-read-budget.ts +266 -5
  133. package/packages/core/src/testing/index.ts +2 -1
  134. package/packages/core/src/testing/reduced-read-budget.ts +560 -5
  135. package/skills/guide/SKILL.md +164 -37
  136. package/skills/guide/references/accounts.md +130 -0
  137. package/skills/guide/references/integration-tree.md +16 -5
  138. package/skills/guide/references/merge-policy.md +1 -3
  139. package/skills/guide/references/operator-api.md +144 -53
  140. package/skills/guide/references/plugin-authoring.md +27 -1
  141. package/skills/guide/references/remote-store-protocol.md +259 -91
  142. package/skills/guide/references/remote-ticket-protocol.md +29 -49
  143. package/skills/guide/references/restacking.md +45 -0
  144. package/skills/guide/references/setup.md +34 -129
  145. package/skills/guide/references/spec-standard.md +4 -2
  146. package/skills/guide/references/ticket-dependencies.md +8 -0
  147. package/skills/harvest/SKILL.md +3 -1
  148. package/skills/harvest-review/SKILL.md +3 -1
  149. package/skills/operate/SKILL.md +26 -11
  150. package/skills/reconcile/SKILL.md +6 -0
  151. package/skills/spec/SKILL.md +1 -1
  152. package/skills/tickets/SKILL.md +10 -5
  153. package/templates/hosted-service/package.json +2 -2
  154. package/docs/hosted-dispatcher-cutover-validation.md +0 -178
  155. package/docs/hosted-dispatcher.md +0 -278
  156. package/docs/hosted-service.md +0 -304
  157. package/docs/mcp.md +0 -150
@@ -1,304 +0,0 @@
1
- # Deploy a hosted service
2
-
3
- A service hosts the BuildStore, tickets, dashboard, sign-in, and MCP endpoint.
4
- The default deployment stores state while dispatch runs on another machine.
5
- You need Bun 1.4.x, a Git repository, a Vercel project, PostgreSQL, a blob
6
- backend, and a GitHub OAuth application.
7
-
8
- Create a new directory containing these two files (also shipped in the hosted
9
- package's `deployment/` directory and in `templates/hosted-service/`).
10
-
11
- `package.json`:
12
-
13
- ```json
14
- {
15
- "private": true,
16
- "scripts": {
17
- "build": "ab-hosted-service-build"
18
- },
19
- "dependencies": {
20
- "@defrex/autobuild-hosted-store-service": "1.1.0",
21
- "@defrex/autobuild": "1.1.0",
22
- "next": "16.1.6",
23
- "react": "19.2.4",
24
- "react-dom": "19.2.4"
25
- }
26
- }
27
- ```
28
-
29
- `vercel.json`:
30
-
31
- ```json
32
- {
33
- "$schema": "https://openapi.vercel.sh/vercel.json",
34
- "framework": "nextjs",
35
- "installCommand": "bun install --frozen-lockfile",
36
- "buildCommand": "bun run build",
37
- "bunVersion": "1.4.x"
38
- }
39
- ```
40
-
41
- Run `bun install`, then commit both files and `bun.lock`. Add `.gitignore`
42
- entries for `node_modules/`, `.next/`, `.vercel/`, `app/`, `next.config.ts`,
43
- `next-env.d.ts`, `tsconfig.json`, and `.autobuild-service-assets.json`.
44
- These application assets are generated during each build. Keep your own files
45
- outside those names; the builder refuses to overwrite consumer-owned files.
46
- Do not commit generated application sources or edit them to customize deployment.
47
-
48
- Push the directory to your Git host. Import it in Vercel with the repository
49
- root as Root Directory and Next.js as the framework. The checked-in platform
50
- configuration installs the lockfile and runs `bun run build`. Each build stages
51
- the installed package, runs its idempotent database migrations against the
52
- configured database, then builds Next into the root `.next/`. Missing database
53
- configuration, incompatible schema, or a failed migration stops the build.
54
- Provide database access from the build environment as well as runtime.
55
-
56
- ## Connect a project
57
-
58
- From a checkout with an origin remote, run `ab connect https://YOUR_ORIGIN`.
59
- The CLI prints a verification URL and short code and attempts to open a browser.
60
- Sign in as an allowed owner, check the full repository identity and code, and
61
- approve or deny. Another device can open the printed URL, or visit `/connect`
62
- and enter the code. Approval requires the web-enabled service origin; a
63
- standalone machine-only listener cannot present browser consent. Requests
64
- expire after ten minutes. Denial and timeout leave local configuration unchanged.
65
-
66
- On approval the service registers the project and issues a project credential.
67
- The CLI keeps it in `$XDG_CONFIG_HOME/autobuild/credentials` (or
68
- `~/.config/autobuild/credentials`), keyed by normalized service and origin,
69
- with directory mode 0700 and file mode 0600. Credentials never belong in the
70
- repository. It adds the non-secret `[store] url` to `autobuild.toml` when
71
- absent; review and commit that change yourself. An existing different URL
72
- must be changed explicitly before connecting. Reconnecting replaces the saved
73
- credential only after approval and revokes the previous credential.
74
-
75
- All worktrees share the main checkout's configuration and the user's saved
76
- credential. A service manager running as that user uses the same HOME and
77
- XDG_CONFIG_HOME, with no AB_STORE or AB_TOKEN exports. A fresh clone with
78
- committed store configuration but no saved credential fails with `ab connect`
79
- guidance; it never silently creates local state. Run connect on each host/user.
80
-
81
- `ab connect` without a URL reports service, project, and credential status:
82
- accepted, rejected, missing, or unreachable. `ab disconnect` revokes the saved
83
- credential remotely before removing it locally, keeping the project registered,
84
- its data, and store configuration. A network/server failure retains the local
85
- entry for retry; an already revoked credential can be removed. If saving a new
86
- connection fails, the CLI cancels/revokes it and retains the previous entry.
87
- If remote cleanup cannot be confirmed, check the printed credential id with
88
- the owner's administrative tools before retrying.
89
-
90
- Store selection is `--store` > nonblank `AB_STORE` > `[store] url` > the
91
- main checkout's `.autobuild/`. `AB_TOKEN` overrides the exact service/project's
92
- saved credential for CI and other non-interactive hosts. A service override
93
- never borrows another service's credential. Build and harvest sessions keep
94
- their explicit scoped authority.
95
-
96
- ## Environment
97
-
98
- Set these server-side variables in every Vercel environment you deploy:
99
-
100
- - `AB_POSTGRES_URL` or `DATABASE_URL`: PostgreSQL connection URL. The explicit
101
- `AB_POSTGRES_URL` takes precedence; use the same database at build and runtime.
102
- - `AB_STORE_SECRET`: a high-entropy secret for machine token signing.
103
- - `AB_BLOB_BACKEND=vercel` with `BLOB_READ_WRITE_TOKEN`, or `AB_BLOB_BACKEND=s3`
104
- with `AB_S3_BUCKET`, `AB_S3_REGION`, `AB_S3_ACCESS_KEY_ID`, and
105
- `AB_S3_SECRET_ACCESS_KEY` (and optional endpoint for compatible storage).
106
- - `BETTER_AUTH_SECRET`: an independent high-entropy secret of at least 32 characters.
107
- - `BETTER_AUTH_URL`: the exact production HTTPS origin, with no path.
108
- - `GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET`: GitHub OAuth application credentials.
109
- - `AB_WEB_AUTH_PROVIDERS=github`.
110
- - `AB_WEB_SUPER_USER_EMAILS`: comma-separated super-user emails. Other operators require organization membership.
111
- - `AB_WEB_REPOSITORIES`: comma-separated repository origins visible to operators.
112
-
113
- Register `https://YOUR_ORIGIN/api/auth/callback/github` as the GitHub callback
114
- and allow read-only email access (`user:email`). Sign-in must use the configured
115
- production origin. Do not expose secrets through `NEXT_PUBLIC_` variables.
116
- See the [complete environment reference](configuration.md) for storage,
117
- project ticket lifecycle, credential administration, and optional MCP resource configuration.
118
-
119
- ## Check the deployment
120
-
121
- `GET /health` returns service and protocol versions. Open `/sign-in` and sign
122
- in; `/` redirects unauthenticated browsers to sign-in. Machine routes
123
- require a machine token; `/mcp` challenges an unauthenticated client with OAuth
124
- resource metadata. Check both discovery documents:
125
-
126
- ```sh
127
- curl https://YOUR_ORIGIN/.well-known/oauth-protected-resource
128
- curl https://YOUR_ORIGIN/.well-known/oauth-authorization-server
129
- ```
130
-
131
- The authorization-server document advertises a reachable `/api/auth/jwks`
132
- URI and `/api/auth/mcp/register` dynamic registration endpoint. MCP clients
133
- register with `redirect_uris` as an array of strings and
134
- `token_endpoint_auth_method: "none"`; treat the returned `client_id` as opaque.
135
- See [MCP](mcp.md) for authorization and client setup.
136
-
137
- Without the optional hosted dispatcher installed, `GET /api/dispatch` returns
138
- 503 JSON: `{"error":"dispatch runs elsewhere for this deployment"}`. The
139
- template has no cron and installs no dispatcher/provider package. Run dispatch
140
- from a connected project or follow the separate, opt-in
141
- [hosted dispatcher procedure](hosted-dispatcher.md), which retains its
142
- source-checkout packaging and cron setup.
143
-
144
- ## Upgrade
145
-
146
- Bump the exact hosted-service and core package pins in `package.json` to the
147
- same new release, run `bun install` to refresh `bun.lock`, commit, and push.
148
- Vercel's Git integration migrates and builds the pinned package automatically.
149
- Upgrade the service **before connected projects**: that is the order expected
150
- by the protocol compatibility window. No source extraction, patch application,
151
- or manual production deployment is required.
152
-
153
- ## Hosted ticket projects and v1 migration
154
-
155
- Hosted queues are partitioned by registered repository. Credentials select the
156
- project. Independent ticket policy selects lifecycle; `ab connect --tickets URL`
157
- publishes it before dispatch. Older clients retain uploaded dispatcher configuration
158
- as a fallback. See the [ticket protocol](remote-ticket-protocol.md). Projects using file,
159
- Linear or another external source continue to access it directly through their
160
- dispatcher. Service ticket surfaces refuse those projects with source feedback.
161
- The service never connects to Linear.
162
-
163
- The removed `AB_TICKET_BACKEND` and `LINEAR_API_KEY` settings are ignored for
164
- all values, including blanks, with one startup message asking for removal.
165
- The removed `AB_TICKET_TRIAGE_STATE`, `AB_TICKET_READY_STATE`,
166
- `AB_TICKET_DOING_STATE` and `AB_TICKET_DONE_STATE` settings are ignored even if
167
- malformed. Lifecycle now comes only from project configuration.
168
-
169
- The environment-aware migration first imports `AB_WEB_REPOSITORIES` into the
170
- registry once, including upgrades from released main schema v9 where registry
171
- tables do not yet exist. This import and the main-schema promotion share the
172
- ticket transaction: a stopped ticket migration rolls them back too. The owner
173
- `projects add` and `tickets assign-team` commands can independently bootstrap
174
- the registry while that old main marker remains, so recovery does not require
175
- a successful ticket migration. If the retired environment is unavailable,
176
- register the intended project with `ab-hosted-store projects add REPOSITORY
177
- --user IDENTITY` before assigning its legacy team. Once the import succeeds,
178
- later changes to the retired environment are ignored.
179
-
180
- Fresh databases install ticket schema v2 directly. Existing team-keyed v1
181
- queues migrate in one transaction. For each registered project, migration reads
182
- the effective configuration selected by its latest dispatcher run and reloads,
183
- including the actual immutable artifact bytes in blob storage. A legacy team
184
- must have one claimant, or an explicit owner assignment. A registered project
185
- with no dispatcher run or no selected effective-config reference makes no team
186
- claim and does not block other projects. Unclaimed teams still stop unchanged.
187
- When ownership must be inferred, a selected but missing, inaccessible or invalid
188
- configuration fails closed with the project and remaining teams in the message.
189
- Restore those bytes or explicitly assign every remaining legacy team, then
190
- rerun; complete assignments to registered projects settle ownership without
191
- reading unrelated configurations. Conflicting claimants and asset ownership
192
- conflicts also stop without changing schema markers or tickets.
193
- Historical ids, states, timestamps, blockers, comments and asset rows remain
194
- unchanged. Review the named projects and resolve a shared legacy team locally:
195
-
196
- ```sh
197
- ab-hosted-store tickets assign-team ENG https://github.com/acme/app --user owner@example.com
198
- ab-postgres-store migrate
199
- ```
200
-
201
- The assignment command works before the v2 migration succeeds and records the
202
- actor in an append-only journal. The latest assignment moves the whole legacy
203
- team once; it grants no future cross-project access. It must name a registered
204
- project. Rerun migration after resolving every named team or configuration error.
205
-
206
- For populated-v1 upgrades, both the owner migration CLI and `deploy:build` need
207
- the same blob backend, access, credentials and `AB_BLOB_PREFIX` as the running
208
- service: S3 bucket/region/credentials (and endpoint/path style when configured),
209
- or Vercel access mode and token/OIDC store identity. The deployment build inherits
210
- these variables and runs the environment-aware migration before Next build.
211
- Missing blob configuration or denied reads stop deployment before Next builds;
212
- diagnostics never print credentials. SQL-only fresh installs, empty-v1 upgrades
213
- and already-v2 reruns do not open blob storage and keep their existing database
214
- requirements. Migration reruns are idempotent.
215
-
216
- ## Local builds with hosted tickets
217
-
218
- Hosted tickets do not require hosted builds. Set `[tickets] source = "hosted"`
219
- and `teamKey = "ENG"`, then run `ab connect --tickets https://your-service.example`.
220
- Approve the project in the browser. This saves a service-scoped credential and
221
- `[tickets] url` while leaving `[store]` unchanged. Ticket commands work immediately,
222
- before any dispatcher runs. `ab connect` reports every service and whether it serves
223
- builds, tickets, or both. Use `ab disconnect --tickets` to revoke ticket access;
224
- when services differ use `--builds` to select build access. Shared uses share one
225
- credential, so disconnecting either shared use affects both.
226
-
227
- Ticket URL selection is `[tickets] url`, then the selected build service (including
228
- AB_STORE or a supported --store override). With local builds, `[tickets] url` is
229
- required. Builds, events, artifacts, and harvest journals remain in the local store.
230
- The service stores ticket records, project ticket policy, and restricted ticket
231
- grants. Normal project clients synchronize current `[tickets]` policy before use;
232
- failed synchronization fails the operation. Harvest grants can read and create;
233
- phase grants can only read. Neither can change policy or access BuildStore routes.
234
-
235
- New hosted policy defaults to `triage`, `ready`, `doing`, `done`, with creation and
236
- harvest proposals in `triage`. Explicit state names preserve their spelling.
237
- To retain earlier names configure `triageState = "Backlog"`,
238
- `claimedState = "Doing"`, `doneState = "Done"`, and the desired `readyState`.
239
- Existing ticket rows are never renamed. Older combined-service clients continue
240
- using the uploaded dispatcher configuration until independent policy is published.
241
-
242
- ## Integration tree metadata
243
-
244
- Hosted tickets store `kind` (`work` or `node`, default `work`) and optional
245
- `target`, the canonical readable id of a node in the same project. Create accepts
246
- both fields; update and guarded update preserve omitted fields and accept
247
- `target: null` to clear an edge. Targets must exist and be nodes. Self-targets,
248
- ancestor cycles, and demoting a node with targeting tickets (including completed
249
- work) are rejected before any part of a mixed patch is written. Graph mutations
250
- serialize per project in the same transaction as validation and revision checks.
251
- Effective metadata changes increment the revision; equivalent aliases are no-ops.
252
-
253
- Ticket responses include these fields only with `x-autobuild-ticket-tree: 1`.
254
- This capability is independent of revision and comment capabilities and of the
255
- client version. Without it, both fields are projected away, preserving historical
256
- strict decoders. Current hosted clients send all three capability headers and
257
- default absent kind to `work`. Unfiltered listing includes all ticket states and
258
- empty nodes for `ab ticket tree`; dispatch and merge behavior are unchanged.
259
-
260
- ## Reading across upgrades
261
-
262
- Within the advertised client compatibility window, readers with mixed-version
263
- read support tolerate newer build and repository facts. Raw event endpoints
264
- retain unknown types, payload fields and the producer's `compatibility`
265
- metadata (`writerVersion` and `classification`). Known payload fields remain
266
- validated. Adding an advisory field to an existing type is safe; a semantic
267
- change that older kernels must respect requires a new decisive event type.
268
-
269
- Named reduction responses retain exactly `{version, cursor, value}`. The
270
- `x-autobuild-catalog-identity` response header identifies the backend's read
271
- catalog independently of its package release and reducer version. Clients
272
- accept an answer only when that identity, reducer version and finished shape
273
- match their own; otherwise they replay raw events locally through the response
274
- cursor. A missing header from an earlier service also triggers replay. A
275
- service never invents an identity for a backend that supplies none. This keeps
276
- released strict JSON decoders working without a new request capability.
277
-
278
- Unknown advisory facts are counted and skipped. Unknown decisive facts defer
279
- claiming, routing, merge and publication only for their build; status,
280
- context and dashboards remain readable. One `build.compatibility-deferred`
281
- attention fact per decisive boundary appears in the default `ab watch` stream.
282
- Its diagnostic names unsupported types and producer releases: restart with a
283
- build that understands those types. The type names matter even when both
284
- processes report the same package version, as source builds may differ.
285
- Legacy unknown facts lacking metadata are decisive and report that the writer
286
- version is unavailable. Restarting with a reader that understands the facts
287
- clears the guard through replay, without an escalation answer.
288
-
289
- Caches are scoped to the reader's catalog. Replaying a reduction from an
290
- unrecognized reducer version never overwrites its bytes; lower-version snapshot
291
- writes cannot replace higher-version rows even at a later cursor. This
292
- protects both upgrade directions. Readers predating this support still fail
293
- closed; this guarantee does not widen the advertised client window.
294
-
295
-
296
- The retired `AB_WEB_ALLOWED_EMAILS` variable is refused at startup, even if empty.
297
- Replace it with `AB_WEB_SUPER_USER_EMAILS`; review the list because these identities
298
- are deployment maintainers. Bootstrap the first organization through the
299
- [browser management contract](operator-api.md#organization-management-browser),
300
- then add members by email and assign legacy unassigned projects. Super users alone
301
- create orgs, set or clear the single owner, and assign or move projects. Owners
302
- manage their org's members. Removing the last membership or super-user designation
303
- revokes human access on the next request without re-login; existing project
304
- credentials remain valid until revoked.
package/docs/mcp.md DELETED
@@ -1,150 +0,0 @@
1
- # The hosted MCP server
2
-
3
- The hosted service exposes the agent tool registry over [Streamable HTTP](https://modelcontextprotocol.io) at
4
- `/mcp`, on the same origin as the operator dashboard. External agents — Claude
5
- web, Claude Desktop, Claude Code, Codex, or any harness with an MCP client —
6
- get the same operator surface across supported external bindings, at parity by
7
- construction: tool names, descriptions, JSON schemas, and annotations are read
8
- from the registry's closed table, and every execution goes through the
9
- operator API's token-verified protocol.
10
-
11
- ## What the endpoint serves
12
-
13
- - **Every registry tool**, with its schema and annotations, plus
14
- **`repositories.list`** — a read-only tool returning the repository
15
- identities this deployment serves (the values every tool's `repo` field
16
- accepts). The binding is data-driven: when a future ticket adds registry
17
- entries, they appear on the endpoint with no change to the deployment.
18
- - **Server instructions** summarizing how Autobuild works (dispatcher, builds,
19
- tickets, harvest, notes) and pointing clients at `repositories.list`.
20
- - A **stateless transport**: fresh transport and server per request, JSON
21
- responses, no session ids. Every request is authenticated independently, so
22
- cold starts behave identically to warm instances.
23
-
24
- ## Authentication: OAuth 2.1 through Better Auth
25
-
26
- The endpoint is an OAuth 2.1 **protected resource**; the deployment's Better
27
- Auth instance is the **authorization server**. An unauthenticated request to
28
- `/mcp` receives `401` with an RFC 9728 `WWW-Authenticate` challenge pointing at
29
- `/.well-known/oauth-protected-resource`. From there a client:
30
-
31
- 1. Reads the protected-resource metadata (served at the origin root and under
32
- `/api/auth`) to discover the authorization server.
33
- 2. Reads the authorization-server metadata
34
- (`/.well-known/oauth-authorization-server`) — authorization, token, and
35
- dynamic-registration endpoints, plus the `jwks_uri`.
36
- 3. Registers dynamically (`POST /api/auth/mcp/register`, RFC 7591); the
37
- registered `client_name` becomes the `via` marker recorded on writes.
38
- 4. Runs the authorization-code flow with PKCE through `GET /api/auth/mcp/authorize`.
39
- A signed-out person is redirected to the deployment's sign-in page (the
40
- existing GitHub sign-in and organization membership policy); the flow resumes after
41
- sign-in. Only super users and organization members are admitted. The resource
42
- rechecks admission and project access on every tool callback, so removed
43
- members lose authority with existing tokens (`403`).
44
- 5. Exchanges the code at `/api/auth/mcp/token`; access tokens are short-lived
45
- and refresh tokens rotate. Consent renders only when the client sends
46
- `prompt=consent` (the plugin's designed behavior); clients that omit it
47
- receive a code directly.
48
-
49
- Every tool call resolves the token's subject to the signed-in operator, mints
50
- the same 30-second attributed operator token the web gateway mints — stamped
51
- with `via: {kind: "mcp", client}` — and executes the named tool through the
52
- operator server. A mutating tool's durable event therefore names the person
53
- who authorized the client and which client executed it:
54
-
55
- ```json
56
- { "kind": "human", "user": "ada@example.com", "via": { "kind": "mcp", "client": "Claude web" } }
57
- ```
58
-
59
- Tool calls naming a repository outside the deployment's served set are refused
60
- (`kind: "validation"`).
61
-
62
- ## Duration limits
63
-
64
- The MCP route's `maxDuration` is 300 s (Vercel Pro default) — the same pairing
65
- the [dispatcher route](hosted-dispatcher.md) documents. Tool-requested bounded
66
- waits (`builds.events`' `waitSeconds`) are clamped to **`MCP_MAX_WAIT_SECONDS`
67
- = 240 s** at the binding, so no single MCP request outlives the route's limit;
68
- the registry's own schema currently caps that tool's waits lower, and the
69
- clamp is the guard that holds if that cap rises.
70
-
71
- ## Connecting clients
72
-
73
- ### Claude web (custom connector)
74
-
75
- Settings → Connectors → **Add custom connector**, enter the deployment URL
76
- plus `/mcp` (e.g. `https://operator.example/mcp`). Claude discovers the
77
- authorization server from the protected-resource metadata, registers
78
- dynamically, and sends the person through GitHub sign-in and the consent page;
79
- the OAuth callback is `https://claude.ai/api/mcp/auth_callback` (allowed by
80
- dynamic registration — no configuration needed on the deployment).
81
-
82
- ### Claude Code
83
-
84
- ```sh
85
- claude mcp add --transport http autobuild https://operator.example/mcp
86
- ```
87
-
88
- Claude Code runs the same OAuth 2.1 flow in the terminal (it opens a browser
89
- for sign-in and consent).
90
-
91
- ### Codex
92
-
93
- ```sh
94
- codex mcp add autobuild --url https://operator.example/mcp
95
- ```
96
-
97
- ### Any MCP client
98
-
99
- Point the client at `<deployment>/mcp` over Streamable HTTP. A client only
100
- needs RFC 9728 discovery, dynamic client registration, PKCE, and refresh —
101
- the standard surface the endpoint serves.
102
-
103
- ## Operational variables
104
-
105
- - `AB_WEB_MCP_RESOURCE` (optional): the protected resource the plugin binds
106
- tokens to. Defaults to `<BETTER_AUTH_URL>/mcp`, which is correct for the
107
- standard deployment; override only when a proxy or custom domain fronts the
108
- function. Must be an absolute http(s) URL (https in production).
109
- - `BETTER_AUTH_URL`: the public origin — the authorization-server issuer and
110
- the default MCP resource's base.
111
- - `AB_WEB_SUPER_USER_EMAILS`: the super-user email list. Other operators need organization membership;
112
- admission and repository access are rechecked on every tool callback.
113
- - `AB_WEB_REPOSITORIES` (deprecated): optional once-per-database registry
114
- bootstrap, never an ongoing allowlist. `repositories.list` queries current
115
- active registrations on every call, and every tool checks current membership.
116
-
117
- Super users see every registered project; other users see only active projects
118
- assigned to their organizations. Database-authorized
119
- owners use the [project commands](setup.md#connected-projects) to add or remove
120
- projects without redeploying. Removal hides retained data until re-registration;
121
- registry failures never authorize a call.
122
-
123
- The endpoint requires no additional variables beyond the hosted service's
124
- existing web/auth set. Note that consent renders when the client sends
125
- `prompt=consent`; a client that omits it gets a code directly (the plugin's
126
- designed behavior).
127
-
128
- ### Tree and consent reads
129
-
130
- `merges.list` takes `{repo}` and returns slug-sorted ready consent or held
131
- merges, with effective target, source branch, candidate, verification receipts
132
- and node completeness/children. It reads reduced durable state; `builds.control`
133
- with `merge` rechecks readiness and live completeness. `hold` remains available
134
- before readiness. `tickets.tree` takes `{repo}` and returns `{root, children,
135
- diagnostics}` from exhaustive configured-source enumeration. Source ancestry is
136
- separate from frozen build ancestry. Both tools are read-only and repository scoped.
137
-
138
- The CLI equivalents are `ab merges [--json] [--store <ref>]` and
139
- `ab ticket tree [--json]`. Default `ab watch` attention includes node merges,
140
- restack conflicts and derived `build.consent-ready` observations with durable
141
- cursor positions. `ab wait` supports `consent`, `node-merged` and
142
- `restack-conflicted`; current-state conditions return immediately. Explicit
143
- watch event globs emit durable events only. A readiness episode changes on a
144
- new candidate or exit/re-entry, and cursor resume suppresses its duplicate.
145
-
146
- Consent and hold readiness produce only `build.consent-ready`; merge attention is
147
- reserved for current gate deferrals and unsafe forge outcomes. Named and
148
- repository-wide watches report an already-ready merge on first discovery.
149
- Readiness observations use the same `{kind, branch, ticket?, build?}` effective
150
- target shape as queue entries.