# CLAUDE.md Guidance for any coding agent in this repository. `AGENTS.md` is a symlink to this file: one source. ## Ultimate A full-stack, **Bun-only**, opinionated web framework: Rails' philosophy on Bun + Postgres + SolidJS, where **the primary developer is an AI agent**. The promise: **reduce the number of problems the author has to worry about** — every decision the framework makes is one an agent does not have to. This repo is the framework: the `@ultimat3/*` packages, the `x` CLI, the docs, the wiki, three tracked apps — the reference app (`examples/dummy`), the deployed demo (`dummy/social-media-clone`) and the docs site (`dummy/docs-site`), each gated on its own `expectedRed` table. CLI binary `x`, npm scope `@ultimat3`, imports `@ultimat3/`. **Status:** released, every package in lockstep. Semver covers the primitive shapes, the `x` CLI, the tier table and the `X_*` codes; from v31 one major per 90 days (`X_RELEASE_MAJOR_WINDOW`), breaks wait on `next` (`X_BREAKING_ON_MAIN`): [`wiki/Stability.md`](wiki/Stability.md). **This page states no version number, on purpose.** Every fact below is a command. What each answer means: [`PUBLISHING.md`](PUBLISHING.md#facts-as-commands); history: [`publishing-and-provenance.md`](docs/history/publishing-and-provenance.md). | Fact | Read it yourself | |---|---| | the stamped version, per workspace | `bun run scripts/list-workspaces.ts --json` — `.data[].version` | | the whole repository is at one version | `bun run scripts/release.ts --check ` | | the workflow names every publishable workspace | `bun run scripts/release-workflow.ts --json` | | every one is on npm at that version, attested | `bun run scripts/registry-audit.ts --json` | | what npm serves | `npm view @ultimat3/core version` | | provenance on a release | `npm view @ultimat3/core@ dist.attestations _npmUser` | | the tag is **annotated** and on the remote | `git ls-remote --tags origin 'refs/tags/v*'` — `git tag -a` only | | the GitHub Release exists | `gh release view v --json tagName,isDraft,publishedAt` | | the OIDC trusted publisher is attached | `NPM_CONFIG_OTP= bun run scripts/trust-publishers.ts --check --json` | | the `v*` tag rule and no reviewers on `npm-publish` | `gh api repos/developerz-ai/ultimate/environments/npm-publish --jq '.protection_rules, .deployment_branch_policy'` · `gh api repos/developerz-ai/ultimate/environments/npm-publish/deployment-branch-policies` — by hand, an admin token | | which majors shipped, and what each breaks | `ls docs/changelog/` · [`wiki/Upgrading.md`](wiki/Upgrading.md) | ## Design axioms (override any instinct that conflicts) 1. **One way to do each thing.** Ambiguity is the tax agents pay. Never add a second path. 2. **Define once, project everywhere.** One `action` → HTTP + OpenAPI + typed client + job handle + MCP tool + tests. 3. **Enforced, not documented.** A convention that isn't a build error doesn't exist. 4. **Errors are instructions.** Stable code + cause + exact fix command + `--json`. 5. **One command means shippable.** `x verify` is the contract. 6. **Static path never pays for the app path.** Separate bundle graphs, hard boundaries. 7. **Deploy anywhere = containers only.** Zero platform primitives in the framework. 8. **Ultimate ships mechanism; your app ships convention.** Mechanisms and *structural* conventions ship — the same for a bank and a blog. *Business* conventions never do. Primitives are functions returning values, so an app encodes its own by wrapping one: no fork, no patch, no plugin API. [`docs/idea/19-mechanism-not-convention.md`](docs/idea/19-mechanism-not-convention.md). 9. **Useful, then efficient.** Working function first; bytes and milliseconds second. A route or island budget is a measurement, not a ceiling to game: when real function costs bytes, raise the budget by the measured amount, with the number and the reason in the same diff (`bun run budget-raises`, `X_BUDGET_RAISE_UNSTATED`). Never cut or stub a feature, or leave it `X_NOT_IMPLEMENTED`, to hold a figure. Bytes that buy no function are still a defect. Axiom 6 is not traded. ## Commands Run everything from the repo root. | Task | Command | |---|---| | install | `bun install` | | fresh clone to running | `bun run setup` — idempotent; safe to re-run after every pull | | **the gate** | `bun run verify` — `x verify` at the repo root, 21 steps: typecheck, lint, boundaries, filesize, package-shape, errors, unit, contract, live, job, exercise, e2e, eval, drift, contract-diff, budgets, seo, i18n, policy, manifest, roadmap. Green = shippable; list: `VERIFY_STEP_NAMES`, `packages/cli/src/verify-step.ts` | | typecheck | `bun run typecheck` (queues; one compiler per checkout) · start over: `bun run typecheck:clean` | | lint | `bun run lint` · fix: `bun run lint:fix` | | test (all) | `bun run test` — every framework suite, opt-in ones included | | test (one file) | `bun test ./packages/core/src/errors.test.ts` — **always `./`**: bare `packages/` is a substring filter, also running `examples/dummy/packages/` under the wrong config | | test services | `docker compose -f docker/docker-compose.test.yml up -d --wait`, then `set -a; . docker/test-services.env; set +a` — in RAM; unset, live suites skip | | test (one name) | `bun test ./packages/core/src/errors.test.ts -t ''` — **always with a path** (a bare `-t` loads every file) | | before reporting | `bun run preflight []` — cheap ratchets, touched units' coverage, serve-graph on a moved src file: one verdict | | coverage, per unit | `bun run coverage` — 30 packages, `create-ultimate` and `scripts/` · `bun run coverage:package ` | | **the app gate** | `bun run scripts/reference-app-gate.ts` — builds the three apps (`x build --target static`), then verifies. As of 2026-11 every `expectedRed` table (`scripts/lib/gated-apps.ts`) is empty: all steps pass. `--app ` gates one | | a new error code | `bun run new-error-code --package --title '…' --cause '…' --fix '…' (--status \| --off-socket) [--browser \| --server-only]` — registration + `wiki/Error-Codes-.md` row + HTTP status. Tier ≤ 4: one of pair 1, tier 5 none; realtime: one of pair 2. A script's code: `--script scripts/.ts`, no `--package` (never-ships list + row) | | new framework package | `bun run scripts/new-package.ts --tier ` | | regenerate manifest | `bun run manifest` | | both tracked apps' schema dumps | `bun run schema-dumps` regenerates `packages/db/schema/` in each · `--check` only reports | | stale `@ultimat3/*` ranges in `bun.lock` | `bun run lockfile` reports, `bun run lockfile:fix` edits | | the CLI, in-repo | `bun run x -- `; an app command takes `--cwd examples/dummy` (at the root: `X_NOT_IN_APP`) | | dev MCP server | `bun run x -- mcp serve --cwd examples/dummy` — routes, schema, policies, tests, logs, read-only SQL: ask it before grepping | | **every guard** | [`docs/architecture/guards.md`](docs/architecture/guards.md) — generated from each guard's header by `bun run scripts/guards-doc.ts --write`, drift refused by `--check` | ## Layout ``` packages/ the framework — one package per responsibility, tiered (see below) examples/dummy/ the reference app: every primitive, once, idiomatically dummy/social-media-clone/ the deployed demo app: production image built on every push to main dummy/docs-site/ the wiki as a static site docs/idea/ what and why — the design spec docs/architecture/ how it's built — internals docs/ops/ running an app for real — PaaS → Compose → K8s, secrets, observability, runbooks docs/history/ why things are the way they are — decision records moved out of this file docs/plans/ dated execution plans; status.yml per plan wiki/ the reference manual, the one documentation source (GitHub wiki + `dummy/docs-site`) scripts/ setup, verify, guards, manifest, release, bench docker/ Dockerfile + compose + helm llms.txt the machine-readable repo map framework.manifest.json GENERATED facts: every package, tier, X_* code and its file. `bun run manifest`; never hand-edited (X_MANIFEST_DRIFT) ``` ## Package tiers — imports may only go DOWN A package may import from strictly lower tiers. Never sideways within a tier, never upward. Enforced by `bun run boundaries`. [`scripts/lib/tiers.ts`](scripts/lib/tiers.ts) is the executable copy of this table, and they must agree. | Tier | Packages | |---|---| | 0 | `core`, `schema` | | 1 | `i18n`, `money`, `time`, `cache`, `seo`, `db`, `storage`, `flags` | | 2 | `entity`, `policy`, `http`, `auth` | | 3 | `action`, `query`, `jobs`, `realtime` | | 4 | `render`, `pwa`, `mcp`, `ai`, `manifest`, `mail`, `ui`, `notify`, `scraping` | | 5 | `admin`, `testing`, `cli` | Declared sideways edges, one line each ([record](docs/history/tier-decisions.md)): - `core → schema` — the reverse stays forbidden: `t` is in every bundle graph. - `realtime → query` — a live query is a query. - `cli → admin` — the dev dashboard is the admin package's. - `cli → testing` — already a runtime dependency of the CLI. - `create-ultimate → cli` — tier 6, and its only permitted import. The FLOOR is enforced too: a package above the tier its imports allow needs a `FLOOR_ABOVE` row saying what moving it down would legalise (`X_TIER_FLOOR_UNDECLARED` / `X_TIER_FLOOR_STALE`). Adding a package picks its tier first; one that fits no tier is a design to fix, never a wider table. ## The eight primitives `entity` · `policy` · `action` · `mutator` · `query` · `job` · `route` · `task` Everything in the framework is one of these. **A feature that fits none doesn't ship.** No ninth. Canonical shapes: [`docs/idea/02-primitives.md`](docs/idea/02-primitives.md). `PRIMITIVE_KINDS` in [`packages/core/src/registrar.ts`](packages/core/src/registrar.ts) is the executable list, pinned at eight by `registrar.test.ts`. A new capability arrives as a **factory over an existing primitive**, never a new kind of thing: `llm()` returns an `action`, `backfill()` returns a `job` ([`docs/history/primitive-factories.md`](docs/history/primitive-factories.md)). The factories are a list, never a count or ordinal: `PRIMITIVE_FACTORIES` in the same file, held complete by `scripts/primitive-factories.test.ts`. ## Non-negotiables - **Bun only.** No Node-specific APIs unless via `node:` and unavoidable, with a `why:` comment (`bun run node-imports`). - **No new dependencies** without a strong reason stated in the PR — the bar is [`docs/idea/18-build-vs-wrap.md`](docs/idea/18-build-vs-wrap.md). - **No `any`.** Biome fails the build. Use `unknown` + a schema parse. - **Never throw a bare `Error`.** Subclass `UltimateError` with a code, a cause, and an executable `fix:`. Codes are `X_SCREAMING_SNAKE` and stable forever once shipped. In tests too: `expect.unreachable` states a test's verdict (`scripts/test-bare-error.ts`); a `new Error` handed to the code under test is input, not a verdict. - **SRP.** One file, one job. Target < 200 LOC, hard ceiling ~500: split before it. - **Named exports only.** No default exports. `src/index.ts` re-exports the public API explicitly — no blind `export *`. - **`import type` / `export type`** for type-only imports (`verbatimModuleSyntax` is on). - **Tests next to source** as `.test.ts`. A test that can't fail isn't a test. - **`--json` on every CLI command and every error.** - **No hardcoded user-facing strings.** Everything through `t()`. - **No raw colours.** Semantic tokens only, in every component and stylesheet. - **No date formatted without an explicit IANA `timeZone`.** No ambient default, anywhere. - **No float money.** `Money = { readonly minor: number; readonly currency: string }`, always both — one declaration in `@ultimat3/schema`, never restated and never a `bigint`. ## Conventions - File names `kebab-case.ts`. Single quotes, semicolons, 2-space indent, 100 cols, trailing commas — Biome owns this. - A 1–4 line header comment per file stating its single responsibility. Comments explain **why**, never what. - Every package carries `README.md` (public API) + `CLAUDE.md` (boundary, deps, commands). This file stays ≤ 16 KB and a package's ≤ 24 KB or its pin (`bun run scripts/claude-md-size.ts`): history goes to `docs/history/`. - Route files: `page.tsx` on `site/`/`app/` — the directory is the URL. `registerRoute()` enforces it (`X_ROUTE_FILE_INVALID`). `api/` holds no route file: actions and queries via `defineApi()`. `site/` never imports `app/` (`X_BOUNDARY_SITE_TO_APP`). - i18n catalogs: one flat file per locale. An **app's** live at `packages/i18n/catalogs/.json` (`x i18n check` audits them); the **framework's own** is `packages/i18n/src/catalogs/en.json` (the `boundaries` step audits it, `X_CATALOG_KEY_UNREACHABLE`). - Docs style: lead with the rule, fragments over sentences, tables for any ≥3-row structure, no meta-framing, no trailing summary. Date load-bearing claims `As of 2026-07`. ## Where things live | Need | Go to | |---|---| | the design rationale | [`docs/idea/`](docs/idea/README.md) | | how a subsystem actually works | [`docs/architecture/`](docs/architecture/README.md) | | the coding contract in full | [`docs/architecture/00-conventions.md`](docs/architecture/00-conventions.md) | | **adding a feature, step by step** | [`docs/architecture/15-adding-a-feature.md`](docs/architecture/15-adding-a-feature.md) | | running an app in production | [`docs/ops/`](docs/ops/README.md) | | which rung of the scale ladder a claim belongs to | [`docs/idea/17-scale-ladder.md`](docs/idea/17-scale-ladder.md) | | every error code | [`wiki/Error-Codes.md`](wiki/Error-Codes.md) | | every CLI flag | [`wiki/CLI-Reference.md`](wiki/CLI-Reference.md) | | tables, with no ORM | `entity()` declares; `postgresDriver()` (`packages/entity/src/pg-driver.ts`) is hand-written SQL | | realtime capacity, as measured | [`scripts/bench/results/README.md`](scripts/bench/results/README.md) | | the deploy-proof milestone | [`docs/history/milestone-11.md`](docs/history/milestone-11.md) · [`docs/idea/14-roadmap.md`](docs/idea/14-roadmap.md) | ## CI Free runners only (public repo): `ubuntu-latest`, `windows-latest`, `macos-latest`. Under 5 min. One runner per unit ([why](docs/history/ci-split.md)); each job's question is the comment above it in `ci.yml`. `awk '/^jobs:/{j=1;next} j && /^ [a-z-]+:$/{print $1}' .github/workflows/ci.yml` re-derives the jobs. - `gate` — the gate in parts: `x verify --only ` per runner, `unit` sharded. Never a verdict, and never a lint/typecheck job beside it. - `verify` — the verdict: `x verify merge` over the parts, red for a step no part ran. - `scaffold-smoke` — a scaffolded app gates twice per shape (`demoapp`, `bareapp`); the second gate catches broken generators. - `windows` — native Windows in pwsh: lint, typecheck, a path-heavy unit subset, scaffold smoke. - `fault-drills` — `x drill` on the reference app: three faults, real Postgres. `ci.yml` runs on pushes to `main`, `next` and `release/*`. Other workflows (release, deploy, `workflow-lint.yml`'s zizmor, …) and their triggers: [`ci-split.md`](docs/history/ci-split.md#the-other-workflows). ## How to work Act as an independent, proactive senior engineer: do the full job. Don't ask what the code, the docs or a sensible default answers: decide, then state the decision. Finish the work: fix, test, document, run the gate. Find the root cause; fix what you find along the way. Ask only before an irreversible or outward-facing act the owner hasn't already asked for. ## Note No git worktrees in this checkout: a team of subagents shares it, on disjoint file sets. (Another repo the owner may be editing on a non-`main` checkout: work in a git worktree there.) **Many agents, one machine:** a worker runs its own files, the coordinator runs the gate once; heavy runs queue in one memory ledger (`x heavy status`, [guide](wiki/Many-Agents.md)). **Only the top-level agent spawns subagents.** A subagent works and reports back; it never delegates ([why](docs/history/feature-workflow.md)). Too large a scope is said in the report; widening the split is the top-level agent's call.