@defrex/autobuild 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -18
- package/SPEC.md +499 -238
- package/bin/ab-dispatch-generation.ts +11 -2
- package/docs/accounts.md +119 -0
- package/docs/agent-runtimes.md +4 -4
- package/docs/answering-blocked-builds.md +2 -2
- package/docs/architecture.md +262 -53
- package/docs/assets/headline-wide.png +0 -0
- package/docs/build-store.md +3 -41
- package/docs/builds.md +4 -4
- package/docs/cli.md +18 -4
- package/docs/configuration-overview.md +115 -4
- package/docs/configuration.md +488 -334
- package/docs/dispatcher-hosting.md +19 -34
- package/docs/dispatcher.md +1 -1
- package/docs/forges.md +5 -5
- package/docs/getting-started.md +2 -2
- package/docs/glossary.md +6 -6
- package/docs/intake.md +2 -0
- package/docs/integration-overview.md +15 -15
- package/docs/integration-tree.md +45 -38
- package/docs/integration.md +6 -6
- package/{skills/guide/references/landing-policy.md → docs/merge-policy.md} +40 -24
- package/docs/migration-1.0.md +17 -13
- package/docs/operating.md +41 -19
- package/docs/operator-api.md +180 -51
- package/docs/operator-surfaces.md +5 -18
- package/docs/overview.md +3 -3
- package/docs/plugin-authoring.md +21 -0
- package/docs/remote-store-protocol.md +242 -68
- package/docs/remote-ticket-protocol.md +30 -50
- package/docs/restacking.md +54 -15
- package/docs/seams.md +8 -8
- package/docs/setup.md +59 -119
- package/docs/skills.md +1 -1
- package/docs/spec-standard.md +6 -6
- package/docs/ticket-dependencies.md +7 -7
- package/docs/ticket-sources.md +18 -0
- package/docs/tickets.md +8 -2
- package/docs/troubleshooting.md +8 -12
- package/docs/upgrading.md +9 -4
- package/docs/verification.md +60 -14
- package/docs/workspaces.md +4 -4
- package/package.json +17 -6
- package/packages/core/src/accounts/chatgpt-oauth.ts +216 -0
- package/packages/core/src/accounts/chatgpt-state.ts +41 -0
- package/packages/core/src/accounts/local-credentials.ts +194 -0
- package/packages/core/src/accounts/local-inference.ts +106 -0
- package/packages/core/src/accounts/local-owner.ts +123 -0
- package/packages/core/src/accounts/sensitive.ts +2 -0
- package/packages/core/src/cli/accounts.ts +147 -0
- package/packages/core/src/cli/binary-direct.ts +13 -1
- package/packages/core/src/cli/binary-lifecycle.ts +65 -2
- package/packages/core/src/cli/binary.ts +3 -1
- package/packages/core/src/cli/build-control.ts +83 -28
- package/packages/core/src/cli/connect.ts +3 -3
- package/packages/core/src/cli/context.ts +81 -38
- package/packages/core/src/cli/dashboard/facts.ts +2 -1
- package/packages/core/src/cli/dashboard/integration-detail.ts +8 -8
- package/packages/core/src/cli/dashboard/integration-row.ts +40 -13
- package/packages/core/src/cli/dashboard/landing-display.ts +25 -0
- package/packages/core/src/cli/dashboard/model.ts +56 -33
- package/packages/core/src/cli/dashboard/poll.ts +9 -3
- package/packages/core/src/cli/dashboard/render.ts +59 -37
- package/packages/core/src/cli/dashboard/target-distance.ts +14 -0
- package/packages/core/src/cli/dashboard/tree.ts +3 -2
- package/packages/core/src/cli/dispatch-args.ts +1 -1
- package/packages/core/src/cli/dispatch-frontend.ts +6 -3
- package/packages/core/src/cli/dispatch-handoff.ts +125 -44
- package/packages/core/src/cli/dispatch-launch-contract.ts +187 -0
- package/packages/core/src/cli/dispatch-launcher.ts +54 -21
- package/packages/core/src/cli/dispatch-preflight.ts +6 -1
- package/packages/core/src/cli/dispatch.ts +106 -11
- package/packages/core/src/cli/env.ts +4 -0
- package/packages/core/src/cli/help.ts +46 -23
- package/packages/core/src/cli/init-readiness-remote.ts +22 -1
- package/packages/core/src/cli/init-readiness-shared.ts +5 -1
- package/packages/core/src/cli/init-validation.ts +160 -18
- package/packages/core/src/cli/main.ts +68 -8
- package/packages/core/src/cli/node-verification-provenance.ts +1 -97
- package/packages/core/src/cli/publication-settlement.ts +47 -21
- package/packages/core/src/cli/repository-status.ts +20 -9
- package/packages/core/src/cli/secrets.ts +173 -0
- package/packages/core/src/cli/status.ts +42 -5
- package/packages/core/src/cli/store-opening.ts +17 -2
- package/packages/core/src/cli/terminal.ts +22 -1
- package/packages/core/src/cli/terminals.ts +14 -10
- package/packages/core/src/cli/upgrade-agent.ts +9 -1
- package/packages/core/src/cli/upgrade-landing.ts +70 -30
- package/packages/core/src/cli/upgrade.ts +3 -1
- package/packages/core/src/cli/wait.ts +15 -7
- package/packages/core/src/cli/watch-lifetime.ts +111 -0
- package/packages/core/src/cli/watch.ts +635 -510
- package/packages/core/src/config/accounts.ts +101 -0
- package/packages/core/src/config/effective-artifact.fixture.ts +27 -0
- package/packages/core/src/config/effective-artifact.ts +13 -0
- package/packages/core/src/config/landing.ts +1 -1
- package/packages/core/src/config/live.ts +14 -1
- package/packages/core/src/config/load.ts +21 -1
- package/packages/core/src/config/pipeline-source.ts +28 -0
- package/packages/core/src/config/reference-metadata.ts +2 -0
- package/packages/core/src/config/reference.ts +22 -7
- package/packages/core/src/config/roles.ts +54 -3
- package/packages/core/src/config/schema.ts +146 -162
- package/packages/core/src/context-directory.ts +26 -0
- package/packages/core/src/distribution-packaging.ts +26 -5
- package/packages/core/src/events/catalog.ts +10 -2
- package/packages/core/src/events/compatibility.ts +2 -1
- package/packages/core/src/events/globs.ts +1 -1
- package/packages/core/src/events/payloads.ts +73 -1
- package/packages/core/src/events/policy.ts +7 -0
- package/packages/core/src/events/repository.ts +4 -4
- package/packages/core/src/events/sessions.ts +6 -6
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +574 -0
- package/packages/core/src/kernel/auto-merge.ts +2 -2
- package/packages/core/src/kernel/engine.ts +255 -26
- package/packages/core/src/kernel/generators/leaf-restack-log.ts +10 -0
- package/packages/core/src/kernel/integration-landing.ts +3 -3
- package/packages/core/src/kernel/integration-state.ts +27 -4
- package/packages/core/src/kernel/leaf-restack-state.ts +28 -3
- package/packages/core/src/kernel/log-index.ts +13 -1
- package/packages/core/src/kernel/node-landing.ts +8 -8
- package/packages/core/src/kernel/node-parent.ts +2 -2
- package/packages/core/src/kernel/node-restack-transaction.ts +1 -1
- package/packages/core/src/kernel/node-verification-context.ts +216 -0
- package/packages/core/src/kernel/phases.ts +1 -1
- package/packages/core/src/kernel/plan-verify-selection.ts +16 -0
- package/packages/core/src/kernel/publication-retry.ts +168 -0
- package/packages/core/src/kernel/reconcile-restack.ts +29 -1
- package/packages/core/src/kernel/reducer.ts +85 -5
- package/packages/core/src/kernel/target-distance.ts +45 -0
- package/packages/core/src/kernel/terminal-guard.ts +10 -1
- package/packages/core/src/kernel/verify-stage-state.ts +123 -0
- package/packages/core/src/kernel/verify-stages.ts +39 -0
- package/packages/core/src/ontology.ts +1 -0
- package/packages/core/src/operator/annotations.ts +6 -0
- package/packages/core/src/operator/control.ts +1 -1
- package/packages/core/src/operator/index.ts +3 -7
- package/packages/core/src/operator/landings.ts +5 -1
- package/packages/core/src/operator/presentation.ts +6 -1
- package/packages/core/src/operator/protocol.ts +6 -0
- package/packages/core/src/operator/query.ts +14 -18
- package/packages/core/src/operator/registry.ts +39 -7
- package/packages/core/src/operator/sandbox-host.ts +64 -40
- package/packages/core/src/operator/sandbox.ts +3 -0
- package/packages/core/src/operator/ticket-source-backend.ts +3 -12
- package/packages/core/src/operator/tickets.ts +25 -4
- package/packages/core/src/plugins/manifest.ts +2 -1
- package/packages/core/src/ports/forge/contract.ts +2 -2
- package/packages/core/src/ports/forge/git-rewrite.ts +25 -2
- package/packages/core/src/ports/forge/github-readiness.ts +2 -2
- package/packages/core/src/ports/forge/github.ts +26 -7
- package/packages/core/src/ports/forge/local-git.ts +4 -4
- package/packages/core/src/ports/forge/readiness.ts +1 -1
- package/packages/core/src/ports/forge-failure.ts +24 -0
- package/packages/core/src/ports/runner/account-env.ts +88 -0
- package/packages/core/src/ports/runner/chatgpt-provider.ts +85 -0
- package/packages/core/src/ports/runner/claude.ts +26 -2
- package/packages/core/src/ports/runner/codex.ts +63 -31
- package/packages/core/src/ports/runner/one-shot.ts +2 -0
- package/packages/core/src/ports/runner/provider-error.ts +5 -0
- package/packages/core/src/ports/runner/routing.ts +35 -4
- package/packages/core/src/ports/tickets/contract.ts +58 -0
- package/packages/core/src/ports/tickets/tree.ts +1 -1
- package/packages/core/src/ports/types.ts +28 -7
- package/packages/core/src/ports/workspace/account-policy.ts +72 -0
- package/packages/core/src/ports/workspace/build-execution.ts +9 -2
- package/packages/core/src/ports/workspace/builtin-capabilities.ts +1 -0
- package/packages/core/src/ports/workspace/create.ts +2 -0
- package/packages/core/src/ports/workspace/git-worktree.ts +6 -1
- package/packages/core/src/ports/workspace/phase-scratch.ts +4 -3
- package/packages/core/src/ports/workspace/provider-capabilities.ts +1 -0
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +182 -72
- package/packages/core/src/processes/build-child.ts +6 -8
- package/packages/core/src/processes/build-execution-state.ts +8 -5
- package/packages/core/src/processes/build-runner.ts +554 -99
- package/packages/core/src/processes/dispatcher.ts +209 -101
- package/packages/core/src/processes/execution-no-progress.ts +8 -1
- package/packages/core/src/processes/execution-settlement.ts +21 -3
- package/packages/core/src/processes/harvest-runner.ts +68 -8
- package/packages/core/src/processes/phase-failure-budget.ts +1 -0
- package/packages/core/src/processes/publication-loss.ts +8 -2
- package/packages/core/src/processes/publication-state.ts +42 -4
- package/packages/core/src/processes/repo-view.ts +14 -0
- package/packages/core/src/processes/verify-cycle-config.ts +96 -0
- package/packages/core/src/project-secrets.ts +105 -0
- package/packages/core/src/{integration → scenarios}/harness.ts +330 -317
- package/packages/core/src/secret-name.ts +41 -0
- package/packages/core/src/store/account-redaction.ts +156 -0
- package/packages/core/src/store/adapter.ts +1 -0
- package/packages/core/src/store/build-scope.ts +9 -0
- package/packages/core/src/store/contract.ts +116 -2
- package/packages/core/src/store/local/schema.ts +13 -0
- package/packages/core/src/store/local/store.ts +42 -0
- package/packages/core/src/store/memory.ts +47 -0
- package/packages/core/src/store/operator-presence.ts +21 -0
- package/packages/core/src/store/phase-session.ts +10 -0
- package/packages/core/src/store/reducer-value-shapes.json +5185 -4156
- package/packages/core/src/store/remote/client.ts +89 -48
- package/packages/core/src/store/remote/compatibility.ts +20 -0
- package/packages/core/src/store/remote/protocol.ts +4 -0
- package/packages/core/src/store/remote/version.ts +3 -1
- package/packages/core/src/store/retention.ts +2 -3
- package/packages/core/src/store/session-handle.ts +9 -0
- package/packages/core/src/store/streams/session-writer.ts +1 -1
- package/packages/core/src/store/types.ts +12 -2
- package/packages/core/src/testing/dispatch-read-budget.ts +122 -0
- package/packages/core/src/testing/index.ts +12 -1
- package/packages/core/src/testing/reduced-read-budget.ts +47 -0
- package/packages/core/src/testing/temp-directories.ts +58 -0
- package/skills/code-review/SKILL.md +23 -9
- package/skills/finalize/SKILL.md +15 -7
- package/skills/guide/SKILL.md +373 -148
- package/skills/guide/references/accounts.md +119 -0
- package/skills/guide/references/integration-tree.md +45 -38
- package/{docs/landing-policy.md → skills/guide/references/merge-policy.md} +40 -24
- package/skills/guide/references/migration-1.0.md +17 -13
- package/skills/guide/references/operator-api.md +180 -51
- package/skills/guide/references/plugin-authoring.md +21 -0
- package/skills/guide/references/remote-store-protocol.md +242 -68
- package/skills/guide/references/remote-ticket-protocol.md +30 -50
- package/skills/guide/references/restacking.md +54 -15
- package/skills/guide/references/setup.md +59 -119
- package/skills/guide/references/spec-standard.md +6 -6
- package/skills/guide/references/ticket-dependencies.md +7 -7
- package/skills/harvest/SKILL.md +3 -1
- package/skills/harvest-review/SKILL.md +3 -1
- package/skills/implement/SKILL.md +43 -17
- package/skills/operate/SKILL.md +118 -118
- package/skills/plan/SKILL.md +39 -13
- package/skills/plan-review/SKILL.md +15 -10
- package/skills/reconcile/SKILL.md +22 -3
- package/skills/spec/SKILL.md +20 -20
- package/skills/tickets/SKILL.md +12 -9
- package/templates/autobuild.toml +1 -1
- package/templates/hosted-service/package.json +2 -2
- package/docs/hosted-dispatcher-cutover-validation.md +0 -178
- package/docs/hosted-dispatcher.md +0 -275
- package/docs/hosted-service.md +0 -293
- package/docs/mcp.md +0 -149
- package/packages/core/src/orchestrator/approvals.ts +0 -115
- package/packages/core/src/orchestrator/conversation.ts +0 -167
- package/packages/core/src/orchestrator/model.ts +0 -86
- package/packages/core/src/orchestrator/prompt.ts +0 -63
- package/packages/core/src/orchestrator/tools.ts +0 -117
- package/packages/core/src/orchestrator/turn-runner.ts +0 -457
- package/packages/core/src/processes/orchestrator-tick.ts +0 -360
package/docs/hosted-service.md
DELETED
|
@@ -1,293 +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.0.1",
|
|
21
|
-
"@defrex/autobuild": "1.0.1",
|
|
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_ALLOWED_EMAILS`: comma-separated operator email allowlist.
|
|
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 landing 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, landing 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.
|
package/docs/mcp.md
DELETED
|
@@ -1,149 +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 the embedded orchestrator has, 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 email allowlist); the flow resumes after
|
|
41
|
-
sign-in. A person outside the allowlist cannot complete the flow — and the
|
|
42
|
-
resource re-checks the allowlist on every tool call, so a person dropped
|
|
43
|
-
from the list has their live tokens refused immediately (`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_ALLOWED_EMAILS`: the operator allowlist. Sign-in admission and every
|
|
112
|
-
MCP tool call are checked against it.
|
|
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
|
-
Every allowlisted user sees every registered project. Database-authorized
|
|
118
|
-
owners use the [project commands](setup.md#connected-projects) to add or remove
|
|
119
|
-
projects without redeploying. Removal hides retained data until re-registration;
|
|
120
|
-
registry failures never authorize a call.
|
|
121
|
-
|
|
122
|
-
The endpoint requires no additional variables beyond the hosted service's
|
|
123
|
-
existing web/auth set. Note that consent renders when the client sends
|
|
124
|
-
`prompt=consent`; a client that omits it gets a code directly (the plugin's
|
|
125
|
-
designed behavior).
|
|
126
|
-
|
|
127
|
-
### Tree and consent reads
|
|
128
|
-
|
|
129
|
-
`landings.list` takes `{repo}` and returns slug-sorted ready consent or held
|
|
130
|
-
landings, with effective target, source branch, candidate, verification receipts
|
|
131
|
-
and node completeness/children. It reads reduced durable state; `builds.control`
|
|
132
|
-
with `land` rechecks readiness and live completeness. `hold` remains available
|
|
133
|
-
before readiness. `tickets.tree` takes `{repo}` and returns `{root, children,
|
|
134
|
-
diagnostics}` from exhaustive configured-source enumeration. Source ancestry is
|
|
135
|
-
separate from frozen build ancestry. Both tools are read-only and repository scoped.
|
|
136
|
-
|
|
137
|
-
The CLI equivalents are `ab landings [--json] [--store <ref>]` and
|
|
138
|
-
`ab ticket tree [--json]`. Default `ab watch` attention includes node landings,
|
|
139
|
-
restack conflicts and derived `build.consent-ready` observations with durable
|
|
140
|
-
cursor positions. `ab wait` supports `consent`, `node-landed` and
|
|
141
|
-
`restack-conflicted`; current-state conditions return immediately. Explicit
|
|
142
|
-
watch event globs emit durable events only. A readiness episode changes on a
|
|
143
|
-
new candidate or exit/re-entry, and cursor resume suppresses its duplicate.
|
|
144
|
-
|
|
145
|
-
Consent and hold readiness produce only `build.consent-ready`; merge attention is
|
|
146
|
-
reserved for current gate deferrals and unsafe forge outcomes. Named and
|
|
147
|
-
repository-wide watches report an already-ready landing on first discovery.
|
|
148
|
-
Readiness observations use the same `{kind, branch, ticket?, build?}` effective
|
|
149
|
-
target shape as queue entries.
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The turn approval list (AUT-342): which registry tool calls suspend a turn
|
|
3
|
-
* until the operator answers. Configured as `[orchestrator].approvals` — a
|
|
4
|
-
* list of registry tool names, optionally qualified by the accepted value of
|
|
5
|
-
* the tool's discriminator field (`tool:qualifier`).
|
|
6
|
-
*
|
|
7
|
-
* Semantics:
|
|
8
|
-
* - A bare entry (`builds.control`) suspends every call to that tool.
|
|
9
|
-
* - A qualified entry (`tickets.move:ready`) suspends only calls whose
|
|
10
|
-
* discriminator equals the qualifier; other values of the same tool run
|
|
11
|
-
* without pause.
|
|
12
|
-
* - An entry naming an absent or unknown tool is inert by design, never an
|
|
13
|
-
* error — the default list is stable while the registry grows.
|
|
14
|
-
* - A qualified entry for a tool without a declared discriminator never
|
|
15
|
-
* matches (there is nothing to compare).
|
|
16
|
-
*
|
|
17
|
-
* Nothing here encodes this repository's specifics.
|
|
18
|
-
*/
|
|
19
|
-
import type { ToolApprovalStatus } from 'ai'
|
|
20
|
-
|
|
21
|
-
/** A per-tool approval configuration value: a static status or a function
|
|
22
|
-
* deciding from the call's input. (The SDK's per-tool map accepts both.) */
|
|
23
|
-
export type ApprovalDecision = ToolApprovalStatus | ((input: unknown) => ToolApprovalStatus)
|
|
24
|
-
|
|
25
|
-
/** The registry tools' discriminator fields, for qualified entries. A tool
|
|
26
|
-
* absent from this map has no discriminator; only bare entries match it. */
|
|
27
|
-
const DISCRIMINATOR_FIELDS: Record<string, string> = {
|
|
28
|
-
'builds.control': 'action',
|
|
29
|
-
'builds.answer': 'resolution',
|
|
30
|
-
'tickets.move': 'state',
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface ParsedApprovalEntry {
|
|
34
|
-
tool: string
|
|
35
|
-
qualifier?: string
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** Parse one configured entry into its tool and optional qualifier. The
|
|
39
|
-
* config schema already enforces the entry shape syntactically. */
|
|
40
|
-
export function parseApprovalEntry(entry: string): ParsedApprovalEntry {
|
|
41
|
-
const separator = entry.indexOf(':')
|
|
42
|
-
if (separator === -1) return { tool: entry }
|
|
43
|
-
return { tool: entry.slice(0, separator), qualifier: entry.slice(separator + 1) }
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Parse the whole configured list. Duplicate entries collapse harmlessly:
|
|
47
|
-
* the resulting matcher is a predicate, not a table. */
|
|
48
|
-
export function parseApprovalEntries(entries: readonly string[]): ParsedApprovalEntry[] {
|
|
49
|
-
return entries.map(parseApprovalEntry)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* The AI SDK `toolApproval` per-tool configuration for the parsed list: a
|
|
54
|
-
* bare entry maps the whole tool to `user-approval`; a qualified entry maps
|
|
55
|
-
* to a function that returns `user-approval` when the discriminator equals
|
|
56
|
-
* one of the tool's configured qualifiers, else `not-applicable`. Tools with
|
|
57
|
-
* no matching entry get no key at all — the SDK treats an absent key as
|
|
58
|
-
* not-applicable.
|
|
59
|
-
*/
|
|
60
|
-
export function approvalConfiguration(
|
|
61
|
-
entries: readonly ParsedApprovalEntry[],
|
|
62
|
-
): Record<string, ApprovalDecision> {
|
|
63
|
-
const bare = new Set<string>()
|
|
64
|
-
const qualified = new Map<string, Set<string>>()
|
|
65
|
-
for (const entry of entries) {
|
|
66
|
-
if (entry.qualifier === undefined) {
|
|
67
|
-
bare.add(entry.tool)
|
|
68
|
-
continue
|
|
69
|
-
}
|
|
70
|
-
if (bare.has(entry.tool)) continue
|
|
71
|
-
const set = qualified.get(entry.tool) ?? new Set<string>()
|
|
72
|
-
set.add(entry.qualifier)
|
|
73
|
-
qualified.set(entry.tool, set)
|
|
74
|
-
}
|
|
75
|
-
const configuration: Record<string, ApprovalDecision> = {}
|
|
76
|
-
for (const tool of bare) configuration[tool] = 'user-approval'
|
|
77
|
-
for (const [tool, qualifiers] of qualified) {
|
|
78
|
-
if (bare.has(tool)) continue
|
|
79
|
-
const field = DISCRIMINATOR_FIELDS[tool]
|
|
80
|
-
configuration[tool] = (input: unknown) => {
|
|
81
|
-
// A qualified entry for a tool without a declared discriminator never
|
|
82
|
-
// matches — there is nothing to compare.
|
|
83
|
-
if (field === undefined) return 'not-applicable'
|
|
84
|
-
const discriminator =
|
|
85
|
-
typeof input === 'object' && input !== null
|
|
86
|
-
? (input as Record<string, unknown>)[field]
|
|
87
|
-
: undefined
|
|
88
|
-
return typeof discriminator === 'string' && qualifiers.has(discriminator)
|
|
89
|
-
? 'user-approval'
|
|
90
|
-
: 'not-applicable'
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return configuration
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** Whether a specific call would be suspended — the mirror of
|
|
97
|
-
* `approvalConfiguration` for tests and for the runner's own diagnostics. */
|
|
98
|
-
export function callNeedsApproval(
|
|
99
|
-
entries: readonly ParsedApprovalEntry[],
|
|
100
|
-
tool: string,
|
|
101
|
-
input: unknown,
|
|
102
|
-
): boolean {
|
|
103
|
-
for (const entry of entries) {
|
|
104
|
-
if (entry.tool !== tool) continue
|
|
105
|
-
if (entry.qualifier === undefined) return true
|
|
106
|
-
const field = DISCRIMINATOR_FIELDS[tool]
|
|
107
|
-
if (field === undefined) continue
|
|
108
|
-
const discriminator =
|
|
109
|
-
typeof input === 'object' && input !== null
|
|
110
|
-
? (input as Record<string, unknown>)[field]
|
|
111
|
-
: undefined
|
|
112
|
-
if (discriminator === entry.qualifier) return true
|
|
113
|
-
}
|
|
114
|
-
return false
|
|
115
|
-
}
|