#!/usr/bin/env python3
"""Draw the randomized 70-task pack for the image-resize 4-arm experiment.

Sampling frame: evaluation_examples/test_nogdrive.json (361 tasks) —
test_all.json minus the 8 Google-Drive-dependent multi_apps tasks, which
fail for account/infra reasons. No other exclusions; infeasible-style tasks
stay in (they are part of the benchmark).

Procedure: flatten to (domain, task_id) pairs, sort lexicographically so the
draw is independent of JSON key order, then sample 70 without replacement
with random.Random(SEED). Seed was fixed before any task outcome was known.

Rerunning this script must reproduce task-pack-70-meta.json exactly.
"""
import json
import random
from pathlib import Path

SEED = 20260704  # pre-declared: draw date, chosen before sampling
N = 70

ROOT = Path("/srv/controller-data")
FRAME = ROOT / "repos/OSWorld-focuschain/evaluation_examples/test_nogdrive.json"
OUT_DIR = Path(__file__).resolve().parent

universe = json.loads(FRAME.read_text())
pairs = sorted((dom, tid) for dom, tids in universe.items() for tid in tids)
assert len(pairs) == 361, f"frame changed: {len(pairs)} tasks"

picked = random.Random(SEED).sample(pairs, N)

meta = {}
for dom, tid in sorted(picked):
    meta.setdefault(dom, []).append(tid)

out = OUT_DIR / "task-pack-70-meta.json"
out.write_text(json.dumps(meta, indent=1) + "\n")

counts = {d: len(t) for d, t in meta.items()}
print(f"wrote {out} — {sum(counts.values())} tasks")
print(json.dumps(counts, indent=1))
