File size: 10,366 Bytes
b199558 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | """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())
|