<?php
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;
}

$brainDir = 'C:/Users/HP/.gemini/antigravity-ide/brain';
$logFiles = scan_dir_for_logs($brainDir);

echo "Found " . count($logFiles) . " log files to scan.\n";

$allLinks = [];
foreach ($logFiles as $logPath) {
    echo "Scanning $logPath...\n";
    $handle = fopen($logPath, 'r');
    if (!$handle) continue;
    
    $lineNum = 0;
    while (($line = fgets($handle)) !== false) {
        $lineNum++;
        // Search for any Google Drive links or direct image links
        if (stripos($line, 'drive.google.com') !== false || stripos($line, 'lh3.googleusercontent.com') !== false) {
            // Find matches for Google Drive file links
            // e.g. drive.google.com/file/d/[id]/view
            if (preg_match_all('/(?:drive\.google\.com\/file\/d\/|lh3\.googleusercontent\.com\/d\/)([a-zA-Z0-9_-]{25,})/', $line, $matches)) {
                foreach ($matches[1] as $id) {
                    $allLinks[$id][] = [
                        'file' => basename(dirname(dirname($logPath))), // conversation folder
                        'line' => $lineNum
                    ];
                }
            }
        }
    }
    fclose($handle);
}

echo "\nUnique Google Drive IDs found:\n";
foreach ($allLinks as $id => $occurrences) {
    echo "ID: $id (found in " . count($occurrences) . " places, e.g., " . $occurrences[0]['file'] . ")\n";
}
