<?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 not found\n");
}
$handle = fopen($logPath, "r");
$idx = 0;
$out = "";
while (($line = fgets($handle)) !== false) {
    $idx++;
    if (strpos($line, 'futureLocationTS') !== false || strpos($line, 'futureVariableTS') !== false) {
        $data = json_decode($line, true);
        if (!$data) continue;
        
        if (isset($data['tool_calls'])) {
            foreach ($data['tool_calls'] as $tc) {
                if ($tc['name'] === 'replace_file_content' || $tc['name'] === 'multi_replace_file_content' || $tc['name'] === 'write_to_file') {
                    $args = $tc['args'] ?? [];
                    $str = json_encode($args, JSON_PRETTY_PRINT);
                    if (strpos($str, '<select') !== false || strpos($str, '<div') !== false || strpos($str, 'futureLocationTS') !== false) {
                        $out .= "=== Step $idx ($tc[name]) ===\n";
                        if (isset($args['ReplacementContent'])) {
                            $out .= "--- ReplacementContent ---\n" . $args['ReplacementContent'] . "\n\n";
                        }
                        if (isset($args['TargetContent'])) {
                            $out .= "--- TargetContent ---\n" . $args['TargetContent'] . "\n\n";
                        }
                        if (isset($args['CodeContent'])) {
                            $out .= "--- CodeContent ---\n" . substr($args['CodeContent'], 0, 3000) . "\n\n";
                        }
                    }
                }
            }
        }
    }
}
fclose($handle);
file_put_contents("scratch/ts_html_extracted.txt", $out);
echo "Saved to scratch/ts_html_extracted.txt\n";
