amber_game_kit toolchain-wasi-33.0m
The shared engine for co-op browser games built with Crystal and Amber V2. A game brings its rules, maps, art and sound; the kit brings everything else a phone game in a browser needs.
What it gives a game
- Invite from inside the game. One Invite panel with a four-letter room code, the share sheet (or Copy link), and a QR code of the join link drawn on the phone for whoever stands beside the player.
- Saves on the player's own device. IndexedDB on each phone, party copies passed between phones, and save files to keep or move. The relay holds nothing between sessions.
- One input layer. Keyboard, touch, the on-screen thumb stick, gamepad and tilt all feed the actions a game declares once in Crystal.
- Shared movement and physics. Tile movement, route finding, a camera and 2D bodies in Crystal, compiled to WebAssembly by crystal-alpha, so every phone runs the same rules.
- An Amber V2 relay. Rooms, seats, host handoff, direct links with TURN fallback, a TLS 1.3 listener and per-network limits.
- A performance budget checked in CI. Frame time, input response, memory, first load and resume, measured on a reference phone profile on every change.
Quick start
Play the sample game on your own computer. You need an Apple silicon Mac with Homebrew and the pinned toolchain.
git clone https://github.com/amberframework/amber_game_kit.git
cd amber_game_kit
/usr/bin/ruby tooling/fetch_wasm_toolchain.rb --chrome
cd sample_game
minecart install --frozen
/usr/bin/ruby ../tooling/build_wasm.rb --game-root .
/usr/bin/ruby ../tooling/build_web.rb --game-root .
cd relay
minecart install --frozen
mkdir -p bin
crystal-alpha build src/relay.cr -o bin/relay
./bin/relay
Open http://127.0.0.1:4232/sample_game/, press Invite, and open the join link in a second browser window. Walk with the arrow keys, flip the lamp with Space, and watch both windows.
[!TIP] Play it the way CI does: from
sample_game/,/usr/bin/ruby ../tooling/playtest.rb --game-root . --minutes 3 --runner local --serve, then/usr/bin/ruby ../tooling/budget_check.rb build/playtest/<run>.jsonprints each measure against its budget.
Making your own game? Read Your first co-op browser game.
How a game fits together
flowchart LR
subgraph Phone["Each phone (browser)"]
Page["page modules<br/>web/kit/*.js"] -->|actions| Rules["rules in WebAssembly<br/>Crystal, wasm32"]
Rules -->|world| Page
Page --> Saves[("device saves<br/>IndexedDB")]
end
Page <-->|"WebSocket: snapshots, actions, invites"| Relay["relay<br/>Amber V2"]
Page <-.->|"direct link (WebRTC)"| Other["other phones"]
Relay <--> Other
classDef kit fill:#2B3245,stroke:#DAB56E,color:#ECE7DD
classDef store fill:#3F7A5F,stroke:#DAB56E,color:#ECE7DD
class Page,Rules,Relay,Other kit
class Saves store
The host phone runs the rules; guests send their actions and draw the host's snapshots. The relay seats phones in rooms and passes messages; it keeps no saves.
Layout
amber_game_kit/
shard.yml package manifest
toolchain.lock.json every tool pinned by version and sha256
src/amber_game_kit.cr rules side (bridge, saves, input, movement, physics); never requires Amber
src/amber_game_kit/relay relay base for a game's Amber V2 relay
web/kit/ page modules: rules loader, input, invite, device saves, relay link, probe
tooling/ Ruby tools: wasm build, Chrome harness, playtest, soak, budget check, deploy
spec/ tooling/spec/ web/spec/
sample_game/ a one-room co-op game CI builds, plays and holds to the budget
docs/guide.md your first co-op browser game
A game keeps its own rules, maps, art, sound, relay messages and settings (web/game_config.js, config/performance_budget.json, config/tooling.json, config/deploy.json), and runs the kit's tools from lib/amber_game_kit/tooling/.
Pinned toolchain
Every build, playtest, soak and CI job first runs tooling/verify_toolchain.rb, which stops on any mismatch with toolchain.lock.json.
| Tool | Pin | Checked by |
|---|---|---|
| crystal-alpha | 1.22.3-incremental-8 from crimson-knight/agent-crystal at d886be7 |
bottle sha256, tap commit, --version |
| minecart (shards-alpha) | 2025.11.25.10 from amberframework/amber_cli at 6beaf1c |
bottle sha256, tap commit, --version |
| WASI SDK | 33.0+m, macOS arm64 | tarball sha256 |
| wasm32 libraries | crystal-1.22.3-incremental-8 | tarball sha256 |
| binaryen (wasm-opt) | 126 | tarball sha256 and --version |
| Chrome for Testing | 158.0.8127.88 | zip sha256 |
| Ruby | macOS /usr/bin/ruby 2.6.10 |
version line |
| Amber V2 | c49aa654 |
the relay's shard.lock |
tooling/fetch_wasm_toolchain.rb downloads the WASI SDK, the wasm32 libraries, binaryen and (with --chrome) Chrome for Testing into ~/.amber_game_kit/toolchain/ and checks each sha256. The WebAssembly toolchain is published for Apple silicon Macs; tooling/build_linux_relay.rb cross-builds the relay for a Linux server.
Performance budget
| Measure | Kit budget | Sample game budget | Sample game measured |
|---|---|---|---|
| Frame work, p95 / p99 | 16.7 ms / 33.4 ms | same | 0.1 ms / 0.6 ms |
| Dropped frames (reference runner) | 2% | same | 0.063% |
| Input to visible response, p95, each action kind | 100 ms, 30 samples or more | same | 15.8 to 21.5 ms, 165 to 248 samples |
| WebAssembly memory, peak | 64 MiB | 32 MiB | 12.6 MiB, flat for 60 minutes |
| First load | 4 MiB | 2 MiB | 1.44 MiB |
| Resume after a reload or a dropped link | 3 s | same | 1.09 s |
Measured by tooling/playtest.rb in a 3-minute play on the reference phone profile (390 x 844 CSS px, device scale 3, touch, CPU throttled 4x, Fast 4G) on the reference runner, plus the 60-minute tap soak in CI. A game may only lower a number in its config/performance_budget.json. On GitHub-hosted runners tooling/budgets/hosted_runner.json sets the input-response ceiling to 189.6 ms (calibrated from 10 hosted runs) and skips dropped frames; the strict numbers hold on the reference runner.
The sample game
sample_game/ is one room, a lamp switch and a walker per phone, laid out exactly like a real game that uses the kit: Crystal rules in src/, the page in web/, an Amber V2 relay in relay/, playtest steps and a soak bot in tooling/. CI builds it, plays it for 3 minutes, checks the budget and runs a 60-minute tap soak on every push.
Premium
[!NOTE] Teams who want stricter gates can add the premium layer: reference-runner budgets, multi-phone co-op soaks, the relay load test, nightly trends, per-chip relay builds and blue/green deploys. Ask at agentc.consulting.
Contributing and security
See CONTRIBUTING.md. Report a vulnerability privately as described in SECURITY.md.
License
MIT. See LICENSE.
Built by AgentC Consulting for the Amber framework.
amber_game_kit
- 0
- 0
- 0
- 0
- 1
- 7 minutes ago
- November 30, 2026
MIT License
Tue, 01 Dec 2026 02:47:34 GMT