@arbol-ai/maximus 7.3.1 → 7.4.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 (55) hide show
  1. package/dist/analytics/analytics.d.ts +1 -1
  2. package/dist/body.d.ts +1 -1
  3. package/dist/chunks/builder-BiXv7d2v.js +100 -0
  4. package/dist/chunks/{execution-B-yy4C7N.js → define-app-DvD_1jUE.js} +5 -71
  5. package/dist/chunks/errors-D7zG9kx9.js +126 -0
  6. package/dist/chunks/execution-kVUJPy1A.js +71 -0
  7. package/dist/chunks/http-paths-yKD6TSNJ.js +199 -0
  8. package/dist/chunks/prepare-project-CMyGSEtI.js +236 -0
  9. package/dist/chunks/prepare-project-MtS0-W_n.js +3 -0
  10. package/dist/chunks/{runtime-BPnaa-NK.js → runtime-DlqA7J38.js} +4 -3
  11. package/dist/chunks/{src-DPSpGNnT.js → src-N3oyx5QF.js} +31 -104
  12. package/dist/chunks/standard-failures-CLjxS2ea.js +74 -0
  13. package/dist/chunks/{types-BWxDd3tY.d.ts → types-DQdfRF3f.d.ts} +13 -4
  14. package/dist/client/client.d.ts +1 -1
  15. package/dist/client/client.js +2 -2
  16. package/dist/diagnostics.d.ts +1 -1
  17. package/dist/errors.d.ts +1 -1
  18. package/dist/errors.js +1 -124
  19. package/dist/http-paths.d.ts +1 -1
  20. package/dist/http-paths.js +1 -197
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.js +5 -4
  23. package/dist/internals.d.ts +1 -1
  24. package/dist/internals.js +3 -2
  25. package/dist/mcp/index.d.ts +1 -1
  26. package/dist/mcp/index.js +3 -3
  27. package/dist/project/config.d.ts +101 -0
  28. package/dist/project/config.js +80 -0
  29. package/dist/project/index.d.ts +1 -1
  30. package/dist/project/index.js +3 -3
  31. package/dist/schemas.d.ts +1 -1
  32. package/dist/standard-failures.js +1 -72
  33. package/dist/tooling/cli.js +10 -10
  34. package/dist/tooling/vite.d.ts +1 -1
  35. package/dist/tooling/vite.js +38 -25
  36. package/dist/webhooks.d.ts +1 -1
  37. package/dist/workers/runtime.d.ts +1 -1
  38. package/dist/workers/runtime.js +1 -1
  39. package/package.json +5 -1
  40. package/skills/maximus/SKILL.md +4 -5
  41. package/skills/maximus/references/building-a-service.md +8 -8
  42. package/skills/maximus/references/publishing-and-verification.md +14 -11
  43. package/templates/project/.agents/skills/project/SKILL.md.template +7 -7
  44. package/templates/project/CLAUDE.md.template +10 -7
  45. package/templates/project/README.md.template +8 -7
  46. package/templates/project/cloudflare.config.ts.template +1 -1
  47. package/templates/project/{src/application.ts.template → maximus.config.ts.template} +4 -10
  48. package/templates/project/middleware/10-response.ts.template +13 -0
  49. package/templates/project/package.json.template +4 -0
  50. package/templates/project/routes/v1/greeting.ts.template +33 -17
  51. package/templates/project/tsconfig.json.template +1 -0
  52. package/dist/chunks/prepare-project-zi106pWF.js +0 -146
  53. package/templates/project/src/app.ts.template +0 -2
  54. package/templates/project/src/index.ts.template +0 -3
  55. package/templates/project/src/worker.ts.template +0 -6
