@estebanforge/pi-antigravity-bridge 1.4.4 → 1.4.5
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.
- package/CHANGELOG.md +10 -0
- package/README.md +3 -2
- package/docs/ACP-ADOPTION-PLAN.md +2 -2
- package/docs/DEVELOPMENT.md +1 -1
- package/extensions/index.ts +76 -29
- package/package.json +1 -1
- package/src/acp/auth.ts +71 -0
- package/src/acp/connection.ts +2 -2
- package/src/acp/setup.ts +11 -6
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.4.5] - 2026-09-04
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `/agy auth` subcommand: runs the antigravity-acp sign-in on demand (spawns the server, sends `authenticate`, waits for the browser round-trip to complete; minutes-scale). Signing in no longer rides the first Antigravity message, and both login-pending moments now point at `/agy auth`. The sign-in URL toast (and its ssh port-forward hint) fires during `/agy auth` exactly as it does during turns. After the authenticate reply the run waits up to 5 s for `acp_token.json` before killing the sign-in server, and a second concurrent `/agy auth` fails fast instead of racing the token write.
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- `/agy acp-auth` renamed to `/agy auth-manual` (no alias): it prints the manual credential setup for those who want it. Auth-error remediation, MANUAL_SETUP, README, and docs now point at `/agy auth` / `/agy auth-manual`, and the stale first-message login wording is gone from the manual steps.
|
|
14
|
+
|
|
5
15
|
## [1.4.4] - 2026-09-04
|
|
6
16
|
|
|
7
17
|
### Added
|
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ Turns run through one of two engines behind the same provider surface (`config.e
|
|
|
25
25
|
|
|
26
26
|
Engine-dependent features: pi image attachments ride natively only on the ACP engine (the picker offers image attach automatically when `config.engine` is `acp`; the stream-json CLI prompt is text-only). With the optional G1 digest enabled, its delivery also differs: ACP ships it as a native `embeddedContext` resource block, stream-json prepends it to the prompt text.
|
|
27
27
|
|
|
28
|
-
Switch with `/agy engine acp|stream-json` (takes effect on restart). Setup is automatic: switching to `acp` installs Google's official ACP server binary from the [antigravity-acp registry entry](https://github.com/agentclientprotocol/registry) (`~/.local/opt/agy-acp/<build>/` + a `current` symlink, zip sha256 recorded; layout and pinning in [docs/ACP-ADOPTION-PLAN.md](docs/ACP-ADOPTION-PLAN.md)) and prepares the login. The login is your Antigravity subscription:
|
|
28
|
+
Switch with `/agy engine acp|stream-json` (takes effect on restart). Setup is automatic: switching to `acp` installs Google's official ACP server binary from the [antigravity-acp registry entry](https://github.com/agentclientprotocol/registry) (`~/.local/opt/agy-acp/<build>/` + a `current` symlink, zip sha256 recorded; layout and pinning in [docs/ACP-ADOPTION-PLAN.md](docs/ACP-ADOPTION-PLAN.md)) and prepares the login. The login is your Antigravity subscription: the same account and plan you use for the Antigravity CLI (`agy`). Sign in explicitly with `/agy auth` (engine `acp` selected): it opens the Google login in your browser and completes when you finish it. If no browser is available (an SSH session on a remote machine), pi shows the sign-in URL to copy, plus the ssh port-forward command for the login redirect. It is no different from logging into the CLI; the server just keeps its own token file on your machine, like any Google tool, and this extension never sees your credentials. If you also export `GEMINI_API_KEY`, it is ignored: the server uses the auth type in settings.json, and setup always writes `oauth-personal`. A session start self-heals the same way, silently when everything is ready. Manual instructions (`/agy auth-manual`) surface only when a step fails. Sessions are engine-scoped, so switching engines never crosses conversations.
|
|
29
29
|
|
|
30
30
|
## What it cannot do
|
|
31
31
|
|
|
@@ -121,6 +121,7 @@ The `activate_skill` catalog mirrors pi's directory-based skill discovery: the t
|
|
|
121
121
|
/agy status, or open the full settings picker (TUI)
|
|
122
122
|
/agy status print current settings + session counts
|
|
123
123
|
/agy doctor bridge state, driver counters, bridge port, last lifecycle events
|
|
124
|
+
/agy auth run the antigravity-acp sign-in now (engine acp): opens the Google login in your browser, shows the URL when no browser opens
|
|
124
125
|
/agy mode plan review-only: agy plans but writes nothing
|
|
125
126
|
/agy mode accept-edits agy applies edits directly (default)
|
|
126
127
|
/agy permissions on|off auto-approve / prompt for tool calls (see warning)
|
|
@@ -132,7 +133,7 @@ The `activate_skill` catalog mirrors pi's directory-based skill discovery: the t
|
|
|
132
133
|
/agy bridge all|mcp|none which pi tools the MCP bridge exposes to agy (default all; none = bridge off)
|
|
133
134
|
/agy acp-bin <path|auto> point the ACP engine at a specific server binary (auto = setup installs, or AGY_ACP_BIN; applies on the next ACP turn)
|
|
134
135
|
/agy engine acp|stream-json switch the turn engine (restart to apply; default stream-json; acp runs self-service setup: binary install + auth bootstrap)
|
|
135
|
-
/agy
|
|
136
|
+
/agy auth-manual manual ACP credential setup (fallback; auto-setup normally covers this; default login = your Antigravity subscription, same account as the agy CLI)
|
|
136
137
|
/agy patch-cleanup restore the original pi files if an older version patched them
|
|
137
138
|
/agy clear drop all session bindings (force fresh conversations)
|
|
138
139
|
```
|
|
@@ -325,7 +325,7 @@ Tested with the parity suite (section 11) and `scripts/parity-live.mjs`
|
|
|
325
325
|
| Human decision latency on parked G9 tool round-trips exceeds the 10m overall-turn cap | Turn killed mid-wait | `AcpDriver` pauses the overall timer while parked, re-armed with REMAINING budget; every park carries its own timeout (9.3) |
|
|
326
326
|
| Binary size (1.5 GB + 117 MB) | Disk + update churn | Pinned install layout (section 12), registry pin by build id |
|
|
327
327
|
| aarch64 TCMalloc startup failure (forum report, Chromebook) | arch-specific | x86_64 unaffected; gate install per-arch, link the forum issue in README |
|
|
328
|
-
| Separate auth state from `agy` CLI | First-run auth friction | `/agy
|
|
328
|
+
| Separate auth state from `agy` CLI | First-run auth friction | `/agy auth-manual` prints exact instructions; `gemini-api-key` path works headless via `GEMINI_API_KEY`. The agent never writes credentials |
|
|
329
329
|
| Thought text changes rendering volume | Noisy transcript | Route through the existing thinking block pipeline, close-on-switch unchanged; no new block types |
|
|
330
330
|
| Two engines drift on behavior | Confusing support surface | Shared provider layer + shared parity suite run against both engines in CI |
|
|
331
331
|
|
|
@@ -827,7 +827,7 @@ Install layout:
|
|
|
827
827
|
request (issue) once we depend on this.
|
|
828
828
|
- `--uid=` from the linux registry entry: the server ran without it here.
|
|
829
829
|
Treat as a launcher artifact; revisit if a future build refuses to start.
|
|
830
|
-
- Auth onboarding: `/agy
|
|
830
|
+
- Auth onboarding: `/agy auth-manual` prints the four methods with exact
|
|
831
831
|
`settings.json` shapes (source: official Zed docs, section 2.3). Headless
|
|
832
832
|
path: `GEMINI_API_KEY` + `auth.type: "gemini-api-key"`. The agent NEVER
|
|
833
833
|
writes or reads credentials; it prints instructions and verifies by
|
package/docs/DEVELOPMENT.md
CHANGED
|
@@ -37,7 +37,7 @@ AGY_LIVE=1 node --experimental-strip-types scripts/smoke-stream-json.mjs
|
|
|
37
37
|
|
|
38
38
|
# Live smoke for the ACP engine through OUR driver stack. OPT-IN: spends a
|
|
39
39
|
# little quota. Needs AGY_ACP_BIN (or acp on PATH) and a one-time
|
|
40
|
-
# /agy
|
|
40
|
+
# /agy auth-manual credential setup.
|
|
41
41
|
AGY_ACP_LIVE=1 AGY_ACP_BIN=~/.local/opt/agy-acp/current/agy_acp_server.par \
|
|
42
42
|
npx tsx scripts/smoke-acp.mjs
|
|
43
43
|
|
package/extensions/index.ts
CHANGED
|
@@ -40,6 +40,7 @@ import { SessionStore } from "../src/sessions.js";
|
|
|
40
40
|
import { ToolRoundTrips, WrapperReplay, createStreamSimple } from "../src/provider.js";
|
|
41
41
|
import { AgyDriver } from "../src/driver.js";
|
|
42
42
|
import { AcpDriver } from "../src/acp/driver.js";
|
|
43
|
+
import { runAcpAuth } from "../src/acp/auth.js";
|
|
43
44
|
import { setupAuthUrlCapture } from "../src/acp/browser-capture.js";
|
|
44
45
|
import { ensureAcpReady, inspectAcpSetup } from "../src/acp/setup.js";
|
|
45
46
|
import type { TurnDriver } from "../src/driver-types.js";
|
|
@@ -135,24 +136,27 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
135
136
|
"unsupported-server-request",
|
|
136
137
|
]);
|
|
137
138
|
const legacyDriver = new AgyDriver();
|
|
139
|
+
// Shared ACP log sink (driver turns AND /agy auth): the login URL event
|
|
140
|
+
// toasts so SSH users can copy it; genuine failures reach stderr.
|
|
141
|
+
const acpLog = (msg: string, data?: unknown): void => {
|
|
142
|
+
if (msg === "auth-url") {
|
|
143
|
+
const { url, port } = (data ?? {}) as { url?: string; port?: number | null };
|
|
144
|
+
if (!url) return;
|
|
145
|
+
const ssh = port ? `\nSSH session? Forward the port on your machine first:\n ssh -N -L ${port}:127.0.0.1:${port} <user@host>` : "";
|
|
146
|
+
const text = `Google sign-in URL for the ACP engine:\n${url}${ssh}`;
|
|
147
|
+
if (activeUi) activeUi.notify(text, "warning");
|
|
148
|
+
else console.error(`[antigravity-bridge acp] ${text}`);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (!acpFailures.has(msg)) return;
|
|
152
|
+
console.error(`[antigravity-bridge acp] ${msg}${data !== undefined ? " " + JSON.stringify(data) : ""}`);
|
|
153
|
+
};
|
|
138
154
|
const acpDriver = new AcpDriver({
|
|
139
155
|
// Resolved per connection: the setup flow can install the binary and
|
|
140
156
|
// update acp.bin mid-session; the next turn picks it up (no restart).
|
|
141
157
|
bin: () => loadConfig().acp.bin,
|
|
142
158
|
...(authCapture ? { extraEnv: authCapture.browserEnv, authUrlFile: authCapture.file } : {}),
|
|
143
|
-
log:
|
|
144
|
-
if (msg === "auth-url") {
|
|
145
|
-
const { url, port } = (data ?? {}) as { url?: string; port?: number | null };
|
|
146
|
-
if (!url) return;
|
|
147
|
-
const ssh = port ? `\nSSH session? Forward the port on your machine first:\n ssh -N -L ${port}:127.0.0.1:${port} <user@host>` : "";
|
|
148
|
-
const text = `Google sign-in URL for the ACP engine:\n${url}${ssh}`;
|
|
149
|
-
if (activeUi) activeUi.notify(text, "warning");
|
|
150
|
-
else console.error(`[antigravity-bridge acp] ${text}`);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
if (!acpFailures.has(msg)) return;
|
|
154
|
-
console.error(`[antigravity-bridge acp] ${msg}${data !== undefined ? " " + JSON.stringify(data) : ""}`);
|
|
155
|
-
},
|
|
159
|
+
log: acpLog,
|
|
156
160
|
mcpServers: () => {
|
|
157
161
|
const handle = mcpHandle;
|
|
158
162
|
if (!handle) return [];
|
|
@@ -232,6 +236,8 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
232
236
|
acpDriver,
|
|
233
237
|
engine,
|
|
234
238
|
getMcpPort: () => mcpHandle?.port ?? null,
|
|
239
|
+
acpLog,
|
|
240
|
+
authCapture: authCapture ?? null,
|
|
235
241
|
});
|
|
236
242
|
|
|
237
243
|
// AskAntigravity tool: one-shot delegation to agy (ported from
|
|
@@ -299,7 +305,7 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
299
305
|
saveConfig({ acp: { bin: status.bin, permissions: loadConfig().acp.permissions } });
|
|
300
306
|
}
|
|
301
307
|
if (status.needsLogin) {
|
|
302
|
-
const msg = acpLoginPending(
|
|
308
|
+
const msg = acpLoginPending();
|
|
303
309
|
if (ctx.hasUI) ctx.ui.notify(msg, "warning");
|
|
304
310
|
else console.error(`[antigravity-bridge] ${msg}`);
|
|
305
311
|
}
|
|
@@ -416,11 +422,11 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
416
422
|
// --- /agy command -----------------------------------------------------------
|
|
417
423
|
|
|
418
424
|
/** Shared body for every ACP-login-pending moment (session_start self-heal,
|
|
419
|
-
* /agy engine acp
|
|
420
|
-
* account.
|
|
421
|
-
*
|
|
422
|
-
function acpLoginPending(
|
|
423
|
-
return `One-time sign-in needed to finish ACP setup.
|
|
425
|
+
* /agy engine acp). End-user simple: what to run, what happens, which
|
|
426
|
+
* account. Sign-in is explicit (/agy auth); it never rides the first
|
|
427
|
+
* message. */
|
|
428
|
+
function acpLoginPending(): string {
|
|
429
|
+
return `One-time sign-in needed to finish ACP setup. Run /agy auth: the Google sign-in opens in your browser. Use the Google account of your Antigravity subscription (the same account as your agy CLI login). If no browser opens, pi shows the sign-in URL to copy. The token stays on your machine; this extension never sees it.`;
|
|
424
430
|
}
|
|
425
431
|
|
|
426
432
|
interface AgyCommandCtx {
|
|
@@ -432,6 +438,11 @@ interface AgyCommandCtx {
|
|
|
432
438
|
/** Engine latched at extension load (see the provider wiring note). */
|
|
433
439
|
engine: Engine;
|
|
434
440
|
getMcpPort: () => number | null;
|
|
441
|
+
/** Shared ACP log sink (login URL surfacing + failure events). */
|
|
442
|
+
acpLog: (msg: string, data?: unknown) => void;
|
|
443
|
+
/** BROWSER-capture handles; null when unavailable (Windows, unwritable
|
|
444
|
+
* data dir). /agy auth passes them to the sign-in process. */
|
|
445
|
+
authCapture: { browserEnv: Record<string, string>; file: string } | null;
|
|
435
446
|
}
|
|
436
447
|
|
|
437
448
|
interface PendingConfig {
|
|
@@ -467,7 +478,7 @@ function statusText(ctx: AgyCommandCtx): string {
|
|
|
467
478
|
row("digest:", config.digest ? "on" : "off"),
|
|
468
479
|
row("system prompt:", config.systemPrompt ? "on" : "off"),
|
|
469
480
|
"",
|
|
470
|
-
"Subcommands: /agy engine stream-json|acp, /agy mode plan|accept-edits, /agy permissions on|off, /agy ask on|off, /agy model <alias>, /agy thinking low|medium|high, /agy bridge all|mcp|none, /agy digest on|off, /agy system-prompt on|off, /agy acp-bin <path|auto>, /agy
|
|
481
|
+
"Subcommands: /agy auth, /agy auth-manual, /agy engine stream-json|acp, /agy mode plan|accept-edits, /agy permissions on|off, /agy ask on|off, /agy model <alias>, /agy thinking low|medium|high, /agy bridge all|mcp|none, /agy digest on|off, /agy system-prompt on|off, /agy acp-bin <path|auto>, /agy patch-cleanup, /agy clear",
|
|
471
482
|
].join("\n");
|
|
472
483
|
}
|
|
473
484
|
|
|
@@ -475,7 +486,7 @@ function statusText(ctx: AgyCommandCtx): string {
|
|
|
475
486
|
function registerAgyCommand(pi: ExtensionAPI, ctx: AgyCommandCtx): void {
|
|
476
487
|
pi.registerCommand("agy", {
|
|
477
488
|
description:
|
|
478
|
-
"Antigravity provider: status, doctor, settings picker, clear sessions. Usage: /agy [status|doctor|engine stream-json|acp|mode plan|accept-edits|permissions on|off|ask on|off|model <alias>|thinking low|medium|high|bridge all|mcp|none|digest on|off|system-prompt on|off|acp-bin <path|auto>|
|
|
489
|
+
"Antigravity provider: status, doctor, settings picker, clear sessions. Usage: /agy [status|doctor|auth|auth-manual|engine stream-json|acp|mode plan|accept-edits|permissions on|off|ask on|off|model <alias>|thinking low|medium|high|bridge all|mcp|none|digest on|off|system-prompt on|off|acp-bin <path|auto>|patch-cleanup|clear]",
|
|
479
490
|
handler: async (args, cmdCtx: ExtensionCommandContext) => {
|
|
480
491
|
const ui = cmdCtx.ui;
|
|
481
492
|
if (ui) activeUi = ui;
|
|
@@ -535,7 +546,7 @@ function registerAgyCommand(pi: ExtensionAPI, ctx: AgyCommandCtx): void {
|
|
|
535
546
|
saveConfig({ acp: { bin: status.bin, permissions: loadConfig().acp.permissions } });
|
|
536
547
|
if (status.needsLogin) {
|
|
537
548
|
ui?.notify(
|
|
538
|
-
`ACP engine set. ${acpLoginPending(
|
|
549
|
+
`ACP engine set. ${acpLoginPending()}`,
|
|
539
550
|
"warning",
|
|
540
551
|
);
|
|
541
552
|
} else {
|
|
@@ -546,6 +557,42 @@ function registerAgyCommand(pi: ExtensionAPI, ctx: AgyCommandCtx): void {
|
|
|
546
557
|
}
|
|
547
558
|
return;
|
|
548
559
|
}
|
|
560
|
+
if (sub === "auth") {
|
|
561
|
+
// Gate on the CONFIGURED engine (disk + env), not the latched one:
|
|
562
|
+
// /agy engine acp followed by /agy auth in the same session works,
|
|
563
|
+
// no restart needed before signing in.
|
|
564
|
+
if (loadConfig().engine !== "acp") {
|
|
565
|
+
ui?.notify(`the selected engine is ${loadConfig().engine}. /agy engine acp first, then /agy auth.`, "warning");
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
ui?.notify("Preparing the ACP server (binary + auth settings)…", "info");
|
|
569
|
+
const status = await ensureAcpReady({ configBin: loadConfig().acp.bin, onProgress: (m) => ui?.notify(m, "info") });
|
|
570
|
+
if (!status.ok) {
|
|
571
|
+
ui?.notify(`ACP auto-setup failed (${status.error}).\n${status.manual}`, "warning");
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
saveConfig({ acp: { bin: status.bin, permissions: loadConfig().acp.permissions } });
|
|
575
|
+
if (!status.needsLogin) {
|
|
576
|
+
ui?.notify(`Already signed in (auth: ${status.auth}). Nothing to do.`, "info");
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
ui?.notify(
|
|
580
|
+
"Signing in: the Google sign-in opens in your browser and completes when you finish it (minutes-scale). If no browser opens, pi shows the sign-in URL to copy.",
|
|
581
|
+
"info",
|
|
582
|
+
);
|
|
583
|
+
const r = await runAcpAuth({
|
|
584
|
+
bin: status.bin,
|
|
585
|
+
extraEnv: ctx.authCapture?.browserEnv,
|
|
586
|
+
authUrlFile: ctx.authCapture?.file,
|
|
587
|
+
log: ctx.acpLog,
|
|
588
|
+
});
|
|
589
|
+
if (r.ok) {
|
|
590
|
+
ui?.notify("Signed in. The ACP engine is ready; takes effect on the next pi start (or /reload).", "info");
|
|
591
|
+
} else {
|
|
592
|
+
ui?.notify(`ACP sign-in failed (${r.error}).\nRun /agy auth to retry; /agy auth-manual has manual steps.`, "warning");
|
|
593
|
+
}
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
549
596
|
if (sub === "acp-bin") {
|
|
550
597
|
const rest = (args ?? "").trim().split(/\s+/).slice(1).join(" ");
|
|
551
598
|
if (rest.length > 0) {
|
|
@@ -564,7 +611,7 @@ function registerAgyCommand(pi: ExtensionAPI, ctx: AgyCommandCtx): void {
|
|
|
564
611
|
}
|
|
565
612
|
return;
|
|
566
613
|
}
|
|
567
|
-
if (sub === "
|
|
614
|
+
if (sub === "auth-manual") {
|
|
568
615
|
ui?.notify(
|
|
569
616
|
[
|
|
570
617
|
"ACP engine authentication (one-time; usually automatic -",
|
|
@@ -580,16 +627,16 @@ function registerAgyCommand(pi: ExtensionAPI, ctx: AgyCommandCtx): void {
|
|
|
580
627
|
"1. Server binary: auto-setup installs it. Manual: agy_acp_server.par from",
|
|
581
628
|
" the antigravity-acp registry; point acp.bin or AGY_ACP_BIN at it.",
|
|
582
629
|
'2. Default: put {"auth":{"type":"oauth-personal"}} in',
|
|
583
|
-
" ~/.gemini/antigravity-acp/settings.json, run
|
|
584
|
-
" Google login that opens in your browser. No browser (SSH
|
|
585
|
-
" pi shows the sign-in URL to copy; forward the redirect
|
|
586
|
-
" (ssh -N -L <port>:127.0.0.1:<port> <user@host>), then
|
|
587
|
-
" on your machine.",
|
|
630
|
+
" ~/.gemini/antigravity-acp/settings.json, run /agy auth, and complete",
|
|
631
|
+
" the Google login that opens in your browser. No browser (SSH",
|
|
632
|
+
" session)? pi shows the sign-in URL to copy; forward the redirect",
|
|
633
|
+
" port over ssh (ssh -N -L <port>:127.0.0.1:<port> <user@host>), then",
|
|
634
|
+
" open the URL on your machine.",
|
|
588
635
|
' Headless alternative: GEMINI_API_KEY + {"auth":{"type":"gemini-api-key"}}',
|
|
589
636
|
" (metered paid API - not your Antigravity plan). The key is used only",
|
|
590
637
|
" when that type is selected; with the default oauth-personal in place,",
|
|
591
638
|
" an exported key is ignored.",
|
|
592
|
-
"3.
|
|
639
|
+
"3. /agy doctor shows the server version when auth is OK.",
|
|
593
640
|
].join("\n"),
|
|
594
641
|
"info",
|
|
595
642
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estebanforge/pi-antigravity-bridge",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"description": "Gemini provider for Pi on the Antigravity ACP server (official Google ACP) or the stream-json agy CLI. antigravity/* models in Pi's /model picker, no-patch MCP bridge: agy runs Pi's tools. ToS safe to use.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
package/src/acp/auth.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { AcpConnection } from "./connection.js";
|
|
2
|
+
import { hasAcpToken } from "./setup.js";
|
|
3
|
+
|
|
4
|
+
// Explicit sign-in (/agy auth): spawn a short-lived server, send
|
|
5
|
+
// `authenticate` (the RPC that fires the loopback listener + browser OAuth
|
|
6
|
+
// flow), and wait for the token to land in the shared acp_token.json. A
|
|
7
|
+
// dedicated process keeps the minutes-scale login ritual away from live
|
|
8
|
+
// turns; the next driver connection picks the token up. The real server
|
|
9
|
+
// blocks until the browser round-trip completes; the observed window is
|
|
10
|
+
// minutes-scale (one flow timed out at ~8.5 minutes), so the timeout is
|
|
11
|
+
// generous.
|
|
12
|
+
|
|
13
|
+
export const AUTH_TIMEOUT_MS = 10 * 60_000;
|
|
14
|
+
|
|
15
|
+
export interface AcpAuthOptions {
|
|
16
|
+
bin: string;
|
|
17
|
+
binArgs?: string[];
|
|
18
|
+
cwd?: string;
|
|
19
|
+
extraEnv?: Record<string, string>;
|
|
20
|
+
authUrlFile?: string;
|
|
21
|
+
/** The server is expected to have written acp_token.json by the time
|
|
22
|
+
* authenticate replies, but write-after-reply is unverified; after a
|
|
23
|
+
* successful reply the run polls for the token up to this long before
|
|
24
|
+
* SIGTERM, so a laggard write is never killed mid-flight. */
|
|
25
|
+
tokenGraceMs?: number;
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
log?: (msg: string, data?: unknown) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface AcpAuthResult {
|
|
31
|
+
ok: boolean;
|
|
32
|
+
/** Failure reason (spawn, timeout, -32000 family, concurrent run). Absent when ok. */
|
|
33
|
+
error?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let authInFlight: Promise<AcpAuthResult> | null = null;
|
|
37
|
+
|
|
38
|
+
export function runAcpAuth(opts: AcpAuthOptions): Promise<AcpAuthResult> {
|
|
39
|
+
const conn = new AcpConnection({
|
|
40
|
+
bin: opts.bin,
|
|
41
|
+
binArgs: opts.binArgs,
|
|
42
|
+
cwd: opts.cwd ?? process.cwd(),
|
|
43
|
+
extraEnv: opts.extraEnv,
|
|
44
|
+
authUrlFile: opts.authUrlFile,
|
|
45
|
+
log: opts.log ?? (() => {}),
|
|
46
|
+
onUpdate: () => {},
|
|
47
|
+
onExit: () => {},
|
|
48
|
+
});
|
|
49
|
+
const sleep = (ms: number): Promise<void> => new Promise((r) => setTimeout(r, ms));
|
|
50
|
+
const grace = opts.tokenGraceMs ?? 5_000;
|
|
51
|
+
const run = async (): Promise<AcpAuthResult> => {
|
|
52
|
+
try {
|
|
53
|
+
await conn.start();
|
|
54
|
+
await conn.request("authenticate", { methodId: "oauth-personal" }, opts.timeoutMs ?? AUTH_TIMEOUT_MS);
|
|
55
|
+
const deadline = Date.now() + grace;
|
|
56
|
+
while (!hasAcpToken() && Date.now() < deadline) await sleep(200);
|
|
57
|
+
return { ok: true };
|
|
58
|
+
} catch (err) {
|
|
59
|
+
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
60
|
+
} finally {
|
|
61
|
+
conn.kill();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
// One sign-in at a time: two concurrent runs would race the OAuth loopback
|
|
65
|
+
// and the token write. A second invocation fails fast instead.
|
|
66
|
+
if (authInFlight) return Promise.resolve({ ok: false, error: "a sign-in is already running; wait for it to finish" });
|
|
67
|
+
authInFlight = run();
|
|
68
|
+
return authInFlight.finally(() => {
|
|
69
|
+
authInFlight = null;
|
|
70
|
+
});
|
|
71
|
+
}
|
package/src/acp/connection.ts
CHANGED
|
@@ -38,7 +38,7 @@ export interface AcpSessionInfo {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/** Auth failed (-32000 family). Message carries the remediation the server
|
|
41
|
-
* provided plus the /agy
|
|
41
|
+
* provided plus the /agy auth-manual pointer. */
|
|
42
42
|
export class AcpAuthError extends Error {
|
|
43
43
|
constructor(message: string) {
|
|
44
44
|
super(message);
|
|
@@ -424,7 +424,7 @@ export function translateError(method: string, err: unknown): Error {
|
|
|
424
424
|
if (err.code === -32000) {
|
|
425
425
|
const detail = typeof err.data === "object" && err.data !== null ? (err.data as { message?: unknown }).message : undefined;
|
|
426
426
|
const detailText = typeof detail === "string" ? `: ${detail}` : `: ${err.message}`;
|
|
427
|
-
return new AcpAuthError(`ACP authentication required for ${method}${detailText}. Run /agy
|
|
427
|
+
return new AcpAuthError(`ACP authentication required for ${method}${detailText}. Run /agy auth to sign in; /agy auth-manual has manual steps.`);
|
|
428
428
|
}
|
|
429
429
|
// Typed protocol errors survive: callers probe .code (-32601 cancel-
|
|
430
430
|
// unsupported, -32602 param shape). The method prefix is lost — describe()
|
package/src/acp/setup.ts
CHANGED
|
@@ -48,8 +48,8 @@ export type AcpSetupStatus =
|
|
|
48
48
|
bin: string;
|
|
49
49
|
binarySource: "env" | "config" | "installed" | "existing";
|
|
50
50
|
auth: string;
|
|
51
|
-
/** True when auth was just set to oauth-personal:
|
|
52
|
-
* Google login in the browser
|
|
51
|
+
/** True when auth was just set to oauth-personal: /agy auth opens
|
|
52
|
+
* the Google login in the browser. */
|
|
53
53
|
needsLogin: boolean;
|
|
54
54
|
/** Human-readable actions taken (empty when everything was ready). */
|
|
55
55
|
actions: string[];
|
|
@@ -70,10 +70,10 @@ export const MANUAL_SETUP = [
|
|
|
70
70
|
" (~/.local/opt/agy-acp/current/agy_acp_server.par works; 'current' is a",
|
|
71
71
|
" symlink to the build dir).",
|
|
72
72
|
'3. Log in: put {"auth":{"type":"oauth-personal"}} in',
|
|
73
|
-
" ~/.gemini/antigravity-acp/settings.json and
|
|
74
|
-
" opens in your browser
|
|
73
|
+
" ~/.gemini/antigravity-acp/settings.json and run /agy auth, then complete",
|
|
74
|
+
" the Google login that opens in your browser. That login IS your",
|
|
75
75
|
" Antigravity subscription (Google AI Plus/Pro/Ultra).",
|
|
76
|
-
"Details: /agy
|
|
76
|
+
"Details: /agy auth-manual",
|
|
77
77
|
].join("\n");
|
|
78
78
|
|
|
79
79
|
export function platformKey(): string {
|
|
@@ -239,6 +239,11 @@ function tokenPresent(target: string): boolean {
|
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
+
/** Whether a login token exists (default dir, or an explicit one). */
|
|
243
|
+
export function hasAcpToken(dir?: string): boolean {
|
|
244
|
+
return tokenPresent(dir ?? path.join(os.homedir(), ".gemini", "antigravity-acp"));
|
|
245
|
+
}
|
|
246
|
+
|
|
242
247
|
/** Auth state WITHOUT reading any credential value: settings.json carries
|
|
243
248
|
* only auth.type (+ non-secret gcp placement), acp_token.json is stat()ed. */
|
|
244
249
|
export function readAuthState(dir?: string): AuthState {
|
|
@@ -334,7 +339,7 @@ export async function ensureAcpReady(opts: SetupOptions = {}): Promise<AcpSetupS
|
|
|
334
339
|
// before the first spawn, so a fresh write takes effect. oauth-personal is
|
|
335
340
|
// THE default: it is the Antigravity subscription (same Google account and
|
|
336
341
|
// plan as the agy CLI login). gemini-api-key (metered paid API) stays a
|
|
337
|
-
// manual option for headless boxes (/agy
|
|
342
|
+
// manual option for headless boxes (/agy auth-manual); never the default.
|
|
338
343
|
const gdir = defaultGeminiDir(opts);
|
|
339
344
|
const auth = readAuthState(gdir);
|
|
340
345
|
if (!auth.configured) {
|