"""Real-server reproduction. Use a fresh T3 home and empty Codex home per commit.
Start the app with T3CODE_DEV_SEED=0; configure providerInstances.codex as
{"driver":"codex","config":{"homePath":"<codex-home>"}} before startup.
Open Settings > Providers and record the Codex card while running this driver.
No model request is sent; the API key is synthetic.
"""
import argparse,json,os,subprocess,time
from pathlib import Path
p=argparse.ArgumentParser()
p.add_argument('--worktree',type=Path,required=True)
p.add_argument('--codex-home',type=Path,required=True)
p.add_argument('--output',type=Path,required=True)
a=p.parse_args()
out=a.output/time.strftime('%Y%m%d-%H%M%S');out.mkdir(parents=True)
with (out/'transcript.jsonl').open('w') as log:
 def emit(d):
  line=json.dumps(d);print(line,flush=True);log.write(line+'\n');log.flush()
 def snapshot(label):
  d=json.loads((a.worktree/'.t3/caches/codex.json').read_text())
  emit({'step':label,**{k:d.get(k) for k in ['status','auth','message','checkedAt']}})
 def edit(values):
  f=a.worktree/'.t3/userdata/settings.json';d=json.loads(f.read_text());d.update(values);f.write_text(json.dumps(d))
 snapshot('Initial empty Codex home')
 env={**os.environ,'CODEX_HOME':str(a.codex_home)}
 r=subprocess.run(['codex','login','--with-api-key'],input='sk-synthetic-auth-probe-evidence\n',text=True,capture_output=True,env=env)
 emit({'step':'Synthetic API-key sign-in','exit':r.returncode})
 r=subprocess.run(['codex','login','status'],capture_output=True,text=True,env=env)
 emit({'step':'CLI login status','exit':r.returncode,'apiKeyConfigured':'API key configured' in r.stdout+r.stderr})
 edit({'promptSuggestionsEnabled':True});emit({'step':'Applied unrelated promptSuggestionsEnabled=true','waitSeconds':20});time.sleep(20);snapshot('After unrelated settings')
 edit({'backgroundActivity':{'profile':'custom','overrides':{'providerHealthRefreshInterval':600000}}});emit({'step':'Applied custom health interval 600000','waitSeconds':20});time.sleep(20);snapshot('After health interval settings')
