(Body Snatcher) Pass 3
This commit is contained in:
1 parent
d819146009
commit
832f3a3345
36 files changed
+6416
No files matched your search
Executable
+279
@@ -0,0 +1,279 @@
|
||||
#!/usr/bin/env bash
|
||||
# build.sh — self-orchestrating factory for Body Snatcher.
|
||||
# Drives the build in phases via `pi -p` (fresh isolated context each phase),
|
||||
# gated mechanically by `node verify.js <phase>`. Max 3 retries + targeted fix.
|
||||
set -uo pipefail
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
MAX_RETRIES=3
|
||||
MODEL="--model openai/gpt-5.2 --thinking high"
|
||||
mkdir -p build
|
||||
LOG=build/build.log
|
||||
: > "$LOG"
|
||||
|
||||
if [ ! -f verify.js ]; then echo "FATAL: verify.js missing" >&2; exit 1; fi
|
||||
|
||||
# ---- shared contract + phase scopes written to build/_*.md ------------------
|
||||
cat > build/_contract.md <<'EOF'
|
||||
You are building "Body Snatcher" — a single index.html browser possession roguelike.
|
||||
STEP 0: Read AGENTS.md in THIS directory COMPLETELY. It is the authoritative spec.
|
||||
Then, if index.html already exists, read ALL of the current index.html before editing.
|
||||
After phase 1, NEVER rewrite index.html from scratch — edit it incrementally and
|
||||
PRESERVE every working system from earlier phases.
|
||||
|
||||
HARD CONSTRAINTS (every phase):
|
||||
- Single index.html. Zero external dependencies: no CDN, no npm, no ES `import`,
|
||||
no <script src=>. All CSS and JS inline.
|
||||
- The game MUST NOT auto-start play on load. It sits on the title screen until
|
||||
start() or a valid user key.
|
||||
- MUST NOT crash if Canvas.getContext('2d') or AudioContext are no-op mocks.
|
||||
Guard every canvas/audio call.
|
||||
- Core game logic is DETERMINISTIC and step-driven, NOT wall-clock. tick(n) advances
|
||||
enemy AI AND decrements the ghost timer by exactly n steps. 1 step = 1 second.
|
||||
Base ghost timer = 15 steps; Ghost T1 = 20 steps. (Visuals/audio may use real time;
|
||||
the timer and AI must not.)
|
||||
- Expose window.GAME = { state, player, enemies, grid, floor, essence, upgrades,
|
||||
achievements, projectiles, log, start, input, tick, spawn, setFloor, newRun,
|
||||
save, load, openShop, buy }.
|
||||
* state is one of: title, playing, possessed, shop, paused, won, lost.
|
||||
* player = { x, y, ghost(bool), timer, host, facing }.
|
||||
* enemy = { type, hp, maxHp, damage, speed, x, y, ... }.
|
||||
* grid[y][x] = number (0 floor, 1 wall, 2 door, 3 exit, 4 shop, 5 chest)
|
||||
OR an object { type, solid }. Pick one shape and stay consistent.
|
||||
- input(key) accepts: ArrowUp/Down/Left/Right, w a s d, ' ' and 'Space', q e,
|
||||
x (abandon host), Enter, Escape, l (legend toggle).
|
||||
- spawn(type, tx, ty) creates and returns the enemy. setFloor(n) regenerates floor n
|
||||
and places the ghost at spawn (state playing). newRun() starts a fresh floor-1 run
|
||||
with a NEW random layout. openShop() (debug) enters shop state AND grants a test
|
||||
stipend (set essence >= 30) so buy() can succeed; the real between-floor shop uses
|
||||
earned essence. buy(index) purchases; hard-block if essence is insufficient; enforce
|
||||
per-tree prerequisites (T1 -> T2 -> T3 -> T4). After openShop and after the
|
||||
between-floor shop, expose the 3 choices on GAME as G.choices (the harness also
|
||||
accepts G.shopChoices / G.upgradeChoices); make choice[0] a prereq-met, unowned item.
|
||||
- Title screen MUST visibly explain WASD/arrows, SPACE, Q/E (facing), ENTER, ESC.
|
||||
It MUST offer an enemy Legend/Bestiary panel (toggle 'l') listing each enemy's
|
||||
behavior AND its possessed kit. The live HUD shows a contextual SPACE hint (possess
|
||||
while ghost; attack/special while possessed; press X to abandon host while
|
||||
possessed). Pause (ESC) and shop screens show their own controls.
|
||||
|
||||
PACING RULES — these are completion criteria and verify.js checks them directly:
|
||||
- NO friendly fire between enemies. Enemy melee, AoE explosions, charges, and
|
||||
projectiles damage the PLAYER ONLY and never reduce another enemy's HP. (Your
|
||||
possessed host's attacks and your host's AoE still damage enemies normally, and you
|
||||
still gain essence for those kills.) verify.js places a "meat" enemy on the line of
|
||||
an enemy Sentinel/Turret shot, inside an enemy Bomber's blast, and on an enemy
|
||||
Charger's charge line, and asserts that enemy's HP is unchanged WHILE confirming the
|
||||
AoE/projectile actually happened.
|
||||
- Aggro radius ~6 tiles, line-of-sight gated. Enemies start DOCILE and only chase /
|
||||
attack when the player is within radius AND visible. Outside it they idle and do NOT
|
||||
path toward the player. The whole floor MUST NOT swarm on spawn. Keep the spawn area
|
||||
clear (place enemies at least 6 manhattan tiles from spawn).
|
||||
- Sentinel and Turret fire a 3-shot BURST then OVERHEAT into a forced multi-turn (>=3)
|
||||
no-fire window during which they cannot shoot (Turret is also fully vulnerable then).
|
||||
verify.js places them 5-7 tiles away along a cleared corridor and asserts a burst
|
||||
followed by >=3 consecutive no-fire turns. No infinite-fire enemies.
|
||||
|
||||
SELF-CHECK before you report done: run `node verify.js <this phase>` and every lower
|
||||
phase too (to confirm no regression), and FIX every failure. The harness is headless:
|
||||
it evals your inline <script> with mocked DOM/canvas/audio/localStorage and drives the
|
||||
game exclusively through window.GAME. If a check fails, read its message — it names the
|
||||
exact expectation.
|
||||
EOF
|
||||
|
||||
cat > build/_p1.md <<'EOF'
|
||||
Implement PHASE 1 ONLY (core engine). Do not implement possession, enemies, procgen
|
||||
beyond a basic floor, shop, or save/load yet.
|
||||
- HTML5 Canvas (25x18 tile grid, 800x576 canvas + HUD bar), game loop, grid system,
|
||||
tile rendering with visible grid lines.
|
||||
- Wall collision. Ghost movement: WASD / arrows, one tile per turn.
|
||||
- Base ghost timer = 15 steps, decremented by tick(n). Show it in the HUD.
|
||||
- Fog of war: visible radius around the player; explored-but-unseen tiles dimmed.
|
||||
- Title screen that visibly explains WASD/arrows, SPACE, Q/E, ENTER, ESC, AND offers
|
||||
the enemy Legend/Bestiary panel (toggle 'l'). Live HUD shows a contextual SPACE hint.
|
||||
- A basic floor for now: a simple carved layout with walls, floor, and an exit tile.
|
||||
Full procedural generation is phase 4 — do not build it yet.
|
||||
- start() must initialize to the TITLE screen. Expose window.GAME per the contract.
|
||||
Finish by running: node verify.js 1 (must exit 0).
|
||||
EOF
|
||||
|
||||
cat > build/_p2.md <<'EOF'
|
||||
Implement PHASE 2 ONLY (possession + first 3 enemies). Preserve all of phase 1.
|
||||
- Possession: SPACE on an orthogonally adjacent enemy -> state becomes 'possessed';
|
||||
the player takes that host's hp/stats/attack and occupies its tile. Adjacency test
|
||||
must also accept a diagonally-adjacent enemy (use Chebyshev distance in the fallback).
|
||||
- Voluntary ABANDON: press X while possessed -> return to ghost (state playing), host
|
||||
SURVIVES at its current HP and stays in the enemy list, pacified for 2 turns with a
|
||||
2-turn re-possess LOCKOUT (so input('Space') right after abandon must NOT re-possess).
|
||||
The ghost timer RESUMES from where it paused — it is NOT reset to 15.
|
||||
- Brute: enemy maxHp 8, damage 3, slow chase every 2 turns via A*/BFS. Player kit high
|
||||
HP / slow / 3 dmg.
|
||||
- Skitterer: maxHp 2, damage 1, moves every 2 turns, loose swarm + flank. Player kit
|
||||
low HP / fast / 1 dmg/turn.
|
||||
- Sentinel: maxHp 4, ranged. Fires a BURST of 3 shots (toward the player, projectiles
|
||||
hit PLAYER only) then OVERHEATS for 3 turns (cannot fire, repositions slowly). Keeps
|
||||
distance. No melee. Player kit same burst/overheat rhythm, shoot in facing, no melee.
|
||||
- A*/BFS pathfinding: enemies navigate AROUND walls toward the ghost.
|
||||
- Essence: when YOUR host kills an enemy, essence increases (values per AGENTS.md) and
|
||||
accumulates in G.essence.
|
||||
- Host death: check host hp <= 0 EVERY tick; when it dies, eject the ghost with a FRESH
|
||||
timer (15, or 20 with Ghost T1). If ejection happens during a tick, do NOT decrement
|
||||
that fresh timer on the same step.
|
||||
Finish by running: node verify.js 1 && node verify.js 2 (both must exit 0).
|
||||
EOF
|
||||
|
||||
cat > build/_p3.md <<'EOF'
|
||||
Implement PHASE 3 ONLY (the remaining 9 enemies). Each needs full enemy AI + player
|
||||
kit, with stats distinct from every other enemy. Preserve phases 1-2.
|
||||
- Shielder (maxHp 5): frontal shield blocks damage from facing; Q/E rotate. Enemy slow
|
||||
chase; player must rotate to face threats.
|
||||
- Bomber (maxHp 3): ENEMY chases when aggroed and explodes 3x3 AoE 3 dmg to the PLAYER
|
||||
ONLY on death or when adjacent (never other enemies). HOST: SPACE detonates (suicide,
|
||||
3x3 AoE 4 dmg) and ejects you as ghost.
|
||||
- Healer (maxHp 3): ENEMY stays near other enemies, heals nearby enemies +1/turn within
|
||||
3 tiles, flees the player. HOST: SPACE AoE heal pulse (self +2, allies +1 within 3).
|
||||
- Phaser (maxHp 4): ENEMY teleports toward the player every 3 turns (within LOS),
|
||||
materializes/attacks/dematerializes. HOST: SPACE blink 5 tiles in facing (through
|
||||
walls), 2-turn cooldown.
|
||||
- Turret (maxHp 4): ENEMY stationary, fires a BURST (3 shots, 1 every 2 turns) at an
|
||||
aggroed player then OVERHEATS 3 turns (fully silenced + vulnerable) — projectiles hit
|
||||
PLAYER only, never enemies. HOST: rooted, SPACE fires in facing (Q/E rotate), same
|
||||
overheat rhythm so it cannot fire forever.
|
||||
- Charger (maxHp 5): ENEMY telegraphs 1 turn, then charges straight toward the player's
|
||||
telegraphed position; collision with player = 3 dmg to PLAYER only; hits a wall =
|
||||
stunned 2 turns; the charge does NOT damage other enemies. HOST: SPACE dash-charge 4
|
||||
tiles in facing, 2 dmg per enemy hit in path.
|
||||
- Siren (maxHp 3): ENEMY slow drift, emits pull field (drags player 1 tile/turn within 5)
|
||||
+ weak melee. HOST: SPACE pulls all enemies within 4 one tile toward you.
|
||||
- Mimic (maxHp 4): ENEMY disguised as a chest; when the player is adjacent it reveals
|
||||
and bursts 2 dmg in a cross. HOST: passive (enemies don't aggro you while disguised);
|
||||
SPACE surprise burst (2 dmg 3x3 cross).
|
||||
- Leech (maxHp 4): ENEMY slow chase; on hit drains 1 from the player and heals self +1.
|
||||
HOST: every hit deals 1 and heals you +1.
|
||||
Re-enforce: enemy Bomber blast, enemy Charger charge, and enemy Turret shots damage the
|
||||
PLAYER only and never reduce other enemies' HP (verify.js checks each). Pathfinder must
|
||||
route around walls, never through them.
|
||||
Finish by running: node verify.js 1 && node verify.js 2 && node verify.js 3 (all 0).
|
||||
EOF
|
||||
|
||||
cat > build/_p4.md <<'EOF'
|
||||
Implement PHASE 4 ONLY (procgen + progression + shop + save/load). Preserve 1-3.
|
||||
- Procedural dungeon: random walk + room carving. Per floor: 5-8 rooms (4x4 to 8x6),
|
||||
L-shaped 1-wide corridors (never diagonal), exit stairs in the FARthest room from
|
||||
spawn, shop pad on floors 3/5/7/9, enemies scale 4+N per floor, 1-2 chests. Layouts
|
||||
MUST differ across runs (Math.random-based) — verify.js generates 3 and compares wall
|
||||
positions. Difficulty scaling per AGENTS.md (which enemy types appear on which floors).
|
||||
- 10 floors with escalating enemy variety.
|
||||
- Between-floor shop: after every floor exit (descend), show a shop with 3 random
|
||||
upgrade choices BEFORE the next floor. All 11 upgrades across Ghost/Body/Meta trees
|
||||
with per-tree prerequisites (T1->T2->T3->T4) and the essence costs in AGENTS.md.
|
||||
- Save/load via localStorage key 'bodysnatcher_save'. Autosave on floor transition,
|
||||
shop purchase, possession change. Save floor, essence, upgrades, player state (incl.
|
||||
the possessed host), and the current floor layout. load() MUST validate/normalize the
|
||||
stored data (treat it as untrusted/malformed), re-link player.host/body to the
|
||||
restored host object, and restore G._exit by scanning the grid. Because verify.js may
|
||||
overwrite the exit tile TYPE during other tests, ALSO trigger descend when the player
|
||||
stands on the recorded G._exit coordinates during step().
|
||||
- Shop API: openShop() (debug) sets state 'shop' AND grants essence>=30 so buy(0) works;
|
||||
the between-floor shop uses earned essence; buy() hard-blocks insufficient essence and
|
||||
enforces prereqs; expose the 3 choices on G.choices.
|
||||
Finish by running (procgen is randomized, so run it a few times):
|
||||
for i in 1 2 3 4 5; do node verify.js $i || break; done (all must exit 0).
|
||||
EOF
|
||||
|
||||
cat > build/_p5.md <<'EOF'
|
||||
Implement PHASE 5 ONLY (polish + audio + achievements + win/lose). Preserve everything.
|
||||
- Web Audio API procedural sounds (hit, possess, death, pickup, explosion) via simple
|
||||
oscillators — no audio files. Guard if AudioContext is unavailable/mock.
|
||||
- Game feel: screen shake on explosions/big hits, particles on death/possession/essence
|
||||
pickup, hit flash (white ~100ms), smooth movement interpolation (150ms ease). NONE of
|
||||
this may break the deterministic tick.
|
||||
- All 8 achievements, tracked in G.achievements and localStorage: First Possession,
|
||||
Body Hopper (5 different enemy types one run), Pacifist Ghost (reach floor 3 with no
|
||||
host damage), Essence Hoarder (>=30), Deep Diver (floor 7), Escape Artist (win),
|
||||
Bomberman (3 kills in one Bomber blast), Dual Wield (unlock Body T3).
|
||||
- Win state: reach the floor-10 exit -> state 'won' victory screen.
|
||||
- Lose state: ghost timer hits 0 -> state 'lost' with run stats.
|
||||
- Pause menu (ESC) with Save + Quit, controls, and the bestiary reachable from it.
|
||||
- Complete contextual controls on title, HUD, shop, and pause screens.
|
||||
Finish by running: for i in 1 2 3 4 5; do node verify.js $i || break; done (all 0),
|
||||
and mentally stress a 200-tick session (the harness does this for you).
|
||||
EOF
|
||||
|
||||
cat > build/_review.md <<'EOF'
|
||||
You are an adversarial QA reviewer for Body Snatcher. Read AGENTS.md and the COMPLETE
|
||||
current index.html. Find bugs / missing features / spec violations and FIX them directly
|
||||
in index.html (do not just report). Focus on:
|
||||
- Any JS error or crash path (especially with mocked canvas/audio/localStorage).
|
||||
- Enemies whose AI or player kit is broken; abilities that throw.
|
||||
- Save/load edge cases (corrupt/missing/partial data) leaving bad state.
|
||||
- Missing or untriggered achievements.
|
||||
- Fog-of-war bugs.
|
||||
- Base ghost timer below 15 steps.
|
||||
- PACING VIOLATIONS (the most important): friendly fire between enemies; the whole floor
|
||||
swarming on spawn instead of ~6-tile line-of-sight-gated aggro; Sentinel/Turret that
|
||||
never overheat into a forced no-fire window.
|
||||
- Missing controls text on title / HUD / shop / pause; missing bestiary.
|
||||
After fixing, run and ensure ALL pass:
|
||||
node verify.js 1 && node verify.js 2 && node verify.js 3 && node verify.js 4 && node verify.js 5
|
||||
EOF
|
||||
|
||||
# ---- phase runner -----------------------------------------------------------
|
||||
run_phase() {
|
||||
local phase=$1 contract=$2 scope=$3 attempt ok p
|
||||
local prompt; prompt="$(cat "$contract")"$'\n\n'"$(cat "$scope")"
|
||||
for ((attempt=1; attempt<=MAX_RETRIES; attempt++)); do
|
||||
echo "=== Phase $phase (attempt $attempt/$MAX_RETRIES) ===" | tee -a "$LOG"
|
||||
pi -p -a $MODEL "$prompt" >"build/phase${phase}.attempt${attempt}.log" 2>&1 || true
|
||||
tail -n 5 "build/phase${phase}.attempt${attempt}.log" | tee -a "$LOG"
|
||||
ok=1
|
||||
for ((p=1; p<=phase; p++)); do
|
||||
if ! node verify.js "$p" >>"$LOG" 2>&1; then ok=0; fi
|
||||
done
|
||||
if [ $ok -eq 1 ]; then
|
||||
echo "=== Phase $phase PASSED (gates 1..$phase green) ===" | tee -a "$LOG"
|
||||
return 0
|
||||
fi
|
||||
echo "=== Phase $phase gate FAILED (attempt $attempt) ===" | tee -a "$LOG"
|
||||
node verify.js "$phase" 2>&1 | tail -n 16 | tee -a "$LOG"
|
||||
if [ $attempt -eq $MAX_RETRIES ]; then
|
||||
echo "=== Phase $phase: targeted fix from gate output ===" | tee -a "$LOG"
|
||||
local fix; fix="$(node verify.js "$phase" 2>&1 || true)"
|
||||
pi -p -a $MODEL "Phase $phase of Body Snatcher failed its verify.js gate. Read AGENTS.md and the CURRENT index.html. The gate output was:
|
||||
$fix
|
||||
Fix ONLY the specific failures — do NOT rewrite index.html from scratch. Then run 'node verify.js $phase' (and lower phases) until green." >"build/phase${phase}.fix.log" 2>&1 || true
|
||||
ok=1
|
||||
for ((p=1; p<=phase; p++)); do
|
||||
if ! node verify.js "$p" >>"$LOG" 2>&1; then ok=0; fi
|
||||
done
|
||||
if [ $ok -eq 1 ]; then
|
||||
echo "=== Phase $phase PASSED after fix ===" | tee -a "$LOG"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
done
|
||||
echo "=== Phase $phase FAILED after all retries ===" | tee -a "$LOG"
|
||||
return 1
|
||||
}
|
||||
|
||||
run_phase 1 build/_contract.md build/_p1.md || { echo "HALT: phase 1 failed" | tee -a "$LOG"; exit 1; }
|
||||
run_phase 2 build/_contract.md build/_p2.md || { echo "HALT: phase 2 failed" | tee -a "$LOG"; exit 1; }
|
||||
run_phase 3 build/_contract.md build/_p3.md || { echo "HALT: phase 3 failed" | tee -a "$LOG"; exit 1; }
|
||||
run_phase 4 build/_contract.md build/_p4.md || { echo "HALT: phase 4 failed" | tee -a "$LOG"; exit 1; }
|
||||
run_phase 5 build/_contract.md build/_p5.md || { echo "HALT: phase 5 failed" | tee -a "$LOG"; exit 1; }
|
||||
|
||||
echo "=== ADVERSARIAL REVIEW ===" | tee -a "$LOG"
|
||||
pi -p -a $MODEL "$(cat build/_review.md)" >build/review.log 2>&1 || true
|
||||
tail -n 5 build/review.log | tee -a "$LOG"
|
||||
|
||||
echo "=== FINAL VERIFICATION ===" | tee -a "$LOG"
|
||||
final=0
|
||||
for p in 1 2 3 4 5; do
|
||||
if node verify.js "$p" 2>&1 | tee -a "$LOG"; then
|
||||
echo "Phase $p: PASS" | tee -a "$LOG"
|
||||
else
|
||||
echo "Phase $p: FAIL" | tee -a "$LOG"; final=1
|
||||
fi
|
||||
done
|
||||
|
||||
echo "=== BUILD COMPLETE (final=$final) ===" | tee -a "$LOG"
|
||||
exit $final
|
||||
Reference in new issue
Block a user