"""Assemble the public Hugging Face dataset folder. Writes OUT/tasks.jsonl (one task per line: id, family, domain, level, an example instruction, the calibration screen stats and whether the task is in the submission), and OUT/source/ (the environment, tools, tests, Dockerfile). The README card is kept by hand. Usage: python tools/make_dataset.py --screen runs/screen1.jsonl --selected runs/selected.txt --out dataset """ import argparse import json import os import random import shutil import sys from collections import defaultdict sys.path.insert(0, ".") from terminal_desk.families import FAMILIES, all_task_ids, parse_task_id # noqa: E402 SOURCE = ["terminal_desk", "tools", "tests", "Dockerfile", "openenv.yaml", "requirements-v3.txt", "README.md", "BUILD_NOTES.md", "vendor"] def main() -> None: p = argparse.ArgumentParser() p.add_argument("--screen", required=True) p.add_argument("--selected", required=True) p.add_argument("--out", required=True) a = p.parse_args() stats = defaultdict(list) for line in open(a.screen): r = json.loads(line) if "error" not in r: stats[r["task_id"]].append(r) selected = {ln.strip() for ln in open(a.selected) if ln.strip() and not ln.startswith("#")} with open(os.path.join(a.out, "tasks.jsonl"), "w") as fh: for tid in all_task_ids(): fid, level = parse_task_id(tid) fam = FAMILIES[fid] built = fam.build(level, random.Random(0)) rs = stats.get(tid, []) rewards = [r["reward"] for r in rs] fh.write(json.dumps({ "task_id": tid, "family": fid, "domain": fam.domain, "level": level, "title": fam.title, "in_submission": tid in selected, "screen_episodes": len(rs), "screen_mean_reward": round(sum(rewards) / len(rewards), 3) if rewards else None, "screen_full_solves": sum(1 for x in rewards if x == 1.0), "screen_non_json_endings": sum(1 for r in rs if r["ended"] in ("invalid_reply", "truncated", "invalid_action")), "screen_budget_endings": sum(1 for r in rs if r["ended"] in ("budget", "context")), "screen_mean_steps": round(sum(r["steps"] for r in rs) / len(rs), 2) if rs else None, "artifact_path": built.root + "/" + built.artifact.path, "artifact_kind": built.artifact.kind, "example_instruction": built.instruction, }) + "\n") src = os.path.join(a.out, "source") shutil.rmtree(src, ignore_errors=True) for name in SOURCE: if os.path.isdir(name): shutil.copytree(name, os.path.join(src, name), ignore=shutil.ignore_patterns("__pycache__")) else: shutil.copy(name, os.path.join(src, name)) print("dataset folder ready:", a.out) if __name__ == "__main__": main()