import json, pathlib, sys
home = pathlib.Path(sys.argv[1])
files = list((home / "sessions").rglob("*.jsonl"))
assert len(files) == 1, f"Expected one synthetic rollout, found {len(files)}"
p = files[0]
rows = [json.loads(line) for line in p.read_text().splitlines()]
changed = 0
for row in rows:
    item = row.get("payload", {})
    if item.get("type") == "reasoning" and item.get("encrypted_content"):
        content = item["encrypted_content"]
        at = len(content) // 2
        item["encrypted_content"] = content[:at] + ("A" if content[at] != "A" else "B") + content[at+1:]
        changed += 1
assert changed, "No encrypted reasoning item was produced"
p.write_text("".join(json.dumps(row) + "\n" for row in rows))
print(json.dumps({"encryptedItemsCorrupted": changed, "nativeSessionId": rows[0]["payload"]["id"]}))
