@devries-cameron20 / t3code-1 / commits / 944d1820e2
Fork 0

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

fix(server): Antigravity Google sign-in shows its link with the native CLI (#38953)

Julius Marminge committed Nov 19, 2026 at 15:41 UTC 944d1820e2b797fd1369f81035a13746b02a99de
6 files changed +361 -30
apps/server/src/provider/AntigravityAuth.test.ts
+57
@@ -27,6 +27,8 @@ const otherOwner = "t3-auth-session-other";
27 const authorizationUrl =
28 "https://accounts.google.com/o/oauth2/v2/auth?response_type=code&redirect_uri=http%3A%2F%2F127.0.0.1%3A51234%2F&state=test-state";
29 const callbackUrl = "http://127.0.0.1:51234/?state=test-state&code=test-code";
30 +const loginUrl =
31 + "https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=https%3A%2F%2Fantigravity.google%2Foauth-callback&state=login-state";
32
33 const initialized = {
34 protocolVersion: 1,
@@ -60,8 +62,11 @@ const makeHarness = Effect.fn("makeAuthTestHarness")(function* (
62 readonly supportsLogout?: boolean;
63 readonly beforeInitialize?: Effect.Effect<void>;
64 readonly forwardCallback?: Effect.Effect<void, ProviderSetupError>;
65 + readonly codeLogin?: boolean;
66 } = {},
67 ) {
68 + const loginCodes: string[] = [];
69 + const loginCode = yield* Deferred.make<void>();
70 const authenticated = yield* Deferred.make<void, AcpErrors.AcpError>();
71 const discovered = yield* Deferred.make<void, AcpErrors.AcpError>();
72 const closed = yield* Deferred.make<void>();
@@ -132,6 +137,21 @@ const makeHarness = Effect.fn("makeAuthTestHarness")(function* (
137 Effect.sync(() => {
138 forwarded += 1;
139 }),
140 + codeLogin: ({ onAuthorizationUrl }) =>
141 + Effect.gen(function* () {
142 + if (!options.codeLogin) return undefined;
143 + events.push("login-open");
144 + yield* Effect.addFinalizer(() => Effect.sync(() => events.push("login-close")));
145 + yield* onAuthorizationUrl(loginUrl);
146 + return {
147 + submit: (response: string) =>
148 + Effect.sync(() => loginCodes.push(response)).pipe(
149 + Effect.andThen(Deferred.succeed(loginCode, undefined)),
150 + Effect.asVoid,
151 + ),
152 + completed: Deferred.await(loginCode),
153 + };
154 + }),
155 });
156 return {
157 auth,
@@ -142,6 +162,7 @@ const makeHarness = Effect.fn("makeAuthTestHarness")(function* (
162 events,
163 catalog: () => catalog,
164 forwarded: () => forwarded,
165 + loginCodes,
166 receiveAuthorizationUrl: (url: string) =>
167 Effect.suspend(() =>
168 receiveAuthorizationUrl
@@ -170,6 +191,42 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("AntigravityAuth"
191 }),
192 );
193
194 + it.effect("signs in through the CLI's code login, then authenticates a fresh process", () =>
195 + Effect.gen(function* () {
196 + const harness = yield* makeHarness({ codeLogin: true });
197 + const state = yield* harness.auth.controller.start(owner);
198 + const waiting = yield* phase(harness.auth, "waiting");
199 + assert.equal(waiting.authorizationUrl, loginUrl);
200 + assert.equal(waiting.interaction?.type, "credentials");
201 + const respond = (code: string) =>
202 + harness.auth.controller.respond!(owner, {
203 + instanceId,
204 + flowId: state.flowId!,
205 + interactionId: state.flowId!,
206 + response: { type: "credentials", values: { code } },
207 + });
208 + for (const invalid of [callbackUrl, "two words", ""]) {
209 + assert.isTrue(Exit.isFailure(yield* respond(invalid).pipe(Effect.exit)), invalid);
210 + }
211 + assert.equal((yield* respond("4/0Ab-code")).phase, "verifying");
212 + assert.deepEqual(harness.loginCodes, ["4/0Ab-code"]);
213 +
214 + yield* Deferred.succeed(harness.authenticated, undefined);
215 + yield* Deferred.succeed(harness.discovered, undefined);
216 + yield* phase(harness.auth, "succeeded");
217 + assert.deepEqual(harness.events, [
218 + "login-open",
219 + "login-close",
220 + "process-open",
221 + "initialize",
222 + "authenticate",
223 + "session-new",
224 + "catalog-published",
225 + "process-close",
226 + ]);
227 + }),
228 + );
229 +
230 it.effect("rejects a different second authorization URL", () =>
231 Effect.gen(function* () {
232 const harness = yield* makeHarness({
apps/server/src/provider/AntigravityAuth.ts
+107 -14
@@ -21,6 +21,7 @@ import * as AcpErrors from "effect-acp/errors";
21
22 import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
23 import {
24 + antigravityLoginResponse,
25 parseAntigravityAuthorizationUrl,
26 type AntigravityAuthorizationUrl,
27 } from "./antigravityAuthSupport.ts";
@@ -45,6 +46,7 @@ const NO_RESPONSE_MESSAGE =
46 const UNREACHABLE_MESSAGE =
47 "Antigravity could not reach Google. Check this machine's network connection, then start sign-in again.";
48 const FORWARDING_FAILED_MESSAGE = "Could not deliver the sign-in response. Start sign-in again.";
49 +const LOGIN_CODE_FIELD = "code";
50 const isSetupError = Schema.is(ProviderSetupError);
51 const isAcpRequestError = Schema.is(AcpErrors.AcpRequestError);
52 const isAcpProcessExitedError = Schema.is(AcpErrors.AcpProcessExitedError);
@@ -52,6 +54,7 @@ const isAcpProcessExitedError = Schema.is(AcpErrors.AcpProcessExitedError);
54 interface AuthSnapshot {
55 readonly ownerSessionId: string | null;
56 readonly state: ProviderAuthState;
57 + readonly codeLogin?: boolean;
58 }
59
60 interface AuthFlow {
@@ -62,6 +65,8 @@ interface AuthFlow {
65 pending: AntigravityAuthorizationUrl | undefined;
66 initialized: boolean;
67 callbackSent: boolean;
68 + codeLogin: boolean;
69 + submitCode: ((response: string) => Effect.Effect<void>) | undefined;
70 fiber: Fiber.Fiber<void> | undefined;
71 forwarding: Fiber.Fiber<void, ProviderSetupError> | undefined;
72 }
@@ -79,6 +84,13 @@ export interface AntigravityAuth {
84 ) => Effect.Effect<A, E | ProviderSetupError, R | Scope.Scope>;
85 }
86
87 +/** `agy acp --login`: it prints a Google link and reads the code the Antigravity page shows. */
88 +export interface AntigravityCodeLogin {
89 + readonly submit: (response: string) => Effect.Effect<void>;
90 + /** Succeeds once the runtime has stored the sign-in. */
91 + readonly completed: Effect.Effect<void, ProviderSetupError>;
92 +}
93 +
94 export type AntigravityAuthRuntime = Pick<
95 AcpSessionRuntime.AcpSessionRuntime["Service"],
96 "initialize" | "start" | "request"
@@ -98,6 +110,14 @@ export interface AntigravityAuthOptions<
110 readonly onSignedOut: Effect.Effect<void>;
111 readonly forwardCallback?: (callback: URL) => Effect.Effect<void, ProviderSetupError>;
112 readonly usesBrowser?: boolean;
113 + /** Undefined when the runtime signs in through ACP `authenticate` and T3's browser helper. */
114 + readonly codeLogin?: (input: {
115 + readonly onAuthorizationUrl: (url: string) => Effect.Effect<void, AcpErrors.AcpError>;
116 + }) => Effect.Effect<
117 + AntigravityCodeLogin | undefined,
118 + AcpErrors.AcpError | ProviderSetupError,
119 + Scope.Scope
120 + >;
121 }
122
123 function visibleSnapshot(snapshot: AuthSnapshot, ownerSessionId: string): ProviderAuthState {
@@ -185,7 +205,11 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* <
205 );
206 const publishFlow = (flow: AuthFlow, state: ProviderAuthState) => {
207 flow.state = state;
188 - return SubscriptionRef.set(snapshot, { ownerSessionId: flow.ownerSessionId, state });
208 + return SubscriptionRef.set(snapshot, {
209 + ownerSessionId: flow.ownerSessionId,
210 + state,
211 + codeLogin: flow.codeLogin,
212 + });
213 };
214 const stopOwnedProcesses = Effect.suspend(() =>
215 Effect.forEach(
@@ -260,8 +284,8 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* <
284 }),
285 );
286
263 - const receiveAuthorizationUrl = (flow: AuthFlow, url: string) =>
264 - parseAntigravityAuthorizationUrl(url).pipe(
287 + const receiveAuthorizationUrl = (flow: AuthFlow, url: string, redirect: "loopback" | "code") =>
288 + parseAntigravityAuthorizationUrl(url, redirect).pipe(
289 Effect.flatMap((authorization) =>
290 lock.withPermits(1)(
291 Effect.gen(function* () {
@@ -274,12 +298,15 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* <
298 });
299 }
300 flow.pending = authorization;
301 + flow.codeLogin = redirect === "code";
302 yield* publishFlow(flow, {
303 ...flow.state,
304 phase: "waiting",
305 authorizationUrl: authorization.authorizationUrl,
306 message:
282 - "Open the Google sign-in link. If you are remote, paste the redirect URL here.",
307 + redirect === "loopback"
308 + ? "Open the Google sign-in link. If you are remote, paste the redirect URL here."
309 + : "Open the Google sign-in link, then paste the code from the Antigravity page here.",
310 });
311 }),
312 ),
@@ -302,9 +329,24 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* <
329 const runSignIn = Effect.fn("AntigravityAuth.runSignIn")(
330 function* (flow: AuthFlow, stopSessions: Effect.Effect<void, ProviderSetupError>) {
331 yield* stopSessions.pipe(Effect.ensuring(stopOwnedProcesses));
305 - const runtime = yield* options.makeRuntime({
306 - onAuthorizationUrl: (url) => receiveAuthorizationUrl(flow, url),
307 - });
332 + const signedIn = yield* Effect.scoped(
333 + Effect.gen(function* () {
334 + const login = yield* (
335 + options.codeLogin?.({
336 + onAuthorizationUrl: (url) => receiveAuthorizationUrl(flow, url, "code"),
337 + }) ?? Effect.undefined
338 + );
339 + if (login === undefined) return false;
340 + flow.submitCode = login.submit;
341 + yield* login.completed;
342 + return true;
343 + }),
344 + );
345 + const runtime = yield* options.makeRuntime(
346 + signedIn
347 + ? {}
348 + : { onAuthorizationUrl: (url) => receiveAuthorizationUrl(flow, url, "loopback") },
349 + );
350 const startupHint = yield* publishStartingHint(flow, STARTUP_HINT_MS, NOT_STARTED_MESSAGE);
351 // `start` reuses this memoized handshake.
352 yield* runtime.initialize();
@@ -428,6 +470,8 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* <
470 pending: undefined,
471 initialized: false,
472 callbackSent: false,
473 + codeLogin: false,
474 + submitCode: undefined,
475 fiber: undefined,
476 forwarding: undefined,
477 };
@@ -489,6 +533,43 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* <
533 }
534 return pending.flow.state;
535 }),
536 + respond: Effect.fn("AntigravityAuth.respond")(function* (ownerSessionId, input) {
537 + return yield* lock.withPermits(1)(
538 + Effect.gen(function* () {
539 + const flow = yield* requireFlow(ownerSessionId, input.flowId, "respond");
540 + if (!flow.pending || !flow.submitCode || flow.callbackSent) {
541 + return yield* setupError(
542 + "respond",
543 + flow.callbackSent
544 + ? "The sign-in response was already sent. Wait for Google to finish."
545 + : "Wait for the Google sign-in link before you send a code.",
546 + );
547 + }
548 + const response =
549 + input.interactionId === flow.id && input.response.type === "credentials"
550 + ? antigravityLoginResponse(
551 + flow.pending,
552 + input.response.values[LOGIN_CODE_FIELD] ?? "",
553 + )
554 + : undefined;
555 + if (response === undefined) {
556 + return yield* setupError(
557 + "respond",
558 + "Paste the code from the Antigravity page, or that page's full URL.",
559 + );
560 + }
561 + flow.callbackSent = true;
562 + yield* flow.submitCode(response);
563 + yield* publishFlow(flow, {
564 + ...flow.state,
565 + phase: "verifying",
566 + authorizationUrl: null,
567 + message: "Waiting for Google to finish sign-in.",
568 + });
569 + return flow.state;
570 + }),
571 + );
572 + }),
573 cancel: Effect.fn("AntigravityAuth.cancel")(function* (ownerSessionId, flowId) {
574 const flow = yield* lock.withPermits(1)(requireFlow(ownerSessionId, flowId, "cancel"));
575 yield* stopFlow(flow, "cancelled", "Google sign-in was cancelled.");
@@ -580,13 +661,25 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* <
661 credentialOwner: "provider" as const,
662 interaction:
663 state.phase === "waiting" && state.authorizationUrl && state.flowId
583 - ? {
584 - type: "browser" as const,
585 - id: state.flowId,
586 - url: state.authorizationUrl,
587 - requiresConsent: false,
588 - acceptsCallback: true,
589 - }
664 + ? value.codeLogin
665 + ? {
666 + type: "credentials" as const,
667 + id: state.flowId,
668 + fields: [
669 + {
670 + name: LOGIN_CODE_FIELD,
671 + label: "Code from the Antigravity page",
672 + secret: false,
673 + },
674 + ],
675 + }
676 + : {
677 + type: "browser" as const,
678 + id: state.flowId,
679 + url: state.authorizationUrl,
680 + requiresConsent: false,
681 + acceptsCallback: true,
682 + }
683 : null,
684 };
685 }),
apps/server/src/provider/Drivers/AntigravityDriver.ts
+115 -13
@@ -16,11 +16,14 @@ import * as SecureRandom from "effect/crypto/SecureRandom";
16 import * as Deferred from "effect/Deferred";
17 import * as Effect from "effect/Effect";
18 import * as Exit from "effect/Exit";
19 +import * as Fiber from "effect/Fiber";
20 import * as FileSystem from "effect/FileSystem";
21 +import * as Option from "effect/Option";
22 import * as Path from "effect/Path";
23 import * as Schema from "effect/Schema";
24 import * as Scope from "effect/Scope";
25 import * as Stream from "effect/Stream";
26 +import * as ChildProcess from "effect/process/ChildProcess";
27 import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
28 import { HttpClient } from "effect/http";
29 import * as AcpErrors from "effect-acp/errors";
@@ -200,10 +203,14 @@ export const AntigravityDriver: ProviderDriver<
203 Effect.map((catalog) => stampIdentity(ModelCatalog.applyModelCatalog(draft, catalog))),
204 );
205
203 - const makeRuntime = Effect.fn("AntigravityDriver.makeRuntime")(function* (
204 - input: AntigravityAdapterV2RuntimeInput,
206 + const prepareSpawn = Effect.fn("AntigravityDriver.prepareSpawn")(function* (
207 + cwd: string,
208 + baseEnv: NodeJS.ProcessEnv,
209 ): Effect.fn.Return<
206 - AcpSessionRuntime.AcpSessionRuntime["Service"],
210 + {
211 + readonly executable: AntigravityInstallation.AntigravityExecutable;
212 + readonly spawn: AcpSessionRuntime.AcpSpawnInput;
213 + },
214 AcpErrors.AcpError | ProviderSetupError,
215 Scope.Scope
216 > {
@@ -270,26 +277,41 @@ export const AntigravityDriver: ProviderDriver<
277 ),
278 ),
279 );
280 + return {
281 + executable,
282 + spawn: buildAntigravityAcpSpawnInput({
283 + installation: executable,
284 + profile,
285 + cwd,
286 + baseEnv,
287 + auth,
288 + runtimeTempDirectory,
289 + }),
290 + };
291 + });
292 +
293 + const makeRuntime = Effect.fn("AntigravityDriver.makeRuntime")(function* (
294 + input: AntigravityAdapterV2RuntimeInput,
295 + ): Effect.fn.Return<
296 + AcpSessionRuntime.AcpSessionRuntime["Service"],
297 + AcpErrors.AcpError | ProviderSetupError,
298 + Scope.Scope
299 + > {
300 // `buildAntigravityAcpSpawnInput` sets `extendEnv: false`, so thread variables only reach the
301 // agent's shell through `baseEnv`.
302 const { processEnvironment: threadEnvironment, ...runtimeInput } = input;
276 - const spawnEnvironment =
303 + const { executable, spawn } = yield* prepareSpawn(
304 + runtimeInput.cwd,
305 threadEnvironment === undefined
306 ? processEnvironment
279 - : { ...processEnvironment, ...threadEnvironment };
307 + : { ...processEnvironment, ...threadEnvironment },
308 + );
309 const runtime = yield* makeAntigravityAcpRuntime({
310 ...runtimeInput,
311 runtimeVersion: executable.version,
312 authMethod: auth.authMethod,
313 childProcessSpawner: spawner,
285 - spawn: buildAntigravityAcpSpawnInput({
286 - installation: executable,
287 - profile,
288 - cwd: runtimeInput.cwd,
289 - baseEnv: spawnEnvironment,
290 - auth,
291 - runtimeTempDirectory,
292 - }),
314 + spawn,
315 }).pipe(Effect.provideService(SecureRandom.SecureRandom, random));
316 return {
317 ...runtime,
@@ -354,6 +376,85 @@ export const AntigravityDriver: ProviderDriver<
376 };
377 });
378
379 + // The agy CLI ignores T3's browser helper during ACP `authenticate`, so Google sign-in runs its
380 + // remote-friendly `--login`, which stores the sign-in where the ACP process reads it.
381 + const codeLogin = Effect.fn("AntigravityDriver.codeLogin")(function* (input: {
382 + readonly onAuthorizationUrl: (url: string) => Effect.Effect<void, AcpErrors.AcpError>;
383 + }) {
384 + if (auth.authMethod !== "oauth-personal") return undefined;
385 + const resolved = yield* installation
386 + .resolve(settings.binaryPath, processEnvironment)
387 + .pipe(Effect.option);
388 + if (Option.isSome(resolved) && resolved.value.harnessPath !== null) return undefined;
389 + const cwd = yield* fileSystem
390 + .makeTempDirectoryScoped({ prefix: "t3-antigravity-login-" })
391 + .pipe(
392 + Effect.mapError(
393 + () =>
394 + new ProviderSetupError({
395 + instanceId,
396 + operation: "start",
397 + detail: "Could not create an Antigravity setup workspace.",
398 + }),
399 + ),
400 + );
401 + const { executable, spawn } = yield* prepareSpawn(cwd, processEnvironment);
402 + if (executable.harnessPath !== null) return undefined;
403 + const failed = (detail: string, cause?: unknown) =>
404 + new ProviderSetupError({ instanceId, operation: "start", detail, cause });
405 + // Without a display it prints the link only, instead of opening a browser on this machine.
406 + const { DISPLAY: _display, WAYLAND_DISPLAY: _wayland, ...env } = spawn.env ?? {};
407 + const child = yield* spawner
408 + .spawn(
409 + ChildProcess.make(spawn.command, [...spawn.args, "--login"], {
410 + cwd,
411 + env,
412 + extendEnv: false,
413 + shell: false,
414 + }),
415 + )
416 + .pipe(Effect.mapError((cause) => failed("Could not start Antigravity sign-in.", cause)));
417 + const code = yield* Deferred.make<string>();
418 + yield* Stream.fromEffect(Deferred.await(code)).pipe(
419 + Stream.map((response) => `${response}\n`),
420 + Stream.encodeText,
421 + Stream.run(child.stdin),
422 + Effect.ignore,
423 + Effect.forkScoped,
424 + );
425 + const output = yield* child.stdout.pipe(
426 + Stream.decodeText(),
427 + Stream.splitLines,
428 + Stream.map((line) => line.trim()),
429 + Stream.runForEach((line) =>
430 + line.startsWith("https://accounts.google.com/")
431 + ? input.onAuthorizationUrl(line)
432 + : Effect.void,
433 + ),
434 + Effect.forkScoped,
435 + );
436 + yield* Stream.runDrain(child.stderr).pipe(Effect.ignore, Effect.forkScoped);
437 + return {
438 + submit: (response: string) => Deferred.succeed(code, response).pipe(Effect.asVoid),
439 + completed: Effect.gen(function* () {
440 + // Stdout closes when the process exits, or this fails first on an unusable link.
441 + yield* Fiber.join(output).pipe(
442 + Effect.mapError((cause) =>
443 + failed("Antigravity returned an invalid Google sign-in link.", cause),
444 + ),
445 + );
446 + const exitCode = yield* child.exitCode.pipe(
447 + Effect.mapError((cause) => failed("Antigravity sign-in stopped unexpectedly.", cause)),
448 + );
449 + if (Number(exitCode) !== 0) {
450 + return yield* failed(
451 + "Antigravity could not finish Google sign-in. Start sign-in again.",
452 + );
453 + }
454 + }),
455 + };
456 + });
457 +
458 const publishCatalog = Effect.fn("AntigravityDriver.publishCatalog")(function* (
459 started: AcpSessionRuntime.AcpSessionRuntimeStartResult,
460 runtime: Pick<
@@ -394,6 +495,7 @@ export const AntigravityDriver: ProviderDriver<
495 ),
496 onSignedOut: Effect.suspend(() => provider.onSignedOut),
497 usesBrowser: antigravityAuthUsesBrowser(auth.authMethod),
498 + codeLogin,
499 });
500
501 // The probe must not spawn. The agent is a PyInstaller one-file bundle
apps/server/src/provider/antigravityAuthSupport.test.ts
+41
@@ -30,6 +30,7 @@ import {
30 isAntigravitySignInRequiredError,
31 makeAntigravityStderrHandler,
32 makeAntigravityStdoutTransform,
33 + antigravityLoginResponse,
34 parseAntigravityAuthorizationUrl,
35 prepareAntigravityProfile,
36 resolveAntigravityInstanceDirectories,
@@ -272,6 +273,46 @@ describe("Antigravity authorization URL", () => {
273 );
274 });
275
276 +describe("Antigravity code sign-in", () => {
277 + const loginUrl =
278 + "https://accounts.google.com/o/oauth2/auth?access_type=offline&code_challenge_method=S256&redirect_uri=https%3A%2F%2Fantigravity.google%2Foauth-callback&response_type=code&state=login-state";
279 +
280 + it.effect("accepts the agy CLI's link and only a code or page URL for that sign-in", () =>
281 + Effect.gen(function* () {
282 + const pending = yield* parseAntigravityAuthorizationUrl(loginUrl, "code");
283 + expect(pending.redirectUri).toBe("https://antigravity.google/oauth-callback");
284 + for (const other of [
285 + loginUrl.replace("antigravity.google", "antigravity.google.example.invalid"),
286 + loginUrl.replace("/o/oauth2/auth", "/o/oauth2/v2/auth"),
287 + ]) {
288 + expect(
289 + Result.isFailure(
290 + yield* parseAntigravityAuthorizationUrl(other, "code").pipe(Effect.result),
291 + ),
292 + ).toBe(true);
293 + }
294 + expect(
295 + Result.isFailure(yield* parseAntigravityAuthorizationUrl(loginUrl).pipe(Effect.result)),
296 + ).toBe(true);
297 +
298 + const page = "https://antigravity.google/oauth-callback?state=login-state&code=4%2F0Ab-c";
299 + expect(antigravityLoginResponse(pending, " 4/0Ab-code_1.x~ ")).toBe("4/0Ab-code_1.x~");
300 + expect(antigravityLoginResponse(pending, page)).toBe(page);
301 + for (const invalid of [
302 + "",
303 + "4/0Ab code",
304 + "4/0Ab\nsecond line",
305 + page.replace("login-state", "other-state"),
306 + page.replace("antigravity.google", "evil.example"),
307 + page.replace("&code=4%2F0Ab-c", ""),
308 + `${page}&code=again`,
309 + ]) {
310 + expect(antigravityLoginResponse(pending, invalid)).toBeUndefined();
311 + }
312 + }),
313 + );
314 +});
315 +
316 describe("Antigravity sign-in errors", () => {
317 it("recognizes native auth-required errors and the blocked-login transport error", () => {
318 expect(isAntigravitySignInRequiredError(AcpErrors.AcpRequestError.authRequired())).toBe(true);
apps/server/src/provider/antigravityAuthSupport.ts
+36 -2
@@ -499,9 +499,13 @@ export function buildAntigravityAcpSpawnInput(input: {
499 };
500 }
501
502 +/** Where `agy acp --login` sends Google; the page shows a code the user pastes back. */
503 +const ANTIGRAVITY_CODE_REDIRECT_URI = "https://antigravity.google/oauth-callback";
504 +
505 export const parseAntigravityAuthorizationUrl = Effect.fn("parseAntigravityAuthorizationUrl")(
506 function* (
507 authorizationUrl: string,
508 + kind: "loopback" | "code" = "loopback",
509 ): Effect.fn.Return<AntigravityAuthorizationUrl, AcpErrors.AcpError> {
510 const invalidUrl = () =>
511 authSupportError("Antigravity returned an invalid Google sign-in URL.");
@@ -513,7 +517,7 @@ export const parseAntigravityAuthorizationUrl = Effect.fn("parseAntigravityAutho
517 const redirectUri = url.searchParams.get("redirect_uri");
518 if (
519 url.origin !== "https://accounts.google.com" ||
516 - url.pathname !== "/o/oauth2/v2/auth" ||
520 + url.pathname !== (kind === "loopback" ? "/o/oauth2/v2/auth" : "/o/oauth2/auth") ||
521 url.username !== "" ||
522 url.password !== "" ||
523 url.hash !== "" ||
@@ -526,16 +530,46 @@ export const parseAntigravityAuthorizationUrl = Effect.fn("parseAntigravityAutho
530 state.length > 512 ||
531 /\s/.test(state) ||
532 redirectUri === null ||
529 - !/^http:\/\/127\.0\.0\.1:[1-9][0-9]{0,4}\/$/.test(redirectUri)
533 + (kind === "loopback"
534 + ? !/^http:\/\/127\.0\.0\.1:[1-9][0-9]{0,4}\/$/.test(redirectUri)
535 + : redirectUri !== ANTIGRAVITY_CODE_REDIRECT_URI)
536 ) {
537 return yield* invalidUrl();
538 }
539 + if (kind === "code") return { authorizationUrl, redirectUri, state };
540 const redirect = yield* decodeUrl(redirectUri).pipe(Effect.mapError(invalidUrl));
541 if (Number(redirect.port) < 1_024) return yield* invalidUrl();
542 return { authorizationUrl, redirectUri, state };
543 },
544 );
545
546 +/**
547 + * What `agy acp --login` reads after its link: the code the Antigravity page shows, or that page's
548 + * URL, which must answer this sign-in. Undefined for anything else, including any line break.
549 + */
550 +export function antigravityLoginResponse(
551 + pending: AntigravityAuthorizationUrl,
552 + response: string,
553 +): string | undefined {
554 + const value = response.trim();
555 + if (/^[\w./~-]{1,2048}$/.test(value)) return value;
556 + if (value.length > maxAuthorizationUrlLength || /\s/.test(value)) return undefined;
557 + const url = URL.parse(value);
558 + if (
559 + url === null ||
560 + `${url.origin}${url.pathname}` !== pending.redirectUri ||
561 + url.username !== "" ||
562 + url.password !== "" ||
563 + url.searchParams.getAll("state").length !== 1 ||
564 + url.searchParams.get("state") !== pending.state ||
565 + url.searchParams.getAll("code").length !== 1 ||
566 + !url.searchParams.get("code")
567 + ) {
568 + return undefined;
569 + }
570 + return value;
571 +}
572 +
573 export function makeAntigravityStdoutTransform(
574 input: {
575 readonly onAuthorizationUrl?: (
docs/user/providers-antigravity.md
+5 -1
@@ -18,7 +18,11 @@ Antigravity setup.
18
19 ### Sign in from a remote device
20
21 -Google returns to a `127.0.0.1` address. It can finish directly when your browser is
21 +With the native CLI, Google finishes on an Antigravity page that shows a code. Paste that
22 +code, or the page's full address, into the code field in the client where you started
23 +sign-in. This works the same from any device.
24 +
25 +With the older 1.4.5 runtime, Google returns to a `127.0.0.1` address. It can finish directly when your browser is
26 on the environment's machine. From another device, the final page will usually
27 fail to load because the sign-in listener is on the environment.
28