@aibridge/driver-agy 0.9.0 → 0.9.2

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/README.md CHANGED
@@ -1,11 +1,14 @@
1
1
  # @aibridge/driver-agy
2
2
 
3
- Antigravity (`agy`) CLI driver for [aibridge](https://github.com/ycmjason/aibridge): build print-mode invocations, probe availability, run delegated tasks (including the answer-file capture protocol), and read Antigravity quota windows.
3
+ Driver for the Antigravity (`agy`) CLI. It builds print-mode commands, checks
4
+ availability, runs delegated tasks, captures answer files, and reads quota
5
+ windows.
4
6
 
5
7
  ```ts
6
8
  import { probe, run, fetchAgyQuota } from '@aibridge/driver-agy';
7
9
  ```
8
10
 
9
- Requires the `agy` CLI on `PATH` and authed. Part of the [aibridge](https://github.com/ycmjason/aibridge) monorepo — the agent skill + CLI that lets coding agents drive models from other providers.
11
+ Requires an authenticated `agy` CLI on `PATH`. Part of the
12
+ [aibridge](https://github.com/ycmjason/aibridge) monorepo.
10
13
 
11
14
  [MIT](https://github.com/ycmjason/aibridge/blob/main/LICENSE)
package/dist/index.d.mts CHANGED
@@ -27,11 +27,15 @@ declare function buildAgyPrintArgs(prompt: string, opts: AgyPrintArgs): string[]
27
27
  * token — no separate login. Mechanism learned from
28
28
  * github.com/skainguyen1412/antigravity-usage (reimplemented, not vendored):
29
29
  *
30
- * 1. Read `~/.gemini/antigravity-cli/antigravity-oauth-token`
31
- * ({ token: { access_token, refresh_token, expiry } }) — agy refreshes
32
- * this file itself whenever it runs. If expired, refresh in-memory via
33
- * Google's token endpoint with Antigravity's installed-app client
34
- * (public by design for installed apps); we NEVER write agy's file.
30
+ * 1. Read agy's credential — the OS keyring entry (go-keyring, service
31
+ * `gemini`, account `antigravity`) first, then the fallback file
32
+ * `~/.gemini/antigravity-cli/antigravity-oauth-token`. Both hold
33
+ * { token: { access_token, refresh_token, expiry }, auth_method }; agy
34
+ * only writes the file when the keyring is bypassed or unreachable, so
35
+ * the file goes stale once the keyring works. If expired, refresh
36
+ * in-memory via Google's token endpoint with Antigravity's installed-app
37
+ * client (public by design for installed apps); we NEVER write agy's
38
+ * store.
35
39
  * 2. POST cloudcode-pa.googleapis.com/v1internal:loadCodeAssist
36
40
  * (metadata ideType ANTIGRAVITY / pluginType GEMINI) → project id.
37
41
  * 3. POST /v1internal:fetchAvailableModels { project } — the
package/dist/index.mjs CHANGED
@@ -36,11 +36,15 @@ const AGY_CANONICAL_TO_NATIVE = {
36
36
  * token — no separate login. Mechanism learned from
37
37
  * github.com/skainguyen1412/antigravity-usage (reimplemented, not vendored):
38
38
  *
39
- * 1. Read `~/.gemini/antigravity-cli/antigravity-oauth-token`
40
- * ({ token: { access_token, refresh_token, expiry } }) — agy refreshes
41
- * this file itself whenever it runs. If expired, refresh in-memory via
42
- * Google's token endpoint with Antigravity's installed-app client
43
- * (public by design for installed apps); we NEVER write agy's file.
39
+ * 1. Read agy's credential — the OS keyring entry (go-keyring, service
40
+ * `gemini`, account `antigravity`) first, then the fallback file
41
+ * `~/.gemini/antigravity-cli/antigravity-oauth-token`. Both hold
42
+ * { token: { access_token, refresh_token, expiry }, auth_method }; agy
43
+ * only writes the file when the keyring is bypassed or unreachable, so
44
+ * the file goes stale once the keyring works. If expired, refresh
45
+ * in-memory via Google's token endpoint with Antigravity's installed-app
46
+ * client (public by design for installed apps); we NEVER write agy's
47
+ * store.
44
48
  * 2. POST cloudcode-pa.googleapis.com/v1internal:loadCodeAssist
45
49
  * (metadata ideType ANTIGRAVITY / pluginType GEMINI) → project id.
46
50
  * 3. POST /v1internal:fetchAvailableModels { project } — the
@@ -70,9 +74,53 @@ function parseQuotaGroups(groups) {
70
74
  function agyTokenPath() {
71
75
  return process.env.AGY_OAUTH_TOKEN_PATH ?? join(homedir(), ".gemini", "antigravity-cli", "antigravity-oauth-token");
72
76
  }
77
+ const KEYRING_B64_PREFIX = "go-keyring-base64:";
78
+ /**
79
+ * go-keyring base64-wraps the secret on macOS (`go-keyring-base64:` prefix)
80
+ * and stores it raw on Linux. Returns undefined unless the result parses as
81
+ * the token JSON, so a malformed keyring entry falls through to the file.
82
+ */
83
+ function decodeKeyringSecret(raw) {
84
+ const s = raw.trim();
85
+ const json = s.startsWith(KEYRING_B64_PREFIX) ? Buffer.from(s.slice(18), "base64").toString("utf8") : s;
86
+ try {
87
+ const parsed = JSON.parse(json);
88
+ return parsed && typeof parsed === "object" ? parsed : void 0;
89
+ } catch {
90
+ return;
91
+ }
92
+ }
93
+ async function readKeyringCredential() {
94
+ const cmd = {
95
+ darwin: ["security", [
96
+ "find-generic-password",
97
+ "-s",
98
+ "gemini",
99
+ "-a",
100
+ "antigravity",
101
+ "-w"
102
+ ]],
103
+ linux: ["secret-tool", [
104
+ "lookup",
105
+ "service",
106
+ "gemini",
107
+ "username",
108
+ "antigravity"
109
+ ]]
110
+ }[process.platform];
111
+ if (!cmd) return void 0;
112
+ const res = await runCaptured(cmd[0], cmd[1], { timeoutMs: 5e3 }).catch(() => void 0);
113
+ return res?.code === 0 ? decodeKeyringSecret(res.stdout) : void 0;
114
+ }
115
+ async function readAgyCredential() {
116
+ if (!process.env.AGY_OAUTH_TOKEN_PATH) {
117
+ const fromKeyring = await readKeyringCredential();
118
+ if (fromKeyring) return fromKeyring;
119
+ }
120
+ return JSON.parse(readFileSync(agyTokenPath(), "utf8"));
121
+ }
73
122
  async function getAccessToken() {
74
- const raw = readFileSync(agyTokenPath(), "utf8");
75
- const parsed = JSON.parse(raw);
123
+ const parsed = await readAgyCredential();
76
124
  const access = parsed.token?.access_token;
77
125
  const refresh = parsed.token?.refresh_token;
78
126
  const expiry = parsed.token?.expiry;
@@ -160,7 +208,7 @@ function findModelQuota(snapshot, labelOrId) {
160
208
  }
161
209
  //#endregion
162
210
  //#region src/probe.ts
163
- const INSTALL_HINT$1 = "Install the Antigravity CLI and sign in.";
211
+ const INSTALL_HINT = "Install the Antigravity CLI and sign in.";
164
212
  async function probe(run = runCaptured) {
165
213
  try {
166
214
  const res = await run("agy", ["--version"], { timeoutMs: 1e4 });
@@ -175,12 +223,12 @@ async function probe(run = runCaptured) {
175
223
  };
176
224
  return {
177
225
  ok: false,
178
- error: `aibridge: "agy" returned no version output. ${INSTALL_HINT$1}`
226
+ error: `aibridge: "agy" returned no version output. ${INSTALL_HINT}`
179
227
  };
180
228
  } catch (err) {
181
229
  if (isNotFound(err)) return {
182
230
  ok: false,
183
- error: `aibridge: "agy" not found on PATH. ${INSTALL_HINT$1}`
231
+ error: `aibridge: "agy" not found on PATH. ${INSTALL_HINT}`
184
232
  };
185
233
  return {
186
234
  ok: false,
@@ -314,7 +362,6 @@ function mtime(path) {
314
362
  //#endregion
315
363
  //#region src/run.ts
316
364
  const NOISE_RE = /^Shell cwd was reset[^\n]*$/gm;
317
- const INSTALL_HINT = "Install the Antigravity CLI and sign in.";
318
365
  function clean(s) {
319
366
  return stripAnsi(s).replace(NOISE_RE, "").trim();
320
367
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aibridge/driver-agy",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Antigravity (agy) CLI driver for aibridge",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,6 +1,6 @@
1
1
  import assert from 'node:assert/strict';
2
2
  import { test } from 'vitest';
3
- import { findModelQuota, parseModels, parseQuotaGroups } from './agyQuota.ts';
3
+ import { decodeKeyringSecret, findModelQuota, parseModels, parseQuotaGroups } from './agyQuota.ts';
4
4
 
5
5
  test('parseQuotaGroups preserves fractions or defaults to 0 if absent', () => {
6
6
  const groups = [
@@ -124,3 +124,20 @@ test('findModelQuota hits modelId id-form', () => {
124
124
  const found = findModelQuota(snapshot, 'gemini-3.7-flash-high');
125
125
  assert.equal(found?.modelId, 'gemini-3.7-flash-high');
126
126
  });
127
+
128
+ test('decodeKeyringSecret accepts raw JSON (linux) and go-keyring base64 (macOS)', () => {
129
+ const token = {
130
+ token: { access_token: 'a', refresh_token: 'r', expiry: '2026-01-01T00:00:00Z' },
131
+ };
132
+ const json = JSON.stringify(token);
133
+ assert.deepEqual(decodeKeyringSecret(`${json}\n`), token);
134
+ const b64 = Buffer.from(json).toString('base64');
135
+ assert.deepEqual(decodeKeyringSecret(`go-keyring-base64:${b64}\n`), token);
136
+ });
137
+
138
+ test('decodeKeyringSecret returns undefined for malformed payloads so the file fallback runs', () => {
139
+ assert.equal(decodeKeyringSecret(''), undefined);
140
+ assert.equal(decodeKeyringSecret('not json'), undefined);
141
+ assert.equal(decodeKeyringSecret('go-keyring-base64:!!!'), undefined);
142
+ assert.equal(decodeKeyringSecret('"a string"'), undefined);
143
+ });
package/src/agyQuota.ts CHANGED
@@ -3,11 +3,15 @@
3
3
  * token — no separate login. Mechanism learned from
4
4
  * github.com/skainguyen1412/antigravity-usage (reimplemented, not vendored):
5
5
  *
6
- * 1. Read `~/.gemini/antigravity-cli/antigravity-oauth-token`
7
- * ({ token: { access_token, refresh_token, expiry } }) — agy refreshes
8
- * this file itself whenever it runs. If expired, refresh in-memory via
9
- * Google's token endpoint with Antigravity's installed-app client
10
- * (public by design for installed apps); we NEVER write agy's file.
6
+ * 1. Read agy's credential — the OS keyring entry (go-keyring, service
7
+ * `gemini`, account `antigravity`) first, then the fallback file
8
+ * `~/.gemini/antigravity-cli/antigravity-oauth-token`. Both hold
9
+ * { token: { access_token, refresh_token, expiry }, auth_method }; agy
10
+ * only writes the file when the keyring is bypassed or unreachable, so
11
+ * the file goes stale once the keyring works. If expired, refresh
12
+ * in-memory via Google's token endpoint with Antigravity's installed-app
13
+ * client (public by design for installed apps); we NEVER write agy's
14
+ * store.
11
15
  * 2. POST cloudcode-pa.googleapis.com/v1internal:loadCodeAssist
12
16
  * (metadata ideType ANTIGRAVITY / pluginType GEMINI) → project id.
13
17
  * 3. POST /v1internal:fetchAvailableModels { project } — the
@@ -21,7 +25,7 @@
21
25
  import { readFileSync } from 'node:fs';
22
26
  import { homedir } from 'node:os';
23
27
  import { join } from 'node:path';
24
- import { AuthExpiredError } from '@aibridge/proc';
28
+ import { AuthExpiredError, runCaptured } from '@aibridge/proc';
25
29
  import { AGY_CANONICAL_TO_NATIVE } from './registry.ts';
26
30
 
27
31
  const CLOUDCODE_BASE = 'https://cloudcode-pa.googleapis.com';
@@ -95,9 +99,50 @@ interface AgyTokenFile {
95
99
  token?: { access_token?: string; refresh_token?: string; expiry?: string };
96
100
  }
97
101
 
102
+ const KEYRING_B64_PREFIX = 'go-keyring-base64:';
103
+
104
+ /**
105
+ * go-keyring base64-wraps the secret on macOS (`go-keyring-base64:` prefix)
106
+ * and stores it raw on Linux. Returns undefined unless the result parses as
107
+ * the token JSON, so a malformed keyring entry falls through to the file.
108
+ */
109
+ export function decodeKeyringSecret(raw: string): AgyTokenFile | undefined {
110
+ const s = raw.trim();
111
+ const json = s.startsWith(KEYRING_B64_PREFIX)
112
+ ? Buffer.from(s.slice(KEYRING_B64_PREFIX.length), 'base64').toString('utf8')
113
+ : s;
114
+ try {
115
+ const parsed: unknown = JSON.parse(json);
116
+ return parsed && typeof parsed === 'object' ? (parsed as AgyTokenFile) : undefined;
117
+ } catch {
118
+ return undefined;
119
+ }
120
+ }
121
+
122
+ async function readKeyringCredential(): Promise<AgyTokenFile | undefined> {
123
+ const lookup: Record<string, [string, string[]]> = {
124
+ darwin: ['security', ['find-generic-password', '-s', 'gemini', '-a', 'antigravity', '-w']],
125
+ linux: ['secret-tool', ['lookup', 'service', 'gemini', 'username', 'antigravity']],
126
+ };
127
+ const cmd = lookup[process.platform];
128
+ if (!cmd) return undefined;
129
+ // ponytail: a locked keyring may pop a desktop unlock prompt that the 5s
130
+ // timeout then abandons; the file fallback covers it. Surface the reason in
131
+ // the preflight warning if this ever needs diagnosing.
132
+ const res = await runCaptured(cmd[0], cmd[1], { timeoutMs: 5_000 }).catch(() => undefined);
133
+ return res?.code === 0 ? decodeKeyringSecret(res.stdout) : undefined;
134
+ }
135
+
136
+ async function readAgyCredential(): Promise<AgyTokenFile> {
137
+ if (!process.env.AGY_OAUTH_TOKEN_PATH) {
138
+ const fromKeyring = await readKeyringCredential();
139
+ if (fromKeyring) return fromKeyring;
140
+ }
141
+ return JSON.parse(readFileSync(agyTokenPath(), 'utf8')) as AgyTokenFile;
142
+ }
143
+
98
144
  async function getAccessToken(): Promise<string> {
99
- const raw = readFileSync(agyTokenPath(), 'utf8');
100
- const parsed = JSON.parse(raw) as AgyTokenFile;
145
+ const parsed = await readAgyCredential();
101
146
  const access = parsed.token?.access_token;
102
147
  const refresh = parsed.token?.refresh_token;
103
148
  const expiry = parsed.token?.expiry;
package/src/probe.ts CHANGED
@@ -4,7 +4,7 @@ export type Availability =
4
4
  | { readonly ok: true; readonly version: string }
5
5
  | { readonly ok: false; readonly error: string };
6
6
 
7
- const INSTALL_HINT = 'Install the Antigravity CLI and sign in.';
7
+ export const INSTALL_HINT = 'Install the Antigravity CLI and sign in.';
8
8
 
9
9
  export async function probe(run: typeof runCaptured = runCaptured): Promise<Availability> {
10
10
  try {
package/src/run.ts CHANGED
@@ -3,6 +3,7 @@ import { tmpdir } from 'node:os';
3
3
  import { join } from 'node:path';
4
4
  import { isNotFound, type RunResult, runCaptured, stripAnsi } from '@aibridge/proc';
5
5
  import { buildAgyPrintArgs } from './agy.ts';
6
+ import { INSTALL_HINT } from './probe.ts';
6
7
 
7
8
  export interface DelegationTask {
8
9
  readonly prompt: string;
@@ -26,7 +27,6 @@ export type DelegationResult =
26
27
  };
27
28
 
28
29
  const NOISE_RE = /^Shell cwd was reset[^\n]*$/gm;
29
- const INSTALL_HINT = 'Install the Antigravity CLI and sign in.';
30
30
 
31
31
  function clean(s: string): string {
32
32
  return stripAnsi(s).replace(NOISE_RE, '').trim();