forked from Rockachopa/Timmy-time-dashboard
- Add dashboard/store.py: MessageLog dataclass singleton tracking user/agent/error messages for the lifetime of the server process - agents.py: write each chat turn to MessageLog; add GET and DELETE /agents/timmy/history routes returning the history.html partial - partials/history.html: render stored messages by role (YOU / TIMMY / SYSTEM); falls back to the Mission Control init message when empty - index.html: chat-log loads history via hx-get on page start; new CLEAR button in panel header sends hx-delete to reset the log - style.css: add .mc-btn-clear (muted, red-on-hover for the header) - tests: autouse reset_message_log fixture in conftest; 5 new history tests covering empty state, recording, offline errors, clear, and post-clear state → 32 tests total, all passing https://claude.ai/code/session_01KZMfwBpLuiv6x9GbzTqbys
32 lines
754 B
Python
32 lines
754 B
Python
from dataclasses import dataclass, field
|
|
|
|
|
|
@dataclass
|
|
class Message:
|
|
role: str # "user" | "agent" | "error"
|
|
content: str
|
|
timestamp: str
|
|
|
|
|
|
class MessageLog:
|
|
"""In-memory chat history for the lifetime of the server process."""
|
|
|
|
def __init__(self) -> None:
|
|
self._entries: list[Message] = []
|
|
|
|
def append(self, role: str, content: str, timestamp: str) -> None:
|
|
self._entries.append(Message(role=role, content=content, timestamp=timestamp))
|
|
|
|
def all(self) -> list[Message]:
|
|
return list(self._entries)
|
|
|
|
def clear(self) -> None:
|
|
self._entries.clear()
|
|
|
|
def __len__(self) -> int:
|
|
return len(self._entries)
|
|
|
|
|
|
# Module-level singleton shared across the app
|
|
message_log = MessageLog()
|