rewrite: TS monorepo — pi SDK stateless agents, Postgres+pg-boss, SvelteKit themed UI; legacy moved to legacy/
This commit is contained in:
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
# scripts/fetch-vendor.sh
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
VENDOR="$ROOT/public/vendor"
|
||||
mkdir -p "$VENDOR"
|
||||
|
||||
fetch() {
|
||||
local url="$1"; local out="$2"
|
||||
if [ -f "$VENDOR/$out" ]; then return 0; fi
|
||||
echo "[vendor] $url"
|
||||
curl -fsSL "$url" -o "$VENDOR/$out"
|
||||
}
|
||||
|
||||
# chess.js 0.13.4 — last UMD release; provides global `Chess` constructor with
|
||||
# snake_case API (load_pgn, history({verbose:true}), move, fen).
|
||||
fetch "https://cdn.jsdelivr.net/npm/chess.js@0.13.4/chess.js" chess.min.js
|
||||
|
||||
# chessground 9.2.1
|
||||
fetch "https://cdn.jsdelivr.net/npm/chessground@9.2.1/dist/chessground.min.js" chessground.min.js
|
||||
fetch "https://cdn.jsdelivr.net/npm/chessground@9.2.1/assets/chessground.base.css" chessground.base.css
|
||||
fetch "https://cdn.jsdelivr.net/npm/chessground@9.2.1/assets/chessground.brown.css" chessground.brown.css
|
||||
fetch "https://cdn.jsdelivr.net/npm/chessground@9.2.1/assets/chessground.cburnett.css" chessground.cburnett.css
|
||||
|
||||
# xterm.js 5.3.0
|
||||
fetch "https://cdn.jsdelivr.net/npm/xterm@5.3.0/lib/xterm.js" xterm.js
|
||||
fetch "https://cdn.jsdelivr.net/npm/xterm@5.3.0/css/xterm.css" xterm.css
|
||||
fetch "https://cdn.jsdelivr.net/npm/xterm-addon-fit@0.8.0/lib/xterm-addon-fit.js" xterm-addon-fit.js
|
||||
|
||||
echo "[vendor] done"
|
||||
Executable
+98
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env bash
|
||||
# scripts/pane-agent.sh <white|black>
|
||||
# Launched in a tmux pane; talks to backend on 127.0.0.1:7833 to figure out
|
||||
# which agent (claude|codex) plays this side, writes per-side config files
|
||||
# under ./config/, then exec's the agent TUI.
|
||||
set -euo pipefail
|
||||
|
||||
side="${1:?usage: pane-agent.sh <white|black>}"
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
CFG="$ROOT/config"
|
||||
mkdir -p "$CFG"
|
||||
|
||||
# wait until backend ready
|
||||
for _ in $(seq 1 120); do
|
||||
if curl -fsS "http://127.0.0.1:7833/api/state" >/dev/null 2>&1; then break; fi
|
||||
sleep 0.5
|
||||
done
|
||||
|
||||
# poll agent binding (start.sh POSTs /api/new-game before creating panes)
|
||||
agent=""
|
||||
for _ in $(seq 1 120); do
|
||||
agent="$(curl -fsS "http://127.0.0.1:7833/api/agent-binding/${side}" 2>/dev/null \
|
||||
| python3 -c 'import sys,json;
|
||||
try: print(json.load(sys.stdin).get("agent",""))
|
||||
except Exception: print("")' 2>/dev/null || true)"
|
||||
if [ -n "$agent" ]; then break; fi
|
||||
sleep 0.5
|
||||
done
|
||||
|
||||
if [ -z "$agent" ]; then
|
||||
echo "[pane-agent] no agent binding for $side after 60s — dropping to shell"
|
||||
exec bash
|
||||
fi
|
||||
|
||||
case "$side" in
|
||||
white) claude_theme='light' ; codex_theme='Catppuccin Latte' ;;
|
||||
black) claude_theme='dark' ; codex_theme='Catppuccin Mocha' ;;
|
||||
*) echo "bad side: $side"; exec bash ;;
|
||||
esac
|
||||
|
||||
echo "[pane-agent] side=$side agent=$agent claude_theme=$claude_theme codex_theme=\"$codex_theme\""
|
||||
|
||||
if [ "$agent" = "human" ]; then
|
||||
cat <<EOF
|
||||
[pane-agent] $side is controlled by a human — playing through the browser.
|
||||
Nothing to run here. You can leave this pane attached or detach.
|
||||
EOF
|
||||
exec sleep infinity
|
||||
fi
|
||||
|
||||
cd "$ROOT"
|
||||
|
||||
: "${CLAUDE_BIN:=$(command -v claude || echo /usr/local/bin/claude)}"
|
||||
: "${CODEX_BIN:=$(command -v codex || echo /usr/local/bin/codex)}"
|
||||
|
||||
case "$agent" in
|
||||
claude)
|
||||
cat > "$CFG/claude-settings.${side}.json" <<EOF
|
||||
{
|
||||
"theme": "${claude_theme}",
|
||||
"permissions": { "allow": ["*"], "defaultMode": "bypassPermissions" }
|
||||
}
|
||||
EOF
|
||||
cat > "$CFG/claude-mcp.${side}.json" <<EOF
|
||||
{
|
||||
"mcpServers": {
|
||||
"chess": {
|
||||
"type": "http",
|
||||
"url": "http://127.0.0.1:7833/mcp/${side}"
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
exec "$CLAUDE_BIN" \
|
||||
--model opus \
|
||||
--effort max \
|
||||
--mcp-config "$CFG/claude-mcp.${side}.json" \
|
||||
--settings "$CFG/claude-settings.${side}.json" \
|
||||
--strict-mcp-config \
|
||||
--dangerously-skip-permissions
|
||||
;;
|
||||
|
||||
codex)
|
||||
# Override the global config's chess MCP url (each side talks to its own
|
||||
# path). The user's persistent ~/.codex/config.toml does NOT get
|
||||
# rewritten — we just pass an inline override.
|
||||
exec "$CODEX_BIN" \
|
||||
-c 'model="gpt-5.5"' \
|
||||
-c 'model_reasoning_effort="xhigh"' \
|
||||
-c 'service_tier="fast"' \
|
||||
-c "tui.theme=\"${codex_theme}\"" \
|
||||
-c "mcp_servers.chess.url=\"http://127.0.0.1:7833/mcp/${side}\"" \
|
||||
--dangerously-bypass-approvals-and-sandbox
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "unknown agent: $agent"; exec bash ;;
|
||||
esac
|
||||
Executable
+59
@@ -0,0 +1,59 @@
|
||||
#!/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')"
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# scripts/stop.sh — tear down the tmux session and backend
|
||||
tmux kill-session -t chess 2>/dev/null && echo "[ai-chess] tmux session 'chess' killed" || true
|
||||
pkill -f 'python -m ai_chess' 2>/dev/null && echo "[ai-chess] backend stopped" || true
|
||||
Reference in New Issue
Block a user