Little Agent Valley
A pixel-art farm in this site's homepage hero where four simulated villagers plan their own days. I built it by directing a team of AI coding agents.
- Stack
- TypeScript, Canvas 2D, Node.js (node:sqlite), Server-Sent Events, Cloudflare Workers + Durable Objects, Vite, Vitest, Playwright

Contents
Summary
Little Agent Valley is a small, original pixel-art farm in the hero of this site. Four villagers live there: Mira the farmer, Bram the woodworker, Juniper the angler and Pip, a baker and musician. They farm, fish and talk. They remember what was said, and they organise things together, such as a harvest festival or a rush to save ripe crops before a storm. Visitors only watch. Hovering over or tapping a villager shows what they are doing, what they remember and who their closest friend is.
I built it by directing a team of AI coding agents in Claude Code. A Team Lead session planned the work and owned the shared type contract. Role agents built the simulation, the villagers’ decision-making, the renderer, the art, the backend and the integration with this site. Separate QA, visual-review and playtest agents judged the work against a scripted quality gate, and none of them reviewed code it had written. My part was the brief, the product decisions in the decision log, and accepting work only on evidence.
Demo: the live valley is the hero on the homepage. This site is not deployed yet, so every number below comes from local or lab runs recorded on 2026-12-05.
Problem
The hero’s media slot held a placeholder. Replacing it with a live simulation ran into four rules the site already enforces:
- The list of interactive islands is closed (ADR 0006). Adding a new one needs its own decision record.
- Every route has byte budgets, checked by a script on each build (ADR 0017).
- The hero text must stay the LCP element.
- No new npm dependencies without a decision record (SEC-01).
The brief added more. The farm must work with no backend and no LLM key, cost nothing to run, use only original art, and accept no visitor input.
Screenshots




