This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
alexpaynex 7d4e07854f feat: chat history persistence via localStorage (#13)
Tracks Gitea issue perplexity/the-matrix #4.

## Storage helpers (ui.js)
- loadChatHistory(agentId) — reads matrix:chat:<agentId> from localStorage,
  returns [] on missing/corrupt data
- saveChatHistory(agentId, messages) — writes capped array (slice -100) to
  localStorage; silently ignores QuotaExceededError
- In-memory chatHistory map per agentId populated from both helpers
- Storage keys: matrix:chat:alpha, matrix:chat:beta, matrix:chat:gamma,
  matrix:chat:delta, matrix:chat:sys

## Timestamps
- appendChatMessage now stamps each message with Date.now()
- formatTimestamp(ts) formats as HH:MM for display
- Rendered as <span class="chat-ts">[HH:MM]</span> before the agent name
- Timestamp stored in persisted message object for sort-on-restore

## Restore on load
- loadAllHistories() called from initUI() combines all five stores (4 agents
  + sys), sorts by timestamp, renders last MAX_CHAT_ENTRIES (12) into panel
- No flash: history is populated synchronously before first rAF tick

## Persist on receive (websocket.js)
- appendChatMessage for chat messages: passes def.id as agentId (4th param)
- logEvent (SYS messages): passes 'sys' as agentId
- No changes to WS connect/message/reconnect logic

## Clear button (index.html + ui.js)
- #chat-clear-btn: fixed position, outside #ui-overlay, pointer-events:all
  so it remains clickable while the overlay is pointer-events:none
- Positioned bottom-right, left of OFFLINE/CONNECTED indicator
- On click: removes all five localStorage keys, clears DOM, resets chatEntries
- Hover brightens from dim green to full #00ff41 glow for discoverability

## Deviation from spec
- Task assumed per-agent panels with selectAgent(). Current UI has one shared
  global panel. Per-agent storage is implemented exactly as specified; restore
  on load shows combined last-12 across all agents (best fit for single panel).
  Clear wipes all stored histories (no per-agent panel to scope it to).

## Verified
- npm run build exits 0, 14 modules, no new warnings
2026-03-18 23:57:07 +00:00
2026-03-13 23:21:55 +00:00
2026-03-18 17:19:38 +00:00
2026-03-13 23:21:55 +00:00
2026-03-13 23:21:55 +00:00
2026-03-13 23:21:55 +00:00
Description
Timmy — Lightning-gated AI agent (TypeScript/Express)
30 MiB
Languages
TypeScript 68.2%
JavaScript 14.8%
Shell 12.4%
HTML 4.1%
CSS 0.4%