Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

antigravityAuthSupport.ts

607 lines22.0 KB

1// @effect-diagnostics-next-line nodeBuiltinImport:off - Effect's symlink has no type argument, and Windows needs a junction to link without elevation.
2import * as NodeFSP from "node:fs/promises";
3​
4import type { AntigravityAuthMethod, ProviderInstanceId } from "@t3tools/contracts";
5import * as HostProcess from "@t3tools/shared/HostProcess";
6import { resolveNodeExecutable, nodeRuntimeUnavailableMessage } from "@t3tools/shared/nodeRuntime";
7import * as Digest from "effect/crypto/Digest";
8import * as Effect from "effect/Effect";
9import * as Hex from "effect/encoding/Hex";
10import * as FileSystem from "effect/FileSystem";
11import * as Path from "effect/Path";
12import type * as PlatformError from "effect/PlatformError";
13import * as Schema from "effect/Schema";
14import * as Stream from "effect/Stream";
15import * as ChildProcess from "effect/process/ChildProcess";
16import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
17import * as AcpErrors from "effect-acp/errors";
18​
19import { collectUint8StreamText } from "@t3tools/provider-core/server/collectStreamText";
20import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
21import {
22 antigravityUserSkillDirectories,
23 resolveAntigravityUserHome,
24} from "./Drivers/AntigravitySkills.ts";
25​
26export const ANTIGRAVITY_AUTH_STDOUT_PREFIX =
27 "Open the following link to authenticate the ACP server: ";
28export const ANTIGRAVITY_AUTH_BROWSER_MARKER = "__T3_ANTIGRAVITY_AUTH_URL__";
29export const ANTIGRAVITY_SIGN_IN_REQUIRED_MESSAGE =
30 "Sign in to Antigravity in Settings before you continue.";
31​
32const maxAuthorizationUrlLength = 16_384;
33const maxBrowserHelperLineLength =
34 Math.max(ANTIGRAVITY_AUTH_BROWSER_MARKER.length, ANTIGRAVITY_AUTH_STDOUT_PREFIX.length) +
35 maxAuthorizationUrlLength +
36 2;
37const maxStdoutLineBytes = 16 * 1024 * 1024;
38const authPrefixBytes = new TextEncoder().encode(ANTIGRAVITY_AUTH_STDOUT_PREFIX);
39const decodeUrl = Schema.decodeUnknownEffect(Schema.URLFromString);
40const decodeBrowserHelperUrl = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.String));
41const ProfileSettingsFile = Schema.Struct({
42 auth: Schema.Struct({ type: Schema.String }),
43 gcp: Schema.optional(
44 Schema.Struct({
45 project: Schema.optional(Schema.String),
46 location: Schema.optional(Schema.String),
47 }),
48 ),
49});
50const encodeProfileSettings = Schema.encodeSync(Schema.fromJsonString(ProfileSettingsFile));
51const isAcpRequestError = Schema.is(AcpErrors.AcpRequestError);
52const isAcpTransportError = Schema.is(AcpErrors.AcpTransportError);
53​
54// Python splits BROWSER on path separators before parsing quotes. Exit 0 on EPIPE to prevent browser fallback after cancellation.
55const browserHelperSource =
56 `process.stderr.on("error",()=>process.exit(0)).write(` +
57 `"${ANTIGRAVITY_AUTH_BROWSER_MARKER}"+JSON.stringify(process.argv[1])+"\\n",` +
58 `()=>process.exit(0))`;
59const browserPreflightUrl = "https://example.invalid/t3-antigravity-browser-preflight";
60​
61const removedEnvironmentKeys = new Set([
62 "GEMINI_API_KEY",
63 "GOOGLE_API_KEY",
64 "GOOGLE_APPLICATION_CREDENTIALS",
65 "GOOGLE_CLOUD_PROJECT",
66 "GOOGLE_CLOUD_LOCATION",
67 "GOOGLE_CLOUD_QUOTA_PROJECT",
68 "GOOGLE_GENAI_USE_VERTEXAI",
69 "GCLOUD_PROJECT",
70 "CLOUDSDK_CORE_PROJECT",
71 "AGY_ACP_CCPA_PROJECT",
72 "AGY_ACP_ENABLE_OAUTH",
73 "GEMINI_HOME",
74 "AGY_ACP_FORCE_FILE_STORAGE",
75 "ANTIGRAVITY_HARNESS_PATH",
76 "BROWSER",
77 "PYTHONUNBUFFERED",
78 "ELECTRON_RUN_AS_NODE",
79]);
80​
81export interface AntigravityProfile {
82 readonly platform: NodeJS.Platform;
83 readonly geminiHome: string;
84 readonly acpDirectory: string;
85 readonly tokenPath: string;
86 readonly tempDirectory: string;
87 readonly browserCommand: string;
88 readonly caBundlePath?: string;
90​
91export interface AntigravityAuthConfig {
92 readonly authMethod: AntigravityAuthMethod;
93 readonly apiKey: string;
94 readonly gcpProject: string;
95 readonly gcpLocation: string;
97​
98const ANTIGRAVITY_PERSONAL_AUTH: AntigravityAuthConfig = {
99 authMethod: "oauth-personal",
100 apiKey: "",
101 gcpProject: "",
102 gcpLocation: "",
103};
104​
105export function antigravityAuthUsesBrowser(authMethod: AntigravityAuthMethod): boolean {
106 return authMethod === "oauth-personal" || authMethod === "oauth-business";
108​
109export function antigravityAuthLabel(authMethod: AntigravityAuthMethod): string {
110 switch (authMethod) {
111 case "oauth-personal":
112 return "Google account";
113 case "oauth-business":
114 return "Gemini Enterprise";
115 case "gemini-api-key":
116 return "Gemini API key";
117 case "agent-platform":
118 return "Agent Platform";
119 }
121​
122export function antigravityAuthConfigIssue(auth: AntigravityAuthConfig): string | null {
123 switch (auth.authMethod) {
124 case "oauth-personal":
125 return null;
126 case "oauth-business":
127 return auth.gcpProject && auth.gcpLocation
128 ? null
129 : "Gemini Enterprise needs a GCP project and location in the Antigravity provider settings.";
130 case "gemini-api-key":
131 return auth.apiKey ? null : "Enter a Gemini API key in the Antigravity provider settings.";
132 case "agent-platform":
133 return auth.apiKey || (auth.gcpProject && auth.gcpLocation)
134 ? null
135 : "Agent Platform needs an API key, or a GCP project and location, in the Antigravity provider settings.";
136 }
138​
139/**
140 * `auth.type` names the selected method so a native logout clears only that method's credentials
141 * instead of every stored token. Never holds a credential.
142 */
143function antigravityProfileSettings(auth: AntigravityAuthConfig): string {
144 const gcp = {
145 ...(auth.gcpProject ? { project: auth.gcpProject } : {}),
146 ...(auth.gcpLocation ? { location: auth.gcpLocation } : {}),
147 };
148 return `${encodeProfileSettings({
149 auth: { type: auth.authMethod },
150 ...(Object.keys(gcp).length > 0 ? { gcp } : {}),
151 })}\n`;
153​
154export interface AntigravityAuthorizationUrl {
155 readonly authorizationUrl: string;
156 readonly redirectUri: string;
157 readonly state: string;
159​
160function authSupportError(detail: string) {
161 return new AcpErrors.AcpTransportError({ detail, cause: undefined });
163​
164export function isAntigravitySignInRequiredError(error: unknown): boolean {
165 return (
166 (isAcpRequestError(error) && error.code === -32000) ||
167 (isAcpTransportError(error) && error.detail === ANTIGRAVITY_SIGN_IN_REQUIRED_MESSAGE)
168 );
170​
171export interface AntigravityInstanceDirectories {
172 readonly profile: string;
173 /** Keep beside the profile: 120-character archive members under its longer name would exceed Windows' 260-character limit. */
174 readonly runtimeTemp: string;
176​
177/** Hashes the instance ID so case-only differences stay separate on case-insensitive filesystems. */
178export const resolveAntigravityInstanceDirectories = Effect.fn(
179 "resolveAntigravityInstanceDirectories",
180)(function* (stateDir: string, instanceId: ProviderInstanceId) {
181 const digest = yield* Digest.Digest;
182 const path = yield* Path.Path;
183 const key = Hex.encode(yield* digest.digest(Digest.sha256, new TextEncoder().encode(instanceId)));
184 return {
185 profile: path.join(stateDir, "providers", "antigravity", key),
186 runtimeTemp: path.join(stateDir, "antigravity-tmp", key.slice(0, 12)),
187 } satisfies AntigravityInstanceDirectories;
188});
189​
190function quoteBrowserArgument(value: string): string {
191 return `'${value.replaceAll("'", `'"'"'`)}'`;
193​
194function antigravityEnvironment(
195 profile: AntigravityProfile,
196 baseEnv: NodeJS.ProcessEnv,
197 auth: AntigravityAuthConfig,
198 runtimeTempDirectory?: string,
199) {
200 const environment: NodeJS.ProcessEnv = {};
201 for (const [key, value] of Object.entries(baseEnv)) {
202 // Windows treats environment keys as case-insensitive. Remove aliases too.
203 if (!removedEnvironmentKeys.has(key.toUpperCase())) environment[key] = value;
204 }
205 // Put the GCP pair in settings.json because GOOGLE_API_KEY takes precedence in the environment.
206 const credential =
207 auth.authMethod === "gemini-api-key" && auth.apiKey
208 ? { GEMINI_API_KEY: auth.apiKey }
209 : auth.authMethod === "agent-platform" && auth.apiKey
210 ? { GOOGLE_API_KEY: auth.apiKey }
211 : {};
212 // Each launch unpacks about 1 GB; use T3-owned temp so the driver can reclaim files after force-kill.
213 const tempDirectory = runtimeTempDirectory ?? profile.tempDirectory;
214 return {
215 ...environment,
216 ...credential,
217 ...(profile.caBundlePath !== undefined &&
218 baseEnv.SSL_CERT_FILE === undefined &&
219 baseEnv.SSL_CERT_DIR === undefined
220 ? { SSL_CERT_FILE: profile.caBundlePath }
221 : {}),
222 GEMINI_HOME: profile.geminiHome,
223 AGY_ACP_FORCE_FILE_STORAGE: "1",
224 BROWSER: profile.browserCommand,
225 PYTHONUNBUFFERED: "1",
226 ELECTRON_RUN_AS_NODE: "1",
227 ...(profile.platform === "win32"
228 ? { TEMP: tempDirectory, TMP: tempDirectory }
229 : { TMPDIR: tempDirectory }),
230 };
232​
233/** Private GEMINI_HOME isolates credentials/hooks/MCP; link global skills from the real ~/.gemini. */
234const linkAntigravityUserSkills = Effect.fn("linkAntigravityUserSkills")(function* (input: {
235 readonly profileDirectory: string;
236 readonly userHome: string;
237 readonly platform: NodeJS.Platform;
238}): Effect.fn.Return<void, never, FileSystem.FileSystem | Path.Path> {
239 const fs = yield* FileSystem.FileSystem;
240 const path = yield* Path.Path;
241 const links = antigravityUserSkillDirectories(path, input.profileDirectory);
242 const targets = antigravityUserSkillDirectories(path, path.join(input.userHome, ".gemini"));
243 for (const [link, target] of [
244 [links[0], targets[0]],
245 [links[1], targets[1]],
246 ] as const) {
247 yield* Effect.gen(function* () {
248 // The harness creates these folders itself, and mkdir fails on a dangling link.
249 if (!(yield* fs.exists(target))) {
250 const linked = yield* fs.readLink(link).pipe(
251 Effect.as(true),
252 Effect.orElseSucceed(() => false),
253 );
254 if (linked) yield* fs.remove(link);
255 return;
256 }
257 const existing = yield* fs.readLink(link).pipe(
258 Effect.map((value): string | undefined => path.resolve(path.dirname(link), value)),
259 Effect.catchReason("PlatformError", "NotFound", () => Effect.undefined),
260 // An empty folder is the harness's placeholder from a launch without the link.
261 // rmdir refuses a non-empty folder, so content added meanwhile is never deleted.
262 Effect.catch((error) =>
263 Effect.tryPromise(() => NodeFSP.rmdir(link)).pipe(
264 Effect.as(undefined),
265 Effect.mapError(() => error),
266 ),
267 ),
268 );
269 if (existing === target) return;
270 if (existing !== undefined) {
271 yield* fs.remove(link);
272 }
273 yield* fs.makeDirectory(path.dirname(link), { recursive: true });
274 yield* Effect.tryPromise(() =>
275 NodeFSP.symlink(target, link, input.platform === "win32" ? "junction" : "dir"),
276 );
277 }).pipe(
278 Effect.catch((error) =>
279 Effect.logWarning("Antigravity user skills are not linked into the profile.", {
280 link,
281 target,
282 error,
283 }),
284 ),
285 );
286 }
287});
288​
289export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")(function* (input: {
290 readonly profileDirectory: string;
291 readonly baseEnv?: NodeJS.ProcessEnv;
292 readonly runtimeExecutablePath?: string;
293 readonly platform?: NodeJS.Platform;
294 readonly auth?: AntigravityAuthConfig;
295 readonly userHome?: string;
296 readonly tempDirectory?: string;
297}) {
298 const auth = input.auth ?? ANTIGRAVITY_PERSONAL_AUTH;
299 const fs = yield* FileSystem.FileSystem;
300 const path = yield* Path.Path;
301 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
302 const platform = input.platform ?? (yield* HostProcess.Platform);
303 const userHome =
304 input.userHome ??
305 resolveAntigravityUserHome(
306 platform,
307 input.baseEnv ?? process.env,
308 yield* HostProcess.HomeDirectory,
309 );
310 const runtimeExecutablePath =
311 input.runtimeExecutablePath ??
312 (yield* resolveNodeExecutable("Antigravity sign-in", input.baseEnv).pipe(
313 Effect.mapError(
314 (cause) =>
315 new AcpErrors.AcpTransportError({
316 detail: nodeRuntimeUnavailableMessage("Antigravity sign-in"),
317 cause,
318 }),
319 ),
320 ));
321 const helperExecutable =
322 platform === "win32" ? runtimeExecutablePath.replaceAll("\\", "/") : runtimeExecutablePath;
323 const browserArguments = [helperExecutable, "-e", browserHelperSource, "--", "%s"];
324 const browserCommand = browserArguments.map(quoteBrowserArgument).join(" ");
325 if (
326 browserCommand.includes(platform === "win32" ? ";" : ":") ||
327 helperExecutable.includes("\r") ||
328 helperExecutable.includes("\n") ||
329 helperExecutable.includes("\0") ||
330 helperExecutable.includes("%s")
331 ) {
332 return yield* authSupportError(
333 "The T3 runtime path cannot be used to suppress Antigravity browser launches.",
334 );
335 }
336​
337 const geminiHome = path.resolve(input.profileDirectory);
338 const acpDirectory = path.join(geminiHome, "antigravity-acp");
339 const tempDirectory = input.tempDirectory ?? path.join(acpDirectory, "tmp");
340 let caBundlePath: string | undefined;
341 if (platform === "linux") {
342 // Bundled Python may look for certificates at paths absent on this distribution.
343 // Relative paths would resolve differently when the agent runs in the project directory.
344 for (const candidate of [
345 (input.baseEnv ?? process.env).NIX_SSL_CERT_FILE,
346 "/etc/ssl/certs/ca-bundle.crt",
347 "/etc/ssl/certs/ca-certificates.crt",
348 "/etc/pki/tls/certs/ca-bundle.crt",
349 "/etc/ssl/cert.pem",
350 ]) {
351 if (
352 candidate &&
353 path.isAbsolute(candidate) &&
354 (yield* fs.exists(candidate).pipe(Effect.orElseSucceed(() => false)))
355 ) {
356 caBundlePath = candidate;
357 break;
358 }
359 }
360 }
361 const profile: AntigravityProfile = {
362 platform,
363 geminiHome,
364 acpDirectory,
365 tokenPath: path.join(acpDirectory, "acp_token.json"),
366 tempDirectory,
367 browserCommand,
368 ...(caBundlePath === undefined ? {} : { caBundlePath }),
369 };
370 const environment = antigravityEnvironment(profile, input.baseEnv ?? process.env, auth);
371 yield* Effect.gen(function* () {
372 const child = yield* spawner.spawn(
373 ChildProcess.make(helperExecutable, ["-e", browserHelperSource, "--", browserPreflightUrl], {
374 env: environment,
375 extendEnv: false,
376 shell: false,
377 }),
378 );
379 const [stdout, stderr, exitCode] = yield* Effect.all(
380 [
381 collectUint8StreamText({ stream: child.stdout, maxBytes: 4_096 }),
382 collectUint8StreamText({ stream: child.stderr, maxBytes: 4_096 }),
383 child.exitCode,
384 ],
385 { concurrency: "unbounded" },
386 );
387 if (
388 Number(exitCode) !== 0 ||
389 stdout.bytes !== 0 ||
390 stdout.truncated ||
391 stderr.truncated ||
392 stderr.text !== `${ANTIGRAVITY_AUTH_BROWSER_MARKER}"${browserPreflightUrl}"\n`
393 ) {
394 return yield* authSupportError("Antigravity browser suppression could not be verified.");
395 }
396 }).pipe(
397 Effect.scoped,
398 Effect.timeoutOrElse({
399 duration: "5 seconds",
400 orElse: () =>
401 Effect.fail(authSupportError("Antigravity browser suppression verification timed out.")),
402 }),
403 Effect.mapError((error) =>
404 error._tag === "AcpTransportError"
405 ? error
406 : authSupportError("Antigravity browser suppression could not be verified."),
407 ),
408 );
409​
410 for (const directory of [geminiHome, acpDirectory, tempDirectory]) {
411 yield* fs
412 .makeDirectory(directory, { recursive: true, mode: 0o700 })
413 .pipe(
414 Effect.mapError(() =>
415 authSupportError("The Antigravity profile directory could not be created."),
416 ),
417 );
418 if (platform !== "win32") {
419 yield* fs
420 .chmod(directory, 0o700)
421 .pipe(
422 Effect.mapError(() =>
423 authSupportError("The Antigravity profile directory permissions could not be set."),
424 ),
425 );
426 }
427 }
428 yield* fs
429 .writeFileString(path.join(acpDirectory, "settings.json"), antigravityProfileSettings(auth))
430 .pipe(
431 Effect.mapError(() =>
432 authSupportError("The Antigravity profile settings could not be written."),
433 ),
434 );
435 yield* linkAntigravityUserSkills({ profileDirectory: geminiHome, userHome, platform });
436 return profile;
437});
438​
439export function buildAntigravityAcpSpawnInput(input: {
440 readonly installation: {
441 readonly executablePath: string;
442 readonly harnessPath: string;
443 };
444 readonly profile: AntigravityProfile;
445 readonly cwd: string;
446 readonly baseEnv?: NodeJS.ProcessEnv;
447 readonly auth?: AntigravityAuthConfig;
448 readonly runtimeTempDirectory?: string;
449}): AcpSessionRuntime.AcpSpawnInput {
450 return {
451 command: input.installation.executablePath,
452 args: input.profile.platform === "linux" ? ["--uid="] : [],
453 cwd: input.cwd,
454 env: {
455 ...antigravityEnvironment(
456 input.profile,
457 input.baseEnv ?? process.env,
458 input.auth ?? ANTIGRAVITY_PERSONAL_AUTH,
459 input.runtimeTempDirectory,
460 ),
461 ANTIGRAVITY_HARNESS_PATH: input.installation.harnessPath,
462 },
463 extendEnv: false,
464 };
466​
467export const parseAntigravityAuthorizationUrl = Effect.fn("parseAntigravityAuthorizationUrl")(
468 function* (
469 authorizationUrl: string,
470 ): Effect.fn.Return<AntigravityAuthorizationUrl, AcpErrors.AcpError> {
471 const invalidUrl = () =>
472 authSupportError("Antigravity returned an invalid Google sign-in URL.");
473 if (authorizationUrl.length > maxAuthorizationUrlLength || /\s/.test(authorizationUrl)) {
474 return yield* invalidUrl();
475 }
476 const url = yield* decodeUrl(authorizationUrl).pipe(Effect.mapError(invalidUrl));
477 const state = url.searchParams.get("state");
478 const redirectUri = url.searchParams.get("redirect_uri");
479 if (
480 url.origin !== "https://accounts.google.com" ||
481 url.pathname !== "/o/oauth2/v2/auth" ||
482 url.username !== "" ||
483 url.password !== "" ||
484 url.hash !== "" ||
485 url.searchParams.getAll("state").length !== 1 ||
486 url.searchParams.getAll("redirect_uri").length !== 1 ||
487 url.searchParams.getAll("response_type").length !== 1 ||
488 url.searchParams.get("response_type") !== "code" ||
489 state === null ||
490 state.length === 0 ||
491 state.length > 512 ||
492 /\s/.test(state) ||
493 redirectUri === null ||
494 !/^http:\/\/127\.0\.0\.1:[1-9][0-9]{0,4}\/$/.test(redirectUri)
495 ) {
496 return yield* invalidUrl();
497 }
498 const redirect = yield* decodeUrl(redirectUri).pipe(Effect.mapError(invalidUrl));
499 if (Number(redirect.port) < 1_024) return yield* invalidUrl();
500 return { authorizationUrl, redirectUri, state };
501 },
502);
503​
504export function makeAntigravityStdoutTransform(
505 input: {
506 readonly onAuthorizationUrl?: (
507 authorizationUrl: string,
508 ) => Effect.Effect<void, AcpErrors.AcpError>;
509 } = {},
510) {
511 const handleLine = Effect.fn("antigravityAuthSupport.handleStdoutLine")(function* (
512 line: Uint8Array,
513 ) {
514 if (!authPrefixBytes.every((byte, index) => line[index] === byte)) return [line];
515 const message = new TextDecoder().decode(line).replace(/\r?\n$/, "");
516 const request = yield* parseAntigravityAuthorizationUrl(
517 message.slice(ANTIGRAVITY_AUTH_STDOUT_PREFIX.length),
518 );
519 if (!input.onAuthorizationUrl) {
520 return yield* authSupportError(ANTIGRAVITY_SIGN_IN_REQUIRED_MESSAGE);
521 }
522 yield* input.onAuthorizationUrl(request.authorizationUrl);
523 return [];
524 });
525​
526 return (
527 stdout: ChildProcessSpawner.ChildProcessHandle["stdout"],
528 ): Stream.Stream<Uint8Array, PlatformError.PlatformError | AcpErrors.AcpError> =>
529 Stream.suspend(() => {
530 let pending: Uint8Array[] = [];
531 let pendingBytes = 0;
532 const finishLine = () => {
533 const line = Buffer.concat(pending, pendingBytes);
534 pending = [];
535 pendingBytes = 0;
536 return line;
537 };
538 return stdout.pipe(
539 Stream.mapEffect(
540 Effect.fn("antigravityAuthSupport.splitStdoutLines")(function* (chunk: Uint8Array) {
541 const lines: Uint8Array[] = [];
542 let offset = 0;
543 while (offset < chunk.byteLength) {
544 const newline = chunk.indexOf(10, offset);
545 const end = newline === -1 ? chunk.byteLength : newline + 1;
546 const part = chunk.subarray(offset, end);
547 if (pendingBytes + part.byteLength > maxStdoutLineBytes) {
548 return yield* authSupportError(
549 "Antigravity sent a protocol line that is too large.",
550 );
551 }
552 pending.push(part);
553 pendingBytes += part.byteLength;
554 if (newline !== -1) lines.push(finishLine());
555 offset = end;
556 }
557 return lines;
558 }),
559 ),
560 Stream.flatMap(Stream.fromIterable),
561 Stream.concat(
562 Stream.suspend(() => (pendingBytes > 0 ? Stream.succeed(finishLine()) : Stream.empty)),
563 ),
564 Stream.mapEffect(handleLine),
565 Stream.flatMap(Stream.fromIterable),
566 );
567 });
569​
570export function makeAntigravityStderrHandler(
571 input: {
572 readonly onAuthorizationUrl?: (
573 authorizationUrl: string,
574 ) => Effect.Effect<void, AcpErrors.AcpError>;
575 } = {},
576) {
577 let pending = "";
578 const handleLine = (line: string) => {
579 const message = line.endsWith("\r") ? line.slice(0, -1) : line;
580 if (message.length > maxBrowserHelperLineLength) {
581 return Effect.void;
582 }
583 const url = message.startsWith(ANTIGRAVITY_AUTH_STDOUT_PREFIX)
584 ? Effect.succeed(message.slice(ANTIGRAVITY_AUTH_STDOUT_PREFIX.length))
585 : message.startsWith(ANTIGRAVITY_AUTH_BROWSER_MARKER)
586 ? decodeBrowserHelperUrl(message.slice(ANTIGRAVITY_AUTH_BROWSER_MARKER.length))
587 : undefined;
588 if (url === undefined) return Effect.void;
589 return url.pipe(
590 Effect.flatMap(parseAntigravityAuthorizationUrl),
591 Effect.matchEffect({
592 onFailure: () => Effect.void,
593 onSuccess: (request) =>
594 input.onAuthorizationUrl
595 ? input.onAuthorizationUrl(request.authorizationUrl)
596 : Effect.fail(authSupportError(ANTIGRAVITY_SIGN_IN_REQUIRED_MESSAGE)),
597 }),
598 );
599 };
600​
601 return Effect.fn("antigravityAuthSupport.handleStderr")(function* (text: string) {
602 const lines = `${pending}${text}`.split("\n");
603 pending = lines.pop() ?? "";
604 if (pending.length > maxBrowserHelperLineLength) pending = "";
605 yield* Effect.forEach(lines, handleLine, { discard: true });
606 });