<?php
$logPath = 'C:/Users/HP/.gemini/antigravity-ide/brain/dabec389-a1dd-4fd5-add9-97761faf96ae/.system_generated/logs/transcript.jsonl';
if (!file_exists($logPath)) {
    die("Log 1 not found\n");
}

$handle = fopen($logPath, "r");
$idx = 0;
while (($line = fgets($handle)) !== false) {
    $idx++;
    $data = json_decode($line, true);
    if (!$data) continue;
    if (isset($data['tool_calls'])) {
        foreach ($data['tool_calls'] as $tc) {
            $name = $tc['name'] ?? '';
            $args = $tc['args'] ?? [];
            if ($name === 'write_to_file' || $name === 'default_api:write_to_file') {
                $tf = $args['TargetFile'] ?? '';
                if (stripos($tf, 'index.php') !== false) {
                    echo "Found full write to index.php at step $idx\n";
                    if (isset($args['CodeContent'])) {
                        $content = $args['CodeContent'];
                        $out = 'C:/Users/HP/Downloads/climate-system/climate-system/restored_log1_step_' . $idx . '.php';
                        file_put_contents($out, $content);
                        echo "  Wrote " . strlen($content) . " bytes to $out\n";
                    }
                }
            }
        }
    }
}
fclose($handle);
