import json, pathlib, subprocess, sys
checkout, home, workspace, port = sys.argv[1:]
checkout = pathlib.Path(checkout)
workspace = pathlib.Path(workspace)
workspace.mkdir(parents=True, exist_ok=True)
(workspace/'README.md').write_text('Synthetic rendering sample.\n')
def git(*args): subprocess.run(['git','-C',str(workspace),*args],check=True,capture_output=True)
if not (workspace/'.git').exists():
 git('init','--quiet','--initial-branch=main')
 git('add','README.md')
 git('-c','user.name=Scenario','-c','user.email=scenario@example.invalid','commit','--quiet','-m','Synthetic sample')
lines = ['{'] + [f'  "entry_{i:03d}": "'+ ('synthetic_code_sample_'*15)+f'{i:03d}"'+(',' if i<540 else '') for i in range(541)] + ['}']
text = 'Tall code sample\n\n```json\n'+'\n'.join(lines)+'\n```\n\nSmall highlighted sample\n\n```typescript\nconst greeting: string = "Hello";\nconsole.log(greeting);\n```\n\nTall narrow sample\n\n```json\n'+json.dumps(list(range(543)),indent=2)+'\n```\n\nEnd of samples.'
frames = [
 {'type':'transcript_start','provider':'acpRegistry','protocol':'acp.ndjson-jsonrpc','version':'1','scenario':'tall_code'},
 {'type':'expect_outbound','frame':{'kind':'request','method':'session/prompt','params':'<any>'}},
 {'type':'emit_inbound','frame':{'kind':'notification','method':'session/update','params':{'sessionId':'dev-replay-session','update':{'sessionUpdate':'agent_message_chunk','content':{'type':'text','text':text}}}}},
 {'type':'emit_inbound','frame':{'kind':'response','method':'session/prompt','result':{'stopReason':'end_turn'}}}]
(checkout/'apps/server/scripts/dev-replay/showcase_transcript.ndjson').write_text('\n'.join(map(json.dumps,frames))+'\n')
import os
env = dict(os.environ,T3CODE_PORT=port)
def cli(*args):
 result = subprocess.run(['node','apps/server/src/bin.ts',*args,'--base-dir',home],cwd=checkout,env=env,check=True,capture_output=True,text=True)
 return result.stdout
cli('project','add',str(workspace),'--title','Code samples')
result = json.loads(cli('thread','start',str(workspace),'Show the synthetic code samples.','--title','Tall code rendering','--provider','devReplay','--model','showcase','--wait','--json'))
print(json.dumps({key:result[key] for key in ['threadId','status']}))
print(json.dumps({'lines':len(lines),'longestLine':max(map(len,lines))}))