@@ -1,74 +1,3 @@
1
- // src/standard-failures.ts
2
- /** The framework's own failures, by the name `standardErrors` gives each. */
3
- const STANDARD_FAILURES = {
4
- invalidInput: {
5
- code: "INVALID_INPUT",
6
- status: 400,
7
- message: "The request does not match the published schema."
8
- },
9
- unauthorized: {
10
- code: "UNAUTHORIZED",
11
- status: 401,
12
- message: "A valid access token is required."
13
- },
14
- forbidden: {
15
- code: "FORBIDDEN",
16
- status: 403,
17
- message: "The token does not authorize this operation."
18
- },
19
- notFound: {
20
- code: "NOT_FOUND",
21
- status: 404,
22
- message: "The requested operation does not exist."
23
- },
24
- methodNotAllowed: {
25
- code: "HTTP_METHOD_NOT_ALLOWED",
26
- status: 405,
27
- message: "The HTTP method is not supported for this resource."
28
- },
29
- tooLarge: {
30
- code: "REQUEST_TOO_LARGE",
31
- status: 413,
32
- message: "The request exceeds the allowed size."
33
- },
34
- unsupportedMedia: {
35
- code: "UNSUPPORTED_MEDIA_TYPE",
36
- status: 415,
37
- message: "The request content type is not supported."
38
- },
39
- rateLimited: {
40
- code: "RATE_LIMITED",
41
- status: 429,
42
- message: "The request rate limit was exceeded. Try again later.",
43
- retryable: true,
44
- retryAfter: 60
45
- },
46
- internal: {
47
- code: "INTERNAL_ERROR",
48
- status: 500,
49
- message: "The service could not complete the operation."
50
- },
51
- upstreamUnavailable: {
52
- code: "UPSTREAM_UNAVAILABLE",
53
- status: 503,
54
- message: "The upstream service could not complete the request.",
55
- retryable: true
56
- },
57
- upstreamTimeout: {
58
- code: "UPSTREAM_TIMEOUT",
59
- status: 504,
60
- message: "The upstream service did not respond before its deadline.",
61
- retryable: true
62
- },
63
- /**
64
- * A write may have been applied and its answer was lost. Never retried: the caller reconciles (reads
65
- * the resource or polls the operation) before deciding to repeat anything.
66
- */
67
- outcomeUnknown: {
68
- code: "OUTCOME_UNKNOWN",
69
- status: 502,
70
- message: "The operation may have been applied; check its result before repeating it."
71
- }
72
- };
1
+ import { t as STANDARD_FAILURES } from "./chunks/standard-failures-CLjxS2ea.js";
73
2
 
74
3
  export { STANDARD_FAILURES };
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { t as prepareProject } from "../chunks/prepare-project-zi106pWF.js";
3
- import { dirname, join, relative, resolve } from "node:path";
4
2
  import { existsSync, mkdirSync, readFileSync, readdirSync, symlinkSync, writeFileSync } from "node:fs";
3
+ import { dirname, join, relative, resolve } from "node:path";
5
4
  import { parseArgs } from "node:util";
6
5
  import { randomBytes } from "node:crypto";
7
6
 
