"""Deterministic fixes of visual answers before rendering (no model call), measured on recorded runs. importmap the page loads three.js as ES modules (imports from 'three', 'three/addons/...' or from the unpkg URL, whose addons import the bare name 'three') but has no import map: insert the import map of the task at the start of
. usage: vis_autofix.py --src results/vis_rep/vis.jsonl --out results/vis_rep_fix/vis.jsonl Records whose answer is changed get "autofix": [...]; the rest are copied unchanged (exactly paired). """ import argparse import json import os import re import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from render import extract # noqa: E402 IMPORT_MAP = ('') USES_THREE_MODULE = re.compile(r"""from\s+['"](three|three/addons/[^'"]+|https://unpkg\.com/three@[^'"]+)['"]""") def fix_importmap(src): if 'type="importmap"' in src or "type='importmap'" in src or not USES_THREE_MODULE.search(src): return src m = re.search(r"]*>", src, re.I) if m: return src[:m.end()] + "\n" + IMPORT_MAP + src[m.end():] m = re.search(r"