@arbol-ai/maximus 0.0.0-stage → 7.1.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/LICENSE +21 -0
- package/README.md +51 -2
- package/config/oxfmt.d.mts +8 -0
- package/config/oxfmt.mjs +30 -0
- package/config/oxlint-plugin.mjs +41 -0
- package/config/oxlint.d.mts +8 -0
- package/config/oxlint.mjs +118 -0
- package/dist/analytics/analytics.d.ts +34 -0
- package/dist/analytics/analytics.js +62 -0
- package/dist/body.d.ts +2 -0
- package/dist/body.js +4 -0
- package/dist/chunks/body-BcMbreNd.js +106 -0
- package/dist/chunks/correlation-gaiEoMBr.js +45 -0
- package/dist/chunks/execution-qfZuMSIu.js +700 -0
- package/dist/chunks/json-Dwni3u4c.js +63 -0
- package/dist/chunks/record-D2H3cg8S.js +36 -0
- package/dist/chunks/schemas-q-51wBMQ.js +216 -0
- package/dist/chunks/src-Ph5KHCRP.js +1160 -0
- package/dist/chunks/telemetry-DvZgrzZn.js +220 -0
- package/dist/chunks/types-CGwAhnTE.d.ts +1630 -0
- package/dist/chunks/validation-DWxKk1Js.js +382 -0
- package/dist/client/client.d.ts +131 -0
- package/dist/client/client.js +325 -0
- package/dist/diagnostics.d.ts +41 -0
- package/dist/diagnostics.js +4 -0
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +128 -0
- package/dist/http-paths.d.ts +2 -0
- package/dist/http-paths.js +200 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +11 -0
- package/dist/internals.d.ts +2 -0
- package/dist/internals.js +5 -0
- package/dist/mcp/index.d.ts +12 -0
- package/dist/mcp/index.js +406 -0
- package/dist/postgres/index.d.ts +81 -0
- package/dist/postgres/index.js +140 -0
- package/dist/projection.d.ts +36 -0
- package/dist/projection.js +60 -0
- package/dist/schemas.d.ts +2 -0
- package/dist/schemas.js +4 -0
- package/dist/standard-failures.d.ts +91 -0
- package/dist/standard-failures.js +75 -0
- package/dist/tooling/cli.js +110 -0
- package/dist/tooling/testing.d.ts +7 -0
- package/dist/tooling/testing.js +21 -0
- package/dist/webhooks.d.ts +69 -0
- package/dist/webhooks.js +162 -0
- package/dist/workers/runtime.d.ts +112 -0
- package/dist/workers/runtime.js +228 -0
- package/package.json +157 -4
- package/skills/maximus/SKILL.md +89 -0
- package/skills/maximus/references/adding-an-operation.md +179 -0
- package/skills/maximus/references/building-a-service.md +158 -0
- package/skills/maximus/references/errors-and-results.md +77 -0
- package/skills/maximus/references/migration-from-v2.md +62 -0
- package/skills/maximus/references/migration-to-v5.md +37 -0
- package/skills/maximus/references/publishing-and-verification.md +39 -0
- package/skills/maximus/references/testing.md +73 -0
- package/skills/maximus/references/transports.md +119 -0
- package/templates/service/.agents/skills/project/SKILL.md.template +10 -0
- package/templates/service/.github/workflows/ci.yml.template +21 -0
- package/templates/service/.gitignore.template +8 -0
- package/templates/service/CLAUDE.md.template +3 -0
- package/templates/service/README.md.template +45 -0
- package/templates/service/cloudflare.config.ts.template +30 -0
- package/templates/service/oxfmt.config.ts.template +1 -0
- package/templates/service/oxlint.config.ts.template +1 -0
- package/templates/service/package.json.template +31 -0
- package/templates/service/src/app.ts.template +30 -0
- package/templates/service/src/index.ts.template +13 -0
- package/templates/service/tests/contract.test.ts.template +12 -0
- package/templates/service/tsconfig.json.template +16 -0
- package/templates/service/vite.config.ts.template +7 -0
- package/templates/service/vitest.config.ts.template +10 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Migrating from 2.x
|
|
2
|
+
|
|
3
|
+
Move every `@getarbol/maximus*` dependency to the same 3.x version together.
|
|
4
|
+
(`@getarbol/maximus-postgres` is versioned on its own and unaffected.) Signed admission, unsigned
|
|
5
|
+
delegation and the service artifact below describe 3.x and 4.x; 5.0 removed them (see
|
|
6
|
+
`migration-to-v5.md`).
|
|
7
|
+
|
|
8
|
+
## Breaking changes in 3.0.0
|
|
9
|
+
|
|
10
|
+
| Area | 2.x | 3.x | Do |
|
|
11
|
+
| --- | --- | --- | --- |
|
|
12
|
+
| Issuer | `tokens.issuer` had a built-in default | No default | Set `tokens.issuer` everywhere OAuth tokens are verified or documented. Missing → every OAuth token is 401 and `/openapi.json` is 500. |
|
|
13
|
+
| Proof type | `arbol-admission+jwt` | `maximus-admission+jwt` | Release signer and all owners together. |
|
|
14
|
+
| OpenAPI extensions | `x-arbol-service-id`, `-publication`, `-publish`, `-input-schema`, `-actor-kinds` | `x-maximus-…` | Update readers of classified documents. |
|
|
15
|
+
| Security schemes | `arbolToken`, `arbolHuman`, `arbolMachine` | `oauth2`, `bearer` | Update clients and generators. |
|
|
16
|
+
| Service owner | `'arbol'` | `'platform'` | Replace in `service.owner`. |
|
|
17
|
+
| `maximus token` | `ARBOL_CLIENT_ID`, `ARBOL_CLIENT_SECRET`, `ARBOL_ISSUER` | `--issuer` (required), `MAXIMUS_CLIENT_ID`, `MAXIMUS_CLIENT_SECRET` | Removed in 4.0: drop it from operator scripts. |
|
|
18
|
+
|
|
19
|
+
## Notable 3.x additions
|
|
20
|
+
|
|
21
|
+
- 3.1.0: `@getarbol/maximus/projection`, `callAdmitted`, admission service schemas, `OUTCOME_UNKNOWN`.
|
|
22
|
+
- 3.2.0: `checkSchema`, `readSchema`.
|
|
23
|
+
- 3.3.0: `INVALID_INPUT` carries `data.issues` everywhere; clients expecting `data: {}` must accept it.
|
|
24
|
+
- 3.3.1: plain routes beneath a transport path.
|
|
25
|
+
- 3.4.0: `admission.attachments`; `describe` for an internal runtime's agent.
|
|
26
|
+
- 3.4.1: `callAdmitted` fixed for real Service Binding stubs; upgrade dispatchers from 3.4.0.
|
|
27
|
+
- 3.5.0: runtime-free `@getarbol/maximus/admitted` and `@getarbol/maximus/failures`.
|
|
28
|
+
- 3.6.0: `.build()` refuses a missing or non-HTTPS `tokens.issuer` and input codecs outside
|
|
29
|
+
`inputSchema()`.
|
|
30
|
+
|
|
31
|
+
## Classifying an unclassified (pre-2.13) service
|
|
32
|
+
|
|
33
|
+
1. `publication: 'private' | 'selected'`.
|
|
34
|
+
2. `publish: { rest, mcp }` on every operation (`true` only with the transport declared, never for
|
|
35
|
+
internal operations or in a private service).
|
|
36
|
+
3. `actorKinds` on every operation.
|
|
37
|
+
4. `api: { resource, verb, id? }` on every published or admitted operation.
|
|
38
|
+
5. `service: { kind, owner, publicName?, dependencies?, connections?, roles? }`.
|
|
39
|
+
6. `bun --bun maximus check`, then `bun --bun maximus export --allow-dirty --out artifact.json`.
|
|
40
|
+
|
|
41
|
+
`.build()` names the next operation and rule to fix.
|
|
42
|
+
|
|
43
|
+
## Unsigned delegation → signed admission
|
|
44
|
+
|
|
45
|
+
| | Before | After |
|
|
46
|
+
| --- | --- | --- |
|
|
47
|
+
| Operation | `delegated: { surfaces, actorKinds, clientClasses }` | `admission: { callers, ingresses }`, `actorKinds` |
|
|
48
|
+
| Application | `delegation: { authorize(env, grant) }` | `admission: { verification, authorize }` |
|
|
49
|
+
| Props | `{ caller: 'gateway', mode: 'delegated' }` | `{ caller: '<dispatcher>', mode: 'admitted' }` |
|
|
50
|
+
|
|
51
|
+
Same `worker.delegatedEntrypoint`. Unsigned grants are refused once `publication` is set.
|
|
52
|
+
|
|
53
|
+
## From 1.x
|
|
54
|
+
|
|
55
|
+
Explicit packages instead of Elysia/Eden; one fluent base with mounted resource modules; opt-in MCP
|
|
56
|
+
and telemetry; remove `Function` test shims; check consumers' RPC types against `Service<T>` with a
|
|
57
|
+
`never` control; keep Durable Object class names, migration tags and durable keys.
|
|
58
|
+
|
|
59
|
+
## Verify
|
|
60
|
+
|
|
61
|
+
Typecheck, tests, dry-run bundle, `maximus check` for classified services, then verify the deployed
|
|
62
|
+
Worker (health, OpenAPI, a 401 without token, a real call).
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Migrating to 5.0
|
|
2
|
+
|
|
3
|
+
The platform Gateway is a proxy to each service's own origin; services call each other over native
|
|
4
|
+
RPC. 5.0 removes what nothing calls anymore. TypeScript names each removed option that remains.
|
|
5
|
+
|
|
6
|
+
## Remove from the application
|
|
7
|
+
|
|
8
|
+
- `gateway: { audience, issuer, … }`: list the platform audience in `tokens.audience` instead
|
|
9
|
+
(`[OWN, PLATFORM]`); the origin verifies the forwarded token like any other. Move rules that
|
|
10
|
+
`gateway.authorize` applied into context or middleware.
|
|
11
|
+
- `originRoutes`: a selected service's origin serves and documents every declared route (as
|
|
12
|
+
`'declared'` did). With `'none'` it now also serves `/`, `/openapi.json` and `/health`; a web app
|
|
13
|
+
that needs `/` sets `http.basePath`.
|
|
14
|
+
- `contract`, `admission`, `delegation`.
|
|
15
|
+
- `service.kind`, `service.owner`, `service.dependencies`, `service.connections` (keep
|
|
16
|
+
`publicName`, `permissions`, `roles`).
|
|
17
|
+
- On operations: `admission`, `delegated`, `resourceSlots`, `execution`.
|
|
18
|
+
|
|
19
|
+
## Remove from the Worker
|
|
20
|
+
|
|
21
|
+
- `worker.delegatedEntrypoint` and its export (and the export declared in `cloudflare.config.ts` or
|
|
22
|
+
Wrangler), and bindings with props `mode: 'token' | 'admitted' | 'delegated'`.
|
|
23
|
+
- `maximus publish`, `maximus export`, `maximus permissions` steps in CI.
|
|
24
|
+
|
|
25
|
+
## Imports
|
|
26
|
+
|
|
27
|
+
- `isResult`: from `@getarbol/maximus` (was `/admitted`).
|
|
28
|
+
- Gone: `/admitted` (`callAdmitted`), `/delegation` (everything), `exportServiceContract`,
|
|
29
|
+
`ContractBuild`, `gatewayServes`, `GatewayPolicy`, `GatewayCall`, `OriginRoutes`, and from
|
|
30
|
+
`/projection` `publicName`, `cliCommand`, `restRoute`, `encodeQuery`, `decodeQuery`.
|
|
31
|
+
- `originServes(publication, operation, surface)` lost its `originRoutes` argument.
|
|
32
|
+
- `authority.admission` is gone; `authority.token` remains.
|
|
33
|
+
|
|
34
|
+
## OpenAPI
|
|
35
|
+
|
|
36
|
+
`x-maximus-gateway`, `x-maximus-failures` and `x-maximus-service.kind` are gone; `x-maximus-tokens:
|
|
37
|
+
{ issuer, audiences }` names whose tokens the service verifies. The `artifact` projection is gone.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Deploying and verifying
|
|
2
|
+
|
|
3
|
+
## A new service (`@arbol-ai/maximus`)
|
|
4
|
+
|
|
5
|
+
One command, `bunx @arbol-ai/maximus init <dir> --name <name>`: a starter project on the CLI's own
|
|
6
|
+
release, scripted with `cf`; it passes `bun run verify` as generated. Replace the placeholder origin,
|
|
7
|
+
audience and issuer in `src/app.ts` before deploying. Develop, build and deploy with `cf dev`,
|
|
8
|
+
`cf build`, `cf workers types` and `cf deploy`: Maximus does not wrap them.
|
|
9
|
+
|
|
10
|
+
`createOpenApi(app)` builds the document the origin serves at `/openapi.json`, for SDKs or a contract
|
|
11
|
+
check at build time. Nothing is published from the service: deploying it is the release.
|
|
12
|
+
|
|
13
|
+
## Before deploying
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
bun run typecheck # cf build does not typecheck
|
|
17
|
+
bun run test
|
|
18
|
+
cf build # then read .cloudflare/output/v0/workers/default/worker.config.json: no dev token
|
|
19
|
+
cf deploy --prebuilt --mode production # --dry-run first; cf auth login or CLOUDFLARE_API_TOKEN
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`nodejs_compat` on; secrets as `bindings.secret()`, uploaded with `cf deploy --secrets-file` or kept
|
|
23
|
+
in Secrets Store, never in `bindings.text()`; `.dev.vars` local only, and the development token
|
|
24
|
+
declared for `cf dev` alone; Durable Object class names unchanged and declared as exports; preview
|
|
25
|
+
environments use their own audience, state and credentials.
|
|
26
|
+
|
|
27
|
+
## After deploying
|
|
28
|
+
|
|
29
|
+
Verify the real Worker: `/health` version; `/openapi.json` operations (`verifyContract`); `401`
|
|
30
|
+
without a token; a real token call for a test organization; MCP `tools/list`;
|
|
31
|
+
RPC calls through a real caller. Keep tokens and raw responses in an ignored `.private/`
|
|
32
|
+
(0700/0600) and never print sensitive bodies to shared logs. Mocks are never evidence of a live
|
|
33
|
+
deployment.
|
|
34
|
+
|
|
35
|
+
## Releasing Maximus itself (framework repository)
|
|
36
|
+
|
|
37
|
+
`bun run verify` (build, typecheck, lint, tests, packed-package and isolation checks), packages in
|
|
38
|
+
dependency order from packed tarballs, never with `workspace:` or `file:` dependencies; then install
|
|
39
|
+
from the registry, run consumers' workerd tests and dry bundles, and verify a real deployment.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Testing
|
|
2
|
+
|
|
3
|
+
Maximus tests its own guarantees (token verification, routing, envelopes, validation boundaries,
|
|
4
|
+
diagnostics privacy, MCP pagination). Test what only the service knows: domain rules, tenant
|
|
5
|
+
isolation in queries, provider projections, state, retries and policies. Do not copy the framework's
|
|
6
|
+
matrices into every service.
|
|
7
|
+
|
|
8
|
+
## Handler tests (Node or Bun, Vitest)
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { createHttpHandler } from '@arbol-ai/maximus';
|
|
12
|
+
import { app } from '../src/app'; // app.ts must not import cloudflare:workers
|
|
13
|
+
|
|
14
|
+
const handle = createHttpHandler(app);
|
|
15
|
+
const response = await handle(new Request('http://localhost:5173/v1/notes'), env);
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
- Fake bindings through the narrow interfaces in `Env` (a `Map` behind a `NoteStore`), not casts.
|
|
19
|
+
- Default OAuth verification: `createHttpHandler(app, { verify: async () => claims })` replaces only
|
|
20
|
+
the JWT check. Person claims: `{ sub, azp, org_id: 'org_1234567890abcdef', scope, permissions }`;
|
|
21
|
+
machine: `{ sub: '<client>@clients', client_id: '<client>', org_id, scope }`. Send
|
|
22
|
+
`authorization: Bearer a.b.c` (JWT-shaped). Never pass `verify` in production.
|
|
23
|
+
- Custom `tokens.resolve`: put the test credential in `env` and exercise the real resolver.
|
|
24
|
+
- Typed client against the handler:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
const client = createClient<typeof app>('http://localhost:5173', token, {
|
|
28
|
+
response: 'data',
|
|
29
|
+
fetch: async (input, init) => await handle(new Request(input, init), env),
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## MCP
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
const handle = createHttpHandler(app, { verify: async () => claims, transports: [mcp()] });
|
|
37
|
+
// POST /mcp with accept: application/json, text/event-stream and a JSON-RPC body;
|
|
38
|
+
// parse the response with /data: (\{[^\n]*)/
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Without a transport
|
|
42
|
+
|
|
43
|
+
`executeOperation(app, app.operations.name, env, principal, input, authority?)` from
|
|
44
|
+
`@arbol-ai/maximus/internals` runs the shared execution path (input decoding, derive, middleware,
|
|
45
|
+
handler, output check) for RPC-only operations. Principal:
|
|
46
|
+
`{ actorId, actorKind, organizationId: 'org_' + 16 alphanumerics, requestId: crypto.randomUUID() }`.
|
|
47
|
+
|
|
48
|
+
## Contract smoke
|
|
49
|
+
|
|
50
|
+
`verifyContract((request) => handle(request, env), origin)` from `@arbol-ai/maximus/testing` checks
|
|
51
|
+
that `/openapi.json` and `/openapi.yaml` are the same document and returns `{ paths, operations }`.
|
|
52
|
+
Run one per service against the real Worker (workerd or a deployment).
|
|
53
|
+
|
|
54
|
+
## workerd
|
|
55
|
+
|
|
56
|
+
Durable Objects, real bindings and Service Bindings: Cloudflare's Vitest integration with remote
|
|
57
|
+
bindings off, or Miniflare with several Workers.
|
|
58
|
+
|
|
59
|
+
## RPC types
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
type AssertFalse<T extends false> = T;
|
|
63
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
64
|
+
export type QuoteReturnExists = AssertFalse<IsNever<Awaited<ReturnType<Service<typeof PricingService>['quoteItems']>>>>;
|
|
65
|
+
// @ts-expect-error The control must fail; otherwise the check proves nothing.
|
|
66
|
+
export type NeverControl = AssertFalse<IsNever<never>>;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## CI rules
|
|
70
|
+
|
|
71
|
+
Synthetic data only; no live providers, paid services or production resources; remote bindings
|
|
72
|
+
off. Scripts call domain functions or the typed client, never a second provider implementation.
|
|
73
|
+
Keep security, privacy and retry tests where they are.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Transports
|
|
2
|
+
|
|
3
|
+
| | HTTP | MCP | Native RPC |
|
|
4
|
+
| --- | --- | --- | --- |
|
|
5
|
+
| Opt in | `http: { method, path }` | `mcp: { name, idempotent }` + `transports: [mcp()]` | `rpc: true` or `{ callers }` + app `rpc.callers` |
|
|
6
|
+
| Caller proves | Bearer token | Bearer token with `<namespace>:mcp:use` | Service Binding props `{ caller }` |
|
|
7
|
+
| Scopes checked | Yes | Yes, also to list tools | No |
|
|
8
|
+
| Success | Envelope `{ success: true, data, error: null, metadata: { requestId } }` | `structuredContent` + JSON text | `{ ok: true, value }` |
|
|
9
|
+
| Failure | Catalog status + `{ success: false, data: null, error, metadata }` | `isError: true`, failure JSON text | `{ ok: false, error }` |
|
|
10
|
+
|
|
11
|
+
All three share input validation, `derive`, middleware, the handler and output validation.
|
|
12
|
+
|
|
13
|
+
## HTTP and OpenAPI
|
|
14
|
+
|
|
15
|
+
- Responses always carry `x-request-id`, `cache-control: private, no-store`, `nosniff` and
|
|
16
|
+
`server-timing`. A `401` carries `WWW-Authenticate: Bearer resource_metadata="<origin>/.well-known/oauth-protected-resource"`.
|
|
17
|
+
- `/openapi.json`, `/openapi.yaml`, `/openapi.yml`: OpenAPI 3.1 of the public HTTP operations (never
|
|
18
|
+
an internal one): scopes as OAuth security requirements (`<issuer>authorize`, `<issuer>oauth/token`
|
|
19
|
+
by default), one response per failure status naming the codes that answer with it
|
|
20
|
+
(`FailureResponse` narrowed to them), and the operation extensions `x-required-scopes`,
|
|
21
|
+
`x-scope-match` (with more than one scope), `x-conditional-scopes`, `x-effect`, `x-mcp-tool` (with
|
|
22
|
+
`x-mcp-idempotent`, `x-mcp-open-world`), `x-native-rpc`, `x-max-body-bytes` and
|
|
23
|
+
`x-max-output-bytes` (the limits in force), `x-body`, `x-input-headers` and `x-response`. The root
|
|
24
|
+
holds only `openapi`, `info`, `servers`, `paths` and `components`; the tag defaults to the
|
|
25
|
+
operation's name. Every `$ref` is local: a schema's `$id` (shared schemas, `PageInfo`, each `Page`,
|
|
26
|
+
recursive schemas) becomes `#/components/schemas/<id>`; every envelope's `metadata` refers to
|
|
27
|
+
`ResponseMetadata` and every failure narrows `Failure`. MCP tool schemas stay self-contained: named
|
|
28
|
+
schemas written in place, without `$id`.
|
|
29
|
+
- `createOpenApi(app)` builds that same document at build time.
|
|
30
|
+
- Rate limiting: `rateLimit: { binding, retryAfter }` (a Workers rate limit binding), keyed by
|
|
31
|
+
organization and actor after authentication; 429 `RATE_LIMITED`.
|
|
32
|
+
- Typed callers: `createClient<typeof app>(baseUrl, token, { response: 'data' })` from
|
|
33
|
+
`@arbol-ai/maximus/client`, importing `app` as a type only. HTTPS (plain `http://` only on
|
|
34
|
+
loopback), no redirects, no write retries, `fetch` option for tests.
|
|
35
|
+
|
|
36
|
+
## MCP
|
|
37
|
+
|
|
38
|
+
- Endpoint `/mcp` (or `mcp({ path })`, `/` for a dedicated host), Streamable HTTP, stateless.
|
|
39
|
+
Clients send `accept: application/json, text/event-stream`; answers are SSE `data:` lines.
|
|
40
|
+
- Tools visible to a token: its scopes match the operation and `actorKinds` allows its actor. 50 per
|
|
41
|
+
`tools/list` page. Calls of unseen tools are JSON-RPC errors.
|
|
42
|
+
- Annotations: `readOnlyHint` = effect read, `destructiveHint` = effect delete, `idempotentHint` =
|
|
43
|
+
`mcp.idempotent`, `openWorldHint` = `mcp.openWorld ?? true`. Hints are not authorization.
|
|
44
|
+
- App `mcp`: `instructions`; `guides: [{ name, title, text }]` (resources and prompts);
|
|
45
|
+
`skills: [{ name, description, text }]` (MCP Skills extension, `skill://<name>/SKILL.md`);
|
|
46
|
+
`skillTool: 'read_skill'` (skills as one read-only tool, first in the catalog).
|
|
47
|
+
- A union input lists as one object (every member's fields, the discriminator as an `enum`), since
|
|
48
|
+
hosts refuse a root `anyOf`; each call is still checked against the exact union.
|
|
49
|
+
- An unexpected failure of the server answers the JSON-RPC `Internal error`, never its own text, and
|
|
50
|
+
is reported as `maximus.unexpected`.
|
|
51
|
+
- Resources `openapi-json` and `openapi-yaml` expose the public contract, named by the URLs that
|
|
52
|
+
serve it (below `http.basePath`); reading grants nothing.
|
|
53
|
+
- The endpoint admits the largest `maxBodyBytes` among the tools the caller may call and holds each
|
|
54
|
+
call to its own.
|
|
55
|
+
- A `bearer` token scheme cannot mount MCP. Keep credential and permission management out of tools.
|
|
56
|
+
|
|
57
|
+
## Native RPC
|
|
58
|
+
|
|
59
|
+
Owner:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
maximus<Env>({ /* ... */ rpc: { callers: ['orders'] } })
|
|
63
|
+
.operation('quoteItems', { /* ... */ rpc: true }, handler);
|
|
64
|
+
export const PricingService = createWorker(app).entrypoint;
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Owner `cloudflare.config.ts` declares `exports: { PricingService: exports.worker() }` and exports its
|
|
68
|
+
`defineWorker` definition; caller `cloudflare.config.ts`:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
PRICING: bindings.worker({ worker: pricingWorker, exportName: 'PricingService', props: { caller: 'orders' } }),
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Locally, the caller's `vite.config.ts` runs the owner beside it:
|
|
75
|
+
`cloudflare({ auxiliaryWorkers: [{ config: pricingWorker, devOnly: true }] })`.
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
// Env: PRICING: Service<typeof PricingService>
|
|
79
|
+
const quote = await env.PRICING.quoteItems(principal, { items }); // forward the verified principal
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
- The owner requires props exactly `{ caller }` with an admitted caller, and a principal that matches
|
|
83
|
+
`{ actorId, actorKind, organizationId, requestId }` exactly; otherwise `UNAUTHORIZED`.
|
|
84
|
+
- No scopes are checked and `authority` is absent: the calling deployment is trusted. When the owner
|
|
85
|
+
must verify the original authority, call its HTTP route with the caller's token
|
|
86
|
+
(`authority.token`).
|
|
87
|
+
- Owner failures belong to the owner's catalog: translate them before returning them, or the
|
|
88
|
+
caller's output check turns them into `INTERNAL_ERROR`. Catch thrown calls (owner unreachable).
|
|
89
|
+
- `worker.service(Class)` and `worker.durableObject(Class)` wrap your own entrypoints and Durable
|
|
90
|
+
Objects with diagnostics and adapters. Never rename Durable Object classes or migration tags.
|
|
91
|
+
|
|
92
|
+
## Plain routes and Worker composition
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
createWorker(app, {
|
|
96
|
+
routes: { '/webhooks/payments': paymentWebhook }, // exact paths, no principal, not in OpenAPI
|
|
97
|
+
http: {
|
|
98
|
+
basePath: '/api', // operations + discovery below /api; transports stay absolute
|
|
99
|
+
mounts: { '/files': serveFiles }, // prefix + slash-delimited descendants
|
|
100
|
+
before: async (request) => null, // first; a Response answers
|
|
101
|
+
aroundOperation: async (request, env, op, run) => run(env), // matched HTTP operations; run once
|
|
102
|
+
origins: ['https://notes.example.com'], // exact HTTPS origins, others 404
|
|
103
|
+
healthPath: '/healthz',
|
|
104
|
+
},
|
|
105
|
+
assets: { binding: 'ASSETS', pages: { paths: ['/'] }, immutablePrefixes: ['/assets/'] },
|
|
106
|
+
handlers: { scheduled: runJobs },
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
- A plain route (`HttpRoute<Env>`: `(request, env, { requestId, fail, waitUntil })`) verifies its
|
|
111
|
+
own signature on the exact bytes (`readBodyBytes(request, { maxBytes, signal })`) before treating
|
|
112
|
+
them as data, answers failures with `context.fail(failure, headers?)`, and may set its own
|
|
113
|
+
`cache-control`.
|
|
114
|
+
- Reserved: `/v<n>/…`, native paths, transport paths, `tokens.resources` keys. Collisions fail at
|
|
115
|
+
construction. A route may sit beneath a transport's path.
|
|
116
|
+
- `fallback` (or `assets`, not both) answers only paths outside API, versioned, native,
|
|
117
|
+
`/.well-known` and transport namespaces.
|
|
118
|
+
- Assets: configure the binding with `html_handling: "none"`, `not_found_handling: "none"` and
|
|
119
|
+
`run_worker_first: true`.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: __PROJECT_NAME__-development
|
|
3
|
+
description: Add and verify operations in the __PROJECT_NAME__ service.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Read CLAUDE.md and the Maximus skill at node_modules/@arbol-ai/maximus/skills/maximus/SKILL.md.
|
|
7
|
+
Declare strict input/output, effect and scope in src/api/<resource>/operations.ts and mount the
|
|
8
|
+
module in src/app.ts. Expose only the transports a caller needs (http, mcp, rpc). Keep upstream
|
|
9
|
+
protocols and state in this project. Use @arbol-ai/maximus/testing for the contract smoke and add
|
|
10
|
+
domain tests for the risks unique to this service.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: Verify
|
|
2
|
+
on: [push, pull_request]
|
|
3
|
+
permissions:
|
|
4
|
+
contents: read
|
|
5
|
+
packages: read
|
|
6
|
+
jobs:
|
|
7
|
+
verify:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
steps:
|
|
10
|
+
- uses: actions/checkout@v7
|
|
11
|
+
- uses: oven-sh/setup-bun@v2
|
|
12
|
+
with:
|
|
13
|
+
bun-version: 1.4.3
|
|
14
|
+
# cf runs on Node 22 or later.
|
|
15
|
+
- uses: actions/setup-node@v7
|
|
16
|
+
with:
|
|
17
|
+
node-version: 24
|
|
18
|
+
- run: bun install --frozen-lockfile
|
|
19
|
+
env:
|
|
20
|
+
NODE_AUTH_TOKEN: ${{ secrets.PACKAGES_TOKEN || github.token }}
|
|
21
|
+
- run: bun run verify
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# Agent guide
|
|
2
|
+
|
|
3
|
+
Read .agents/skills/project/SKILL.md and the installed Maximus skill (node_modules/@arbol-ai/maximus/skills/maximus/SKILL.md). Code/docs are English. Use organizationId, strict schemas and namespaced scopes. Keep credentials and provider evidence in ignored .private/ (0700/0600). Add operations in resource modules; compose once in app.ts. Domain functions are shared with scripts. Tests own provider behavior, not framework JWT/protocol matrices. Run bun run verify. Never call live providers in CI. Configure audience, issuer, callers and deployment resources before release.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# __PROJECT_NAME__
|
|
2
|
+
|
|
3
|
+
A [Maximus](https://github.com/getarbol/maximus) service on Cloudflare Workers. It
|
|
4
|
+
declares each operation once and serves it over HTTP with its OpenAPI document, and, when an
|
|
5
|
+
operation asks for them, as an MCP tool and a Worker RPC method.
|
|
6
|
+
|
|
7
|
+
## Before the first deployment
|
|
8
|
+
|
|
9
|
+
`src/app.ts` uses placeholders: set `origin` to the service's public HTTPS origin, `tokens.audience`
|
|
10
|
+
to the audience its access tokens carry and `tokens.issuer` to the authorization server that issues
|
|
11
|
+
them. The starter declares no operation, so it serves only its discovery documents and `/health`.
|
|
12
|
+
|
|
13
|
+
## Run it locally
|
|
14
|
+
|
|
15
|
+
`bun run dev` serves the Worker on `localhost` with `cf dev`. `maximus init` wrote a random development
|
|
16
|
+
token to `.dev.vars`, which Git ignores and `cloudflare.config.ts` declares for `cf dev` alone, so no
|
|
17
|
+
deployed build carries it. From `localhost` it is a developer holding every scope the service declares:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
TOKEN=$(sed 's/^DEVELOPMENT_TOKEN=//' .dev.vars)
|
|
21
|
+
curl -H "authorization: Bearer $TOKEN" http://localhost:5173/v1/<your operation's route>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Commands
|
|
25
|
+
|
|
26
|
+
| Command | Runs |
|
|
27
|
+
| ------------------------------- | -------------------------------------------------------------------------------------------- |
|
|
28
|
+
| `bun install` | Installs the dependencies. |
|
|
29
|
+
| `bun run dev` | The Worker locally, with `cf dev`. |
|
|
30
|
+
| `bun run typecheck` | Generates the binding and runtime types with `cf workers types`, then TypeScript. |
|
|
31
|
+
| `bun run check` / `bun run fix` | Lint and format with the Maximus presets. |
|
|
32
|
+
| `bun run test` | The tests, in the Workers runtime. |
|
|
33
|
+
| `bun run build` | `cf build`, which writes the build `cf deploy` uploads. |
|
|
34
|
+
| `bun run verify` | Everything above. |
|
|
35
|
+
| `bun run deploy` | `verify`, then deploys that same build with `cf deploy`. Sign in with `cf auth login` first. |
|
|
36
|
+
|
|
37
|
+
## Layout
|
|
38
|
+
|
|
39
|
+
- `src/app.ts`: the application. Declare operations in resource modules
|
|
40
|
+
(`src/api/<resource>/operations.ts`) that build on `base`, and mount each module here once.
|
|
41
|
+
- `src/index.ts`: the Worker: its default export serves HTTP, and the named entrypoint serves RPC.
|
|
42
|
+
- `tests/`: the contract smoke and the tests for what is specific to this service.
|
|
43
|
+
|
|
44
|
+
Use synthetic data in tests, give previews their own resources and never point CI at production.
|
|
45
|
+
Keep credentials and provider evidence out of the repository (`.private/` is ignored).
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Worker as `cf` develops, builds and deploys it: its name, runtime, entrypoint and bindings.
|
|
3
|
+
*/
|
|
4
|
+
import { bindings, defineConfig } from 'cf/config';
|
|
5
|
+
|
|
6
|
+
import * as entrypoint from './src/index.ts' with { type: 'cf-worker' };
|
|
7
|
+
|
|
8
|
+
export default defineConfig(({ mode }) => ({
|
|
9
|
+
worker: {
|
|
10
|
+
name: '__PROJECT_NAME__',
|
|
11
|
+
compatibilityDate: '2026-10-12',
|
|
12
|
+
// Maximus keeps per-invocation diagnostics in AsyncLocalStorage (node:async_hooks).
|
|
13
|
+
compatibilityFlags: ['nodejs_compat'],
|
|
14
|
+
entrypoint,
|
|
15
|
+
// A workers.dev URL or a preview URL would be one more origin for the same Worker.
|
|
16
|
+
workersDev: false,
|
|
17
|
+
previewUrls: false,
|
|
18
|
+
observability: {
|
|
19
|
+
enabled: true,
|
|
20
|
+
redactQueryString: true,
|
|
21
|
+
logs: { enabled: true, invocationLogs: true },
|
|
22
|
+
traces: { enabled: true },
|
|
23
|
+
},
|
|
24
|
+
env: {
|
|
25
|
+
// The development token `maximus init` wrote to .dev.vars, declared for `cf dev` alone: no build that
|
|
26
|
+
// is deployed carries it.
|
|
27
|
+
DEVELOPMENT_TOKEN: mode === 'development' && bindings.secret(),
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '@arbol-ai/maximus/oxfmt';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '@arbol-ai/maximus/oxlint';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__PROJECT_NAME__",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "cf dev",
|
|
7
|
+
"typecheck": "cf workers types && tsc",
|
|
8
|
+
"check": "ultracite check",
|
|
9
|
+
"fix": "ultracite fix",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"build": "cf build",
|
|
12
|
+
"verify": "bun run typecheck && bun run check && bun run test && bun run build",
|
|
13
|
+
"deploy": "bun run verify && cf deploy --prebuilt --mode production"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@arbol-ai/maximus": "__MAXIMUS_VERSION__"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@cloudflare/vite-plugin": "^2.0.0-beta.v.1",
|
|
20
|
+
"@cloudflare/vitest-plugin": "^1.4.4",
|
|
21
|
+
"@types/node": "^26.6.5",
|
|
22
|
+
"cf": "^1.0.0-beta.18",
|
|
23
|
+
"oxfmt": "^0.73.0",
|
|
24
|
+
"oxlint": "^1.88.0",
|
|
25
|
+
"typescript": "^7.0.2",
|
|
26
|
+
"ultracite": "^8.0.1",
|
|
27
|
+
"vite": "^8.3.4",
|
|
28
|
+
"vitest": "^5.0.5"
|
|
29
|
+
},
|
|
30
|
+
"packageManager": "bun@1.4.3"
|
|
31
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The service's application: its configuration, its error catalog and, as you add them, its operations.
|
|
3
|
+
*/
|
|
4
|
+
import { defineErrors, maximus } from '@arbol-ai/maximus';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The service's one application. Set its public origin, the OAuth audience its tokens are issued for
|
|
8
|
+
* and the authorization server that issues them before the first deployment.
|
|
9
|
+
*/
|
|
10
|
+
export const base = maximus<Env>({
|
|
11
|
+
name: '__PROJECT_NAME__',
|
|
12
|
+
namespace: '__PROJECT_NAME__',
|
|
13
|
+
title: '__PROJECT_NAME__',
|
|
14
|
+
version: '0.1.0',
|
|
15
|
+
origin: 'https://__PROJECT_NAME__.example.com',
|
|
16
|
+
tokens: {
|
|
17
|
+
audience: 'https://__PROJECT_NAME__.example.com',
|
|
18
|
+
issuer: 'https://auth.example.com/',
|
|
19
|
+
// From localhost only: the token `maximus init` wrote to `.dev.vars`, for `cf dev`.
|
|
20
|
+
development: { binding: 'DEVELOPMENT_TOKEN' },
|
|
21
|
+
},
|
|
22
|
+
errors: defineErrors({}),
|
|
23
|
+
rpc: { callers: [] },
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The checked application. Chain operations on `base`, or mount resource modules built on it, before
|
|
28
|
+
* `.build()`.
|
|
29
|
+
*/
|
|
30
|
+
export const app = base.build();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The service's Worker: its fetch handler and its RPC entrypoint.
|
|
3
|
+
*/
|
|
4
|
+
import { createWorker } from '@arbol-ai/maximus/workers';
|
|
5
|
+
|
|
6
|
+
import { app } from './app';
|
|
7
|
+
|
|
8
|
+
/** The application as a Worker. */
|
|
9
|
+
const worker = createWorker(app);
|
|
10
|
+
|
|
11
|
+
/** The named RPC entrypoint other Workers bind to; its methods are the operations that declare `rpc`. */
|
|
12
|
+
export const __ENTRYPOINT__ = worker.entrypoint;
|
|
13
|
+
export default worker.handler;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The service's contract smoke test, against the Worker in workerd.
|
|
3
|
+
*/
|
|
4
|
+
import { verifyContract } from '@arbol-ai/maximus/testing';
|
|
5
|
+
import { exports } from 'cloudflare:workers';
|
|
6
|
+
import { expect, it } from 'vitest';
|
|
7
|
+
|
|
8
|
+
it('publishes one runtime contract', async () => {
|
|
9
|
+
const contract = await verifyContract((request) => exports.default.fetch(request), 'https://example.test');
|
|
10
|
+
// A new service publishes no paths yet; list them here as you add operations.
|
|
11
|
+
expect(contract.paths).toEqual([]);
|
|
12
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2024",
|
|
4
|
+
"lib": ["ES2024"],
|
|
5
|
+
"module": "preserve",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"types": ["node"],
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"allowImportingTsExtensions": true,
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
"verbatimModuleSyntax": true,
|
|
13
|
+
"skipLibCheck": true
|
|
14
|
+
},
|
|
15
|
+
"include": ["src", "tests", "cloudflare.config.ts", ".cloudflare/types"]
|
|
16
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The build `cf` runs: Cloudflare's Vite plugin bundles the Worker and, under `cf dev`, runs it in workerd.
|
|
3
|
+
*/
|
|
4
|
+
import { cloudflare } from '@cloudflare/vite-plugin';
|
|
5
|
+
import { defineConfig } from 'vite';
|
|
6
|
+
|
|
7
|
+
export default defineConfig({ plugins: [cloudflare()] });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tests run in workerd, with the Worker and the bindings cloudflare.config.ts declares.
|
|
3
|
+
*/
|
|
4
|
+
import { cloudflareTest } from '@cloudflare/vitest-plugin';
|
|
5
|
+
import { defineConfig } from 'vitest/config';
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
plugins: [cloudflareTest({ remoteBindings: false, experimental: { newConfig: true } })],
|
|
9
|
+
test: { include: ['tests/**/*.test.ts'] },
|
|
10
|
+
});
|