"""Create synthetic Claude history and a real linked Git worktree.
Usage: python3 seed-import.py /path/to/new-fixture-directory
Set CLAUDE_CONFIG_DIR to that directory's claude child when running the scenario.
In scripts/scenarios/start-app.ts, enable claudeAgent for history discovery:
replace `enabled: false,` with `enabled: driver === "claudeAgent",`.
For capture runs, pass a synthetic ANTHROPIC_API_KEY and a loopback
ANTHROPIC_BASE_URL (port 9), with both in T3_SCENARIO_INHERIT_ENV;
this prevents an authentication diagnostic exposing the local T3 home.
No real provider turn is run by this scenario.
"""
from pathlib import Path
import subprocess, json, uuid, datetime, sys
base = Path(sys.argv[1]).resolve()
repo = base / 'sample-project'
repo.mkdir(parents=True)
def git(*args):
    subprocess.run(['git', '-C', str(repo), *args], check=True, capture_output=True)
git('init', '-b', 'main')
(repo / 'README.md').write_text('Synthetic import evidence\n')
git('add', '.')
git('-c', 'user.name=Scenario', '-c', 'user.email=scenario@example.invalid', 'commit', '-m', 'Initial')
worktree = repo / '.claude/worktrees/feature'
git('worktree', 'add', '-b', 'feature', str(worktree))
for cwd, title in [(repo, 'Root conversation'), (worktree, 'Worktree conversation')]:
    directory = base / 'claude/projects' / str(cwd).replace('/', '-')
    directory.mkdir(parents=True)
    sid = str(uuid.uuid4())
    now = datetime.datetime.now(datetime.timezone.utc).isoformat()
    rows = [
        dict(type='user', cwd=str(cwd), sessionId=sid, timestamp=now, uuid=str(uuid.uuid4()), message={'role': 'user', 'content': title}),
        dict(type='assistant', cwd=str(cwd), sessionId=sid, timestamp=now, uuid=str(uuid.uuid4()), message={'role': 'assistant', 'content': [{'type': 'text', 'text': 'Synthetic conversation ready for import.'}], 'model': 'claude-sonnet-4-5'}),
        dict(type='custom-title', customTitle=title, sessionId=sid),
    ]
    (directory / (sid + '.jsonl')).write_text('\n'.join(map(json.dumps, rows)) + '\n')
