feat: experiment log append/read utilities and rich viewer
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user