#!/usr/bin/env python3
"""Run from an installed checkout with a fresh T3 dev server (T3CODE_DEV_SEED=0).
Enable OpenCode and agent browser access in this isolated server first.
Usage: python3 driver.py /path/to/synthetic/git/project /path/to/new/output-dir
"""
import json, pathlib, subprocess, sys
project, output = map(pathlib.Path, sys.argv[1:])
output.mkdir(parents=True, exist_ok=False)
prompt = 'Call preview_open with no URL, then call preview_evaluate on that tab with the expression throw new Error("a".repeat(492) + "😀"), then quote the returned error verbatim.'
def cli(*args):
    return subprocess.check_output(['node', 'apps/server/src/bin.ts', *args, '--base-dir', '.t3'], text=True)
cli('project', 'add', str(project), '--title', 'Preview error boundary')
started = json.loads(cli('thread', 'start', str(project), prompt, '--provider', 'opencode', '--model', 'anthropic/claude-haiku-5-5', '--title', 'Preview error boundary', '--json'))
(output / 'thread.json').write_text(json.dumps(started, indent=2))
print(started['threadId'])
print('Open this thread in the web client. After completion, start a browser recording, then invoke the repeat command below:')
print('node apps/server/src/bin.ts thread send ' + started['threadId'] + ' --base-dir .t3 --json <prompt>')
print(prompt)
