omp-antigravity-acp-provider 0.1.14 → 0.1.15

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
@@ -19,7 +19,7 @@ The repository keeps the OMP adapter sources separately and installs upstream ve
19
19
 
20
20
  ## Status
21
21
 
22
- Version 0.1.14 supports all models advertised by the official ACP server. Tested with macOS, OMP 18.12.3, upstream provider 0.1.15 and official ACP runtime 1.4.1. Other platforms and OMP versions are not yet verified.
22
+ Version 0.1.15 supports all models advertised by the official ACP server. Tested with macOS, OMP 18.12.3, upstream provider 0.1.15 and official ACP runtime 1.4.1. Other platforms and OMP versions are not yet verified.
23
23
 
24
24
  Google's consumer-plan policies can restrict third-party agent access even through the official CLI or ACP executable. An official transport does not establish permission to use a subscription in OMP. Check the current [Antigravity FAQ](https://www.antigravity.google/docs/faq/) and [terms](https://antigravity.google/terms) for your account.
25
25
 
@@ -56,7 +56,7 @@ Or, inside OMP:
56
56
 
57
57
  Select **omp-antigravity-acp-provider** in the browser, install it, and restart OMP to load the provider.
58
58
 
59
- OMP's marketplace installer currently copies Git content without installing npm dependencies. This marketplace therefore ships a small source launcher that retrieves the exact published **0.1.14** prebuilt npm adapter and production dependencies on first load. It disables npm install scripts, skips Pi CLI peer installation, and performs no local compilation. Node.js 22.19+ and npm must be on PATH. First preparation needs internet access and roughly **150 MiB** of disk space; later loads reuse the installed cache without npm network access.
59
+ OMP's marketplace installer currently copies Git content without installing npm dependencies. This marketplace therefore ships a small source launcher that retrieves the exact published **0.1.15** prebuilt npm adapter and production dependencies on first load. It disables npm install scripts, skips Pi CLI peer installation, and performs no local compilation. Node.js 22.19+ and npm must be on PATH. First preparation needs internet access and roughly **150 MiB** of disk space; later loads reuse the installed cache without npm network access.
60
60
 
61
61
  The launcher stores its versioned dependencies in `.runtime/` inside the installed marketplace plugin's cache directory. Uninstalling the marketplace plugin removes that cache when it is no longer referenced by another scope. Google credentials and the separately downloaded official ACP runtime are unaffected.
62
62
 
@@ -80,7 +80,7 @@ omp plugin install npm:omp-antigravity-acp-provider
80
80
  To pin a specific release:
81
81
 
82
82
  ```sh
83
- omp plugin install npm:omp-antigravity-acp-provider@0.1.14
83
+ omp plugin install npm:omp-antigravity-acp-provider@0.1.15
84
84
  ```
85
85
 
86
86
  Restart OMP after installation. The npm package includes the built adapter; users do not need esbuild or a manual build step. Disable any older ACP adapter for the same provider before loading this package.
@@ -1,6 +1,6 @@
1
1
  // Presentation only: the SDK watchdog still sees all notifications, and OMP
2
2
  // tool invocations/results travel through the separate MCP bridge.
