magicciv/scripts/claude-player-server.sh
Natalie aaa7e24357 feat(@projects/@magic-civilization): add os-specific godot runner logic
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
2026-05-17 02:06:12 -07:00

68 lines
2.5 KiB
Bash
Executable file

#!/usr/bin/env bash
# p2-67 Phase 3 — Launch wrapper for the Claude Player headless harness.
#
# Spawns flatpak Godot headless with the claude_player_main scene and
# stdin/stdout piped through. Designed to be exec'd by the Claude SDK
# adapter as a child process — `child = spawn("scripts/claude-player-server.sh")`.
#
# Env vars are forwarded into the sandbox (see CLAUDE_PLAYER_API.md):
# CP_SEED, CP_PLAYERS, CP_CLAUDE_SLOT, CP_MAP_SIZE, CP_MAP_TYPE,
# CP_OMNISCIENT, CP_TIMEOUT_SEC, CP_LOG_FILE.
#
# Exit code 0 on clean shutdown (shutdown request received or stdin EOF).
# Non-zero on protocol error or harness crash.
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
# Defaults — adapter overrides via env.
: "${CP_SEED:=42}"
: "${CP_PLAYERS:=2}"
: "${CP_CLAUDE_SLOT:=0}"
: "${CP_MAP_SIZE:=duel}"
: "${CP_MAP_TYPE:=continents}"
: "${CP_OMNISCIENT:=0}"
: "${CP_TIMEOUT_SEC:=60}"
: "${CP_LOG_FILE:=}"
# Pure-headless mode — no Wayland needed. JSON-Lines speaks to stdout.
#
# Linux uses flatpak Godot (matches the rest of the apricot pipeline).
# macOS uses the locally-installed `godot` binary (Homebrew); a parallel
# flatpak runtime just for this harness is silly when native Godot 4
# works directly. Env-var passthrough is automatic for the native path.
export CP_SEED CP_PLAYERS CP_CLAUDE_SLOT CP_MAP_SIZE CP_MAP_TYPE \
CP_OMNISCIENT CP_TIMEOUT_SEC CP_LOG_FILE
case "$(uname -s)" in
Darwin)
GODOT_BIN="${GODOT_BIN:-godot}"
if ! command -v "$GODOT_BIN" >/dev/null 2>&1; then
echo "ERROR: no godot binary on PATH (set GODOT_BIN or 'brew install godot')." >&2
exit 1
fi
exec "$GODOT_BIN" \
--path "$PROJECT_DIR/src/game" \
--headless \
--rendering-method gl_compatibility \
res://engine/scenes/headless/claude_player_main.tscn
;;
*)
exec flatpak run --user \
--env=CP_SEED="$CP_SEED" \
--env=CP_PLAYERS="$CP_PLAYERS" \
--env=CP_CLAUDE_SLOT="$CP_CLAUDE_SLOT" \
--env=CP_MAP_SIZE="$CP_MAP_SIZE" \
--env=CP_MAP_TYPE="$CP_MAP_TYPE" \
--env=CP_OMNISCIENT="$CP_OMNISCIENT" \
--env=CP_TIMEOUT_SEC="$CP_TIMEOUT_SEC" \
--env=CP_LOG_FILE="$CP_LOG_FILE" \
org.godotengine.Godot \
--path "$PROJECT_DIR/src/game" \
--headless \
--rendering-method gl_compatibility \
res://engine/scenes/headless/claude_player_main.tscn
;;
esac