Add ADRs 0001-0013 from the plan's day-0 list
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by oscabriel · committed by oscabriel · parent a781c9e · Browse files · 13 files·+266 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
13 files+266 added−0 removed
- other:+266 added−0 removed
Provenance
- Commit
e100fdc- Tree
a8938d5- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
a781c9e
13 files changed+266 added−0 removed
added:docs/adr/0001-bun-workspaces-and-turborepo.md+18 added
123456789101112131415161718---status: accepted---
# Bun workspaces and Turborepo, not pnpm
The repo is a Bun workspace with a dependency catalog, and Turborepo runs its tasks. Bun is the maintainer's default, and `bun build --compile` turns the CLI into single binaries. Turborepo caches tasks and costs one file.
## Considered Options
- **pnpm.** The Effect team uses it, and Cloudflare's `cloudflare.config.ts` tooling does not support Bun. That second reason went away once Wrangler became the deploy tool (ADR 0002).- **Workspace scripts with no task runner.** Nothing would be cached, so every check reruns on every change.
## Consequences
We keep pnpm's supply-chain guarantees by configuration rather than by tool: `--frozen-lockfile` in CI and in acceptance runs, exact pins, a minimum release age, and `trustedDependencies` for install scripts.
Rat Stack, which we port from (ADR 0013), says not to replace pnpm with Bun. That rule is about cold installs of Rat Stack's own template. The guarantees it protects are the ones kept above.added:docs/adr/0002-wrangler-deploys-every-worker.md+49 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849---status: proposed---
# Wrangler deploys every Worker during the competition; `cf` is an ops CLI; after the deadline, cf or Alchemy
Until the competition closes on Oct 14, 2026, Wrangler deploys all three Workers (`platform`, `sandbox` and `web`). Cloudflare's `cf` CLI runs only read-mostly operations. After the deadline we move to cf or to Alchemy, whichever one's gate opens first. This departs from Cloudflare's own advice for new projects: "Prefer it over Wrangler … Wrangler is only for projects that already use it" ([cf launch post](https://blog.cloudflare.com/cloudflare-cf-cli-launch/)). We depart from it because neither alternative can yet declare what this platform deploys, and one deploy tool is safer in the recording week.
## Considered Options
- **Alchemy** (`2.0.0-beta.81`). - Released Alchemy cannot declare Durable Object-managed containers (`schedulingPolicy: "durable_object"`, which the Sandbox SDK 1.0 uses). Support is in open [PR #1905](https://github.com/alchemy-run/alchemy/pull/1905), so any Alchemy path today needs two tools. - Betas 79, 80 and 81 shipped on Sep 18, Oct 2 and Oct 5, and beta.80 had three breaking changes. - The Artifacts push trigger is not a reason either way. Whichever tool deploys, it is one REST call: `PUT /accounts/{account_id}/triggers/{script_name}` with a `cf.artifacts.repo.pushed` filter and a Workflow target.- **cf with `cloudflare.config.ts`** (cf `1.0.0-beta.12`, `@cloudflare/config` `0.23.0`). - The config's `Trigger` union has no events trigger, and `cf migrate` drops it: "Artifact event triggers are not supported by the new config and were not migrated." - cf hands container builds to Wrangler. - The config always writes `script_name` on a Durable Object binding, so the deploy refuses the sandbox's container DO bound from its own Worker: "You cannot configure a container on a Durable Object that is defined in another Worker." - Wrangler would still be needed for non-Vite bundling, `tail`, single secrets, the Workers vitest plugin and `varlock-wrangler`. - cf shipped beta.0 to beta.12 between Sep 25 and Oct 2, with open deploy bugs ([#192](https://github.com/cloudflare/cf/issues/192), #197, #72).
## Consequences
- `infra/bootstrap.ts` makes the events-trigger call idempotently and is the one place that checks it.- cf runs only as `bun run ops -- …`, pinned exactly, with telemetry off. A hook refuses its project commands (`dev`, `build`, `deploy`, `init`, `migrate`, `previews`), and any `delete` or `revoke` goes to the maintainer.- The README says in one line that Wrangler deploys the Workers and cf is the ops CLI, and why.
## After the deadline
**cf**, once `@cloudflare/config` gains an events trigger and the container `script_name` fix, or cf reaches GA:1. `cf migrate` each app.2. Write `exports` for the Durable Objects.3. Keep the trigger in `bootstrap.ts`.4. Remove the sandbox's self-bindings.5. Move web to `@cloudflare/vite-plugin@2`.6. Fence bindings with `InferEnv` over `defineWorker` references.7. Pass varlock values through `--secrets-file`.8. Set `DO_NOT_TRACK=1`.
Watch cf #179, #180, #192, #197, #198 and #204.
**Alchemy**, once #1905 merges (before then, the sandbox would deploy through `Command.Exec` running Wrangler):- **Async style:** plain `Cloudflare.Worker("X", { main, env })`, so Worker code stays tool-agnostic.- **The events trigger as an `Action`:** it GETs, diffs only the entries it owns, and PUTs only on a difference. An `Action` reruns only when its input changes, so the input carries a per-deploy revision. Destroy is `PUT []`.- **The binding fence:** `Cloudflare.InferEnv<typeof Platform>`, so deleting a binding is a type error.- **Config:** local state, telemetry off (`ALCHEMY_TELEMETRY_DISABLED=1`) and an exact pin.- **Frozen Durable Object names:** Alchemy deletes a removed Durable Object by default, so a rename is a delete and loses data. A test pins the class list.
Watch [#1950](https://github.com/alchemy-run/alchemy/pull/1950) (an events-trigger resource) and [#1916](https://github.com/alchemy-run/alchemy/pull/1916) (Artifacts reads).added:docs/adr/0003-rpcgroup-is-the-one-schema.md+29 added
1234567891011121314151617181920212223242526272829---status: accepted---
# An Effect `RpcGroup` is the one schema
`packages/protocol` defines every operation once, as an `Rpc` in an Effect `RpcGroup` with payload, success and error schemas plus annotations. Everything else is derived from it with `bun run gen`: server handlers, the web client, CLI commands, MCP tools, skills, JSON Schema and the refusal docs. We chose `RpcGroup` because:- the contract and handler split is native: the group is schemas only, and `group.toLayer(handlers)` implements it;- `stream` is native on `Rpc.make`, which serves the Project DO's live views;- `omit`, `merge` and `prefix` give each surface its own subset;- its annotations use the same keys Effect's MCP `Tool` reads.
## Considered Options
- **`HttpApi` → OpenAPI → Forge**, tried on Oct 6, 2026 and rejected for the window: 1. It loses streaming beyond SSE and loses refusal identity: refusals become per-status error classes, without a static `retryable`. 2. It has no MCP or skill target. 3. Its CLI generator is cf's own, and the commands it emits are bound to Cloudflare's auth. 4. Its SDK generator, Fern, rejects `_tag` discriminants when two or more tags share a status. 5. Nothing is on npm ([forge#6](https://github.com/cloudflare/forge/issues/6)). 6. It needs Docker and a 1.3 GB generator image.- **Rat Stack's `packages/capability` as the source**, with `RpcGroup` as one projection of it. It passes all 59 of its tests on our Effect pin, but it lacks native `stream` and subsets, and it would put borrowed code at the centre of the product. It is the fallback if the port below is not green by hour 2 of Oct 7.
## Consequences
- The CLI-flag and MCP-tool algorithms are ported from [Rat Stack](https://github.com/joelhooks/rat-stack) at `fba26d8` (MIT): `to-command.ts` l.20–207 and `to-toolkit.ts` l.59–94, about 220 lines, into `protocol/{cli,mcp}`. They are recorded in `PROVENANCE.md` (ADR 0013).- Wire schemas use `Schema.Int` or `Schema.Finite`, never bare `Schema.Number`, and `Schema.optionalKey`, never `Schema.optional`. Effect's `Schema.toJsonSchemaDocument`, which `McpServer` uses for tool schemas, turns `Schema.Number` into an `anyOf` that admits the strings `"Infinity"`, `"-Infinity"` and `"NaN"`, and turns `Schema.optional(Schema.String)` into string-or-`null`.- Every `effect/rpc` API is marked `@stability unstable`, so each package that uses one allows it explicitly in `allowedUnstableApis`.- A public REST SDK, if one is wanted later, comes from an `HttpApi` projection of the `RpcGroup`, not from a second source.added:docs/adr/0004-git-gateway-owns-custody.md+18 added
123456789101112131415161718---status: accepted---
# A git gateway owns custody, and refusals arrive in git's own output
Every git request goes through a gateway Worker that proxies git's smart HTTP protocol to Cloudflare Artifacts and holds every Artifacts token. Before it forwards a push, it reads the ref update commands and can refuse them with git's own `ng <ref> <reason>` lines, so a refusal shows up in the pusher's `git push` output with nothing installed. Holding custody in one place also gives us protected refs, claim-scoped tokens, anonymous public clones, push detection at the moment of the push, and reads limited by visibility (ADR 0007).
## Considered Options
- **Flag stray pushes afterwards and revert them.** This was the earlier design. It stays as a backstop: an Artifacts events trigger starts a Workflow for any push that reaches storage without passing the gateway.- **A client-side `git-remote-<name>` helper that rewrites push results.** It needs an install on every machine and is not authoritative, since a plain `git push` skips it. It is deferred, and it returns only if the gateway cannot be built.
## Consequences
- For an answer, the gateway forwards the push to the answerer's own fork, then rewrites git's report-status with the verdict of the cheap stages of the gate (ADR 0006).- A git credential helper ships so that tokens stay out of remote URLs.- If the gateway cannot be built, the fallback is raw per-fork tokens plus the push-event backstop, and the `git-remote-<name>` helper returns to put refusals in push output.added:docs/adr/0005-rules-read-from-the-landed-sha.md+12 added
123456789101112---status: accepted---
# Rules are read from the landed SHA stored in the Project DO; the ref is a mirror
The platform reads a project's rules only from the commit it last landed itself. That SHA lives in the Project Durable Object's row and is written in the same transaction as the landing record. The rules are the config folder, the judge closure and the env shape (ADR 0009). A landed ref in the repo mirrors the SHA for people and tools, and nothing reads it to make a decision. So neither an answer nor a stray push can change what judges it.
## Considered Options
- **Read rules from a landed ref pushed atomically with `main`.** This was the earlier design, and it made an atomic two-ref push a requirement of every landing. Artifacts' `readFile` accepts a commit ID as its `ref` ([Workers binding](https://developers.cloudflare.com/artifacts/api/workers-binding/)), so reading by SHA needs no second ref.- **Read rules from the tip of `main`.** A push that reached `main` outside the gateway would then rewrite the rules that judge the next push.added:docs/adr/0006-landing-is-a-parse.md+20 added
1234567891011121314151617181920---status: accepted---
# Landing is a parse: a cost-ordered gate and a closed refusal union
Every push is treated as unknown input. The gate runs its stages in order of cost (the claim, the territory, judge custody and weakening, the merge, the project's own commands, then held-back checks) and narrows the push either to a checked tree, which the platform lands, or to refusals. Refusals are a closed union of `Schema.TaggedError` classes, so people, agents and code can all branch on them.
## Considered Options
- **Free-text check failures**, as most CI reports them. A person can read them, but an agent or a script has to guess what went wrong and what to do next.- **One refusal per push.** An agent with three shape problems would need three pushes to learn about them.
## Consequences
- Each refusal carries a static `retryable`, a `next` command and an optional `at: {path, line}`. It carries no `message` field: Effect's MCP server renders a tool error as text only when its message is non-empty, so without one, MCP clients get the structured error.- Text for git `remote:` lines, the CLI and MCP comes from one renderer, `protocol/render`.- Stage-1 (shape) refusals accumulate, so one push gets every shape problem at once. Costly stages stop at the first failure. The `ng` line names the first tag; `remote:` lines, CLI JSON and MCP JSON list them all.- The union is a public contract. A `_tag` is renamed only with an alias.- `Flake` and `VerifierBlocked` never count against the answerer.added:docs/adr/0007-visibility-boundary-is-the-repo-boundary.md+18 added
123456789101112131415161718---status: accepted---
# The visibility boundary is the repo boundary
Git cannot hide part of a repo: whoever can fetch a commit can fetch every object in its tree. So each audience's files form a layer that lives in its own repo, and the platform composes layers over `main` only where the reader may see them. One flow rule holds: no write down. Content reaches a wider audience only through a credited release, and nothing from a layer enters a public tree.
## Considered Options
- **Private branches or folders in one repo.** Git's object reachability would leak them to anyone who can clone.- **Fully hidden project layers.** Every project layer is declared publicly instead. Only personal layers may be hidden, because invisible gates destroy contributors' trust.
## Consequences
- The platform lands the answer's tree, never the composed tree, and snapshots before held-back files are written.- Public-serving Workers have no binding to the private namespace. A type test checks that the web Worker's generated env has no `ARTIFACTS_PRIVATE`.- A push that would put a layer path into a public tree is refused as `PrivatePathInPublicTree`.added:docs/adr/0008-claims-are-exclusive-by-default.md+15 added
123456789101112131415---status: accepted---
# Claims are exclusive by default and kept alive by pushes
An ask takes one claim at a time. A claim is a fork plus a scoped token, and only pushes keep it alive: after 2 idle hours the claimant is warned, and after 24 the claim lapses (`ClaimLapsed`). A full ask returns `AskFull` before any fork is made. Racing is opt-in, for kinds where parallel attempts are the point, such as hill-climbing or design asks.
## Considered Options
- **Three claims per ask, shown as "2 of 3 taken".** Duplicate work wastes newcomers' effort, and asks open to racing get swarmed, as bounty markets do.
## Consequences
The front page shows an ask as either claimed or open.added:docs/adr/0009-env-shape-is-env-schema.md+19 added
1+---2+status: accepted3+---4+5+# The env shape is the project's `.env.schema`, parsed and never resolved6+7+A project's env shape is its committed `.env.schema`, in the [@env-spec](https://github.com/dmno-dev/varlock/discussions/17) format that varlock reads. The platform parses it at the landed SHA with `@env-spec/parser` and never resolves it: no `exec`, no plugins, and no imports from outside the repo. Function-valued flags count as sensitive. Values are stored only for `@sensitive` items, as write-only values, envelope-encrypted in the Project DO under a master key held as a Worker secret. Unlanded code sees a placeholder for every `@sensitive` item. For a `@proxy` item, the platform swaps the real value in on matching outbound HTTPS requests ([Sandbox outbound interception](https://developers.cloudflare.com/sandbox/network/call-an-authenticated-api/)).8+9+## Considered Options10+11+- **An `env.ts` in the config folder.** Only the platform would read it, while the app kept its own env loading, and the two shapes would drift. One file now serves the app, local tools, agents and the platform.12+- **Cloudflare Secrets Store for project values.** It holds [up to 100 secrets per account, in one store](https://developers.cloudflare.com/secrets-store/manage-secrets/).13+14+## Consequences15+16+- `.env.schema` and committed `.env.*` files, except `*.local`, are in the judge closure. An answer cannot add or change an env item, such as adding a `@proxy` domain or turning off `@sensitive`; a decider lands it.17+- This repo's own env uses varlock. Tools run through `varlock run`. Workers deploy through `varlock-wrangler` ([`@varlock/cloudflare-integration`](https://varlock.dev/integrations/cloudflare/)), which passes non-sensitive values as `--var` and sensitive ones through `--secrets-file`. Agents read the env only through `varlock load --agent`, with values redacted.18+- No Worker imports varlock's runtime. Its `init` patches `console` and the global `Response` and scans every streamed body, and the gateway streams git packs.19+- The format is varlock's, and the README credits it.added:docs/adr/0010-no-inbound-github-sync.md+12 added
1+---2+status: accepted3+---4+5+# No inbound or two-way GitHub sync6+7+A project can be imported from GitHub once, to start it. After that, nothing flows in from GitHub, and nothing syncs both ways. Inbound sync would be a second way onto `main` that skips the gate.8+9+## Consequences10+11+- Export is `git clone`. Code, asks and credit trailers leave with a clone, and verdicts need one more fetch of `refs/notes/*`. The README says so.12+- A one-way push mirror of `main` to GitHub is on the roadmap for after the competition, not in it.added:docs/adr/0011-the-fence.md+19 added
1+---2+status: accepted3+---4+5+# The fence: compiler first, then lint; verify is the authority6+7+Each rule this repo keeps is held by the strongest enforcer available. First, make the mistake unrepresentable in types; then catch it with lint; then with a test; prose is the last rung. Git hooks are early feedback only; `bun run verify` and CI are the authority. The repo is built fast and mostly by agents, and a rule nothing checks drifts under that load. The fence also dogfoods the product: its judge closure, weakening and ratchet apply to this repo first.8+9+## Considered Options10+11+- **The full test suite in pre-commit.** Too slow for an agent sprint. Hooks run lint, format check and typecheck; tests run in `verify` and CI.12+- **A `no-comments` lint rule.** Rejected: agents need room for workaround notes.13+14+## Consequences15+16+- Every escape (`oxlint-disable`, `@effect-diagnostics`, `@ts-expect-error`) carries a reason after ` -- `. `scripts/debt.ts` counts escapes against `debt.baseline.json` in `verify`, and the count rises only with the maintainer's sign-off.17+- One hook policy refuses the usual ways around hooks: `--no-verify`, `commit -n`, `core.hooksPath` overrides, `LEFTHOOK=0` and `lefthook uninstall`. It is wired into each agent harness the repo uses.18+- A deploy is never a way around a red gate: `infra/deploy.ts` refuses without an explicit stage and runs smoke tests after.19+- `AGENTS.md` lists each principle with the check that holds it. Where the check and the prose disagree, the check wins.added:docs/adr/0012-lifecycles-are-pure-transitions.md+15 added
1+---2+status: accepted3+---4+5+# Lifecycles are pure transitions run per DO call6+7+Claim and landing state are each a lifecycle: a pure `transition(state, command, now)` function (`ClaimLifecycle`, `LandingLifecycle`). Each Durable Object call hydrates state, runs one transition, persists the row and an outbox entry, then settles side effects. Deadlines run on DO alarms, never on in-memory timers. Pure transitions can be model-tested over generated histories.8+9+## Considered Options10+11+- **XState 6 with `@xstate/effect`.** Both were alphas, released on Oct 3 and Oct 1, 2026, and snapshot restore was not supported yet. Revisit after the competition.12+13+## Consequences14+15+They are called lifecycles, never "deciders", although the code pattern goes by that name elsewhere: in the glossary a **Decider** is a person.added:docs/adr/0013-provenance-copy-with-attribution.md+22 added
1+---2+status: accepted3+---4+5+# Provenance: copy with attribution6+7+Code from other projects enters as ports: it is copied with attribution into our own files, and from then on it is ours to change. The repo has its own history from the first commit. It is not a fork, a template or a vendor commit of another project, and it holds no third-party prose or artwork. `PROVENANCE.md`, `LICENSES/` and `UPSTREAM.md` record every port: its source, commit, licence and our changes. Upstream `main` is never synced in. The competition's [Official Rules](https://www.cloudflare.com/documents/build-next-gen-git-platform-competition-terms.pdf) (§4) require "Entrant's own original content and creation" with no "third-party copyrighted material or artwork without the copyright holder's permission", and originality is half the score (§6). So credited plumbing is fine, and the centre of the product must be ours.8+9+## Considered Options10+11+- **Fork or template Rat Stack.** A fork carries several hundred commits of someone else's history. A template marks the repo "generated from" its source and brings about 85k lines.12+- **A 25% derived and 15% near-verbatim ceiling.** That was sized for adopting a whole stack, not for grafting plumbing.13+14+## Consequences15+16+- Derived lines stay under 15% of the codebase and near-verbatim lines under 10%, with a target of about 5%. `scripts/provenance.ts` measures both.17+- Planned ports:18+ - from [Rat Stack](https://github.com/joelhooks/rat-stack) at `fba26d8` (MIT): the CLI and MCP projections (ADR 0003), `no-module-level-mutable-state`, the debt ledger, and `vendor-agent-sources.sh`;19+ - from t3code (MIT), via Rat Stack: `no-manual-effect-runtime-in-tests`;20+ - from [anti-slop](https://github.com/dmmulroy/anti-slop) at `c44ef22` (MIT): its oxlint plugins, installed by its own vendoring script.21+- Ideas taken without code, such as cf's merged command catalog, are credited in `PROVENANCE.md` as ideas.22+- Credits live in the README and `PROVENANCE.md`, not on screen in the demo.