{"slug": "show-hn-clockwork-2d-game-engine-with-an-ai-agent-verified-by-kane-cli", "title": "Show HN: Clockwork – 2D game engine with an AI agent verified by Kane CLI", "summary": "Clockwork, a browser-native 2D game engine built by developer Tope Olajide, ships with an in-editor AI agent that verifies its own changes through Kane CLI, running each check first in the engine simulator and then in a real browser before returning a typed verdict to the chat. The engine requires Node 20+ and pnpm, and offers 14 genre starters, 3 classic templates and a Blank project, with 57 commands, 26 behaviour types and 13 built-in Test Mode profiles. AI authoring and Kane runs are optional, explicitly invoked workflows; manual editing and Play work without a model.", "body_md": "Clockwork is a browser-native 2D game engine with an AI co-worker inside the editor. Build a scene by hand, ask the Game Director for a change, play it, test it with Kane CLI, then export a standalone build or share a read-only link.\n\nManual editing and Play work without a model. AI authoring and Kane runs are optional, explicitly invoked workflows.\n\nRequires Node 20+ and pnpm.\n\n```\npnpm install\npnpm dev\n```\n\nOpen [http://localhost:5173](http://localhost:5173).\n\n`pnpm dev` runs Vite and the local API server together. The API serves the agent transport, provider settings, snapshots, player bundling, and the Kane bridge.\n\n```\npnpm typecheck\npnpm build\npnpm preview\npnpm test\npnpm check:repo\n```\n\n`pnpm build` typechecks and builds the client. The exported-game player is generated on demand by `GET /api/build/player.js` with esbuild.\n\n- **Projects:** create from Blank, one of 14 genre starters, one of 3 classic templates, or a written brief; search/filter/sort; rename, duplicate, archive, export and import`.clockwork.json` ; damaged-project recovery.\n- **Editor:** PixiJS viewport with selection, multi-select, marquee, move/scale/rotate, snapping, pan/zoom, layers, hierarchy drag/reparent, inspector and undo/redo.\n- **Assets:** seeded starter art/audio, import, search/filter, rename, manual slicing, animation clips, and tilemap paint/erase/fill/pick.\n- **Gameplay authoring:** 57 commands, 26 behaviour types, variables, five rule conditions, eight rule actions, prefabs with overrides and detach, input bindings, gravity, HUD and scene audio.\n- **Runtime:** fixed-step manual Play with pause/step/reset, telemetry, keyboard/pointer/gamepad input, sub-stepping, and merged tilemap collision.\n- **Agent:** Ask / Build / Plan modes, typed read/write tools, live project context, atomic command batches, plan ghosts, agent presence, change-set cards, and normal undo.\n- **Shipping:** self-contained`.zip` export, expiring snapshot links (`/s/:id` ), read-only snapshot player, and project cover capture.\n\nThe New Project dialog offers **14 genre starters**, **3 classic templates**, and **Blank**, or you can describe a game in a written brief:\n\n- Genre starters: Space Shooter, Space Invaders, Asteroid Field, Ping Pong, Brick Breaker, Flappy Flyer, Platform Jumper, Clockwork Meadows, Meadow Sandbox, Endless Runner, Arena Survival, Falling Objects, Maze Escape, Snake.\n- Classic templates: Platformer, Top-down, Puzzle.\n- Blank: one empty scene and layer.\n\nMeadow Sandbox uses the Clockwork Meadows hero, art and parallax on a short 2,800 px stage with three easy ledges and no coins, enemies, hazards, variables or HUD. It is a clean starting point for adding features, for example with the agent.\n\nEach starter is a real generated document with a scene, objects, behaviours, rules and HUD data. Test Mode has 13 built-in game-test profiles, one for every genre starter except Meadow Sandbox. Any other game (Meadow Sandbox, the classic templates, Blank and your own projects) gets a profile derived from the project itself, so every game has a Test Mode. The derived profile exposes status, player X/Y, every variable (up to 10), up to 6 object-tag counts and event counts (COLLECTED, DESTROYED, DAMAGE EVENTS, SHOTS FIRED). Readouts for a score or coins added later appear automatically.\n\nKane is used in four distinct ways. See [`docs/kane-cli-usage.md`](https://github.com/tope-olajide/clockwork/blob/main/docs/kane-cli-usage.md) for the field guide.\n\nThe in-app agent builds a change, asks Kane to check it, and reads the result:\n\n1. The user asks the agent for a change and a Kane check.\n2. The agent edits the project through the normal command registry.\n3. The agent calls `verify_with_kane` .\n4. The check runs first in the engine simulator.\n5. The same check then runs in a real browser through Kane.\n6. The typed verdict and readouts return to the chat and to the agent.\n7. The agent reports the result or repairs the project.\n\n**Headline run, `a20a4b28-5387-4849-a978-a5ca5aa499c3` (2026-11-25).** On a Meadow Sandbox project the user asked the agent to add coins tagged `coin`, give +1 score per coin, show a SCORE HUD, and verify with Kane. The agent applied the changes (6 coins, a score variable, a Score HUD widget), ran a headless preflight, then called `verify_with_kane`. The check passed at project revision 9: SCORE 0 → 1, COIN COUNT 6 → 5, COLLECTED 0 → 1, PLAYER X 240 → 473.67 after holding MOVE RIGHT for 45 frames. The simulator and the browser agreed on every readout. Evidence is served locally at `/api/kane/runs/a20a4b28-5387-4849-a978-a5ca5aa499c3/evidence`.\n\nThat run exposed two agent problems, now fixed. The user had to send a follow-up message before Kane ran because the agent used up its step budget. The chat agent now gets 12 model steps per message, reserves the last 3 for a requested Kane check and is told to stop editing; if the budget runs out, the chat says so. The agent also re-added a HUD widget it could not see, so HUD widgets are now in its context and `hud.add` rejects a duplicate widget id.\n\n1. **AI Testing (reviewed phases).** The built-in agent drafts a bounded test plan from a goal. The user reviews and approves it. Kane runs one phase at a time in deterministic Test Mode, clicking real controls and reading runtime observations. The typed verdict and evidence return to the agent conversation (the review panel passes its result to the agent with`agent.continueWithPhaseResult` ). A pass requires matching assertions, delivered input, budget compliance and an evidence bundle. Live passes on Space Shooter:`b967bbdd` (agent-driven, 79.7 s),`98e21783` (94.7 s) and`ea1bb3b3` (78.1 s), the last two approved through the review panel. Each returned typed PASSED with shots-fired 3, projectiles 3, accepted inputs 1 and 45 frames. Details are in[`docs/kane-proof.md`](https://github.com/tope-olajide/clockwork/blob/main/docs/kane-proof.md) .\n2. **AI Play.** A one-off snapshot probe with an AI HUD and optional deterministic embedded-collectible repair. It is a constrained gameplay check, not autonomous playtesting or visual bug detection.\n3. **Saved engine E2E.** A saved`testmd` test drives the real editor: create a Platform Jumper project, verify the canvas/hierarchy/Inspector, edit and undo Object Y, play the game with`LIVES 3` , restart with R, and return to the editor. This tests the application, not a user-created game.\n4. **Agent verification tools.** The agent can call`verify_with_kane` ,`run_ai_play` , and`run_kane_test_phase` ; results return as typed cards/events. This is the path used by the headline run above.\n\n| Path | Timeout | Steps | \n|---|---|---|\n| Defaults ( `KANE_TIMEOUT_SECONDS` ,`KANE_MAX_STEPS` ) | 180 s | 40 | \n| `verify_with_kane` (`POST /api/kane/qa` ) | 180 s default | min(40, 6 + 2 per step + 2 per readout) | \n| AI Play ( `POST /api/kane/ai-play` ) | at most 140 s | at most 8 | \n| Approved test phase ( `POST /api/kane/phase` ) | plan budget, at most 600 s per phase | at most 12 per phase, at most 3 phases | \n\n- Engine QA runs K1, K3a, K3b, K4 and K5 passed against the real editor.\n- K2 caught two real defects: Build accepting a request with no model configured, and undo history being wiped when returning from Play. Both are fixed, and K2 passed afterwards (`bded0577` : Air jumps 0 → 1, a second mid-air jump, then back to 0 with one Undo).\n- A seeded uncollectible coin made AI Play fail with evidence (`87f6f320...` ). The deterministic repair moved the coin, and the rerun passed (`646cff5f...` , STATUS WON, coins 3). The seeded defect is deliberate demo data.\n\nWith the app already running:\n\n```\npnpm kane:engine-e2e\n```\n\nOr start the app, wait for Vite and `/api/health`, run the test, and tear down only what it started:\n\n```\npnpm kane:engine-e2e:dev\n```\n\nBoth print one JSON object to stdout with `status`, `steps`, `durationSeconds`, `finalState`, `testUrl`, `sessionId`, `evidencePath`, and file paths. The one-command wrapper writes app logs to `.testmuai/runs/engine-e2e-dev.log` so stdout stays machine-readable.\n\nThe saved test first passed authored in 286 s (2026-11-24, session `aceb577f-0a26-456e-a2d7-944652113935`): project `Engine E2E Platformer`, Object Y restored by undo, `LIVES 3` in Play and after R, and the final URL back on the project scene. The one-command cold-start path then passed again in 89 s with 1/1 replayed steps (session `e547a290-4de8-4797-af91-19efb79ce3af`), and its wrapper stopped the app cleanly. The latest result and 3.8 MB evidence pack are under `.testmuai/`. Only `.testmuai/tests/engine-template-e2e_test.md` is tracked; `.testmuai/runs/`, `.testmuai/evidence/` and `.testmuai/tests/output-*/` are gitignored.\n\n```\npnpm smoke:phase\n```\n\nThis runs fixture Kane plus a mock agent through the approve-and-replay panel flow with real headless Chrome and a console-error check.\n\nCopy the variables you need into the environment of the API process.\n\n| Variable | Purpose | \n|---|---|\n| `PORT` | API port, default `3000` | \n| `AI_MOCK=1` | Development-only mock model; never present as a real provider | \n| `AI_BASE_URL` ,`AI_API_KEY` ,`AI_MODEL` | Env-configured OpenAI-compatible model | \n| `CLOCKWORK_SECRET` | Extra secret mixed into the local key vault | \n| Kane CLI login | Required for Kane runs; no feature flag | \n| `KANE_CLI` | Optional path or command for the Kane CLI | \n| `KANE_TIMEOUT_SECONDS` ,`KANE_MAX_STEPS` | Default Kane limits (180 s, 40 steps); see the table above for per-path limits | \n| `CLOCKWORK_PUBLIC_URL` | Origin Kane opens (Vite in dev, usually `http://localhost:5173` ) | \n\nProvider keys can also be saved to the local vault from **Project → AI Settings**; session-only keys are intentionally lost when the server restarts. See [`docs/model-setup.md`](https://github.com/tope-olajide/clockwork/blob/main/docs/model-setup.md).\n\n- Projects, assets and chat threads live in this browser's IndexedDB.\n- Snapshots, Kane evidence and the key vault live under `.data/` on the local server.\n- Export a project before deleting browser data; there is no cloud sync in v1.\n- Kane and screenshots require Chrome/WebGL; exported players do not need the local server.\n\n- `src/engine/` — Zod document schema, 57-command bus, PixiJS renderer, fixed-step runtime, persistence, agent tools.\n- `src/features/` — dashboard, editor, content/logic/presentation, playtest, agent, settings, ship.\n- `src/play/` — standalone exported-game player and the AI HUD.\n- `server/` — Hono API for agent streaming, providers, snapshots, player bundling and Kane runs.\n- `shared/` — protocol, tool definitions and snapshot contracts shared by client and server.\n- `.testmuai/tests/` — saved Kane`testmd` tests, including the engine E2E.\n- `scripts/kane/` — terminal Kane runners and the one-command dev wrapper.\n\nThe document model, command registry, renderer, runtime and persistence are separate layers. Manual edits and agent edits both dispatch through the same command registry, so they share revisions, validation and undo history.\n\n- [`docs/PROJECT_FEATURE_AUDIT.md`](https://github.com/tope-olajide/clockwork/blob/main/docs/PROJECT_FEATURE_AUDIT.md) — verified feature inventory, workflows, architecture and limitations.\n- [`docs/FEATURE_VERIFICATION.md`](https://github.com/tope-olajide/clockwork/blob/main/docs/FEATURE_VERIFICATION.md) — claim-to-source verification ledger.\n- [`docs/HACKATHON_SUBMISSION_DESCRIPTION.md`](https://github.com/tope-olajide/clockwork/blob/main/docs/HACKATHON_SUBMISSION_DESCRIPTION.md) — submission-ready project description.\n- [`docs/kane-cli-usage.md`](https://github.com/tope-olajide/clockwork/blob/main/docs/kane-cli-usage.md) — how Kane is used for engine and game testing.\n- [`docs/known-issues.md`](https://github.com/tope-olajide/clockwork/blob/main/docs/known-issues.md) — limitations and risks.\n- [`docs/implementation-log.md`](https://github.com/tope-olajide/clockwork/blob/main/docs/implementation-log.md) — build log, ending with the 2026-11-25 final status.\n- [`docs/clockwork-implementation-plan.md`](https://github.com/tope-olajide/clockwork/blob/main/docs/clockwork-implementation-plan.md) — the original brief.\n- `docs/archive/` — historical planning docs (`KANE_AI_TESTING_IMPLEMENTATION_PLAN.md` ,`slice-3-7-fixes.md` ,`chat-kane-integration-plan.md` ,`agent-chat-ux-plan.md` ,`game-starter-templates-plan.md` ,`video-scene/` ).\n- [`docs/kane-proof.md`](https://github.com/tope-olajide/clockwork/blob/main/docs/kane-proof.md) — dated Kane evidence and negative controls.\n- [`docs/testing-hooks.md`](https://github.com/tope-olajide/clockwork/blob/main/docs/testing-hooks.md) — selectors, URL params, data attributes and debug API.\n- [`features.md`](https://github.com/tope-olajide/clockwork/blob/main/features.md) — slice-by-slice feature status.\n\n- Single-user and local-first: no accounts, cloud sync, multiplayer, arbitrary user scripting, 3D, skeletal animation, or mobile editor layout below 1024 px. Shared and exported players work on mobile.\n- Kane checks gameplay readouts and inputs. The only automatic repair is the deterministic embedded-collectible policy used by AI Play.\n- Phase results and idempotency state on the server are held in memory and are cleared when the server restarts.\n- Phase replay from a saved test is wired in (`POST /api/kane/phase` accepts`replayTestKey` ), but no phase replay speedup has been measured yet. The engine E2E replayed 1/1 steps in 89 s, re-confirmed on 2026-11-26 in 164 s.\n\n176 tests across 27 test files pass (`pnpm test`), `pnpm typecheck`, `pnpm build` and `pnpm check:repo` pass, and `pnpm test:hud` passes 108/108 HUD layouts. `pnpm smoke:phase` passes against a running app. Kane runs are recorded evidence, not CI; coverage boundaries are listed in [`docs/known-issues.md`](https://github.com/tope-olajide/clockwork/blob/main/docs/known-issues.md).", "url": "https://wpnews.pro/news/show-hn-clockwork-2d-game-engine-with-an-ai-agent-verified-by-kane-cli", "canonical_source": "https://github.com/tope-olajide/clockwork", "published_at": "2026-11-26 15:21:32+00:00", "updated_at": "2026-11-26 15:44:15.355107+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "generative-ai"], "entities": ["Clockwork", "Kane CLI", "Tope Olajide", "PixiJS", "Vite", "esbuild", "Node"], "also_reported_by": [], "takeaway": "Clockwork's agent calls a verify_with_kane tool that runs each check in the engine simulator and then in a real browser, returning a typed verdict and readouts the agent uses to report or repair the project.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/show-hn-clockwork-2d-game-engine-with-an-ai-agent-verified-by-kane-cli", "markdown": "https://wpnews.pro/news/show-hn-clockwork-2d-game-engine-with-an-ai-agent-verified-by-kane-cli.md", "text": "https://wpnews.pro/news/show-hn-clockwork-2d-game-engine-with-an-ai-agent-verified-by-kane-cli.txt", "jsonld": "https://wpnews.pro/news/show-hn-clockwork-2d-game-engine-with-an-ai-agent-verified-by-kane-cli.jsonld"}}