feat: view past sessions, edit session details, log rituals while reviewing

- View any past session as a read-only HUD: /session?id=N (hud(session_id) +
  /session/data?id=); /history rows now link there. Closed sessions show played
  duration + final net; recap link when one exists.
- Edit session details during or after play: poker.update_session (recomputes net
  when buy-in/cash-out change), PATCH /session/{id}, an update_session tool ("venue
  was actually Bellagio", "I bought in for 600"), and an inline ✎ Edit form on the HUD.
- Rituals attach to the most-recent session post-close (poker.review_session_id),
  so scar/confidence/reset work while reviewing after you rack up.
- Edit form is poll-safe (won't clobber mid-edit); past-session view doesn't poll.
- test_modes.py +3 (edit, review rituals, past-session HUD); 49 green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-21 05:12:13 +00:00
parent cca8322ee2
commit 559faaed30
7 changed files with 224 additions and 29 deletions
+11 -3
View File
@@ -108,11 +108,19 @@ def create_app() -> FastAPI:
return FileResponse(str(_STATIC / "session.html"))
@app.get("/session/data")
async def session_hud_data() -> dict:
"""The current live session's HUD bundle (or {session: None} if none open)."""
bundle = await asyncio.to_thread(poker.hud)
async def session_hud_data(id: int | None = None) -> dict:
"""HUD bundle for the live session, or a specific past session via ?id=."""
bundle = await asyncio.to_thread(poker.hud, id)
return bundle or {"session": None}
@app.patch("/session/{session_id}")
async def session_update(session_id: int, request: Request) -> dict:
"""Edit a session's details (venue/stakes/game/buy-in/cash-out/…)."""
body = await request.json()
s = await asyncio.to_thread(lambda: poker.update_session(session_id, **body))
logbus.log("info", "session edited", id=session_id, fields=list(body))
return {"ok": s is not None, "session": s}
@app.delete("/session/entry/{kind}/{entry_id}")
async def delete_entry(kind: str, entry_id: int) -> dict:
"""Delete one HUD entry (hand | stack | read | ritual) by id."""