"""Run from a current-main checkout before scenarios:prove. Uses synthetic state only."""
import json
import tempfile
from pathlib import Path

home = tempfile.mkdtemp(prefix="no-project-proof-")
p = Path("scripts/e2e.config.ts")
s = p.read_text().replace('path.resolve(scripts, "../.t3/scenarios")', json.dumps(home))
p.write_text(s)
p = Path("scripts/scenarios/start-app.ts")
s = p.read_text().replace('import { ScenarioError } from "./shell.ts";', 'import { run, ScenarioError } from "./shell.ts";')
s = s.replace('  // Editor discovery is cached', '  yield* fs.makeDirectory(path.join(home, "scratch"), { recursive: true });\n  yield* run("git", ["init", "-b", "main"], { cwd: path.join(home, "scratch") });\n  // Editor discovery is cached')
s = s.replace('model: "showcase"', 'model: "multi-turn"')
s = s.replace('      defaultModelSelection: REPLAY,', '      defaultModelSelection: REPLAY,\n      defaultThreadEnvMode: "worktree",')
p.write_text(s)
print("Prepared a fresh external scenario home with an unborn main scratch repository.")
