import os, pathlib, subprocess, json, uuid, datetime, re
root=pathlib.Path(os.environ['EVIDENCE_FIXTURE'])
repo=root/'repo';repo.mkdir(parents=True,exist_ok=True)
def git(*args):subprocess.run(['git','-C',str(repo),*args],check=True,stdout=subprocess.DEVNULL)
if not (repo/'.git').exists():
 git('init','-b','main');(repo/'checkout-marker.txt').write_text('ROOT CHECKOUT\n');git('add','.');git('-c','user.name=Scenario','-c','user.email=scenario@example.invalid','commit','-m','Initial fixture')
 for name in ['alpha','beta','gamma']:
  git('worktree','add','-b',name,str(repo/'.claude/worktrees'/name))
  (repo/'.claude/worktrees'/name/'checkout-marker.txt').write_text(name.upper()+' WORKTREE\n')
for index,name in enumerate(['root','alpha','beta','gamma'],1):
 cwd=repo if name=='root' else repo/'.claude/worktrees'/name
 digit=str(index); sid=f'{digit*8}-{digit*4}-4{digit*3}-8{digit*3}-{digit*12}'; user=str(uuid.uuid4()); assistant=str(uuid.uuid4())
 timestamp=datetime.datetime.now(datetime.timezone.utc).isoformat()
 common={'sessionId':sid,'cwd':str(cwd),'version':'2.1.39','isSidechain':False,'userType':'external','gitBranch':'main' if name=='root' else name}
 rows=[{**common,'type':'user','uuid':user,'parentUuid':None,'timestamp':timestamp,'message':{'role':'user','content':f'{name}: inspect the checkout'}},{**common,'type':'assistant','uuid':assistant,'parentUuid':user,'timestamp':timestamp,'message':{'id':'msg_'+str(index),'type':'message','role':'assistant','model':'claude-haiku-4-5','content':[{'type':'text','text':f'{name.upper()} session saved in its original checkout.'}],'stop_reason':'end_turn','stop_sequence':None,'usage':{'input_tokens':10,'output_tokens':10}}},{'type':'custom-title','customTitle':f'{name} session','sessionId':sid}]
 folder=root/'claude/projects'/re.sub(r'[^a-zA-Z0-9]', '-', str(cwd));folder.mkdir(parents=True,exist_ok=True)
 (folder/(sid+'.jsonl')).write_text('\n'.join(map(json.dumps,rows))+'\n')
for name in ['codex','pi']:(root/name).mkdir(exist_ok=True)
print('Seeded one root session and three linked-worktree sessions.')
