@devries-cameron20 / t3code Mirror · read-only / commits / 86b5734cfc
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

fix(server): Windows .cmd launchers work as the Antigravity binary path (#24683)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Victor committed Nov 19, 2026 at 01:31 UTC 86b5734cfc46db8e663d6d74f39b184c14101746
3 files changed +168 -3
apps/server/src/provider/AntigravityInstallation.test.ts
+124
@@ -1,4 +1,5 @@
1 import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2 +import * as NodePath from "@effect/platform-node/NodePath";
3 import * as NodeServices from "@effect/platform-node/NodeServices";
4 import * as Layer from "effect/Layer";
5 import { expect, it } from "@effect/vitest";
@@ -1213,6 +1214,129 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("Antigravity inst
1214 }),
1215 );
1216
1217 + it.effect("pairs a Windows launcher script with the helper beside the executable it runs", () =>
1218 + Effect.gen(function* () {
1219 + const fs = yield* FileSystem.FileSystem;
1220 + const path = yield* Path.Path;
1221 + const baseDir = yield* fs
1222 + .makeTempDirectoryScoped({ prefix: "t3-agy-launcher-$$-test-" })
1223 + .pipe(Effect.flatMap((directory) => fs.realPath(directory)));
1224 + const runtimeDirectory = path.join(baseDir, "runtime (x64)");
1225 + const launcherDirectory = path.join(baseDir, "launchers");
1226 + const runtimeExecutable = path.join(runtimeDirectory, "agy_acp_server.exe");
1227 + const runtimeHarness = path.join(runtimeDirectory, "localharness_external.exe");
1228 + yield* fs.makeDirectory(runtimeDirectory);
1229 + yield* fs.makeDirectory(launcherDirectory);
1230 + yield* fs.writeFileString(runtimeExecutable, "external server");
1231 + yield* fs.writeFileString(runtimeHarness, "external harness");
1232 + const { installation } = yield* makeHarness({ baseDir, platform: "win32", previous: true });
1233 + const writeLauncher = Effect.fn("test.writeAntigravityLauncher")(function* (
1234 + name: string,
1235 + launch: string,
1236 + ) {
1237 + const launcher = path.join(launcherDirectory, name);
1238 + yield* fs.writeFileString(
1239 + launcher,
1240 + `@echo off\r\nrem Runtime launcher\r\n:: Keep environment setup\r\nset AGY_EXTRA=1\r\n${launch} %*\r\nexit /b\r\n`,
1241 + );
1242 + return launcher;
1243 + });
1244 +
1245 + const absolute = yield* writeLauncher("agy.cmd", `"${runtimeExecutable}"`);
1246 + expect(yield* installation.resolve(absolute)).toMatchObject({
1247 + executablePath: absolute,
1248 + harnessPath: runtimeHarness,
1249 + source: "override",
1250 + managedVersionDirectory: null,
1251 + });
1252 + const quoted = yield* writeLauncher(
1253 + "quoted.cmd",
1254 + `set "PATH=C:\\Program Files (x86)\\SDK;%PATH%"\r\n"${runtimeExecutable}"`,
1255 + );
1256 + expect(yield* installation.resolve(quoted)).toMatchObject({
1257 + executablePath: quoted,
1258 + harnessPath: runtimeHarness,
1259 + });
1260 + const relative = yield* writeLauncher(
1261 + "relative.BAT",
1262 + `"%~dp0../runtime (x64)/agy_acp_server.exe"`,
1263 + );
1264 + expect(yield* installation.resolve(relative)).toMatchObject({
1265 + executablePath: relative,
1266 + harnessPath: runtimeHarness,
1267 + });
1268 +
1269 + const managed = yield* installation.resolve();
1270 + const intoManaged = yield* writeLauncher("managed.cmd", `"${managed.executablePath}"`);
1271 + expect(yield* installation.resolve(intoManaged)).toMatchObject({
1272 + executablePath: intoManaged,
1273 + harnessPath: managed.harnessPath,
1274 + version: previousVersion,
1275 + managedVersionDirectory: managed.managedVersionDirectory,
1276 + });
1277 + expect(yield* installation.remove([intoManaged]).pipe(Effect.flip)).toMatchObject({
1278 + operation: "remove",
1279 + });
1280 +
1281 + const ambiguous = yield* writeLauncher(
1282 + "ambiguous.cmd",
1283 + `"${managed.executablePath}" --version\r\n"${runtimeExecutable}"`,
1284 + );
1285 + expect(yield* installation.resolve(ambiguous).pipe(Effect.flip)).toMatchObject({
1286 + operation: "resolve",
1287 + });
1288 +
1289 + for (const [name, launch] of [
1290 + ["comment.cmd", `rem Previous runtime: "${runtimeExecutable}"\r\n"%AGY_TARGET%"`],
1291 + ["label-comment.cmd", `:: "${runtimeExecutable}"\r\n"%AGY_TARGET%"`],
1292 + ["echo.cmd", `echo "${runtimeExecutable}"`],
1293 + [
1294 + "conditional.cmd",
1295 + `if defined AGY_TARGET "%AGY_TARGET%" %* & exit /b\r\n"${runtimeExecutable}"`,
1296 + ],
1297 + ["early-exit.cmd", `exit /b\r\n"${runtimeExecutable}"`],
1298 + ["continued-set.cmd", `set IGNORED=1^\r\n"${runtimeExecutable}"`],
1299 + [
1300 + "chained-comment.cmd",
1301 + `rem setup & "${managed.executablePath}"\r\n"${runtimeExecutable}"`,
1302 + ],
1303 + ["chained.cmd", `"${runtimeExecutable}" --version && "%AGY_TARGET%"`],
1304 + ["unquoted-parens.cmd", `set PATH=C:\\Program Files (x86)\\SDK\r\n"${runtimeExecutable}"`],
1305 + [
1306 + "quoted-chained.cmd",
1307 + `set "PATH=C:\\Program Files (x86)" & "${managed.executablePath}"\r\n"${runtimeExecutable}"`,
1308 + ],
1309 + ["quoted-redirect.cmd", `set "AGY_MODE=1" > nul\r\n"${runtimeExecutable}"`],
1310 + ["quoted-block.cmd", `(set "AGY_MODE=1")\r\n"${runtimeExecutable}"`],
1311 + ["quoted-expansion.cmd", `set Q="\r\nset "X=%Q%&exit /b&rem ()"\r\n"${runtimeExecutable}"`],
1312 + ] as const) {
1313 + const uncertain = yield* writeLauncher(name, launch);
1314 + expect(yield* installation.resolve(uncertain).pipe(Effect.flip)).toMatchObject({
1315 + operation: "resolve",
1316 + });
1317 + }
1318 +
1319 + const win32 = yield* Path.Path.pipe(Effect.provide(NodePath.layerWin32));
1320 + const serverOnC: Path.Path = {
1321 + ...win32,
1322 + resolve: (...segments) => win32.resolve("C:\\t3", ...segments),
1323 + };
1324 + const launcherOnD = "D:\\launchers\\agy.cmd";
1325 + for (const [written, expected] of [
1326 + ["\\runtime\\agy_acp_server.exe", null],
1327 + ["C:runtime\\agy_acp_server.exe", null],
1328 + ["%~dp0runtime\\agy_acp_server.exe", "D:\\launchers\\runtime\\agy_acp_server.exe"],
1329 + ["\\\\server\\share\\agy_acp_server.exe", "\\\\server\\share\\agy_acp_server.exe"],
1330 + ["D:/runtime/agy_acp_server.exe", "D:\\runtime\\agy_acp_server.exe"],
1331 + ["//server/share/agy_acp_server.exe", "\\\\server\\share\\agy_acp_server.exe"],
1332 + ] as const) {
1333 + expect(AntigravityInstallation.launcherTargetPath(serverOnC, launcherOnD, written)).toBe(
1334 + expected,
1335 + );
1336 + }
1337 + }),
1338 + );
1339 +
1340 it.effect("keeps leased releases available while new sessions resolve the new release", () =>
1341 Effect.gen(function* () {
1342 const manifestEntered = yield* Deferred.make<void>();
apps/server/src/provider/AntigravityInstallation.ts
+41 -3
@@ -59,9 +59,22 @@ const UPDATE_CHECK_INTERVAL = 60 * 60 * 1000;
59 const FREE_SPACE_MARGIN = 256 * 1024 * 1024;
60 const RECORD_MAX_BYTES = 8 * 1024;
61 const RELEASE_RECORD = ".install-complete.json";
62 +const LAUNCHER_SETUP =
63 + /^[\s@]*(?:|::[^&|<>]*|rem(?:\s[^&|<>]*|$)|set\s+"[^"=&|<>]+=[^"&|<>]*"\s*|(?:echo|set|setlocal|endlocal)(?:\s[^&|<>()]*)?)$/iu;
64 +const LAUNCHER_COMMAND =
65 + /^[\s@]*(?:"([^"]*agy_acp_server\.exe)"|([^\s"&|<>()@]*agy_acp_server\.exe))(?:\s[^&|<>()]*)?$/iu;
66 const LARGE_PAGE_KERNEL_MESSAGE =
67 "Google's linux-arm64 Antigravity runtime needs a kernel with 4 KiB memory pages, and this kernel uses larger pages (as on Asahi Linux or Raspberry Pi 5). Use a remote environment or a custom Antigravity executable.";
68
69 +// The launcher runs in the project directory, so a target like `\x\agy_acp_server.exe`
70 +// whose drive comes from the working directory may not be the file resolved here.
71 +export const launcherTargetPath = (path: Path.Path, launcher: string, written: string) => {
72 + const target = written.replace(/%~dp0/giu, () => `${path.dirname(launcher)}${path.sep}`);
73 + if (/[%!]/u.test(target)) return null;
74 + const resolved = path.resolve(target);
75 + return path.parse(path.normalize(target)).root === path.parse(resolved).root ? resolved : null;
76 +};
77 +
78 const ReleaseId = Schema.String.check(Schema.isPattern(/^[a-f0-9]{64}$/u));
79 const ActiveRelease = Schema.Struct({ releaseId: ReleaseId });
80 const InstalledRelease = Schema.Struct({
@@ -321,24 +334,49 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
334 } satisfies AntigravityExecutable;
335 });
336
337 + // Infer helper pairing only from a plain launcher with one literal executable path.
338 + const launcherTarget = Effect.fn("AntigravityInstallation.launcherTarget")(function* (
339 + launcher: string,
340 + ) {
341 + if (platform !== "win32" || !/\.(?:bat|cmd)$/iu.test(launcher)) return null;
342 + const contents = yield* fs.readFileString(launcher);
343 + const targets = new Set<string>();
344 + for (const line of contents.split(/\r?\n/u)) {
345 + if (line.includes("^")) return null;
346 + if (/^[\s@]*exit(?:\s+\/b)?(?:\s+-?\d+)?\s*$/iu.test(line)) break;
347 + if (LAUNCHER_SETUP.test(line)) continue;
348 + const match = LAUNCHER_COMMAND.exec(line);
349 + if (!match) return null;
350 + const target = launcherTargetPath(path, launcher, match[1] ?? match[2] ?? "");
351 + if (target === null) return null;
352 + targets.add(target);
353 + }
354 + const [target] = targets;
355 + if (targets.size !== 1 || !target || !(yield* executableFile(target))) return null;
356 + return yield* fs.realPath(target);
357 + });
358 +
359 const fromExternal = Effect.fn("AntigravityInstallation.fromExternal")(function* (
360 candidate: string,
361 source: "override" | "path",
362 ) {
363 if (!(yield* executableFile(candidate))) return null;
364 const executablePath = yield* fs.realPath(candidate);
365 + const launched = yield* launcherTarget(executablePath);
366 const realVersions = yield* fs.realPath(versionsDirectory).pipe(Effect.option);
331 - const directory = path.dirname(executablePath);
367 + const directory = path.dirname(launched ?? executablePath);
368 if (
369 Option.isSome(realVersions) &&
370 path.dirname(directory) === realVersions.value &&
371 /^[a-f0-9]{64}$/u.test(path.basename(directory))
372 ) {
373 const installed = yield* completedRelease(path.basename(directory));
338 - return { ...installed, source };
374 + return launched === null
375 + ? { ...installed, source }
376 + : { ...installed, executablePath, source };
377 }
378 // Keep launcher symlinks intact: version-manager shims dispatch by their invoked name.
341 - if (isAntigravityCli(candidate, executablePath)) {
379 + if (launched === null && isAntigravityCli(candidate, executablePath)) {
380 return {
381 executablePath: candidate,
382 harnessPath: null,
docs/user/providers-antigravity.md
+3
@@ -61,6 +61,9 @@ Install [Antigravity CLI](https://antigravity.google/docs/getting-started) on th
61 Set **Binary path** to its `agy` executable and update it yourself.
62 Leave the field blank to use the managed runtime, or a compatible executable on
63 `PATH` if no managed runtime is installed.
64 +On Windows, **Binary path** can also be a `.cmd` or `.bat` script that only sets
65 +variables and then runs `agy_acp_server.exe` by its full path or a `%~dp0`-relative
66 +path; keep `localharness_external.exe` beside that executable.
67
68 ## Update the managed runtime
69