#!/usr/bin/env python3
"""Create the SVG reproduction through T3 Code's public CLI on a fresh server.
Usage: python3 seed-svg-proof.py CHECKOUT PORT T3_HOME OUTPUT_DIRECTORY
"""
import json, os, pathlib, subprocess, sys
checkout, port, home, output = sys.argv[1:]
out = pathlib.Path(output)
out.mkdir(parents=True, exist_ok=True)
project = out / 'svg-sizing'
project.mkdir()
for name, attrs, w, h, color in [
    ('icon', 'width="48"', 24, 24, '#ff0000'),
    ('banner', 'height="100"', 200, 50, '#0000ff'),
    ('control', 'width="48" height="48"', 24, 24, '#00ff00'),
]:
    (project / (name + '.svg')).write_text(f'<svg xmlns="http://www.w3.org/2000/svg" {attrs} viewBox="0 0 {w} {h}"><rect width="{w}" height="{h}" fill="{color}"/></svg>\n')
subprocess.run(['git', 'init', '-q', str(project)], check=True)
subprocess.run(['git', '-C', str(project), 'add', '.'], check=True)
subprocess.run(['git', '-C', str(project), '-c', 'user.name=SVG proof', '-c', 'user.email=proof@example.invalid', 'commit', '-qm', 'SVG fixtures'], check=True)
env = {**os.environ, 'T3CODE_PORT': port, 'T3CODE_DEV_SEED': '0'}
def cli(*args):
    result = subprocess.run(['node', 'apps/server/src/bin.ts', *args, '--base-dir', home], cwd=checkout, env=env, text=True, capture_output=True)
    if result.returncode: raise RuntimeError(result.stderr + result.stdout)
    return result.stdout
print(cli('project', 'add', str(project), '--title', 'SVG sizing'))
prompt = 'Reply with exactly these three standalone Markdown images, with blank lines between them. Do not read files, use tools, or add any other text:\n\n![icon](./icon.svg)\n\n![banner](./banner.svg)\n\n![control](./control.svg)'
reply = cli('thread', 'start', str(project), prompt, '--title', 'SVG dimensions', '--provider', 'opencode', '--model', 'openai/gpt-6-luna', '--wait', '--json')
(out / 'thread.json').write_text(reply)
print(reply)
