history.py 559 B

12345678910111213141516171819202122
  1. from __future__ import annotations
  2. from dataclasses import dataclass, field
  3. @dataclass(frozen=True)
  4. class HistoryEvent:
  5. title: str
  6. detail: str
  7. @dataclass
  8. class HistoryLog:
  9. events: list[HistoryEvent] = field(default_factory=list)
  10. def add(self, title: str, detail: str) -> None:
  11. self.events.append(HistoryEvent(title=title, detail=detail))
  12. def as_markdown(self) -> str:
  13. lines = ['# Session History', '']
  14. lines.extend(f'- {event.title}: {event.detail}' for event in self.events)
  15. return '\n'.join(lines)