fix(server): unwrap Antigravity .cmd wrappers to the real ACP pair #12878
Closedcestercian(GitHub profile, opens in a new tab)wants to merge 7 commits into
main fromrefs/pull/12878/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/provider/AntigravityInstallation.ts lines 432 to 450OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -364,0 +430,21 @@430+ function* (candidate: string) {431+ if (platform !== "win32" || !isWindowsLauncherPath(candidate)) return candidate;432+ const sibling = path.join(path.dirname(candidate), names.executable);433+ if (yield* executableFile(sibling)) return yield* fs.realPath(sibling);434+ const info = yield* fs.stat(candidate).pipe(Effect.option);435+ if (436+ Option.isNone(info) ||437+ info.value.type !== "File" ||438+ Number(info.value.size) > WRAPPER_MAX_BYTES439+ ) {440+ return null;441+ }442+ const contents = yield* fs.readFileString(candidate);443+ const wrapperDirectory = path.dirname(candidate);444+ for (const referenced of wrapperExecutableReferences(contents, names.executable)) {445+ const resolved = expandWrapperPath(referenced, wrapperDirectory, path);446+ if (!(yield* executableFile(resolved))) continue;447+ const real = yield* fs.realPath(resolved);448+ if (path.basename(real).toLowerCase() !== names.executable.toLowerCase()) continue;449+ return real;450+ }
- apps/server/src/provider/AntigravityInstallation.ts lines 170 to 184OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -144,0 +164,21 @@164+ lower.endsWith(`\\${name}`) ||165+ lower.endsWith(`%~dp0${name}`)166+ );167+}168+169+/** Quoted and unquoted references to the ACP executable inside a launcher script. */170+function wrapperExecutableReferences(contents: string, executableName: string) {171+ const found: string[] = [];172+ const seen = new Set<string>();173+ const add = (value: string) => {174+ const trimmed = value.trim();175+ if (!trimmed || seen.has(trimmed) || !refersToAcpExecutable(trimmed, executableName)) return;176+ seen.add(trimmed);177+ found.push(trimmed);178+ };179+ for (const rawLine of contents.split(/\r?\n/u)) {180+ const line = rawLine.trim();181+ if (line.length === 0 || /^(?:rem\b|::)/iu.test(line)) continue;182+ for (const match of line.matchAll(/"([^"]+)"/g)) add(match[1] ?? "");183+ for (const match of line.matchAll(/'([^']+)'/g)) add(match[1] ?? "");184+ for (const token of line.split(/[\s,;=&|<>^]+/u)) add(token.replace(/^@+/u, ""));apps/server/src/provider/AntigravityInstallation.ts lines 432 to 433OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -362,3 +422,12 @@362422 } satisfies AntigravityExecutable;363423 });364424425+ // Follow .cmd/.bat wrappers to agy_acp_server.exe and use that file's426+ // sibling harness. ACP is JSON-RPC over stdin/stdout; spawning the427+ // launcher through cmd.exe breaks the handshake, and a copied harness428+ // next to the wrapper can be a different release.429+ const unwrapWindowsLauncher = Effect.fn("AntigravityInstallation.unwrapWindowsLauncher")(430+ function* (candidate: string) {431+ if (platform !== "win32" || !isWindowsLauncherPath(candidate)) return candidate;432+ const sibling = path.join(path.dirname(candidate), names.executable);433+ if (yield* executableFile(sibling)) return yield* fs.realPath(sibling);
- apps/server/src/provider/AntigravityInstallation.ts lines 195 to 202OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -144,0 +182,21 @@182+ const target = quoted?.[1] ?? unquoted?.[1];183+ return target !== undefined && isProvenLaunchPath(target, executableName) ? target : null;184+}185+186+/**187+ * The executable a `.cmd`/`.bat` wrapper actually starts, not a path mentioned188+ * in `echo`/`set` or an unexecuted branch. Returns null when control flow or189+ * quoting makes that target unprovable.190+ */191+function provenWrapperLaunchTarget(contents: string, executableName: string) {192+ let found: string | undefined;193+ for (const rawLine of contents.split(/\r?\n/u)) {194+ const line = rawLine.trim().replace(/^@+/u, "").trim();195+ if (line.length === 0 || /^(?:rem\b|::)/iu.test(line) || BATCH_IGNORABLE_LINE.test(line)) {196+ continue;197+ }198+ if (199+ BATCH_CONTROL_FLOW_LINE.test(line) ||200+ /^:[^:]/u.test(line) ||201+ (line.match(/"/g) ?? []).length % 2 !== 0 ||202+ /[&|<>()]/.test(line.replace(/"[^"]*"/g, ""))
- apps/server/src/provider/AntigravityInstallation.ts lines 176 to 176OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -144,0 +156,21 @@156+}157+158+function refersToAcpExecutable(value: string, executableName: string) {159+ const lower = value.trim().toLowerCase();160+ const name = executableName.toLowerCase();161+ return (162+ lower === name ||163+ lower.endsWith(`/${name}`) ||164+ lower.endsWith(`\\${name}`) ||165+ lower.endsWith(`%~dp0${name}`)166+ );167+}168+169+/** `%VAR%` / `!VAR!` paths are not expanded; only `%~dp0` is a proven location. */170+function isProvenLaunchPath(value: string, executableName: string) {171+ if (!refersToAcpExecutable(value, executableName)) return false;172+ return !/[%!]/u.test(value.replace(/%~dp0/giu, ""));173+}174+175+const BATCH_IGNORABLE_LINE =176+ /^(?:echo(?:\.|\s+.*)?|set(?:local)?\b.*|endlocal\b.*|(?:cd|chdir|pushd|popd)\b.*|(?:title|chcp|cls|color)\b.*)$/iu;
- apps/server/src/provider/AntigravityInstallation.ts lines 176 to 176OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -144,0 +156,21 @@156+}157+158+function refersToAcpExecutable(value: string, executableName: string) {159+ const lower = value.trim().toLowerCase();160+ const name = executableName.toLowerCase();161+ return (162+ lower === name ||163+ lower.endsWith(`/${name}`) ||164+ lower.endsWith(`\\${name}`) ||165+ lower.endsWith(`%~dp0${name}`)166+ );167+}168+169+/** `%VAR%` / `!VAR!` paths are not expanded; only `%~dp0` is a proven location. */170+function isProvenLaunchPath(value: string, executableName: string) {171+ if (!refersToAcpExecutable(value, executableName)) return false;172+ return !/[%!]/u.test(value.replace(/%~dp0/giu, ""));173+}174+175+const BATCH_IGNORABLE_LINE =176+ /^(?:echo(?:\.|\s+.*)?|set(?:local)?\b.*|endlocal\b.*|(?:cd|chdir|pushd|popd)\b.*|(?:title|chcp|cls|color)\b.*|exit\s+\/b\b.*)$/iu;
- apps/server/src/provider/AntigravityInstallation.ts line 176OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -144,0 +156,21 @@156+}157+158+function refersToAcpExecutable(value: string, executableName: string) {159+ const lower = value.trim().toLowerCase();160+ const name = executableName.toLowerCase();161+ return (162+ lower === name ||163+ lower.endsWith(`/${name}`) ||164+ lower.endsWith(`\\${name}`) ||165+ lower.endsWith(`%~dp0${name}`)166+ );167+}168+169+/** `%VAR%` / `!VAR!` paths are not expanded; only `%~dp0` is a proven location. */170+function isProvenLaunchPath(value: string, executableName: string) {171+ if (!refersToAcpExecutable(value, executableName)) return false;172+ return !/[%!]/u.test(value.replace(/%~dp0/giu, ""));173+}174+175+const BATCH_IGNORABLE_LINE =176+ /^(?:echo(?:\.|\s+.*)?|set(?:local)?\b.*|endlocal\b.*|(?:cd|chdir|pushd|popd)\b.*|(?:title|chcp|cls|color)\b.*|exit\s+\/b\b.*)$/iu;
juliusmarminge added labelsmacroscope-review
maria-rcks closed this
maria-rcks reopened this
maria-rcks closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed