#!/usr/bin/env python3
"""Synthetic seed and real-Claude driver used for the before/after captures.

For each checkout (dependencies installed), use a fresh home:
  python reproduce.py prepare CHECKOUT HOME SAMPLE
  T3CODE_DEV_SEED=0 T3CODE_ENVIRONMENT_LABEL=Evidence vp run dev --home-dir HOME
After the server says Listening, in another terminal:
  python reproduce.py run CHECKOUT HOME SAMPLE

Open the startup pairing URL in the preview browser, then open the returned
thread by its environment/thread URL. Captures: Linux web client, light theme,
1440x1000 CSS pixels (device scale 2). Expand "Worked for ...", scroll the
.messages-timeline-scroll element to 245. On base, also expand the activity
bundle and its Thought row to inspect the hidden progress note.

Uses real Claude Fable 5.2, high effort, --thinking-display omitted. No replay,
mock provider, fixture database, or modified application source is involved.
"""
import json
import pathlib
import subprocess
import sys

mode, checkout_arg, home_arg, sample_arg = sys.argv[1:]
checkout, home, sample = map(lambda s: pathlib.Path(s).resolve(),
                             [checkout_arg, home_arg, sample_arg])
prompt = ("Investigate this directory carefully: list files, read each one, count "
          "words in each with wc, and grep for 'hello'. Keep me posted with brief "
          "progress notes between steps.")
if mode == 'prepare':
    userdata = home / 'userdata'
    userdata.mkdir(parents=True, exist_ok=True)
    (userdata / 'settings.json').write_text(json.dumps({
        'providerInstances': {'claudeAgent': {
            'driver': 'claudeAgent', 'enabled': True,
            'config': {'launchArgs': '--thinking-display omitted'}}},
        'defaultModelSelection': {'instanceId': 'claudeAgent',
            'model': 'claude-fable-5-2',
            'options': [{'id': 'effort', 'value': 'high'}]}}))
    sample.mkdir(parents=True, exist_ok=True)
    (sample / 'hello.txt').write_text('hello world\nA tiny file for word counting.\n')
    (sample / 'notes.txt').write_text('Progress updates should remain visible.\nhello again\n')
    (sample / 'show.py').write_text('import json, sys\nfor line in open(sys.argv[1]):\n    print(json.loads(line))\n')
    for n in range(6):
        (sample / f'probe-{n+1}.jsonl').write_text(''.join(json.dumps({
            'type': 'assistant', 'message': {'role': 'assistant', 'content': [
                {'type': 'thinking', 'thinking': 'Inspect files carefully and report progress.'},
                {'type': 'text', 'text': 'hello, inspecting the directory.'}]},
            'probe': n, 'line': i}) + '\n' for i in range(650)))
    subprocess.run(['git', 'init', '--quiet', '--initial-branch=main', str(sample)], check=True)
elif mode == 'run':
    cli = ['node', 'apps/server/src/bin.ts']
    subprocess.run(cli + ['project', 'add', str(sample), '--title',
        'Thinking progress proof', '--base-dir', str(home)], cwd=checkout, check=True)
    subprocess.run(cli + ['thread', 'start', str(sample), prompt, '--title',
        'Directory investigation', '--provider', 'claudeAgent', '--model',
        'claude-fable-5-2', '--option', 'effort=high', '--base-dir', str(home),
        '--json', '--wait'], cwd=checkout, check=True)
else:
    raise SystemExit('mode must be prepare or run')
