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