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
+3
View File
@@ -238,3 +238,6 @@ undefined/
# hand-off zips and local reports (python -m collection export-bot-kit / refresh)
exports/
inbox/
# PyCharm
.idea/
+16 -8
View File
@@ -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")
+35 -5
View File
@@ -150,10 +150,27 @@ def bot_variables(traj, crosswalk):
return v, unmapped
BURN_REASONS = { # why the bot chose to die, in words (the bot's own reason codes)
"TREE_NO_SHADOW_AUTO_BURN": "no shadow at the tree",
"MEADOW_NO_BLUE_AUTO_BURN": "no Blue in the meadow",
}
def _seen_after(steps, start, key):
"""Values the bot saw (step["seen"][key]) from step index `start` on."""
out = []
for st in steps[start:]:
v = (st.get("seen") or {}).get(key)
if v is not None:
out += v if isinstance(v, list) else [v]
return out
def bot(name, spec):
cw = [(re.compile(rx), col, val) for rx, col, val in read_yaml(spec["transform"]["spec"])["crosswalk"]]
rows = []
for traj in bot_trajectories(spec):
steps = traj["steps"]
v, _ = bot_variables(traj, cw)
red = v.pop("red", None)
v.pop("scream_investigate", None)
@@ -165,18 +182,31 @@ def bot(name, spec):
if o["type"] == "BONDED":
outcome, colour = "Bonded", (o.get("colour") or "").capitalize() or None
elif o["type"] == "BURNED":
last_tint = traj["steps"][-1].get("tint")
last_tint = steps[-1].get("tint") if steps else None
outcome = "Incinerated" if v.get("hour") else "Died before the hour"
colour = last_tint.capitalize() if last_tint and v.get("hour") else None
if o.get("intentional"):
flags.append("deliberate burn (the bot chose to die)")
else:
why = BURN_REASONS.get(o.get("reason") or "", "")
flags.append("deliberate burn (the bot chose to die" + (f": {why}" if why else "") + ")")
else: # ABORTED, ENDED_NO_BOND: the run stopped without an ending the bot saw
outcome, colour = "No outcome recorded", None
if not steps:
flags.append("bonded dragon only (the bot logged no steps)")
target = (meta.get("target") or "").capitalize() or None
row = blank_row(run_id=traj["id"], source=spec["run_source"], date=(meta.get("startedAt") or "")[:10] or None,
attempt=meta.get("attempt"), goal=target if target in COLOURS else None,
row = blank_row(run_id=traj["id"], source=spec["run_source"], bot_mode=meta.get("decisionMode"),
date=(meta.get("startedAt") or "")[:10] or None, attempt=meta.get("attempt"),
goal=target if target in COLOURS else None,
outcome=outcome, outcome_color=colour, data_flags="; ".join(flags), **v)
row["attempt_group"] = attempt_group(row["attempt"])
# what the bot saw: the shadow at the treetop, and which dragons waited in the meadow
shadow = _seen_after(steps, 0, "shadow")
if row["hour"] == "Tree" and shadow:
row["saw_shadow"] = any(shadow)
if row["branch"] == "Passed the Red: meadow":
i = next((k for k, st in enumerate(steps) if re.search(r"no way this is your dragon", _norm(st["optionText"]))), len(steps))
meadow = _seen_after(steps, i + 1, "dragons")
if meadow or o.get("reason") == "MEADOW_NO_BLUE_AUTO_BURN":
row["saw_blue_meadow"] = "blue" in meadow or colour == "Blue"
encounter_columns(row, intentional=bool(o.get("intentional")))
rows.append(row)
return rows
+131 -3
View File
@@ -215,17 +215,145 @@ def merge_scenes(existing, scenes):
return dict(sorted(out.items()))
# ---------------------------------------------------------------- run records with steps (the bot's schema 2)
def _to(key):
"""The bot's toKey -> ours: a scene id, BURNED or BONDED:<colour>."""
key = str(key or "")
if key == "TERMINAL:BURNED":
return "BURNED"
if key.startswith("TERMINAL:BONDED"):
return "BONDED:" + (key.split("_", 1)[1].lower() if "_" in key else "unknown")
return key or None
def _seen(observed):
"""What the bot saw on a screen that the route model needs: the dragons (from the tint) and the shadow."""
o = observed or {}
out = {}
if o.get("dragons"):
out["dragons"] = [str(d).lower() for d in o["dragons"]]
if "shadow" in o:
out["shadow"] = bool(o["shadow"])
return out
def trajectory_from_run(r, account_key):
"""A run record that carries its own steps -> a trajectory. Nothing but choice text, ids and outcomes is kept."""
steps = []
for st in r.get("steps") or []:
text = st.get("choiceText") or st.get("choiceNorm")
if not text:
continue
steps.append({
"scene": st.get("nodeId"), "stage": st.get("stage") or "UNKNOWN", "tint": st.get("tint"),
"option": option_id(text), "optionText": text,
"offered": [option_id(o.get("text") or o.get("norm")) for o in st.get("offered") or [] if o.get("text") or o.get("norm")],
"rule": st.get("rule"), "decisionMode": "manual" if st.get("manual") else st.get("decisionMode"),
"manual": bool(st.get("manual")), "at": st.get("at"), "seen": _seen(st.get("observed")),
"propensity": st.get("propensity"), "to": _to(st.get("toKey")),
})
colour = str(r["dragonColor"]).lower() if r.get("dragonColor") else None
return {
"id": "bot-" + sha1(r["runId"], 10),
"source": "bot",
"meta": {"attempt": r.get("accountAttempt") or r.get("attempt"), "startedAt": r.get("startedAt"),
"accountKey": account_key, "accountRole": r.get("accountRole"), "target": r.get("targetDragon"),
"decisionMode": r.get("decisionMode"), "policyId": r.get("policyId"),
"experimentId": r.get("experimentId"), "arm": r.get("arm")},
"steps": steps,
"outcome": {"type": r.get("outcome") or "ABORTED", "colour": colour, "intentional": bool(r.get("intentionalBurn")),
"reason": (r.get("burn") or {}).get("reason")},
}
def _account_files(files):
"""{account: {"runs": [...], "encounters": [...]}} from the packed files. The top-level files are the bot's
original single account; data/accounts/<name>/ and logs/accounts/<name>/ hold one account each."""
out = {}
for rel, text in files.items():
if text is None:
continue
parts = rel.split("/")
acct = parts[2] if len(parts) == 4 and parts[1] == "accounts" else "(default)"
kind = "runs" if rel.endswith("runs.jsonl") else "encounters" if rel.endswith("encounters.jsonl") else None
if kind:
out.setdefault(acct, {"runs": [], "encounters": []})[kind] += _jsonl(text)
# since the bot keeps one folder per account, its top-level files mirror its first account (the same runs,
# logged a moment apart): counting both would count those runs twice
if len(out) > 1:
out.pop("(default)", None)
return out
def account_salt(env, privacy):
"""The salt that turns account names into anonymous keys: the environment variable if set, otherwise one made
once and kept in the private raw store (data/raw/bot/account-salt.txt, never committed)."""
salt = env.get(privacy.get("account_salt_env", ""))
if salt:
return salt
from ..common import path
import secrets
p = path("data/raw/bot/account-salt.txt")
if not p.exists():
p.parent.mkdir(parents=True, exist_ok=True)
p.write_text(secrets.token_hex(16), encoding="utf-8")
return p.read_text(encoding="utf-8").strip()
def transform(raw_path, spec, ctx):
with open(raw_path, encoding="utf-8") as f:
files = json.load(f)
k = files.get("data/knowledge.json")
knowledge = json.loads(k) if k else {"nodes": {}}
encounters = _jsonl(files.get("logs/encounters.jsonl"))
runs = _jsonl(files.get("data/runs.jsonl"))
privacy = spec.get("privacy") or {}
scenes, trajectories, unlabeled = import_bot(knowledge, encounters, runs, ctx.get("env", {}).get(privacy.get("account_salt_env", "")))
salt = account_salt(ctx.get("env", {}), privacy)
accounts = _account_files(files)
all_encounters = [e for a in accounts.values() for e in a["encounters"]]
scenes = build_scenes(knowledge, all_encounters)
trajectories, seen_ids = [], set()
for acct, data in sorted(accounts.items()):
key = sha1(f"{salt}:{acct}", 10)
with_steps = [r for r in data["runs"] if r.get("steps") and r.get("runId")]
for r in with_steps:
t = trajectory_from_run(r, key)
if t["id"] not in seen_ids:
seen_ids.add(t["id"])
trajectories.append(t)
# older runs without steps: rebuild them from the decision log, as before
legacy = [r for r in data["runs"] if not r.get("steps")]
window = SPEC["match_hours"] * 3600e3
same_run = lambda t, r: (t["meta"]["attempt"] == (r.get("accountAttempt") or r.get("attempt")) # noqa: E731
and abs(_ms(t["meta"]["startedAt"]) - _ms(r.get("startedAt"))) < window)
old = attach_run_meta(trajectories_from_encounters(data["encounters"], scenes), legacy, salt)
kept = []
for t in old: # the decision log also holds the runs that have steps: keep only the others
if any(same_run(t, r) for r in with_steps) or t["id"] in seen_ids:
continue
t["meta"]["accountKey"] = key
seen_ids.add(t["id"])
trajectories.append(t)
kept.append(t)
# bonded runs logged without any steps still say which dragon was bonded
for r in legacy:
if r.get("outcome") == "BONDED" and r.get("runId") and not any(same_run(t, r) for t in kept):
t = trajectory_from_run({**r, "steps": []}, key)
if t["id"] not in seen_ids:
seen_ids.add(t["id"])
trajectories.append(t)
# scenes the run records show but the knowledge file does not have yet
for t in trajectories:
for st in t["steps"]:
if st["scene"] and st["scene"] not in scenes:
scenes[st["scene"]] = {"stage": st["stage"], "tint": st["tint"], "backdrop": None,
"label": label_for(st["scene"], {"stage": st["stage"], "tint": st["tint"]}), "options": []}
sc = scenes.get(st["scene"])
if sc is not None and st["option"] not in {o["id"] for o in sc["options"]}:
sc["options"].append({"id": st["option"], "text": st["optionText"]})
unlabeled = [f"{sid} ({s['stage']}{', ' + s['tint'] if s['tint'] else ''})" for sid, s in scenes.items() if sid not in SPEC["labels"]]
for obj in (scenes, trajectories):
check_public(obj, set(privacy.get("refuse_fields", [])), privacy.get("max_string", 200))
trajectories.sort(key=lambda t: (str(t["meta"].get("startedAt")), t["id"]))
return {"scenes": scenes, "trajectories": trajectories, "_unlabeled": unlabeled}
+8 -2
View File
@@ -79,10 +79,16 @@ sources:
label: DragonKind bot runs (Ken's private bot, imported locally)
run_source: bot
# the bot's repo is private: this step runs only on a machine with a copy of it
extract: { kind: local_dir, env: DRAGONKIND_BOT_DIR, files: [data/knowledge.json, data/runs.jsonl, logs/encounters.jsonl] }
# data/accounts/<account>/ and logs/accounts/<account>/: one folder per game account (account names are
# replaced by salted hashes); the top-level files are the bot's original single account
extract:
kind: local_dir
env: DRAGONKIND_BOT_DIR
files: [data/knowledge.json, data/runs.jsonl, logs/encounters.jsonl, data/accounts/*/runs.jsonl, logs/accounts/*/encounters.jsonl]
transform: { name: bot, spec: collection/specs/bot.yaml }
privacy:
account_salt_env: DK_ACCOUNT_SALT # account ids are hashed with this salt, which is never committed
account_salt_env: DK_ACCOUNT_SALT # account names are hashed with this salt (or, if unset, one kept in
# data/raw/bot/account-salt.txt); never committed
refuse_fields: [prose, proseNorm, proseExcerpt, email, password, accountId, accountName]
max_string: 200 # anything longer looks like game prose
load: data/bot # scenes.json (merged) + trajectories-<date>.jsonl
+17 -4
View File
@@ -46,15 +46,20 @@ crosswalk:
- ["^enter the valley alone", company, "Alone"]
- ["^enter the valley with one of your squadmates", company, "1 Squadmate"]
- ["^enter the valley with two of your squadmates", company, "2 Squadmates"]
- ["^leave your squadmates?$", left_squadmates, true]
- ["^head east toward the roar", direction, "East"]
- ["^head west toward the scent", direction, "West"]
- ["^head toward the center of the forest", direction, "Center"]
# with squadmates, the direction is agreed with them
- ["^go east with your squad|^convince them to head east", direction, "East"]
- ["^go west with your squad|^convince them to head west", direction, "West"]
- ["^keep walking the cadets are just as dangerous", scream, "Ignore the scream"]
- ["^run and hope", sighting_action, "Retreat / run"]
- ["hold still", sighting_action, "Hold still"]
- ["hold still|hold your ground", sighting_action, "Hold still"]
- ["lower your eyes in respect|lower your eyes and turn to face it", sighting_action, "Respect / face it"]
- ["meeting its gaze", sighting_action, "Meet its gaze"]
- ["^hide behind a tree", sighting_action, "Hide"]
- ["^hide behind a tree|^duck behind a boulder", sighting_action, "Hide"]
- ["^approach with confidence|^approach from the left", sighting_action, "Approach"]
- ["^investigate the scream", scream_investigate, true]
- ["^help your squadmate", scream, "Investigate & help"]
- ["^play it safe and leave them", scream, "Investigate & leave"]
@@ -68,14 +73,22 @@ crosswalk:
- ["^leave the bullies alive", resolution, "Left bullies to the dragons"]
- ["tourniquet", resolution, "Tourniquet"]
# the wounded cadet's other two choices (the bot has not logged this screen yet, so these are kept loose)
- ["leave (them|him|her) to die", resolution, "Left injured cadet"]
- ["take (their|his|her) weapons?", resolution, "Took their weapons"]
- ["leave (them|him|her) to die|^keep going clearly they've been found lacking", resolution, "Left injured cadet"]
- ["take (their|his|her|the cadet's) weapons?", resolution, "Took their weapons"]
- ["^walk toward the east", post_path, "East"]
- ["^walk toward the west", post_path, "West"]
- ["^walk farther into the forest", post_path, "Forest"]
- ["^continue toward the center of the valley", hour, "Valley"]
- ["^find the tallest tree", hour, "Tree"]
# the Red in the valley centre
- ["^there's no way this is your dragon", branch, "Passed the Red: meadow"]
- ["^this is your dragon and it's time to start bonding", branch, "Valley Red"]
- ["^descend quickly", branch, "Descend quickly: Red"]
- ["^climb down slowly to pursue the green", branch, "Descend slowly: two Greens"]
- ["^reds are too hot tempered", red, "Let it pass (two Greens)"]
- ["^jump (now|in a few seconds)", red, "Jump onto the Red"]
# Route choices (before the hour) that no column of the coded runs has a value for; they are coded as unknown.
# tests/collection/test_collection.py fails on any other unmapped route choice.
not_coded:
- "^stare at the ground and drop the weapon" # a first-sighting reaction with no form category
+10 -4
View File
@@ -84,15 +84,19 @@
[/^enter the valley alone/, "company", "Alone"],
[/^enter the valley with one of your squadmates/, "company", "1 Squadmate"],
[/^enter the valley with two of your squadmates/, "company", "2 Squadmates"],
[/^leave your squadmates?$/, "left_squadmates", true],
[/^head east toward the roar/, "direction", "East"],
[/^head west toward the scent/, "direction", "West"],
[/^head toward the center of the forest/, "direction", "Center"],
[/^go east with your squad|^convince them to head east/, "direction", "East"],
[/^go west with your squad|^convince them to head west/, "direction", "West"],
[/^keep walking the cadets are just as dangerous/, "scream", "Ignore the scream"],
[/^run and hope/, "sighting_action", "Retreat / run"],
[/hold still/, "sighting_action", "Hold still"],
[/hold still|hold your ground/, "sighting_action", "Hold still"],
[/lower your eyes in respect|lower your eyes and turn to face it/, "sighting_action", "Respect / face it"],
[/meeting its gaze/, "sighting_action", "Meet its gaze"],
[/^hide behind a tree/, "sighting_action", "Hide"],
[/^hide behind a tree|^duck behind a boulder/, "sighting_action", "Hide"],
[/^approach with confidence|^approach from the left/, "sighting_action", "Approach"],
[/^investigate the scream/, "scream_investigate", true],
[/^help your squadmate/, "scream", "Investigate & help"],
[/^play it safe and leave them/, "scream", "Investigate & leave"],
@@ -105,13 +109,15 @@
[/^allow your squadmate to exact/, "resolution", "Squadmate's revenge"],
[/^leave the bullies alive/, "resolution", "Left bullies to the dragons"],
[/tourniquet/, "resolution", "Tourniquet"],
[/leave (them|him|her) to die/, "resolution", "Left injured cadet"],
[/take (their|his|her) weapons?/, "resolution", "Took their weapons"],
[/leave (them|him|her) to die|^keep going clearly they've been found lacking/, "resolution", "Left injured cadet"],
[/take (their|his|her|the cadet's) weapons?/, "resolution", "Took their weapons"],
[/^walk toward the east/, "post_path", "East"],
[/^walk toward the west/, "post_path", "West"],
[/^walk farther into the forest/, "post_path", "Forest"],
[/^continue toward the center of the valley/, "hour", "Valley"],
[/^find the tallest tree/, "hour", "Tree"],
[/^there's no way this is your dragon/, "branch", "Passed the Red: meadow"],
[/^this is your dragon and it's time to start bonding/, "branch", "Valley Red"],
[/^descend quickly/, "branch", "Descend quickly: Red"],
[/^climb down slowly to pursue the green/, "branch", "Descend slowly: two Greens"],
[/^reds are too hot tempered/, "red", "Let it pass (two Greens)"],
+17 -2
View File
@@ -94,8 +94,8 @@
"description": "Every run from every source, one per row, coded into the same columns (collection/etl/runs.py; the form's rules are core/spec/form.yaml). The `source` column says where each run came from.",
"contentUrl": "https://ekcschiano.github.io/threshing-atlas/data/runs_clean.csv",
"encodingFormat": "text/csv",
"sha256": "766d8708dad77327534063df42cd4ff806ab707497618ab5263cf3dce98a30c7",
"contentSize": "2146368 B"
"sha256": "ebea05e83b0de850a4db77095beebe1f42ffb89f3f7b1d5f66469f772494af23",
"contentSize": "2152413 B"
},
{
"@type": "cr:FileObject",
@@ -213,6 +213,21 @@
}
}
},
{
"@type": "cr:Field",
"@id": "runs/bot_mode",
"name": "bot_mode",
"description": "For bot runs, how the bot chose: \"auto_learn\" (its own rules and the route PDF), \"atlas_policy\" (the Atlas's route model), \"explore\" (trying untested options), \"experiment\" (a randomised test), \"manual\" (a person clicked). Matters for analysis: the bot follows a strategy, so its choices are not like a player's. Empty for other sources. Values: auto_learn; atlas_policy; explore; experiment; manual.",
"dataType": "sc:Text",
"source": {
"fileObject": {
"@id": "runs_clean"
},
"extract": {
"column": "bot_mode"
}
}
},
{
"@type": "cr:Field",
"@id": "runs/date",
+8
View File
@@ -87,6 +87,14 @@ columns:
bulk-pasted logs keep the label they were pasted with. Bulk logs record every run of the players who kept
them, so they are the least selectively reported rows. Empty for other sources.
values: [Form, Data Import, BulkUpload3, Manual Upload, Historical import, Unknown import]
bot_mode:
type: text
description: >-
For bot runs, how the bot chose: "auto_learn" (its own rules and the route PDF), "atlas_policy" (the Atlas's
route model), "explore" (trying untested options), "experiment" (a randomised test), "manual" (a person
clicked). Matters for analysis: the bot follows a strategy, so its choices are not like a player's. Empty for
other sources.
values: [auto_learn, atlas_policy, explore, experiment, manual]
date: { type: date, description: "Date of the run or its report (YYYY-MM-DD): the form submission, the issue, or the bot attempt. Empty for bulk-pasted rows and result pages." }
wing: { type: text, description: The rider's wing, from the form., values: [First, Second, Third, Fourth, Multiple, Unknown] }
section: { type: text, description: The rider's section within the wing (free text as answered). }
+6007 -6007
View File
File diff suppressed because it is too large Load Diff
+7 -2
View File
@@ -15,8 +15,13 @@ When GitHub Pages is not available, the same files travel as zips:
- **Atlas → bot:** `python -m collection export-bot-kit` writes `exports/atlas-for-bot-<date>-<policy id>.zip`
(`policy.json`, `solver.js`, `graph.js`, a README with checksums). Unzip it into the bot's `vendor/threshing-atlas/`.
- **Bot → atlas:** zip the bot's `data/runs.jsonl`, `data/knowledge.json` and `logs/encounters.jsonl` (folder names
kept; a zip of the whole repo works too) and send it. Put it in the atlas's `inbox/` and run
- **Bot → atlas:** zip the bot's `data/` and `logs/` folders (folder names kept; a zip of the whole repo works too;
screenshots are not needed) and send it. The importer reads `data/knowledge.json` and, for every account,
`data/accounts/<account>/runs.jsonl` and `logs/accounts/<account>/encounters.jsonl` (with one folder per
account, the top-level `data/runs.jsonl` and `logs/encounters.jsonl` mirror the first account and are skipped).
Run records that carry their own steps (the bot's schema 2) are used as they are, including what the bot saw
(shadow, meadow dragons), its decision mode and the policy id; older runs are rebuilt from the decision log.
Account names become salted hashes. Put it in the atlas's `inbox/` and run
`python -m collection refresh --bot inbox/<the zip>`: it imports the runs (anonymised: no prose, no account names),
rebuilds everything, and then `export-bot-kit` makes the new zip to send back.
+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:
+1 -10
View File
@@ -43,13 +43,4 @@ test("Beta credible interval", () => {
assert.ok(p.lo >= 0 && p.hi < 0.5 && p.mean === 0.1);
});
test("every choice the bot has seen maps onto a form variable, except answers inside a bonding encounter", () => {
const scenes = require("../../data/bot/scenes.json");
const unmapped = [];
for (const s of Object.values(scenes)) {
if (s.options.length < 2) continue; // nothing to choose
if (/two Greens in the clearing/.test(s.label)) continue; // answers at the Greens' encounter: not modelled yet
for (const o of s.options) if (!G.CROSSWALK.some(([re]) => re.test(G.norm(o.text)))) unmapped.push(`${s.label}: ${o.text}`);
}
assert.deepStrictEqual(unmapped, []);
});
// every route choice the bot has seen maps onto a column: tests/collection/test_collection.py (Bot)