@timmyjl12/pi-agy-bridge 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema": 1,
3
3
  "agy": {
4
- "tested": ["1.5.3", "1.5.8", "1.5.9", "1.5.12", "1.5.14"],
4
+ "tested": ["1.5.3", "1.5.8", "1.5.9", "1.5.12", "1.5.14", "1.5.16"],
5
5
  "minimum": "1.5.1",
6
6
  "knownBad": []
7
7
  },
@@ -10,6 +10,6 @@
10
10
  },
11
11
  "sdk": {
12
12
  "package": "google-antigravity",
13
- "tested": ["0.1.23"]
13
+ "tested": ["0.1.23", "0.1.24"]
14
14
  }
15
15
  }
package/compat/probe.ts CHANGED
@@ -40,7 +40,7 @@ export const PROBE_PROTOCOL_VERSION = 1;
40
40
  export const PROBE_CLIENT_INFO = {
41
41
  name: "pi-agy-bridge-compat-probe",
42
42
  title: "pi-agy-bridge zero-cost compat probe",
43
- version: "0.2.0",
43
+ version: "0.3.0",
44
44
  } as const;
45
45
 
46
46
  /** One failed probe step. `step` names the command or exchange. */
@@ -3,7 +3,7 @@ name = "pi-agy-sdk-canary"
3
3
  version = "0.1.0"
4
4
  description = "Protocol drift canary for the google-antigravity harness contract (pi-agy-bridge upgrade path)"
5
5
  requires-python = ">=3.10"
6
- dependencies = ["google-antigravity==0.1.23"]
6
+ dependencies = ["google-antigravity==0.1.24"]
7
7
 
8
8
  [tool.uv]
9
9
  package = false
