#!/usr/bin/env bash # Body Snatcher — self-orchestrating build factory. # Each phase runs in a FRESH `pi -p` context (reads AGENTS.md + verify.js), # gated by `node verify.js `, retried up to MAX_RETRIES, then a targeted # fix attempt, then an adversarial review, then a full final gate. set -euo pipefail cd "$(dirname "$0")" MAX_RETRIES=3 COMMON="@AGENTS.md @verify.js" # Pitfalls learned from prior sessions — every phase must respect these. PITFALLS=" HARD PITFALLS (non-negotiable, learned the hard way): - Keep the player SPAWN AREA clear: carve an open room around the spawn and do NOT place procedural enemies within ~5 tiles of it (movement/possession checks depend on it). - tick(n) must be DETERMINISTIC and advance BOTH enemy AI and the ghost timer by n steps. Do NOT rely on wall-clock time for game-state logic; use tick steps. Visual interpolation and audio may use real time, but state must be tick-driven. - Canvas getContext('2d') and AudioContext may be no-op mocks; guard every call so the game never throws when they are absent or return no-ops. - When a host dies DURING tick and ejects the ghost, reset the 15s/20s timer and SKIP the rest of that tick so the freshly-reset timer is not immediately decremented. - Movement must enforce grid bounds and wall collision for ghost AND every enemy (including charging/dashing enemies — check occupancy before entering a tile). - Save/load: store the possessed host separately; on load, re-link player.host and player.body to the SAME object. Treat localStorage as UNTRUSTED: validate grid/fog dimensions, normalize entities and stats, and never leave partial state after a failed load. - Single index.html, zero external dependencies, no ES import/require, no