@arbol-ai/maximus 7.3.1 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +36 -38
  2. package/bin/maximus.js +4 -0
  3. package/config/oxfmt.mjs +1 -0
  4. package/config/oxlint.mjs +10 -0
  5. package/dist/analytics/analytics.d.ts +21 -9
  6. package/dist/analytics/analytics.js +19 -5
  7. package/dist/body.d.ts +1 -1
  8. package/dist/body.js +2 -2
  9. package/dist/chunks/agent-skills-Ef65jTf_.js +49 -0
  10. package/dist/chunks/agent-skills-m7y1EUch.js +3 -0
  11. package/dist/chunks/{body-6LichrQm.js → body-DOIHwIIl.js} +14 -7
  12. package/dist/chunks/{correlation-BEkcFFGT.js → correlation-4b23a-a4.js} +8 -5
  13. package/dist/chunks/define-app-CfVZBt7D.js +336 -0
  14. package/dist/chunks/errors-WfyKhiyk.js +131 -0
  15. package/dist/chunks/execution-CfZEx_JP.js +84 -0
  16. package/dist/chunks/generate-C-9FKW0o.js +197 -0
  17. package/dist/chunks/handler-DWTGoduQ.js +140 -0
  18. package/dist/chunks/http-layout-_h7xwgPC.js +128 -0
  19. package/dist/chunks/http-paths-DMBxwpp6.js +218 -0
  20. package/dist/chunks/{json-Bu4BLT25.js → json-B14evE6-.js} +21 -5
  21. package/dist/chunks/names-ncD7A3DV.js +280 -0
  22. package/dist/chunks/openapi-CV0KmJpS.js +1588 -0
  23. package/dist/chunks/openapi-file-OjSs9mRv.js +83 -0
  24. package/dist/chunks/pages-DyC0m8Zb.js +14 -0
  25. package/dist/chunks/prepare-configured-BmRJLg6J.js +3 -0
  26. package/dist/chunks/prepare-configured-Cithjf80.js +52 -0
  27. package/dist/chunks/project-files-C0OX7MQQ.js +130 -0
  28. package/dist/chunks/query-kind-CWKAXEME.js +40 -0
  29. package/dist/chunks/record-DQUDTpEA.js +10 -0
  30. package/dist/chunks/result-CKgZHrnj.js +56 -0
  31. package/dist/chunks/{runtime-BPnaa-NK.js → runtime-CVVf5hmp.js} +50 -25
  32. package/dist/chunks/scaffold-DGrcjR3h.js +3 -0
  33. package/dist/chunks/scaffold-DZD6dfoZ.js +138 -0
  34. package/dist/chunks/{schemas-CzTvbXb6.js → schemas-p_aRcMC1.js} +30 -14
  35. package/dist/chunks/server-CCc7fil4.js +410 -0
  36. package/dist/chunks/src--HZrH1U9.js +568 -0
  37. package/dist/chunks/standard-failures-CLjxS2ea.js +74 -0
  38. package/dist/chunks/{telemetry-BTwB68m5.js → telemetry-C3LfZcOB.js} +32 -11
  39. package/dist/chunks/{types-BWxDd3tY.d.ts → types-BQYB4Ads.d.ts} +998 -337
  40. package/dist/chunks/{validation-r-sgmsqb.js → validation-fTohBT6R.js} +69 -28
  41. package/dist/chunks/workers-types-iONp32T4.d.ts +143 -0
  42. package/dist/chunks/yaml-Dk2L24yQ.js +74 -0
  43. package/dist/diagnostics.d.ts +6 -4
  44. package/dist/diagnostics.js +2 -2
  45. package/dist/errors.d.ts +2 -2
  46. package/dist/errors.js +2 -125
  47. package/dist/http-paths.d.ts +1 -1
  48. package/dist/http-paths.js +1 -197
  49. package/dist/index.d.ts +2 -2
  50. package/dist/index.js +12 -10
  51. package/dist/internals.d.ts +1 -1
  52. package/dist/internals.js +5 -3
  53. package/dist/mcp/index.d.ts +3 -2
  54. package/dist/mcp/index.js +5 -387
  55. package/dist/postgres/index.d.ts +25 -8
  56. package/dist/postgres/index.js +17 -8
  57. package/dist/project/config.d.ts +139 -0
  58. package/dist/project/config.js +196 -0
  59. package/dist/project/index.d.ts +17 -4
  60. package/dist/project/index.js +44 -9
  61. package/dist/projection.d.ts +14 -13
  62. package/dist/projection.js +8 -32
  63. package/dist/schemas.d.ts +1 -1
  64. package/dist/schemas.js +2 -2
  65. package/dist/standard-failures.d.ts +2 -89
  66. package/dist/standard-failures.js +1 -72
  67. package/dist/tooling/cli.js +151 -107
  68. package/dist/tooling/testing.js +2 -2
  69. package/dist/vite/cloudflare-workers.js +25 -0
  70. package/dist/vite/index.d.ts +157 -0
  71. package/dist/vite/index.js +1477 -0
  72. package/dist/webhooks.d.ts +12 -10
  73. package/dist/webhooks.js +26 -12
  74. package/dist/workers/runtime.d.ts +1 -1
  75. package/dist/workers/runtime.js +1 -1
  76. package/package.json +30 -22
  77. package/skills/maximus/SKILL.md +165 -69
  78. package/skills/maximus/references/deploying.md +73 -0
  79. package/skills/maximus/references/errors-and-results.md +114 -55
  80. package/skills/maximus/references/project.md +202 -0
  81. package/skills/maximus/references/routes-and-tools.md +256 -0
  82. package/skills/maximus/references/testing.md +137 -50
  83. package/skills/maximus/references/transports.md +113 -100
  84. package/skills/maximus/references/writing-code.md +84 -0
  85. package/templates/mcp/mcp/instructions.md.template +2 -0
  86. package/templates/mcp/routes/v1/greeting.get.ts.template +12 -0
  87. package/templates/mcp/tests/mcp.test.ts.template +36 -0
  88. package/templates/project/.agents/skills/project/SKILL.md.template +21 -12
  89. package/templates/project/.github/workflows/ci.yml.template +4 -1
  90. package/templates/project/CLAUDE.md.template +41 -22
  91. package/templates/project/README.md.template +54 -47
  92. package/templates/project/middleware/10-response.ts.template +16 -0
  93. package/templates/project/package.json.template +16 -8
  94. package/templates/project/pages/index.ts.template +2 -4
  95. package/templates/project/routes/v1/greeting.get.ts.template +10 -0
  96. package/templates/project/routes/v1/greeting.post.ts.template +12 -0
  97. package/templates/project/tests/greeting.test.ts.template +45 -0
  98. package/templates/project/tsconfig.json.template +8 -5
  99. package/templates/project/vite.config.ts.template +15 -7
  100. package/templates/web/app/main.tsx.template +16 -0
  101. package/templates/web/app/root.tsx.template +17 -0
  102. package/templates/web/app/routes/index.tsx.template +9 -0
  103. package/templates/web/index.html.template +12 -0
  104. package/templates/web/package.json.template +12 -0
  105. package/templates/web/tsconfig.json.template +7 -0
  106. package/templates/web/vite.config.ts.template +22 -0
  107. package/dist/chunks/execution-B-yy4C7N.js +0 -691
  108. package/dist/chunks/prepare-project-zi106pWF.js +0 -146
  109. package/dist/chunks/record-DY-lX9w1.js +0 -34
  110. package/dist/chunks/src-DPSpGNnT.js +0 -1164
  111. package/dist/client/client.d.ts +0 -129
  112. package/dist/client/client.js +0 -321
  113. package/dist/tooling/vite.d.ts +0 -3
  114. package/dist/tooling/vite.js +0 -44
  115. package/skills/maximus/references/adding-an-operation.md +0 -179
  116. package/skills/maximus/references/building-a-service.md +0 -167
  117. package/skills/maximus/references/migration-from-v2.md +0 -62
  118. package/skills/maximus/references/migration-to-v5.md +0 -37
  119. package/skills/maximus/references/publishing-and-verification.md +0 -39
  120. package/templates/project/cloudflare.config.ts.template +0 -24
  121. package/templates/project/routes/v1/greeting.ts.template +0 -22
  122. package/templates/project/src/app.ts.template +0 -2
  123. package/templates/project/src/application.ts.template +0 -26
  124. package/templates/project/src/index.ts.template +0 -3
  125. package/templates/project/src/worker.ts.template +0 -6
  126. package/templates/service/.agents/skills/project/SKILL.md.template +0 -10
  127. package/templates/service/.github/workflows/ci.yml.template +0 -21
  128. package/templates/service/.gitignore.template +0 -9
  129. package/templates/service/CLAUDE.md.template +0 -5
  130. package/templates/service/README.md.template +0 -45
  131. package/templates/service/cloudflare.config.ts.template +0 -30
  132. package/templates/service/package.json.template +0 -36
  133. package/templates/service/src/app.ts.template +0 -30
  134. package/templates/service/src/index.ts.template +0 -13
  135. package/templates/service/tests/contract.test.ts.template +0 -12
  136. package/templates/service/tsconfig.json.template +0 -16
  137. package/templates/service/vite.config.ts.template +0 -13
  138. package/templates/service/vitest.config.ts.template +0 -10
