feat: docker container + deploy on chess.danosito.com
Container: - Dockerfile: python:3.12-slim with stockfish + tmux apt; src copied before pip install -e so the editable wheel actually finds ai_chess. fetch-vendor.sh runs at build time so the image is self-contained. - docker-compose.yml: two networks (default + caddy-network), alias 'chessai' on caddy-network, AI_CHESS_HOST=0.0.0.0 env so uvicorn listens on all interfaces (Caddy reverse-proxies over the network), volumes for games/, logs/, config/ to persist across rebuilds. - __main__.py reads AI_CHESS_HOST + AI_CHESS_PORT from env (falls back to 127.0.0.1:7833 for local dev). - .dockerignore excludes .git, .venv, runtime dirs, screenshots. - deploy/chess.danosito.com.caddy: site snippet, imports header_common, reverse_proxy chessai:7833. Live game UX fixes that landed alongside the deploy: - Snap viewPly to null on every move event so an accidental history-scrub no longer leaves the board locked; previously the only way out was a hard refresh. - movable.events.after wired in chessground constructor (instead of top-level events.move) so user moves are submitted only when they pass chessground's own legality check. - Hide stockfish entirely in human-vs-AI: no eval bar, no best-move arrow, no pv string. AI-vs-AI keeps the full spectator HUD. Coordinator / tmux: - New-game rebuilds the 'chess' tmux session from scratch so pane-agent.sh picks up the new bindings (different agent on a side / human side) instead of running with stale state. - /api/dispatch-first now queues the dispatch in a background task and sleeps 12 s first to let claude/codex finish booting inside the panes — paste-buffer was landing on a still-booting bash before.
This commit is contained in:
+35
-17
@@ -40,18 +40,21 @@ const cg = Chessground($("board"), {
|
||||
viewOnly: false,
|
||||
fen: "start",
|
||||
orientation: "white",
|
||||
movable: { free: false, color: undefined, dests: new Map(), showDests: true },
|
||||
movable: {
|
||||
free: false, color: undefined, dests: new Map(), showDests: true,
|
||||
events: {
|
||||
after: (orig, dest) => {
|
||||
// movable.events.after fires only on LEGAL completed user moves —
|
||||
// perfect for submitting a human move to the server.
|
||||
submitHumanMove(orig, dest);
|
||||
},
|
||||
},
|
||||
},
|
||||
draggable: { enabled: true, showGhost: true },
|
||||
selectable: { enabled: true },
|
||||
drawable: { enabled: true, visible: true },
|
||||
events: {
|
||||
move: (orig, dest) => {
|
||||
// Only used in human-vs-AI mode; AI-vs-AI sets movable.color to undefined,
|
||||
// making this unreachable.
|
||||
submitHumanMove(orig, dest);
|
||||
},
|
||||
},
|
||||
});
|
||||
window.cg = cg; // for debugging
|
||||
|
||||
// ---------- responsive board sizing ----------
|
||||
function fitBoard() {
|
||||
@@ -123,12 +126,6 @@ function renderBoard() {
|
||||
const uci = moves[idx].uci || "";
|
||||
if (uci.length >= 4) lastMove = [uci.slice(0, 2), uci.slice(2, 4)];
|
||||
}
|
||||
const e = STATE.evalByFen.get(fenKey(fen));
|
||||
const shapes = (e && e.best_uci && e.best_uci.length >= 4)
|
||||
? [{ orig: e.best_uci.slice(0, 2), dest: e.best_uci.slice(2, 4), brush: "green" }]
|
||||
: [];
|
||||
|
||||
// Human-vs-AI: enable board moves only on the human's turn at the live FEN.
|
||||
const hSide = humanSide();
|
||||
const sideToMove = STATE.game.side_to_move;
|
||||
const isHumanTurn = (
|
||||
@@ -137,8 +134,16 @@ function renderBoard() {
|
||||
&& !STATE.game.status?.result
|
||||
);
|
||||
|
||||
// Stockfish hints are NOT shown to a human player — eval bar + best-move
|
||||
// arrow would be cheating. They stay on for spectator (AI-vs-AI) games.
|
||||
const showHints = !hSide;
|
||||
const e = showHints ? STATE.evalByFen.get(fenKey(fen)) : null;
|
||||
const shapes = (e && e.best_uci && e.best_uci.length >= 4)
|
||||
? [{ orig: e.best_uci.slice(0, 2), dest: e.best_uci.slice(2, 4), brush: "green" }]
|
||||
: [];
|
||||
|
||||
const movable = isHumanTurn
|
||||
? { free: false, color: hSide, dests: legalDestsForFen(fen), showDests: true, events: {} }
|
||||
? { free: false, color: hSide, dests: legalDestsForFen(fen), showDests: true }
|
||||
: { free: false, color: undefined, dests: new Map(), showDests: false };
|
||||
|
||||
cg.set({
|
||||
@@ -151,7 +156,14 @@ function renderBoard() {
|
||||
viewOnly: !isHumanTurn,
|
||||
});
|
||||
$("live-btn").hidden = STATE.viewPly === null;
|
||||
applyEvalForFen(fen);
|
||||
if (showHints) {
|
||||
applyEvalForFen(fen);
|
||||
} else {
|
||||
// Wipe any leftover eval visual from a prior spectator session.
|
||||
$("eval-text").textContent = "";
|
||||
$("eval-fill").style.height = "50%";
|
||||
$("sf-pv").textContent = "";
|
||||
}
|
||||
}
|
||||
|
||||
function renderChat() {
|
||||
@@ -345,6 +357,9 @@ function applySnapshot(s) {
|
||||
STATE.viewPly = null;
|
||||
STATE.evalByFen.clear();
|
||||
for (const e of (s.evals || [])) storeEval(e);
|
||||
// Hide the eval bar in human-vs-AI to avoid cheating.
|
||||
const evalCol = $("eval-col");
|
||||
if (evalCol) evalCol.style.display = humanSide() ? "none" : "";
|
||||
renderBoard(); renderChat(); renderHistory(); renderStatus();
|
||||
refreshGamesLink();
|
||||
}
|
||||
@@ -374,13 +389,16 @@ function connect() {
|
||||
if (!ev.status?.result) {
|
||||
STATE.game.side_to_move = ev.side === "white" ? "black" : "white";
|
||||
}
|
||||
// Always snap back to live on a new move — otherwise an accidental
|
||||
// history-scrub leaves the board locked into a past position and the
|
||||
// user can't make their next move without reloading.
|
||||
STATE.viewPly = null;
|
||||
// think timer: mover finished, opponent starts
|
||||
if (THINK.startedAt != null && THINK.side === ev.side) {
|
||||
THINK.lastMs[ev.side] = Date.now() - THINK.startedAt;
|
||||
}
|
||||
THINK.startedAt = ev.status?.result ? null : Date.now();
|
||||
THINK.side = ev.status?.result ? null : (ev.side === "white" ? "black" : "white");
|
||||
// stay live unless user clicked back
|
||||
renderBoard(); renderChat(); renderHistory(); renderStatus(); renderThinking();
|
||||
log(`${ev.side} ${ev.san} «${ev.comment || ""}»`);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user