3
- export function showAcpUpdate(notification: any, debugToolUpdates: boolean): boolean {
3
+ export function showAcpUpdate(notification: { update?: { sessionUpdate?: string } }, debugToolUpdates: boolean): boolean {
4
4
  const kind = notification.update?.sessionUpdate;
5
5
  return debugToolUpdates || (kind !== "tool_call" && kind !== "tool_call_update");
6
6
  }
@@ -0,0 +1,276 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { clearAntigravityCredentials, hasAntigravityAuth, resolveAntigravityAcpDirectory } from "./runtime.mjs";
5
+ import type { TierConnection } from "./tier-connection.ts";
6
+
7
+ export const MARKER = "pi-antigravity-acp:managed-by-antigravity";
8
+
9
+ // macOS keychain operations behind one mutable object so offline command
10
+ // tests can substitute them without touching the user's real keychain.
11
+ export const keychain = {
12
+ // Check existence only. Never retrieve credentials from the keychain.
13
+ present(): boolean | undefined {
14
+ if (process.platform !== "darwin") return undefined;
15
+ try {
16
+ execFileSync("/usr/bin/security", ["find-generic-password", "-s", "gemini", "-a", "antigravity-acp"], { stdio: "ignore", timeout: 3000 });
17
+ return true;
18
+ } catch { return false; }
19
+ },
20
+ // Local logout for macOS keychain storage. The Antigravity server owns this
21
+ // item; removing it is required for a complete logout when no token file exists.
22
+ remove(): boolean | undefined {
23
+ if (process.platform !== "darwin") return undefined;
24
+ try {
25
+ execFileSync("/usr/bin/security", ["delete-generic-password", "-s", "gemini", "-a", "antigravity-acp"], { stdio: "ignore", timeout: 3000 });
26
+ return true;
27
+ } catch { return false; }
28
+ },
29
+ // Extract only the email claim from the ACP item's stored id_token. The
30
+ // token bytes stay in this process and are never logged or persisted; the
31
+ // agy CLI's separate keychain item is never read.
32
+ accountEmail(): string | undefined {
33
+ if (process.platform !== "darwin") return undefined;
34
+ try {
35
+ const raw = execFileSync("/usr/bin/security", ["find-generic-password", "-s", "gemini", "-a", "antigravity-acp", "-w"], { timeout: 3000 });
36
+ return emailFromTokenJson(raw.toString("utf8"));
37
+ } catch { return undefined; }
38
+ },
39
+ };
40
+
41
+ function emailFromTokenJson(raw: string): string | undefined {
42
+ try {
43
+ const parsed = JSON.parse(raw) as { id_token?: unknown } | null;
44
+ const idToken = parsed?.id_token;
45
+ if (typeof idToken !== "string" || !idToken.includes(".")) return undefined;
46
+ const claims = JSON.parse(Buffer.from(idToken.split(".")[1]!, "base64url").toString("utf8")) as { email?: unknown };
47
+ return typeof claims.email === "string" && claims.email.includes("@") ? claims.email : undefined;
48
+ } catch { return undefined; }
49
+ }
50
+
51
+ // The signed-in Google account, from the ACP server's own stored token. The
52
+ // token file is preferred because it needs no keychain access.
53
+ export function antigravityAccountEmail(): string | undefined {
54
+ try {
55
+ return emailFromTokenJson(fs.readFileSync(path.join(resolveAntigravityAcpDirectory(), "acp_token.json"), "utf8"));
56
+ } catch { /* keychain storage or signed out */ }
57
+ return keychain.accountEmail();
58
+ }
59
+
60
+ // Timing knobs for following OMP-side logouts; mutable so offline tests can
61
+ // run the delayed detection without real waits.
62
+ export const logoutFollow = { delayMs: 500, retryMs: 15_000 };
63
+
64
+ export function authReady(): boolean {
65
+ return hasAntigravityAuth() || keychain.present() === true;
66
+ }
67
+
68
+ export interface OmpCommandContext {
69
+ ui: {
70
+ notify: (text: string, level?: string) => void;
71
+ input?: (message: string, placeholder?: string) => Promise<string | undefined>;
72
+ select?: (title: string, options: string[]) => Promise<string>;
73
+ };
74
+ sessionManager?: {
75
+ getSessionId?: () => string | undefined;
76
+ };
77
+ modelRegistry?: {
78
+ refreshProvider?: (provider: string, mode?: string) => Promise<void>;
79
+ authStorage?: {
80
+ credentials?: {
81
+ getOAuth?: (provider: string) => { refresh?: string; email?: string; authorizedAt?: number } | undefined;
82
+ remove?: (provider: string) => Promise<void>;
83
+ onGeneration?: (listener: () => void) => () => void;
84
+ };
85
+ keys?: {
86
+ describe?: (provider: string, sessionId?: string) => string | undefined;
87
+ };
88
+ };
89
+ };
90
+ }
91
+
92
+ // OMP stores only the non-secret marker credential. Read it defensively:
93
+ // the model registry surface is host version dependent and absent in tests.
94
+ export function ompCredentialSummary(ctx: OmpCommandContext | undefined) {
95
+ try {
96
+ const stored = ctx?.modelRegistry?.authStorage?.credentials?.getOAuth?.("antigravity-acp");
97
+ if (!stored) return { present: false };
98
+ return {
99
+ present: true,
100
+ record: stored.refresh === MARKER ? "non-secret managed marker" : "oauth credential",
101
+ email: typeof stored.email === "string" && stored.email ? stored.email : undefined,
102
+ authorizedAt: typeof stored.authorizedAt === "number" ? new Date(stored.authorizedAt).toISOString() : undefined,
103
+ };
104
+ } catch (error: unknown) {
105
+ return { present: undefined, error: error instanceof Error ? error.message : String(error) };
106
+ }
107
+ }
108
+
109
+ // Removes OMP's stored marker record so one command completes the logout.
110
+ export async function removeOmpCredentialRecord(ctx: OmpCommandContext | undefined): Promise<"removed" | "absent" | "unavailable"> {
111
+ try {
112
+ const credentials = ctx?.modelRegistry?.authStorage?.credentials;
113
+ if (!credentials?.remove || !credentials.getOAuth) return "unavailable";
114
+ if (!credentials.getOAuth("antigravity-acp")) return "absent";
115
+ await credentials.remove("antigravity-acp");
116
+ try { await ctx?.modelRegistry?.refreshProvider?.("antigravity-acp", "online"); } catch { /* advisory only */ }
117
+ return "removed";
118
+ } catch { return "unavailable"; }
119
+ }
120
+
121
+ export interface AuthCoordinatorDeps {
122
+ pi: {
123
+ on: (name: string, handler: (event: unknown, ctx: OmpCommandContext) => unknown) => void;
124
+ };
125
+ connections: Set<TierConnection>;
126
+ isPoolBusy: () => boolean;
127
+ logoutAllRuntimes: () => Promise<void>;
128
+ closeAllRuntimes: () => Promise<void>;
129
+ onSyncProvider: () => void;
130
+ }
131
+
132
+ // OMP's oauth contract has no logout hook: /logout only removes the stored
133
+ // marker credential. Watching the credential store's generation counter lets
134
+ // this adapter finish the Antigravity-side logout when OMP reports removal.
135
+ export class OmpAuthCoordinator {
136
+ private watchingCredentials = false;
137
+ private markerPresent: boolean | undefined;
138
+ private suppressFollow = false;
139
+ private selfLogout = false;
140
+ // Whether registerProvider keeps the non-secret config apiKey fallback.
141
+ apiKeyFallback = true;
142
+ private followTimer: ReturnType<typeof setTimeout> | undefined;
143
+ private followRetry: ReturnType<typeof setTimeout> | undefined;
144
+
145
+ constructor(private readonly deps: AuthCoordinatorDeps) {}
146
+
147
+ ompMarkerStored(ctx: OmpCommandContext | undefined): boolean | undefined {
148
+ try {
149
+ return Boolean(ctx?.modelRegistry?.authStorage?.credentials?.getOAuth?.("antigravity-acp"));
150
+ } catch { return undefined; }
151
+ }
152
+
153
+ // A dying ACP server can flush its in-memory token back to the keychain,
154
+ // racing a plain deletion and restoring the previous account. Wait for this
155
+ // adapter's server processes to fully exit first, then verify the removal.
156
+ async removeKeychainCredentialDurably(): Promise<boolean | undefined> {
157
+ const pending = [...this.deps.connections].map(connection => connection.process.exited.catch(() => undefined));
158
+ if (pending.length > 0) {
159
+ await Promise.race([Promise.allSettled(pending), new Promise(resolve => setTimeout(resolve, 10_000))]);
160
+ }
161
+ for (let attempt = 0; attempt < 3; attempt++) {
162
+ if (keychain.present() === false) return true;
163
+ const removed = keychain.remove();
164
+ if (removed !== true) return removed;
165
+ await new Promise(resolve => setTimeout(resolve, 400));
166
+ }
167
+ return keychain.present() === false;
168
+ }
169
+
170
+ // /login must mean a fresh Google sign-in: drop stored credentials (and this
171
+ // process's old-account servers) so a new server cannot silently reuse the
172
+ // saved login and keep the previous account.
173
+ async beginFreshGoogleLogin(): Promise<void> {
174
+ if (this.deps.isPoolBusy()) {
175
+ throw new Error("Wait for active Antigravity requests to finish before logging in.");
176
+ }
177
+ await this.deps.closeAllRuntimes();
178
+ clearAntigravityCredentials();
179
+ keychain.remove();
180
+ }
181
+
182
+ async performCommandLogout(ctx: OmpCommandContext): Promise<{ keychainRemoved: boolean | undefined; ompMarker: "removed" | "absent" | "unavailable" }> {
183
+ if (this.deps.isPoolBusy()) {
184
+ throw new Error("Wait for active Antigravity requests to finish before logging out.");
185
+ }
186
+ await this.deps.logoutAllRuntimes();
187
+ await this.deps.closeAllRuntimes();
188
+ const keychainRemoved = await this.removeKeychainCredentialDurably();
189
+ // Removing the marker ourselves must not trigger the follow-up logout.
190
+ this.selfLogout = true;
191
+ let ompMarker: "removed" | "absent" | "unavailable";
192
+ try { ompMarker = await removeOmpCredentialRecord(ctx); } finally { this.selfLogout = false; }
193
+ if (ompMarker !== "unavailable") {
194
+ // Drop the config apiKey with the marker even without the watcher.
195
+ this.apiKeyFallback = false;
196
+ this.deps.onSyncProvider();
197
+ }
198
+ return { keychainRemoved, ompMarker };
199
+ }
200
+
201
+ private async finishFollowedLogout(ctx: OmpCommandContext): Promise<void> {
202
+ if (this.deps.isPoolBusy()) {
203
+ // Never interrupt an in-flight Antigravity request; retry once idle.
204
+ clearTimeout(this.followRetry);
205
+ this.followRetry = setTimeout(() => {
206
+ this.followRetry = undefined;
207
+ if (this.ompMarkerStored(ctx) === false) void this.finishFollowedLogout(ctx);
208
+ }, logoutFollow.retryMs);
209
+ this.followRetry.unref?.();
210
+ return;
211
+ }
212
+ await this.deps.logoutAllRuntimes();
213
+ await this.deps.closeAllRuntimes();
214
+ const keychainRemoved = await this.removeKeychainCredentialDurably();
215
+ // Keep the confirmation terse; /antigravity-acp account shows the details.
216
+ const cleared = ["Google credentials", "saved ACP sessions"];
217
+ if (keychainRemoved === true) cleared.push("the macOS keychain entry");
218
+ const list = cleared.slice(0, -1).join(", ") + " and " + cleared[cleared.length - 1];
219
+ try {
220
+ ctx?.ui?.notify?.(`Antigravity ACP: finished the logout OMP started — ${list} cleared.${keychainRemoved === false ? " The macOS keychain entry was not present or not removable." : ""}`, "info");
221
+ } catch { /* the host UI may already be gone */ }
222
+ }
223
+
224
+ watchOmpCredentials(ctx: OmpCommandContext | undefined): void {
225
+ if (this.watchingCredentials || !ctx) return;
226
+ const credentials = ctx.modelRegistry?.authStorage?.credentials;
227
+ if (!credentials?.getOAuth || !credentials.onGeneration) return;
228
+ const initial = this.ompMarkerStored(ctx);
229
+ if (initial === undefined) return;
230
+ this.watchingCredentials = true;
231
+ this.markerPresent = initial;
232
+ // Automatic soft-disables (for example an invalid_grant refresh) must not
233
+ // destroy the Antigravity-side login. OMP emits credential_disabled for
234
+ // those, but not for user-initiated removals such as /logout.
235
+ this.deps.pi.on("credential_disabled", (event: unknown) => {
236
+ if (event && typeof event === "object" && "provider" in event && event.provider === "antigravity-acp") {
237
+ this.suppressFollow = true;
238
+ }
239
+ });
240
+ credentials.onGeneration(() => {
241
+ const current = this.ompMarkerStored(ctx);
242
+ if (current === undefined) return;
243
+ const wasPresent = this.markerPresent === true;
244
+ this.markerPresent = current;
245
+ if (current) this.suppressFollow = false;
246
+ if (wasPresent !== current) {
247
+ // Flip the config apiKey in the same synchronous tick as the marker
248
+ // change: OMP's own logout report then finds no remaining
249
+ // "provider config (fallback)" source, while a fresh profile that
250
+ // never stored a marker keeps the catalog visible.
251
+ this.apiKeyFallback = current;
252
+ this.deps.onSyncProvider();
253
+ }
254
+ if (!wasPresent || current || this.selfLogout) return;
255
+ clearTimeout(this.followTimer);
256
+ this.followTimer = setTimeout(() => {
257
+ this.followTimer = undefined;
258
+ if (process.env.OMP_ACP_FOLLOW_LOGOUT === "0") return;
259
+ if (this.suppressFollow) {
260
+ this.suppressFollow = false;
261
+ this.apiKeyFallback = true;
262
+ this.deps.onSyncProvider();
263
+ return;
264
+ }
265
+ // A quick re-login after the removal cancels the cleanup.
266
+ if (this.ompMarkerStored(ctx) !== false) {
267
+ this.apiKeyFallback = true;
268
+ this.deps.onSyncProvider();
269
+ return;
270
+ }
271
+ void this.finishFollowedLogout(ctx);
272
+ }, logoutFollow.delayMs);
273
+ this.followTimer.unref?.();
274
+ });
275
+ }
276
+ }
@@ -0,0 +1,104 @@
1
+ import fs from "node:fs";
2
+ import { writeJsonAtomic } from "./fs-atomic.ts";
3
+ import { resolveContextOptions, type ContextOptions, type ContextSettings } from "./context-settings.ts";
4
+ import { EFFORTS, projectCatalog, readModels, type AdvertisedModel, type PublicCatalogModel } from "./model-catalog.ts";
5
+ import { officialApiCost } from "./pricing.ts";
6
+ import { advertisedRecord, choices, selector } from "./selectors.ts";
7
+ import { TierConnection } from "./tier-connection.ts";
8
+ import type { SessionCleanup } from "./session-cleanup.ts";
9
+
10
+ export interface ConfiguredCatalogModel extends PublicCatalogModel {
11
+ ompContextPolicy: ReturnType<typeof resolveContextOptions>;
12
+ }
13
+
14
+ export class CatalogStore {
15
+ readonly upstreamModels = new Map<string, ConfiguredCatalogModel>();
16
+ currentModels: ConfiguredCatalogModel[] = [];
17
+
18
+ constructor(
19
+ private readonly cachePath: string,
20
+ private readonly cleanup: SessionCleanup,
21
+ private readonly prepareRuntime: () => Promise<void>,
22
+ private readonly fallbackModels: () => PublicCatalogModel[],
23
+ ) {}
24
+
25
+ projectWithSettings(models: PublicCatalogModel[], settings: ContextSettings): ConfiguredCatalogModel[] {
26
+ return models.map(source => {
27
+ const limits = resolveContextOptions(source, settings);
28
+ const model: ConfiguredCatalogModel = {
29
+ ...source,
30
+ contextWindow: limits.contextWindow,
31
+ maxTokens: limits.maxTokens,
32
+ ompContextPolicy: limits,
33
+ cost: officialApiCost(source.id) ?? source.cost,
34
+ };
35
+ const efforts = EFFORTS.filter(effort => model.thinkingLevelMap?.[effort]);
36
+ if (efforts.length && !model.thinking) {
37
+ model.thinking = { mode: "effort", efforts, defaultLevel: efforts.includes("high") ? "high" : efforts[0]! };
38
+ }
39
+ this.upstreamModels.set(model.id, model);
40
+ return model;
41
+ });
42
+ }
43
+
44
+ readCachedCatalog(): AdvertisedModel[] {
45
+ try {
46
+ const cache = JSON.parse(fs.readFileSync(this.cachePath, "utf8")) as { schemaVersion?: unknown; models?: unknown };
47
+ if (cache.schemaVersion !== 1 && cache.schemaVersion !== 2) return [];
48
+ return readModels(cache.models);
49
+ } catch { return []; }
50
+ }
51
+
52
+ loadInitialOrCached(settings: ContextSettings): ConfiguredCatalogModel[] {
53
+ const cached = this.readCachedCatalog();
54
+ const base = cached.length ? projectCatalog(cached) : this.fallbackModels();
55
+ this.currentModels = this.projectWithSettings(base, settings);
56
+ return this.currentModels;
57
+ }
58
+
59
+ reconfigure(settings: ContextSettings): ConfiguredCatalogModel[] {
60
+ this.currentModels = this.projectWithSettings(this.currentModels, settings);
61
+ return this.currentModels;
62
+ }
63
+
64
+ async discoverModels(): Promise<AdvertisedModel[]> {
65
+ await this.prepareRuntime();
66
+ const connection = new TierConnection({ cwd: process.cwd(), ompCleanup: this.cleanup });
67
+ let discoveredSession: string | undefined;
68
+ try {
69
+ await connection.initialize();
70
+ const session = await connection.newSession(process.cwd());
71
+ discoveredSession = session.sessionId;
72
+ const modern = choices(selector(session, "model"));
73
+ if (modern.length) {
74
+ const models: AdvertisedModel[] = [];
75
+ for (const option of modern) {
76
+ // Model changes can alter reasoning choices; inspect each model's
77
+ // confirmed configuration rather than sharing one global tier list.
78
+ await connection.setModel(session.sessionId, option.value);
79
+ models.push(advertisedRecord(connection.getSessionState(session.sessionId), option.value, option.name));
80
+ }
81
+ return models;
82
+ }
83
+ const models = readModels(session.models?.availableModels);
84
+ if (!models.length) throw new Error("Antigravity did not advertise any models");
85
+ return models;
86
+ } finally {
87
+ if (discoveredSession) connection.discardSession(discoveredSession);
88
+ await connection.close();
89
+ }
90
+ }
91
+
92
+ async refresh(settings: ContextSettings): Promise<ConfiguredCatalogModel[]> {
93
+ const models = await this.discoverModels();
94
+ this.upstreamModels.clear();
95
+ const registered = this.projectWithSettings(projectCatalog(models), settings);
96
+ this.currentModels = registered;
97
+ writeJsonAtomic(this.cachePath, {
98
+ schemaVersion: 2,
99
+ discoveredAt: new Date().toISOString(),
100
+ models,
101
+ });
102
+ return registered;
103
+ }
104
+ }