Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions .agent/tools/learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"""
import argparse, datetime, json, os, subprocess, sys

if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
sys.stderr.reconfigure(encoding="utf-8", errors="replace")

BASE = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
CANDIDATES = os.path.join(BASE, "memory/candidates")
sys.path.insert(0, os.path.join(BASE, "harness"))
Expand All @@ -40,16 +44,17 @@ def _lesson_already_appended(cid):
return False
target = f"lesson_{cid}"
try:
for line in open(lessons_path):
line = line.strip()
if not line:
continue
try:
row = json.loads(line)
except json.JSONDecodeError:
continue
if row.get("id") == target:
return True
with open(lessons_path, encoding="utf-8") as f:
for line in f:
line = line.strip()
if not line:
continue
try:
row = json.loads(line)
except json.JSONDecodeError:
continue
if row.get("id") == target:
return True
except OSError:
return False
return False
Expand Down Expand Up @@ -105,7 +110,7 @@ def stage(claim, conditions, source="learn", importance=7):
"rejection_count": 0,
}
path = os.path.join(CANDIDATES, f"{cid}.json")
with open(path, "w") as f:
with open(path, "w", encoding="utf-8") as f:
json.dump(candidate, f, indent=2)
_append_episodic_mirror(cid, claim, now, source)
return cid, path
Expand Down