import argparse, json, subprocess
from pathlib import Path

p = argparse.ArgumentParser()
p.add_argument("directory", type=Path)
a = p.parse_args()
root = a.directory.resolve()
root.mkdir(parents=True, exist_ok=True)
files = {'proof_mcp.py': "import sys,json\nfor line in sys.stdin:\n try:\n  m=json.loads(line); method=m.get('method'); rid=m.get('id')\n  if rid is None: continue\n  if method=='initialize': result={'protocolVersion':'2024-11-05','capabilities':{'tools':{}},'serverInfo':{'name':'plugin-proof','version':'1.0'}}\n  elif method=='tools/list': result={'tools':[{'name':'plugin_document_stamp','description':'Return the synthetic document plugin stamp.','inputSchema':{'type':'object','properties':{}}}]}\n  elif method=='tools/call': result={'content':[{'type':'text','text':'PLUGIN_TOOL_LOADED_39082'}]}\n  else: result={}\n  print(json.dumps({'jsonrpc':'2.0','id':rid,'result':result}),flush=True)\n except Exception: pass\n", 'plugin.json': '{"name": "factory-plugin-proof", "version": "1.0.0", "description": "Synthetic plugin for global plugin evidence"}', 'skills/proof-gdocs/SKILL.md': '---\nname: proof-gdocs\ndescription: Synthetic document plugin proof skill\n---\nWhen asked to use this skill, respond with PLUGIN_SKILL_LOADED_39082.\n'}
for name, contents in files.items():
    target = root / name
    target.parent.mkdir(parents=True, exist_ok=True)
    target.write_text(contents)
(root / "mcp_config.json").write_text(json.dumps({"mcpServers":{"plugin-proof":{"command":"python3","args":[str(root / "proof_mcp.py")]}}}))
subprocess.run(["agy", "plugin", "install", str(root)], check=True)
subprocess.run(["agy", "plugin", "enable", "factory-plugin-proof"], check=True)
subprocess.run(["agy", "plugin", "list", "--json"], check=True)
