#!/usr/bin/env python3
"""Run against a checkout already serving a fresh T3 home with T3CODE_DEV_SEED=0.
Usage: python3 reproduce.py CHECKOUT SAMPLE_DIRECTORY
Then pair the web client, open Image read preview, close Thread details,
and expand Worked for ... at a 1280x800 viewport in dark appearance.
"""
import json
import pathlib
import subprocess
import sys

checkout = pathlib.Path(sys.argv[1]).resolve()
sample = pathlib.Path(sys.argv[2]).resolve()
sample.mkdir(parents=True, exist_ok=True)
subprocess.run(['git', 'init', '-q', str(sample)], check=True)
subprocess.run(['convert', '-size', '200x120', 'xc:lightblue', '-fill', 'red',
                '-draw', 'circle 100,60 135,60', str(sample / 'shot.png')], check=True)
settings = checkout / '.t3/userdata/settings.json'
data = json.loads(settings.read_text())
data.setdefault('providerInstances', {})['pi'] = {
    'driver': 'pi', 'enabled': True, 'config': {'enabled': True}}
settings.write_text(json.dumps(data))
cli = ['node', 'apps/server/src/bin.ts']
subprocess.run(cli + ['project', 'add', '--base-dir', '.t3', '--title',
                     'Image preview', str(sample)], cwd=checkout, check=True)
subprocess.run(cli + ['thread', 'start', '--base-dir', '.t3', '--provider', 'pi',
                     '--model', 'xai/grok-4.7', '--title', 'Image read preview',
                     '--wait', str(sample),
                     'Use your read tool on ./shot.png and tell me in one sentence what it shows.'],
               cwd=checkout, check=True)
