AGENTS.md: rules for coding agents
Working rules for coding agents in the Pebble3D repo: where things are, the commands, the invariants you must not break, and what to run before you finish.
Pebble3D is a browser 3D engine: JSON scenes validated by a zod schema, rendered by three.js 0.187 (WebGPU, WebGL fallback), simulated by Rapier compiled from Rust to WebAssembly. New here? Read docs/getting-started.md first.
Skills
Section titled “Skills”For any request to make a game, start with skills/make-a-game/SKILL.md and follow it. It runs the other skills in this order: interview, brief, scaffold, build, game feel, art pass, complete loop, verify.
| Skill | Use it for |
|---|---|
| make-a-game | Entry point: interview, brief, scaffold, build, game feel, art pass, complete loop, verify. |
| game-interview | Turn a vague idea into a short design brief (with a non-interactive fallback). |
| start-a-game | Scaffold a new app the way the demos are laid out and prove it boots. |
| verify-your-work | What done means: tests, captures, sidecars, looking at every image. |
| engine-pitfalls | Known engine traps as “if you see X, do Y”. |
| game-feel | Hit-stop, shake, particles, buffering and sound that make actions land. |
| art-direction | Commit to one look and judge captures against it. |
| complete-game-loop | Title, play, results, restart, a demo bot and a README. |
| genre-playbooks | Per-genre recipes that reuse the shipped demo for that genre. |
The same files are copied to .claude/skills/, where Claude Code, Cursor and GitHub Copilot discover project skills. Edit skills/ only, then run pnpm skills:sync; a test fails if the copies are stale.
Repo map
Section titled “Repo map”| Path | What it is |
|---|---|
crates/engine-core |
Rust Rapier world compiled to wasm (World): spawn, step, state buffers, raycast, body control, state hash. Two builds: deterministic (default) and fast (SIMD). |
packages/sdk |
@pebble3d/sdk: scene schema (src/schema.ts), expandScene, loadSim/StateViews, FixedStepLoop, createGame. Prebuilt wasm lands in packages/sdk/wasm/ (gitignored). |
packages/renderer |
@pebble3d/renderer: createRenderer, PBR/toon pipeline, splats, glTF, characters, camera controllers. |
packages/studio-overlay |
@pebble3d/studio-overlay: the stats overlay (mountOverlay), toggled with the backtick key. |
packages/mcp-server |
Placeholder, not implemented. |
apps/playground |
Loads any scene in apps/playground/scenes/ via /?scene=<name>; owns public/assets/ that every app serves. |
apps/katana-defense |
Ronin Outpost (port 5180): toon horde defence, skinned crowds, IK. |
apps/breakpoint |
Breakpoint (5210): physics demolition, sim in a Web Worker, fast build. |
apps/ghostline |
Ghostline (5220): marble time trials, ghosts re-simulated from inputs. |
apps/field-notes |
Field Notes (5231): photography in Gaussian-splat captures, depth of field. |
apps/rockfall |
Rockfall (5240): survival under spawner-driven rock waves; boots renderer and sim itself. |
apps/chain-reaction |
Chain Reaction (5250): JSON-level puzzle, headless Node verifier. |
skills |
Agent skills: markdown playbooks for building a game, starting with make-a-game. Copied to .claude/skills/ by pnpm skills:sync. |
scripts/shot |
pnpm shot: build, serve, render in Chromium, write PNG + JSON sidecar. |
scripts/docs |
pnpm docs:gen: regenerates the reference docs and llms-full.txt; drift-guard tests. |
scripts/fetch-assets.mjs, scripts/assets |
Download and derive large assets per apps/playground/assets.manifest.json. |
scripts/build-wasm.sh |
pnpm build:wasm: builds both wasm flavours with wasm-bindgen-cli 0.2.130. |
Commands
Section titled “Commands”| Task | Command |
|---|---|
| Install | pnpm i |
| Build wasm (only after a Rust change) | pnpm build:wasm |
| Fetch assets (HDRI, splats, avatars) | pnpm fetch-assets |
| Playground dev server (port 5173) | pnpm dev, then /?scene=showcase |
| One app’s dev server | pnpm --filter <app> dev (for example pnpm --filter rockfall dev) |
| All TS tests | pnpm test (root vitest, every project) or pnpm -r test |
| One project’s tests | npx vitest run --project rockfall (a project must be listed in the root vitest.config.ts) |
| Typecheck | pnpm typecheck |
| Lint (biome) | pnpm lint; auto-fix with npx biome check --write <paths> (never --unsafe on CSS: it deletes !important) |
| Rust tests, both builds | cargo test -p engine-core --features deterministic and cargo test -p engine-core --no-default-features --features fast |
| Determinism (Node) | node --experimental-strip-types packages/sdk/test/determinism.mjs --expect "$(cat packages/sdk/test/fixtures/det-hash.txt)" |
| Screenshot | pnpm shot --scene showcase --cam hero or pnpm shot --app rockfall --param demo=1 --ticks 600 |
| Regenerate docs | pnpm docs:gen (not pnpm docs, which is a pnpm builtin); pnpm docs:gen --check exits 1 if stale |
Regenerate scene.schema.json after a schema edit |
pnpm --filter @pebble3d/sdk schema |
Copy skills/ to .claude/skills/ |
pnpm skills:sync |
| Chain Reaction headless verify | pnpm --filter chain-reaction verify |
Details: docs/verification.md.
Adding a new app
Section titled “Adding a new app”apps/<name>/package.json(scriptsdev,build,test: "vitest run",typecheck; deps@pebble3d/sdk,@pebble3d/rendererasworkspace:*,three0.187.0),index.htmlwith<link rel="icon" href="/favicon.svg">.- Copy
apps/rockfall/vite.config.tsandapps/rockfall/tsconfig.jsonunchanged. - Register its tests, or they never run:
apps/<name>/vitest.config.tswithdefineProject({ test: { name: "<name>", include: ["test/**/*.test.ts"] } }), and an"apps/<name>"entry in the rootvitest.config.tsprojectslist. pnpm i, thennpx vitest run --project <name>.- Node tests that must match the browser use the browser’s tick order: with
createGame,world.step(1)then the rules each tick.
Walkthrough with every file: docs/getting-started.md.
Invariants
Section titled “Invariants”- The determinism hash is
2d76d9927e780425, frompackages/sdk/test/fixtures/det-hash.txt. - No
Math.randomorDatein sim paths. - No per-frame allocation in hot paths.
- Engine changes must be opt-in, with defaults unchanged.
- The physics WASM is committed. Run
pnpm build:wasmonly after a Rust change, and commitpackages/sdk/wasm/with it (pnpm testfails until you do). pnpm shot --outmust be insideartifacts/.- Linux Chromium needs
--enable-unsafe-webgpu --enable-features=Vulkan --use-angle=vulkan.
What they mean in practice:
| Rule | How the repo does it |
|---|---|
| Determinism | Sims draw randomness from a seeded generator (apps/rockfall/src/game/rng.ts). A random seed may be picked at boot outside the sim (apps/rockfall/src/main.ts uses Date.now() only in realtime mode; fixed mode uses seed 7). Never use --write on determinism.mjs to “fix” a mismatch. |
| No per-frame allocation | Preallocate and reuse: event rings (apps/chain-reaction/src/puzzle/sim.ts), scratch reads via game.views.scratch. world.bodyCounts(), world.transformOf(), __pebble3d.player() and position() allocate: stats or debug only. |
| Opt-in engine changes | New features default off (post.style defaults to "pbr", fixInternalEdges defaults to false, renderer.dof starts disabled). The determinism hash and existing scenes must not change. |
| Stale wasm | packages/sdk/wasm/ is gitignored, so a pull or merge never updates it. See docs/troubleshooting.md. |
| Assets | Large files are not committed. Add them to apps/playground/assets.manifest.json with a sha256 and licence, then pnpm fetch-assets (it regenerates apps/playground/public/assets/LICENSES.md). Only licences that allow commercial use (CC0, CC BY, MIT); CC BY-NC captures were rejected. Apps serve the playground’s public/ via publicDir: "../playground/public" in their vite.config.ts. |
Before you finish
Section titled “Before you finish”-
pnpm testpasses (andcargo testfor both builds if you touched Rust). -
pnpm typecheckandpnpm lintare clean. - The determinism script still prints
2d76d9927e780425. - Rust changed:
pnpm build:wasmran, and the change is opt-in. - Schema changed:
pnpm --filter @pebble3d/sdk schemaandpnpm docs:genran, and their output is committed. - Rendering changed: a
pnpm shotexits 0 with an empty console, and you looked at the PNG. - Game changed: its
?demo=1bot still plays a full loop, and itsbench/capture-final.shstill exits 0. - No
Math.random/Dateadded to a sim, no allocation added to a per-frame path.
| Page | Use it for |
|---|---|
| docs/getting-started.md | A first scene, then a minimal game app. |
| docs/scene-reference.md | Every scene JSON field (generated). |
| docs/api-reference.md | @pebble3d/sdk, @pebble3d/renderer and wasm World members (generated). |
| docs/verification.md | pnpm shot, determinism checks, demo bots, fps benches. |
| docs/troubleshooting.md | Error message or symptom, cause, fix. |