antigravity-usage 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +118 -34
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1852,12 +1852,21 @@ async function detectOnUnix() {
|
|
|
1852
1852
|
const { stdout } = await execAsync("ps aux");
|
|
1853
1853
|
const lines = stdout.split("\n");
|
|
1854
1854
|
for (const line of lines) {
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1855
|
+
const lower = line.toLowerCase();
|
|
1856
|
+
if (!lower.includes("antigravity")) {
|
|
1857
|
+
continue;
|
|
1858
|
+
}
|
|
1859
|
+
if (lower.includes("server installation script")) {
|
|
1860
|
+
continue;
|
|
1861
|
+
}
|
|
1862
|
+
const hasServerSignal = line.includes("language-server") || line.includes("lsp") || line.includes("--csrf_token") || line.includes("--extension_server_port") || line.includes("exa.language_server_pb");
|
|
1863
|
+
if (!hasServerSignal) {
|
|
1864
|
+
continue;
|
|
1865
|
+
}
|
|
1866
|
+
debug("process-detector", `Found potential Antigravity process: ${line}`);
|
|
1867
|
+
const processInfo = parseUnixProcessLine(line);
|
|
1868
|
+
if (processInfo) {
|
|
1869
|
+
return processInfo;
|
|
1861
1870
|
}
|
|
1862
1871
|
}
|
|
1863
1872
|
debug("process-detector", "No Antigravity process found");
|
|
@@ -1894,24 +1903,27 @@ async function detectOnWindows() {
|
|
|
1894
1903
|
// 10MB buffer for long command lines
|
|
1895
1904
|
);
|
|
1896
1905
|
const lines = stdout.split("\n").filter((line) => line.trim() && !line.includes("Node,CommandLine,ProcessId"));
|
|
1906
|
+
const candidates = [];
|
|
1897
1907
|
for (const line of lines) {
|
|
1898
1908
|
const parts = line.split(",");
|
|
1899
1909
|
if (parts.length >= 3) {
|
|
1900
1910
|
const commandLine = parts.slice(1, -1).join(",");
|
|
1901
1911
|
const pid = parseInt(parts[parts.length - 1].trim(), 10);
|
|
1902
1912
|
if (!isNaN(pid) && commandLine.toLowerCase().includes("antigravity")) {
|
|
1903
|
-
|
|
1904
|
-
const csrfToken = extractArgument(commandLine, "--csrf_token");
|
|
1905
|
-
const extensionServerPort = extractArgument(commandLine, "--extension_server_port");
|
|
1906
|
-
return {
|
|
1913
|
+
candidates.push({
|
|
1907
1914
|
pid,
|
|
1908
|
-
csrfToken:
|
|
1909
|
-
extensionServerPort:
|
|
1915
|
+
csrfToken: extractArgument(commandLine, "--csrf_token") || void 0,
|
|
1916
|
+
extensionServerPort: parsePortValue(extractArgument(commandLine, "--extension_server_port")),
|
|
1910
1917
|
commandLine
|
|
1911
|
-
};
|
|
1918
|
+
});
|
|
1912
1919
|
}
|
|
1913
1920
|
}
|
|
1914
1921
|
}
|
|
1922
|
+
const selected = selectBestWindowsCandidate(candidates);
|
|
1923
|
+
if (selected) {
|
|
1924
|
+
debug("process-detector", `Selected Antigravity process on Windows: PID ${selected.pid}`);
|
|
1925
|
+
return selected;
|
|
1926
|
+
}
|
|
1915
1927
|
return await detectOnWindowsPowerShell();
|
|
1916
1928
|
} catch (err) {
|
|
1917
1929
|
debug("process-detector", "Error detecting process on Windows with WMIC, trying PowerShell", err);
|
|
@@ -1928,28 +1940,73 @@ async function detectOnWindowsPowerShell() {
|
|
|
1928
1940
|
}
|
|
1929
1941
|
const processes = JSON.parse(stdout);
|
|
1930
1942
|
const processList = Array.isArray(processes) ? processes : [processes];
|
|
1943
|
+
const candidates = [];
|
|
1931
1944
|
for (const proc of processList) {
|
|
1932
1945
|
if (proc.Id) {
|
|
1933
1946
|
const { stdout: cmdLine } = await execAsync(
|
|
1934
1947
|
`powershell -Command "(Get-CimInstance Win32_Process -Filter 'ProcessId = ${proc.Id}').CommandLine"`
|
|
1935
1948
|
);
|
|
1936
1949
|
const commandLine = cmdLine.trim();
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1950
|
+
if (!commandLine.toLowerCase().includes("antigravity")) {
|
|
1951
|
+
continue;
|
|
1952
|
+
}
|
|
1953
|
+
candidates.push({
|
|
1940
1954
|
pid: proc.Id,
|
|
1941
|
-
csrfToken:
|
|
1942
|
-
extensionServerPort:
|
|
1955
|
+
csrfToken: extractArgument(commandLine, "--csrf_token") || void 0,
|
|
1956
|
+
extensionServerPort: parsePortValue(extractArgument(commandLine, "--extension_server_port")),
|
|
1943
1957
|
commandLine
|
|
1944
|
-
};
|
|
1958
|
+
});
|
|
1945
1959
|
}
|
|
1946
1960
|
}
|
|
1961
|
+
const selected = selectBestWindowsCandidate(candidates);
|
|
1962
|
+
if (selected) {
|
|
1963
|
+
debug("process-detector", `Selected Antigravity process on Windows (PowerShell): PID ${selected.pid}`);
|
|
1964
|
+
return selected;
|
|
1965
|
+
}
|
|
1947
1966
|
return null;
|
|
1948
1967
|
} catch (err) {
|
|
1949
1968
|
debug("process-detector", "Error detecting process on Windows with PowerShell", err);
|
|
1950
1969
|
return null;
|
|
1951
1970
|
}
|
|
1952
1971
|
}
|
|
1972
|
+
function parsePortValue(rawPort) {
|
|
1973
|
+
if (!rawPort) {
|
|
1974
|
+
return void 0;
|
|
1975
|
+
}
|
|
1976
|
+
const parsed = parseInt(rawPort, 10);
|
|
1977
|
+
return isNaN(parsed) ? void 0 : parsed;
|
|
1978
|
+
}
|
|
1979
|
+
function scoreWindowsCandidate(candidate) {
|
|
1980
|
+
const lower = candidate.commandLine.toLowerCase();
|
|
1981
|
+
let score = 0;
|
|
1982
|
+
if (lower.includes("antigravity")) score += 1;
|
|
1983
|
+
if (lower.includes("lsp")) score += 5;
|
|
1984
|
+
if (candidate.extensionServerPort) score += 10;
|
|
1985
|
+
if (candidate.csrfToken) score += 20;
|
|
1986
|
+
if (lower.includes("language_server") || lower.includes("language-server") || lower.includes("exa.language_server_pb")) {
|
|
1987
|
+
score += 50;
|
|
1988
|
+
}
|
|
1989
|
+
return score;
|
|
1990
|
+
}
|
|
1991
|
+
function selectBestWindowsCandidate(candidates) {
|
|
1992
|
+
if (candidates.length === 0) {
|
|
1993
|
+
return null;
|
|
1994
|
+
}
|
|
1995
|
+
debug("process-detector", `Found ${candidates.length} Antigravity candidate process(es) on Windows`);
|
|
1996
|
+
let best = null;
|
|
1997
|
+
let bestScore = -1;
|
|
1998
|
+
for (const candidate of candidates) {
|
|
1999
|
+
const score = scoreWindowsCandidate(candidate);
|
|
2000
|
+
if (score > bestScore) {
|
|
2001
|
+
best = candidate;
|
|
2002
|
+
bestScore = score;
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
if (best) {
|
|
2006
|
+
debug("process-detector", `Selected PID ${best.pid} with score ${bestScore}`);
|
|
2007
|
+
}
|
|
2008
|
+
return best;
|
|
2009
|
+
}
|
|
1953
2010
|
function extractArgument(commandLine, argName) {
|
|
1954
2011
|
const eqRegex = new RegExp(`${argName}=([^\\s"']+|"[^"]*"|'[^']*')`, "i");
|
|
1955
2012
|
const eqMatch = commandLine.match(eqRegex);
|
|
@@ -2076,6 +2133,8 @@ async function discoverPortsOnWindows(pid) {
|
|
|
2076
2133
|
// src/local/port-prober.ts
|
|
2077
2134
|
import https from "https";
|
|
2078
2135
|
import http from "http";
|
|
2136
|
+
var CONNECT_RPC_PATH = "/exa.language_server_pb.LanguageServerService/GetUnleashData";
|
|
2137
|
+
var VALID_CONNECT_STATUSES = /* @__PURE__ */ new Set([200, 401]);
|
|
2079
2138
|
async function probeForConnectAPI(ports, csrfToken, timeout = 500) {
|
|
2080
2139
|
debug("port-prober", `Probing ${ports.length} ports: ${ports.join(", ")}`);
|
|
2081
2140
|
const probePromises = ports.map((port) => probePort(port, csrfToken, timeout));
|
|
@@ -2095,7 +2154,7 @@ async function probePort(port, csrfToken, timeout = 500) {
|
|
|
2095
2154
|
if (httpsResult) {
|
|
2096
2155
|
return httpsResult;
|
|
2097
2156
|
}
|
|
2098
|
-
const httpResult = await probeHttp(port, timeout);
|
|
2157
|
+
const httpResult = await probeHttp(port, timeout, csrfToken);
|
|
2099
2158
|
if (httpResult) {
|
|
2100
2159
|
return httpResult;
|
|
2101
2160
|
}
|
|
@@ -2106,7 +2165,7 @@ function probeHttps(port, timeout, csrfToken) {
|
|
|
2106
2165
|
const options = {
|
|
2107
2166
|
hostname: "127.0.0.1",
|
|
2108
2167
|
port,
|
|
2109
|
-
path:
|
|
2168
|
+
path: CONNECT_RPC_PATH,
|
|
2110
2169
|
method: "POST",
|
|
2111
2170
|
timeout,
|
|
2112
2171
|
rejectUnauthorized: false,
|
|
@@ -2118,7 +2177,7 @@ function probeHttps(port, timeout, csrfToken) {
|
|
|
2118
2177
|
}
|
|
2119
2178
|
};
|
|
2120
2179
|
const req = https.request(options, (res) => {
|
|
2121
|
-
if (res.statusCode
|
|
2180
|
+
if (res.statusCode && VALID_CONNECT_STATUSES.has(res.statusCode)) {
|
|
2122
2181
|
debug("port-prober", `HTTPS Connect RPC probe on port ${port}: status ${res.statusCode} - valid connect port`);
|
|
2123
2182
|
resolve({
|
|
2124
2183
|
baseUrl: `https://127.0.0.1:${port}`,
|
|
@@ -2144,23 +2203,43 @@ function probeHttps(port, timeout, csrfToken) {
|
|
|
2144
2203
|
req.end();
|
|
2145
2204
|
});
|
|
2146
2205
|
}
|
|
2147
|
-
function probeHttp(port, timeout) {
|
|
2206
|
+
function probeHttp(port, timeout, csrfToken) {
|
|
2148
2207
|
return new Promise((resolve) => {
|
|
2149
2208
|
const options = {
|
|
2150
|
-
hostname: "
|
|
2209
|
+
hostname: "127.0.0.1",
|
|
2151
2210
|
port,
|
|
2152
|
-
path:
|
|
2153
|
-
method: "
|
|
2154
|
-
timeout
|
|
2211
|
+
path: CONNECT_RPC_PATH,
|
|
2212
|
+
method: "POST",
|
|
2213
|
+
timeout,
|
|
2214
|
+
headers: {
|
|
2215
|
+
"Content-Type": "application/json",
|
|
2216
|
+
"Connect-Protocol-Version": "1",
|
|
2217
|
+
...csrfToken ? { "X-Codeium-Csrf-Token": csrfToken } : {}
|
|
2218
|
+
}
|
|
2155
2219
|
};
|
|
2156
2220
|
const req = http.request(options, (res) => {
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2221
|
+
let data = "";
|
|
2222
|
+
res.on("data", (chunk) => {
|
|
2223
|
+
data += chunk.toString();
|
|
2224
|
+
});
|
|
2225
|
+
res.on("end", () => {
|
|
2226
|
+
if (data.toLowerCase().includes("client sent an http request to an https server")) {
|
|
2227
|
+
debug("port-prober", `HTTP probe on port ${port}: protocol mismatch response, rejecting`);
|
|
2228
|
+
resolve(null);
|
|
2229
|
+
return;
|
|
2230
|
+
}
|
|
2231
|
+
if (res.statusCode && VALID_CONNECT_STATUSES.has(res.statusCode)) {
|
|
2232
|
+
debug("port-prober", `HTTP Connect RPC probe on port ${port}: status ${res.statusCode} - valid connect port`);
|
|
2233
|
+
resolve({
|
|
2234
|
+
baseUrl: `http://127.0.0.1:${port}`,
|
|
2235
|
+
protocol: "http",
|
|
2236
|
+
port
|
|
2237
|
+
});
|
|
2238
|
+
return;
|
|
2239
|
+
}
|
|
2240
|
+
debug("port-prober", `HTTP probe on port ${port}: status ${res.statusCode} - not connect port`);
|
|
2241
|
+
resolve(null);
|
|
2162
2242
|
});
|
|
2163
|
-
res.resume();
|
|
2164
2243
|
});
|
|
2165
2244
|
req.on("error", (err) => {
|
|
2166
2245
|
debug("port-prober", `HTTP probe on port ${port} failed: ${err.message}`);
|
|
@@ -2171,6 +2250,7 @@ function probeHttp(port, timeout) {
|
|
|
2171
2250
|
req.destroy();
|
|
2172
2251
|
resolve(null);
|
|
2173
2252
|
});
|
|
2253
|
+
req.write(JSON.stringify({ wrapper_data: {} }));
|
|
2174
2254
|
req.end();
|
|
2175
2255
|
});
|
|
2176
2256
|
}
|
|
@@ -2468,7 +2548,11 @@ async function fetchQuotaLocal() {
|
|
|
2468
2548
|
throw new AntigravityNotRunningError();
|
|
2469
2549
|
}
|
|
2470
2550
|
debug("service", `Found Antigravity process: PID ${processInfo.pid}`);
|
|
2471
|
-
|
|
2551
|
+
let ports = await discoverPorts(processInfo.pid);
|
|
2552
|
+
if (ports.length === 0 && processInfo.extensionServerPort) {
|
|
2553
|
+
debug("service", `Falling back to extension_server_port: ${processInfo.extensionServerPort}`);
|
|
2554
|
+
ports = [processInfo.extensionServerPort];
|
|
2555
|
+
}
|
|
2472
2556
|
if (ports.length === 0) {
|
|
2473
2557
|
throw new PortDetectionError();
|
|
2474
2558
|
}
|