import json, pathlib, sqlite3, sys
# Only export the specific synthetic probe events; never export full provider logs.
log, database, side = sys.argv[1:]
print(side)
tools = {}
for line in pathlib.Path(log).read_text().splitlines():
    d = json.loads(line[line.index('{'):])
    p = d.get('event', {}).get('payload', {})
    ts = line[1:25]
    if p.get('subtype') == 'task_started' and p.get('is_backgrounded'):
        print(ts, 'background subagent started')
    if p.get('type') == 'result' and p.get('result') == 'LAUNCHED':
        print(ts, 'parent result: LAUNCHED')
    for c in p.get('message', {}).get('content', []) if isinstance(p.get('message', {}).get('content', []), list) else []:
        if c.get('type') == 'tool_use':
            i = c.get('input', {})
            name = c.get('name')
            target = i.get('command') or i.get('file_path')
            if target in ('sleep 10', 'echo probe', '/etc/hosts', 'cat /etc/hosts', 'ls /tmp'):
                tools[c['id']] = f'{name} {target}'
                print(ts, 'tool call:', tools[c['id']])
        if c.get('type') == 'tool_result' and c.get('tool_use_id') in tools:
            content = str(c.get('content', ''))
            result = 'Claude V2 adapter has no active turn for this tool request.' if 'no active turn' in content else ('tool error (contents omitted)' if c.get('is_error') else 'success (contents omitted)')
            print(ts, tools[c['tool_use_id']], '=>', result)
con = sqlite3.connect(f'file:{database}?mode=ro', uri=True)
rows = con.execute('select created_at,kind,status,resolved_at from orchestration_v2_projection_runtime_requests').fetchall()
print('Persisted runtime requests:', len(rows))
for row in rows: print(*row)
