import json,pathlib,sys
from PIL import Image, ImageDraw, ImageFont
root=pathlib.Path(__file__).parent
paths=[pathlib.Path(p) for p in sys.argv[1:]]
font=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',20)
heading=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf',26)
for path in paths:
 d=json.loads(path.read_text()); side='before' if d['commit'].startswith('7f81') else 'after'
 def select(t): return {k:t[k] for k in ['title','status','createdBy','creationSource','parentThreadId','relationshipToParent','delegatedFrom'] if k in t}
 no=d['listWithoutSubagents']['response']; yes=d['listWithSubagents']['response']; read=d['read']['response']['thread']
 lines=['REAL SERVER / MCP RESPONSE CAPTURE — '+side.upper(),d['commit'],'Linux | two isolated servers A and B | fresh databases','OpenCode: opencode/deepseek-v4.1-flash-free','A delegated to B; task completed. Calls enter A and forward to B.','Agent tool outputs: list(false) and read; direct MCP: list(true).\nSelected JSON fields below; complete responses attached.','',
 't3_thread_list {environmentId: B, allProjects: true,','                includeSubagents: false}',json.dumps({'threads':[select(t) for t in no['threads']],'total':no['total']},indent=2),'',
 't3_thread_list {environmentId: B, allProjects: true,','                includeSubagents: true}',json.dumps({'threads':[select(t) for t in yes['threads']],'total':yes['total']},indent=2),'',
 't3_thread_read {environmentId: B, threadId: delegated task}',json.dumps({'thread':select(read)},indent=2),'',
 'delegatedFrom field presence in returned metadata:',f'  list (includeSubagents:true): {"delegatedFrom" in yes["threads"][0]}',f'  read: {"delegatedFrom" in read}','',
 'Destination database, read-only: delegatedFrom is stored on BOTH commits.']
 text='\n'.join(lines); (root/(side+'.txt')).write_text(text+'\n')
 # Same capture geometry, type size and theme for both sides.
 image=Image.new('RGB',(1540,1850),'#10151e'); draw=ImageDraw.Draw(image)
 y=32
 for i,line in enumerate(text.splitlines()):
  draw.text((32,y),line,font=heading if i==0 else font,fill='#edf2f8' if i==0 else '#d6e0ec')
  y+=29
 if y>1820: raise RuntimeError(f'Capture clipped: {y}')
 image.save(root/(side+'.png'))
 print(side,'lines',len(text.splitlines()),'height',y)
