"""Portable form of the scratch fixture setup used for this manual reproduction.
Run beside hook.py, trust.py, and show-hooks.py. Never upload codex-home.
"""
import pathlib,json,shutil,subprocess,os
p=pathlib.Path(__file__).resolve().parent
h=p/'codex-home'; h.mkdir(exist_ok=True)
source=pathlib.Path(os.environ.get('CODEX_HOME', str(pathlib.Path.home()/'.codex')))
(h/'config.toml').write_text((source/'config.toml').read_text().split('[otel]')[0])
shutil.copyfile(source/'auth.json', h/'auth.json')
(h/'hooks.json').write_text(json.dumps({'hooks':{event:[{'hooks':[{'type':'command','command':f'python3 {p}/hook.py'}]}] for event in ['SessionStart','Stop']}}))
x=json.loads(subprocess.check_output(['python3', str(p/'trust.py')]))
with (h/'config.toml').open('a') as f:
 for hook in x['result']['data'][0]['hooks']:
  f.write('\n[hooks.state.'+json.dumps(hook['key'])+']\ntrusted_hash = '+json.dumps(hook['currentHash'])+'\n')
repo=p/'hook-demo'; repo.mkdir(exist_ok=True)
subprocess.run(['git','init','-q','-b','main',str(repo)],check=True)
subprocess.run(['git','-C',str(repo),'-c','user.name=Proof','-c','user.email=proof@example.invalid','commit','--allow-empty','-qm','Initial commit'],check=True)
print('Fixture ready. Configure the isolated T3 Codex homePath to codex-home; use GPT-6-Luna.')
