# The agent loop

> How a coding agent builds a Minekube game end to end - it changes the rules, proves them in Bun, installs them on a live server, plays them with bot clients, and reads the message logs to find out why something happened.

A coding agent is only as good as what it can check. Most game platforms give an agent source code and a server log. Minekube gives it the same loop a developer has, and every step of it returns data the agent can read.

## The loop

1. **Read the rules of the project.** `AGENTS.md` and the `minekube-games` skill say how a game is structured and which checks to run. See [Build with a coding agent](https://minekube.com/games/get-started/coding-agent).
2. **Change the rules and prove them in Bun.** The agent edits the rules component, writes a [Story](https://minekube.com/games/testing/rules), and runs `bun run check` and `bun test`. This takes seconds and needs no server.
3. **Install on the live server.** `mk dev .` builds the game on every save, and the dev server [swaps](https://minekube.com/games/local-development/live-swap) it on the next tick. A broken bundle never replaces a working one, so the agent cannot take the server down.
4. **Play it with a bot.** The agent starts a [bot client](https://minekube.com/games/testing/bots) through the daemon. The bot is a real Minecraft client with an Effect bundle that walks, clicks and reports what it saw.
5. **Read what happened.** Both the server's and the bot's recordings stream into the devtools. The agent reads them through MCP: `list_entries` for what happened, `get_chain` for why, and `diff_state` for what changed.
6. **Keep the evidence.** A session that shows the behavior goes into `recordings/`, and `bun test` [replays](https://minekube.com/games/testing/recordings#replays) it from then on.

## Why this works for agents

- **Everything is data.** Messages, Models and Command arguments have Schemas. A recording is JSON that any tool can read, not a screenshot or a log line to parse.
- **Causes are recorded.** Every entry points to the entry that caused it. An agent does not guess why a score reset; it follows the chain back to the event.
- **The agent cannot cheat.** The devtools' `dispatch` tool is off, so an agent cannot send messages the game would never get from a player. It acts through a real client, like a person.
- **Two sides, one clock.** Server and client entries carry the world's game time (`tick`), so a test can line up what the server decided with what the player saw.
- **Mistakes fail fast.** One command, `bun run check`, runs the type checker and Effect's strict lint rules, so code that ignores an Effect or a nullable value fails before the agent installs it.

## What each step returns

| Step | Returns | Where |
| --- | --- | --- |
| `bun run check` | Type errors and Effect lint errors | The terminal |
| `bun test` | Failing Stories, and the first message where a replay diverges | The terminal |
| `mk dev .` | `Installed` or `Reloaded` with the revision, or why the bundle was rejected | The server log |
| A bot client | The bot's own recording, frame by frame | The daemon's event stream |
| The devtools | Entries, cause chains and Model diffs | MCP at `http://127.0.0.1:4774/mcp` |

## Today and next

The check, the tests, the dev server, the devtools and MCP ship with every project today. Bot bundles need a [Minekube checkout](https://minekube.com/games/testing/bots) until `@minekube/client` is part of the release. The `minekube-games` skill does not cover bot clients yet.
