import subprocess, pathlib, textwrap, sys
from PIL import Image, ImageDraw, ImageFont
out=pathlib.Path(sys.argv[3])
font=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',19)
for side,checkout in [('before',sys.argv[1]),('after',sys.argv[2])]:
    root=pathlib.Path(checkout)
    sha=subprocess.check_output(['git','rev-parse','HEAD'],cwd=root,text=True).strip()
    result=subprocess.run(['node','apps/server/src/bin.ts','thread','start','--help'],cwd=root,text=True,capture_output=True)
    if result.returncode: raise RuntimeError(result.stderr)
    guide=(root/'docs/user/outside-agents.md').read_text()
    paragraph=guide[guide.index('To choose the model,'):guide.index('\n\n`--wait`',guide.index('To choose the model,'))]
    option=next(line.strip() for line in result.stdout.splitlines() if line.strip().startswith('--option'))
    full=f'Commit: {sha}\nEnvironment: Linux; Node source CLI; no server or database needed for help.\n\n$ t3 thread start --help\n{result.stdout}\n$ Read docs/user/outside-agents.md: model selection\n{paragraph}\n'
    (out/f'{side}.txt').write_text(full)
    content=f'{side.upper()}: CLI help and user guide\nCommit: {sha[:12]}\nLinux | Node source CLI | no server/database\n\n$ t3 thread start --help\n[--option excerpt; full output in transcript]\n{option}\n\n$ Read user guide: model selection\n{paragraph}'
    lines=[]
    for line in content.splitlines(): lines.extend(textwrap.wrap(line,100,replace_whitespace=False) or [''])
    img=Image.new('RGB',(1240,80+len(lines)*29),'#101820'); draw=ImageDraw.Draw(img)
    for i,line in enumerate(lines): draw.text((30,30+i*29),line,font=font,fill='#e6edf3')
    img.save(out/f'{side}.png')
print('Captured real CLI help and guide for both commits.')
