Download build_dataset.py from noodcon/TerminalBench-DockerLess: direct link, hf CLI and curl.
- Browser
- Download file 10.4 kB
-
https://huggingface.co/datasets/noodcon/TerminalBench-DockerLess/resolve/main/build_dataset.py
- Command line
-
hf download hf://datasets/noodcon/TerminalBench-DockerLess/build_dataset.py
-
curl -L -o build_dataset.py https://huggingface.co/datasets/noodcon/TerminalBench-DockerLess/resolve/main/build_dataset.py
10.4 kB
| """Build TerminalBench-DockerLess.jsonl from tasks/. | |
| A Terminal-Bench task is a directory: instruction, environment, solution, tests. | |
| Docker supplies the environment; here `environment/setup.sh` builds the same | |
| state in a throwaway directory instead, so a row is self-contained. | |
| For every task this script: | |
| 1. flattens the task directory into a row (instruction, files, tests, solution, | |
| dockerfile) and renders both a classic `task.yaml` and a Harbor `task.toml`; | |
| 2. runs the task with no agent at all, to record which verifier tests fail on | |
| the untouched environment (`dockerless.baseline_failures`); | |
| 3. writes the JSONL; | |
| 4. re-runs the whole file through run_harness.py with --solution and | |
| --baseline, and fails loudly unless the oracle scores 4/4 and the baseline | |
| scores 0/4. | |
| Run with: python build_dataset.py | |
| """ | |
| import json | |
| import shutil | |
| import subprocess | |
| import sys | |
| import tempfile | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parent | |
| TASKS_DIR = ROOT / "tasks" | |
| OUT = ROOT / "TerminalBench-DockerLess.jsonl" | |
| REPORTS = ROOT / "reports" | |
| sys.path.insert(0, str(ROOT)) | |
| import run_harness # noqa: E402 | |
| AUTHOR = {"name": "WorkBuddy Benchmarks", "email": "benchmarks@example.invalid"} | |
| TASKS = [ | |
| { | |
| "dir": "access-log-report", | |
| "task_id": "tbdl-access-log-report", | |
| "difficulty": "medium", | |
| "category": "data-processing", | |
| "tags": ["log-parsing", "text-processing", "json", "python"], | |
| "description": "Aggregate a damaged access log into a canonical JSON report, a malformed-line index and a gzip archive.", | |
| "expert_time_estimate_min": 25, | |
| "junior_time_estimate_min": 90, | |
| "max_agent_timeout_sec": 600.0, | |
| "max_test_timeout_sec": 120.0, | |
| "requires": ["bash", "python"], | |
| }, | |
| { | |
| "dir": "git-recovery", | |
| "task_id": "tbdl-git-recovery", | |
| "difficulty": "hard", | |
| "category": "software-engineering", | |
| "tags": ["git", "forensics", "history-recovery"], | |
| "description": "Restore a deleted module from history, resurrect an unreachable commit, tag a release and leave a clean tree.", | |
| "expert_time_estimate_min": 20, | |
| "junior_time_estimate_min": 75, | |
| "max_agent_timeout_sec": 600.0, | |
| "max_test_timeout_sec": 120.0, | |
| "requires": ["bash", "git"], | |
| }, | |
| { | |
| "dir": "csv-canon", | |
| "task_id": "tbdl-csv-canon", | |
| "difficulty": "hard", | |
| "category": "data-processing", | |
| "tags": ["csv", "cli", "spec-compliance", "exit-codes"], | |
| "description": "Write a byte-exact CSV-to-TSV canonicaliser with strict error codes and numeric normalisation.", | |
| "expert_time_estimate_min": 35, | |
| "junior_time_estimate_min": 120, | |
| "max_agent_timeout_sec": 900.0, | |
| "max_test_timeout_sec": 120.0, | |
| "requires": ["bash", "python"], | |
| }, | |
| { | |
| "dir": "build-repair", | |
| "task_id": "tbdl-build-repair", | |
| "difficulty": "hard", | |
| "category": "software-engineering", | |
| "tags": ["build", "shell", "debugging"], | |
| "description": "Repair a shell build with three independent faults so it produces the expected report and passes its own suite.", | |
| "expert_time_estimate_min": 25, | |
| "junior_time_estimate_min": 90, | |
| "max_agent_timeout_sec": 600.0, | |
| "max_test_timeout_sec": 120.0, | |
| "requires": ["bash", "python"], | |
| }, | |
| ] | |
| def read_text(path): | |
| """Decode without newline translation so CRLF/BOM fixtures survive.""" | |
| return path.read_bytes().decode("utf-8") | |
| def workspace_files(environment_dir): | |
| files = {} | |
| for path in sorted(environment_dir.rglob("*")): | |
| if not path.is_file(): | |
| continue | |
| rel = path.relative_to(environment_dir).as_posix() | |
| if rel in ("Dockerfile", "setup.sh"): | |
| continue | |
| files[rel] = read_text(path) | |
| return files | |
| def render_task_yaml(meta, instruction): | |
| lines = [ | |
| "# Terminal-Bench task definition", | |
| "instruction: |", | |
| ] | |
| for line in instruction.rstrip("\n").split("\n"): | |
| lines.append(" " + line if line else "") | |
| lines += [ | |
| "author_name: %s" % AUTHOR["name"], | |
| "author_email: %s" % AUTHOR["email"], | |
| "difficulty: %s" % meta["difficulty"], | |
| "category: %s" % meta["category"], | |
| "tags:", | |
| ] | |
| for tag in meta["tags"]: | |
| lines.append(" - %s" % tag) | |
| lines += [ | |
| "parser_name: pytest", | |
| "max_agent_timeout_sec: %.1f" % meta["max_agent_timeout_sec"], | |
| "max_test_timeout_sec: %.1f" % meta["max_test_timeout_sec"], | |
| "expert_time_estimate_min: %d" % meta["expert_time_estimate_min"], | |
| "junior_time_estimate_min: %d" % meta["junior_time_estimate_min"], | |
| ] | |
| return "\n".join(lines) + "\n" | |
| def render_task_toml(meta): | |
| keywords = ", ".join('"%s"' % tag for tag in meta["tags"]) | |
| return ( | |
| 'schema_version = "1.4"\n' | |
| 'source = "TerminalBench-DockerLess"\n' | |
| "\n" | |
| "[task]\n" | |
| 'name = "swedl/%s"\n' | |
| 'authors = [{ name = "%s", email = "%s" }]\n' | |
| 'description = "%s"\n' | |
| "keywords = [%s]\n" | |
| "\n" | |
| "[metadata]\n" | |
| 'difficulty = "%s"\n' | |
| 'category = "%s"\n' | |
| "tags = [%s]\n" | |
| "expert_time_estimate_min = %d\n" | |
| "junior_time_estimate_min = %d\n" | |
| "\n" | |
| "[verifier]\n" | |
| "timeout_sec = %.1f\n" | |
| "\n" | |
| "[agent]\n" | |
| "timeout_sec = %.1f\n" | |
| "\n" | |
| "[environment]\n" | |
| 'network_mode = "no-network"\n' | |
| 'os = "linux"\n' | |
| 'workdir = "/workspace"\n' | |
| % ( | |
| meta["dir"], | |
| AUTHOR["name"], | |
| AUTHOR["email"], | |
| meta["description"], | |
| keywords, | |
| meta["difficulty"], | |
| meta["category"], | |
| keywords, | |
| meta["expert_time_estimate_min"], | |
| meta["junior_time_estimate_min"], | |
| meta["max_test_timeout_sec"], | |
| meta["max_agent_timeout_sec"], | |
| ) | |
| ) | |
| def build_row(meta): | |
| task_dir = TASKS_DIR / meta["dir"] | |
| environment = task_dir / "environment" | |
| instruction = read_text(task_dir / "instruction.md") | |
| setup_path = environment / "setup.sh" | |
| setup = read_text(setup_path) if setup_path.is_file() else "" | |
| row = { | |
| "task_id": meta["task_id"], | |
| "instruction": instruction, | |
| "author_name": AUTHOR["name"], | |
| "author_email": AUTHOR["email"], | |
| "difficulty": meta["difficulty"], | |
| "category": meta["category"], | |
| "tags": list(meta["tags"]), | |
| "parser_name": "pytest", | |
| "max_agent_timeout_sec": meta["max_agent_timeout_sec"], | |
| "max_test_timeout_sec": meta["max_test_timeout_sec"], | |
| "expert_time_estimate_min": meta["expert_time_estimate_min"], | |
| "junior_time_estimate_min": meta["junior_time_estimate_min"], | |
| "task_yaml": render_task_yaml(meta, instruction), | |
| "task_toml": render_task_toml(meta), | |
| "dockerfile": read_text(environment / "Dockerfile"), | |
| "solution": read_text(task_dir / "solution" / "solve.sh"), | |
| "tests": { | |
| path.name: read_text(path) | |
| for path in sorted((task_dir / "tests").iterdir()) | |
| if path.is_file() | |
| }, | |
| "dockerless": { | |
| "setup": setup, | |
| "setup_timeout_sec": 120, | |
| "files": workspace_files(environment), | |
| "test_cmd": "", | |
| "workdir": "workspace", | |
| "requires": list(meta["requires"]), | |
| "baseline_failures": [], | |
| }, | |
| } | |
| return row | |
| def baseline(row): | |
| root = Path(tempfile.mkdtemp(prefix="tbdl-build-")) | |
| try: | |
| result, _ = run_harness.evaluate(row, "", root) | |
| finally: | |
| shutil.rmtree(root, ignore_errors=True) | |
| return result | |
| def main(): | |
| rows = [] | |
| print("%-24s %-7s %-8s %s" % ("task_id", "diff", "files", "baseline")) | |
| for meta in TASKS: | |
| row = build_row(meta) | |
| result = baseline(row) | |
| row["dockerless"]["baseline_failures"] = result["failing"] | |
| if result["resolved"]: | |
| raise RuntimeError( | |
| "%s passes with no agent at all -- the task is not solvable-proof" | |
| % row["task_id"] | |
| ) | |
| if not result["tests_total"]: | |
| raise RuntimeError("%s: verifier collected no tests" % row["task_id"]) | |
| rows.append(row) | |
| print( | |
| "%-24s %-7s %-8d %d/%d failing" | |
| % ( | |
| row["task_id"], | |
| row["difficulty"], | |
| len(row["dockerless"]["files"]), | |
| result["tests_total"] - result["tests_passed"], | |
| result["tests_total"], | |
| ) | |
| ) | |
| with open(OUT, "w", encoding="utf-8", newline="\n") as handle: | |
| for row in rows: | |
| handle.write(json.dumps(row, ensure_ascii=False) + "\n") | |
| print("\nwrote %s (%d rows, %.1f KiB)" % (OUT.name, len(rows), OUT.stat().st_size / 1024.0)) | |
| REPORTS.mkdir(exist_ok=True) | |
| failures = [] | |
| for mode, expected in (("--solution", len(rows)), ("--baseline", 0)): | |
| report_path = REPORTS / ("%s.json" % mode.lstrip("-")) | |
| proc = subprocess.run( | |
| [ | |
| sys.executable, | |
| str(ROOT / "run_harness.py"), | |
| "--dataset", | |
| str(OUT), | |
| mode, | |
| "--out", | |
| str(report_path), | |
| ], | |
| capture_output=True, | |
| text=True, | |
| encoding="utf-8", | |
| ) | |
| tail = (proc.stdout.strip().splitlines() or ["<no output>"])[-1] | |
| print("%-12s %s" % (mode, tail)) | |
| if proc.returncode != 0: | |
| failures.append("%s exited %d: %s" % (mode, proc.returncode, proc.stderr[-800:])) | |
| continue | |
| resolved = json.loads(report_path.read_text(encoding="utf-8"))["resolved"] | |
| if resolved != expected: | |
| failures.append("%s resolved %d, expected %d" % (mode, resolved, expected)) | |
| if failures: | |
| print("\nVERIFICATION FAILED") | |
| for message in failures: | |
| print(" - %s" % message) | |
| return 1 | |
| print("\nverification passed: oracle %d/%d, baseline 0/%d" % (len(rows), len(rows), len(rows))) | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |