Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

fix: resolve MITM not working when connecting Antigravity (#1399)

diegosouzapwb90901305810
diff --git a/src/mitm/cert/install.ts b/src/mitm/cert/install.ts
index 8e23611e5e..cccf294817 100644
--- a/src/mitm/cert/install.ts
+++ b/src/mitm/cert/install.ts
@@ -82,10 +82,13 @@ async function installCertMac(sudoPassword, certPath) {
}
async function installCertWindows(certPath) {
- // Use PowerShell elevated to add cert to Root store
- const psCommand = `Start-Process certutil -ArgumentList '-addstore','Root','${certPath.replace(/'/g, "''")}' -Verb RunAs -Wait`;
+ // Use PowerShell elevated to add cert to Root store and capture exit code
+ const psScript = `
+ $proc = Start-Process certutil -ArgumentList '-addstore','Root','${certPath.replace(/'/g, "''")}' -Verb RunAs -Wait -PassThru;
+ if ($proc.ExitCode -ne 0) { throw "certutil exited with code $($proc.ExitCode)" }
+ `;
return new Promise((resolve, reject) => {
- exec(`powershell -Command "${psCommand}"`, (error) => {
+ exec(`powershell -Command "${psScript.replace(/\n/g, " ")}"`, (error) => {
if (error) {
reject(new Error(`Failed to install certificate: ${error.message}`));
} else {
diff --git a/src/mitm/dns/dnsConfig.ts b/src/mitm/dns/dnsConfig.ts
index 3353f8e3c9..e0f87070e8 100644
--- a/src/mitm/dns/dnsConfig.ts
+++ b/src/mitm/dns/dnsConfig.ts
@@ -30,8 +30,11 @@ export function execWithPassword(command, password) {
*/
function execElevatedWindows(command) {
return new Promise((resolve, reject) => {
- const psCommand = `Start-Process cmd -ArgumentList '/c','${command.replace(/'/g, "''")}' -Verb RunAs -Wait`;
- exec(`powershell -Command "${psCommand}"`, (error, stdout, stderr) => {
+ const psScript = `
+ $proc = Start-Process cmd -ArgumentList '/c','${command.replace(/'/g, "''")}' -Verb RunAs -Wait -PassThru;
+ if ($proc.ExitCode -ne 0) { throw "Elevated command exited with code $($proc.ExitCode)" }
+ `;
+ exec(`powershell -Command "${psScript.replace(/\n/g, " ")}"`, (error, stdout, stderr) => {
if (error) {
reject(new Error(`Elevated command failed: ${error.message}\n${stderr}`));
} else {
@@ -50,7 +53,7 @@ export function checkDNSEntry() {
const lines = hostsContent.split(/\r?\n/);
return lines.some((line) => {
const parts = line.trim().split(/\s+/);
- return parts.length >= 2 && parts[0] === "127.0.0.1" && parts.some(p => p === TARGET_HOST);
+ return parts.length >= 2 && parts[0] === "127.0.0.1" && parts.some((p) => p === TARGET_HOST);
});
} catch {
return false;
diff --git a/src/mitm/manager.ts b/src/mitm/manager.ts
index 5e156acae6..0a082a9cb7 100644
--- a/src/mitm/manager.ts
+++ b/src/mitm/manager.ts
@@ -25,11 +25,14 @@ export function clearCachedPassword() {
const PID_FILE = path.join(resolveDataDir(), "mitm", ".mitm.pid");
const MITM_SERVER_URL = new URL("./server.cjs", import.meta.url);
-const MITM_SERVER_PATH =
+const urlPath =
process.platform === "win32" && MITM_SERVER_URL.pathname.startsWith("/")
? decodeURIComponent(MITM_SERVER_URL.pathname.slice(1))
: decodeURIComponent(MITM_SERVER_URL.pathname);
+const cwdPath = path.join(process.cwd(), "src", "mitm", "server.cjs");
+const MITM_SERVER_PATH = fs.existsSync(cwdPath) ? cwdPath : urlPath;
+
// Check if a PID is alive
function isProcessAlive(pid) {
try {