Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Antigravity: keep each native CLI account's sign-in in its profile on 1.5.16
laijsg17dd86877d1b8
diff --git a/server/drivers/antigravity-acp.ts b/server/drivers/antigravity-acp.tsindex d6bb100f8e..89173d8fed 100644--- a/server/drivers/antigravity-acp.ts+++ b/server/drivers/antigravity-acp.ts@@ -87,6 +87,7 @@ const REMOVED_ENVIRONMENT_KEYS = new Set(["AGY_ACP_DEFAULT_MODEL","GEMINI_HOME","AGY_ACP_FORCE_FILE_STORAGE",+ "AGY_CLI_FORCE_FILE_TOKEN_STORAGE","ANTIGRAVITY_HARNESS_PATH","BROWSER","PYTHONUNBUFFERED",@@ -297,11 +298,13 @@ export async function prepareAntigravityProfile(input: {// Updates come only through this app's updater; the release folder is read-only besides.AGY_CLI_DISABLE_AUTO_UPDATE: "1",// The CLI ignores AGY_ACP_FORCE_FILE_STORAGE and keeps one Google sign-in per computer in the OS keyring,- // whatever --gemini-dir says (1.5.14), unless it believes it runs over SSH: then each profile keeps its own in- // its file (1.5.15, signed in for real). So every account here has its own sign-in, the keychain and the CLI- // in a terminal are never touched, and a box without a keyring works the same. A fixed value, so no address- // of the host reaches the box.+ // whatever --gemini-dir says. 1.5.14 and 1.5.15 keep each profile's in its file instead while they believe+ // they run over SSH. 1.5.16 ignores SSH_CONNECTION and uses the keychain whenever it can open one, unless+ // AGY_CLI_FORCE_FILE_TOKEN_STORAGE is set (both measured on macOS). With both, every account here has its+ // own sign-in, the keychain and the CLI in a terminal are never touched, and a box without a keyring works+ // the same. SSH_CONNECTION is a fixed value, so no address of the host reaches the box.SSH_CONNECTION: ANTIGRAVITY_SSH_CONNECTION,+ AGY_CLI_FORCE_FILE_TOKEN_STORAGE: "1",}: { ANTIGRAVITY_HARNESS_PATH: input.runtime.harnessPath! }),BROWSER: browserCommand,diff --git a/server/drivers/antigravity-cli-install.ts b/server/drivers/antigravity-cli-install.tsindex b0a179b85a..544ce326dc 100644--- a/server/drivers/antigravity-cli-install.ts+++ b/server/drivers/antigravity-cli-install.ts@@ -33,8 +33,9 @@ export const ANTIGRAVITY_NATIVE_CLI_ENV = "OMB_ANTIGRAVITY_NATIVE_CLI";export const ANTIGRAVITY_CLI_FIRST = process.env[ANTIGRAVITY_NATIVE_CLI_ENV] === "1";/** Where the CLI keeps a Google sign-in, under `<profile>/antigravity-acp/`, when it does not use the OS keyring (which- * it skips while SSH_CONNECTION is set). It never writes the pinned runtime's `acp_token.json`, and stores no OAuth- * client, so this app cannot refresh it. */+ * it skips while SSH_CONNECTION is set up to 1.5.15, and while AGY_CLI_FORCE_FILE_TOKEN_STORAGE is set from 1.5.16):+ * `{"token":{"access_token","expiry",…},"auth_method":"consumer"}` in 1.5.16. It never writes the pinned runtime's+ * `acp_token.json`, and stores no OAuth client, so this app cannot refresh it. */export const ANTIGRAVITY_CLI_TOKEN_FILE = "antigravity-oauth-token";/** Whether a configuration that does not name the native CLI (no path, or `agy`) runs it on `platform` when no pinneddiff --git a/server/drivers/antigravity-cli-login.test.ts b/server/drivers/antigravity-cli-login.test.tsindex 5344487ea7..fd1b0170f5 100644--- a/server/drivers/antigravity-cli-login.test.ts+++ b/server/drivers/antigravity-cli-login.test.ts@@ -68,7 +68,7 @@ const cliRuntime = (executablePath: string): AntigravityRuntime => ({ executableconst pinnedRuntime: AntigravityRuntime = { executablePath: "/r/agy_acp_server.par", harnessPath: "/r/localharness_external", source: "managed", version: "1.4.3" };describe("the native CLI's environment and sign-in file", () => {- it("turns its self-update off and sets the SSH_CONNECTION that keeps the sign-in in the profile, a fixed value even over SSH", async () => {+ it("turns its self-update off and keeps the sign-in in the profile: a fixed SSH_CONNECTION even over SSH, and file storage", async () => {const baseDir = folder();const cli = await prepareAntigravityProfile({instanceId: "cli", baseDir, runtime: cliRuntime("/cli/antigravity"),@@ -76,14 +76,18 @@ describe("the native CLI's environment and sign-in file", () => {});expect(cli.environment.AGY_CLI_DISABLE_AUTO_UPDATE).toBe("1");expect(cli.environment.SSH_CONNECTION).toBe(ANTIGRAVITY_SSH_CONNECTION);+ expect(cli.environment.AGY_CLI_FORCE_FILE_TOKEN_STORAGE).toBe("1");// `tokenPath` is the pinned runtime's file on either runtime: the CLI's sign-in is asked of the CLI itself.expect(cli.tokenPath).toBe(join(cli.directory, "antigravity-acp", "acp_token.json"));const pinned = await prepareAntigravityProfile({- instanceId: "pinned", baseDir, runtime: pinnedRuntime, baseEnv: { PATH: "/usr/bin", SSH_CONNECTION: "203.0.113.9 52144 10.0.0.2 22" },+ instanceId: "pinned", baseDir, runtime: pinnedRuntime,+ baseEnv: { PATH: "/usr/bin", SSH_CONNECTION: "203.0.113.9 52144 10.0.0.2 22", AGY_CLI_FORCE_FILE_TOKEN_STORAGE: "1" },});- // The pinned runtime gets the environment as before: the server's own value passes, nothing is set.+ // The pinned runtime gets the environment as before: the server's own value passes, nothing is set, and the+ // native CLI's file storage switch is not inherited.expect(pinned.environment.SSH_CONNECTION).toBe("203.0.113.9 52144 10.0.0.2 22");expect(pinned.environment.AGY_CLI_DISABLE_AUTO_UPDATE).toBeUndefined();+ expect(pinned.environment.AGY_CLI_FORCE_FILE_TOKEN_STORAGE).toBeUndefined();expect(pinned.tokenPath).toBe(join(pinned.directory, "antigravity-acp", "acp_token.json"));});@@ -101,7 +105,7 @@ describe("the native CLI's environment and sign-in file", () => {});describe.skipIf(WINDOWS)("signing in with `antigravity acp --login`", () => {- it("starts the CLI with no display, the fixed SSH_CONNECTION and no self-update, so it prints its link and keeps the sign-in in the profile", async () => {+ it("starts the CLI with no display, the fixed SSH_CONNECTION, file storage and no self-update, so it prints its link and keeps the sign-in in the profile", async () => {const fake = fakeCli();const profile = await prepareAntigravityProfile({instanceId: "login", baseDir: folder(), runtime: cliRuntime(fake.executable),@@ -117,6 +121,7 @@ describe.skipIf(WINDOWS)("signing in with `antigravity acp --login`", () => {expect(launch.env.DISPLAY).toBeUndefined();expect(launch.env.WAYLAND_DISPLAY).toBeUndefined();expect(launch.env.SSH_CONNECTION).toBe(ANTIGRAVITY_SSH_CONNECTION);+ expect(launch.env.AGY_CLI_FORCE_FILE_TOKEN_STORAGE).toBe("1");expect(launch.env.AGY_CLI_DISABLE_AUTO_UPDATE).toBe("1");await login.complete(flow.flowId!, `${ANTIGRAVITY_LOGIN_REDIRECT}?state=fixture-state&code=good-code`);expect(signedIn).toBe(1);diff --git a/server/drivers/antigravity-native-sign-in.test.ts b/server/drivers/antigravity-native-sign-in.test.tsindex 346c98784e..b366fad302 100644--- a/server/drivers/antigravity-native-sign-in.test.ts+++ b/server/drivers/antigravity-native-sign-in.test.ts@@ -35,8 +35,8 @@ describe("the access token of the native CLI's stored sign-in", () => {});});-// The app starts the CLI as over SSH (antigravity-acp.ts), so each account's sign-in is its profile's file, on every-// system: the OS keychain is never asked.+// The app starts the CLI as over SSH and with file token storage, so each account's sign-in is its profile's file and+// the usage report reads only that file.describe("which stored sign-in's access token is used", () => {const profileFile = join(antigravityProfileDirectory("native"), "antigravity-acp", "antigravity-oauth-token");const store = (file: string | null) => {diff --git a/server/drivers/antigravity-native-sign-in.ts b/server/drivers/antigravity-native-sign-in.tsindex aa190bc1f1..1f1b5c5104 100644--- a/server/drivers/antigravity-native-sign-in.ts+++ b/server/drivers/antigravity-native-sign-in.ts@@ -9,9 +9,10 @@ import { antigravityProfileDirectory } from "./antigravity-acp.ts";import { antigravityCliAccessToken } from "./antigravity-account.ts";import { antigravityNativeTokenPath } from "./antigravity-native-status.ts";-// Antigravity CLI 1.5.14 keeps one sign-in per computer in the OS keyring (on macOS the login keychain), unless it runs-// over SSH: then each profile's is the file in that profile. This app always starts it as over SSH-// (antigravity-acp.ts), so the profile's file is the account's sign-in, and the keychain is never read.+// Antigravity CLI keeps one sign-in per computer in the OS keyring (on macOS the login keychain), unless it runs over+// SSH (1.5.14, 1.5.15) or with AGY_CLI_FORCE_FILE_TOKEN_STORAGE (1.5.16): then each profile's is the file in that+// profile. This app always starts it with both, so the profile's file is the account's sign-in, and the keychain is+// never read.const STORED_MAX_BYTES = 1024 * 1024;export interface NativeSignInStore {diff --git a/server/routes/instances-antigravity-native.test.ts b/server/routes/instances-antigravity-native.test.tsindex 04a20a4dc2..4e39811fe4 100644--- a/server/routes/instances-antigravity-native.test.ts+++ b/server/routes/instances-antigravity-native.test.ts@@ -1,6 +1,6 @@// The native Antigravity CLI through the server's own instance routes, with a real registry and driver and a fake CLI// on disk: the sign-in, the status, a turn, the check and the sign-out the app offers, and removing the account.-import { existsSync, mkdtempSync, readdirSync, rmSync } from "node:fs";+import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";import { createServer, type Server } from "node:http";import type { AddressInfo } from "node:net";import { tmpdir } from "node:os";@@ -187,11 +187,11 @@ describe.skipIf(WINDOWS)("the native Antigravity CLI through the instance routesexpect(Object.keys(cfg.instances!)).not.toContain("antigravity-added");}, 180_000);- // 1.5.14 keeps one keyring entry per computer unless it runs over SSH; the app always starts it so, so every account- // keeps its own sign-in in its own profile, even where the CLI's keyring would be shared.- it("keeps each account's sign-in its own: another account is not signed in by it, and a sign-out or removal ends only its own", async () => {+ // The CLI keeps one keyring entry per computer unless it runs over SSH (1.5.14) or is told to use files (1.5.16); the+ // app always starts it with both, so every account keeps its own sign-in in its own profile.+ it.each(["1.5.14", "1.5.16"])("keeps each account's sign-in its own on %s: another account is not signed in by it, and a sign-out or removal ends only its own", async (version) => {const keyring = folder();- const { cfg, registry } = await nativeSetup(["antigravity-a", "antigravity-b"], { FAKE_AGY_KEYRING: keyring, FAKE_AGY_KEYRING_SHARED: "1" });+ const { cfg, registry } = await nativeSetup(["antigravity-a", "antigravity-b"], { FAKE_AGY_KEYRING: keyring, FAKE_AGY_KEYRING_SHARED: "1", FAKE_AGY_VERSION: version });const { request, call, status } = await serve(registry, cfg);for (const id of ["antigravity-a", "antigravity-b"]) {const flow = (await call("POST", `/api/instances/${id}/auth/start`, {})).auth;@@ -211,6 +211,24 @@ describe.skipIf(WINDOWS)("the native Antigravity CLI through the instance routesexpect(await status("antigravity-b")).toMatchObject({ authenticated: false });}, 180_000);+ it.each(["1.5.14", "1.5.16"])("never takes up or changes a sign-in the computer's keyring already holds, on %s", async (version) => {+ const keyring = folder();+ writeFileSync(join(keyring, "shared"), "the keyring's own sign-in\n");+ const { cfg, registry } = await nativeSetup([], { FAKE_AGY_KEYRING: keyring, FAKE_AGY_KEYRING_SHARED: "1", FAKE_AGY_VERSION: version });+ const { request, call, status } = await serve(registry, cfg);+ expect(await status("antigravity")).toMatchObject({ authenticated: false });++ const flow = (await call("POST", "/api/instances/antigravity/auth/start", {})).auth;+ await call("POST", "/api/instances/antigravity/auth/complete", { flowId: flow.flowId, callbackUrl: "fixture-code" });+ expect(await status("antigravity")).toMatchObject({ authenticated: true });+ expect((await request("POST", "/api/instances/antigravity/auth/sign-out", {})).status).toBe(200);+ await call("POST", "/api/instances/antigravity/check", {});+ expect(await status("antigravity")).toMatchObject({ authenticated: false });++ expect(readdirSync(keyring)).toEqual(["shared"]);+ expect(readFileSync(join(keyring, "shared"), "utf8")).toBe("the keyring's own sign-in\n");+ }, 180_000);+it("ends a sign-in that waits for its code, with the CLI's process gone, when the person signs out", async () => {const { fixture, cfg, registry } = await nativeSetup();const { call } = await serve(registry, cfg);diff --git a/server/testing/fake-antigravity-cli.ts b/server/testing/fake-antigravity-cli.tsindex b55ff7ab49..2ae388f224 100644--- a/server/testing/fake-antigravity-cli.ts+++ b/server/testing/fake-antigravity-cli.ts@@ -1,5 +1,5 @@#!/usr/bin/env node-// Offline stand-in for Google's native Antigravity CLI (1.5.x), as measured against 1.5.14, started as `antigravity acp+// Offline stand-in for Google's native Antigravity CLI (1.5.x), as measured against 1.5.14 to 1.5.16, started as `antigravity acp// --gemini-dir <dir> --app-data-dir antigravity-acp [--login]`, or `--version`. Its sign-in is the file// <gemini-dir>/antigravity-acp/antigravity-oauth-token, which stands for the OS keyring.// - ACP over stdio: `initialize` names "Antigravity ACP Server" and offers `logout` and `session/close`; `authenticate`@@ -19,8 +19,8 @@// FAKE_AGY_KEYRING_SHARED with FAKE_AGY_KEYRING: one entry for every --gemini-dir, as the macOS keyring holds in 1.5.14// FAKE_AGY_SESSION_ERROR a message session/new fails with as -32000, signed in or not// FAKE_AGY_KEYRING a folder that stands for the OS keyring: the sign-in is kept there, one entry per --gemini-dir,-// and only `logout` removes it; ignored while SSH_CONNECTION is set, as the real CLI ignores the-// keyring then+// and only `logout` removes it; ignored while SSH_CONNECTION is set (before 1.5.16) or+// AGY_CLI_FORCE_FILE_TOKEN_STORAGE is set (from 1.5.16), as the real CLI ignores the keyring thenimport { createHash } from "node:crypto";import { appendFileSync, existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";import { join, resolve } from "node:path";@@ -44,8 +44,12 @@ if (argv[0] !== "acp") {const flag = (name: string) => argv.includes(name) ? argv[argv.indexOf(name) + 1] : undefined;const geminiDir = resolve(flag("--gemini-dir") ?? ".");const stateDir = join(geminiDir, flag("--app-data-dir") ?? "antigravity-acp");-// As 1.5.14 and 1.5.15 do: over SSH (SSH_CONNECTION set, as the app always starts it) the profile's file, never the keyring.-const credentialFile = process.env.FAKE_AGY_KEYRING && !process.env.SSH_CONNECTION+// 1.5.14 and 1.5.15 skip the keyring over SSH; 1.5.16 ignores SSH_CONNECTION and skips it only when told to.+const [major = 0, minor = 0, patch = 0] = version.split(".").map(Number);+const fileStorage = major > 1 || (major === 1 && (minor > 5 || (minor === 5 && patch >= 16)))+ ? Boolean(process.env.AGY_CLI_FORCE_FILE_TOKEN_STORAGE)+ : Boolean(process.env.SSH_CONNECTION);+const credentialFile = process.env.FAKE_AGY_KEYRING && !fileStorage? join(process.env.FAKE_AGY_KEYRING, process.env.FAKE_AGY_KEYRING_SHARED ? "shared" : createHash("sha256").update(geminiDir).digest("hex")): join(stateDir, "antigravity-oauth-token");const accountModel = process.env.FAKE_AGY_ACCOUNT_MODEL ?? "fixture-account-model";