"""Write task instances to disk for independent solver checks. Usage: python tools/dump_instances.py OUT_DIR [SEEDS] Writes OUT_DIR/tasks///{task.txt,app/...} and OUT_DIR/expected.json (keep it away from solvers). """ import json import os import random import sys from terminal_desk.families import FAMILIES, all_task_ids, parse_task_id out, seeds = sys.argv[1], int(sys.argv[2]) if len(sys.argv) > 2 else 3 expected = {} for tid in all_task_ids(): fid, lv, _ = parse_task_id(tid) for seed in range(seeds): built = FAMILIES[fid].build(lv, random.Random(1000 + seed)) base = os.path.join(out, "tasks", tid, str(seed)) for name, content in built.files.items(): path = os.path.join(base, "app", name) os.makedirs(os.path.dirname(path), exist_ok=True) if isinstance(content, bytes): open(path, "wb").write(content) else: open(path, "w", encoding="utf-8", newline="").write(content) open(os.path.join(base, "task.txt"), "w").write(built.instruction) expected[f"{tid}/{seed}"] = {"path": built.artifact.path, "kind": built.artifact.kind, "expected": built.artifact.expected} json.dump(expected, open(os.path.join(out, "expected.json"), "w"), indent=1, default=str) print(len(expected), "instances")