Skip to content
bradene0Public

About

Browser-first game runtime for coding agents: JSON projects, MoonBit behaviors compiled to WebAssembly, headless tests, and single-file HTML games.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Moonstage

Moonstage is a lightweight, browser-first runtime for games and interactive media. It is built on MoonBit and WebAssembly. A project is a folder of plain JSON and MoonBit files. Humans, scripts and software agents can all read it, diff it, validate it and test it, with or without a GUI.

Status: early development. The project format, plugin API and behavior ABI are still being designed and may change. Nothing here is stable yet.

What it looks like

moon-hopper/
├── moonstage.json          manifest: scenes, input map, behavior interfaces, plugins
├── scenes/main.scene.json  entities with stable ids and components
├── behaviors/              MoonBit module; each behavior compiles to a tiny .wasm
├── plugins/spin.js         a project-local plugin
└── tests/*.test.json       headless tests: scripted input + assertions
{
  "id": "lander",
  "components": {
    "transform": { "position": [800, 900] },
    "shape": { "kind": "polygon", "points": [[0, -18], [14, 14], [0, 8], [-14, 14]], "fill": "#e8ecff" },
    "behavior": { "module": "lander", "params": { "thrust": 360, "gravity": 120 }, "refs": { "flame": "flame" } }
  }
}
///|
pub fn ms_update(entity : Int, dt : Double) -> Unit {
  let vy = @sdk.state(entity, state_vy) + @sdk.param(param_gravity) * dt
  @sdk.set_y(entity, @sdk.y(entity) + vy * dt)
  @sdk.set_state(entity, state_vy, vy)
}

Try it

You need Node.js 22 or newer and the MoonBit toolchain (moon).

Start a project from npm:

npx moonstage new my-game --template platformer   # or shooter, topdown, minimal
cd my-game
npx moonstage check     # validate, compile, test, simulate and render in one step
npx moonstage run       # play at http://localhost:5173

Or run the reference game from this repository:

git clone https://github.com/bradene0/moonstage.git && cd moonstage
npm install
npm run build
node packages/cli/dist/main.js run examples/moon-hopper

This opens the reference game at http://localhost:5173. Use ← → to turn and ↑ or Space to thrust.

Without a browser:

node packages/cli/dist/main.js test examples/moon-hopper             # headless tests
node packages/cli/dist/main.js render examples/moon-hopper --tick 120  # write a frame as SVG
node packages/cli/dist/main.js run examples/moon-hopper --headless --ticks 600 --json

Every command accepts --json, and the exit codes are meaningful (see moonstage describe). The docs and agent skills ship with the CLI: moonstage guide.

For coding agents

Moonstage is built to be driven by agents: every command takes --json, problems are diagnostics with stable codes, and moonstage check validates, compiles, tests, simulates and renders in one call.

  • Skills. moonstage new puts the Moonstage skills in the project's .claude/skills/ and .agents/skills/, where agents pick them up. For an existing project or all your projects:

    npx moonstage skills install            # this project
    npx moonstage skills install --global   # ~/.claude/skills and ~/.agents/skills
  • Claude Code plugin. This repository is also a plugin marketplace with the skills and the MCP server:

    /plugin marketplace add bradene0/moonstage
    /plugin install moonstage@moonstage
    
  • MCP. moonstage mcp serves the same commands as tools over stdio.

  • Record and replay. In moonstage run, F8 downloads the session as a test file that replays exactly; moonstage record turns any session into an animated SVG an agent or a person can watch.

Playing a project in a page

<script type="importmap">{ "imports": { "@moonstage/core": "./runtime/core/index.js" } }</script>
<script type="module" src="./runtime/player/element.js"></script>
<moonstage-player src="./game/"></moonstage-player>

moonstage build writes exactly this kind of static bundle to dist/. To ship a game as one file, run moonstage build --single-file: the result is a single .html that plays anywhere, offline. Or run moonstage pack and point a player at the package: <moonstage-player src="./game.msp">. You can also play from code: import { play } from "@moonstage/player"; play("#game", "./game/"). The player has no framework dependency.

The player records every session: F8 (or player.saveRecording()) downloads it as a test file that replays exactly. Play one back with <moonstage-player src="./game/" replay="./bug.test.json">, the replay option of play(), or ?replay= on a built page.

Packages

Path Package What it is
packages/core @moonstage/core Project model, schemas, validation, world, behavior host (WebAssembly ABI), plugin host, render frames, headless test runner. No dependencies, no DOM, no Node.
packages/player @moonstage/player Browser player: Canvas 2D renderer, keyboard input, <moonstage-player>.
packages/cli moonstage The moonstage command.
plugins/physics @moonstage/physics Rigid-body physics provider; the engine is MoonBit compiled to WebAssembly. Ships with the CLI.
plugins/rive @moonstage/rive Rive artboards and state machines as entities; the reference advanced plugin.
packages/moonbit-sdk moonstage/sdk (MoonBit) MoonBit bindings for the behavior ABI.
schemas/ JSON Schemas for project, scene, test and operation files.
examples/moon-hopper Reference project. It is also used as a conformance fixture.
examples/physics-playground Physics through the provider contract, with a reference provider plugin.

Documentation

License

MIT

About

Browser-first game runtime for coding agents: JSON projects, MoonBit behaviors compiled to WebAssembly, headless tests, and single-file HTML games.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages