"""Diary module for persistent journaling.""" from __future__ import annotations import json from datetime import datetime from pathlib import Path from jenaai.core.module import BaseModule class Module(BaseModule): """Stores conversations, reflections, and errors.""" def __init__(self, event_bus, config): super().__init__(event_bus, config) self.diary_path = Path(config.get("diary_path", "data/diary.json")) self.diary_path.parent.mkdir(parents=True, exist_ok=True) async def write_entry(self, category: str, content: str) -> None: entry = { "timestamp": datetime.utcnow().isoformat(), "category": category, "content": content, } entries = [] if self.diary_path.exists(): entries = json.loads(self.diary_path.read_text()) entries.append(entry) self.diary_path.write_text(json.dumps(entries, indent=2))