feat(menu): unified home screen + ai-vs-ai/play split + human mode

Routes:
- GET /        → menu.html (new home/menu).
- GET /ai-vs-ai → old index.html (AI-vs-AI live game).
- GET /play    → same index.html; app.js detects the human side from
  bindings and enables chessground move input on that side only.
- GET /games   → unchanged.

Backend:
- coordinator: 'human' is now an allowed agent type alongside claude/codex.
  start_new_game accepts overrides[side].agent = 'human'. _send_first /
  _send_turn / watchdog skip human sides.
- POST /api/human-move: humans submit moves from the browser (UCI/SAN
  + optional comment); rejected if it's not their turn or side isn't human.
- /api/options now also returns 'all_agents' = AI agents + 'human' for the
  human-vs-AI configurator.
- pane-agent.sh: when binding agent is 'human', the pane just prints a
  note and sleeps — no claude/codex is launched for that side.

Frontend menu (new public/menu.{html,css,js}):
- 'underground tournament' aesthetic: Major Mono Display title, JetBrains
  Mono body (Google Fonts), warm gold (#c0a060) / crimson (#c04040)
  accents, subtle film-grain overlay.
- Three big mode cards: 01 AI×AI, 02 HUMAN×AI, 03 GAMES·STATS.
- Inline configurator below the cards: WHITE / VS / BLACK columns with
  agent / model / persona selects, persona description preview, swap +
  randomize tools, abort-current warning that links to /api/abort-game.
- Start button routes to /ai-vs-ai or /play depending on whether a human
  side was picked. Enter submits.
- HUD strip with tmux / stockfish / games-played counters.

app.js changes:
- Chessground constructed with viewOnly toggling; renderBoard rebuilds
  movable.color + dests = legal moves at the live FEN from chess.js for
  the human's turn only; board is read-only when scrubbing history,
  during the AI's turn, or in AI-vs-AI.
- humanSide() helper reads bindings; orientation auto-flips when the
  human plays black.
This commit is contained in:
ai-chess
2026-05-15 01:10:47 +03:00
parent 42f23c71cc
commit ab38cda1bd
7 changed files with 889 additions and 13 deletions
+34 -2
View File
@@ -204,6 +204,27 @@ def build_app(state: state_mod.AppState) -> FastAPI:
await start_new_game(state, overrides=overrides)
return state.game.get_state() # type: ignore[union-attr]
@app.post("/api/human-move")
async def human_move(body: dict[str, Any]) -> dict[str, Any]:
"""The human side submits a move from the browser. Accepts UCI/SAN
plus an optional comment. Only succeeds if the side-to-move is bound
to agent='human'."""
if state.game is None or state.game.is_game_over():
return {"ok": False, "reason": "no_active_game"}
side_to_move = state.game.side_to_move
binding = state.bindings.get(side_to_move)
if not binding or binding.agent != "human":
return {"ok": False, "reason": "not_your_turn_or_not_human"}
move_str = str(body.get("move") or "").strip()
if not move_str:
return {"ok": False, "reason": "missing_move"}
comment = body.get("comment")
if comment is not None:
comment = str(comment)
from ai_chess.mcp_server import build_tools_for_side
tools = build_tools_for_side(side_to_move, state)
return await tools["move"]({"move": move_str, "comment": comment})
@app.post("/api/abort-game")
async def abort_game() -> dict[str, Any]:
if state.game is None:
@@ -226,7 +247,8 @@ def build_app(state: state_mod.AppState) -> FastAPI:
from ai_chess.coordinator import AGENTS, MODEL_OPTIONS
from ai_chess.prompts import list_prompt_presets, DEFAULT_PROMPT
return {
"agents": AGENTS,
"agents": AGENTS, # only AI agent ids — used for AI-vs-AI screen
"all_agents": AGENTS + ["human"],
"models": MODEL_OPTIONS,
"prompts": list_prompt_presets(),
"defaults": {"prompt": DEFAULT_PROMPT},
@@ -419,7 +441,17 @@ def build_app(state: state_mod.AppState) -> FastAPI:
app.mount("/static", StaticFiles(directory=state_mod.PUBLIC_DIR), name="static")
@app.get("/")
async def index() -> FileResponse:
async def menu_page() -> FileResponse:
return FileResponse(state_mod.PUBLIC_DIR / "menu.html")
@app.get("/ai-vs-ai")
async def ai_vs_ai_page() -> FileResponse:
return FileResponse(state_mod.PUBLIC_DIR / "index.html")
@app.get("/play")
async def play_page() -> FileResponse:
# Same UI as /ai-vs-ai — app.js detects the human binding and
# enables board interactivity for that side.
return FileResponse(state_mod.PUBLIC_DIR / "index.html")
@app.get("/games")