feat: prompt presets, setup dialog, /games + leaderboard, one-game gate

Backend:
- prompts.py: 5 personality presets (уличный_гопник default, профессор,
  поэт, молчун, шут). Each provides voice + label + description.
  build_system_prompt accepts `preset` parameter; the MCP-tools section
  + must-call-move rule is shared common tail.
- coordinator: `start_new_game` now accepts `overrides` ({white: {agent,
  model, prompt}, black: {...}}) — missing fields filled randomly.
  MODEL_OPTIONS published per agent.
- AppState.prompts tracks the preset id per side; persisted into game's
  agents dict and PGN.
- AppState.eval_cache cleared on new_game (was per-life-of-process before).
- persistence.save_game now stores full history (with comments) and the
  per-position eval cache in the game JSON.
- ChessGame.abort() — manual game termination with result='*' and
  Termination='aborted'.
- New endpoints:
  • GET  /api/options   — agents, models per agent, prompt presets.
  • GET  /api/stats     — leaderboard aggregated from games/*.json:
        per (agent, model) and per persona, with score = wins + 0.5*draws.
  • POST /api/abort-game — force-end current game.
- POST /api/new-game now returns 409 when a game is in progress.
- GET  /api/games[/{id}[/pgn]] also 409 while in progress — gallery is
  hidden behind the one-game-at-a-time rule.

Frontend:
- New setup dialog: per-side agent / model / persona selects, swap +
  random shortcuts, persona description preview, abort button inline
  when current game blocks the start.
- 'games & stats' link in the board footer; greyed out while a game is
  active.
- /games page reworked: leaderboard (player × model + by persona),
  games table with persona labels, replay panel showing eval per ply
  with prev/next/first/last + arrow-key nav.
- chess.js loadPgn → load_pgn fix consolidated; replay prefers saved
  history (comments + side) over PGN parse when available.
This commit is contained in:
ai-chess
2026-05-15 00:40:35 +03:00
parent 0657cec846
commit 37bac9b0f6
12 changed files with 952 additions and 124 deletions
+75 -20
View File
@@ -2,34 +2,89 @@
<html lang="ru">
<head>
<meta charset="utf-8" />
<title>ai-chess — games</title>
<title>ai-chess — games & stats</title>
<link rel="stylesheet" href="/static/vendor/chessground.base.css" />
<link rel="stylesheet" href="/static/vendor/chessground.brown.css" />
<link rel="stylesheet" href="/static/vendor/chessground.cburnett.css" />
<link rel="stylesheet" href="/static/style.css" />
</head>
<body>
<main style="padding: 16px;">
<h1>Games</h1>
<a href="/">← back to live</a>
<table id="games-table" style="width: 100%; margin-top: 16px;">
<thead><tr><th>id</th><th>white</th><th>black</th><th>result</th><th>termination</th><th>moves</th><th>pgn</th></tr></thead>
<tbody></tbody>
</table>
<hr />
<div id="replay-wrap" style="display: none;">
<h3 id="replay-title"></h3>
<div style="display: grid; grid-template-columns: 360px 1fr; gap: 16px;">
<div id="replay-board" style="width: 360px; aspect-ratio: 1/1;"></div>
<div>
<div>
<button id="prev">←</button>
<button id="next">→</button>
<span id="ply">ply 0</span>
<main id="games-page">
<header id="games-page-header">
<a id="back-link" href="/">← back to live</a>
<h1>games & stats</h1>
<span id="games-count"></span>
</header>
<div id="blocked-banner" hidden>
<strong>Game in progress.</strong> Finish or abort it on the
<a href="/">main page</a> before browsing past games.
</div>
<div id="page-grid">
<section id="stats-pane">
<header class="col-header"><span>leaderboard (player × model)</span></header>
<table id="leaderboard">
<thead>
<tr>
<th>agent / model</th>
<th>games</th>
<th>wins</th>
<th>draws</th>
<th>losses</th>
<th>score</th>
<th>winrate</th>
</tr>
</thead>
<tbody></tbody>
</table>
<header class="col-header"><span>by persona</span></header>
<table id="leaderboard-prompts">
<thead>
<tr><th>persona</th><th>games</th><th>wins</th><th>draws</th><th>losses</th><th>score</th></tr>
</thead>
<tbody></tbody>
</table>
</section>
<section id="games-pane">
<header class="col-header"><span>games</span></header>
<table id="games-table">
<thead>
<tr>
<th>id</th>
<th>white</th>
<th>black</th>
<th>result</th>
<th>termination</th>
<th>moves</th>
<th>pgn</th>
</tr>
</thead>
<tbody></tbody>
</table>
<div id="replay-wrap" hidden>
<header class="col-header"><span id="replay-title">replay</span>
<button id="replay-close" type="button">close</button>
</header>
<div id="replay-layout">
<div id="replay-board"></div>
<aside id="replay-side">
<div id="replay-controls">
<button id="replay-first">⏮</button>
<button id="replay-prev">←</button>
<button id="replay-next">→</button>
<button id="replay-last">⏭</button>
<span id="replay-ply">ply 0/0</span>
<span id="replay-eval"></span>
</div>
<ol id="replay-history"></ol>
</aside>
</div>
<ol id="replay-history" style="max-height: 60vh; overflow: auto;"></ol>
</div>
</div>
</section>
</div>
</main>
<script src="/static/games.js" type="module"></script>