<?php
$brainDir = 'C:/Users/HP/.gemini/antigravity-ide/brain';

function scan_dir_for_logs($dir) {
    $found = [];
    if (!is_dir($dir)) return $found;
    $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
    foreach ($it as $file) {
        if ($file->isFile() && $file->getFilename() === 'transcript.jsonl') {
            $found[] = $file->getPathname();
        }
    }
    return $found;
}

$logFiles = scan_dir_for_logs($brainDir);
$mappings = [];

foreach ($logFiles as $logPath) {
    $handle = fopen($logPath, 'r');
    if (!$handle) continue;
    
    while (($line = fgets($handle)) !== false) {
        // If the line contains tool call to replace file content or similar
        // Let's decode JSON
        $data = json_decode($line, true);
        if (!$data || !isset($data['tool_calls'])) continue;
        
        foreach ($data['tool_calls'] as $tc) {
            $args = $tc['args'] ?? [];
            $str = json_encode($args);
            
            // Check if it looks like a database insert or update
            if (stripos($str, 'save_future') !== false || stripos($str, 'stripe') !== false) {
                // Look for Google Drive links inside the args
                if (preg_match_all('/(?:drive\.google\.com\/file\/d\/|lh3\.googleusercontent\.com\/d\/)([a-zA-Z0-9_-]{25,})/', $str, $matches)) {
                    // We found some Google Drive links in this tool call. Let's output it.
                    echo "=== Match in " . basename(dirname(dirname($logPath))) . " ===\n";
                    echo substr($str, 0, 1500) . "\n\n";
                }
            }
        }
    }
    fclose($handle);
}
