Moonstage
in plain words
A game engine for the browser, made so AI coding agents can build games that hold together. Each game is plain data with tests, so an agent can change one part without quietly breaking another, and the finished game shares as a single HTML file.
under the hood
How it works
- Projects are schema-validated JSON, and every problem comes back with a stable error code, its location and a fix hint.
- Game logic is MoonBit compiled to WebAssembly behind a small numbers-only interface, so any WebAssembly language could be used.
- Simulation is deterministic, so a session recorded in the browser replays exactly in Node.
- moonstage check validates, compiles, tests, simulates and renders in one call. Every command has JSON output and an MCP tool.
- Plugins add features without touching the core, including a MoonBit rigid-body physics engine and a Rive animation plugin.
- Agent evals over three rounds compared it with freestyle builds. The results, and the fixes they led to, are in the repo.
Stack
- MoonBit
- Game logic and a rigid-body physics engine, compiled to WebAssembly
- WebAssembly
- A small numbers-only behavior interface, so any WebAssembly language could be used
- TypeScript
- A monorepo published as four npm packages, with a zero-dependency core enforced by tests
- JSON Schema
- Validates every project, with stable error codes, locations and fix hints
- MCP
- A server that exposes every CLI command as a tool for agents
- Agent Skills
- Bundled skills installed into new projects, plus a Claude Code plugin
- Rive
- An animation plugin
- GitHub Actions
- CI on Node 22 and 24 with gzipped size budgets (core about 38 KB)
The longer version
Games that AI agents write freestyle are quick to produce and hard to check. They have no tests, they need a browser, and later changes break earlier features. Moonstage makes an agent-built game editable as data, testable deterministically and inspectable without a screen.
It’s on npm as npx moonstage, at v0.4.0 under the MIT license.
Built for agents
moonstage check validates, compiles, tests, simulates and renders in one call. Headless JSON tests script input and assert on game state, events and SVG frame renders. moonstage record saves a whole run as an animated SVG, and pressing F8 in the browser saves the session as a regression test. Four game templates ship with passing tests, and moonstage run serves a game with live reload.
Engineering
There are 111 tests, including end-to-end tests that compile real MoonBit and long-running physics stability tests. The file format, behavior interface and plugin API are versioned separately, so older behaviors and plugins keep working across releases.
Measured against freestyle
Fresh agents built the same game briefs with Moonstage and without it, across three rounds. Freestyle was about twice as fast on one-off games. Moonstage produced tested, structured games that are easy to share. Every round turned up fixes that were then made, like physics stacks collapsing, a moving-platform bug and missing tooling.