From 2dd428bfa2324db8665055478aa1c4b36c45c644 Mon Sep 17 00:00:00 2001 From: Alexander Whitestone Date: Sun, 22 Mar 2026 21:48:57 -0400 Subject: [PATCH] feat: add "Clear history" button in session panel Add a link-style button in the active session step that calls DELETE /api/sessions/:id/history to clear server-side conversation context. Shows a 2.5s green confirmation on success. Fixes #41 Co-Authored-By: Claude Opus 4.6 (1M context) --- the-matrix/index.html | 9 +++++++++ the-matrix/js/session.js | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/the-matrix/index.html b/the-matrix/index.html index afffbc5..ba274f9 100644 --- a/the-matrix/index.html +++ b/the-matrix/index.html @@ -330,6 +330,14 @@ .panel-btn.muted { border-color: #0e2318; color: #226644; } .panel-btn.muted:hover:not(:disabled) { background: #0e2318; color: #44dd88; } + .session-link-btn { + background: none; border: none; color: #557755; font-size: 10px; + font-family: inherit; cursor: pointer; margin-top: 10px; padding: 4px 0; + letter-spacing: 1px; display: block; + } + .session-link-btn:hover:not(:disabled) { color: #44dd88; text-decoration: underline; } + .session-link-btn:disabled { opacity: 0.35; cursor: not-allowed; } + #job-status { font-size: 11px; margin-top: 8px; color: #5577aa; min-height: 16px; } #job-error { font-size: 11px; margin-top: 4px; min-height: 16px; color: #994444; } @@ -622,6 +630,7 @@ TYPE IN THE INPUT BAR TO ASK TIMMY.
EACH REQUEST DEDUCTS FROM YOUR BALANCE.

+
diff --git a/the-matrix/js/session.js b/the-matrix/js/session.js index bfaedf7..b505770 100644 --- a/the-matrix/js/session.js +++ b/the-matrix/js/session.js @@ -51,6 +51,7 @@ export function initSessionPanel() { _on('session-back-btn', 'click', () => _setStep('active')); _on('topup-quick-btn', 'click', () => { _openPanel(); _setStep('topup'); }); _on('session-hud-topup', 'click', (e) => { e.preventDefault(); _openPanel(); _setStep('topup'); }); + _on('session-clear-history-btn', 'click', _clearHistory); // Amount preset buttons — deposit (quick-fill the number input) _panel.querySelectorAll('[data-session-step="fund"] .session-amount-btn').forEach(btn => { @@ -419,6 +420,30 @@ function _startTopupPolling() { _pollTimer = setTimeout(poll, POLL_MS); } +// ── Clear history ───────────────────────────────────────────────────────────── + +async function _clearHistory() { + if (!_sessionId || !_macaroon) return; + const btn = document.getElementById('session-clear-history-btn'); + if (btn) btn.disabled = true; + try { + const res = await fetch(`${API}/sessions/${_sessionId}/history`, { + method: 'DELETE', + headers: { 'Authorization': `Bearer ${_macaroon}` }, + }); + if (res.ok) { + _setStatus('active', '✓ History cleared', '#44dd88'); + setTimeout(() => _setStatus('active', '', ''), 2500); + } else { + _setStatus('active', 'Failed to clear history', '#ff6644'); + } + } catch (err) { + _setStatus('active', 'Error: ' + err.message, '#ff6644'); + } finally { + if (btn) btn.disabled = false; + } +} + // ── Restore from localStorage ───────────────────────────────────────────────── async function _tryRestore() { -- 2.43.0