#!/usr/bin/env python3
"""Extract synthetic runtime proof from the current checkout, without credentials or host paths."""
import json, sqlite3, pathlib, subprocess, sys
root = pathlib.Path.cwd()
conn = sqlite3.connect(f"file:{root}/.t3/userdata/statev2.sqlite?mode=ro", uri=True)
items = [json.loads(row[0]) for row in conn.execute("select payload_json from orchestration_v2_projection_turn_items where type='dynamic_tool' order by updated_at")]
delegate = [item for item in items if item.get('toolName','').endswith('delegate_task')][-1]
responses = []
for path in (root/'.t3/userdata/providers/antigravity').rglob('transcript.jsonl'):
    for line in path.read_text().splitlines():
        entry = json.loads(line)
        if entry.get('source') == 'MODEL' and entry.get('type') == 'PLANNER_RESPONSE':
            responses.append(entry)
proof = {'commit': subprocess.check_output(['git','rev-parse','HEAD'],text=True).strip(), 'environment': {'surface':'Web and real T3 server', 'runtime':'agy 1.5.18', 'authentication':'Gemini API key', 'freshDatabase':True, 'parentModel':'gpt-6-luna'}, 'delegateTask':{'input':delegate['input'],'output':delegate['output']}, 'nativePlannerResponses':responses}
pathlib.Path(sys.argv[1]).write_text(json.dumps(proof,indent=2)+'\n')
print(json.dumps({'model':delegate['output']['model'],'executedModel':delegate['output']['executedModel'],'status':delegate['output']['status'],'nativeModels':[x.get('model') for x in responses]}))
