"""Run from either installed checkout, with its isolated dev server already running.
Set CODEX_HOME to a scratch directory and PROOF_ENDPOINT / PROOF_HUB_KEY to a
custom endpoint and its model-call key. Credentials are never printed.
Run: python3 reproduce.py
Then pair the web client, open the returned thread, and inspect its notice.
Both sides: Codex CLI 0.169.0, 1280x800 CSS viewport, light theme.
"""
import base64, datetime, json, os, pathlib, subprocess, time
home = pathlib.Path(os.environ["CODEX_HOME"])
home.mkdir(parents=True, exist_ok=True)
def enc(value):
    return base64.urlsafe_b64encode(json.dumps(value).encode()).decode().rstrip("=")
claims = {"sub": "synthetic", "email": "demo@example.com", "exp": int(time.time())+86400,
          "iat": int(time.time()), "https://api.openai.com/auth": {
              "chatgpt_account_id": "synthetic", "chatgpt_plan_type": "plus"}}
token = enc({"alg":"none"}) + "." + enc(claims) + ".c3ludGhldGlj"
(home/"config.toml").write_text('model = "gpt-6.1-sol"\nopenai_base_url = '+json.dumps(os.environ["PROOF_ENDPOINT"])+"\n")
(home/"auth.json").write_text(json.dumps({"auth_mode":"chatgpt", "tokens":{
    "id_token":token, "access_token":os.environ["PROOF_HUB_KEY"],
    "refresh_token":"synthetic", "account_id":"synthetic"},
    "last_refresh":datetime.datetime.now(datetime.timezone.utc).isoformat()}))
cli = ["node", "apps/server/src/bin.ts"]
subprocess.run(cli+["project","add",".","--title","Custom endpoint demo","--base-dir",".t3"],check=True)
reply = subprocess.check_output(cli+["thread","start",".",
    "Reply with only the word hi. Do not run any tools.","--title","Custom endpoint capture",
    "--provider","codex","--model","gpt-6.1-sol","--base-dir",".t3","--json"],text=True)
print(reply)
thread = json.loads(reply)["threadId"]
# After opening the thread and starting browser recording, repeat the same prompt:
print("Follow-up command:", " ".join(cli+["thread","send",thread,
    repr("Reply with only the word hi. Do not run any tools."),"--base-dir",".t3","--json"]))
