History Logger (src/history.py)

claw-code · src/history.py · python · MIT
testing, analytics, infra, tag:markdown, tag:session

Logs and formats session events as markdown. Reuse for tracking and documenting user actions.

# Source: https://github.com/ultraworkers/claw-code | License: MIT | Copyright 2026 UltraWorkers and Claw Code contributors
# Provided via justclaw.it.com; keep this notice with the code.
from __future__ import annotations

from dataclasses import dataclass, field


@dataclass(frozen=True)
class HistoryEvent:
    title: str
    detail: str


@dataclass
class HistoryLog:
    events: list[HistoryEvent] = field(default_factory=list)

    def add(self, title: str, detail: str) -> None:
        self.events.append(HistoryEvent(title=title, detail=detail))

    def as_markdown(self) -> str:
        lines = ['# Session History', '']
        lines.extend(f'- {event.title}: {event.detail}' for event in self.events)
        return '\n'.join(lines)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key