#!/usr/bin/env python3
"""Consolidated reproduction commands used for each fresh real-app checkout.

Run the checkout's dev server first with T3CODE_DEV_SEED=0 vp run dev.
Usage: python3 reproduce.py CHECKOUT NEW_SCRATCH_DIRECTORY
No provider responses or application data are fabricated.
"""
import json
import pathlib
import subprocess
import sys

checkout = pathlib.Path(sys.argv[1]).resolve()
scratch = pathlib.Path(sys.argv[2]).resolve()
scratch.mkdir(parents=True, exist_ok=False)
project = scratch / 'proj'
project.mkdir()
subprocess.run(['git', 'init', str(project)], check=True)

def t3(*args):
    result = subprocess.run(
        ['node', 'apps/server/src/bin.ts', *args], cwd=checkout,
        text=True, capture_output=True, check=True,
    )
    return result.stdout.strip()

t3('project', 'add', '--base-dir', '.t3', '--title', 'Tab filename proof', str(project))
write = json.loads(t3(
    'thread', 'start', '--base-dir', '.t3', '--title', 'Tab filename Write and Edit',
    '--provider', 'claudeAgent', '--model', 'claude-haiku-5-5', '--wait', '--json',
    str(project),
    'Use your native Write tool exactly once to create the relative filename name<TAB>part.txt, where <TAB> means one real U+0009 tab character, with content hello followed by a newline. Do not use Bash or any other tool. Then stop.',
))
edit = json.loads(t3(
    'thread', 'send', '--base-dir', '.t3', '--wait', '--json', write['threadId'],
    'Use Read on that same tab-containing file, then use your native Edit tool once to change hello to hello world, keeping the trailing newline. Do not use Bash or Write. Then stop.',
))
print(json.dumps({'threadId': write['threadId'], 'writeStatus': write['status'],
                  'editStatus': edit['status'], 'filenames': [p.name for p in project.iterdir() if p.is_file()],
                  'content': (project / 'name\tpart.txt').read_text()}, indent=2))

# Browser steps used on both sides (1280x800, light, Chromium):
# Pair with the dev server, navigate directly to /<environment>/<encoded threadId>.
# Hide sidebar and thread details. Expand the Write turn's Worked for group,
# Changed 1 file, and proj/name<TAB>part.txt; click Open diff; maximize Diff.
# Inspect Tool call scope and changed lines. Hover/click Copy file path.
# Restore/close Diff, repeat for the second turn's Edit tool (not its Read tool).
# Capture only the maximized Diff so no host identity or working directory appears.
# Clipboard reads were denied by the browser. Observe actual writes without changing them:
# window.__copied = [];
# const original = navigator.clipboard.writeText.bind(navigator.clipboard);
# navigator.clipboard.writeText = async text => {
#   window.__copied.push(text); return original(text);
# };
# Inspect window.__copied after clicking the real Copy file path button.
