feat(ui): floating moves under board, chat full-height right, refined eval bar
Layout (after iterative feedback): - Two columns: board+eval (left, square) | chat full-height (right). - Moves row floats just under the board as a compact one-row strip with the controls (new game / settings) — replaces the old right sidebar. - Board sized imperatively via fitBoard + ResizeObserver; eval bar height matches the board exactly (no overflow into neighbours). Eval bar: - 36px wide (was 28); text fits without pill background. - System sans-serif, 10.5px / 700 weight, tabular-nums. - Text positioned on whichever side is winning (bottom-white-half when white ahead → dark text; top-black-half when black ahead → light). - Sign now correct: backend stores raw cp from side-to-move; frontend flips when FEN says "b" so the bar always reflects white POV. Replay: - evalByFen on the client gets backfilled from /api/state's new `evals` list (backend keeps state.eval_cache per game). Clicking past bubbles now restores the stockfish eval for that ply. - renderBoard clears stockfish arrow when no eval is known yet for the shown FEN, so the arrow no longer 'lags' onto the next position. Auto-focus: - Latest played move is highlighted in both the chat bubble list and the moves strip when in live mode (viewPly === null). - scrollIntoView keeps the active bubble/SAN visible after each move.
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 4.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
+107
-48
@@ -9,6 +9,7 @@ const STATE = {
|
|||||||
settings: null,
|
settings: null,
|
||||||
bindings: null, // {white: {agent, model, ...}, black: {...}}
|
bindings: null, // {white: {agent, model, ...}, black: {...}}
|
||||||
viewPly: null, // null = live; otherwise integer ply (1-based)
|
viewPly: null, // null = live; otherwise integer ply (1-based)
|
||||||
|
evalByFen: new Map(), // fen → eval payload (cp, mate, best_uci, pv) — from white's POV
|
||||||
};
|
};
|
||||||
window._STATE = STATE; // for debugging
|
window._STATE = STATE; // for debugging
|
||||||
|
|
||||||
@@ -20,6 +21,27 @@ const cg = Chessground($("board"), {
|
|||||||
drawable: { enabled: true, visible: true },
|
drawable: { enabled: true, visible: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ---------- responsive board sizing ----------
|
||||||
|
function fitBoard() {
|
||||||
|
const row = $("board-row");
|
||||||
|
const evalCol = $("eval-col");
|
||||||
|
const board = $("board");
|
||||||
|
if (!row || !board || !evalCol) return;
|
||||||
|
// 10px = gap between eval-col and board in #board-row (CSS).
|
||||||
|
const w = row.clientWidth - evalCol.offsetWidth - 10;
|
||||||
|
const h = row.clientHeight;
|
||||||
|
const side = Math.max(120, Math.floor(Math.min(w, h)));
|
||||||
|
board.style.width = side + "px";
|
||||||
|
board.style.height = side + "px";
|
||||||
|
evalCol.style.height = side + "px";
|
||||||
|
// Let chessground recompute internal layout.
|
||||||
|
if (cg && cg.redrawAll) cg.redrawAll();
|
||||||
|
}
|
||||||
|
const _ro = new ResizeObserver(fitBoard);
|
||||||
|
_ro.observe($("board-row"));
|
||||||
|
window.addEventListener("resize", fitBoard);
|
||||||
|
requestAnimationFrame(fitBoard);
|
||||||
|
|
||||||
// ---------- agent labels ----------
|
// ---------- agent labels ----------
|
||||||
function agentOfSide(side) {
|
function agentOfSide(side) {
|
||||||
return STATE.bindings?.[side]?.agent || "?";
|
return STATE.bindings?.[side]?.agent || "?";
|
||||||
@@ -31,27 +53,34 @@ function agentDisplay(side) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------- rendering ----------
|
// ---------- rendering ----------
|
||||||
|
function currentFen() {
|
||||||
|
if (!STATE.game) return "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
||||||
|
const moves = (STATE.game.history || []).filter(h => h.san);
|
||||||
|
if (STATE.viewPly === null) return STATE.game.fen;
|
||||||
|
const c = new Chess();
|
||||||
|
for (let i = 0; i < STATE.viewPly; i++) c.move(moves[i].san);
|
||||||
|
return c.fen();
|
||||||
|
}
|
||||||
|
|
||||||
function renderBoard() {
|
function renderBoard() {
|
||||||
if (!STATE.game) return;
|
if (!STATE.game) return;
|
||||||
let fen = STATE.game.fen;
|
|
||||||
let lastMove = undefined;
|
|
||||||
const moves = (STATE.game.history || []).filter(h => h.san);
|
const moves = (STATE.game.history || []).filter(h => h.san);
|
||||||
if (STATE.viewPly !== null && STATE.viewPly >= 0) {
|
const fen = currentFen();
|
||||||
const c = new Chess();
|
let lastMove = undefined;
|
||||||
for (let i = 0; i < STATE.viewPly; i++) c.move(moves[i].san);
|
const idx = STATE.viewPly === null ? moves.length - 1 : STATE.viewPly - 1;
|
||||||
fen = c.fen();
|
if (idx >= 0 && moves[idx]) {
|
||||||
if (STATE.viewPly > 0) {
|
const uci = moves[idx].uci || "";
|
||||||
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)];
|
if (uci.length >= 4) lastMove = [uci.slice(0, 2), uci.slice(2, 4)];
|
||||||
}
|
}
|
||||||
cg.set({ fen, lastMove });
|
// Pass shapes via set() to atomically replace last move + arrow.
|
||||||
|
// Arrow comes from stored eval for this FEN, if any.
|
||||||
|
const e = STATE.evalByFen.get(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" }]
|
||||||
|
: [];
|
||||||
|
cg.set({ fen, lastMove, drawable: { autoShapes: shapes } });
|
||||||
$("live-btn").hidden = STATE.viewPly === null;
|
$("live-btn").hidden = STATE.viewPly === null;
|
||||||
|
applyEvalForFen(fen);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderChat() {
|
function renderChat() {
|
||||||
@@ -60,13 +89,15 @@ function renderChat() {
|
|||||||
const moves = (STATE.game?.history || []).filter(h => h.san);
|
const moves = (STATE.game?.history || []).filter(h => h.san);
|
||||||
const counter = $("chat-counter");
|
const counter = $("chat-counter");
|
||||||
counter.textContent = moves.length ? `${moves.length} moves` : "";
|
counter.textContent = moves.length ? `${moves.length} moves` : "";
|
||||||
|
const activePly = STATE.viewPly === null ? moves.length : STATE.viewPly;
|
||||||
|
|
||||||
|
let activeDiv = null;
|
||||||
moves.forEach((h, i) => {
|
moves.forEach((h, i) => {
|
||||||
const ply = i + 1;
|
const ply = i + 1;
|
||||||
const side = h.side; // "white" | "black"
|
const side = h.side;
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
div.className = `bubble bubble-${side}`;
|
div.className = `bubble bubble-${side}`;
|
||||||
if (STATE.viewPly === ply) div.classList.add("active");
|
if (ply === activePly) { div.classList.add("active"); activeDiv = div; }
|
||||||
const moveNum = Math.floor(i / 2) + 1;
|
const moveNum = Math.floor(i / 2) + 1;
|
||||||
const moveLabel = side === "white" ? `${moveNum}.` : `${moveNum}...`;
|
const moveLabel = side === "white" ? `${moveNum}.` : `${moveNum}...`;
|
||||||
const meta = document.createElement("div");
|
const meta = document.createElement("div");
|
||||||
@@ -86,14 +117,21 @@ function renderChat() {
|
|||||||
list.appendChild(div);
|
list.appendChild(div);
|
||||||
});
|
});
|
||||||
|
|
||||||
// auto-scroll to bottom if at live
|
// Scroll the active bubble into view (smooth at live tail, instant elsewhere).
|
||||||
if (STATE.viewPly === null) list.scrollTop = list.scrollHeight;
|
if (activeDiv) {
|
||||||
|
requestAnimationFrame(() => activeDiv.scrollIntoView({
|
||||||
|
behavior: "smooth", block: "nearest",
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
const activePly = STATE.viewPly === null ? moves.length : STATE.viewPly;
|
||||||
|
let activeLi = null;
|
||||||
|
|
||||||
let row = 0;
|
let row = 0;
|
||||||
for (let i = 0; i < moves.length; i += 2) {
|
for (let i = 0; i < moves.length; i += 2) {
|
||||||
row++;
|
row++;
|
||||||
@@ -104,18 +142,23 @@ function renderHistory() {
|
|||||||
|
|
||||||
const w = document.createElement("li");
|
const w = document.createElement("li");
|
||||||
w.textContent = moves[i]?.san || "";
|
w.textContent = moves[i]?.san || "";
|
||||||
if (STATE.viewPly === i + 1) w.classList.add("active");
|
if (i + 1 === activePly) { w.classList.add("active"); activeLi = w; }
|
||||||
w.addEventListener("click", () => setView(i + 1));
|
w.addEventListener("click", () => setView(i + 1));
|
||||||
list.appendChild(w);
|
list.appendChild(w);
|
||||||
|
|
||||||
const b = document.createElement("li");
|
const b = document.createElement("li");
|
||||||
b.textContent = moves[i + 1]?.san || "";
|
b.textContent = moves[i + 1]?.san || "";
|
||||||
if (moves[i + 1]) {
|
if (moves[i + 1]) {
|
||||||
if (STATE.viewPly === i + 2) b.classList.add("active");
|
if (i + 2 === activePly) { b.classList.add("active"); activeLi = b; }
|
||||||
b.addEventListener("click", () => setView(i + 2));
|
b.addEventListener("click", () => setView(i + 2));
|
||||||
}
|
}
|
||||||
list.appendChild(b);
|
list.appendChild(b);
|
||||||
}
|
}
|
||||||
|
if (activeLi) {
|
||||||
|
requestAnimationFrame(() => activeLi.scrollIntoView({
|
||||||
|
behavior: "smooth", block: "nearest",
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderStatus() {
|
function renderStatus() {
|
||||||
@@ -129,32 +172,53 @@ function renderStatus() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyEval(e) {
|
function storeEval(e) {
|
||||||
const cp = e.cp, mate = e.mate;
|
if (!e || !e.fen) return;
|
||||||
const col = $("eval-col"), bar = $("eval-fill"), txt = $("eval-text");
|
// Normalize cp/mate to WHITE's POV. Stockfish reports from side-to-move.
|
||||||
// pct = % of the bar occupied by WHITE (bottom-anchored).
|
// If FEN says black to move, flip the sign.
|
||||||
// 50 = even; >50 = white ahead; <50 = black ahead.
|
const sideToMove = e.fen.split(" ")[1] || "w";
|
||||||
|
const flip = sideToMove === "b";
|
||||||
|
const norm = {
|
||||||
|
cp: e.cp == null ? null : (flip ? -e.cp : e.cp),
|
||||||
|
mate: e.mate == null ? null : (flip ? -e.mate : e.mate),
|
||||||
|
best_uci: e.best_uci || null,
|
||||||
|
pv: e.pv || [],
|
||||||
|
fen: e.fen,
|
||||||
|
};
|
||||||
|
STATE.evalByFen.set(e.fen, norm);
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyEvalForFen(fen) {
|
||||||
|
const e = STATE.evalByFen.get(fen);
|
||||||
|
const col = $("eval-col"), bar = $("eval-fill"), txt = $("eval-text"), pv = $("sf-pv");
|
||||||
|
if (!e) {
|
||||||
|
txt.textContent = "—";
|
||||||
|
pv.textContent = "";
|
||||||
|
bar.style.height = "50%";
|
||||||
|
col.classList.remove("advantage-black");
|
||||||
|
return;
|
||||||
|
}
|
||||||
let pct = 50;
|
let pct = 50;
|
||||||
if (mate != null) {
|
if (e.mate != null) {
|
||||||
pct = mate > 0 ? 100 : 0;
|
pct = e.mate > 0 ? 100 : 0;
|
||||||
txt.textContent = (mate > 0 ? "+M" : "-M") + Math.abs(mate);
|
txt.textContent = (e.mate > 0 ? "+M" : "-M") + Math.abs(e.mate);
|
||||||
} else if (cp != null) {
|
} else if (e.cp != null) {
|
||||||
// map cp to percentage: ±800cp = full bar. Capped.
|
pct = Math.max(2, Math.min(98, 50 + e.cp / 16));
|
||||||
pct = Math.max(2, Math.min(98, 50 + cp / 16));
|
const v = (e.cp / 100);
|
||||||
const v = (cp / 100);
|
|
||||||
txt.textContent = (v > 0 ? "+" : "") + v.toFixed(2);
|
txt.textContent = (v > 0 ? "+" : "") + v.toFixed(2);
|
||||||
} else {
|
} else {
|
||||||
txt.textContent = "—";
|
txt.textContent = "—";
|
||||||
}
|
}
|
||||||
bar.style.height = `${pct}%`;
|
bar.style.height = `${pct}%`;
|
||||||
col.classList.toggle("advantage-black", pct < 50);
|
col.classList.toggle("advantage-black", pct < 50);
|
||||||
if (e.best_uci && e.best_uci.length >= 4) {
|
col.classList.toggle("advantage-white", pct > 50);
|
||||||
const from = e.best_uci.slice(0, 2), to = e.best_uci.slice(2, 4);
|
pv.textContent = e.pv && e.pv.length ? "pv: " + e.pv.slice(0, 6).join(" ") : "";
|
||||||
cg.setShapes([{ orig: from, dest: to, brush: "green" }]);
|
}
|
||||||
}
|
|
||||||
if (e.pv && e.pv.length) {
|
function applyEval(e) {
|
||||||
$("sf-pv").textContent = "pv: " + e.pv.slice(0, 6).join(" ");
|
storeEval(e);
|
||||||
}
|
// If we're currently looking at this fen, refresh the visuals.
|
||||||
|
if (currentFen() === e.fen) renderBoard();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setView(ply) {
|
function setView(ply) {
|
||||||
@@ -167,20 +231,15 @@ function goLive() {
|
|||||||
renderBoard(); renderChat(); renderHistory();
|
renderBoard(); renderChat(); renderHistory();
|
||||||
}
|
}
|
||||||
|
|
||||||
function log(line) {
|
function log(_line) { /* log strip removed; keep no-op to preserve callsites */ }
|
||||||
const t = $("log-text");
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
function applySnapshot(s) {
|
function applySnapshot(s) {
|
||||||
STATE.game = s.game;
|
STATE.game = s.game;
|
||||||
STATE.settings = s.settings;
|
STATE.settings = s.settings;
|
||||||
STATE.bindings = s.bindings;
|
STATE.bindings = s.bindings;
|
||||||
STATE.viewPly = null;
|
STATE.viewPly = null;
|
||||||
|
STATE.evalByFen.clear();
|
||||||
|
for (const e of (s.evals || [])) storeEval(e);
|
||||||
renderBoard(); renderChat(); renderHistory(); renderStatus();
|
renderBoard(); renderChat(); renderHistory(); renderStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-19
@@ -10,21 +10,14 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main id="layout">
|
<main id="layout">
|
||||||
<aside id="chat-col">
|
|
||||||
<header class="col-header">
|
|
||||||
<span>chat</span>
|
|
||||||
<span id="chat-counter"></span>
|
|
||||||
</header>
|
|
||||||
<div id="chat-list"></div>
|
|
||||||
</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"></div>
|
<div id="board-row">
|
||||||
|
<div id="eval-col" title="stockfish eval">
|
||||||
|
<div id="eval-fill"></div>
|
||||||
|
<div id="eval-text">0.00</div>
|
||||||
|
</div>
|
||||||
|
<div id="board"></div>
|
||||||
|
</div>
|
||||||
<div id="board-footer">
|
<div id="board-footer">
|
||||||
<span id="status-line">…</span>
|
<span id="status-line">…</span>
|
||||||
<span id="sf-pv"></span>
|
<span id="sf-pv"></span>
|
||||||
@@ -32,14 +25,19 @@
|
|||||||
<button id="new-game">new game</button>
|
<button id="new-game">new game</button>
|
||||||
<button id="settings-btn" title="settings">⚙</button>
|
<button id="settings-btn" title="settings">⚙</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="moves-floating">
|
||||||
|
<span class="moves-label">moves</span>
|
||||||
|
<ol id="history-list"></ol>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<aside id="moves-col">
|
<aside id="chat-col">
|
||||||
<header class="col-header"><span>moves</span></header>
|
<header class="col-header">
|
||||||
<ol id="history-list"></ol>
|
<span>chat</span>
|
||||||
|
<span id="chat-counter"></span>
|
||||||
|
</header>
|
||||||
|
<div id="chat-list"></div>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<footer id="log-strip"><pre id="log-text"></pre></footer>
|
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<dialog id="settings-dialog">
|
<dialog id="settings-dialog">
|
||||||
|
|||||||
+104
-87
@@ -7,77 +7,67 @@ body {
|
|||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ============ layout: 2 columns ============ */
|
||||||
#layout {
|
#layout {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: minmax(280px, 1.1fr) 28px minmax(420px, 700px) minmax(180px, 240px);
|
grid-template-columns: minmax(440px, min(900px, 60vw)) minmax(380px, 1fr);
|
||||||
grid-template-rows: 1fr 110px;
|
grid-template-rows: 1fr;
|
||||||
grid-template-areas:
|
grid-template-areas: "board chat";
|
||||||
"chat eval board moves"
|
|
||||||
"log log log log";
|
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
gap: 8px;
|
width: 100vw;
|
||||||
padding: 8px;
|
gap: 20px;
|
||||||
|
padding: 14px;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
#chat-col { grid-area: chat; min-width: 0; min-height: 0; }
|
#board-col { grid-area: board; min-width: 0; min-height: 0; overflow: hidden; display: flex; flex-direction: column; gap: 10px; }
|
||||||
#eval-col { grid-area: eval; min-width: 0; min-height: 0; }
|
#chat-col { grid-area: chat; min-width: 0; min-height: 0; overflow: hidden; }
|
||||||
#board-col { grid-area: board; 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; }
|
|
||||||
|
|
||||||
/* ----- columns shared header ----- */
|
/* ============ board area ============ */
|
||||||
.col-header {
|
#board-row {
|
||||||
display: flex; justify-content: space-between; align-items: center;
|
display: flex;
|
||||||
padding: 4px 8px; opacity: 0.6; font-size: 11px; text-transform: uppercase;
|
align-items: center;
|
||||||
letter-spacing: 0.08em; border-bottom: 1px solid #2a2a30;
|
justify-content: flex-start;
|
||||||
|
gap: 12px;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
min-height: 0;
|
||||||
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
#board {
|
||||||
|
/* size set imperatively by fitBoard() */
|
||||||
|
background: #444;
|
||||||
|
border-radius: 4px;
|
||||||
|
overflow: hidden;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
}
|
||||||
|
#board cg-container { width: 100% !important; height: 100% !important; }
|
||||||
|
|
||||||
/* ----- chat (left) ----- */
|
#board-footer {
|
||||||
#chat-col { display: flex; flex-direction: column; background: #15151a; border-radius: 6px; overflow: hidden; }
|
display: flex; gap: 10px; align-items: center;
|
||||||
#chat-list {
|
padding: 4px 2px;
|
||||||
flex: 1; overflow-y: auto; padding: 8px;
|
font-size: 12.5px;
|
||||||
display: flex; flex-direction: column; gap: 6px;
|
|
||||||
}
|
}
|
||||||
.bubble {
|
#status-line { flex: 0 0 auto; opacity: 0.85; }
|
||||||
padding: 6px 9px 8px;
|
#sf-pv { flex: 1; opacity: 0.5; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||||
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; }
|
|
||||||
|
|
||||||
/* ----- eval bar (lichess-style two-bar) ----- */
|
/* ============ eval bar ============ */
|
||||||
#eval-col {
|
#eval-col {
|
||||||
position: relative;
|
position: relative;
|
||||||
background: #2a2a30; /* the BLACK half — sits at the top */
|
width: 36px;
|
||||||
|
flex: 0 0 36px;
|
||||||
|
background: #2a2a30; /* BLACK half on top */
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
box-shadow: inset 0 0 0 1px #3a3a40;
|
box-shadow: inset 0 0 0 1px #3a3a40;
|
||||||
}
|
}
|
||||||
/* center reference line (50/50) */
|
#eval-col::after { /* 50/50 reference line */
|
||||||
#eval-col::after {
|
|
||||||
content: "";
|
content: "";
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0; right: 0; top: 50%;
|
left: 0; right: 0; top: 50%;
|
||||||
height: 1px; background: rgba(255,255,255,0.12);
|
height: 1px; background: rgba(255,255,255,0.12);
|
||||||
pointer-events: none; z-index: 2;
|
pointer-events: none; z-index: 2;
|
||||||
}
|
}
|
||||||
#eval-fill { /* the WHITE half — anchored at bottom */
|
#eval-fill { /* WHITE half from bottom */
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0; right: 0; bottom: 0;
|
left: 0; right: 0; bottom: 0;
|
||||||
height: 50%;
|
height: 50%;
|
||||||
@@ -86,59 +76,86 @@ body {
|
|||||||
z-index: 1;
|
z-index: 1;
|
||||||
}
|
}
|
||||||
#eval-text {
|
#eval-text {
|
||||||
position: absolute; left: 0; right: 0; bottom: 4px;
|
position: absolute;
|
||||||
text-align: center; font-size: 10px;
|
left: 0; right: 0;
|
||||||
color: #18181c; mix-blend-mode: difference; z-index: 3;
|
font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||||
font-weight: 700; letter-spacing: 0.04em;
|
font-size: 10.5px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: -0.03em;
|
||||||
|
text-align: center;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
pointer-events: none; z-index: 3;
|
||||||
|
transition: color 0.2s, top 0.4s, bottom 0.4s;
|
||||||
|
/* default — slight white or even: text near bottom on white half, dark */
|
||||||
|
bottom: 4px; top: auto;
|
||||||
|
color: #1a1a1a;
|
||||||
}
|
}
|
||||||
#eval-col.advantage-black #eval-text {
|
#eval-col.advantage-black #eval-text {
|
||||||
bottom: auto; top: 4px; /* flip text to top when black is ahead */
|
bottom: auto; top: 4px;
|
||||||
|
color: #e7e5e4;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----- board ----- */
|
/* ============ floating moves panel (below board) ============ */
|
||||||
#board-col {
|
#moves-floating {
|
||||||
display: flex; flex-direction: column; align-items: center; gap: 8px;
|
display: flex; align-items: flex-start; gap: 8px;
|
||||||
min-width: 0; min-height: 0;
|
background: #15151a;
|
||||||
}
|
border: 1px solid #2a2a30;
|
||||||
#board {
|
border-radius: 8px;
|
||||||
width: min(100%, calc(100vh - 220px));
|
padding: 6px 10px;
|
||||||
aspect-ratio: 1 / 1;
|
max-height: 84px;
|
||||||
max-width: 100%;
|
|
||||||
background: #444;
|
|
||||||
border-radius: 4px;
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
box-shadow: 0 2px 8px rgba(0,0,0,0.3);
|
||||||
}
|
}
|
||||||
#board cg-container { width: 100% !important; height: 100% !important; }
|
.moves-label {
|
||||||
#board-footer {
|
font-size: 10px; opacity: 0.45; text-transform: uppercase;
|
||||||
display: flex; gap: 8px; align-items: center; width: 100%; padding: 0 4px;
|
letter-spacing: 0.1em; padding-top: 2px; flex: 0 0 auto;
|
||||||
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; }
|
|
||||||
|
|
||||||
/* ----- moves history ----- */
|
|
||||||
#moves-col { display: flex; flex-direction: column; background: #15151a; border-radius: 6px; overflow: hidden; }
|
|
||||||
#history-list {
|
#history-list {
|
||||||
flex: 1; overflow-y: auto; padding: 4px 8px; margin: 0;
|
list-style: none; padding: 0; margin: 0;
|
||||||
list-style: none;
|
display: flex; flex-wrap: wrap; gap: 2px 8px;
|
||||||
display: grid; grid-template-columns: 28px 1fr 1fr; row-gap: 1px;
|
font-size: 12.5px; overflow-y: auto; flex: 1;
|
||||||
align-content: start;
|
font-variant-numeric: tabular-nums;
|
||||||
}
|
}
|
||||||
#history-list li { padding: 2px 6px; border-radius: 3px; cursor: pointer; font-size: 12.5px; }
|
#history-list li { padding: 1px 4px; border-radius: 3px; cursor: pointer; }
|
||||||
#history-list li.ply-num { opacity: 0.4; cursor: default; }
|
#history-list li.ply-num { opacity: 0.4; cursor: default; padding-right: 2px; }
|
||||||
#history-list li:not(.ply-num):hover { background: #25252b; }
|
#history-list li:not(.ply-num):hover { background: #25252b; }
|
||||||
#history-list li.active { background: #3d342a; color: #f0d090; }
|
#history-list li.active { background: #3d342a; color: #f0d090; }
|
||||||
|
|
||||||
/* ----- log strip ----- */
|
/* ============ chat panel (right, full height) ============ */
|
||||||
#log-strip {
|
#chat-col { display: flex; flex-direction: column; background: #15151a; border-radius: 8px; overflow: hidden; border: 1px solid #2a2a30; }
|
||||||
background: #0c0c0e; border: 1px solid #1f1f24; border-radius: 6px;
|
.col-header {
|
||||||
overflow: auto; padding: 4px 8px;
|
display: flex; justify-content: space-between; align-items: center;
|
||||||
|
padding: 6px 10px; opacity: 0.6; font-size: 10px; text-transform: uppercase;
|
||||||
|
letter-spacing: 0.1em; border-bottom: 1px solid #2a2a30;
|
||||||
}
|
}
|
||||||
#log-text {
|
#chat-list {
|
||||||
font-size: 11px; margin: 0; color: #888; white-space: pre-wrap;
|
flex: 1; overflow-y: auto; padding: 10px;
|
||||||
|
display: flex; flex-direction: column; gap: 8px;
|
||||||
}
|
}
|
||||||
|
.bubble {
|
||||||
|
padding: 7px 10px 9px;
|
||||||
|
border-radius: 9px;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
line-height: 1.4;
|
||||||
|
word-wrap: break-word;
|
||||||
|
transition: outline-color 0.1s ease;
|
||||||
|
outline: 1px solid transparent;
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
.bubble:hover { outline-color: #555; }
|
||||||
|
.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: 13px; }
|
||||||
|
.bubble-empty { font-style: italic; opacity: 0.5; }
|
||||||
|
|
||||||
/* ----- buttons + dialog ----- */
|
/* ============ buttons + dialog ============ */
|
||||||
button {
|
button {
|
||||||
background: #25252b; color: #e7e5e4; border: 1px solid #34343a;
|
background: #25252b; color: #e7e5e4; border: 1px solid #34343a;
|
||||||
padding: 4px 10px; cursor: pointer; border-radius: 4px; font-size: 12px;
|
padding: 4px 10px; cursor: pointer; border-radius: 4px; font-size: 12px;
|
||||||
|
|||||||
+11
-4
@@ -54,6 +54,9 @@ def build_app(state: state_mod.AppState) -> FastAPI:
|
|||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
ev = await q.get()
|
ev = await q.get()
|
||||||
|
if ev.get("type") == "new_game":
|
||||||
|
state.eval_cache.clear()
|
||||||
|
continue
|
||||||
if ev.get("type") != "move" or not ev.get("fen"):
|
if ev.get("type") != "move" or not ev.get("fen"):
|
||||||
continue
|
continue
|
||||||
if not eng_ok:
|
if not eng_ok:
|
||||||
@@ -62,9 +65,10 @@ def build_app(state: state_mod.AppState) -> FastAPI:
|
|||||||
res = await eng.analyze(
|
res = await eng.analyze(
|
||||||
ev["fen"], depth=state.settings.stockfish_depth,
|
ev["fen"], depth=state.settings.stockfish_depth,
|
||||||
)
|
)
|
||||||
await state.events.publish(
|
payload = {"type": "eval", **res, "fen": ev["fen"]}
|
||||||
{"type": "eval", **res, "fen": ev["fen"]},
|
# Cache so future WS clients can backfill on connect.
|
||||||
)
|
state.eval_cache[ev["fen"]] = {**res, "fen": ev["fen"]}
|
||||||
|
await state.events.publish(payload)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[eval_bridge] analyze failed: {e}", flush=True)
|
print(f"[eval_bridge] analyze failed: {e}", flush=True)
|
||||||
finally:
|
finally:
|
||||||
@@ -88,13 +92,16 @@ def build_app(state: state_mod.AppState) -> FastAPI:
|
|||||||
|
|
||||||
@app.get("/api/state")
|
@app.get("/api/state")
|
||||||
async def get_state() -> dict[str, Any]:
|
async def get_state() -> dict[str, Any]:
|
||||||
|
evals = list(state.eval_cache.values())
|
||||||
if state.game is None:
|
if state.game is None:
|
||||||
return {"game": None, "settings": state.settings.model_dump(),
|
return {"game": None, "settings": state.settings.model_dump(),
|
||||||
"bindings": {s.value: b.to_dict() for s, b in state.bindings.items()}}
|
"bindings": {s.value: b.to_dict() for s, b in state.bindings.items()},
|
||||||
|
"evals": evals}
|
||||||
return {
|
return {
|
||||||
"game": state.game.get_state(),
|
"game": state.game.get_state(),
|
||||||
"settings": state.settings.model_dump(),
|
"settings": state.settings.model_dump(),
|
||||||
"bindings": {s.value: b.to_dict() for s, b in state.bindings.items()},
|
"bindings": {s.value: b.to_dict() for s, b in state.bindings.items()},
|
||||||
|
"evals": evals,
|
||||||
}
|
}
|
||||||
|
|
||||||
@app.get("/api/games")
|
@app.get("/api/games")
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ class AppState:
|
|||||||
self.bindings: dict[Side, AgentBinding] = {}
|
self.bindings: dict[Side, AgentBinding] = {}
|
||||||
self.first_move_sent: dict[Side, bool] = {Side.WHITE: False, Side.BLACK: False}
|
self.first_move_sent: dict[Side, bool] = {Side.WHITE: False, Side.BLACK: False}
|
||||||
self.nudge_count: dict[Side, int] = {Side.WHITE: 0, Side.BLACK: 0}
|
self.nudge_count: dict[Side, int] = {Side.WHITE: 0, Side.BLACK: 0}
|
||||||
|
# fen → {cp, mate, best_uci, pv, fen} — populated by eval_bridge per move
|
||||||
|
self.eval_cache: dict[str, dict] = {}
|
||||||
|
|
||||||
|
|
||||||
state = AppState()
|
state = AppState()
|
||||||
|
|||||||
+12
-2
@@ -88,9 +88,19 @@ class TmuxSession:
|
|||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def submit(self, pane: int, text: str) -> None:
|
async def submit(self, pane: int, text: str, *, settle_ms: int = 600) -> None:
|
||||||
"""Paste text and press Enter to submit."""
|
"""Paste text and press Enter to submit.
|
||||||
|
|
||||||
|
`settle_ms` is a short wait between paste-buffer and Enter so that the
|
||||||
|
target TUI's paste-burst detector finishes collecting the pasted block
|
||||||
|
before we send the submit keystroke. codex shows the paste as
|
||||||
|
'[Pasted Content N chars]' and only treats a *subsequent* Enter as
|
||||||
|
submit; without the delay the Enter gets folded into the paste burst
|
||||||
|
and never submits.
|
||||||
|
"""
|
||||||
await self.paste_text(pane, text)
|
await self.paste_text(pane, text)
|
||||||
|
if settle_ms > 0:
|
||||||
|
await asyncio.sleep(settle_ms / 1000)
|
||||||
await self.send_keys(pane, ["Enter"])
|
await self.send_keys(pane, ["Enter"])
|
||||||
|
|
||||||
async def capture_pane(self, pane: int, *, escape: bool = True, history: int = 0) -> str:
|
async def capture_pane(self, pane: int, *, escape: bool = True, history: int = 0) -> str:
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 165 KiB |
Reference in New Issue
Block a user