feat(scripts): start.sh — install deps, run backend, open tmux
This commit is contained in:
Executable
+53
@@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# scripts/start.sh — install deps, run backend, open tmux session "chess"
|
||||||
|
set -euo pipefail
|
||||||
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||||
|
cd "$ROOT"
|
||||||
|
|
||||||
|
echo "[ai-chess] checking deps"
|
||||||
|
which stockfish >/dev/null || { echo "[ai-chess] installing stockfish"; brew install stockfish; }
|
||||||
|
which tmux >/dev/null || { echo "[ai-chess] installing tmux"; brew install tmux; }
|
||||||
|
which uv >/dev/null || { echo "[ai-chess] installing uv"; brew install uv; }
|
||||||
|
|
||||||
|
if [ ! -d .venv ]; then
|
||||||
|
uv venv
|
||||||
|
fi
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
source .venv/bin/activate
|
||||||
|
uv pip install -e ".[dev]" >/dev/null
|
||||||
|
|
||||||
|
echo "[ai-chess] fetching vendor JS"
|
||||||
|
"$ROOT/scripts/fetch-vendor.sh"
|
||||||
|
|
||||||
|
# kill existing
|
||||||
|
tmux kill-session -t chess 2>/dev/null || true
|
||||||
|
pkill -f 'python -m ai_chess' 2>/dev/null || true
|
||||||
|
sleep 0.3
|
||||||
|
|
||||||
|
# start backend
|
||||||
|
LOGS="$ROOT/logs"; mkdir -p "$LOGS"
|
||||||
|
nohup python -m ai_chess >"$LOGS/backend.log" 2>&1 &
|
||||||
|
backend_pid=$!
|
||||||
|
echo "[ai-chess] backend pid=$backend_pid; tail: $LOGS/backend.log"
|
||||||
|
|
||||||
|
# wait for backend
|
||||||
|
for _ in $(seq 1 40); do
|
||||||
|
if curl -fsS http://127.0.0.1:7833/api/state >/dev/null 2>&1; then break; fi
|
||||||
|
sleep 0.25
|
||||||
|
done
|
||||||
|
|
||||||
|
# bootstrap a new game so bindings exist before panes start
|
||||||
|
curl -fsS -X POST http://127.0.0.1:7833/api/new-game >/dev/null || {
|
||||||
|
echo "[ai-chess] failed to start new game; aborting"; exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
# create tmux session: pane 0 (white, left), pane 1 (black, right), pane 2 (log, bottom)
|
||||||
|
tmux new-session -d -s chess -x 220 -y 60 "$ROOT/scripts/pane-agent.sh white"
|
||||||
|
tmux split-window -h -p 50 -t chess:0.0 "$ROOT/scripts/pane-agent.sh black"
|
||||||
|
tmux split-window -v -p 15 -t chess:0 "tail -F $LOGS/backend.log"
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "[ai-chess] open: http://127.0.0.1:7833/"
|
||||||
|
echo "[ai-chess] attach: tmux attach -t chess"
|
||||||
|
echo
|
||||||
|
tmux attach -t chess
|
||||||
Reference in New Issue
Block a user