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:
+11
-4
@@ -54,6 +54,9 @@ def build_app(state: state_mod.AppState) -> FastAPI:
|
||||
try:
|
||||
while True:
|
||||
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"):
|
||||
continue
|
||||
if not eng_ok:
|
||||
@@ -62,9 +65,10 @@ def build_app(state: state_mod.AppState) -> FastAPI:
|
||||
res = await eng.analyze(
|
||||
ev["fen"], depth=state.settings.stockfish_depth,
|
||||
)
|
||||
await state.events.publish(
|
||||
{"type": "eval", **res, "fen": ev["fen"]},
|
||||
)
|
||||
payload = {"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:
|
||||
print(f"[eval_bridge] analyze failed: {e}", flush=True)
|
||||
finally:
|
||||
@@ -88,13 +92,16 @@ def build_app(state: state_mod.AppState) -> FastAPI:
|
||||
|
||||
@app.get("/api/state")
|
||||
async def get_state() -> dict[str, Any]:
|
||||
evals = list(state.eval_cache.values())
|
||||
if state.game is None:
|
||||
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 {
|
||||
"game": state.game.get_state(),
|
||||
"settings": state.settings.model_dump(),
|
||||
"bindings": {s.value: b.to_dict() for s, b in state.bindings.items()},
|
||||
"evals": evals,
|
||||
}
|
||||
|
||||
@app.get("/api/games")
|
||||
|
||||
@@ -41,6 +41,8 @@ class AppState:
|
||||
self.bindings: dict[Side, AgentBinding] = {}
|
||||
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}
|
||||
# fen → {cp, mate, best_uci, pv, fen} — populated by eval_bridge per move
|
||||
self.eval_cache: dict[str, dict] = {}
|
||||
|
||||
|
||||
state = AppState()
|
||||
|
||||
+12
-2
@@ -88,9 +88,19 @@ class TmuxSession:
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
async def submit(self, pane: int, text: str) -> None:
|
||||
"""Paste text and press Enter to submit."""
|
||||
async def submit(self, pane: int, text: str, *, settle_ms: int = 600) -> None:
|
||||
"""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)
|
||||
if settle_ms > 0:
|
||||
await asyncio.sleep(settle_ms / 1000)
|
||||
await self.send_keys(pane, ["Enter"])
|
||||
|
||||
async def capture_pane(self, pane: int, *, escape: bool = True, history: int = 0) -> str:
|
||||
|
||||
Reference in New Issue
Block a user