"""Usage: python3 seed.py <scratch-directory>; then set CODEX_HOME to its codex child."""
import os
import datetime
import json
import pathlib
import subprocess
import sys

root = pathlib.Path(sys.argv[1]).resolve()
workspace = root / 'demo-project'
workspace.mkdir(parents=True, exist_ok=True)
subprocess.run(['git', 'init', '-q', '--initial-branch=master', str(workspace)], check=True)
(workspace / 'README.md').write_text('Demo project\n')
subprocess.run(['git', '-C', str(workspace), 'add', '.'], check=True)
subprocess.run(['git', '-C', str(workspace), '-c', 'user.name=Demo', '-c', 'user.email=demo@example.invalid', 'commit', '-qm', 'Initial commit'], check=True)
sessions = root / 'codex/sessions/2026/11/20'
sessions.mkdir(parents=True, exist_ok=True)
rows = [
    {'type': 'session_meta', 'payload': {'id': '93ff74ea-1e71-4e87-b61d-447c51a9d811', 'cwd': str(workspace), 'timestamp': '2026-11-20T10:00:00.000Z'}},
    {'type': 'event_msg', 'timestamp': '2026-11-20T10:00:00.000Z', 'payload': {'type': 'user_message', 'message': 'a' * 99 + '🚀 then deploy'}},
    {'type': 'response_item', 'timestamp': '2026-11-20T10:00:01.000Z', 'payload': {'type': 'message', 'role': 'assistant', 'content': [{'type': 'output_text', 'text': 'Ready to deploy.'}]}},
]
(sessions / 'rollout-2026-11-20-demo.jsonl').write_text(''.join(json.dumps(row) + '\n' for row in rows))

fixed_mtime = datetime.datetime(2026, 11, 19, tzinfo=datetime.timezone.utc).timestamp()
os.utime(sessions / "rollout-2026-11-20-demo.jsonl", (fixed_mtime, fixed_mtime))
