#!/usr/bin/env python3
"""Create the synthetic picker fixture used for both real-app evidence runs.
Usage: python3 seed-picker.py <new-project-directory>
Then add the project to a fresh T3 dev server and follow reproduction.md.
"""
from pathlib import Path
import json, subprocess, sys
p=Path(sys.argv[1]).resolve()
p.mkdir(parents=True, exist_ok=True)
(p / 'server.mjs').write_text('import readline from \'node:readline\';\nconst html="<!doctype html><html><body style=\\"margin:0;padding:16px;background:#152234;color:white;font:16px system-ui\\"><h3>Color picker</h3><button id=\\"pick\\" style=\\"padding:12px 24px;background:#368bff;color:white;border:0;border-radius:6px\\">Pick blue</button><p id=\\"status\\">No color picked</p><script>\\nwindow.addEventListener(\'message\',e=>{if(e.data.id===1){parent.postMessage({jsonrpc:\'2.0\',method:\'ui/notifications/initialized\'},\'*\')}if(e.data.id===2){document.getElementById(\'status\').textContent=\'Picked; model context sent\'}});\\nparent.postMessage({jsonrpc:\'2.0\',id:1,method:\'ui/initialize\',params:{protocolVersion:\'2026-01-26\',appInfo:{name:\'Picker\',version:\'1\'},appCapabilities:{}}},\'*\');\\ndocument.getElementById(\'pick\').onclick=()=>parent.postMessage({jsonrpc:\'2.0\',id:2,method:\'ui/update-model-context\',params:{content:[{type:\'text\',text:\'Color picker: the user picked BLUE-7731.\'}]}},\'*\');\\n</script></body></html>";\nfor await(const line of readline.createInterface({input:process.stdin})) {try {const q=JSON.parse(line);if(q.id===undefined)continue;let result={};switch(q.method){case \'initialize\': result={protocolVersion:q.params.protocolVersion,capabilities:{tools:{},resources:{}},serverInfo:{name:\'picker\',version:\'1\'}};break;case \'tools/list\':result={tools:[{name:\'show_picker\',description:\'Show the color picker app\',inputSchema:{type:\'object\',properties:{}},_meta:{ui:{resourceUri:\'ui://picker/app\'}}}]};break;case \'tools/call\':result={content:[{type:\'text\',text:\'Picker shown.\'}],_meta:{ui:{resourceUri:\'ui://picker/app\'}}};break;case \'resources/read\':result={contents:[{uri:\'ui://picker/app\',mimeType:\'text/html;profile=mcp-app\',text:html}]};break;case \'resources/list\':result={resources:[]};break;}process.stdout.write(JSON.stringify({jsonrpc:\'2.0\',id:q.id,result})+\'\\n\')}catch{}}\n')
(p / 'build.sh').write_text('for i in $(seq 1 45); do echo "Build step $i/45"; sleep 1; done\n')
(p / 'README.md').write_text('Synthetic color picker evidence fixture.\n')
(p / 'build.sh').chmod(0o755)
(p / '.mcp.json').write_text(json.dumps({'mcpServers': {'picker': {'command': 'node', 'args': [str(p / 'server.mjs')]}}}))
subprocess.run(['git', 'init', '-q', str(p)], check=True)
subprocess.run(['git', '-C', str(p), 'add', '.'], check=True)
subprocess.run(['git', '-C', str(p), '-c', 'user.name=Fixture', '-c', 'user.email=fixture@example.invalid', 'commit', '-qm', 'fixture'], check=True)
