Files
ai-chess/scripts/start.sh
T
ai-chess 4c5b306a9a fix(mcp,start): JSON-RPC notifications return 202; no tmux attach
- mcp_post: notifications (no `id` field) → HTTP 202 with empty body,
  per streamable-HTTP MCP transport spec. Fixes rmcp 'transport channel
  closed' on codex's notifications/initialized.
- start.sh: don't attach to tmux; print URL only. Backend + tmux session
  run in background. UI is the only viewing surface.
- scripts/stop.sh: convenience teardown.
2026-05-14 23:41:11 +03:00

60 lines
2.3 KiB
Bash
Executable File

#!/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"
# Give claude/codex ~12s to boot in their panes, then ask coordinator to
# inject the first prompt to the white pane.
( sleep 12 && curl -fsS -X POST http://127.0.0.1:7833/api/dispatch-first >/dev/null ) &
echo
echo "[ai-chess] открой в браузере: http://127.0.0.1:7833/"
echo "[ai-chess] первый промпт улетит белому через ~12с (после старта агентов)"
echo "[ai-chess] tmux работает в фоне; если очень хочется подцепиться руками:"
echo " tmux attach -t chess"
echo "[ai-chess] остановить: ./scripts/stop.sh (или вручную:"
echo " tmux kill-session -t chess; pkill -f 'python -m ai_chess')"