Architecture
Text description of the diagram
A seeded TypeScript simulation runs in a Node server, a Cloudflare Worker (built but not deployed) and the browser client. The servers stream snapshots to the client. If none answers within 2.5 seconds, the client runs the simulation itself. An optional LLM brain can replace rule-based decisions. The client mounts in this site’s hero.
Each villager runs the same loop: perceive, retrieve memories, decide, act, remember, and reflect at night. Memories are scored by recency (with a half-life of one game day), importance and relevance. At bedtime, the day’s strongest memories become short reflections, and each villager keeps at most 120.
The rules brain is always available. It scores each possible action on schedule, needs, personality, weather, recent repetition and promises made to other villagers, then makes a weighted random choice using the seeded generator. An optional LLM brain can take over some decisions and whole conversations. Its JSON output is checked against enums, length limits and reachability, and when an answer is late, invalid or over budget, the rules result stands. It is off without an API key, and by default it is capped at 60 calls an hour with a 4-second timeout. It has only been tested against mocked responses, because no key was available.
The Node server advances the world every 250 ms, streams snapshots over Server-Sent Events about every 500 ms, and saves to SQLite in a transaction every game hour and on shutdown. The edge backend serves the same read-only API from one Durable Object. Time there advances only when a request arrives, catch-up is capped, and saves happen at most once every 30 seconds.
On this site, the loader waits for load, then for the box to come within 200 px of the viewport, then for an idle period. Only then does it import and mount the runtime. The production build sets no backend URL, so the hero runs the in-browser simulation.
Engineering decisions
- A custom Canvas2D renderer instead of Phaser (AgentValley D2). Phaser is about 300 KB gzip on its own, which the site’s budgets cannot absorb.
- All art is generated in code from an original 32-colour palette (D3). This avoids licensing risk and keeps the payload tiny.
- One simulation for server and browser (D4). This is what lets the site work with no backend.
- Use what Node already provides:
node:sqliteand its built-in TypeScript support (D5). Dev dependencies are pinned to versions the host site had already vetted. - Cloudflare Workers Free plus one Durable Object (D9). One object means one authoritative writer with transactional SQLite.
- On the host side (newblog ADR 0022), the valley becomes a fourth island, on
/only. The runtime is copied in verbatim with a sha256 manifest rather than installed from npm. It has its own budget line, B-7 at 95,000 B gzip, plus two checks: one asserts that the runtime is reachable from/, the other that no other route loads it.
Implementation
Sprints were followed by three polish cycles: visuals, villager intelligence, and performance and stability. After each cycle, a non-implementing reviewer re-scored the work, and the defects it raised went into a repair round. Unit tests cover determinism, save and load, a real process restart, mocked LLM calls (including a check that the key is never logged) and the bundle budget. Playwright runs on desktop and mobile Chromium, and every test fails on any console error.
Challenges
Villagers mostly walked. The first playtest measured walking at 62–64 % of awake time, and in 27 % of conversation minutes the two speakers stood stacked on top of each other. The reviewer summed up a week as “commuting plus the same campfire every night”. After the repair work, walking fell to 35–44 % per villager and stacked conversations to 0 %.
A villager hidden behind tall art. A high-severity visual defect, a villager standing behind the well, was fixed and covered by a test. Final acceptance then found the same picture through conversation placement (FA-01, 2 episodes in 240 simulated days). The fix shipped with a guard test that was shown to fail with the fix removed.
The poster that took LCP. The first static poster became the page’s LCP element at four viewport widths. The shipped 192×160 crop is 6,288 B, and its intrinsic area of 30,720 px² is smaller than the heading’s smallest, 38,064 px². A test now checks that the heading is the LCP element at seven viewport widths.
Mounting was one long task. mount() once ran as a single 143 ms task under 4× CPU throttling. The runtime now splits it across idle periods, and its own test finds no long tasks. The host site has not re-measured this yet.
Free-tier abuse. A security review of the edge backend found 1 high and 7 medium issues. The high one was that nothing limited the request rate. The fixes were a token bucket per client, a short cache that merges concurrent requests (15 concurrent requests reached the Durable Object once) and a hotlink filter. One risk was accepted: a distributed flood could still use up the free daily quota, in which case clients fall back to the local simulation.
Trade-offs
- Each visitor sees their own valley until the edge backend is deployed and wired in, which ADR 0022 leaves to a separate decision.
- Lazy time. The edge world advances only while someone is watching.
- 0.6 % budget headroom. New features must fit in the existing bytes, or the ADR must be amended.
- Procedural art has limits. Water and sand corners still step in square notches (VR2-05, low).
- Hourly saves on Node. A hard kill can lose about 30 real seconds, and that case is untested.
Verified outcomes
| Measure | Result | Source |
|---|---|---|
| Final acceptance | 14 / 14 criteria pass; 0 critical or high defects | Acceptance record and final acceptance review |
| Unit tests | 181 at the final runtime commit; 210 after the edge backend | Test report |
| Browser tests | 45 passed, 7 skipped by design (desktop and mobile Chromium) | Test report |
| Edge backend tests | 29 / 29 | Test report |
| Runtime size | 94,476 B gzip against 95,000 B (B-7); re-checked with check:budget on 2026-12-05 |
Architecture decision 0022 |
| Fallback to local | 153–173 ms with the server port refused (budget 4 s) | Test report |
| Memories after restart | 15 / 15 identical after SIGTERM (Node); 24 / 24 after kill -9 (local Worker) |
Test report |
| Weather rules | 0 of 50,400 villager-minutes of outdoor leisure in 63 forced-rain drills | Final acceptance review |
| Host page | <h1> stays the LCP element; lab LCP median 616 → 624 ms (noise); CLS 0 |
Architecture decision 0022, §6 |
Not yet verified: the live LLM path, real devices, Safari and Firefox, and production.
Lessons learned
- Keep the reviewers separate from the builders. Only an independent final check found FA-01, after its parent defect had been marked fixed. The Team Lead never raised the reviewers’ scores.
- Show that a regression test fails first. The map composition test and the FA-01 guard were both run against the broken code before being accepted.
- Make the fallback the same code. The in-browser fallback is the same simulation, so it needed no second implementation.
- Set the budget below the product limit. The host’s 95,000 B ceiling sits under the project’s own 120 KB cap, so growth gets flagged early.
- Measure behaviour rather than describe it. “Feels like commuting” became walking share and stacked-conversation minutes, and both numbers came down.