import sys, pathlib, subprocess, json
root, home = map(pathlib.Path, sys.argv[1:3])
workspace = home.parent / 'image-grant-demo'
workspace.mkdir(exist_ok=True)
(workspace/'README.md').write_text('Synthetic image permission proof\n')
subprocess.run(['convert','-size','640x260','xc:#123741','-fill','#59e3b5','-draw','roundrectangle 25,25 615,235 20,20','-fill','#123741','-font','DejaVu-Sans-Bold','-pointsize','32','-gravity','center','-annotate','0','HOST IMAGE LOADED',str(workspace/'proof.png')],check=True)
subprocess.run(['git','init','-q','--initial-branch=main',str(workspace)],check=True)
subprocess.run(['git','-C',str(workspace),'add','.'],check=True)
subprocess.run(['git','-C',str(workspace),'-c','user.name=Proof','-c','user.email=proof@example.invalid','commit','-qm','Synthetic image fixture'],check=True)
fixture=root/'apps/server/src/orchestration-v2/testkit/fixtures/multi_turn/registry_transcript.ndjson'
rows=[json.loads(x) for x in fixture.read_text().splitlines() if x.strip()]
for row in rows:
    frame=row.get('frame',{})
    params=frame.get('params',{})
    update=params.get('update',{})
    if update.get('sessionUpdate')=='agent_message_chunk':
        update['content']['text']='This image is stored on the host filesystem.\n\n![Host image permission proof](<workspace>/proof.png)\n\nThe broader saved Connect session should load this image automatically.'
fixture.write_text(''.join(json.dumps(x)+'\n' for x in rows))
print(workspace)
