<?php
$logPath = 'C:/Users/HP/.gemini/antigravity-ide/brain/d31b1fe2-ad06-4c7a-9ab1-c82bd4c8dd20/.system_generated/logs/transcript.jsonl';
if (!file_exists($logPath)) {
    die("Log not found\n");
}
$handle = fopen($logPath, "r");
$idx = 0;
$out = "";
while (($line = fgets($handle)) !== false) {
    $idx++;
    if (strpos($line, 'replace_file_content') !== false || strpos($line, 'multi_replace_file_content') !== 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']);
                if (stripos($argsStr, 'TimeSeries') !== false || stripos($argsStr, 'futureLocationTS') !== false) {
                    $out .= "=== Log 2 Step $idx ({$tc['name']}) ===\n";
                    $out .= "Instruction: " . ($tc['args']['Instruction'] ?? '') . "\n";
                    if (isset($tc['args']['ReplacementContent'])) {
                        $out .= "ReplacementContent:\n" . $tc['args']['ReplacementContent'] . "\n";
                    }
                    if (isset($tc['args']['ReplacementChunks'])) {
                        $chunks = $tc['args']['ReplacementChunks'];
                        if (is_string($chunks)) {
                            $chunks = json_decode($chunks, true);
                        }
                        if (is_array($chunks)) {
                            foreach ($chunks as $c) {
                                $out .= "Chunk ReplacementContent:\n" . ($c['ReplacementContent'] ?? '') . "\n";
                            }
                        }
                    }
                    $out .= "========================================\n\n";
                }
            }
        }
    }
}
fclose($handle);
file_put_contents("scratch/search_log2_edits_ts_output_utf8.txt", $out);
echo "Saved to scratch/search_log2_edits_ts_output_utf8.txt\n";
