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

antigravityAuthSupport.ts

603 lines22.8 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 { HostProcessPlatform } from "@t3tools/shared/hostProcess";
6import { resolveNodeExecutable, nodeRuntimeUnavailableMessage } from "@t3tools/shared/nodeRuntime";
7import * as Crypto from "effect/Crypto";
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 "../stream/collectUint8StreamText.ts";
20import type { AcpSpawnInput } from "./acp/AcpSessionRuntime.ts";
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 the platform path separator before it parses quotes.
55// Keep this source free of both colons and semicolons. EPIPE must still exit 0
56// so Python does not fall back to an OS browser after cancellation.
57const browserHelperSource =
58 `process.stderr.on("error",()=>process.exit(0)).write(` +
59 `"${ANTIGRAVITY_AUTH_BROWSER_MARKER}"+JSON.stringify(process.argv[1])+"\\n",` +
60 `()=>process.exit(0))`;
61const browserPreflightUrl = "https://example.invalid/t3-antigravity-browser-preflight";
62​
63const removedEnvironmentKeys = new Set([
64 "GEMINI_API_KEY",
65 "GOOGLE_API_KEY",
66 "GOOGLE_APPLICATION_CREDENTIALS",
67 "GOOGLE_CLOUD_PROJECT",
68 "GOOGLE_CLOUD_LOCATION",
69 "GOOGLE_CLOUD_QUOTA_PROJECT",
70 "GOOGLE_GENAI_USE_VERTEXAI",
71 "GCLOUD_PROJECT",
72 "CLOUDSDK_CORE_PROJECT",
73 "AGY_ACP_CCPA_PROJECT",
74 "AGY_ACP_ENABLE_OAUTH",
75 "GEMINI_HOME",
76 "AGY_ACP_FORCE_FILE_STORAGE",
77 "ANTIGRAVITY_HARNESS_PATH",
78 "BROWSER",
79 "PYTHONUNBUFFERED",
80 "ELECTRON_RUN_AS_NODE",
81]);
82​
83export interface AntigravityProfile {
84 readonly platform: NodeJS.Platform;
85 readonly geminiHome: string;
86 readonly acpDirectory: string;
87 readonly tokenPath: string;
88 /** Parent of the per-process temp directories PyInstaller unpacks into. */
89 readonly tempDirectory: string;
90 readonly browserCommand: string;
92​
93/**
94 * Credentials for the non-personal ACP auth methods. The agent reads the API
95 * key from its environment and the GCP project and location from
96 * `settings.json` in the profile. Empty strings mean "not set".
97 */
98export interface AntigravityAuthConfig {
99 readonly authMethod: AntigravityAuthMethod;
100 readonly apiKey: string;
101 readonly gcpProject: string;
102 readonly gcpLocation: string;
104​
105export const ANTIGRAVITY_PERSONAL_AUTH: AntigravityAuthConfig = {
106 authMethod: "oauth-personal",
107 apiKey: "",
108 gcpProject: "",
109 gcpLocation: "",
110};
111​
112/** True for the two methods that open a Google sign-in page. */
113export function antigravityAuthUsesBrowser(authMethod: AntigravityAuthMethod): boolean {
114 return authMethod === "oauth-personal" || authMethod === "oauth-business";
116​
117/** Label shown on the provider card once the method has authenticated. */
118export function antigravityAuthLabel(authMethod: AntigravityAuthMethod): string {
119 switch (authMethod) {
120 case "oauth-personal":
121 return "Google account";
122 case "oauth-business":
123 return "Gemini Enterprise";
124 case "gemini-api-key":
125 return "Gemini API key";
126 case "agent-platform":
127 return "Agent Platform";
128 }
130​
131/**
132 * Explains what is missing before a non-personal method can authenticate, or
133 * null when the config is complete. Personal sign-in never needs config.
134 */
135export function antigravityAuthConfigIssue(auth: AntigravityAuthConfig): string | null {
136 switch (auth.authMethod) {
137 case "oauth-personal":
138 return null;
139 case "oauth-business":
140 return auth.gcpProject && auth.gcpLocation
141 ? null
142 : "Gemini Enterprise needs a GCP project and location in the Antigravity provider settings.";
143 case "gemini-api-key":
144 return auth.apiKey ? null : "Enter a Gemini API key in the Antigravity provider settings.";
145 case "agent-platform":
146 return auth.apiKey || (auth.gcpProject && auth.gcpLocation)
147 ? null
148 : "Agent Platform needs an API key, or a GCP project and location, in the Antigravity provider settings.";
149 }
151​
152/**
153 * `settings.json` content for the agent's profile. `auth.type` names the
154 * selected method so a native logout clears only that method's credentials
155 * instead of every stored token. The GCP block feeds Enterprise and Agent
156 * Platform. Never holds a credential.
157 */
158export function antigravityProfileSettings(auth: AntigravityAuthConfig): string {
159 const gcp = {
160 ...(auth.gcpProject ? { project: auth.gcpProject } : {}),
161 ...(auth.gcpLocation ? { location: auth.gcpLocation } : {}),
162 };
163 return `${encodeProfileSettings({
164 auth: { type: auth.authMethod },
165 ...(Object.keys(gcp).length > 0 ? { gcp } : {}),
166 })}\n`;
168​
169export interface AntigravityAuthorizationUrl {
170 readonly authorizationUrl: string;
171 readonly redirectUri: string;
172 readonly state: string;
174​
175function authSupportError(detail: string) {
176 return new AcpErrors.AcpTransportError({ detail, cause: undefined });
178​
179/** Recognizes native auth failures and interactive login blocked by T3. */
180export function isAntigravitySignInRequiredError(error: unknown): boolean {
181 return (
182 (isAcpRequestError(error) && error.code === -32000) ||
183 (isAcpTransportError(error) && error.detail === ANTIGRAVITY_SIGN_IN_REQUIRED_MESSAGE)
184 );
186​
187export interface AntigravityInstanceDirectories {
188 /** GEMINI_HOME for the agent. Holds the instance's Google sign-in. */
189 readonly profile: string;
190 /**
191 * Parent of the per-process directories the agent unpacks into. It sits
192 * beside the profile, not inside it: the agent unpacks members up to 120
193 * characters deep, and the profile's longer name would push them past
194 * Windows' 260-character path limit.
195 */
196 readonly runtimeTemp: string;
198​
199/** Hashes the instance ID so case-only differences stay separate on case-insensitive filesystems. */
200export const resolveAntigravityInstanceDirectories = Effect.fn(
201 "resolveAntigravityInstanceDirectories",
202)(function* (stateDir: string, instanceId: ProviderInstanceId) {
203 const crypto = yield* Crypto.Crypto;
204 const path = yield* Path.Path;
205 const key = Hex.encode(yield* crypto.digest("SHA-256", new TextEncoder().encode(instanceId)));
206 return {
207 profile: path.join(stateDir, "providers", "antigravity", key),
208 runtimeTemp: path.join(stateDir, "antigravity-tmp", key.slice(0, 12)),
209 } satisfies AntigravityInstanceDirectories;
210});
211​
212function quoteBrowserArgument(value: string): string {
213 return `'${value.replaceAll("'", `'"'"'`)}'`;
215​
216function antigravityEnvironment(
217 profile: AntigravityProfile,
218 baseEnv: NodeJS.ProcessEnv,
219 auth: AntigravityAuthConfig,
220 runtimeTempDirectory?: string,
221) {
222 const environment: NodeJS.ProcessEnv = {};
223 for (const [key, value] of Object.entries(baseEnv)) {
224 // Windows treats environment keys as case-insensitive. Remove aliases too.
225 if (!removedEnvironmentKeys.has(key.toUpperCase())) environment[key] = value;
226 }
227 // Only the configured method's credential reaches the agent. The agent
228 // prefers GOOGLE_API_KEY over the GCP pair for Agent Platform, so the pair
229 // goes through settings.json instead of the environment.
230 const credential =
231 auth.authMethod === "gemini-api-key" && auth.apiKey
232 ? { GEMINI_API_KEY: auth.apiKey }
233 : auth.authMethod === "agent-platform" && auth.apiKey
234 ? { GOOGLE_API_KEY: auth.apiKey }
235 : {};
236 // The agent is a PyInstaller one-file bundle. It unpacks about 1 GB into
237 // the system temp directory per launch and a force kill leaves that behind.
238 // Point it at a T3-owned directory so the driver can reclaim the space.
239 const tempDirectory = runtimeTempDirectory ?? profile.tempDirectory;
240 return {
241 ...environment,
242 ...credential,
243 GEMINI_HOME: profile.geminiHome,
244 AGY_ACP_FORCE_FILE_STORAGE: "1",
245 BROWSER: profile.browserCommand,
246 PYTHONUNBUFFERED: "1",
247 ELECTRON_RUN_AS_NODE: "1",
248 ...(profile.platform === "win32"
249 ? { TEMP: tempDirectory, TMP: tempDirectory }
250 : { TMPDIR: tempDirectory }),
251 };
253​
254/**
255 * The agent reads its user-global skills under `GEMINI_HOME`, which T3 points
256 * at the private profile. Link the two skill directories back to the user's
257 * real `~/.gemini` so global skills load, while MCP servers, hooks, and
258 * credentials stay isolated. Best effort: a link that cannot be made only
259 * costs global skills, never the session. A real directory at the link path
260 * is the user's own content and is left alone.
261 */
262const linkAntigravityUserSkills = Effect.fn("linkAntigravityUserSkills")(function* (input: {
263 readonly profileDirectory: string;
264 readonly userHome: string;
265 readonly platform: NodeJS.Platform;
266}): Effect.fn.Return<void, never, FileSystem.FileSystem | Path.Path> {
267 const fs = yield* FileSystem.FileSystem;
268 const path = yield* Path.Path;
269 const links = antigravityUserSkillDirectories(path, input.profileDirectory);
270 const targets = antigravityUserSkillDirectories(path, path.join(input.userHome, ".gemini"));
271 for (const [link, target] of [
272 [links[0], targets[0]],
273 [links[1], targets[1]],
274 ] as const) {
275 yield* Effect.gen(function* () {
276 const existing = yield* fs.readLink(link).pipe(
277 Effect.map((value): string | undefined => path.resolve(path.dirname(link), value)),
278 Effect.catchReason("PlatformError", "NotFound", () => Effect.undefined),
279 );
280 if (existing === target) return;
281 if (existing !== undefined) {
282 yield* fs.remove(link);
283 }
284 yield* fs.makeDirectory(path.dirname(link), { recursive: true });
285 yield* Effect.tryPromise(() =>
286 NodeFSP.symlink(target, link, input.platform === "win32" ? "junction" : "dir"),
287 );
288 }).pipe(
289 // A non-symlink at the link path fails `readLink`; anything else is a
290 // filesystem refusal. Both leave the profile usable.
291 Effect.catch((error) =>
292 Effect.logWarning("Antigravity user skills are not linked into the profile.", {
293 link,
294 target,
295 error,
296 }),
297 ),
298 );
299 }
300});
301​
302/** Prepares a private profile without reading or copying Google credentials. */
303export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")(function* (input: {
304 readonly profileDirectory: string;
305 readonly baseEnv?: NodeJS.ProcessEnv;
306 readonly runtimeExecutablePath?: string;
307 readonly platform?: NodeJS.Platform;
308 readonly auth?: AntigravityAuthConfig;
309 /** Home the agent expands `~` against. Defaults to the launch environment's. */
310 readonly userHome?: string;
311 /** Parent of per-process temp directories. Defaults to one inside the profile. */
312 readonly tempDirectory?: string;
313}) {
314 const auth = input.auth ?? ANTIGRAVITY_PERSONAL_AUTH;
315 const fs = yield* FileSystem.FileSystem;
316 const path = yield* Path.Path;
317 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
318 const platform = input.platform ?? (yield* HostProcessPlatform);
319 const userHome =
320 input.userHome ?? resolveAntigravityUserHome(platform, input.baseEnv ?? process.env);
321 const runtimeExecutablePath =
322 input.runtimeExecutablePath ??
323 (yield* resolveNodeExecutable("Antigravity sign-in", input.baseEnv).pipe(
324 Effect.mapError(
325 (cause) =>
326 new AcpErrors.AcpTransportError({
327 detail: nodeRuntimeUnavailableMessage("Antigravity sign-in"),
328 cause,
329 }),
330 ),
331 ));
332 const helperExecutable =
333 platform === "win32" ? runtimeExecutablePath.replaceAll("\\", "/") : runtimeExecutablePath;
334 const browserArguments = [helperExecutable, "-e", browserHelperSource, "--", "%s"];
335 const browserCommand = browserArguments.map(quoteBrowserArgument).join(" ");
336 if (
337 browserCommand.includes(platform === "win32" ? ";" : ":") ||
338 helperExecutable.includes("\r") ||
339 helperExecutable.includes("\n") ||
340 helperExecutable.includes("\0") ||
341 helperExecutable.includes("%s")
342 ) {
343 return yield* authSupportError(
344 "The T3 runtime path cannot be used to suppress Antigravity browser launches.",
345 );
346 }
347​
348 const geminiHome = path.resolve(input.profileDirectory);
349 const acpDirectory = path.join(geminiHome, "antigravity-acp");
350 const tempDirectory = input.tempDirectory ?? path.join(acpDirectory, "tmp");
351 const profile: AntigravityProfile = {
352 platform,
353 geminiHome,
354 acpDirectory,
355 tokenPath: path.join(acpDirectory, "acp_token.json"),
356 tempDirectory,
357 browserCommand,
358 };
359 const environment = antigravityEnvironment(profile, input.baseEnv ?? process.env, auth);
360 yield* Effect.gen(function* () {
361 const child = yield* spawner.spawn(
362 ChildProcess.make(helperExecutable, ["-e", browserHelperSource, "--", browserPreflightUrl], {
363 env: environment,
364 extendEnv: false,
365 shell: false,
366 }),
367 );
368 const [stdout, stderr, exitCode] = yield* Effect.all(
369 [
370 collectUint8StreamText({ stream: child.stdout, maxBytes: 4_096 }),
371 collectUint8StreamText({ stream: child.stderr, maxBytes: 4_096 }),
372 child.exitCode,
373 ],
374 { concurrency: "unbounded" },
375 );
376 if (
377 Number(exitCode) !== 0 ||
378 stdout.bytes !== 0 ||
379 stdout.truncated ||
380 stderr.truncated ||
381 stderr.text !== `${ANTIGRAVITY_AUTH_BROWSER_MARKER}"${browserPreflightUrl}"\n`
382 ) {
383 return yield* authSupportError("Antigravity browser suppression could not be verified.");
384 }
385 }).pipe(
386 Effect.scoped,
387 Effect.timeoutOrElse({
388 duration: "5 seconds",
389 orElse: () =>
390 Effect.fail(authSupportError("Antigravity browser suppression verification timed out.")),
391 }),
392 Effect.mapError((error) =>
393 error._tag === "AcpTransportError"
394 ? error
395 : authSupportError("Antigravity browser suppression could not be verified."),
396 ),
397 );
398​
399 for (const directory of [geminiHome, acpDirectory, tempDirectory]) {
400 yield* fs
401 .makeDirectory(directory, { recursive: true, mode: 0o700 })
402 .pipe(
403 Effect.mapError(() =>
404 authSupportError("The Antigravity profile directory could not be created."),
405 ),
406 );
407 if (platform !== "win32") {
408 yield* fs
409 .chmod(directory, 0o700)
410 .pipe(
411 Effect.mapError(() =>
412 authSupportError("The Antigravity profile directory permissions could not be set."),
413 ),
414 );
415 }
416 }
417 // Rewriting on every launch keeps a method, project, or location edit in
418 // Settings effective. The agent also records auth.type here after a
419 // sign-in, which matches the value written below.
420 yield* fs
421 .writeFileString(path.join(acpDirectory, "settings.json"), antigravityProfileSettings(auth))
422 .pipe(
423 Effect.mapError(() =>
424 authSupportError("The Antigravity profile settings could not be written."),
425 ),
426 );
427 yield* linkAntigravityUserSkills({ profileDirectory: geminiHome, userHome, platform });
428 return profile;
429});
430​
431/** Applies the same subscription-only launch settings to every ACP process. */
432export function buildAntigravityAcpSpawnInput(input: {
433 readonly installation: {
434 readonly executablePath: string;
435 readonly harnessPath: string;
436 };
437 readonly profile: AntigravityProfile;
438 readonly cwd: string;
439 readonly baseEnv?: NodeJS.ProcessEnv;
440 readonly auth?: AntigravityAuthConfig;
441 /** Per-process temp directory. Defaults to the profile's shared temp directory. */
442 readonly runtimeTempDirectory?: string;
443}): AcpSpawnInput {
444 return {
445 command: input.installation.executablePath,
446 args: input.profile.platform === "linux" ? ["--uid="] : [],
447 cwd: input.cwd,
448 env: {
449 ...antigravityEnvironment(
450 input.profile,
451 input.baseEnv ?? process.env,
452 input.auth ?? ANTIGRAVITY_PERSONAL_AUTH,
453 input.runtimeTempDirectory,
454 ),
455 ANTIGRAVITY_HARNESS_PATH: input.installation.harnessPath,
456 },
457 extendEnv: false,
458 };
460​
461/** Reads only the public authorization request, never an OAuth token file. */
462export const parseAntigravityAuthorizationUrl = Effect.fn("parseAntigravityAuthorizationUrl")(
463 function* (
464 authorizationUrl: string,
465 ): Effect.fn.Return<AntigravityAuthorizationUrl, AcpErrors.AcpError> {
466 const invalidUrl = () =>
467 authSupportError("Antigravity returned an invalid Google sign-in URL.");
468 if (authorizationUrl.length > maxAuthorizationUrlLength || /\s/.test(authorizationUrl)) {
469 return yield* invalidUrl();
470 }
471 const url = yield* decodeUrl(authorizationUrl).pipe(Effect.mapError(invalidUrl));
472 const state = url.searchParams.get("state");
473 const redirectUri = url.searchParams.get("redirect_uri");
474 if (
475 url.origin !== "https://accounts.google.com" ||
476 url.pathname !== "/o/oauth2/v2/auth" ||
477 url.username !== "" ||
478 url.password !== "" ||
479 url.hash !== "" ||
480 url.searchParams.getAll("state").length !== 1 ||
481 url.searchParams.getAll("redirect_uri").length !== 1 ||
482 url.searchParams.getAll("response_type").length !== 1 ||
483 url.searchParams.get("response_type") !== "code" ||
484 state === null ||
485 state.length === 0 ||
486 state.length > 512 ||
487 /\s/.test(state) ||
488 redirectUri === null ||
489 !/^http:\/\/127\.0\.0\.1:[1-9][0-9]{0,4}\/$/.test(redirectUri)
490 ) {
491 return yield* invalidUrl();
492 }
493 const redirect = yield* decodeUrl(redirectUri).pipe(Effect.mapError(invalidUrl));
494 if (Number(redirect.port) < 1_024) return yield* invalidUrl();
495 return { authorizationUrl, redirectUri, state };
496 },
497);
498​
499export function makeAntigravityStdoutTransform(
500 input: {
501 readonly onAuthorizationUrl?: (
502 authorizationUrl: string,
503 ) => Effect.Effect<void, AcpErrors.AcpError>;
504 } = {},
505) {
506 const handleLine = Effect.fn("antigravityAuthSupport.handleStdoutLine")(function* (
507 line: Uint8Array,
508 ) {
509 if (!authPrefixBytes.every((byte, index) => line[index] === byte)) return [line];
510 const message = new TextDecoder().decode(line).replace(/\r?\n$/, "");
511 const request = yield* parseAntigravityAuthorizationUrl(
512 message.slice(ANTIGRAVITY_AUTH_STDOUT_PREFIX.length),
513 );
514 if (!input.onAuthorizationUrl) {
515 return yield* authSupportError(ANTIGRAVITY_SIGN_IN_REQUIRED_MESSAGE);
516 }
517 yield* input.onAuthorizationUrl(request.authorizationUrl);
518 return [];
519 });
520​
521 return (
522 stdout: ChildProcessSpawner.ChildProcessHandle["stdout"],
523 ): Stream.Stream<Uint8Array, PlatformError.PlatformError | AcpErrors.AcpError> =>
524 Stream.suspend(() => {
525 let pending: Uint8Array[] = [];
526 let pendingBytes = 0;
527 const finishLine = () => {
528 const line = Buffer.concat(pending, pendingBytes);
529 pending = [];
530 pendingBytes = 0;
531 return line;
532 };
533 return stdout.pipe(
534 Stream.mapEffect(
535 Effect.fn("antigravityAuthSupport.splitStdoutLines")(function* (chunk: Uint8Array) {
536 const lines: Uint8Array[] = [];
537 let offset = 0;
538 while (offset < chunk.byteLength) {
539 const newline = chunk.indexOf(10, offset);
540 const end = newline === -1 ? chunk.byteLength : newline + 1;
541 const part = chunk.subarray(offset, end);
542 if (pendingBytes + part.byteLength > maxStdoutLineBytes) {
543 return yield* authSupportError(
544 "Antigravity sent a protocol line that is too large.",
545 );
546 }
547 pending.push(part);
548 pendingBytes += part.byteLength;
549 if (newline !== -1) lines.push(finishLine());
550 offset = end;
551 }
552 return lines;
553 }),
554 ),
555 Stream.flatMap(Stream.fromIterable),
556 Stream.concat(
557 Stream.suspend(() => (pendingBytes > 0 ? Stream.succeed(finishLine()) : Stream.empty)),
558 ),
559 Stream.mapEffect(handleLine),
560 Stream.flatMap(Stream.fromIterable),
561 );
562 });
564​
565/** Receives native 1.1.1 sign-in URLs and T3 browser-helper URLs without logging stderr. */
566export function makeAntigravityStderrHandler(
567 input: {
568 readonly onAuthorizationUrl?: (
569 authorizationUrl: string,
570 ) => Effect.Effect<void, AcpErrors.AcpError>;
571 } = {},
572) {
573 let pending = "";
574 const handleLine = (line: string) => {
575 const message = line.endsWith("\r") ? line.slice(0, -1) : line;
576 if (message.length > maxBrowserHelperLineLength) {
577 return Effect.void;
578 }
579 const url = message.startsWith(ANTIGRAVITY_AUTH_STDOUT_PREFIX)
580 ? Effect.succeed(message.slice(ANTIGRAVITY_AUTH_STDOUT_PREFIX.length))
581 : message.startsWith(ANTIGRAVITY_AUTH_BROWSER_MARKER)
582 ? decodeBrowserHelperUrl(message.slice(ANTIGRAVITY_AUTH_BROWSER_MARKER.length))
583 : undefined;
584 if (url === undefined) return Effect.void;
585 return url.pipe(
586 Effect.flatMap(parseAntigravityAuthorizationUrl),
587 Effect.matchEffect({
588 onFailure: () => Effect.void,
589 onSuccess: (request) =>
590 input.onAuthorizationUrl
591 ? input.onAuthorizationUrl(request.authorizationUrl)
592 : Effect.fail(authSupportError(ANTIGRAVITY_SIGN_IN_REQUIRED_MESSAGE)),
593 }),
594 );
595 };
596​
597 return Effect.fn("antigravityAuthSupport.handleStderr")(function* (text: string) {
598 const lines = `${pending}${text}`.split("\n");
599 pending = lines.pop() ?? "";
600 if (pending.length > maxBrowserHelperLineLength) pending = "";
601 yield* Effect.forEach(lines, handleLine, { discard: true });
602 });