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:
ekcSchiano
2026-11-10 02:08:57 +00:00
co-authored by Claude Opus 5.5
parent dd25dfaa32
commit 43066ad67f
13 changed files with 6292 additions and 6051 deletions
+32 -4
View File
@@ -100,15 +100,42 @@ class Bot(unittest.TestCase):
self.assertEqual(py, {k: v for k, v in j.items() if k not in ("outcome", "outcome_color")})
def test_every_bot_choice_is_mapped(self):
"""Every choice the bot has seen maps onto a column, except answers inside a bonding encounter."""
"""Every route choice the bot has seen before the hour maps onto a column (answers inside the bonding
encounters are not route choices), unless bot.yaml lists it as not coded."""
import re
cw = [re.compile(rx) for rx, _, _ in read_yaml("collection/specs/bot.yaml")["crosswalk"]]
spec = read_yaml("collection/specs/bot.yaml")
cw = [re.compile(rx) for rx, _, _ in spec["crosswalk"]] + [re.compile(rx) for rx in spec.get("not_coded", [])]
scenes = json.loads((ROOT / "data/bot/scenes.json").read_text(encoding="utf-8"))
route = {"ENTER_THRESHING", "FIRST_SIGHTING", "SCREAM_AND_CADETS"}
unmapped = [f"{s['label']}: {o['text']}" for s in scenes.values()
if len(s["options"]) > 1 and "two Greens in the clearing" not in s["label"]
if len(s["options"]) > 1 and s["stage"] in route and "two Greens in the clearing" not in s["label"]
for o in s["options"] if not any(rx.search(bot.normalize(o["text"])) for rx in cw)]
self.assertEqual(unmapped, [])
def test_runs_with_steps_and_accounts(self):
"""The bot's newer run records (one folder per account) become trajectories without account names or
prose; the top-level files mirror the first account and are skipped."""
run = {"runId": "run-1", "attempt": 3, "accountAttempt": 3, "accountId": "someone-example-com",
"accountRole": "research", "startedAt": "2026-11-09T22:02:14.430Z", "targetDragon": "black",
"decisionMode": "atlas_policy", "policyId": "atlas:x", "outcome": "BURNED", "intentionalBurn": True,
"burn": {"reason": "TREE_NO_SHADOW_AUTO_BURN"}, "dragonColor": None,
"steps": [{"nodeId": "a68f681076c6", "stage": "ENTER_THRESHING", "choiceText": "Find the tallest tree and climb for a better view",
"offered": [{"text": "Find the tallest tree and climb for a better view"}, {"text": "Continue toward the center of the valley"}],
"observed": {"shadow": False, "dragons": ["Green"]}, "propensity": 0.5, "toKey": "TERMINAL:BURNED",
"label": "x" * 300, "prose": "game text"}]}
line = json.dumps(run) + "\n"
files = {"data/runs.jsonl": line, "data/accounts/someone-example-com/runs.jsonl": line,
"logs/accounts/someone-example-com/encounters.jsonl": ""}
accts = bot._account_files(files)
self.assertEqual(list(accts), ["someone-example-com"])
t = bot.trajectory_from_run(run, "abc123")
self.assertEqual(t["steps"][0]["seen"], {"dragons": ["green"], "shadow": False})
self.assertEqual((t["steps"][0]["to"], t["meta"]["accountKey"], t["outcome"]["reason"]), ("BURNED", "abc123", "TREE_NO_SHADOW_AUTO_BURN"))
text = json.dumps(t)
self.assertNotIn("someone", text)
self.assertNotIn("game text", text)
bot.check_public(t, {"prose", "accountId"}, 200)
def test_graph_js_crosswalk_is_generated(self):
self.assertEqual(codegen.graph_js(), (ROOT / codegen.GRAPH_JS).read_text(encoding="utf-8"))
@@ -120,7 +147,8 @@ class Handoff(unittest.TestCase):
z = TMP / "ken.zip"
with zipfile.ZipFile(z, "w") as f: # files under a top folder, as a zipped repo would have them
for rel in spec["files"]:
f.write(FX / rel, f"DragonKind-main/{rel}")
if "*" not in rel:
f.write(FX / rel, f"DragonKind-main/{rel}")
self.assertEqual(extract.pack_local(spec, z), extract.pack_local(spec, FX))
empty = TMP / "empty.zip"
with zipfile.ZipFile(empty, "w") as f: