<?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);

$ids = [
    '1AbUFmM8Fx3Zx_56mTb_oM656SXA8twcO', '1Ju2PDNGGSAMbMxWi2bFFYX_IzDchVo6F',
    '1ppI1lOWn7STFt3mA27uxwy3AK4SHmAGJ', '1v-VA64tw19bZkkfvIKOKkCqaEihXKyPe',
    '1Crc8YGKDMbD9xilyoDJmRSX4Bf5cIAuZ', '1kTHFVXF-26wVhzXQHIpIajZFJFvcv8RF',
    '1N2xVdc4ruJM2PchD9HOMVnh1N6qb54mW', '1IeLIfZmR0X3YyvJDltCt8v9Kc4narlVA',
    '19PGf_99lJJLvVKgMif8gyBXNd2OGUAL_', '1GSdtzLlZ-Mwr9SulrOd_wUZR5ZZXYqLF',
    '12BvWz3Ua-5VUwOSjvSEsc1_1YuU_VBT3', '1ZLCfnhALgJPBIe0kPk7fO0ZRO2nmSqoo',
    '1o2hThPvxhrNYqH5cKkVRo0MqAzWl86Ip', '1nn6GPerh0zDSE4JgRkInFhFjdLvATKpO',
    '1xKWOGtblOhP9G7jraQWd2mZCuHFiO5Ok', '16AwnrBQAqNJ78wiz6ksKuX2XjJRsxNxG',
    '1alVxAayYKalrw2paWsJMPcv7XgJ9QU7o', '1EOpTBlMCdK-r8X_bvzFV_fus-7AeX8R7',
    '11Nu9_WrbC27B7f2hS85TzE97YZ6jpTx8', '1Ejw3daYPXG6HPlbrZjwYE-UFC_Jj4mCv',
    '129I-uZ_mN-nX64Q4V64R26UZ5R9iZf8I', '1M8TuNjVOAzP309EaUvTKE_iA70uSa4eA',
    '1fag01DIqo6HiN_MkfYpn2GXb9m9icFRn', '1CYzZUlvatiC4punu8QTv2uQh_tT59jBE',
    '1oR69r8x3oUzyeqG-DudHNn9mjW4rBwIk', '14JxKBx5j-xoRPV5pAIUTG5wiZWYl4BZQ',
    '1lXjMej57rlIqM3KICDxVjDelijCkjTQw', '1JTdrAc_g9f4f3Lt3kNPC_Z-XOY5L6da7',
    '1ShKyfrRa4YJNOxM6wbpY1CPNKdSjzsAX', '1mfbq0GsGSpPkRnLuFle4zbi6ZfbL63tn',
    '1OSH3tjo21QS6cRYxZZuTsKa-A2pYJdtx', '1YP_EX3qTK4DniKkLXgHiTm0XLeHEdPzp',
    '1TdZtRCZx2gcwHvNS5pmfFL76Gl1vJ4Wc', '1fD4r8ws9ob5GDb3GC1a0P-yV9I7-NOB2',
    '1f8e-vt2E8RS9vZjk6wW0NzX2Gm6hxTVo', '1jJFPXe3-k_7Q93w25BnoWNcZoCja9cd9',
    '1pin3CmKhAAw4bdEmyHGcZ6CnRTz5oTCU', '1TKeOJVmldt0Wub4wX1LVrENC0mJdJbhG',
    '1yMzXu8bT6XSfUFT1VrrVgmFm8YRnuBIJ', '1hU5dXLlH6Ypr6ct3meiZyfcaPrkxebem',
    '1z6ApGjieTCwN5B3t_GH2h36zjmWFXUhm', '1fBZfOBJ6s_ttJmJHkp_RieBv6oQ2vTu6',
    '12SMHMolaw-qqCR8u4vbqGat4vYo0kaLD', '1S_vYAkhDY1SGuf88Aj-fJ6fvL92koKVU',
    '1HnTE9k52eDB_pfO9a7yt5J3Hx3Sxu8De', '1_WjSxhpTW4KGYtro5QHgdqdpVU74dOHI',
    '1-yz39obBBmnCe1ryhNADFCi-Mh5VymFT', '1NH1Zhc9wm5R2cMTMKDB5zyvh58KUvOrY',
    '1DfGEnOiaOcC-XJeNJR5RRvjan-otzRDu', '1epDuwq4n_QDgu0c_Ah-73OS35AyjuexO',
    '1QWJFA1VjyBN_iislEC7P3Zqj7dqGYJ93', '1AMK9YZyTf7y29nyTm-abFvKrW8oANXyo',
    '1NnFIxTd3gx0OYy1eUpN0SYFB24BB4G-h', '1aIF3JQXnDfBtnHNakI0jCDhQx3b3BAtz',
    '1RJaSwWtGr1vCfLGitbOph6EtzXHMvicn', '1BAerInDReE28vEnTjNPjiqivLY-pII4h',
    '17RAaoNK3D_ZF46SSQZ7aCeYKitVeUnBo', '1viEbo21f-ONUzqKTpVFwSQri7Pk4so_v'
];

$results = [];

foreach ($logFiles as $logPath) {
    $handle = fopen($logPath, 'r');
    if (!$handle) continue;
    
    while (($line = fgets($handle)) !== false) {
        foreach ($ids as $id) {
            if (strpos($line, $id) !== false) {
                // Look for tool calls that set variables or contain mapping details
                if (stripos($line, 'replace') !== false || stripos($line, 'write') !== false || stripos($line, 'save') !== false) {
                    $results[$id][] = $line;
                }
            }
        }
    }
    fclose($handle);
}

// Print results for matches that look like key mapping code or database updates
foreach ($results as $id => $lines) {
    echo "ID: $id\n";
    foreach ($lines as $line) {
        // Look for occurrences of words like Precipitation, Suhu, SSP1, SSP2, SSP3, SSP5
        if (preg_match('/(?:ssp[0-9]|Precipitation|Suhu|hujan|kelembaban|angin|radiasi|pH|salinitas|anomali|2021-2050|2031-2060|2041-2070|2051-2080|2061-2090|2071-2100)/i', $line)) {
            // decode json if possible
            $d = json_decode($line, true);
            if ($d && isset($d['tool_calls'])) {
                foreach ($d['tool_calls'] as $tc) {
                    $args = $tc['args'] ?? [];
                    $str = json_encode($args);
                    if (strpos($str, $id) !== false) {
                        // Print the matched arguments block
                        echo "  Match: " . substr($str, 0, 500) . "\n";
                    }
                }
            } else {
                echo "  Match: " . substr(trim($line), 0, 200) . "\n";
            }
        }
    }
    echo "--------------------------------------------------\n";
}
