<?php
$logPaths = [
    '1' => 'C:/Users/HP/.gemini/antigravity-ide/brain/dabec389-a1dd-4fd5-add9-97761faf96ae/.system_generated/logs/transcript.jsonl',
    '2' => 'C:/Users/HP/.gemini/antigravity-ide/brain/d31b1fe2-ad06-4c7a-9ab1-c82bd4c8dd20/.system_generated/logs/transcript.jsonl'
];

foreach ($logPaths as $num => $logPath) {
    if (!file_exists($logPath)) continue;
    echo "=== Scanning Log $num ===\n";
    $handle = fopen($logPath, "r");
    $idx = 0;
    while (($line = fgets($handle)) !== false) {
        $idx++;
        if (strpos($line, 'futureLocationTS') !== false) {
            $data = json_decode($line, true);
            if (!$data) continue;
            echo "Step $idx: Source={$data['source']}, Type={$data['type']}\n";
            // Print content length
            if (isset($data['content'])) {
                echo "  Content length: " . strlen($data['content']) . "\n";
                if (strpos($data['content'], '<select') !== false) {
                    echo "  Contains '<select'\n";
                    // let's print a small chunk around futureLocationTS
                    $pos = strpos($data['content'], 'futureLocationTS');
                    echo "  Snippet: " . substr($data['content'], max(0, $pos - 150), 300) . "\n";
                }
            }
            if (isset($data['tool_calls'])) {
                foreach ($data['tool_calls'] as $tc) {
                    echo "  Tool Call: " . $tc['name'] . "\n";
                    $str = json_encode($tc['args']);
                    if (strpos($str, '<select') !== false) {
                        echo "  Tool args contain '<select'\n";
                        $pos = strpos($str, 'futureLocationTS');
                        echo "  Snippet: " . substr($str, max(0, $pos - 150), 300) . "\n";
                    }
                }
            }
        }
    }
    fclose($handle);
}
