import json, sqlite3, sys
# Read-only inspection of the synthetic server's persisted portable handoff.
connection = sqlite3.connect('file:' + sys.argv[1] + '?mode=ro', uri=True)
row = connection.execute('select payload_json from orchestration_v2_projection_context_handoffs where thread_id=? order by updated_at desc limit 1', (sys.argv[2],)).fetchone()
handoff = json.loads(row[0])
print(json.dumps({
    'strategy': handoff['strategy'],
    'status': handoff['status'],
    'history': [{'role': m['role'], 'text': m['text']} for m in handoff['history']['messages']],
}, indent=2))