@@ -45,7 +44,7 @@ function scaffold(directory, name, layout = "service") {
45
44
  })) {
46
45
  if (!file.isFile() || !file.name.endsWith(".template")) continue;
47
46
  const source = resolve(file.parentPath, file.name);
48
- if (layout === "project" && templateName === "service" && (relative(template, source).startsWith("tests/") || file.name === "vitest.config.ts.template")) continue;
47
+ if (layout === "project" && templateName === "service" && (relative(template, source).startsWith("tests/") || relative(template, source).startsWith("src/") || file.name === "vitest.config.ts.template")) continue;
49
48
  const target = resolve(root, relative(template, source).replace(/\.template$/, ""));
50
49
  mkdirSync(dirname(target), { recursive: true });
51
50
  let text = readFileSync(source, "utf-8");
@@ -65,14 +64,14 @@ function scaffold(directory, name, layout = "service") {
65
64
  return {
66
65
  directory: root,
67
66
  layout,
68
- next: layout === "project" ? "Run bun install and bun run dev. The public home page says Hello World. Configure the origin and token policy in src/application.ts before adding production callers. Use bun run verify for types, lint and build, then bun run deploy." : "Run bun install and bun run dev, and call it with the DEVELOPMENT_TOKEN in .dev.vars. Before the first deployment, set origin, audience and issuer in src/app.ts, run bun run verify, sign in with cf auth login and run bun run deploy."
67
+ next: layout === "project" ? "Run bun install and bun run dev. The public home page says Hello World. Configure the origin and token policy in maximus.config.ts before adding production callers. Use bun run verify for types, lint and build, then bun run deploy." : "Run bun install and bun run dev, and call it with the DEVELOPMENT_TOKEN in .dev.vars. Before the first deployment, set origin, audience and issuer in src/app.ts, run bun run verify, sign in with cf auth login and run bun run deploy."
69
68
  };
70
69
  }
71
70
 
72
71
  // src/tooling/cli.ts
73
72
  /**
74
- * The `maximus` command: `init` creates a new service. Developing, building and deploying it are `cf`'s own
75
- * commands, which Maximus does not wrap.
73
+ * The `maximus` command scaffolds services and reconciles project entries. Vite+ owns development and
74
+ * builds; Cloudflare owns type generation and deployment.
76
75
  */
77
76
  const { values, positionals } = parseArgs({
78
77
  allowPositionals: true,
@@ -97,16 +96,17 @@ const [command, target] = positionals;
97
96
  const USAGE = [
98
97
  "Usage: maximus init <new-directory> --name <name> [--layout service|project]",
99
98
  " maximus prepare [directory] [--mode production|development]",
100
- "Creates a new service. Develop, build and deploy it with cf: cf dev, cf build, cf workers types and",
101
- "cf deploy."
99
+ "Creates a Vite+ service. Use its dev, build, verify and deploy package scripts.",
100
+ "Project layout generates entries from maximus.config.ts, routes/ and middleware/."
102
101
  ].join("\n");
103
102
  if (values.help) {
104
103
  console.info(USAGE);
105
104
  process.exit(0);
106
105
  }
107
106
  /** Runs the command the arguments name. */
108
- function run() {
107
+ async function run() {
109
108
  if (command === "prepare") {
109
+ const { prepareProject } = await import("../chunks/prepare-project-MtS0-W_n.js");
110
110
  console.info(JSON.stringify(prepareProject(target ?? ".", values.mode)));
111
111
  return;
112
112
  }
@@ -120,7 +120,7 @@ function run() {
120
120
  console.info(JSON.stringify(scaffold(target, values.name, values.layout)));
121
121
  }
122
122
  try {
123
- run();
123
+ await run();
124
124
  } catch (error) {
125
125
  console.error(error instanceof Error && !process.env.MAXIMUS_DEBUG ? `maximus: ${error.message}` : error);
126
126
  process.exitCode = 1;
@@ -1,3 +1,3 @@
1
1
  import { Plugin } from "vite";
2
- /** Prepare on startup/build and refresh discovery when convention files are added or removed. */
2
+ /** Prepare before every build and before Vite invalidates source modules during development. */
3
3
  export declare function maximusProject(): Plugin;
@@ -1,42 +1,55 @@
1
- import { n as PROJECT_DIRECTORIES, t as prepareProject } from "../chunks/prepare-project-zi106pWF.js";
1
+ import { n as PROJECT_DIRECTORIES, t as prepareProject } from "../chunks/prepare-project-CMyGSEtI.js";
2
+ import { existsSync } from "node:fs";
2
3
  import { relative, resolve } from "node:path";
3
4
 
4
5
  // src/tooling/vite.ts
5
- /** Optional Vite integration. It generates static imports before Cloudflare reads the Worker. */
6
- /** Prepare on startup/build and refresh discovery when convention files are added or removed. */
6
+ /** Optional Vite integration. It reconciles static imports before Cloudflare reads the Worker. */
7
+ /** Prepare before every build and before Vite invalidates source modules during development. */
7
8
  function maximusProject() {
8
9
  let root = process.cwd();
9
10
  let mode = "production";
11
+ let previous;
12
+ const reconcile = () => {
13
+ const current = prepareProject(root, mode);
14
+ const restart = previous !== void 0 && (previous.config !== current.config || previous.durableObjects.join("\n") !== current.durableObjects.join("\n"));
15
+ previous = current;
16
+ return {
17
+ ...current,
18
+ restart
19
+ };
20
+ };
21
+ const isProjectFile = (file) => {
22
+ const path = relative(root, file).split(/[\\/]/);
23
+ return PROJECT_DIRECTORIES.some((name) => name === path[0]) || path.length === 1 && /^maximus\.config\.(?:ts|mts|js|mjs)$/.test(path[0] ?? "") || path[0] === "src" && ["application.ts", "worker.ts"].includes(path[1] ?? "");
24
+ };
10
25
  return {
11
26
  name: "maximus-project",
12
27
  enforce: "pre",
13
28
  config(config, environment) {
14
29
  root = resolve(config.root ?? root);
15
30
  ({mode} = environment);
16
- prepareProject(root, mode);
31
+ reconcile();
32
+ },
33
+ buildStart() {
34
+ const current = reconcile();
35
+ for (const file of current.files) this.addWatchFile(file);
36
+ if (current.config) this.addWatchFile(resolve(root, current.config));
37
+ for (const directory of PROJECT_DIRECTORIES) {
38
+ const path = resolve(root, directory);
39
+ if (existsSync(path)) this.addWatchFile(path);
40
+ }
17
41
  },
18
- configureServer(server) {
19
- const update = (file) => {
20
- const [directory] = relative(root, file).split(/[\\/]/);
21
- if (!PROJECT_DIRECTORIES.some((name) => name === directory)) return;
22
- try {
23
- prepareProject(root, mode);
24
- server.ws.send({ type: "full-reload" });
25
- } catch (error) {
26
- server.config.logger.error(error instanceof Error ? error.message : String(error));
27
- server.ws.send({
28
- type: "error",
29
- err: {
30
- message: error instanceof Error ? error.message : String(error),
31
- stack: ""
32
- }
33
- });
42
+ hotUpdate: {
43
+ order: "pre",
44
+ async handler({ file, server }) {
45
+ if (!isProjectFile(file)) return;
46
+ const current = reconcile();
47
+ if (current.restart) {
48
+ await server.restart();
49
+ return [];
34
50
  }
35
- };
36
- server.watcher.on("add", update).on("unlink", update);
37
- server.httpServer?.once("close", () => {
38
- server.watcher.off("add", update).off("unlink", update);
39
- });
51
+ if (current.changed) this.environment.hot.send({ type: "full-reload" });
52
+ }
40
53
  }
41
54
  };
42
55
  }
@@ -1,4 +1,4 @@
1
- import { En as Result, Fn as Failure } from "./chunks/types-BWxDd3tY.js";
1
+ import { Rn as Failure, kn as Result } from "./chunks/types-DQdfRF3f.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. */
@@ -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/types-DQdfRF3f.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-DlqA7J38.js";
2
2
 
3
3
  export { createWorker, credentials };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arbol-ai/maximus",
3
- "version": "7.3.1",
3
+ "version": "7.4.0",
4
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.",
5
5
  "keywords": [
6
6
  "api",
@@ -118,6 +118,10 @@
118
118
  "./vite": {
119
119
  "types": "./dist/tooling/vite.d.ts",
120
120
  "import": "./dist/tooling/vite.js"
121
+ },
122
+ "./config": {
123
+ "types": "./dist/project/config.d.ts",
124
+ "import": "./dist/project/config.js"
121
125
  }
122
126
  },
123
127
  "publishConfig": {
@@ -12,18 +12,17 @@ pipeline, never around it.
12
12
 
13
13
  ## Workflow
14
14
 
15
- 1. **Read the service first.** Find `maximus<Env>(…)` (usually `src/application.ts`), the resource
15
+ 1. **Read the service first.** For a project layout, start with `maximus.config.ts` and the project-structure guide; `src/` is optional and routes/middleware are discovered. For explicit composition, find `maximus<Env>(…)` (usually `src/application.ts`), the resource
16
16
  modules (`src/api/<resource>/operations.ts`), the composition (`src/app.ts`) and the Worker
17
17
  (`src/index.ts`). Keep the project's existing folders and named domain functions.
18
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`.
19
+ scope, a truthful effect and only the transports it needs (`http`, `mcp`, `rpc`). Project routes are discovered; explicit service layouts mount modules in `app.ts`. See `references/adding-an-operation.md`.
21
20
  3. **Return Results.** Expected failures are `err(catalog.x.create())` from the application's own
22
21
  catalog; throw only for the unexpected. See `references/errors-and-results.md`.
23
22
  4. **Prepare context with `.derive()`** in the group that needs it, and wrap with `.use()` only for
24
23
  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
24
+ 5. **Verify** with the project's typecheck, lint and Vite+ build, then a dry-run deploy. Run tests only on an explicit human request. Use
25
+ `cf deploy --prebuilt --mode production --dry-run`. See `references/testing.md` and
27
26
  `references/publishing-and-verification.md`.
28
27
 
29
28
  ## Decisions
@@ -1,13 +1,13 @@
1
1
  # Building a service
2
2
 
3
- For optional file conventions, use `maximus init <directory> --name <name> --layout project`.
4
- `routes/` factories receive their versioned file path and return builders derived from
5
- `src/application.ts`; `pages/` returns public native Responses. Middleware runs after authorization.
6
- Cron, queue, email and Durable Object modules are discovered into ignored `.maximus/` imports by
7
- `maximus prepare` and `maximusProject()` from `@arbol-ai/maximus/vite`. Configure infrastructure
8
- explicitly in `cloudflare.config.ts`. Read `docs/guides/project-structure.md` in the Maximus repository
9
- for conventions and boundaries. The generated project uses non-test validation and automatic
10
- deployment on main; production API authentication initially refuses every token.
3
+ For the API-first project layout, use `maximus init <directory> --name <name> --layout project`.
4
+ Configure the application in `maximus.config.ts`; `src/` is optional domain code. Routes export
5
+ `GET`, `POST`, `PUT`, `PATCH` or `DELETE` through `defineRoute` from the generated `#maximus/routes` alias.
6
+ `defineMiddleware` (also named `defineRequestMiddleware`) wraps HTTP requests; `defineOperationMiddleware` runs after native admission on
7
+ HTTP, MCP and RPC. Middleware files run in filename order. The Vite+ plugin reconciles entries on
8
+ builds and source changes. Configure infrastructure explicitly in `cloudflare.config.ts`, importing
9
+ `.maximus/entry.ts` as its entrypoint. Legacy route factories and explicit service composition below
10
+ remain supported. Read `docs/guides/project-structure.md` for configuration, migration and conventions.
11
11
 
12
12
  ## Packages
13
13
 
@@ -2,10 +2,11 @@
2
2
 
3
3
  ## A new service (`@arbol-ai/maximus`)
4
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.
5
+ Run `bunx @arbol-ai/maximus init <dir> --name <name> --layout project` for a Vite+ project on the CLI's
6
+ own release. Configure its origin and token policy in `maximus.config.ts`. The compatible service
7
+ layout is still available and keeps `src/app.ts`. Use the generated package scripts: Vite+ owns
8
+ development, builds and checks; Cloudflare owns types and deployment. Maximus prepares the source
9
+ graph before Vite loads the generated Worker.
9
10
 
10
11
  `createOpenApi(app)` builds the document the origin serves at `/openapi.json`, for SDKs or a contract
11
12
  check at build time. Nothing is published from the service: deploying it is the release.
@@ -13,15 +14,15 @@ check at build time. Nothing is published from the service: deploying it is the
13
14
  ## Before deploying
14
15
 
15
16
  ```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
17
+ bun run verify # preparation, types, lint/format and build; no tests
18
+ # Read .cloudflare/output/v0/workers/default/worker.config.json: no development token.
19
+ cf deploy --prebuilt --mode production --dry-run
19
20
  cf deploy --prebuilt --mode production # --dry-run first; cf auth login or CLOUDFLARE_API_TOKEN
20
21
  ```
21
22
 
22
23
  `nodejs_compat` on; secrets as `bindings.secret()`, uploaded with `cf deploy --secrets-file` or kept
23
24
  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
+ declared for development mode alone; Durable Object class names unchanged and declared as exports; preview
25
26
  environments use their own audience, state and credentials.
26
27
 
27
28
  ## After deploying
@@ -34,6 +35,8 @@ deployment.
34
35
 
35
36
  ## Releasing Maximus itself (framework repository)
36
37
 
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.
38
+ Run `bun run verify` for builds, workspace types, lint and format. Inspect a packed tarball and build
39
+ consumers from it; never publish `workspace:` or `file:` dependencies. After publication, install from
40
+ the registry, produce the consumer's dry bundle and verify the deployed service. Test suites and
41
+ package smoke tests are separate: run them only after an explicit human request. Neither release
42
+ authorization nor a successful build is evidence that tests were authorized or passed.
@@ -3,13 +3,13 @@ name: __PROJECT_NAME__-development
3
3
  description: Extend the __PROJECT_NAME__ Maximus backend using its optional file conventions.
4
4
  ---
5
5
 
6
- Read CLAUDE.md and the installed Maximus skill. Add authenticated route factories in routes/v1/;
7
- their default export receives the path and returns operations derived from src/application.ts's base.
8
- Declare strict input/output schemas, scope and effect. Use src/ for named domain functions.
9
- Pages return native Responses. Middleware modules default-export an OperationMiddleware<Invocation<Env>>.
10
- Crons export a cron expression and a default scheduled handler; queues and email export native handlers.
11
- Durable Object files default-export their class. Infrastructure declarations remain explicit in
12
- cloudflare.config.ts. Read the Maximus project-structure guide before adding another module kind.
6
+ Read CLAUDE.md and the installed Maximus skill. Configure the application in maximus.config.ts.
7
+ Add named GET/POST/PUT/PATCH/DELETE declarations to routes/v1/, importing defineRoute from #maximus/routes.
8
+ Declare strict input/output schemas, scope, effect and explicit MCP/RPC exposure. Use optional src/ for
9
+ named domain functions. Middleware is discovered in filename order: defineMiddleware wraps requests;
10
+ defineOperationMiddleware applies policy after authentication across transports. Keep principal-based
11
+ policy in the operation phase. Read the Maximus project-structure guide before adding another module kind.
12
+ Build reconciliation owns .maximus/; never edit generated entries. Cloud resources and SQL remain explicit.
13
13
  Run bun run verify for non-test validation. Tests require a human request.
14
14
 
15
15
  Vite+ owns the root toolchain: `vite.config.ts` configures lint/format, `vp check` checks them,
@@ -5,13 +5,16 @@ Read .agents/skills/project/SKILL.md and node_modules/@arbol-ai/maximus/skills/m
5
5
 
6
6
  ## Structure
7
7
 
8
- This is a Maximus project layout. The Vite plugin and `maximus prepare` generate `.maximus/` from
9
- optional directories. Never edit generated files. Routes are factories that receive their inferred
10
- versioned path and return a builder derived from `base` in src/application.ts. Pages return native
11
- Responses; public pages never contain tenant data. Middleware runs after authentication and scopes.
12
- Configure platform bindings, triggers and Durable Object migrations in cloudflare.config.ts.
13
- Keep domain logic in src/, schemas and migrations in db/, and uploaded files in public/ only after
14
- configuring an assets binding and explicit file admission. Never apply migrations implicitly.
8
+ This is an API-first Maximus project. Application and transport policy live in maximus.config.ts.
9
+ Routes export GET/POST/PUT/PATCH/DELETE declarations through defineRoute from #maximus/routes. Keep
10
+ operation names, schemas, scopes and effects explicit; MCP and RPC exposure use the same contracts.
11
+ The Vite plugin and maximus prepare reconcile generated .maximus/ entries before builds. Never edit them.
12
+ src/ is optional shared domain code. Root configuration never imports generated modules or routes.
13
+ Middleware files are ordered by name: defineMiddleware wraps HTTP before token admission and has no
14
+ principal; defineOperationMiddleware runs after native admission across HTTP, MCP and RPC. Middleware
15
+ imports configuration types only. Pages return native public Responses and never contain tenant data.
16
+ Bindings, triggers and Durable Object migrations belong in cloudflare.config.ts. Database migrations
17
+ and public asset admission remain explicit; adding files never provisions infrastructure.
15
18
 
16
19
  ## Boundaries
17
20
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  A Maximus backend on Cloudflare Workers, with Vite+ as its default toolchain. `GET /` returns **Hello World**, `/health` reports liveness,
4
4
  and `/api/openapi.json` describes the API. `GET /api/v1/greeting` is authenticated. The starter refuses
5
- production tokens until an identity provider or verified resolver is configured in src/application.ts.
5
+ production tokens until an identity provider or verified resolver is configured in maximus.config.ts.
6
6
 
7
7
  ## Development
8
8
 
@@ -17,27 +17,28 @@ uses optional directories. Add only the modules the service needs:
17
17
 
18
18
  | Directory | Convention |
19
19
  | ---------------- | ------------------------------------------------------------------------------------- |
20
- | routes/ | Versioned API route factories, automatically mounted with their file path. |
20
+ | routes/ | Versioned named GET/POST declarations; paths and methods are discovered. |
21
21
  | pages/ | Fixed-path public response handlers; index.ts serves `/`. |
22
- | middleware/ | Operation middleware, sorted by filename and run after authorization. |
22
+ | middleware/ | Ordered HTTP wrappers or post-admission operation policy. |
23
23
  | crons/ | A `cron` export and a default native scheduled handler. |
24
24
  | queues/ | Default queue handlers named after the physical queue. |
25
25
  | email/ | Default email handlers named after the full recipient; `_default.ts` is the fallback. |
26
26
  | durable-objects/ | Default classes re-exported in PascalCase from kebab-case filenames. |
27
27
  | db/ | Application-owned schemas and SQL migrations, applied explicitly. |
28
- | src/ | Shared domain code, application configuration and Worker options. |
28
+ | src/ | Optional shared domain code; application configuration lives at the root. |
29
29
  | public/ | Optional static assets; configure the binding and admitted files before using it. |
30
30
  | .maximus/ | Generated imports; ignored and never edited by hand. |
31
31
 
32
- The Vite plugin prepares the project before development/build and discovers added/removed modules
33
- during development. `bun run prepare:project` generates the same imports for editors. Files starting
32
+ The Vite plugin reconciles modules and named method exports on every build and source change.
33
+ Root maximus.config.ts owns application and transport policy; the Cloudflare config imports the
34
+ generated .maximus/entry.ts entry. No src/ directory or manual route registration is required. `bun run prepare:project` generates the same imports for editors. Files starting
34
35
  with `_` are ignored except `email/_default.ts`; `.dev.ts` and `.prod.ts` select their matching mode.
35
36
  Platform bindings, cron triggers, queue subscriptions, email routing and Durable Object migrations
36
37
  remain explicit Cloudflare configuration. Adding a handler never provisions infrastructure.
37
38
 
38
39
  ## Deployment
39
40
 
40
- Before deploying, replace the origin and audience in src/application.ts with the deployed HTTPS URL.
41
+ Before deploying, replace the origin and audience in maximus.config.ts with the deployed HTTPS URL.
41
42
  The GitHub workflow checks pull requests and deploys pushes to `main`. Configure repository or
42
43
  organization secrets `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID`. The token needs permission to
43
44
  deploy this Worker. `bun run deploy` performs the same non-test validation and deployment locally.
@@ -1,6 +1,6 @@
1
1
  import { bindings, defineConfig } from 'cf/config';
2
2
 
3
- import * as entrypoint from './src/index.ts' with { type: 'cf-worker' };
3
+ import * as entrypoint from './.maximus/entry.ts' with { type: 'cf-worker' };
4
4
 
5
5
  export default defineConfig(({ mode }) => ({
6
6
  worker: {
@@ -1,8 +1,7 @@
1
- import { defineErrors, err, maximus, standardErrors } from '@arbol-ai/maximus';
1
+ import { defineErrors, err, standardErrors } from '@arbol-ai/maximus';
2
+ import { defineConfig } from '@arbol-ai/maximus/config';
2
3
 
3
- import { middleware } from '../.maximus/middleware';
4
-
5
- let application = maximus<Env>({
4
+ export default defineConfig<Env>({
6
5
  name: '__PROJECT_NAME__',
7
6
  namespace: '__PROJECT_NAME__',
8
7
  title: '__PROJECT_NAME__',
@@ -17,10 +16,5 @@ let application = maximus<Env>({
17
16
  },
18
17
  errors: defineErrors({}),
19
18
  rpc: { callers: [] },
19
+ worker: { http: { basePath: '/api', healthPath: '/health' } },
20
20
  });
21
-
22
- /** All discovered operations share middleware that runs after native authentication and scope checks. */
23
- for (const handler of middleware) {
24
- application = application.use(handler);
25
- }
26
- export const base = application;
@@ -0,0 +1,13 @@
1
+ import { defineMiddleware } from '@arbol-ai/maximus/config';
2
+
3
+ /** Global HTTP policy; protected operations still pass through native token and scope admission. */
4
+ export default defineMiddleware<Env>(async (_request, _env, _context, proceed) => {
5
+ const response = await proceed();
6
+ // Reconstructing a WebSocket upgrade would lose its attached socket.
7
+ if (response.status === 101) {
8
+ return response;
9
+ }
10
+ const headers = new Headers(response.headers);
11
+ headers.set('referrer-policy', 'no-referrer');
12
+ return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
13
+ });
@@ -3,7 +3,11 @@
3
3
  "version": "0.1.0",
4
4
  "private": true,
5
5
  "type": "module",
6
+ "imports": {
7
+ "#maximus/*": "./.maximus/*.ts"
8
+ },
6
9
  "scripts": {
10
+ "prepare": "maximus prepare",
7
11
  "prepare:project": "maximus prepare",
8
12
  "dev": "vp dev",
9
13
  "typecheck": "maximus prepare && cf workers types && tsc",
@@ -1,22 +1,38 @@
1
1
  import { EmptyInputSchema, ok, t } from '@arbol-ai/maximus';
2
2
 
3
- import { base } from '../../src/application';
3
+ import { defineRoute } from '#maximus/routes';
4
4
 
5
5
  const GreetingSchema = t.Object({ message: t.String() }, { $id: 'Greeting', additionalProperties: false });
6
6
 
7
- /** The filename supplies the versioned path; Maximus still owns admission and schema validation. */
8
- export default function greeting(path: string) {
9
- return base.operation(
10
- 'getGreeting',
11
- {
12
- title: 'Get a greeting',
13
- description: 'Return a greeting to an authenticated caller.',
14
- scope: '__PROJECT_NAME__:greeting:read',
15
- effect: 'read',
16
- http: { method: 'GET', path },
17
- input: EmptyInputSchema,
18
- output: GreetingSchema,
19
- },
20
- () => Promise.resolve(ok({ message: 'Hello World' }))
21
- );
22
- }
7
+ /** The filename supplies the path and this export supplies the method. */
8
+ export const GET = defineRoute(
9
+ 'getGreeting',
10
+ {
11
+ title: 'Get a greeting',
12
+ description: 'Return a greeting to an authenticated caller.',
13
+ scope: '__PROJECT_NAME__:greeting:read',
14
+ effect: 'read',
15
+ input: EmptyInputSchema,
16
+ output: GreetingSchema,
17
+ },
18
+ () => Promise.resolve(ok({ message: 'Hello World' }))
19
+ );
20
+
21
+ const EchoInputSchema = t.Object(
22
+ { message: t.String({ minLength: 1, maxLength: 200 }) },
23
+ { additionalProperties: false }
24
+ );
25
+
26
+ /** A POST can expose a read operation; its effect remains truthful because no state changes. */
27
+ export const POST = defineRoute(
28
+ 'echoGreeting',
29
+ {
30
+ title: 'Echo a greeting',
31
+ description: 'Return the authenticated caller’s greeting without storing it.',
32
+ scope: '__PROJECT_NAME__:greeting:read',
33
+ effect: 'read',
34
+ input: EchoInputSchema,
35
+ output: GreetingSchema,
36
+ },
37
+ (_context, input) => Promise.resolve(ok(input))
38
+ );
@@ -22,6 +22,7 @@
22
22
  "email",
23
23
  "durable-objects",
24
24
  "db",
25
+ "maximus.config.ts",
25
26
  "cloudflare.config.ts",
26
27
  "vite.config.ts",
27
28
  ".maximus",