Repository navigation
Expand file tree
/
Copy pathantigravity.ts
More file actions
225 lines (214 loc) · 8.83 KB
/
Copy pathantigravity.ts
File metadata and controls
225 lines (214 loc) · 8.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// Google Antigravity through its official ACP server: managed runtime, isolated Google profile,
// model/mode configuration and OAuth.
import type { ApprovalMode } from "../../shared/approval-mode.ts";
import { antigravityAccount } from "./antigravity-account.ts";
import type {
DriverCreateInput,
ModelCatalog,
ProviderDriver,
ProviderInstance,
ProviderSnapshot,
SendTurnInput,
} from "../contracts.ts";
import { createAcpDriver, type AcpConfig, type AcpSupport } from "./acp/core.ts";
import {
AntigravityAuthController,
antigravityProfileAuthenticated,
prepareAntigravityProfile,
probeAntigravityModels,
removeAntigravitySignIn,
validateAntigravityRuntime,
} from "./antigravity-acp.ts";
import {
antigravityManagedInstallAvailable,
installAntigravityRuntime,
resolveAntigravityRuntime,
} from "./antigravity-runtime.ts";
import { resolveAntigravityReleaseAsset } from "./antigravity-release.ts";
import { VERIFICATION_TEMP_KEY, scheduleAntigravityTempSweep } from "./antigravity-temp.ts";
import { augmentedPath } from "../env-path.ts";
export const STATIC_ANTIGRAVITY_MODELS: ModelCatalog = {
default: "gemini-3.8-flash",
options: [
{
id: "gemini-3.8-flash",
label: "Gemini 3.8 Flash",
variants: [
{ id: "low", label: "Low" },
{ id: "medium", label: "Medium" },
{ id: "high", label: "High" },
],
},
],
};
/** Bots saved before the thinking-level option hold ids like `gemini-3.8-flash-medium` or `gemini-4-argon-high`;
* the official runtime offers only the base model with that option, so run the base at the saved level. A runtime
* that still offers the suffixed id, or lacks the base, or a turn that chose its own level, keeps its selection. */
export function normalizeAntigravityTurn(turn: SendTurnInput, offeredModels: readonly string[]): SendTurnInput {
if (turn.variant !== undefined) return turn;
const match = turn.model?.match(/^(.+)-(low|medium|high)$/u);
return match && offeredModels.includes(match[1]) && !offeredModels.includes(match[0])
? { ...turn, model: match[1], variant: match[2] }
: turn;
}
/** Antigravity's session modes: `yolo` for Full, `auto_edit` for auto-accept edits, `default` otherwise (it has no reviewer for Auto). */
export function antigravityPermissionMode(fullAuto: boolean, approvalMode?: ApprovalMode): "yolo" | "auto_edit" | "default" {
if (fullAuto || approvalMode === "full") return "yolo";
return approvalMode === "edits" ? "auto_edit" : "default";
}
const managedAsset = resolveAntigravityReleaseAsset();
const support: AcpSupport = {
driverKind: "antigravityAgent",
// Named for what people look for: Google moved personal Gemini subscriptions (free, AI Pro, AI Ultra) from Gemini CLI to Antigravity on 2026-06-18.
displayName: "Google Gemini (Antigravity)",
models: STATIC_ANTIGRAVITY_MODELS,
defaultCli: "agy", // migration alias: resolveAntigravityRuntime treats it as managed
nativeSource: "antigravity.acp",
loginNote: "Antigravity needs a Google account — choose Sign in with Google in engine setup",
install: {
docsUrl: "https://github.com/agentclientprotocol/registry/tree/main/antigravity-acp",
...(managedAsset
? { managed: { label: "Install official Antigravity", downloadBytes: managedAsset.archiveBytes } }
: {}),
},
images: true,
spawnArgs: () => [],
selectModel: { configId: "model" },
modelVariants: true,
normalizeSessionSelection: normalizeAntigravityTurn,
// Google's server reads its new-session default from this variable (agy_acp_server 1.4.3
// model_selection.get_default_model_id); a later switch re-fetches the model list (1.3-1.8 s).
sessionModelEnv: "AGY_ACP_DEFAULT_MODEL",
sessionScopedApproval: true,
resumeMethod: "resume",
clientFileSystem: true,
sanitizeToolPayload: true,
resolveCommand: async (env, config, instanceId) => {
const runtime = await resolveAntigravityRuntime(config.cli, env);
const profile = await prepareAntigravityProfile({ instanceId, runtime, baseEnv: env });
if (profile.tempDirectory) scheduleAntigravityTempSweep(instanceId);
return {
command: runtime.executablePath,
args: process.platform === "linux" ? ["--uid="] : [],
env: profile.environment,
};
},
resolveModels: async (env, config, instanceId) => {
const runtime = await resolveAntigravityRuntime(config.cli, env);
const profile = await prepareAntigravityProfile({ instanceId, runtime, baseEnv: env });
if (!(await antigravityProfileAuthenticated(profile))) throw new Error(support.loginNote);
return probeAntigravityModels({
runtime,
profile,
fallbackDefault: STATIC_ANTIGRAVITY_MODELS.default,
});
},
pickAuthMethod: (methods) => methods.some((method) => method.id === "oauth-personal")
? "oauth-personal"
: null,
authFailure: "fail",
requireAuthenticationBeforeSpawn: true,
isAuthenticated: async (env, config, instanceId) => {
try {
const runtime = await resolveAntigravityRuntime(config.cli, env);
const profile = await prepareAntigravityProfile({ instanceId, runtime, baseEnv: env });
return antigravityProfileAuthenticated(profile);
} catch {
return false;
}
},
snapshot: async (env, config, instanceId): Promise<ProviderSnapshot> => {
try {
const runtime = await resolveAntigravityRuntime(config.cli, env);
const profile = await prepareAntigravityProfile({ instanceId, runtime, baseEnv: env });
return {
state: "available",
version: runtime.version,
authenticated: await antigravityProfileAuthenticated(profile),
account: await antigravityAccount(profile.tokenPath),
};
} catch (error) {
return { state: "unavailable", reason: error instanceof Error ? error.message : String(error) };
}
},
configureSession: async ({ request, sessionId, config, turn, configOptions }) => {
if (!Array.isArray(configOptions) || !configOptions.some(option => option?.id === "mode")) {
return;
}
const wanted = antigravityPermissionMode(config.fullAuto, turn.approvalMode);
const result = await request("session/set_config_option", {
sessionId,
configId: "mode",
value: wanted,
});
const mode = Array.isArray(result?.configOptions)
? result.configOptions.find((option: any) => option?.id === "mode")?.currentValue
: undefined;
if (mode !== wanted) throw new Error(`Antigravity did not apply ${wanted} permission mode.`);
},
};
const AcpAntigravityDriver = createAcpDriver(support);
export const AntigravityDriver: ProviderDriver<AcpConfig> = {
...AcpAntigravityDriver,
async create(input: DriverCreateInput<AcpConfig>): Promise<ProviderInstance> {
const base = await AcpAntigravityDriver.create(input);
scheduleAntigravityTempSweep(input.instanceId);
scheduleAntigravityTempSweep(VERIFICATION_TEMP_KEY);
const auth = new AntigravityAuthController(() => void base.refreshModels?.());
let installFailure: string | undefined;
const runtimeAndProfile = async () => {
// A GUI launch's raw PATH may omit the official runtime the model picker found.
const environment = { ...process.env, ...input.environment, PATH: augmentedPath() };
const runtime = await resolveAntigravityRuntime(input.config.cli, environment);
const profile = await prepareAntigravityProfile({
instanceId: input.instanceId,
runtime,
baseEnv: environment,
});
return { runtime, profile };
};
return {
...base,
get models() {
return base.models;
},
get modelsUnconfirmed() {
return base.modelsUnconfirmed;
},
snapshot: async () => {
const snapshot = await base.snapshot();
if (snapshot.state === "available") installFailure = undefined;
return snapshot.state === "unavailable" && installFailure
? { ...snapshot, reason: installFailure }
: snapshot;
},
...(antigravityManagedInstallAvailable()
? {
installRuntime: async () => {
installFailure = undefined;
try {
await installAntigravityRuntime({ validate: validateAntigravityRuntime });
} catch (error) {
installFailure = error instanceof Error ? error.message : String(error);
throw error;
}
},
}
: {}),
startAuthentication: async () => {
const { runtime, profile } = await runtimeAndProfile();
return auth.start(runtime, profile);
},
completeAuthentication: async (flowId, callbackUrl) => auth.complete(flowId, callbackUrl),
cancelAuthentication: async () => auth.cancel(),
signOut: async () => {
auth.cancel();
await removeAntigravitySignIn(input.instanceId);
},
dispose: async () => {
auth.cancel();
await base.dispose();
},
};
},
};