#!/usr/bin/env python3
"""Synthetic seed and live Hermes reproduction. Run once for each stopped checkout.
Requires an authenticated Hermes home, and ACP_MODEL set to its ACP model choice id.
No credentials or runtime model identifiers are embedded in this script.
After starting each app with T3CODE_DEV_SEED=0, open the synthetic project, create
one Hermes thread, and send PROMPT. Use a 1280x800 viewport and the light theme.
Hide the model selector for public captures and close both side panels.
"""
import argparse
import json
import os
from pathlib import Path
import subprocess

PROMPT = 'Call html_preview with <!doctype html><html><body><p>ACP render test</p></body></html>, then call html_render with the same HTML and title ACP render test. If html_preview times out or fails, still call html_render exactly once. Do not use terminal or write files. After html_render succeeds, reply only Done.'
p = argparse.ArgumentParser()
p.add_argument('checkout', type=Path)
p.add_argument('project', type=Path)
p.add_argument('hermes_home', type=Path)
p.add_argument('--seed', action='store_true')
a = p.parse_args()
home = a.checkout.resolve() / '.t3'
model = os.environ['ACP_MODEL']
def cli(*args):
    return subprocess.run(['node', 'apps/server/src/bin.ts', *args, '--base-dir', str(home)], cwd=a.checkout, check=True)
if a.seed:
    providers = {kind: {'driver': kind, 'enabled': False} for kind in ['codex', 'claudeAgent', 'cursor', 'grok', 'muse', 'pi', 'opencode', 'antigravity']}
    providers['hermes'] = {'driver': 'acpRegistry', 'displayName': 'Hermes', 'enabled': True, 'config': {'source': 'local', 'commandPath': 'hermes-acp', 'commandArgs': []}, 'environment': [{'name': 'HERMES_HOME', 'value': str(a.hermes_home.resolve()), 'sensitive': False}]}
    settings = home / 'userdata/settings.json'
    settings.parent.mkdir(parents=True, exist_ok=True)
    settings.write_text(json.dumps({'providerInstances': providers, 'defaultModelSelection': {'instanceId': 'hermes', 'model': model}}))
    a.project.mkdir(parents=True, exist_ok=True)
    subprocess.run(['git', 'init', '-q', str(a.project)], check=True)
    subprocess.run(['git', '-C', str(a.project), '-c', 'user.name=Evidence', '-c', 'user.email=evidence@example.invalid', 'commit', '--allow-empty', '-qm', 'Initial'], check=True)
    print('Start this checkout: T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD=0 T3CODE_DEV_SEED=0 vp run dev -- --host 127.0.0.1')
else:
    cli('project', 'add', str(a.project.resolve()), '--title', 'ACP render test')
    print('For the recorded UI path: open this project, create a Hermes thread, and send:\n' + PROMPT)
    print('Equivalent CLI path:')
    cli('thread', 'start', str(a.project.resolve()), PROMPT, '--title', 'ACP render test', '--provider', 'hermes', '--model', model, '--wait', '--json')
