115 lines
7.4 KiB
Bash
Executable File
115 lines
7.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
MAX_RETRIES=${MAX_RETRIES:-3}
|
|
DISPATCH_TTL=${DISPATCH_TTL:-50m}
|
|
ROOT=$(cd "$(dirname "$0")" && pwd)
|
|
STATE_FILE="$ROOT/.build_state"
|
|
LOCK_DIR="$ROOT/.orchestrate.lock"
|
|
LOG_DIR="$ROOT/.build_logs"
|
|
|
|
if ! mkdir "$LOCK_DIR" 2>/dev/null; then
|
|
echo "Another orchestrate.sh instance is running. Remove $LOCK_DIR only if it is stale." >&2
|
|
exit 1
|
|
fi
|
|
trap 'rm -rf "$LOCK_DIR"' EXIT INT TERM
|
|
mkdir -p "$LOG_DIR"
|
|
cd "$ROOT"
|
|
|
|
if command -v timeout >/dev/null 2>&1; then
|
|
TIMEOUT=timeout
|
|
elif command -v gtimeout >/dev/null 2>&1; then
|
|
TIMEOUT=gtimeout
|
|
else
|
|
echo "GNU timeout is required (brew install coreutils)." >&2
|
|
exit 1
|
|
fi
|
|
|
|
state=$(tr -dc '0-9' < "$STATE_FILE" 2>/dev/null || true)
|
|
state=${state:-0}
|
|
|
|
run_pi() {
|
|
local name=$1 prompt=$2 log="$LOG_DIR/$1.log"
|
|
echo "==> Dispatch: $name"
|
|
if ! "$TIMEOUT" --kill-after=30 "$DISPATCH_TTL" pi -p "$prompt" 2>&1 | tee "$log"; then
|
|
echo "Dispatch failed or timed out: $name (see $log)" >&2
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
run_gate() {
|
|
local phase=$1 output
|
|
output=$(mktemp)
|
|
echo "==> Gate: phase $phase"
|
|
if PYGAME_HIDE_SUPPORT_PROMPT=1 SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
|
python tests/smoke.py --phase "$phase" >"$output" 2>&1; then
|
|
cat "$output"
|
|
rm -f "$output"
|
|
return 0
|
|
fi
|
|
cat "$output"
|
|
GATE_FAILURE=$(cat "$output")
|
|
rm -f "$output"
|
|
return 1
|
|
}
|
|
|
|
fix_until_green() {
|
|
local phase=$1 attempt=0
|
|
while ! run_gate "$phase"; do
|
|
attempt=$((attempt + 1))
|
|
if (( attempt > MAX_RETRIES )); then
|
|
echo "Phase $phase failed after $MAX_RETRIES retries." >&2
|
|
exit 1
|
|
fi
|
|
run_pi "phase-${phase}-fix-${attempt}" "Read AGENTS.md and plan.md completely. Phase $phase gate failed. Fix the implementation, not the test expectations, while preserving earlier phases. Run the gate before finishing. Actual failure:\n\n$GATE_FAILURE"
|
|
done
|
|
printf '%s\n' "$phase" > "$STATE_FILE"
|
|
state=$phase
|
|
}
|
|
|
|
if (( state < 1 )); then
|
|
run_pi phase-1 'Read AGENTS.md and plan.md completely. Implement Phase 1 Foundation exactly: constants, slotted typed entities, BSP dungeon generation, player/enemy models, and a minimal runnable pygame loop. Replace phase_1 in tests/smoke.py with substantive tests for 5 generated maps: >=3 non-overlapping rooms, connectivity by flood fill, and reachable floor-tile stairs on floors 0-8. Preserve later phase stubs. Run python tests/smoke.py --phase 1 before finishing. No TODOs or fake tests.'
|
|
fix_until_green 1
|
|
fi
|
|
|
|
if (( state < 2 )); then
|
|
echo "==> Phase 2 independent systems (parallel)"
|
|
run_pi phase-2-fov 'Read AGENTS.md and plan.md. Implement recursive shadowcasting FOV in engine/fov.py with radius 8, visible/explored updates, typing, and no stubs. Do not edit unrelated systems.' & p1=$!
|
|
run_pi phase-2-pathfinding 'Read AGENTS.md and plan.md. Implement A* pathfinding in engine/pathfinding.py using Manhattan distance, walls and occupied tiles as blockers, and a no-path fallback. Type every signature. Do not edit unrelated systems.' & p2=$!
|
|
run_pi phase-2-combat 'Read AGENTS.md and plan.md. Implement combat in engine/combat.py exactly per hit, armor, crit, damage, death, XP, and message-log rules. Type every signature. Do not edit unrelated systems.' & p3=$!
|
|
failed=0
|
|
wait "$p1" || failed=1
|
|
wait "$p2" || failed=1
|
|
wait "$p3" || failed=1
|
|
(( failed == 0 )) || { echo "A Phase 2 parallel dispatch failed." >&2; exit 1; }
|
|
run_pi phase-2-ai 'Read AGENTS.md and plan.md completely. FOV, pathfinding, and combat now exist. Implement all enemy AI dispatch behavior in ai/behaviors.py, including wander, chase/last-known, flee, ranged/kiting, phase cadence, split handling, and safe blocked-path fallback. Integrate without hidden state. Replace phase_2 in tests/smoke.py with substantive FOV, A*, 1000-attack combat-range, and corridor-chase AI tests. Preserve all earlier tests and later stubs. Run phases 1 and 2 before finishing.'
|
|
fix_until_green 2
|
|
fi
|
|
|
|
if (( state < 3 )); then
|
|
run_pi phase-3 'Read AGENTS.md and plan.md completely. Implement Phase 3 Content Layer: fixed item catalog, inventory/equipment and all potion/scroll effects; cumulative XP and leveling; exact roster/stats and all seven enemy types; depth-gated spawning; and the floor-9 boss arena with dragon breath, two healing potions, victory, and obtainable gear capable of damaging armor 8. Keep GameSession as sole mutable state and log every event. Replace phase_3 in tests/smoke.py with substantive roster, equip-stat, kill/XP/level-up, item-effect, boss-arena, and boss-winnability tests. Preserve prior tests. Run phases 1-3 before finishing. No stubs.'
|
|
fix_until_green 3
|
|
fi
|
|
|
|
if (( state < 4 )); then
|
|
run_pi phase-4a 'Read AGENTS.md and plan.md completely. Implement Phase 4a: GameSession integration, exact JSON save/load for all required state, permadeath save deletion, game actions/intents, menus/state transitions, generated in-memory pygame mixer sound effects, mute, and silent audio failure fallback. Add no assets. Preserve prior systems and tests. Do not attempt rendering yet. No stubs.'
|
|
run_pi phase-4b 'Read AGENTS.md and plan.md completely. Implement Phase 4b: all procedural multi-color pixel-art patterns and cached rasterization; pure renderer composition; distinct player/equipment, seven enemies, items, and visibly blitted glowing stairs; textured/beveled tiles, FOV torch lighting and explored dimming, shadows/vignette; capped particles, shake, easing camera, idle frames; polished bordered UI, bars/icons/log/context prompts; complete pygame main menu/game/death/victory/how-to-play/inventory/equipment/potion/scroll flow and every documented key. New Game must show How to Play. No flat-square entity art and no external assets. Integrate with existing state/actions.'
|
|
run_pi phase-4c-tests 'Read AGENTS.md and plan.md completely. Finish Phase 4 and replace phase_4 in tests/smoke.py with substantive tests for save/load equality, menu states, simulated g pickup and f descent, generated audio mute/failure safety, pure rendering, and proof the renderer blits a distinct stairs sprite. Extend the full suite with safe headless startup/playthrough checks and floor 0-8 stairs reachability. Preserve all prior tests; never weaken expectations. Fix implementation failures and run python tests/smoke.py --phase 4 before finishing.'
|
|
fix_until_green 4
|
|
fi
|
|
|
|
echo "==> Final acceptance backstop"
|
|
for attempt in $(seq 1 "$MAX_RETRIES"); do
|
|
if ! run_pi "goal-audit-$attempt" 'Read AGENTS.md and plan.md completely. Audit EVERY unchecked acceptance criterion in plan.md against the actual game. Run the complete smoke suite and a bounded headless main.py playthrough covering menu, How to Play, movement/combat, g pickup, f descent, save/quit/reload, audio-disabled mode, death, and victory. Inspect visuals structurally to ensure distinct multi-color procedural sprites, visible stairs, lighting, particles, camera/shake, and polished UI are genuinely wired into rendering. Fix every failure you find; do not merely report it, weaken tests, add stubs, or stop early. Ensure all 10 floors are winnable and the dragon is damageable. Finish only when python tests/smoke.py passes.'; then
|
|
echo "Goal-audit dispatch unavailable; running the local acceptance audit." >&2
|
|
fi
|
|
if run_gate 4 && python tests/audit_playthrough.py; then
|
|
echo "Underdepths build complete: all gates pass."
|
|
exit 0
|
|
fi
|
|
echo "Acceptance backstop attempt $attempt failed; retrying."
|
|
done
|
|
|
|
echo "Final acceptance backstop failed after $MAX_RETRIES attempts." >&2
|
|
exit 1
|