Ruby/id/mirror.py

26 lines
746 B
Python

import json
from datetime import datetime
from pathlib import Path
MIRROR_LOG = Path("content/REM/mirror_log.jsonl")
def reflect(event_type: str, context: dict):
"""Logs introspective meta-data about Ruby's internal state/actions."""
entry = {
"timestamp": datetime.utcnow().isoformat(),
"event": event_type,
"context": context
}
with open(MIRROR_LOG, "a", encoding="utf-8") as f:
f.write(json.dumps(entry) + "\n")
def load_reflections(limit: int = 100):
"""Loads the last `limit` reflections."""
if not MIRROR_LOG.exists():
return []
with open(MIRROR_LOG, "r", encoding="utf-8") as f:
lines = f.readlines()[-limit:]
return [json.loads(line) for line in lines]