"""Run from either checkout after starting its fresh dev app and connecting Antigravity.

Setup in both apps: Antigravity 1.5.18, Gemini API key sign-in, any nonempty
key, server environment GOOGLE_GEMINI_BASE_URL pointing to the configured hub.
No existing database is copied. Start dev with T3CODE_DEV_SEED=0.

Run `python3 reproduce.py serve` once to serve the synthetic page.
Run `python3 reproduce.py turn` from each checkout to start the identical turn.
Open the returned thread in the paired web client (1280x800, light theme).
Expand Worked for..., the tool group, then Took a snapshot of the preview page.
Inspect that row for the inline screenshot and snapshot metadata.
Capture the row; hide sidebar/details, crop unrelated UI to avoid host labels.
"""
from http.server import BaseHTTPRequestHandler, HTTPServer
import subprocess,sys

PAGE = b'''<!doctype html><html><head><title>Snapshot recovery sample</title></head><body style="background:#fff4b8;color:#243047;font:24px sans-serif;padding:48px"><h1>Snapshot recovery sample</h1><p>A simple page for visual tool output verification.</p></body></html>'''
PROMPT = 'Use only the T3 Code browser tools. 1) Call preview_open with url http://127.0.0.1:18977/ . 2) Call preview_snapshot with includeImage: true exactly once. Then reply with one sentence describing the page background colour you saw.'

class Handler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('Content-Type','text/html')
        self.end_headers()
        self.wfile.write(PAGE)

if sys.argv[1] == 'serve':
    HTTPServer(('0.0.0.0',18977),Handler).serve_forever()
elif sys.argv[1] == 'turn':
    subprocess.run(['node','apps/server/src/bin.ts','thread','start','--base-dir','.t3','--provider','antigravity','--model','gemini-4-neon','--title','Snapshot output recovery','apps/server',PROMPT,'--json'],check=True)
