#!/usr/bin/env python3
"""Run from either proof checkout after starting its fresh dev server.
UI setup: Settings > Providers > Add provider > Antigravity > Next > Next.
Choose Gemini API key, enter any nonempty test key, Add instance, Connect.
Pair the web client with that server. Use a 1440x900 viewport and dark theme.
Record the thread before steering; do not stop the parent before inspecting.
The scenario runner cannot cover this provider-specific native protocol.
"""
import argparse, subprocess, pathlib, json, sqlite3
p=argparse.ArgumentParser(); p.add_argument('project'); p.add_argument('--inspect', action='store_true'); a=p.parse_args()
def cli(*args):
    return subprocess.check_output(['node','apps/server/src/bin.ts',*args],text=True).strip()
if not a.inspect:
    subprocess.run(['git','init',a.project],check=True)
    print(cli('project','add','--base-dir','.t3','--title','Subagent proof',a.project))
    print(cli('thread','start','--base-dir','.t3','--title','Native subagent lifecycle','--provider','antigravity','--model','gemini-4-neon',a.project,'Launch exactly one native subagent via invoke_subagent named Pong Responder. Its task is immediately send_messages pong to its parent, then run sleep 150. After launching it, you the parent must run sleep 150 and remain active. Do not wait for the child to finish before sleeping. Use native Antigravity tools, not T3 delegation.'))
    print('Open returned thread in web client. During active parent turn send these two composer steers:')
    print('1. run sleep 120 afterwards')
    print('2. use manage_subagents kill_all and list')
    print('Inspect Lineage while parent remains Working, then rerun with --inspect.')
else:
    db=sqlite3.connect('file:.t3/userdata/statev2.sqlite?mode=ro',uri=True)
    print('projection:',db.execute('select status,completed_at,updated_at from orchestration_v2_projection_subagents').fetchall())
    for f in pathlib.Path('.t3/userdata/providers/antigravity').rglob('subagents/*.json'):
        d=json.loads(f.read_text()); print('native:',d['state'])
