Recreate-AAA / scripts /to_run.py
CharlieDreemur's picture
RecreateAAA 0.1.0 from Recreate-AAA/Recreate-AAA@7da1a3d
966b234 verified
Raw History Blame Contribute Delete
4.05 kB
"""Put a finished direct build where the rest of the bench builder looks for builds.
uv run python -m scripts.to_run OUT TASK [--name RUN] [--runs runs]
OUT is what scripts.direct_build wrote (OUT/build, OUT/scores.json) or a build folder of scripts.splat_build; TASK
an existing task (dataset/task/TASK). The build becomes runs/TASK/RUN: `candidate/` (the game, without the
reconstruction's working files), `public-inputs/` (the recording it was built from, as the build's own run has
it), `prompt.md` and `result.json` (an agent build that is complete, by "direct_build"). That is what the web
interface lists and plays, and what a restyle takes as its base run (`base_run: RUN`; a restyle also wants the
task's own contract and draft, which a direct build does not make). It is not an evaluated run: the formal export
asks for an isolated, calibrated evaluation that no builder here produces at present.
"""
from __future__ import annotations
import argparse
import json
import shutil
import sys
import time
from datetime import datetime, timezone
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
parser.add_argument("out", type=Path); parser.add_argument("task")
parser.add_argument("--name", default=""); parser.add_argument("--runs", type=Path, default=ROOT / "runs")
args = parser.parse_args(argv)
build = args.out / "build" if (args.out / "build" / "index.html").is_file() else args.out
if not (build / "index.html").is_file():
print(f"no build in {args.out}", file=sys.stderr); return 1
task = ROOT / "dataset" / "task" / args.task / "benchmark.json"
if not task.is_file():
print(f"no task {args.task} (dataset/task/{args.task}/benchmark.json)", file=sys.stderr); return 1
name = args.name or time.strftime("%Y%m%dT%H%M%SZ", time.gmtime()) + "-direct"
run = args.runs / args.task / name
if run.exists():
print(f"{run} is there already", file=sys.stderr); return 1
shutil.copytree(build, run / "candidate", ignore=shutil.ignore_patterns(".*", "recording.mp4", "input.jsonl", "frame_timestamps.jsonl", "gamepad.jsonl"))
given = Path((build / ".run").read_text().strip()) / "public-inputs" if (build / ".run").is_file() else None
if given and given.is_dir():
shutil.copytree(given, run / "public-inputs")
scores = json.loads((args.out / "scores.json").read_text()) if (args.out / "scores.json").is_file() else []
kept = max((row for row in scores if isinstance(row.get("scene"), (int, float))), key=lambda row: row["scene"], default={})
(run / "prompt.md").write_text("Built by scripts.direct_build: the place reconstructed from the recording, builders' rounds kept by a judge they did not see.\n")
now = datetime.now(timezone.utc).isoformat()
(run / "result.json").write_text(json.dumps({
"schema_version": 1, "run_id": name, "task_id": args.task, "task_name": json.loads(task.read_text()).get("name", args.task), "status": "agent_complete", "mode": "lite",
"calibration_id": "", "display_name": "direct build", "build": {"round": 1, "continuation": False, "conversation_id": name, "goal_mode": False, "harness_plugin": "direct_build"},
"agent": {"profile_id": "direct_build", "name": "direct_build", "harness_plugin": "direct_build"}, "candidate": None,
"scores": {"overall": float(kept.get("scene") or 0.0), "components": {key: kept[key] for key in ("scene", "control", "audio") if key in kept}},
"diagnostics": [], "artifacts": {"candidate": "candidate", "prompt": "prompt.md", "public_inputs": "public-inputs"},
"timestamps": {"started_at": now, "agent_finished_at": now, "finished_at": now}}, indent=1) + "\n")
print(f"{run}: candidate ({sum(1 for _ in (run / 'candidate').rglob('*'))} files), {'public-inputs, ' if (run / 'public-inputs').is_dir() else ''}result.json")
return 0
if __name__ == "__main__":
sys.exit(main())