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

$out = "";
foreach ($logPaths as $logPath) {
    if (!file_exists($logPath)) continue;
    $out .= "=== Scanning $logPath ===\n";
    $handle = fopen($logPath, "r");
    $idx = 0;
    while (($line = fgets($handle)) !== false) {
        $idx++;
        if (strpos($line, 'applyFutureTSFilter') !== false || strpos($line, 'futureImageTimeSeries') !== false || strpos($line, 'futureLocationTS') !== false) {
            $data = json_decode($line, true);
            if (!$data) continue;
            
            if (isset($data['tool_calls'])) {
                foreach ($data['tool_calls'] as $tc) {
                    $argsStr = json_encode($tc['args'], JSON_PRETTY_PRINT);
                    if (strpos($argsStr, 'applyFutureTSFilter') !== false || strpos($argsStr, 'futureImageTimeSeries') !== false || strpos($argsStr, 'futureLocationTS') !== false) {
                        $out .= "Step $idx ($tc[name]):\n";
                        if (isset($tc['args']['ReplacementContent'])) {
                            $out .= "--- ReplacementContent ---\n" . $tc['args']['ReplacementContent'] . "\n";
                        }
                        if (isset($tc['args']['TargetContent'])) {
                            $out .= "--- TargetContent ---\n" . $tc['args']['TargetContent'] . "\n";
                        }
                        if (isset($tc['args']['CodeContent'])) {
                            $out .= "--- CodeContent ---\n" . substr($tc['args']['CodeContent'], 0, 2000) . "\n";
                        }
                    }
                }
            }
            if (isset($data['content']) && (strpos($data['content'], 'applyFutureTSFilter') !== false || strpos($data['content'], 'futureImageTimeSeries') !== false || strpos($data['content'], 'futureLocationTS') !== false)) {
                $out .= "Step $idx (content message):\n";
                $pos = strpos($data['content'], 'applyFutureTSFilter');
                if ($pos === false) $pos = strpos($data['content'], 'futureImageTimeSeries');
                if ($pos === false) $pos = strpos($data['content'], 'futureLocationTS');
                if ($pos !== false) {
                    $out .= substr($data['content'], max(0, $pos - 400), 3000) . "\n";
                }
            }
        }
    }
    fclose($handle);
}
file_put_contents("scratch/scan_ts_output_utf8.txt", $out);
echo "Done! Saved to scratch/scan_ts_output_utf8.txt\n";