@@ -1,4 +1,4 @@
1
- import { En as Result, Fn as Failure } from "./chunks/types-BWxDd3tY.js";
1
+ import { Qn as Result, ur as Failure } from "./chunks/types-BQYB4Ads.js";
2
2
  /** Why a webhook signature was refused: absent, malformed, outside the time tolerance, or not matching. */
3
3
  export declare const WEBHOOK_SIGNATURE_FAILURES: readonly ['missing', 'malformed', 'expired', 'mismatch'];
4
4
  /** Why a webhook signature was refused. */
@@ -23,8 +23,9 @@ export declare const DEFAULT_TOLERANCE_SECONDS = 300;
23
23
  */
24
24
  export declare const MAX_SIGNATURES = 8;
25
25
  /**
26
- * Verify an HMAC-SHA256 of the raw body. `signature` is the header value,
27
- * optionally with a scheme prefix such as `sha256=` (removed with `prefix`).
26
+ * Verifies an HMAC-SHA256 of the raw body. `signature` is the header value, hex or base64 as `encoding`
27
+ * says, optionally with a scheme prefix such as `sha256=` (removed with `prefix`). An absent signature fails
28
+ * as `missing`, one that does not decode as `malformed`, and one that does not match as `mismatch`.
28
29
  */
29
30
  export declare function verifyHmacSignature(options: {
30
31
  body: string | Uint8Array;
@@ -34,9 +35,10 @@ export declare function verifyHmacSignature(options: {
34
35
  signature: string | null | undefined;
35
36
  }): Promise<Result<null, WebhookSignatureFailure>>;
36
37
  /**
37
- * Verify a `t=<unix seconds>,v0=<hex>` header (several `v0`/`v1` values may be
38
- * present during secret rotation, up to {@link MAX_SIGNATURES}; one match is
39
- * enough) signing `<t>.<body>`.
38
+ * Verifies a `t=<unix seconds>,<label>=<hex>` header, an HMAC-SHA256 of `<t>.<body>`. Every hex signature
39
+ * under one of `labels` is tried, up to {@link MAX_SIGNATURES} (a provider rotating its secret sends several;
40
+ * one match is enough), and the timestamp must be within `toleranceSeconds` (300 by default) of `now`, in
41
+ * milliseconds, in either direction. Answers the signed timestamp.
40
42
  */
41
43
  export declare function verifyTimestampedSignature(options: {
42
44
  body: string | Uint8Array;
@@ -50,10 +52,10 @@ export declare function verifyTimestampedSignature(options: {
50
52
  timestamp: number;
51
53
  }, WebhookSignatureFailure>>;
52
54
  /**
53
- * Verify a Standard Webhooks delivery. The secret is the provider's
54
- * `whsec_<base64>` value (the prefix is optional), and the signature header may
55
- * list up to {@link MAX_SIGNATURES} signatures. Returns the message id, the
56
- * idempotency key of the delivery, and its timestamp.
55
+ * Verifies a Standard Webhooks delivery. The secret is the provider's `whsec_<base64>` value (the prefix is
56
+ * optional), the signature header may list up to {@link MAX_SIGNATURES} `v1` signatures, and the timestamp
57
+ * must be within `toleranceSeconds` (300 by default) of `now`, in either direction. Answers the message id,
58
+ * which is the delivery's idempotency key, and its timestamp.
57
59
  */
58
60
  export declare function verifyStandardWebhook(options: {
59
61
  body: string | Uint8Array;
package/dist/webhooks.js CHANGED
@@ -60,6 +60,14 @@ function fromBase64(value) {
60
60
  return null;
61
61
  }
62
62
  }
63
+ /**
64
+ * The secret a verifier was given. A missing or empty one is a configuration error, such as a secret binding
65
+ * the deployment lacks, never a refusal: anyone could sign with it, so no verifier runs without one.
66
+ */
67
+ function requireSecret(secret) {
68
+ if (typeof secret !== "string" && !(secret instanceof Uint8Array) || secret.length === 0) throw new TypeError("A webhook secret is required; check the binding that holds it.");
69
+ return secret;
70
+ }
63
71
  /** An HMAC-SHA256 key that can only verify. */
64
72
  async function hmacKey(secret) {
65
73
  return await crypto.subtle.importKey("raw", secret, {
@@ -77,25 +85,29 @@ const failure = (reason) => ({
77
85
  error: webhookSignatureFailure(reason)
78
86
  });
79
87
  /**
80
- * Verify an HMAC-SHA256 of the raw body. `signature` is the header value,
81
- * optionally with a scheme prefix such as `sha256=` (removed with `prefix`).
88
+ * Verifies an HMAC-SHA256 of the raw body. `signature` is the header value, hex or base64 as `encoding`
89
+ * says, optionally with a scheme prefix such as `sha256=` (removed with `prefix`). An absent signature fails
90
+ * as `missing`, one that does not decode as `malformed`, and one that does not match as `mismatch`.
82
91
  */
83
92
  async function verifyHmacSignature(options) {
93
+ const secret = requireSecret(options.secret);
84
94
  if (!options.signature) return failure("missing");
85
95
  const value = options.prefix && options.signature.startsWith(options.prefix) ? options.signature.slice(options.prefix.length) : options.signature;
86
96
  const signature = options.encoding === "hex" ? fromHex(value.trim()) : fromBase64(value.trim());
87
97
  if (!signature) return failure("malformed");
88
- return await crypto.subtle.verify("HMAC", await hmacKey(bytes(options.secret)), signature, bytes(options.body)) ? {
98
+ return await crypto.subtle.verify("HMAC", await hmacKey(bytes(secret)), signature, bytes(options.body)) ? {
89
99
  ok: true,
90
100
  value: null
91
101
  } : failure("mismatch");
92
102
  }
93
103
  /**
94
- * Verify a `t=<unix seconds>,v0=<hex>` header (several `v0`/`v1` values may be
95
- * present during secret rotation, up to {@link MAX_SIGNATURES}; one match is
96
- * enough) signing `<t>.<body>`.
104
+ * Verifies a `t=<unix seconds>,<label>=<hex>` header, an HMAC-SHA256 of `<t>.<body>`. Every hex signature
105
+ * under one of `labels` is tried, up to {@link MAX_SIGNATURES} (a provider rotating its secret sends several;
106
+ * one match is enough), and the timestamp must be within `toleranceSeconds` (300 by default) of `now`, in
107
+ * milliseconds, in either direction. Answers the signed timestamp.
97
108
  */
98
109
  async function verifyTimestampedSignature(options) {
110
+ const secret = requireSecret(options.secret);
99
111
  if (!options.header) return failure("missing");
100
112
  let timestamp = null;
101
113
  const signatures = [];
@@ -113,7 +125,7 @@ async function verifyTimestampedSignature(options) {
113
125
  if (timestamp === null || signatures.length === 0 || signatures.length > 8) return failure("malformed");
114
126
  const now = options.now?.() ?? Date.now();
115
127
  if (!withinTolerance(timestamp, options.toleranceSeconds ?? 300, now)) return failure("expired");
116
- const key = await hmacKey(bytes(options.secret));
128
+ const key = await hmacKey(bytes(secret));
117
129
  const message = concat(encoder.encode(`${timestamp}.`), bytes(options.body));
118
130
  for (const signature of signatures) if (await crypto.subtle.verify("HMAC", key, signature, message)) return {
119
131
  ok: true,
@@ -122,12 +134,14 @@ async function verifyTimestampedSignature(options) {
122
134
  return failure("mismatch");
123
135
  }
124
136
  /**
125
- * Verify a Standard Webhooks delivery. The secret is the provider's
126
- * `whsec_<base64>` value (the prefix is optional), and the signature header may
127
- * list up to {@link MAX_SIGNATURES} signatures. Returns the message id, the
128
- * idempotency key of the delivery, and its timestamp.
137
+ * Verifies a Standard Webhooks delivery. The secret is the provider's `whsec_<base64>` value (the prefix is
138
+ * optional), the signature header may list up to {@link MAX_SIGNATURES} `v1` signatures, and the timestamp
139
+ * must be within `toleranceSeconds` (300 by default) of `now`, in either direction. Answers the message id,
140
+ * which is the delivery's idempotency key, and its timestamp.
129
141
  */
130
142
  async function verifyStandardWebhook(options) {
143
+ const given = requireSecret(options.secret);
144
+ const encoded = requireSecret(given.startsWith("whsec_") ? given.slice(6) : given);
131
145
  /** A Standard Webhooks header, or its `svix-` spelling. */
132
146
  const header = (name) => options.headers.get(`webhook-${name}`) ?? options.headers.get(`svix-${name}`);
133
147
  const id = header("id");
@@ -138,7 +152,7 @@ async function verifyStandardWebhook(options) {
138
152
  const timestamp = Number(timestampValue);
139
153
  const now = options.now?.() ?? Date.now();
140
154
  if (!withinTolerance(timestamp, options.toleranceSeconds ?? 300, now)) return failure("expired");
141
- const secret = fromBase64(options.secret.startsWith("whsec_") ? options.secret.slice(6) : options.secret);
155
+ const secret = fromBase64(encoded);
142
156
  if (!secret) return failure("malformed");
143
157
  const signatures = signatureValue.split(" ").flatMap((entry) => {
144
158
  const [version, value] = entry.split(",", 2);
@@ -1,2 +1,2 @@
1
- import { a as credentials, i as createWorker, n as WorkerOptions, o as WorkerAssetsOptions, r as WorkerRuntime, t as RpcMethods } from "../chunks/types-BWxDd3tY.js";
1
+ import { a as credentials, i as createWorker, n as WorkerOptions, o as WorkerAssetsOptions, r as WorkerRuntime, t as RpcMethods } from "../chunks/workers-types-iONp32T4.js";
2
2
  export { RpcMethods, type WorkerAssetsOptions, WorkerOptions, WorkerRuntime, createWorker, credentials };
@@ -1,3 +1,3 @@
1
- import { n as credentials, t as createWorker } from "../chunks/runtime-BPnaa-NK.js";
1
+ import { n as credentials, t as createWorker } from "../chunks/runtime-CVVf5hmp.js";
2
2
 
3
3
  export { createWorker, credentials };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arbol-ai/maximus",
3
- "version": "7.3.1",
4
- "description": "Maximus: define a service once and serve it over HTTP, MCP and Worker RPC on Cloudflare Workers, with its OpenAPI, typed client and CLI.",
3
+ "version": "8.0.0",
4
+ "description": "Maximus: define a service once and serve it over HTTP, MCP and Worker RPC on Cloudflare Workers, configured in vite.config.ts, with its OpenAPI and CLI.",
5
5
  "keywords": [
6
6
  "api",
7
7
  "cloudflare",
@@ -12,7 +12,10 @@
12
12
  "multi-tenant",
13
13
  "openapi",
14
14
  "rpc",
15
- "typebox"
15
+ "typebox",
16
+ "vite",
17
+ "vite-plugin",
18
+ "vite-plus"
16
19
  ],
17
20
  "homepage": "https://github.com/getarbol/maximus#readme",
18
21
  "bugs": {
@@ -26,9 +29,10 @@
26
29
  "directory": "packages/maximus"
27
30
  },
28
31
  "bin": {
29
- "maximus": "dist/tooling/cli.js"
32
+ "maximus": "bin/maximus.js"
30
33
  },
31
34
  "files": [
35
+ "bin",
32
36
  "dist",
33
37
  "config",
34
38
  "templates",
@@ -87,10 +91,6 @@
87
91
  "types": "./dist/mcp/index.d.ts",
88
92
  "import": "./dist/mcp/index.js"
89
93
  },
90
- "./client": {
91
- "types": "./dist/client/client.d.ts",
92
- "import": "./dist/client/client.js"
93
- },
94
94
  "./analytics": {
95
95
  "types": "./dist/analytics/analytics.d.ts",
96
96
  "import": "./dist/analytics/analytics.js"
@@ -116,43 +116,51 @@
116
116
  "import": "./dist/project/index.js"
117
117
  },
118
118
  "./vite": {
119
- "types": "./dist/tooling/vite.d.ts",
120
- "import": "./dist/tooling/vite.js"
119
+ "types": "./dist/vite/index.d.ts",
120
+ "import": "./dist/vite/index.js"
121
+ },
122
+ "./config": {
123
+ "types": "./dist/project/config.d.ts",
124
+ "import": "./dist/project/config.js"
121
125
  }
122
126
  },
123
127
  "publishConfig": {
124
128
  "access": "public",
125
129
  "registry": "https://registry.npmjs.org/"
126
130
  },
127
- "scripts": {
128
- "typecheck": "tsc --noEmit",
129
- "build": "vp pack",
130
- "test": "vp test run --exclude \"**/*.integration.test.ts\"",
131
- "test:integration": "vp test run --config vitest.integration.config.ts"
132
- },
133
131
  "dependencies": {
134
- "@modelcontextprotocol/server": "2.3.1",
132
+ "@modelcontextprotocol/server": "2.4.0",
135
133
  "@sinclair/typebox": "0.34.52",
136
134
  "ajv-formats": "3.0.1",
137
- "jose": "6.2.12",
138
- "yaml": "2.9.1"
135
+ "jose": "6.2.13"
139
136
  },
140
137
  "devDependencies": {
138
+ "@cloudflare/vite-plugin": "2.0.0-beta.v.5",
141
139
  "@types/pg": "8.23.1",
142
140
  "ajv": "8.20.0",
143
- "miniflare": "5.20261012.1-beta",
141
+ "cf": "1.0.0-beta.23",
142
+ "miniflare": "5.20261023.0-beta",
144
143
  "pg": "8.23.1",
145
144
  "vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
146
- "vite-plus": "1.4.0"
145
+ "vite-plus": "1.4.0",
146
+ "yaml": "2.9.1"
147
147
  },
148
148
  "peerDependencies": {
149
+ "@cloudflare/vite-plugin": ">=2.0.0-beta.v.5",
150
+ "cf": ">=1.0.0-beta.23",
149
151
  "oxfmt": ">=0.71.0 <1",
150
152
  "oxlint": "^1.86.0",
151
153
  "pg": "^8.23.1",
152
- "ultracite": "^8.0.0",
154
+ "ultracite": "^8.1.0",
153
155
  "vite": "^8.3.4"
154
156
  },
155
157
  "peerDependenciesMeta": {
158
+ "@cloudflare/vite-plugin": {
159
+ "optional": true
160
+ },
161
+ "cf": {
162
+ "optional": true
163
+ },
156
164
  "oxfmt": {
157
165
  "optional": true
158
166
  },
@@ -1,89 +1,185 @@
1
1
  ---
2
2
  name: maximus
3
- description: Build, extend, test, migrate and release services with the Maximus framework (@arbol-ai/maximus*), which declares schema-first, organization-scoped operations once and serves them over HTTP/OpenAPI, MCP and Cloudflare Worker RPC. Use when code imports @arbol-ai/maximus or a task involves Maximus operations, scopes, error catalogs, derive/use middleware, MCP tools, RPC entrypoints, OpenAPI documents or the maximus CLI.
3
+ description: Build, extend, test, upgrade and deploy services with the Maximus framework (@arbol-ai/maximus, whose /vite entry configures a project), organization-scoped APIs on Cloudflare Workers whose route files declare each contract once and are served over HTTP with OpenAPI, as MCP tools and over Worker RPC. Use when a project configures maximus() in vite.config.ts or imports @arbol-ai/maximus, or a task involves Maximus routes, MCP tools, scopes, error catalogs, context.ts, middleware, bindings, Worker RPC, OpenAPI, tests, the maximus CLI or deploying with cf.
4
4
  ---
5
5
 
6
6
  # Maximus
7
7
 
8
- Maximus services declare each operation once (schemas, scope, effect, exposure, handler) on one
9
- fluent application. Each transport admits the caller its own way, then every call runs the same
10
- pipeline: input decoding, preparation, middleware, handler, output validation. Work with that
11
- pipeline, never around it.
8
+ A Maximus service is a project. `vite.config.ts` configures it with `maximus()` from `@arbol-ai/maximus/vite`,
9
+ and its files declare the rest. A route file declares one operation, its handler and its contract; Maximus
10
+ serves it over HTTP with an OpenAPI document, as an MCP tool when the contract names one, and over native
11
+ RPC when the contract says so. Each transport admits its caller (an access token holding the operation's
12
+ scope, or a Service Binding the service trusts), then every call runs one pipeline: input decoding,
13
+ `context.ts`, middleware, the handler, the output check. Work with that pipeline, never around it.
14
+
15
+ ## The project
16
+
17
+ ```text
18
+ vite.config.ts maximus(): origin, tokens.issuer, env (bindings), compatibilityDate, Worker settings
19
+ routes/v1/notes/[noteId].get.ts GET /api/v1/notes/{noteId}: export default defineHandler(handler, contract)
20
+ mcp/tools/summarize-notes.ts The MCP tool summarize_notes: export default defineTool(handler, contract)
21
+ mcp/instructions.md What MCP clients read when they connect; mcp/guides/ and mcp/skills/ too
22
+ context.ts export default defineContext(({ env, principal }) => ({ … }))
23
+ errors.ts export default defineErrors({ … }): the service's own failure codes
24
+ auth.ts export default defineAuth({ resolve }): tokens the service verifies itself
25
+ telemetry.ts export default defineTelemetry({ observers }): observers such as analytics()
26
+ middleware/ defineMiddleware (before admission) or defineOperationMiddleware (after it)
27
+ pages/ crons/ queues/ email/ Public pages and webhooks (pages/webhooks/x.post.ts), event handlers
28
+ durable-objects/ Durable Object classes, one per file
29
+ src/ Domain code: schemas, stores, clients of other services
30
+ tests/ vp test suites that call handler from #maximus/http in Node
31
+ .maximus/ Generated by maximus prepare: never edit it, never commit it
32
+ ```
33
+
34
+ Every file but `vite.config.ts` is optional. [references/project.md](references/project.md) describes
35
+ each one.
12
36
 
13
37
  ## Workflow
14
38
 
15
- 1. **Read the service first.** Find `maximus<Env>(…)` (usually `src/application.ts`), the resource
16
- modules (`src/api/<resource>/operations.ts`), the composition (`src/app.ts`) and the Worker
17
- (`src/index.ts`). Keep the project's existing folders and named domain functions.
18
- 2. **Declare, don't wire.** Add an operation to its resource module with strict schemas, a namespaced
19
- scope, a truthful effect and only the transports it needs (`http`, `mcp`, `rpc`). Mount new
20
- modules in `app.ts`. See `references/adding-an-operation.md`.
21
- 3. **Return Results.** Expected failures are `err(catalog.x.create())` from the application's own
22
- catalog; throw only for the unexpected. See `references/errors-and-results.md`.
23
- 4. **Prepare context with `.derive()`** in the group that needs it, and wrap with `.use()` only for
24
- cross-cutting behavior after authorization.
25
- 5. **Verify** with the project's typecheck, lint and tests, then `cf build` and a dry-run deploy
26
- (`cf deploy --prebuilt --mode production --dry-run`). See `references/testing.md` and
27
- `references/publishing-and-verification.md`.
39
+ 1. **Read before you write.** Read `vite.config.ts`, `errors.ts`, `context.ts`, the route closest to the
40
+ task and its tests. Keep the project's folders and its named domain functions.
41
+ 2. **Generate, then fill in.** `bunx maximus gen route <method> <path>` writes a route file, a tool too with
42
+ `--tool <snake_name>`; `bunx maximus gen tool <kebab-name>` writes a tool only agents call. Replace the
43
+ placeholder handler and description, and declare strict `input` and `output` schemas and the
44
+ `failures`. Declare `scope`, `effect` or `operationId` only where the derived one is wrong. See
45
+ [references/routes-and-tools.md](references/routes-and-tools.md).
46
+ 3. **Write it to be read.** A handler is a few statements that call named functions of `src/`, imported as
47
+ `#src/<module>.ts`; names are whole English words. See
48
+ [references/writing-code.md](references/writing-code.md).
49
+ 4. **Scope by organization in the context.** What every handler needs, such as a store, belongs in
50
+ `context.ts`, built from `principal.organizationId`.
51
+ 5. **Answer failures from the catalog.** `fail(code)` with a code of `errors.ts`, listed in the route's
52
+ `failures`; throw only for what should never happen. See
53
+ [references/errors-and-results.md](references/errors-and-results.md).
54
+ 6. **Declare bindings in `maximus()`.** `env: { NOTES: bindings.kv() }`, with `bindings` from `cf/config`,
55
+ and another Worker's RPC methods in `services`; the generated `Env` types them.
56
+ 7. **Test** each route in `tests/` through `handler` from `#maximus/http`: its answer, its refusals and that
57
+ one organization never reaches another's data. See [references/testing.md](references/testing.md).
58
+ 8. **Verify** with `bun run verify` before you finish.
59
+
60
+ ## Commands
61
+
62
+ | Command | Does |
63
+ | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
64
+ | `bun run dev` | `vp dev`: the Worker in workerd at `http://localhost:5173`. The development token in `.dev.vars` signs in from localhost. |
65
+ | `bunx maximus gen route get /v1/notes/{noteId} --tool get_note` | Writes `routes/v1/notes/[noteId].get.ts`, which is also the MCP tool `get_note`. |
66
+ | `bunx maximus gen tool summarize-notes` | Writes `mcp/tools/summarize-notes.ts`, the tool `summarize_notes`. |
67
+ | `bunx maximus prepare` | Writes `.maximus/` for production, or with `--mode development` as `vp dev` does. `vp dev`, `vp build` and `vp test` prepare by themselves. |
68
+ | `bunx maximus openapi` | Writes `openapi.json`, and `openapi.rpc.json` when a route declares `rpc`; `--check` fails when they differ from the routes. |
69
+ | `bun run test` | `vp test run`: the tests, in Node. |
70
+ | `bun run typecheck` | `maximus prepare`, then `tsc`, which also checks type tests. |
71
+ | `bun run check`, `bun run fix` | Lint and format; with fixes. |
72
+ | `bun run verify` | Types, lint and format, tests and the build. CI runs it. |
73
+ | `bun run deploy` | `bun run verify`, then `cf deploy --prebuilt --mode production`. |
74
+ | `bunx maximus skills` | Links this skill into the project's `.agents/skills`, `.claude/skills` and `.codex/skills`. |
75
+
76
+ Every `maximus` command says what it did in a sentence; `--json` prints it as JSON instead.
28
77
 
29
78
  ## Decisions
30
79
 
31
- | Question | Choose |
32
- | --- | --- |
33
- | Who calls it? People or external services over the network | `http` (and `mcp` for agents) with OAuth tokens |
34
- | Another Worker in the same account, trusted deployment | `rpc` with `rpc.callers`; see `references/transports.md` |
35
- | Documents that list only the failures it can answer | `failures` (its domain codes); any other becomes `INTERNAL_ERROR`; see `references/adding-an-operation.md` |
36
- | A gateway in front of the service, forwarding each caller's own token | Nothing special: list its audience in `tokens.audience` after the service's own; it calls the origin's own routes |
37
- | Staff operations hidden from documents and clients | `visibility: 'internal'`: still routed and decided by scope on the origin |
38
- | Verifying a provider webhook | `@arbol-ai/maximus/webhooks` on the raw body, in a plain route |
39
- | Callers without bearer tokens (webhooks, signed links) | A plain route that verifies its own signature |
40
- | Tokens that are not organization-bound OAuth access tokens | `tokens.resolve`, verifying cryptographically |
41
- | SDKs or a catalog generated from the contract | The origin's `/openapi.json`, or `createOpenApi(app)` at build time; see `references/transports.md` |
42
- | A new service from scratch | `references/building-a-service.md`; `maximus init --layout project` adds optional file conventions |
43
- | Upgrading from 4.x | `references/migration-to-v5.md` |
44
- | Upgrading from 2.x | `references/migration-from-v2.md` |
80
+ | Need | Choose |
81
+ | ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
82
+ | An endpoint for people and services | A route file. Every route is served over HTTP. |
83
+ | The same endpoint for agents | `mcp: { name: 'get_note' }` in its contract, which then needs a `description`. |
84
+ | A capability only agents call | A file of `mcp/tools/` with `defineTool`, which needs a `description` and an `effect`. |
85
+ | Another Worker of the account calls it | `rpc: true` in its contract and the caller's name in `rpc.callers`; commit the `openapi.rpc.json` that `bunx maximus openapi` writes. See [references/transports.md](references/transports.md). |
86
+ | Call another Worker of the account | `services: { PRICING: { worker: 'example-pricing', openapi: '../pricing/openapi.rpc.json' } }` in `maximus()`; import its types from `#maximus/services/pricing`. |
87
+ | Out of the public OpenAPI document | `visibility: 'internal'`: still routed, still checked against its scope. |
88
+ | Setup every call needs: stores, clients | `context.ts`. |
89
+ | A rule for every operation, on every transport | `defineOperationMiddleware` in `middleware/`. |
90
+ | Headers or an early answer around every request | `defineMiddleware` in `middleware/`. It runs before admission and sees no principal. |
91
+ | Access tokens Auth0 issues | `tokens: auth0({ domain, audience })` from `@arbol-ai/maximus/vite`, with RBAC and permissions in the access token turned on. See [references/project.md](references/project.md#tokens). |
92
+ | An application behind Cloudflare Access | `tokens: cloudflareAccess({ team, aud, organizationId, scopes })` from `@arbol-ai/maximus/vite`. It serves no MCP and no OAuth discovery. See [references/project.md](references/project.md#tokens). |
93
+ | Tokens your authorization server does not issue | `auth.ts` with `defineAuth({ resolve })`, which verifies cryptographically. |
94
+ | A provider's webhook, without a token | A page named for its method, `pages/webhooks/<provider>.post.ts`, which verifies the signature on the exact bytes with `@arbol-ai/maximus/webhooks`. See [references/project.md](references/project.md). |
95
+ | Many items in one answer | `output: Page(Item, { $id: 'ItemPage' })` with `input: PageQueryFields`. |
96
+ | A file upload or download | `http: { body: 'bytes' }` with `body.read()`; `output: AttachmentOutputSchema` with `http: { response: 'attachment' }`. |
97
+ | Data in Postgres | `withTenantTransaction` from `@arbol-ai/maximus/postgres`. |
98
+ | Guidance agents read over MCP | `mcp/instructions.md`, `mcp/guides/<name>.md`, `mcp/skills/<name>.md`: static text for every caller, never tenant data. |
99
+ | A 7.x service | [Upgrading to 8.0](https://github.com/getarbol/maximus/blob/main/docs/upgrading-to-8.md). |
45
100
 
46
101
  ## Rules that are never broken
47
102
 
48
- - **Tenancy:** every tenant query uses `context.principal.organizationId`. Never take an
49
- organization from input, a header or a path.
50
- - **Strict schemas:** inputs and outputs are `t.Object({...}, { additionalProperties: false })` or
51
- unions of such objects; a GET input is one object, each field read from the query string as its
52
- kind (integer, number, boolean, comma-separated string list, otherwise string).
53
- - **Validation ownership:** the framework validates operation input and output once. Do not re-parse
54
- inputs in handlers or helpers; do validate provider responses, stored records and model output with
55
- `checkSchema`/`readSchema`. No casts, trust flags or no-op validators.
56
- - **Codecs need `inputSchema()`:** an input using `normalizeSchema`, `refineSchema`,
57
- `transformSchema`, `inspectSchema`, `pipeSchema` or `stripObject` must be wrapped in
58
- `inputSchema(...)`; `.build()` refuses it otherwise, because a plain decode would skip the codecs.
59
- - **Authorization is scopes plus your checks:** effects, `visibility: 'internal'`, descriptions and
60
- MCP annotations never authorize. Ordinary RPC checks no scopes.
61
- - **Failures are honest:** an outage is a failure, never an empty success. A write whose outcome is
62
- lost answers `OUTCOME_UNKNOWN` and is reconciled, never retried blindly.
63
- - **Outbound calls:** in a Worker, `fetch(..., { redirect: 'error' })` throws before any request
64
- (only `follow` and `manual` exist). Send credentials with `redirect: 'manual'` and refuse a `3xx`.
65
- - **Privacy:** never log or return request bodies, credentials or submitted values in failure
66
- `data`, refinement messages, MCP skills or examples. Skills and guides hold no tenant data.
67
- - **Collections are pages:** an operation that returns many items answers `Page(Item, { $id })` with
68
- `PageQueryFields`; one that reads, creates or updates an item answers the named entity (the list's
69
- item); a delete answers `DeletedObjectSchema`. Use the shared schemas (`UuidSchema`,
70
- `EmailAddressSchema`, …) instead of local copies.
71
- - **Construction errors are guidance:** `.build()` throws a `TypeError` stating the rule (usually with
72
- the operation's name); fix the definition rather than loosening checks.
103
+ - **The organization comes from the principal.** Every store, key, query and Durable Object name starts from
104
+ `principal.organizationId`. Never take an organization from input, a header or a path.
105
+ - **Schemas are strict.** Inputs and outputs are strict objects or unions of strict objects: fields given as
106
+ `input: { … }` make one; a `t.Object` needs `{ additionalProperties: false }`. A shared entity has a
107
+ PascalCase `$id`. Use the shared schemas (`UuidSchema`, `EmailAddressSchema`, …) rather than copies.
108
+ - **Each value is checked once, where it enters.** Maximus checks an operation's input and output; a handler
109
+ never parses its input again. Data from outside the pipeline, such as a stored record, a provider's
110
+ answer or a model's output, goes through `readSchema` or `checkSchema`. No casts, trust flags or no-op
111
+ validators in their place.
112
+ - **Failures are declared and honest.** Answer `fail(code)` with a code of `errors.ts`, listed in
113
+ `failures`; the standard failures need no listing. An outage is a failure, never an empty success. A
114
+ write whose outcome is lost answers `OUTCOME_UNKNOWN` and is reconciled, never retried blindly.
115
+ - **Exposure is explicit.** A route is a tool only with `mcp` and an RPC method only with `rpc`. Effects,
116
+ `visibility`, descriptions and MCP hints never authorize: scopes and your own checks do.
117
+ - **No private data in logs or errors.** Request bodies, input values, credentials, tokens, personal or
118
+ clinical data never go in a log line, a failure's `data` or message, a refinement message, an MCP guide or
119
+ skill, or an example. Report a caught error with `reportUnexpected(error, surface)`, which keeps its name
120
+ and drops its message.
121
+ - **Worker code reads `env`, never `process.env`.** A secret is `bindings.secret()`. The development token is
122
+ never declared in `env` and never set on a deployed Worker.
123
+ - **Outbound calls:** a Worker's `fetch(…, { redirect: 'error' })` throws before it sends anything. Send with
124
+ `redirect: 'manual'` and refuse a `3xx`.
125
+ - **Generated code stays generated.** Never edit `.maximus/`: change the source files or `vite.config.ts`.
126
+ - **Refusals are guidance.** `maximus prepare`, `maximus()` and the application's `.build()` refuse a broken
127
+ project with a message that names the rule and the file or operation. Fix the declaration; never loosen
128
+ the check.
73
129
 
74
130
  ## References
75
131
 
76
- Load the one that matches the task:
132
+ Load the one the task needs:
133
+
134
+ - [references/project.md](references/project.md): `vite.config.ts`, tokens from Auth0 or Cloudflare Access,
135
+ the root modules, bindings and `Env`, the development token, what `prepare` generates, pages, background
136
+ work, Durable Objects and web apps.
137
+ - [references/routes-and-tools.md](references/routes-and-tools.md): file names and what they derive, every
138
+ contract field, input, schemas and codecs, lists, byte bodies, tools, context and middleware.
139
+ - [references/errors-and-results.md](references/errors-and-results.md): the catalog, `fail`, declared
140
+ failures, the standard failures, uncertain outcomes and other services' failures.
141
+ - [references/transports.md](references/transports.md): HTTP and OpenAPI, MCP, Worker RPC, and Workers
142
+ composed by hand.
143
+ - [references/testing.md](references/testing.md): tests in Node, stand-ins for bindings, MCP, RPC documents
144
+ and bindings, the contract check and suites against a running Worker.
145
+ - [references/deploying.md](references/deploying.md): the origin and the issuer, secrets, resources,
146
+ `bun run deploy`, the CI workflow and checking a deployment.
147
+ - [references/writing-code.md](references/writing-code.md): the house style for every file you write:
148
+ handlers as statements, `#src/` imports, names, comments, failures and tests.
149
+
150
+ ## Documentation
151
+
152
+ The documentation is in the Maximus repository, indexed by
153
+ [docs/README.md](https://github.com/getarbol/maximus/blob/main/docs/README.md):
77
154
 
78
- - `references/building-a-service.md`: project layout, configuration, tokens, Worker, local run.
79
- - `references/adding-an-operation.md`: every definition field, routes, schemas, codecs, middleware.
80
- - `references/transports.md`: HTTP and OpenAPI, MCP, native RPC, plain routes and Worker composition.
81
- - `references/errors-and-results.md`: catalogs, standard failures, presentation, uncertain outcomes.
82
- - `references/testing.md`: handler tests, the `verify` seam, MCP, `executeOperation`, RPC types.
83
- - `references/migration-to-v5.md`: what 5.0 removed and what to change.
84
- - `references/migration-from-v2.md`: 3.0.0 breaking changes and classifying older services.
85
- - `references/publishing-and-verification.md`: `maximus init`, deploying, verifying a deployment and
86
- releasing Maximus itself.
155
+ - [Getting started](https://github.com/getarbol/maximus/blob/main/docs/getting-started.md) and
156
+ [Concepts](https://github.com/getarbol/maximus/blob/main/docs/concepts.md).
157
+ - Build the API: [Write code people and agents read easily](https://github.com/getarbol/maximus/blob/main/docs/guides/writing-code.md),
158
+ [Project structure](https://github.com/getarbol/maximus/blob/main/docs/guides/project-structure.md),
159
+ [Routes](https://github.com/getarbol/maximus/blob/main/docs/guides/routes.md),
160
+ [Schemas and validation](https://github.com/getarbol/maximus/blob/main/docs/guides/schemas-and-validation.md),
161
+ [Errors and results](https://github.com/getarbol/maximus/blob/main/docs/guides/errors-and-results.md),
162
+ [Authentication and scopes](https://github.com/getarbol/maximus/blob/main/docs/guides/authentication-and-scopes.md),
163
+ [Context and middleware](https://github.com/getarbol/maximus/blob/main/docs/guides/middleware-and-context.md).
164
+ - Reach it: [MCP](https://github.com/getarbol/maximus/blob/main/docs/guides/mcp.md),
165
+ [Worker RPC](https://github.com/getarbol/maximus/blob/main/docs/guides/worker-rpc.md),
166
+ [Web apps](https://github.com/getarbol/maximus/blob/main/docs/guides/web-apps.md),
167
+ [Worker composition](https://github.com/getarbol/maximus/blob/main/docs/guides/worker-composition.md).
168
+ - Use the platform: [Bindings](https://github.com/getarbol/maximus/blob/main/docs/guides/bindings.md),
169
+ [Background work](https://github.com/getarbol/maximus/blob/main/docs/guides/background-work.md),
170
+ [Durable Objects](https://github.com/getarbol/maximus/blob/main/docs/guides/durable-objects.md),
171
+ [Postgres transactions](https://github.com/getarbol/maximus/blob/main/docs/guides/postgres.md).
172
+ - Ship it: [Testing](https://github.com/getarbol/maximus/blob/main/docs/guides/testing.md),
173
+ [Observability](https://github.com/getarbol/maximus/blob/main/docs/guides/observability.md),
174
+ [Deploying](https://github.com/getarbol/maximus/blob/main/docs/guides/deploying.md),
175
+ [Lint and format](https://github.com/getarbol/maximus/blob/main/docs/guides/lint-and-format.md).
176
+ - Reference: [Configuration](https://github.com/getarbol/maximus/blob/main/docs/reference/configuration.md),
177
+ [Route and operation options](https://github.com/getarbol/maximus/blob/main/docs/reference/operations.md),
178
+ [CLI](https://github.com/getarbol/maximus/blob/main/docs/reference/cli.md),
179
+ [Wire formats](https://github.com/getarbol/maximus/blob/main/docs/reference/wire-formats.md),
180
+ [Standard failures](https://github.com/getarbol/maximus/blob/main/docs/reference/standard-failures.md),
181
+ [Package exports](https://github.com/getarbol/maximus/blob/main/docs/reference/exports.md).
182
+ - Design: [Architecture](https://github.com/getarbol/maximus/blob/main/docs/architecture.md).
87
183
 
88
- The full documentation is in the Maximus repository under `docs/`; this skill ships in
89
- `@arbol-ai/maximus` at `skills/maximus/`.
184
+ This skill ships in `@arbol-ai/maximus`, at `skills/maximus/`; a project links the copy of the release it
185
+ installed.