@@ -434,7 +434,7 @@ wheels = [
434
434
 
435
435
  [[package]]
436
436
  name = "google-antigravity"
437
- version = "0.1.23"
437
+ version = "0.1.24"
438
438
  source = { registry = "https://pypi.org/simple" }
439
439
  dependencies = [
440
440
  { name = "absl-py" },
@@ -448,12 +448,12 @@ dependencies = [
448
448
  { name = "websockets", version = "17.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" },
449
449
  ]
450
450
  wheels = [
451
- { url = "https://files.pythonhosted.org/packages/78/1e/71a0db889bdc339ae2ddbf7875366959660dc108c803c6b17242fcca41bc/google_antigravity-0.1.23-py3-none-macosx_11_0_arm64.whl", hash = "sha256:92dc71a52afde0ff8424534e728cc6e168489773b61457b88dcd1c634af4ff6c", size = 40142117, upload-time = "2026-10-28T16:50:40.579Z" },
452
- { url = "https://files.pythonhosted.org/packages/fe/8d/2f489370d5c47c887ba5c9107f009f428eb6b7b9e2e5e96df0f4c8ace29c/google_antigravity-0.1.23-py3-none-macosx_11_0_x86_64.whl", hash = "sha256:5a99fd8993f13f03e43a7da9ba62b4114c05d952f6f933e86f33c3fc79e80b8e", size = 42390102, upload-time = "2026-10-28T16:50:44.189Z" },
453
- { url = "https://files.pythonhosted.org/packages/55/74/fe20c9b0301c9fd3fdaf4f4f92ed43fd3f1ab59c7c6b64ebbc793ec04578/google_antigravity-0.1.23-py3-none-manylinux_2_17_aarch64.musllinux_1_1_aarch64.whl", hash = "sha256:17b2d26575ef168bb3ccd74ddf39ebfe4c528ea426e4bedee8621ea7a41cf527", size = 41215880, upload-time = "2026-10-28T16:50:48.235Z" },
454
- { url = "https://files.pythonhosted.org/packages/9a/53/ea087398e44a3deb216a7a87bb88832b182a4a66489ec6cb43db22b5abda/google_antigravity-0.1.23-py3-none-manylinux_2_17_x86_64.musllinux_1_1_x86_64.whl", hash = "sha256:6b1dfa14090ce8cf10395074eecab2bf20cb49ceed3a2603d39803951c9884e2", size = 45219152, upload-time = "2026-10-28T16:50:56.987Z" },
455
- { url = "https://files.pythonhosted.org/packages/47/77/53b2c4bd11df1ace856fd67ad2e378151193eb2f99e10dc6e6f46087fb82/google_antigravity-0.1.23-py3-none-win_amd64.whl", hash = "sha256:e587980e3e220b7f24fcddbaa8af55a7b46a9e59443c13e782458718a67c2fba", size = 46149708, upload-time = "2026-10-28T16:51:09.079Z" },
456
- { url = "https://files.pythonhosted.org/packages/48/c1/af3a1354977e8d16fd3bbd2e4c9a5bd55f5963578d33eaa37b61965a7e66/google_antigravity-0.1.23-py3-none-win_arm64.whl", hash = "sha256:cbbcbf920b433b2c6db7ea9ed5b4b234a72f574647effa5e3e67f0d97c1793df", size = 42115847, upload-time = "2026-10-28T16:51:24.113Z" },
451
+ { url = "https://files.pythonhosted.org/packages/71/60/d276f00361ddedb6f9d3f2618775a909acff006279fb7bc6a64e23c75fcf/google_antigravity-0.1.24-py3-none-macosx_11_0_arm64.whl", hash = "sha256:9c359bfa7b752ad3417da1a455a114dca643d02bdea7281e8de8d0d0f44c9cca", size = 38296783, upload-time = "2026-11-19T15:44:26.497Z" },
452
+ { url = "https://files.pythonhosted.org/packages/32/e5/23dca5b02fe92b5e4b2516ee41b1fd762de501d931aff2be6893472d60a4/google_antigravity-0.1.24-py3-none-macosx_11_0_x86_64.whl", hash = "sha256:ff368c84cc712b822c87dd2ac99b8fac47716c44ffa39bd1caf823e62f00a18f", size = 40384370, upload-time = "2026-11-19T15:44:22.022Z" },
453
+ { url = "https://files.pythonhosted.org/packages/3d/2b/8ae68143e638cd7ac4db9824cc9b0fb6036b2ad92f8a15c4467602d53dfd/google_antigravity-0.1.24-py3-none-manylinux_2_17_aarch64.musllinux_1_1_aarch64.whl", hash = "sha256:55c95c04b00c417667d37a000931638c23479d0f1fa0fbe6e89abb8c60057cda", size = 39805700, upload-time = "2026-11-19T15:44:19.1Z" },
454
+ { url = "https://files.pythonhosted.org/packages/bc/4f/c697485a4fabffd38947eab670485fbcf7e24add178a64c6982f72c4708a/google_antigravity-0.1.24-py3-none-manylinux_2_17_x86_64.musllinux_1_1_x86_64.whl", hash = "sha256:678c5c56a4efa8d94b90df808a93b339cf3ead498b01898272d5833c8c9ad13f", size = 43525848, upload-time = "2026-11-19T15:44:16.144Z" },
455
+ { url = "https://files.pythonhosted.org/packages/37/63/de80a45b2fad18f5e97cfc12a25436b6498669fe5eb8c6694e386b48d6d8/google_antigravity-0.1.24-py3-none-win_amd64.whl", hash = "sha256:cc2d2af2cbc260d9a9f6c95e7b844185dad29b44760c1e3884d2cb001f55adb8", size = 42817643, upload-time = "2026-11-19T15:44:13.137Z" },
456
+ { url = "https://files.pythonhosted.org/packages/37/0a/b209a4339870016cfc23ec44d87151677972fd9ab5e83de0f87f7ad6f40e/google_antigravity-0.1.24-py3-none-win_arm64.whl", hash = "sha256:28837e53cf361fca8c63edee1d3cc0ba22c08eae3dec594d7f332e320fdcc9b7", size = 39222454, upload-time = "2026-11-19T15:44:10.04Z" },
457
457
  ]
458
458
 
459
459
  [[package]]
@@ -744,7 +744,7 @@ dependencies = [
744
744
  ]
745
745
 
746
746
  [package.metadata]
747
- requires-dist = [{ name = "google-antigravity", specifier = "==0.1.23" }]
747
+ requires-dist = [{ name = "google-antigravity", specifier = "==0.1.24" }]
748
748
 
749
749
  [[package]]
750
750
  name = "protobuf"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@timmyjl12/pi-agy-bridge",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "pi provider for Google Antigravity (agy) models over the official ACP server, modelled on pi-claude-code: pi keeps the loop, history and tool execution",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -22,6 +22,7 @@ import {
22
22
  type LoginHandle,
23
23
  type LoginProgress,
24
24
  type LoginResult,
25
+ type RequestLoginCode,
25
26
  } from "./accounts.ts";
26
27
  import { describeError } from "./errors.ts";
27
28
  import { describeModels } from "./model-catalog.ts";
@@ -303,7 +304,7 @@ export class AccountManager {
303
304
 
304
305
  /** Sign an extra account in through `agy acp --login` (browser). On success the email is recorded as the
305
306
  * account's expected identity and its provider is refreshed. */
306
- async login(id: string, onProgress?: (progress: LoginProgress) => void): Promise<LoginResult> {
307
+ async login(id: string, onProgress?: (progress: LoginProgress) => void, requestCode?: RequestLoginCode): Promise<LoginResult> {
307
308
  await this.load();
308
309
  if (id === DEFAULT_ACCOUNT) {
309
310
  return { ok: false, message: "the default account uses agy's own login: run `agy` in a terminal and sign in there" };
@@ -319,6 +320,7 @@ export class AccountManager {
319
320
  id,
320
321
  env: this.#options.runtime?.pool?.env ?? process.env,
321
322
  onProgress,
323
+ ...(requestCode ? { requestCode } : {}),
322
324
  ...(this.#options.loginPrefixArgs ? { prefixArgs: this.#options.loginPrefixArgs } : {}),
323
325
  });
324
326
  this.#logins.set(id, handle);
package/src/accounts.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  // which account a process serves, and refuses to use an extra-account process that is not the expected account.
11
11
 
12
12
  import { spawn, type ChildProcess } from "node:child_process";
13
- import { mkdir, readFile, rm, stat } from "node:fs/promises";
13
+ import { mkdir, readFile, rename, rm, stat } from "node:fs/promises";
14
14
  import path from "node:path";
15
15
  import { writeFileAtomic } from "./atomic-write.ts";
16
16
 
@@ -76,6 +76,8 @@ export interface AccountPaths {
76
76
  root: string;
77
77
  geminiDir: string;
78
78
  logFile: string;
79
+ /** The previous process's agy log, kept so a failure (a stall, a timeout) can be read after the restart. */
80
+ prevLogFile: string;
79
81
  loginLog: string;
80
82
  tokenFile: string;
81
83
  }
@@ -87,11 +89,34 @@ export function accountPaths(home: string, id: string): AccountPaths {
87
89
  root,
88
90
  geminiDir,
89
91
  logFile: path.join(root, "acp.log"),
92
+ prevLogFile: path.join(root, "acp.prev.log"),
90
93
  loginLog: path.join(root, "login.log"),
91
94
  tokenFile: path.join(geminiDir, "antigravity-cli", "antigravity-oauth-token"),
92
95
  };
93
96
  }
94
97
 
98
+ /** Before an extra-account process starts: move its last log to `acp.prev.log` (replacing the older one) so the new
99
+ * process starts with an empty log for the identity guard, while the previous run stays readable. */
100
+ export async function rotateAccountLog(
101
+ paths: Pick<AccountPaths, "logFile" | "prevLogFile">,
102
+ io: { rename: typeof rename; rm: typeof rm } = { rename, rm },
103
+ ): Promise<void> {
104
+ // On Windows a process that is still exiting can hold the log for a moment (EBUSY/EPERM/EACCES): retry briefly.
105
+ for (let attempt = 0; attempt < 5; attempt += 1) {
106
+ try {
107
+ await io.rename(paths.logFile, paths.prevLogFile);
108
+ return;
109
+ } catch (error) {
110
+ const code = (error as NodeJS.ErrnoException).code ?? "";
111
+ if (code === "ENOENT") return;
112
+ if (!["EBUSY", "EPERM", "EACCES"].includes(code)) break;
113
+ await new Promise((resolve) => setTimeout(resolve, 50 * (attempt + 1)));
114
+ }
115
+ }
116
+ // Still cannot move it: drop it (as before 0.3.0), the identity guard needs a fresh log.
117
+ await io.rm(paths.logFile, { force: true, maxRetries: 5, retryDelay: 100 });
118
+ }
119
+
95
120
  /** Is a saved login present for this extra account (existence only; the file is never read)? */
96
121
  export async function hasSavedLogin(home: string, id: string): Promise<boolean> {
97
122
  try {
@@ -259,6 +284,13 @@ export interface LoginProgress {
259
284
  line?: string;
260
285
  }
261
286
 
287
+ /** agy >= 1.5.14 with file token storage does not catch the OAuth redirect itself: it prints the sign-in link and
288
+ * waits on stdin for the authorization code (or the full URL of the page the browser lands on). */
289
+ const CODE_PROMPT = /paste the authorization code/i;
290
+
291
+ /** Asked once agy waits for the authorization code. Resolve with the code / landing URL, or undefined to cancel. */
292
+ export type RequestLoginCode = (url: string | undefined, signal: AbortSignal) => Promise<string | undefined>;
293
+
262
294
  export interface LoginResult {
263
295
  ok: boolean;
264
296
  email?: string;
@@ -279,6 +311,8 @@ export function startLogin(options: {
279
311
  env?: NodeJS.ProcessEnv;
280
312
  timeoutMs?: number;
281
313
  onProgress?: (progress: LoginProgress) => void;
314
+ /** Supplies the authorization code when agy asks for it. Without it agy's stdin is closed (sign-in fails). */
315
+ requestCode?: RequestLoginCode;
282
316
  /** Test seam: arguments placed before agy's own (e.g. a fake script run by node). */
283
317
  prefixArgs?: readonly string[];
284
318
  }): LoginHandle {
@@ -293,16 +327,48 @@ export function startLogin(options: {
293
327
  child = spawn(options.command, args, {
294
328
  cwd: paths.root,
295
329
  env: { ...(options.env ?? process.env), ...FILE_STORAGE_ENV },
296
- stdio: ["ignore", "pipe", "pipe"],
330
+ stdio: ["pipe", "pipe", "pipe"],
297
331
  windowsHide: true,
298
332
  });
333
+ const stdin = child.stdin;
334
+ stdin?.on("error", () => undefined); // agy may exit before the code is written (EPIPE)
335
+ if (!options.requestCode) stdin?.end();
336
+ const asking = new AbortController();
337
+ let loginUrl: string | undefined;
338
+ let prompted = false;
339
+ let transcript = "";
340
+ const askForCode = async (): Promise<void> => {
341
+ if (!options.requestCode || !stdin) return;
342
+ let code: string | undefined;
343
+ try {
344
+ code = await options.requestCode(loginUrl, asking.signal);
345
+ } catch {
346
+ code = undefined;
347
+ }
348
+ if (asking.signal.aborted) return;
349
+ const value = code?.trim();
350
+ if (!value) {
351
+ cancelled = true;
352
+ child?.kill();
353
+ return;
354
+ }
355
+ stdin.end(`${value}\n`);
356
+ };
299
357
  const onText = (chunk: Buffer | string): void => {
300
- for (const line of String(chunk).split(/\r?\n/)) {
301
- const clean = line.replace(/\x1b\[[0-9;]*m/g, "").trim();
358
+ const text = String(chunk).replace(/\x1b\[[0-9;]*m/g, "");
359
+ for (const line of text.split(/\r?\n/)) {
360
+ const clean = line.trim();
302
361
  if (!clean) continue;
303
362
  const url = /https:\/\/\S+/.exec(clean)?.[0];
363
+ if (url && !loginUrl) loginUrl = url;
304
364
  options.onProgress?.(url ? { url, line: clean } : { line: clean });
305
365
  }
366
+ // The prompt has no trailing newline and may arrive split across chunks.
367
+ transcript = (transcript + text).slice(-4096);
368
+ if (!prompted && CODE_PROMPT.test(transcript)) {
369
+ prompted = true;
370
+ void askForCode();
371
+ }
306
372
  };
307
373
  child.stdout?.on("data", onText);
308
374
  child.stderr?.on("data", onText);
@@ -326,6 +392,7 @@ export function startLogin(options: {
326
392
  resolve({ code });
327
393
  });
328
394
  });
395
+ asking.abort(); // dismiss a still-open code dialog when agy has already exited
329
396
  const identity = await readIdentity(paths.loginLog);
330
397
  if (cancelled) return { ok: false, message: "sign-in cancelled" };
331
398
  if (exit.error) return { ok: false, message: `could not start agy: ${exit.error.message}` };
@@ -336,7 +403,10 @@ export function startLogin(options: {
336
403
  if (!identity.fileStorage) {
337
404
  return { ok: false, message: "agy did not switch to per-account token storage; the account was not isolated (see UPGRADING.md)" };
338
405
  }
339
- if (!identity.email) return { ok: false, message: `sign-in did not complete (agy exit code ${exit.code ?? "?"})` };
406
+ if (!identity.email) {
407
+ const reason = /(?:Error|couldn't log in):?\s*(.+)$/im.exec(transcript)?.[1]?.trim();
408
+ return { ok: false, message: `sign-in did not complete (agy exit code ${exit.code ?? "?"}${reason ? `: ${reason}` : ""})` };
409
+ }
340
410
  return { ok: true, email: identity.email, message: `signed in as ${maskEmail(identity.email)}` };
341
411
  })();
342
412
  return {
@@ -194,7 +194,7 @@ export class AcpProcess {
194
194
  const result = await this.#rpc.request("initialize", {
195
195
  protocolVersion: 1,
196
196
  clientCapabilities: { fs: { readTextFile: false, writeTextFile: false }, terminal: false },
197
- clientInfo: { name: "pi-agy-bridge", title: "pi-agy-bridge", version: "0.2.0" },
197
+ clientInfo: { name: "pi-agy-bridge", title: "pi-agy-bridge", version: "0.3.0" },
198
198
  });
199
199
  return (result ?? {}) as AcpInitializeResult;
200
200
  }
package/src/runtime.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  // The per-extension runtime: configuration, the shared session pool, agy compatibility state and facts learned
2
2
  // while running (observed context windows). One instance per extension load; tests build their own.
3
3
 
4
- import { rm } from "node:fs/promises";
5
4
  import path from "node:path";
6
5
  import {
7
6
  accountPaths,
8
7
  DEFAULT_ACCOUNT,
9
8
  FILE_STORAGE_ENV,
10
9
  maskEmail,
10
+ rotateAccountLog,
11
11
  waitForIdentity,
12
12
  type AccountRecord,
13
13
  type Identity,
@@ -164,7 +164,7 @@ export class AgyRuntime {
164
164
  extraArgs: (staging) =>
165
165
  // The real argv already names the gemini dir through the staging override; a test argv may not.
166
166
  this.#options.pool?.buildArgs ? ["--gemini-dir", staging.geminiDir, "--log-file", paths.logFile] : ["--log-file", paths.logFile],
167
- beforeStart: () => rm(paths.logFile, { force: true }),
167
+ beforeStart: () => rotateAccountLog(paths),
168
168
  verifyProcess: (proc, sessionFailure) => this.#checkIdentity(paths.logFile, proc, sessionFailure),
169
169
  }
170
170
  : {}),
@@ -209,7 +209,16 @@ export class SessionPool {
209
209
  : ["acp", "--add-dir", staging.addDir, "--agent", staging.agentName, "--gemini-dir", staging.geminiDir]),
210
210
  ...(this.#options.extraArgs?.(staging) ?? []),
211
211
  ];
212
- await this.#options.beforeStart?.();
212
+ try {
213
+ await this.#options.beforeStart?.();
214
+ } catch (error) {
215
+ // A local file problem (for example a log still locked by the previous process) is a start failure, retryable
216
+ // for fallback chains. Only the error code goes into the message: the OS text (`EACCES: permission denied`)
217
+ // would be read as a sign-in problem by the classifiers. The full error stays in `cause` and the trace.
218
+ const code = (error as NodeJS.ErrnoException | undefined)?.code ?? "unknown";
219
+ this.#options.log?.(`beforeStart failed: ${describeError(error)}`);
220
+ throw new AgyError("spawn", `agy spawn failed: could not prepare the account log (${code}); retry`, { cause: error });
221
+ }
213
222
  const proc = AcpProcess.start({
214
223
  command,
215
224
  args,
package/src/stream.ts CHANGED
@@ -489,6 +489,12 @@ async function runTurn(
489
489
  let silenceTimer: NodeJS.Timeout | undefined;
490
490
  let probeTimer: NodeJS.Timeout | undefined;
491
491
  let settled = false;
492
+ // Diagnostics for stalls and timeouts (PI_AGY_TRACE=1): what agy last sent, and when.
493
+ const startedAt = Date.now();
494
+ let updates = 0;
495
+ let firstUpdateAt: number | undefined;
496
+ let lastUpdateAt: number | undefined;
497
+ let lastUpdateKind = "none";
492
498
  let expire: () => void = () => undefined;
493
499
  const graceExpired = new Promise<"grace">((resolve) => {
494
500
  expire = () => resolve("grace");
@@ -497,6 +503,12 @@ async function runTurn(
497
503
  const requestCancel = (reason: CancelReason): void => {
498
504
  if (cancelReason || settled) return;
499
505
  cancelReason = reason;
506
+ if (reason === "stall" || reason === "timeout" || reason === "refused") {
507
+ const now = Date.now();
508
+ runtime.trace(
509
+ `turn: ${reason} model=${model.id} after ${now - startedAt}ms; updates=${updates} first=${firstUpdateAt === undefined ? "none" : `${firstUpdateAt - startedAt}ms`} last=${lastUpdateKind}${lastUpdateAt === undefined ? "" : ` ${now - lastUpdateAt}ms ago`} text=${translator.producedOutput}`,
510
+ );
511
+ }
500
512
  if (silenceTimer) clearTimeout(silenceTimer);
501
513
  if (totalTimer) clearTimeout(totalTimer);
502
514
  if (probeTimer) clearTimeout(probeTimer);
@@ -519,6 +531,10 @@ async function runTurn(
519
531
 
520
532
  const stop = proc.listen(acpSessionId, (update) => {
521
533
  arm();
534
+ updates += 1;
535
+ lastUpdateAt = Date.now();
536
+ firstUpdateAt ??= lastUpdateAt;
537
+ lastUpdateKind = update.sessionUpdate ?? "unknown";
522
538
  switch (update.sessionUpdate) {
523
539
  case "agent_message_chunk":
524
540
  if (cancelReason) break;
package/src/ui/menu.ts CHANGED
@@ -3,8 +3,9 @@
3
3
  // Every action here calls the same AccountManager / runtime function as its `/agy-bridge` subcommand, so the menu and
4
4
  // the commands can never drift. In a non-TUI host (RPC, print) the same actions run through ui.select/input/confirm.
5
5
 
6
+ import { spawn } from "node:child_process";
6
7
  import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
7
- import { DEFAULT_ACCOUNT, labelFor, maskEmail, validateAccountName } from "../accounts.ts";
8
+ import { DEFAULT_ACCOUNT, labelFor, maskEmail, validateAccountName, type RequestLoginCode } from "../accounts.ts";
8
9
  import type { AccountManager, AccountView } from "../account-manager.ts";
9
10
  import { buildDoctor, buildStatus } from "../doctor.ts";
10
11
  import { CONFIG_ENV_NAMES } from "../config.ts";
@@ -182,15 +183,52 @@ export function accountActionsView(view: AccountView, loginRunning: boolean): Pa
182
183
 
183
184
  // ---- actions (shared with commands) ------------------------------------------------------------------------------
184
185
 
186
+ /** Open a URL in the system browser. agy with per-account token storage only prints its sign-in link, so the bridge
187
+ * opens it. Disabled by PI_AGY_NO_BROWSER=1. Failures are ignored: the link is also shown as a notification. */
188
+ export function openInBrowser(url: string, env: NodeJS.ProcessEnv = process.env): boolean {
189
+ // Only Google's own sign-in page: the URL comes from a child process's output.
190
+ if (env.PI_AGY_NO_BROWSER === "1" || !url.startsWith("https://accounts.google.com/")) return false;
191
+ const [command, args] =
192
+ process.platform === "win32"
193
+ ? ["rundll32", ["url.dll,FileProtocolHandler", url]] // no cmd.exe: '&' in the URL needs no quoting
194
+ : process.platform === "darwin"
195
+ ? ["open", [url]]
196
+ : ["xdg-open", [url]];
197
+ try {
198
+ const child = spawn(command, args, { detached: true, stdio: "ignore", windowsHide: true });
199
+ child.on("error", () => undefined);
200
+ child.unref();
201
+ return true;
202
+ } catch {
203
+ return false;
204
+ }
205
+ }
206
+
207
+ /** Ask for the authorization code agy waits for. The URL is also sent as a notification so it can be copied. */
208
+ export function codeRequester(ctx: Ctx, id: string): RequestLoginCode | undefined {
209
+ if (!ctx.hasUI) return undefined;
210
+ return (_url, signal) =>
211
+ ctx.ui.input(
212
+ `Sign-in for "${id}": after approving in the browser, paste the code (or the full URL of the page you land on); empty = cancel`,
213
+ "authorization code or https://antigravity.google/oauth-callback?...",
214
+ { signal },
215
+ );
216
+ }
217
+
185
218
  export async function runLogin(manager: AccountManager, id: string, ctx: Ctx, notify: Notify): Promise<boolean> {
186
- notify(`pi-agy-bridge: signing in account "${id}" — finish the Google sign-in in your browser (up to 5 min)…`, "info");
219
+ notify(`pi-agy-bridge: signing in account "${id}" — open the link below, approve, then paste the code it shows (up to 5 min)…`, "info");
187
220
  let urlShown = false;
188
- const result = await manager.login(id, (progress) => {
189
- if (progress.url && !urlShown) {
190
- urlShown = true;
191
- notify(`pi-agy-bridge: if no browser opened, visit: ${progress.url}`, "info");
192
- }
193
- });
221
+ const result = await manager.login(
222
+ id,
223
+ (progress) => {
224
+ if (progress.url && !urlShown) {
225
+ urlShown = true;
226
+ const opened = openInBrowser(progress.url);
227
+ notify(`pi-agy-bridge: ${opened ? "opened the sign-in page; if no browser appeared, visit" : "sign-in link"}: ${progress.url}`, "info");
228
+ }
229
+ },
230
+ codeRequester(ctx, id),
231
+ );
194
232
  notify(`pi-agy-bridge: ${id}: ${result.message}`, result.ok ? "info" : "error");
195
233
  if (result.ok) {
196
234
  const check = await manager.check(id);