from pathlib import Path
import json, os, subprocess, sys

# Usage: python3 seed-demo.py <checkout> <new-home> <new-workspace> <wrapper>
# Run the same script on each commit. MODEL_SLUG stays private in the environment.
checkout, home, workspace, wrapper = map(Path, sys.argv[1:])
model = os.environ["MODEL_SLUG"]
(home / "userdata").mkdir(parents=True, exist_ok=False)
settings = {
    "defaultModelSelection": {"instanceId": "claudeAgent", "model": model},
    "threadTitleInstructions": "Always use exactly Startup check as the title.",
    "providerInstances": {
        "claudeAgent": {"driver": "claudeAgent", "enabled": True, "config": {
            "binaryPath": str(wrapper.resolve()),
            "customModels": [{"slug": model, "name": "Startup check"}]}},
        "codex": {"driver": "codex", "enabled": False},
    },
}
(home / "userdata/settings.json").write_text(json.dumps(settings))
workspace.mkdir(parents=True, exist_ok=False)
(workspace / "README.md").write_text("Synthetic startup demonstration.\n")
for args in [["init", "-q", "--initial-branch=main"], ["add", "."],
             ["-c", "user.name=Demo", "-c", "user.email=demo@example.invalid", "commit", "-qm", "Initial commit"]]:
    subprocess.run(["git", *args], cwd=workspace, check=True)
# Start the dev server on this home, then add the project through the real CLI:
print("node apps/server/src/bin.ts project add", workspace, "--title 'Startup demo' --base-dir", home)
