Files
Jannik 5d93d9f798
Build and Push Docker Image / build-and-push (push) Canceled after 0s
feat: Integrate 4 bars for Antigravity via RetrieveUserQuotaSummary API
2026-08-28 23:08:10 +02:00

65 lines
2.9 KiB
JavaScript

const fs = require('fs');
const http = require('http');
const https = require('https');
const { execSync } = require('child_process');
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;
}
try {
const stdout = execSync('powershell -NoProfile -Command "Get-CimInstance Win32_Process -Filter \\"name like \'language_server%\'\\" | Select-Object ProcessId,CommandLine | ConvertTo-Json -Depth 2"').toString();
const processes = JSON.parse(stdout);
const processInfo = Array.isArray(processes) ? processes.find(p => extractArgument(p.CommandLine, 'csrf_token')) : processes;
if (!processInfo) { console.log('No LS found'); process.exit(0); }
const csrfToken = extractArgument(processInfo.CommandLine, 'csrf_token');
const pid = processInfo.ProcessId;
const netstat = execSync('netstat -ano').toString();
const ports = [];
for (const line of netstat.split(/\r?\n/)) {
if (!/(LISTEN|ABH)/i.test(line) || !new RegExp(`\\s${pid}\\s*$`).test(line)) continue;
for (const match of line.matchAll(/(?:127\.0\.0\.1|\[?::1\]?):(\d{2,5})/g)) {
ports.push(Number(match[1]));
}
}
const requestBody = JSON.stringify({ metadata: { ideName: 'antigravity', extensionName: 'ag-usage', locale: 'en' } });
for (const port of [...new Set(ports)]) {
['http', 'https'].forEach(protocol => {
const client = protocol === 'https' ? https : http;
const req = client.request({
hostname: '127.0.0.1', port, path: '/exa.language_server_pb.LanguageServerService/RetrieveUserQuotaSummary', 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)
}
}, res => {
let body = '';
res.on('data', chunk => body += chunk);
res.on('end', () => {
console.log('Port', port, protocol, res.statusCode);
if (res.statusCode === 200) {
try {
fs.writeFileSync('ag-debug.json', JSON.stringify(JSON.parse(body), null, 2));
} catch(e) {}
}
});
});
req.on('error', () => {});
req.write(requestBody);
req.end();
});
}
} catch (e) {
console.error(e);
}