Bot import: one folder per account, run records with steps
- the importer reads data/accounts/*/runs.jsonl and logs/accounts/*/encounters.jsonl; with account folders, the top-level files (a mirror of the first account) are skipped - run records that carry their steps (schema 2) become trajectories directly, keeping what the bot saw (shadow, meadow dragons), propensities, decision mode and policy id; older runs are still rebuilt from the decision log; bonded runs without steps are kept - account names become salted hashes (DK_ACCOUNT_SALT, or a private salt in data/raw) - runs_clean.csv: new bot_mode column; saw_shadow and saw_blue_meadow from what the bot saw; deliberate burns say why - crosswalk: the valley Red, leaving squadmates, squad direction, hold your ground, hide/approach reactions, the wounded cadet's other two choices Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
dd25dfaa32
commit
43066ad67f
@@ -10,6 +10,8 @@ Each extractor returns the raw bytes, or raises Skip when the source cannot be r
|
||||
secret, the bot's private repo not on this machine).
|
||||
"""
|
||||
import base64
|
||||
import fnmatch
|
||||
import glob
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
@@ -87,9 +89,12 @@ def local_dir(spec, env):
|
||||
if not root:
|
||||
raise Skip(f"the bot's repo is private: set {spec['env']} to a local copy to import it")
|
||||
files = {}
|
||||
for rel in spec["files"]:
|
||||
p = os.path.join(root, rel)
|
||||
files[rel] = Path(p).read_text(encoding="utf-8") if os.path.exists(p) else None
|
||||
for pattern in spec["files"]: # a pattern may have * for one folder level (one folder per bot account)
|
||||
hits = sorted(glob.glob(os.path.join(root, pattern)))
|
||||
for p in hits:
|
||||
files[os.path.relpath(p, root).replace(os.sep, "/")] = Path(p).read_text(encoding="utf-8")
|
||||
if not hits and "*" not in pattern:
|
||||
files[pattern] = None
|
||||
return json.dumps(files, ensure_ascii=False, sort_keys=True).encode("utf-8")
|
||||
|
||||
|
||||
@@ -99,13 +104,16 @@ def pack_local(spec, src):
|
||||
src = Path(src).expanduser()
|
||||
if src.is_dir():
|
||||
return local_dir(spec, {spec["env"]: str(src)})
|
||||
files = {rel: None for rel in spec["files"]}
|
||||
files = {rel: None for rel in spec["files"] if "*" not in rel}
|
||||
with zipfile.ZipFile(src) as z:
|
||||
names = [n for n in z.namelist() if not n.endswith("/") and "__MACOSX" not in n]
|
||||
for rel in spec["files"]:
|
||||
hits = sorted((n for n in names if n == rel or n.endswith("/" + rel)), key=len)
|
||||
if hits:
|
||||
files[rel] = z.read(hits[0]).decode("utf-8")
|
||||
for pattern in spec["files"]:
|
||||
for n in names:
|
||||
# the files may sit under a top folder (a zipped repo): match the pattern on the end of the name
|
||||
parts = n.split("/")
|
||||
rel = next(("/".join(parts[i:]) for i in range(len(parts)) if fnmatch.fnmatchcase("/".join(parts[i:]), pattern)), None)
|
||||
if rel and files.get(rel) is None:
|
||||
files[rel] = z.read(n).decode("utf-8")
|
||||
if not any(files.values()):
|
||||
raise RuntimeError(f"{src.name}: none of {', '.join(spec['files'])} found inside")
|
||||
return json.dumps(files, ensure_ascii=False, sort_keys=True).encode("utf-8")
|
||||
|
||||
Reference in New Issue
Block a user