import pathlib,sys,sqlite3,json
checkout=pathlib.Path(sys.argv[1]);db=checkout/'.t3/manual/userdata/statev2.sqlite'
con=sqlite3.connect(f'file:{db}?mode=ro',uri=True)
rows=con.execute("""select t.thread_id,t.title,json_extract(p.payload_json,'$.nativeThreadRef.nativeId') native_id
from orchestration_v2_projection_threads t join orchestration_v2_projection_provider_threads p on p.thread_id=t.thread_id
where t.deleted_at is null and p.provider_instance_id='acpRegistry_local_acp' and json_extract(p.payload_json,'$.nativeThreadRef.nativeId') is not null""").fetchall()
print(json.dumps([{'threadId':r[0],'title':r[1],'nativeId':r[2]} for r in rows],indent=2))
