fix(server): Antigravity limits show for the 1.5.x CLI's keyring sign-in #36733
ClosedRealDishwash(GitHub profile, opens in a new tab)wants to merge 8 commits into
main fromrefs/pull/36733/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -126,0 +167,21 @@167+168+/** Reads the CLI's keyring entry; `undefined` when there is none. Windows names it `service:account`. */169+const readAntigravityKeyringSecret = Effect.fn("readAntigravityKeyringSecret")(function* (170+ platform: NodeJS.Platform,171+) {172+ // Loading the native binding lazily keeps a broken binding from blocking server startup.173+ const Keyring = yield* Effect.tryPromise({174+ try: () => import("@napi-rs/keyring"),175+ catch: (cause) => new AntigravityKeyringError({ cause }),176+ });177+ const entry =178+ platform === "win32"179+ ? Keyring.AsyncEntry.withTarget(180+ `${KEYRING_SERVICE}:${KEYRING_ACCOUNT}`,181+ KEYRING_SERVICE,182+ KEYRING_ACCOUNT,183+ )184+ : new Keyring.AsyncEntry(KEYRING_SERVICE, KEYRING_ACCOUNT);185+ // Typed as `Uint8Array`, but the binding returns a plain array of bytes.186+ const secret: ArrayLike<number> | undefined = yield* Effect.tryPromise({187+ try: () => entry.getSecret(),@@ -126,0 +159,21 @@159+export class AntigravityKeyringError extends Schema.TaggedError<AntigravityKeyringError>()(160+ "AntigravityKeyringError",161+ { cause: Schema.Defect() },162+) {163+ override get message(): string {164+ return "Could not read the Antigravity sign-in from the system keyring.";165+ }166+}167+168+/** Reads the CLI's keyring entry; `undefined` when there is none. Windows names it `service:account`. */169+const readAntigravityKeyringSecret = Effect.fn("readAntigravityKeyringSecret")(function* (170+ platform: NodeJS.Platform,171+) {172+ // Loading the native binding lazily keeps a broken binding from blocking server startup.173+ const Keyring = yield* Effect.tryPromise({174+ try: () => import("@napi-rs/keyring"),175+ catch: (cause) => new AntigravityKeyringError({ cause }),176+ });177+ const entry =178+ platform === "win32"179+ ? Keyring.AsyncEntry.withTarget(
tanstack-source added labelsbug
juliusmarminge added labelstakeover:in-progress
- @@ -126,0 +159,21 @@159+export class AntigravityKeyringError extends Schema.TaggedError<AntigravityKeyringError>()(160+ "AntigravityKeyringError",161+ { cause: Schema.Defect() },162+) {163+ override get message(): string {164+ return "Could not read the Antigravity sign-in from the system keyring.";165+ }166+}167+168+/** Reads the CLI's keyring entry; `undefined` when there is none. Windows names it `service:account`. */169+const readAntigravityKeyringSecret = Effect.fn("readAntigravityKeyringSecret")(function* (170+ platform: NodeJS.Platform,171+) {172+ // Loading the native binding lazily keeps a broken binding from blocking server startup.173+ const Keyring = yield* Effect.tryPromise({174+ try: () => import("@napi-rs/keyring"),175+ catch: (cause) => new AntigravityKeyringError({ cause }),176+ });177+ const entry =178+ platform === "win32"179+ ? Keyring.AsyncEntry.withTarget(@@ -126,0 +164,21 @@164+ return "Could not read the Antigravity sign-in from the system keyring.";165+ }166+}167+168+/** Reads the CLI's keyring entry; `undefined` when there is none. Windows names it `service:account`. */169+const readAntigravityKeyringSecret = Effect.fn("readAntigravityKeyringSecret")(function* (170+ platform: NodeJS.Platform,171+) {172+ // Loading the native binding lazily keeps a broken binding from blocking server startup.173+ const Keyring = yield* Effect.tryPromise({174+ try: () => import("@napi-rs/keyring"),175+ catch: (cause) => new AntigravityKeyringError({ cause }),176+ });177+ const entry =178+ platform === "win32"179+ ? Keyring.AsyncEntry.withTarget(180+ `${KEYRING_SERVICE}:${KEYRING_ACCOUNT}`,181+ KEYRING_SERVICE,182+ KEYRING_ACCOUNT,183+ )184+ : new Keyring.AsyncEntry(KEYRING_SERVICE, KEYRING_ACCOUNT);@@ -218,3 +295,9 @@218295 const platform = yield* HostProcess.Platform;219296 const architecture = yield* HostProcess.Architecture;220297 const tokenPath = path.join(input.profileDirectory, "antigravity-acp", "acp_token.json");298+ const storedTokenPath = path.join(input.profileDirectory, "antigravity-acp", STORED_TOKEN_FILE);299+ const readKeyringSecret = input.readKeyringSecret ?? readAntigravityKeyringSecret(platform);300+ const readStoredToken = Effect.gen(function* () {301+ const secret = (yield* fs.exists(storedTokenPath))302+ ? yield* fs.readFileString(storedTokenPath)303+ : yield* readKeyringSecret;
juliusmarminge added labelstakeover:blocked
juliusmarminge removed labelstakeover:in-progress
- @@ -126,0 +188,21 @@188+ const runner = yield* ProcessRunner.make();189+ const result = yield* runner190+ .run({191+ command: "/usr/bin/security",192+ args: ["find-generic-password", "-s", KEYRING_SERVICE, "-wa", KEYRING_ACCOUNT],193+ })194+ .pipe(Effect.mapError((cause) => new AntigravityKeyringError({ cause })));195+ if (result.code === 44) return undefined;196+ if (result.code !== 0) {197+ return yield* new AntigravityKeyringError({ cause: `security exited with ${result.code}` });198+ }199+ secret = new TextEncoder().encode(result.stdout.trim());200+ } else {201+ // Loading the native binding lazily keeps a broken binding from blocking server startup.202+ const Keyring = yield* Effect.tryPromise({203+ try: () => import("@napi-rs/keyring"),204+ catch: (cause) => new AntigravityKeyringError({ cause }),205+ });206+ // `getSecret` resolves empty when the Secret Service is locked or unreachable; this rejects.207+ const credentials = yield* Effect.tryPromise({208+ try: () => Keyring.findCredentialsAsync(KEYRING_SERVICE),
juliusmarminge added labelstakeover:in-progress
juliusmarminge removed labelstakeover:blocked
Pushed0c83653
juliusmarminge added labelstakeover:blocked
juliusmarminge removed labelstakeover:in-progress
github-actions[bot](GitHub profile, opens in a new tab) added labelsneeds-rebase
RealDishwash(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed