#!/usr/bin/env python3 """Package recorded agent episodes into the Space's replay-player format. Input: run directories produced by an arena runner (uitars-webtask-eval's run_arena.py or this repo's harness) containing frames/, transcript.txt, and result.json. Frames are assumed to be saved 8x per step (video padding); one frame per step is kept, downscaled to JPEG. python3 scripts/build_replays.py --agent "UI-TARS-1.5-7B (4-bit)" RUN_DIR... Output: server/static/replays//step_NNN.jpg + replay.json, and a top-level manifest.json the landing/replay/play pages read. """ from __future__ import annotations import argparse import json import re import sys from pathlib import Path from PIL import Image OUT_ROOT = Path(__file__).resolve().parent.parent / "server" / "static" / "replays" FRAME_DUP = 8 # frames saved per step by the runners JPEG_WIDTH = 880 JPEG_QUALITY = 68 _STEP = re.compile(r"^\[step (\d+)\] (\w+) point=(.*?) end=.*?content=(.*)$") DIAGNOSIS = { "checkout-form": "Clean run: precise field clicks, correct typing, " "three wizard steps, submit.", "email-triage": "State-tracking failure: archives worked, but the model never " "perceived rows disappearing — it re-clicked fixed coordinates " "while the list reflowed underneath, archiving 7 extra emails " "while blaming 'an unresponsive system'.", "settings-panel": "Environment finding: headless chromium renders native " "