feat: experiment log append/read utilities and rich viewer

This commit is contained in:
2026-04-04 14:31:45 +02:00
parent 02d44d30be
commit 8fdbd81a05
3 changed files with 133 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
"""Append-only experiment log utilities."""
import json
import os
from datetime import datetime, timezone
LOG_PATH = os.path.expanduser('~/.claude/autoresearch/log.jsonl')
def append_entry(entry: dict, path: str = LOG_PATH) -> None:
entry = dict(entry) # don't mutate caller's dict
entry.setdefault('ts', datetime.now(timezone.utc).isoformat())
os.makedirs(os.path.dirname(os.path.abspath(path)), exist_ok=True)
with open(path, 'a') as f:
f.write(json.dumps(entry) + '\n')
def read_entries(path: str = LOG_PATH) -> list:
if not os.path.exists(path):
return []
entries = []
with open(path) as f:
for line in f:
line = line.strip()
if not line:
continue
try:
entries.append(json.loads(line))
except json.JSONDecodeError:
pass
return entries