File size: 945 Bytes
09f1b19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""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))