const http = require('http');

const payload = JSON.stringify({
    method: "antigravity.workbench.executeJavaScript",
    args: {
        code: `JSON.stringify({
            title: document.title,
            total: document.querySelectorAll('*').length,
            btns: document.querySelectorAll('button').length,
            cv: !!document.querySelector('[data-testid="conversation-view"]'),
            stepEls: document.querySelectorAll('[data-step-index]').length,
            botColor: document.querySelectorAll('.text-ide-message-block-bot-color').length,
            prose: document.querySelectorAll('[class*="prose"]').length,
            agentConvo: document.querySelectorAll('[class*="agent-convo"]').length
        })`
    }
});

const req = http.request({
    hostname: '127.0.0.1',
    port: 34332,
    path: '/test-rpc',
    method: 'POST',
    headers: { 'Content-Type': 'application/json' }
}, (res) => {
    let data = '';
    res.on('data', c => data += c);
    res.on('end', () => {
        console.log('Status:', res.statusCode);
        try {
            const parsed = JSON.parse(data);
            console.log('Result:', JSON.stringify(parsed, null, 2));
        } catch {
            console.log('Raw:', data);
        }
    });
});

req.on('error', e => console.log('Error:', e.message));
req.write(payload);
req.end();
