const http = require('http'); const https = require('https'); const { execSync } = require('child_process'); async function listLanguageServerProcesses() { const command = [ 'powershell -NoProfile -Command', '"Get-CimInstance Win32_Process -Filter \\"name like \'language_server%\'\\"', '| Select-Object ProcessId,ParentProcessId,CommandLine,ExecutablePath', '| ConvertTo-Json -Depth 2"' ].join(' '); const result = execSync(command, { encoding: 'utf8' }); return JSON.parse(result); } function extractArgument(commandLine, argumentName) { const escapedName = argumentName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); const pattern = new RegExp(`--${escapedName}(?:=|\\s+)(?:"([^"]*)"|'([^']*)'|([^\\s]+))`, 'i'); const match = commandLine.match(pattern); return match ? (match[1] ?? match[2] ?? match[3] ?? null) : null; } const API_PATH = '/exa.language_server_pb.LanguageServerService/RetrieveUserQuotaSummary'; const requestBody = JSON.stringify({ metadata: { ideName: 'antigravity', extensionName: 'ag-usage', locale: 'en' } }); function tryPort(port, csrfToken, protocol) { return new Promise(resolve => { const client = protocol === 'https' ? https : http; const req = client.request({ hostname: '127.0.0.1', port, path: API_PATH, method: 'POST', ...(protocol === 'https' ? { rejectUnauthorized: false } : {}), headers: { 'X-Codeium-Csrf-Token': csrfToken, 'Connect-Protocol-Version': '1', 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(requestBody), }, timeout: 3000, }, res => { let body = ''; res.setEncoding('utf8'); res.on('data', chunk => body += chunk); res.on('end', () => resolve({ port, statusCode: res.statusCode, body })); }); req.on('error', () => resolve(null)); req.write(requestBody); req.end(); }); } (async () => { const processes = await listLanguageServerProcesses(); let procs = Array.isArray(processes) ? processes : (processes ? [processes] : []); let port, csrfToken, protocol; for (const proc of procs) { if (!proc.CommandLine) continue; const p = extractArgument(proc.CommandLine, 'api_server_port'); const c = extractArgument(proc.CommandLine, 'csrf_token'); if (p && c) { port = p; csrfToken = c; protocol = proc.CommandLine.includes('--api_server_protocol=https') ? 'https' : 'http'; break; } } if (!port) return console.log('not found'); const response = await tryPort(port, csrfToken, protocol); console.log(response.body); })();