"""Read the real server's captured checkpoint after the card appears; never writes DB."""
import json,pathlib,sqlite3,sys
checkout=pathlib.Path(sys.argv[1]);thread=sys.argv[2];output=pathlib.Path(sys.argv[3])
with sqlite3.connect('file:'+str(checkout/'.t3/userdata/statev2.sqlite')+'?mode=ro',uri=True) as db:
 row=db.execute('select payload_json from orchestration_v2_projection_checkpoints where thread_id=? and app_run_ordinal=1',(thread,)).fetchone()
payload=json.loads(row[0]);output.write_text(json.dumps(payload,indent=2)+'\n');print(json.dumps(payload['files'],indent=2))
