feat(ui): chat-bubbles layout, fix eval bar visibility, no terminals

UI rewrite per user feedback:
- Remove agent terminal panels entirely (tmux runs headlessly).
- Left column: chat with colored bubbles per move (white→light, black→
  dark, click to jump to ply, label shows agent+side+SAN).
- Right column: SAN move history (lichess style, click to jump).
- Center: board, untouched, but now constrained so it stops overflowing.
- Eval bar between chat and board, vertical with cp/mate text; the
  earlier visual issue was pure CSS (no explicit height) — bar fills
  full column height now.
- Keyboard nav: ←/→/space.
- Bottom log strip kept (compact).

Backend: TmuxTailer no longer started in lifespan (UI doesn't need
term_chunk events). Stockfish + eval_bridge now log explicit errors
to backend.log on startup failure.
This commit is contained in:
ai-chess
2026-05-14 23:51:24 +03:00
parent 4c5b306a9a
commit 6f4525d59f
4 changed files with 299 additions and 179 deletions
+141 -81
View File
@@ -1,108 +1,137 @@
import { Chess } from "/static/vendor/chess.min.js"; import { Chess } from "/static/vendor/chess.min.js";
import { Chessground } from "/static/vendor/chessground.min.js"; import { Chessground } from "/static/vendor/chessground.min.js";
const Terminal = window.Terminal;
const FitAddon = window.FitAddon;
const wsUrl = `${location.protocol === "https:" ? "wss" : "ws"}://${location.host}/ws`; const wsUrl = `${location.protocol === "https:" ? "wss" : "ws"}://${location.host}/ws`;
const $ = (id) => document.getElementById(id); const $ = (id) => document.getElementById(id);
const STATE = { const STATE = {
game: null, game: null,
settings: null, settings: null,
bindings: null, bindings: null, // {white: {agent, model, ...}, black: {...}}
viewPly: null, // null = live viewPly: null, // null = live; otherwise integer ply (1-based)
}; };
window._STATE = STATE; // for debugging
const cg = Chessground($("board"), { const cg = Chessground($("board"), {
viewOnly: true, viewOnly: true,
fen: "start", fen: "start",
orientation: "white", orientation: "white",
movable: { free: false, color: undefined, dests: new Map() }, movable: { free: false },
drawable: { enabled: true, visible: true }, drawable: { enabled: true, visible: true },
}); });
const terms = { // ---------- agent labels ----------
white: makeTerm(), function agentOfSide(side) {
black: makeTerm(), return STATE.bindings?.[side]?.agent || "?";
};
let termsAttached = false;
function makeTerm() {
const t = new Terminal({
convertEol: true, fontSize: 12, cursorBlink: false,
theme: { background: "#1a1a1a", foreground: "#e7e5e4" },
});
const fit = new FitAddon.FitAddon();
t.loadAddon(fit);
return { term: t, fit };
} }
function agentDisplay(side) {
function attachTerms() { const b = STATE.bindings?.[side];
if (termsAttached) return; if (!b) return side;
if (!STATE.bindings || !STATE.bindings.white) return; return `${b.agent} (${side})`;
const codexSide = STATE.bindings.white.agent === "codex" ? "white" : "black";
const claudeSide = codexSide === "white" ? "black" : "white";
terms[codexSide].term.open($("term-codex"));
terms[claudeSide].term.open($("term-claude"));
setTimeout(() => {
try { terms.white.fit.fit(); } catch (e) {}
try { terms.black.fit.fit(); } catch (e) {}
}, 50);
$("agent-codex").classList.toggle("theme-light", codexSide === "white");
$("agent-codex").classList.toggle("theme-dark", codexSide === "black");
$("agent-claude").classList.toggle("theme-light", claudeSide === "white");
$("agent-claude").classList.toggle("theme-dark", claudeSide === "black");
$("agent-codex").querySelector('[data-bind="codex-side"]').textContent = codexSide;
$("agent-claude").querySelector('[data-bind="claude-side"]').textContent = claudeSide;
termsAttached = true;
} }
// ---------- rendering ----------
function renderBoard() { function renderBoard() {
if (!STATE.game) return; if (!STATE.game) return;
let fen = STATE.game.fen; let fen = STATE.game.fen;
if (STATE.viewPly !== null) { let lastMove = undefined;
const moves = (STATE.game.history || []).filter(h => h.san);
if (STATE.viewPly !== null && STATE.viewPly >= 0) {
const c = new Chess(); const c = new Chess();
const moves = STATE.game.history.filter(h => h.san);
for (let i = 0; i < STATE.viewPly; i++) c.move(moves[i].san); for (let i = 0; i < STATE.viewPly; i++) c.move(moves[i].san);
fen = c.fen(); fen = c.fen();
if (STATE.viewPly > 0) {
const m = moves[STATE.viewPly - 1];
const uci = m.uci || "";
if (uci.length >= 4) lastMove = [uci.slice(0, 2), uci.slice(2, 4)];
}
} else if (moves.length) {
const m = moves[moves.length - 1];
const uci = m.uci || "";
if (uci.length >= 4) lastMove = [uci.slice(0, 2), uci.slice(2, 4)];
} }
cg.set({ fen, lastMove: undefined }); cg.set({ fen, lastMove });
$("live-btn").hidden = STATE.viewPly === null;
}
function renderChat() {
const list = $("chat-list");
list.innerHTML = "";
const moves = (STATE.game?.history || []).filter(h => h.san);
const counter = $("chat-counter");
counter.textContent = moves.length ? `${moves.length} moves` : "";
moves.forEach((h, i) => {
const ply = i + 1;
const side = h.side; // "white" | "black"
const div = document.createElement("div");
div.className = `bubble bubble-${side}`;
if (STATE.viewPly === ply) div.classList.add("active");
const moveNum = Math.floor(i / 2) + 1;
const moveLabel = side === "white" ? `${moveNum}.` : `${moveNum}...`;
const meta = document.createElement("div");
meta.className = "bubble-meta";
const left = document.createElement("span");
left.textContent = agentDisplay(side);
const right = document.createElement("span");
right.className = "bubble-san";
right.textContent = `${moveLabel} ${h.san}`;
meta.append(left, right);
const body = document.createElement("div");
body.className = "bubble-body";
if (h.comment) body.textContent = h.comment;
else { body.classList.add("bubble-empty"); body.textContent = "(без реплики)"; }
div.append(meta, body);
div.addEventListener("click", () => setView(ply));
list.appendChild(div);
});
// auto-scroll to bottom if at live
if (STATE.viewPly === null) list.scrollTop = list.scrollHeight;
} }
function renderHistory() { function renderHistory() {
const list = $("history-list"); const list = $("history-list");
list.innerHTML = ""; list.innerHTML = "";
const moves = (STATE.game?.history || []).filter(h => h.san); const moves = (STATE.game?.history || []).filter(h => h.san);
moves.forEach((h, i) => { let row = 0;
const li = document.createElement("li"); for (let i = 0; i < moves.length; i += 2) {
li.value = Math.floor(i / 2) + 1; row++;
li.textContent = `${h.san}${h.comment ? " «" + h.comment + "»" : ""}`; const num = document.createElement("li");
li.classList.toggle("active", num.className = "ply-num";
STATE.viewPly === null ? i === moves.length - 1 : i === STATE.viewPly - 1); num.textContent = `${row}.`;
li.addEventListener("click", () => { list.appendChild(num);
STATE.viewPly = i + 1;
renderBoard(); renderHistory(); const w = document.createElement("li");
}); w.textContent = moves[i]?.san || "";
list.appendChild(li); if (STATE.viewPly === i + 1) w.classList.add("active");
}); w.addEventListener("click", () => setView(i + 1));
list.appendChild(w);
const b = document.createElement("li");
b.textContent = moves[i + 1]?.san || "";
if (moves[i + 1]) {
if (STATE.viewPly === i + 2) b.classList.add("active");
b.addEventListener("click", () => setView(i + 2));
}
list.appendChild(b);
}
} }
function renderStatus() { function renderStatus() {
const g = STATE.game; const g = STATE.game;
if (!g) { $("status-line").textContent = "no game"; return; } if (!g) { $("status-line").textContent = "no game"; return; }
const result = g.status?.result; const r = g.status?.result;
$("status-line").textContent = result if (r) {
? `Game over: ${result} (${g.status.termination})` $("status-line").textContent = `game over: ${r} (${g.status.termination})`;
: `${g.side_to_move} to move`; } else {
$("status-line").textContent = `${agentDisplay(g.side_to_move)} to move`;
}
} }
function applyEval(e) { function applyEval(e) {
const cp = e.cp; const cp = e.cp, mate = e.mate;
const mate = e.mate; const bar = $("eval-fill"), txt = $("eval-text");
const bar = $("eval-fill"); const txt = $("eval-text");
let pct = 50; let pct = 50;
if (mate != null) { if (mate != null) {
pct = mate > 0 ? 100 : 0; pct = mate > 0 ? 100 : 0;
@@ -110,21 +139,35 @@ function applyEval(e) {
} else if (cp != null) { } else if (cp != null) {
pct = Math.max(0, Math.min(100, 50 + cp / 20)); pct = Math.max(0, Math.min(100, 50 + cp / 20));
txt.textContent = (cp / 100).toFixed(2); txt.textContent = (cp / 100).toFixed(2);
} else {
txt.textContent = "—";
} }
bar.style.bottom = `${100 - pct}%`; bar.style.bottom = `${100 - pct}%`;
if (e.best_uci && e.best_uci.length >= 4) { if (e.best_uci && e.best_uci.length >= 4) {
const from = e.best_uci.slice(0, 2); const from = e.best_uci.slice(0, 2), to = e.best_uci.slice(2, 4);
const to = e.best_uci.slice(2, 4);
cg.setShapes([{ orig: from, dest: to, brush: "green" }]); cg.setShapes([{ orig: from, dest: to, brush: "green" }]);
} }
if (e.pv && e.pv.length) { if (e.pv && e.pv.length) {
$("sf-lines").textContent = "pv: " + e.pv.slice(0, 6).join(" "); $("sf-pv").textContent = "pv: " + e.pv.slice(0, 6).join(" ");
} }
} }
function setView(ply) {
STATE.viewPly = ply;
renderBoard(); renderChat(); renderHistory();
}
function goLive() {
STATE.viewPly = null;
renderBoard(); renderChat(); renderHistory();
}
function log(line) { function log(line) {
const t = $("log-text"); const t = $("log-text");
t.textContent += line + "\n"; t.textContent += line + "\n";
// trim to last 200 lines
const lines = t.textContent.split("\n");
if (lines.length > 200) t.textContent = lines.slice(-200).join("\n");
t.scrollTop = t.scrollHeight; t.scrollTop = t.scrollHeight;
} }
@@ -133,8 +176,7 @@ function applySnapshot(s) {
STATE.settings = s.settings; STATE.settings = s.settings;
STATE.bindings = s.bindings; STATE.bindings = s.bindings;
STATE.viewPly = null; STATE.viewPly = null;
if (STATE.bindings && STATE.bindings.white) attachTerms(); renderBoard(); renderChat(); renderHistory(); renderStatus();
renderBoard(); renderHistory(); renderStatus();
} }
function connect() { function connect() {
@@ -145,7 +187,7 @@ function connect() {
if (ev.type === "new_game") { if (ev.type === "new_game") {
STATE.game = ev.game; STATE.game = ev.game;
STATE.viewPly = null; STATE.viewPly = null;
renderBoard(); renderHistory(); renderStatus(); renderBoard(); renderChat(); renderHistory(); renderStatus();
log(`new game: ${ev.game?.id || "?"}`); log(`new game: ${ev.game?.id || "?"}`);
return; return;
} }
@@ -157,28 +199,31 @@ function connect() {
if (!ev.status?.result) { if (!ev.status?.result) {
STATE.game.side_to_move = ev.side === "white" ? "black" : "white"; STATE.game.side_to_move = ev.side === "white" ? "black" : "white";
} }
STATE.viewPly = null; // stay live unless user clicked back
renderBoard(); renderHistory(); renderStatus(); renderBoard(); renderChat(); renderHistory(); renderStatus();
log(`${ev.side} ${ev.san || ev.uci || "?"}${ev.comment ? " «" + ev.comment + "»" : ""}`); log(`${ev.side} ${ev.san} «${ev.comment || ""}»`);
return; return;
} }
if (ev.type === "eval") return applyEval(ev); if (ev.type === "eval") return applyEval(ev);
if (ev.type === "game_over") { log(`game over: ${ev.result} (${ev.termination})`); return; } if (ev.type === "game_over") {
if (ev.type === "term_chunk") { if (STATE.game?.status) {
const t = terms[ev.side]; STATE.game.status.result = ev.result;
if (!t) return; STATE.game.status.termination = ev.termination;
t.term.reset(); }
t.term.write(ev.data); renderStatus();
log(`game over: ${ev.result} (${ev.termination})`);
return; return;
} }
if (ev.type === "settings") { STATE.settings = ev.settings; return; } if (ev.type === "settings") { STATE.settings = ev.settings; return; }
log(`event: ${ev.type}`); // term_chunk + others — ignore
}); });
ws.addEventListener("close", () => setTimeout(connect, 1000)); ws.addEventListener("close", () => setTimeout(connect, 1000));
ws.addEventListener("error", () => {}); ws.addEventListener("error", () => {});
} }
connect(); connect();
// ---------- controls ----------
$("live-btn").addEventListener("click", goLive);
$("new-game").addEventListener("click", async () => { $("new-game").addEventListener("click", async () => {
await fetch("/api/new-game", { method: "POST" }); await fetch("/api/new-game", { method: "POST" });
}); });
@@ -188,7 +233,6 @@ $("settings-btn").addEventListener("click", async () => {
const s = STATE.settings || (await (await fetch("/api/settings")).json()); const s = STATE.settings || (await (await fetch("/api/settings")).json());
dialog.querySelector('[name="allow_draw_resign"]').checked = s.allow_draw_resign; dialog.querySelector('[name="allow_draw_resign"]').checked = s.allow_draw_resign;
dialog.querySelector('[name="allow_illegal_moves"]').checked = s.allow_illegal_moves; dialog.querySelector('[name="allow_illegal_moves"]').checked = s.allow_illegal_moves;
dialog.querySelector('[name="theme_mode"]').value = s.theme_mode;
dialog.querySelector('[name="stockfish_depth"]').value = s.stockfish_depth; dialog.querySelector('[name="stockfish_depth"]').value = s.stockfish_depth;
dialog.showModal(); dialog.showModal();
}); });
@@ -198,7 +242,6 @@ $("settings-save").addEventListener("click", async (e) => {
const patch = { const patch = {
allow_draw_resign: form.allow_draw_resign.checked, allow_draw_resign: form.allow_draw_resign.checked,
allow_illegal_moves: form.allow_illegal_moves.checked, allow_illegal_moves: form.allow_illegal_moves.checked,
theme_mode: form.theme_mode.value,
stockfish_depth: parseInt(form.stockfish_depth.value, 10), stockfish_depth: parseInt(form.stockfish_depth.value, 10),
}; };
await fetch("/api/settings", { await fetch("/api/settings", {
@@ -208,3 +251,20 @@ $("settings-save").addEventListener("click", async (e) => {
}); });
dialog.close(); dialog.close();
}); });
// Keyboard nav: ← prev ply, → next ply, Space = live
window.addEventListener("keydown", (e) => {
const moves = (STATE.game?.history || []).filter(h => h.san);
if (e.key === "ArrowLeft") {
const cur = STATE.viewPly === null ? moves.length : STATE.viewPly;
if (cur > 0) setView(cur - 1);
} else if (e.key === "ArrowRight") {
const cur = STATE.viewPly === null ? moves.length : STATE.viewPly;
if (cur < moves.length) {
if (cur + 1 === moves.length) goLive();
else setView(cur + 1);
}
} else if (e.key === " ") {
e.preventDefault(); goLive();
}
});
+23 -36
View File
@@ -6,58 +6,47 @@
<link rel="stylesheet" href="/static/vendor/chessground.base.css" /> <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.brown.css" />
<link rel="stylesheet" href="/static/vendor/chessground.cburnett.css" /> <link rel="stylesheet" href="/static/vendor/chessground.cburnett.css" />
<link rel="stylesheet" href="/static/vendor/xterm.css" />
<link rel="stylesheet" href="/static/style.css" /> <link rel="stylesheet" href="/static/style.css" />
</head> </head>
<body> <body>
<main id="layout"> <main id="layout">
<section id="agent-codex" class="agent-panel"> <aside id="chat-col">
<header class="agent-header"> <header class="col-header">
<span class="agent-name">codex</span> <span>chat</span>
<span class="agent-side" data-bind="codex-side">?</span> <span id="chat-counter"></span>
</header> </header>
<div class="terminal" id="term-codex"></div> <div id="chat-list"></div>
</section> </aside>
<div id="eval-col" title="stockfish eval">
<div id="eval-fill"></div>
<div id="eval-text">0.00</div>
</div>
<section id="board-col"> <section id="board-col">
<div id="board-wrap"> <div id="board"></div>
<div id="eval-bar"><div id="eval-fill"></div><div id="eval-text">0.0</div></div>
<div id="board"></div>
<aside id="history">
<ol id="history-list"></ol>
</aside>
</div>
<div id="board-footer"> <div id="board-footer">
<div id="status-line">…</div> <span id="status-line">…</span>
<button id="new-game">New Game</button> <span id="sf-pv"></span>
<button id="settings-btn">⚙</button> <button id="live-btn" hidden>live</button>
<button id="new-game">new game</button>
<button id="settings-btn" title="settings">⚙</button>
</div> </div>
<div id="sf-lines"></div>
</section> </section>
<section id="agent-claude" class="agent-panel"> <aside id="moves-col">
<header class="agent-header"> <header class="col-header"><span>moves</span></header>
<span class="agent-name">claude</span> <ol id="history-list"></ol>
<span class="agent-side" data-bind="claude-side">?</span> </aside>
</header>
<div class="terminal" id="term-claude"></div>
</section>
<footer id="log-strip"><pre id="log-text"></pre></footer> <footer id="log-strip"><pre id="log-text"></pre></footer>
</main> </main>
<dialog id="settings-dialog"> <dialog id="settings-dialog">
<form method="dialog" id="settings-form"> <form method="dialog" id="settings-form">
<h3>Settings</h3> <h3>settings</h3>
<label><input type="checkbox" name="allow_draw_resign" /> allow draw / resign</label> <label><input type="checkbox" name="allow_draw_resign" /> allow draw / resign</label>
<label><input type="checkbox" name="allow_illegal_moves" /> allow illegal moves (cheats)</label> <label><input type="checkbox" name="allow_illegal_moves" /> allow illegal moves</label>
<label>theme_mode:
<select name="theme_mode">
<option value="by_side">by side (white→light, black→dark)</option>
<option value="both_dark">both dark</option>
<option value="both_light">both light</option>
</select>
</label>
<label>stockfish depth: <input type="number" name="stockfish_depth" min="6" max="30" /></label> <label>stockfish depth: <input type="number" name="stockfish_depth" min="6" max="30" /></label>
<menu> <menu>
<button value="cancel">cancel</button> <button value="cancel">cancel</button>
@@ -66,8 +55,6 @@
</form> </form>
</dialog> </dialog>
<script src="/static/vendor/xterm.js"></script>
<script src="/static/vendor/xterm-addon-fit.js"></script>
<script src="/static/app.js" type="module"></script> <script src="/static/app.js" type="module"></script>
</body> </body>
</html> </html>
+111 -47
View File
@@ -2,73 +2,137 @@
html, body { height: 100%; margin: 0; } html, body { height: 100%; margin: 0; }
body { body {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
background: #16161a; background: #0f0f12;
color: #e7e5e4; color: #e7e5e4;
font-size: 13px;
} }
#layout { #layout {
display: grid; display: grid;
grid-template-columns: 30% 40% 30%; grid-template-columns: minmax(280px, 1.1fr) 28px minmax(420px, 700px) minmax(180px, 240px);
grid-template-rows: minmax(0, 88vh) minmax(0, 12vh); grid-template-rows: 1fr 110px;
grid-template-areas: grid-template-areas:
"left center right" "chat eval board moves"
"log log log"; "log log log log";
height: 100vh; height: 100vh;
gap: 8px;
padding: 8px;
} }
#agent-codex { grid-area: left; }
#board-col { grid-area: center; }
#agent-claude{ grid-area: right; }
#log-strip { grid-area: log; border-top: 1px solid #333; overflow: auto; }
#log-text { font-size: 11px; padding: 4px 8px; margin: 0; color: #999; white-space: pre-wrap; }
.agent-panel { #chat-col { grid-area: chat; min-width: 0; min-height: 0; }
display: flex; flex-direction: column; #eval-col { grid-area: eval; min-width: 0; min-height: 0; }
border-right: 1px solid #333; #board-col { grid-area: board; min-width: 0; min-height: 0; }
min-width: 0; min-height: 0; #moves-col { grid-area: moves; min-width: 0; min-height: 0; }
} #log-strip { grid-area: log; min-width: 0; min-height: 0; }
#agent-claude { border-right: none; border-left: 1px solid #333; }
.agent-panel.theme-light { background: #f5f5f4; color: #1a1a1a; } /* ----- columns shared header ----- */
.agent-panel.theme-dark { background: #1a1a1a; color: #e7e5e4; } .col-header {
.agent-header {
padding: 4px 8px; font-weight: 600; border-bottom: 1px solid #333;
display: flex; justify-content: space-between; align-items: center; display: flex; justify-content: space-between; align-items: center;
padding: 4px 8px; opacity: 0.6; font-size: 11px; text-transform: uppercase;
letter-spacing: 0.08em; border-bottom: 1px solid #2a2a30;
} }
.agent-side { font-size: 11px; opacity: 0.6; }
.terminal { flex: 1; min-height: 0; padding: 4px; overflow: hidden; } /* ----- chat (left) ----- */
.terminal .xterm { height: 100%; } #chat-col { display: flex; flex-direction: column; background: #15151a; border-radius: 6px; overflow: hidden; }
#chat-list {
flex: 1; overflow-y: auto; padding: 8px;
display: flex; flex-direction: column; gap: 6px;
}
.bubble {
padding: 6px 9px 8px;
border-radius: 8px;
border: 1px solid transparent;
cursor: pointer;
line-height: 1.35;
word-wrap: break-word;
transition: outline-color 0.1s ease;
outline: 1px solid transparent;
outline-offset: 2px;
}
.bubble:hover { outline-color: #777; }
.bubble.active { outline-color: #c0a060; }
.bubble-white { background: #f0eee6; color: #16161a; align-self: flex-start; max-width: 92%; }
.bubble-black { background: #1f1e22; color: #e7e5e4; align-self: flex-end; max-width: 92%; border-color: #2a2a30; }
.bubble-meta {
font-size: 10px; opacity: 0.65; margin-bottom: 3px;
display: flex; justify-content: space-between; gap: 6px; align-items: center;
}
.bubble-san { font-weight: 700; opacity: 0.95; }
.bubble-body { font-size: 12.5px; }
.bubble-empty { font-style: italic; opacity: 0.55; }
#board-col { /* ----- eval bar ----- */
display: flex; flex-direction: column; padding: 12px; #eval-col {
min-width: 0; min-height: 0; position: relative;
} background: #18181c;
#board-wrap { border-radius: 4px;
display: grid; grid-template-columns: 24px 1fr 200px; overflow: hidden;
gap: 8px; flex: 1; min-height: 0;
}
#eval-bar {
position: relative; width: 24px; background: #444; border-radius: 4px; overflow: hidden;
} }
#eval-fill { #eval-fill {
position: absolute; left: 0; right: 0; bottom: 50%; position: absolute; left: 0; right: 0; bottom: 50%;
background: #f5f5f4; transition: bottom 0.3s ease; background: linear-gradient(180deg, #fafafa 0%, #ddd 100%);
transition: bottom 0.4s ease;
} }
#eval-text { #eval-text {
position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%);
text-align: center; font-size: 10px; color: #000; mix-blend-mode: difference; text-align: center; font-size: 10px; color: #888;
background: rgba(20,20,24,0.6); padding: 2px 0;
} }
#board { aspect-ratio: 1 / 1; background: #444; }
#history { overflow-y: auto; font-size: 14px; }
#history-list { padding-left: 28px; }
#history-list li { cursor: pointer; }
#history-list li.active { background: #555; }
#board-footer { display: flex; gap: 8px; align-items: center; padding: 8px 0; }
#status-line { flex: 1; opacity: 0.8; }
#sf-lines { font-size: 12px; opacity: 0.8; min-height: 1.5em; }
button { background: #2a2a2a; color: #e7e5e4; border: 1px solid #444; padding: 4px 12px; cursor: pointer; } /* ----- board ----- */
button:hover { background: #333; } #board-col {
display: flex; flex-direction: column; align-items: center; gap: 8px;
min-width: 0; min-height: 0;
}
#board {
width: min(100%, calc(100vh - 220px));
aspect-ratio: 1 / 1;
max-width: 100%;
background: #444;
border-radius: 4px;
overflow: hidden;
}
#board cg-container { width: 100% !important; height: 100% !important; }
#board-footer {
display: flex; gap: 8px; align-items: center; width: 100%; padding: 0 4px;
font-size: 12px;
}
#status-line { flex: 0 0 auto; opacity: 0.85; }
#sf-pv { flex: 1; opacity: 0.55; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
dialog { background: #1a1a1a; color: #e7e5e4; border: 1px solid #444; padding: 16px; } /* ----- moves history ----- */
dialog form { display: flex; flex-direction: column; gap: 8px; min-width: 320px; } #moves-col { display: flex; flex-direction: column; background: #15151a; border-radius: 6px; overflow: hidden; }
#history-list {
flex: 1; overflow-y: auto; padding: 4px 8px; margin: 0;
list-style: none;
display: grid; grid-template-columns: 28px 1fr 1fr; row-gap: 1px;
align-content: start;
}
#history-list li { padding: 2px 6px; border-radius: 3px; cursor: pointer; font-size: 12.5px; }
#history-list li.ply-num { opacity: 0.4; cursor: default; }
#history-list li:not(.ply-num):hover { background: #25252b; }
#history-list li.active { background: #3d342a; color: #f0d090; }
/* ----- log strip ----- */
#log-strip {
background: #0c0c0e; border: 1px solid #1f1f24; border-radius: 6px;
overflow: auto; padding: 4px 8px;
}
#log-text {
font-size: 11px; margin: 0; color: #888; white-space: pre-wrap;
}
/* ----- buttons + dialog ----- */
button {
background: #25252b; color: #e7e5e4; border: 1px solid #34343a;
padding: 4px 10px; cursor: pointer; border-radius: 4px; font-size: 12px;
}
button:hover { background: #2e2e36; }
#live-btn { background: #3d342a; color: #f0d090; }
dialog {
background: #15151a; color: #e7e5e4; border: 1px solid #2a2a30;
padding: 16px; border-radius: 6px;
}
dialog form { display: flex; flex-direction: column; gap: 10px; min-width: 320px; }
dialog menu { display: flex; gap: 8px; justify-content: flex-end; padding: 0; margin: 0; } dialog menu { display: flex; gap: 8px; justify-content: flex-end; padding: 0; margin: 0; }
+24 -15
View File
@@ -33,31 +33,40 @@ def build_app(state: state_mod.AppState) -> FastAPI:
eng = StockfishEngine() eng = StockfishEngine()
state.runtime = {"session": session, "coord": coord, "tailer": tailer, "engine": eng} # type: ignore[attr-defined] state.runtime = {"session": session, "coord": coord, "tailer": tailer, "engine": eng} # type: ignore[attr-defined]
eng_ok = False
try: try:
await eng.start() await eng.start()
except Exception: eng_ok = True
pass print("[lifespan] stockfish started", flush=True)
except Exception as e:
print(f"[lifespan] stockfish.start failed: {e}", flush=True)
try: try:
await coord.start() await coord.start()
except Exception: print("[lifespan] coordinator started", flush=True)
pass except Exception as e:
try: print(f"[lifespan] coordinator.start failed: {e}", flush=True)
if await session.exists(): # TmuxTailer is intentionally NOT started — the browser UI no longer
tailer.start() # mirrors the agent panes, so the polling would be wasted work and
except Exception: # also flood every subscriber queue with large term_chunk events.
pass
async def eval_bridge(): async def eval_bridge():
q = state.events.subscribe() q = state.events.subscribe()
try: try:
while True: while True:
ev = await q.get() ev = await q.get()
if ev.get("type") == "move" and ev.get("fen"): if ev.get("type") != "move" or not ev.get("fen"):
try: continue
res = await eng.analyze(ev["fen"], depth=state.settings.stockfish_depth) if not eng_ok:
await state.events.publish({"type": "eval", **res, "fen": ev["fen"]}) continue
except Exception: try:
pass res = await eng.analyze(
ev["fen"], depth=state.settings.stockfish_depth,
)
await state.events.publish(
{"type": "eval", **res, "fen": ev["fen"]},
)
except Exception as e:
print(f"[eval_bridge] analyze failed: {e}", flush=True)
finally: finally:
state.events.unsubscribe(q) state.events.unsubscribe(q)
bridge_task = asyncio.create_task(eval_bridge()) bridge_task = asyncio.create_task(eval_bridge())