Download tools/make_controls.py from noodcon/TerminalBench-DockerLess: direct link, hf CLI and curl.
- Browser
- Download file 3.31 kB
-
https://huggingface.co/datasets/noodcon/TerminalBench-DockerLess/resolve/main/tools/make_controls.py
- Command line
-
hf download hf://datasets/noodcon/TerminalBench-DockerLess/tools/make_controls.py
-
curl -L -o make_controls.py https://huggingface.co/datasets/noodcon/TerminalBench-DockerLess/resolve/main/tools/make_controls.py
3.31 kB
| """Generate a negative control: a plausible but incomplete attempt per task. | |
| Every task must score 0.0. This is the check that the verifier is measuring the | |
| whole task rather than one easy assertion. | |
| The controls are produced by mutating the oracle: the interesting failure mode | |
| for an agent is not "did nothing" but "fixed the obvious half". | |
| Run with: python tools/make_controls.py | |
| """ | |
| import json | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parent.parent | |
| DATASET = ROOT / "TerminalBench-DockerLess.jsonl" | |
| OUTDIR = ROOT / "predictions" | |
| def mutate(text, old, new, label): | |
| if old not in text: | |
| raise SystemExit("control %s: anchor not found" % label) | |
| return text.replace(old, new) | |
| def build_controls(rows): | |
| by_id = {row["task_id"]: row for row in rows} | |
| controls = {} | |
| # 1. access-log: nearest-rank replaced by a 0-based index -> p95 is off by one | |
| # rank, everything else is right. | |
| solution = by_id["tbdl-access-log-report"]["solution"] | |
| controls["tbdl-access-log-report"] = mutate( | |
| solution, | |
| "p95 = durations[math.ceil(0.95 * count) - 1] if count else 0", | |
| "p95 = durations[int(round(0.95 * count)) - 1] if count else 0", | |
| "access-log", | |
| ) | |
| # 2. git-recovery: recovers the *wrong* historical revision and never | |
| # rescues the unreachable commit. | |
| solution = by_id["tbdl-git-recovery"]["solution"] | |
| solution = mutate(solution, "/ Add config loader$/", "/ Initial import$/", "git-recovery") | |
| solution = mutate( | |
| solution, 'git branch recovered "$wip_commit"', "true # gave up on the wip commit", "git-recovery-2" | |
| ) | |
| controls["tbdl-git-recovery"] = solution | |
| # 3. csv-canon: forgets the BOM and forgets to sort. | |
| solution = by_id["tbdl-csv-canon"]["solution"] | |
| solution = mutate(solution, 'encoding="utf-8-sig"', 'encoding="utf-8"', "csv-canon") | |
| solution = mutate( | |
| solution, | |
| 'rows.sort(key=lambda row: (row[0], row[1] if len(row) > 1 else ""))', | |
| "pass # rows arrive sorted, surely", | |
| "csv-canon-2", | |
| ) | |
| controls["tbdl-csv-canon"] = solution | |
| # 4. build-repair: fixes the shell bugs only, leaving both Python faults. | |
| controls["tbdl-build-repair"] = """#!/usr/bin/env bash | |
| set -euo pipefail | |
| cd "$TB_WORK" | |
| python - <<'PYEOF' | |
| from pathlib import Path | |
| path = Path("build.sh") | |
| text = path.read_text(encoding="utf-8") | |
| text = text.replace('mkdir -p "$OUTDIR"', 'mkdir -p "$OUT" build') | |
| path.write_text(text, encoding="utf-8", newline="\\n") | |
| PYEOF | |
| bash build.sh || true | |
| """ | |
| return controls | |
| def main(): | |
| OUTDIR.mkdir(exist_ok=True) | |
| rows = [json.loads(line) for line in open(DATASET, encoding="utf-8") if line.strip()] | |
| controls = build_controls(rows) | |
| target = OUTDIR / "partial.jsonl" | |
| with open(target, "w", encoding="utf-8", newline="\n") as handle: | |
| for row in rows: | |
| handle.write( | |
| json.dumps( | |
| { | |
| "task_id": row["task_id"], | |
| "agent_name": "control-partial", | |
| "agent_script": controls[row["task_id"]], | |
| } | |
| ) | |
| + "\n" | |
| ) | |
| print("wrote %s for %d tasks" % (target, len(rows))) | |
| if __name__ == "__main__": | |
| main() | |