const fs = require('fs');
const path = require('path');

const bundlePath = String.raw`C:\Users\Variet-Worker\AppData\Local\Programs\Antigravity\resources\app\out\jetskiAgent\main.js`;

if (!fs.existsSync(bundlePath)) {
    console.log('Bundle not found at:', bundlePath);
    process.exit(1);
}

const content = fs.readFileSync(bundlePath, 'utf-8');
console.log('Bundle size:', (content.length / 1024 / 1024).toFixed(1), 'MB');

// Search for key DOM-related terms
const terms = [
    'data-testid',
    'conversation-view',
    'data-step-index',
    'message-block-bot',
    'markdown-body',
    'prose',
    'rendered-markdown',
    'step-container',
    'chat-message',
    'bot-message',
    'ai-message',
    'agent-response',
    'tool-call',
    'tool-result',
    'step-content',
    'message-content',
    'conversation-container',
    'chat-content',
    'response-text',
    'planner-response',
];

for (const t of terms) {
    const idx = content.indexOf(t);
    if (idx >= 0) {
        const start = Math.max(0, idx - 200);
        const end = Math.min(content.length, idx + 200);
        console.log(`\n${'='.repeat(60)}`);
        console.log(`FOUND: "${t}" at offset ${idx}`);
        console.log(`${'='.repeat(60)}`);
        console.log(content.substring(start, end));
    } else {
        console.log(`NOT FOUND: "${t}"`);
    }
}

// Also find all data-testid values
console.log('\n' + '='.repeat(60));
console.log('ALL data-testid values:');
console.log('='.repeat(60));
const testIdPattern = /data-testid[=:]["']([^"']+)["']/g;
const testIds = new Set();
let m;
while ((m = testIdPattern.exec(content)) !== null) {
    testIds.add(m[1]);
}
for (const id of [...testIds].sort()) {
    console.log('  -', id);
}

// Find all "className" or class patterns near Step/Message/Conversation
console.log('\n' + '='.repeat(60));
console.log('Step/Message/Conversation related class patterns:');
console.log('='.repeat(60));
const classPattern = /(?:className|class)[=:]"([^"]*(?:step|message|conversation|chat|agent|bot)[^"]*)"/gi;
const classes = new Set();
while ((m = classPattern.exec(content)) !== null) {
    classes.add(m[1].trim().substring(0, 100));
}
for (const cls of [...classes].sort()) {
    console.log('  -', cls);
}
