feat: undo / delete logged entries (fix fat-fingered live logging)
Previously the only delete was whole-session, so a mis-logged stack or a
mis-parsed hand was stuck on the HUD. Now:
- undo_last tool ("scratch that") — deletes the most recent hand/stack/read/
scar/confidence/reset in the live session; added to the Cash toolset.
- poker.delete_hand/stack/read/ritual + delete_entry dispatch + undo_last.
- DELETE /session/entry/{kind}/{id} endpoint.
- HUD: per-row × delete buttons on hands, confidence-bank, and scar-note rows
(stack/read deletes via the tool). Row ids now surfaced in the hud() bundle.
- test_modes.py +2 (undo_last across kinds, tool handler); 46 green.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -113,6 +113,13 @@ def create_app() -> FastAPI:
|
||||
bundle = await asyncio.to_thread(poker.hud)
|
||||
return bundle or {"session": None}
|
||||
|
||||
@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."""
|
||||
ok = await asyncio.to_thread(poker.delete_entry, kind, entry_id)
|
||||
logbus.log("info", "hud entry deleted", kind=kind, id=entry_id, ok=ok)
|
||||
return {"ok": ok}
|
||||
|
||||
@app.get("/history")
|
||||
async def history_page() -> FileResponse:
|
||||
"""Browsable list of past poker sessions."""
|
||||
|
||||
@@ -78,6 +78,12 @@
|
||||
.scar-cls.standard { color: var(--fade); }
|
||||
.card.scar { border-color: #4a2222; } .card.scar .label { color: #d98a8a; }
|
||||
.card.conf { border-color: #234a23; } .card.conf .label { color: var(--good); }
|
||||
/* per-row delete (fix fat-fingered live logging) */
|
||||
li.row-del { display: flex; align-items: center; gap: 8px; }
|
||||
li.row-del > a.hand, li.row-del > .row-body { flex: 1; min-width: 0; }
|
||||
.del-x { flex: none; background: none; border: none; color: var(--fade); font-size: 1.15rem;
|
||||
line-height: 1; padding: 2px 6px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
|
||||
.del-x:active { color: var(--low); }
|
||||
.empty { color: var(--fade); font-size: .92rem; }
|
||||
.err { color: var(--low); text-align: center; padding: 30px; }
|
||||
.big-empty { text-align: center; padding: 50px 20px; color: var(--fade); }
|
||||
@@ -142,6 +148,16 @@
|
||||
|
||||
function netClass(v){ return v == null ? 'flat' : v > 0 ? 'up' : v < 0 ? 'down' : 'flat'; }
|
||||
|
||||
// Delete one logged entry (hand | ritual | read | stack), then refresh.
|
||||
async function del(kind, id){
|
||||
if(!confirm('Delete this entry?')) return;
|
||||
try {
|
||||
const r = await fetch('/session/entry/'+kind+'/'+id, { method:'DELETE' });
|
||||
if(!r.ok) throw new Error('HTTP '+r.status);
|
||||
refresh();
|
||||
} catch(e){ alert('Delete failed: '+e.message); }
|
||||
}
|
||||
|
||||
function render(data){
|
||||
const s = data.session;
|
||||
if (!s) {
|
||||
@@ -199,29 +215,29 @@
|
||||
<div class="card">
|
||||
<p class="label">Hands this session</p>
|
||||
${hands.length ? `<ul class="rows">${hands.slice().reverse().map(h => `
|
||||
<li><a class="hand" href="/hand/${h.id}">
|
||||
<li class="row-del"><a class="hand" href="/hand/${h.id}">
|
||||
<span class="pos">${esc(h.position || '?')}</span>
|
||||
<span class="cards">${esc(h.hole_cards || '')}${h.board ? ' · '+esc(h.board) : ''}</span>
|
||||
${h.tag ? `<span class="tag">${esc(h.tag)}</span>` : ''}
|
||||
${h.result != null ? `<span class="res ${h.result>=0?'up':'down'}">${signed(h.result)}</span>` : ''}
|
||||
</a></li>`).join('')}</ul>`
|
||||
</a><button class="del-x" title="Delete hand" onclick="del('hand',${h.id})">×</button></li>`).join('')}</ul>`
|
||||
: '<p class="empty">No hands logged yet.</p>'}
|
||||
</div>
|
||||
|
||||
<div class="card conf">
|
||||
<p class="label">💰 Confidence Bank</p>
|
||||
${confidence.length ? `<ul class="rows">${confidence.slice().reverse().map(c => `
|
||||
<li>${esc(c.content)}${c.hand_id ? ` · <a class="hand" style="display:inline" href="/hand/${c.hand_id}">hand</a>` : ''}
|
||||
<div class="note-meta">${ago(c.at)}</div></li>`).join('')}</ul>`
|
||||
<li class="row-del"><span class="row-body">${esc(c.content)}${c.hand_id ? ` · <a class="hand" style="display:inline" href="/hand/${c.hand_id}">hand</a>` : ''}
|
||||
<div class="note-meta">${ago(c.at)}</div></span><button class="del-x" title="Delete" onclick="del('ritual',${c.id})">×</button></li>`).join('')}</ul>`
|
||||
: '<p class="empty">Nothing banked yet — disciplined plays land here.</p>'}
|
||||
</div>
|
||||
|
||||
<div class="card scar">
|
||||
<p class="label">🩹 Scar Notes</p>
|
||||
${scars.length ? `<ul class="rows">${scars.slice().reverse().map(sc => `
|
||||
<li>${esc(sc.content)}${sc.classification ? `<span class="scar-cls ${esc(sc.classification)}">${esc(sc.classification)}</span>` : ''}
|
||||
<li class="row-del"><span class="row-body">${esc(sc.content)}${sc.classification ? `<span class="scar-cls ${esc(sc.classification)}">${esc(sc.classification)}</span>` : ''}
|
||||
${sc.hand_id ? ` · <a class="hand" style="display:inline" href="/hand/${sc.hand_id}">hand</a>` : ''}
|
||||
<div class="note-meta">${ago(sc.at)}</div></li>`).join('')}</ul>`
|
||||
<div class="note-meta">${ago(sc.at)}</div></span><button class="del-x" title="Delete" onclick="del('ritual',${sc.id})">×</button></li>`).join('')}</ul>`
|
||||
: '<p class="empty">No scars logged — mistakes to study land here.</p>'}
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user