"""Seed a fresh running T3 dev server with the responsive HTML fixture.
Usage: python3 seed.py CHECKOUT SEED_DIRECTORY
Start the checkout first with T3CODE_DEV_SEED=0 and T3CODE_ENVIRONMENT_LABEL=Scenario.
Requires a configured real OpenCode provider and the supplied report.html.
"""
import json
from pathlib import Path
import subprocess
import sys

checkout, workspace = map(Path, sys.argv[1:])
workspace.mkdir(parents=True, exist_ok=True)
workspace.joinpath('report.html').write_text(Path(__file__).with_name('report.html').read_text())
settings_path = checkout / '.t3/userdata/settings.json'
settings = json.loads(settings_path.read_text())
settings.setdefault('providerInstances', {})['opencode'] = {'driver': 'opencode', 'enabled': True}
settings_path.write_text(json.dumps(settings, indent=2))
cli = ['node', 'apps/server/src/bin.ts']
subprocess.run(cli + ['project', 'add', str(workspace.resolve()), '--title', 'Responsive HTML', '--base-dir', '.t3'], cwd=checkout, check=True)
prompt = '''Read report.html. First call T3 html_preview with its exact full HTML string and width 1144 (this also installs the browser). Then call html_render with the same exact HTML string, title "Responsive height report", height 600. Do not modify the HTML. Reply exactly "done". Do not delegate or create files. If html_preview says installing, retry it. This is the visual fixture; preserve every CSS rule exactly.'''
subprocess.run(cli + ['thread', 'start', str(workspace.resolve()), '-', '--title', 'Wide HTML measurements', '--provider', 'opencode', '--model', 'openai/gpt-6-luna', '--wait', '--json', '--base-dir', '.t3'], cwd=checkout, input=prompt, text=True, check=True)
