mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 19:07:41 +00:00
Enable Antigravity Chat on Windows (#41021)
Adds managed Windows x64/arm64 Antigravity Chat runtimes, keeps compatible host agy selection, and makes sign-in prove the saved token works on a fresh server (Google can grant fewer scopes than requested, leaving a token that can never refresh). Builds on Lami's Windows host-CLI admission work in #40344. Co-authored-by: Lami <154405627+Lqm1@users.noreply.github.com>
This commit is contained in:
@@ -72,6 +72,7 @@ export type AcpLaunchSpec = {
|
||||
privateTempDirectory?: true
|
||||
/** Prefer session/resume even when loading is supported. */
|
||||
resumePreference?: 'resume'
|
||||
/** Extra ACP session metadata required by this provider's protocol implementation. */
|
||||
sessionMeta?: Readonly<Record<string, unknown>>
|
||||
/** Conversation-only configuration, resolved again when a process reopens its session. */
|
||||
resolveSessionMeta?(input: {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { expect, it } from 'vitest'
|
||||
import { LOCAL_EXECUTION_HOST_ID } from '../../../shared/execution-host'
|
||||
import type { AgentSessionExecutionLocation } from '../../../shared/agent-session/lifecycle/agent-session-record'
|
||||
import {
|
||||
supportsAcpStructuredLocation,
|
||||
type AcpStructuredLocationSpec
|
||||
} from './acp-structured-location-support'
|
||||
|
||||
const local: AgentSessionExecutionLocation = {
|
||||
executionHostId: LOCAL_EXECUTION_HOST_ID,
|
||||
wslDistro: null,
|
||||
workspaceId: 'workspace',
|
||||
workspaceKind: 'folder'
|
||||
}
|
||||
|
||||
it('allows a local Windows ACP chat through a declared host backend when no managed release exists', () => {
|
||||
const hostOnly = {
|
||||
managedRuntime: { pin: () => null },
|
||||
hostBackend: {}
|
||||
} satisfies AcpStructuredLocationSpec
|
||||
const managedOnly = {
|
||||
managedRuntime: { pin: () => null }
|
||||
} satisfies AcpStructuredLocationSpec
|
||||
|
||||
expect(supportsAcpStructuredLocation(hostOnly, local, () => true)).toBe(true)
|
||||
expect(supportsAcpStructuredLocation(managedOnly, local, () => true)).toBe(false)
|
||||
expect(
|
||||
supportsAcpStructuredLocation(hostOnly, { ...local, wslDistro: 'Ubuntu' }, () => true)
|
||||
).toBe(false)
|
||||
expect(
|
||||
supportsAcpStructuredLocation(hostOnly, { ...local, executionHostId: 'ssh:host' }, () => true)
|
||||
).toBe(false)
|
||||
})
|
||||
@@ -1,14 +1,20 @@
|
||||
import type { AgentSessionExecutionLocation } from '../../../shared/agent-session/lifecycle/agent-session-record'
|
||||
import type { ManagedRuntime } from '../../node-runtime/managed-runtime-release'
|
||||
import { supportsSupervisedProviderChildLocation } from '../../provider-process/supervised-provider-child-location'
|
||||
import type { AcpLaunchSpec } from '../launch/acp-launch-contract'
|
||||
|
||||
export type AcpStructuredLocationSpec = {
|
||||
managedRuntime?: Pick<ManagedRuntime, 'pin'>
|
||||
hostBackend?: object
|
||||
}
|
||||
|
||||
export function supportsAcpStructuredLocation(
|
||||
spec: AcpLaunchSpec,
|
||||
spec: AcpStructuredLocationSpec,
|
||||
location: AgentSessionExecutionLocation,
|
||||
hasWindowsProcessStartTimeProof?: () => boolean
|
||||
): boolean {
|
||||
return (
|
||||
supportsSupervisedProviderChildLocation(location, hasWindowsProcessStartTimeProof) &&
|
||||
(!spec.managedRuntime || spec.managedRuntime.pin() !== null)
|
||||
// Without a release Orca can install here, only the host's own program can serve the chat.
|
||||
(!spec.managedRuntime || spec.managedRuntime.pin() !== null || spec.hostBackend !== undefined)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { withStructuredHistoryInvocation } from '../../../native-chat/agent-session-wire/acquisition/structured-agent-session-history-invocation'
|
||||
import { observeAcpForkSupport } from '../../capabilities/acp-fork-support'
|
||||
import { acpSessionStartMeta } from '../../launch/acp-session-meta'
|
||||
import { withAcpStartupDiagnostic } from './acp-startup-diagnostic'
|
||||
// An ACP child's handshake, run after the host has published it: initialize, reopen the chat's
|
||||
// session or start a new one, then return its protocol facts to the host. A saved session the agent
|
||||
@@ -27,6 +26,7 @@ import type { AcpStructuredLane } from '../../journal/acp-structured-lane'
|
||||
import type { AcpStructuredLaunch } from '../../launch/acp-structured-launch-resolution'
|
||||
import type { AcpStructuredOptions } from '../../options/acp-structured-options'
|
||||
import type { AcpStructuredPrompts } from '../../requests/acp-structured-prompts'
|
||||
import { acpSessionStartMeta } from '../../launch/acp-session-meta'
|
||||
import type { AcpStructuredSessionAdapterDeps } from '../acp-structured-session-adapter-deps'
|
||||
import { AcpStructuredTurns } from '../../turns/acp-structured-turns'
|
||||
import type { AcpStructuredTurnsDeps } from '../../turns/acp-turn-dispatch-contract'
|
||||
|
||||
@@ -69,7 +69,8 @@ const DOWNGRADE_DETAIL: Record<AgentLaunchDowngradeReason, string> = {
|
||||
structured_support_unknown: 'the execution host has not established structured session support',
|
||||
wsl_execution_runtime: 'this workspace runs under WSL',
|
||||
codex_on_windows: 'Codex has no structured session on Windows',
|
||||
chat_unavailable_on_windows: "this agent's chat isn't available on Windows yet",
|
||||
chat_unavailable_on_windows:
|
||||
"on Windows this agent's chat runs on agy, which is missing, outdated, or not signed in with a personal Google account",
|
||||
structured_unsupported_on_host: 'the execution host cannot create one here',
|
||||
chat_runtime_not_installed:
|
||||
"its chat runtime isn't installed on this host (install it from a new chat tab in Orca)"
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
const CONFIGURED_ANTIGRAVITY_ACP_ENVIRONMENT_KEYS = new Set([
|
||||
'AGY_ACP_FORCE_FILE_STORAGE',
|
||||
'BROWSER',
|
||||
'PYTHONUNBUFFERED',
|
||||
'ELECTRON_RUN_AS_NODE'
|
||||
])
|
||||
|
||||
/** Remove inherited authentication, harness and stale Electron Crashpad overrides. */
|
||||
export function scrubAntigravityAcpEnvironment(
|
||||
env: Record<string, string | undefined>,
|
||||
inherited: NodeJS.ProcessEnv
|
||||
): string[] {
|
||||
const removed = [...new Set([...Object.keys(env), ...Object.keys(inherited)])].filter((key) => {
|
||||
const normalized = process.platform === 'win32' ? key.toUpperCase() : key
|
||||
const shadowsConfiguredValue =
|
||||
process.platform === 'win32' &&
|
||||
CONFIGURED_ANTIGRAVITY_ACP_ENVIRONMENT_KEYS.has(normalized) &&
|
||||
key !== normalized
|
||||
return (
|
||||
shadowsConfiguredValue ||
|
||||
normalized.toUpperCase() === 'CHROME_CRASHPAD_PIPE_NAME' ||
|
||||
(!CONFIGURED_ANTIGRAVITY_ACP_ENVIRONMENT_KEYS.has(normalized) &&
|
||||
(normalized === 'GEMINI_API_KEY' ||
|
||||
normalized === 'ANTIGRAVITY_HARNESS_PATH' ||
|
||||
normalized === 'GCLOUD_PROJECT' ||
|
||||
normalized === 'CLOUDSDK_CORE_PROJECT' ||
|
||||
normalized.startsWith('GOOGLE_') ||
|
||||
normalized.startsWith('AGY_ACP_')))
|
||||
)
|
||||
})
|
||||
for (const key of removed) {
|
||||
delete env[key]
|
||||
}
|
||||
return removed
|
||||
}
|
||||
@@ -1,29 +1,10 @@
|
||||
import { ANTIGRAVITY_BROWSER_COMMAND } from './antigravity-browser-helper'
|
||||
export { scrubAntigravityAcpEnvironment } from './antigravity-acp-environment-sanitizer'
|
||||
|
||||
// Isolate sign-in files, capture browser links and flush Python output after scrubbing inherited auth.
|
||||
export const ANTIGRAVITY_ACP_ENV = {
|
||||
AGY_ACP_FORCE_FILE_STORAGE: '1',
|
||||
BROWSER: ANTIGRAVITY_BROWSER_COMMAND,
|
||||
PYTHONUNBUFFERED: '1'
|
||||
}
|
||||
|
||||
/** Remove inherited authentication and harness overrides. */
|
||||
export function scrubAntigravityAcpEnvironment(
|
||||
env: Record<string, string>,
|
||||
inherited: NodeJS.ProcessEnv
|
||||
): string[] {
|
||||
const removed = [...new Set([...Object.keys(env), ...Object.keys(inherited)])].filter(
|
||||
(key) =>
|
||||
!Object.hasOwn(ANTIGRAVITY_ACP_ENV, key) &&
|
||||
(key === 'GEMINI_API_KEY' ||
|
||||
key === 'ANTIGRAVITY_HARNESS_PATH' ||
|
||||
key === 'GCLOUD_PROJECT' ||
|
||||
key === 'CLOUDSDK_CORE_PROJECT' ||
|
||||
key.startsWith('GOOGLE_') ||
|
||||
key.startsWith('AGY_ACP_'))
|
||||
)
|
||||
for (const key of removed) {
|
||||
delete env[key]
|
||||
}
|
||||
return removed
|
||||
PYTHONUNBUFFERED: '1',
|
||||
ELECTRON_RUN_AS_NODE: '1'
|
||||
}
|
||||
|
||||
@@ -73,6 +73,10 @@ const ANTIGRAVITY_MANAGED_LAUNCH_SPEC = {
|
||||
transcriptImport: null,
|
||||
sessionHistory: ANTIGRAVITY_SESSION_HISTORY,
|
||||
privateTempDirectory: true,
|
||||
// The Windows 1.4.5 server otherwise writes its workflow tool into every chat workspace.
|
||||
...(process.platform === 'win32'
|
||||
? { sessionMeta: { antigravity: { disabledTools: ['run_workflow'] } } }
|
||||
: {}),
|
||||
// `session/load` replays the whole conversation, which the chat already holds.
|
||||
resumePreference: 'resume',
|
||||
resolveSessionMeta: antigravityChatRulesMeta,
|
||||
@@ -80,8 +84,11 @@ const ANTIGRAVITY_MANAGED_LAUNCH_SPEC = {
|
||||
} satisfies AcpLaunchSpec
|
||||
|
||||
// An inherited Gemini API key switches agy to key auth, which its models reject (401).
|
||||
function scrubAgyHostApiKeys(env: Record<string, string>): string[] {
|
||||
const removed = ['GEMINI_API_KEY', 'GOOGLE_API_KEY']
|
||||
function scrubAgyHostApiKeys(env: Record<string, string>, inherited: NodeJS.ProcessEnv): string[] {
|
||||
const removed = [...new Set([...Object.keys(env), ...Object.keys(inherited)])].filter((key) => {
|
||||
const normalized = process.platform === 'win32' ? key.toUpperCase() : key
|
||||
return normalized === 'GEMINI_API_KEY' || normalized === 'GOOGLE_API_KEY'
|
||||
})
|
||||
for (const key of removed) {
|
||||
delete env[key]
|
||||
}
|
||||
@@ -119,7 +126,8 @@ const ANTIGRAVITY_HOST_LAUNCH_SPEC: AcpLaunchSpec = {
|
||||
values: { ask: 'default', 'accept-edits': 'accept-edits', 'full-access': 'default' },
|
||||
fullAccessAtLaunch: true
|
||||
},
|
||||
keepsEverySession: true
|
||||
keepsEverySession: true,
|
||||
sessionMeta: undefined
|
||||
}
|
||||
|
||||
// The host's agy ignores Orca's account type, so any other saved choice, a malformed one, or one
|
||||
|
||||
@@ -114,7 +114,8 @@ async function initializeFromDisposableFolder(
|
||||
)
|
||||
outcome.failed = true
|
||||
}
|
||||
await rm(folder, { recursive: true, force: true })
|
||||
// Windows single-file runtimes can briefly retain DLLs they unpacked into this folder.
|
||||
await rm(folder, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 })
|
||||
return outcome
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@ import { probeAntigravityAcpServer } from './antigravity-acp-runtime-probe'
|
||||
|
||||
// 1.4.2 through 1.4.5 are reported to write skills/system/run-workflow/SKILL.md into the chat's
|
||||
// workspace when a session starts; check a newer release in an empty folder before moving this pin.
|
||||
const VERSION = '1.4.1'
|
||||
const VERSION = process.platform === 'win32' ? '1.4.5' : '1.4.1'
|
||||
const RELEASES = 'https://dl.google.com/agy-extensions/releases'
|
||||
const COMMAND = 'agy_acp_server.par'
|
||||
const COMMAND = process.platform === 'win32' ? 'agy_acp_server.exe' : 'agy_acp_server.par'
|
||||
// The server finds its harness beside itself.
|
||||
const HARNESS = 'localharness_external'
|
||||
const HARNESS = process.platform === 'win32' ? 'localharness_external.exe' : 'localharness_external'
|
||||
|
||||
type Pinned = {
|
||||
path: string
|
||||
@@ -57,6 +57,24 @@ const PINNED: Record<string, Pinned> = {
|
||||
serverBytes: 933416796,
|
||||
harness: '18bcd9a2ab80b66d90f61add7a52a37f53d3113bb0429a0b92709ed09f32a6e1',
|
||||
harnessBytes: 124895000
|
||||
},
|
||||
'win32-x64': {
|
||||
path: 'windows/agy-acp-server-1.4.5-windows-x86_64.zip',
|
||||
archive: 'd24f4c73c9f96d4f44384e281c855a56c72d8eaa9c5b0fad7ccb1635c6b63f50',
|
||||
archiveBytes: 100423655,
|
||||
server: 'ccca30a4aef1b915b0d8baa17b149de6cda305841fa27717e52c529bb462c51d',
|
||||
serverBytes: 55839864,
|
||||
harness: '98f808f7796c0a06d104715dbef65025e57243106fff5935d9bedd5843f03cda',
|
||||
harnessBytes: 147843736
|
||||
},
|
||||
'win32-arm64': {
|
||||
path: 'windows/agy-acp-server-1.4.5-windows-arm64.zip',
|
||||
archive: 'ab0a9aac8349e08ef289be6d16da8f89e3abe60eba5158032ef78c4a1220261c',
|
||||
archiveBytes: 102703121,
|
||||
server: 'c1363f25215a131b0c114d28da9a952b39eef7596408e33cfb3487c87f32ffb2',
|
||||
serverBytes: 62293488,
|
||||
harness: 'b56aa033e85c3df681e15deb1aaceda8a98e137c55c05a625071b11546d7b840',
|
||||
harnessBytes: 139322008
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,32 @@ import { join } from 'node:path'
|
||||
import { runProcess } from '@orca/process-host'
|
||||
import { expect, it, vi } from 'vitest'
|
||||
|
||||
import { scrubAntigravityAcpEnvironment } from './antigravity-acp-environment-sanitizer'
|
||||
import {
|
||||
ANTIGRAVITY_BROWSER_MARKER,
|
||||
antigravityBrowserHelperPreflightPassed
|
||||
} from './antigravity-browser-helper'
|
||||
|
||||
it('removes a case-insensitive Crashpad pipe override from the helper environment', () => {
|
||||
const env = { chrome_crashpad_pipe_name: 'stale', PATH: '/bin' }
|
||||
expect(scrubAntigravityAcpEnvironment(env, env)).toContain('chrome_crashpad_pipe_name')
|
||||
expect(env).toEqual({ PATH: '/bin' })
|
||||
})
|
||||
|
||||
it('rejects a truncated browser-helper preflight capture', () => {
|
||||
const marker = `${ANTIGRAVITY_BROWSER_MARKER}${JSON.stringify(
|
||||
'https://example.invalid/orca-antigravity-browser-preflight'
|
||||
)}\n`
|
||||
expect(
|
||||
antigravityBrowserHelperPreflightPassed({
|
||||
code: 0,
|
||||
stdout: '',
|
||||
stderr: marker,
|
||||
outputTruncated: true
|
||||
})
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it.skipIf(process.platform === 'win32')(
|
||||
'runs the real Python BROWSER parser with a colon, space and apostrophe in the executable path',
|
||||
async () => {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { quotePosixShellDoubleQuotedApostrophe } from '../../shared/shell/launch/shell-argument-quoting'
|
||||
import { runProcess } from '@orca/process-host'
|
||||
import { scrubAntigravityAcpEnvironment } from './antigravity-acp-environment-sanitizer'
|
||||
|
||||
export const ANTIGRAVITY_BROWSER_MARKER = '__ORCA_ANTIGRAVITY_AUTH_URL__'
|
||||
|
||||
@@ -17,13 +18,33 @@ const PREFLIGHT_URL = 'https://example.invalid/orca-antigravity-browser-prefligh
|
||||
const executable = process.execPath.replaceAll('\\', '\\\\').replaceAll(':', '\\072')
|
||||
const shell = `exec /usr/bin/env ELECTRON_RUN_AS_NODE=1 "$(printf %b ${quotePosixShellDoubleQuotedApostrophe(executable)})" -e ${quotePosixShellDoubleQuotedApostrophe(HELPER_SOURCE)} -- "$1"`
|
||||
const BROWSER_ARGV = ['/bin/sh', '-c', shell, '--', '%s']
|
||||
export const ANTIGRAVITY_BROWSER_COMMAND = BROWSER_ARGV.map(
|
||||
quotePosixShellDoubleQuotedApostrophe
|
||||
const WINDOWS_BROWSER_ARGV = [process.execPath, '-e', HELPER_SOURCE, '--', '%s']
|
||||
const POSIX_BROWSER_COMMAND = BROWSER_ARGV.map(quotePosixShellDoubleQuotedApostrophe).join(' ')
|
||||
const WINDOWS_BROWSER_COMMAND = WINDOWS_BROWSER_ARGV.map(
|
||||
(arg) => `'${arg.replaceAll("'", `'"'"'`)}'`
|
||||
).join(' ')
|
||||
const usable = !/[\r\n\0]|%s/.test(process.execPath)
|
||||
const usable =
|
||||
!/[\r\n\0]|%s/.test(process.execPath) &&
|
||||
(process.platform !== 'win32' || !process.execPath.includes(';'))
|
||||
|
||||
export const ANTIGRAVITY_BROWSER_COMMAND =
|
||||
process.platform === 'win32' ? WINDOWS_BROWSER_COMMAND : POSIX_BROWSER_COMMAND
|
||||
|
||||
export const antigravityBrowserArgv = (link: string): string[] =>
|
||||
BROWSER_ARGV.map((arg) => (arg === '%s' ? link : arg))
|
||||
(process.platform === 'win32' ? WINDOWS_BROWSER_ARGV : BROWSER_ARGV).map((arg) =>
|
||||
arg === '%s' ? link : arg
|
||||
)
|
||||
|
||||
export const antigravityBrowserHelperPreflightPassed = (result: {
|
||||
readonly code: number | null
|
||||
readonly stdout: string
|
||||
readonly stderr: string
|
||||
readonly outputTruncated?: boolean
|
||||
}): boolean =>
|
||||
result.code === 0 &&
|
||||
result.stdout === '' &&
|
||||
!result.outputTruncated &&
|
||||
result.stderr === `${ANTIGRAVITY_BROWSER_MARKER}${JSON.stringify(PREFLIGHT_URL)}\n`
|
||||
|
||||
/** Check before each server start: a broken helper could let Python launch a real browser. */
|
||||
export async function antigravityBrowserHelperWorks(): Promise<boolean> {
|
||||
@@ -31,11 +52,15 @@ export async function antigravityBrowserHelperWorks(): Promise<boolean> {
|
||||
return false
|
||||
}
|
||||
const [program = '', ...args] = antigravityBrowserArgv(PREFLIGHT_URL)
|
||||
const spec = { program, args, timeoutMs: 5_000, maxOutputBytes: 4_096 }
|
||||
const env: Record<string, string | undefined> = { ...process.env }
|
||||
scrubAntigravityAcpEnvironment(env, process.env)
|
||||
const spec = {
|
||||
program,
|
||||
args,
|
||||
...(process.platform === 'win32' ? { env: { ...env, ELECTRON_RUN_AS_NODE: '1' } } : {}),
|
||||
timeoutMs: 5_000,
|
||||
maxOutputBytes: 4_096
|
||||
}
|
||||
const result = await runProcess(spec).catch(() => null)
|
||||
return (
|
||||
result?.code === 0 &&
|
||||
result.stdout === '' &&
|
||||
result.stderr === `${ANTIGRAVITY_BROWSER_MARKER}${JSON.stringify(PREFLIGHT_URL)}\n`
|
||||
)
|
||||
return result !== null && antigravityBrowserHelperPreflightPassed(result)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { structuredAgentHostLaunchSources } from '../runtime/agent-session/launc
|
||||
import * as profileStorage from '../orca-profiles/profile-storage-paths'
|
||||
// The chat sign-in against a scripted Antigravity server.
|
||||
|
||||
import { existsSync } from 'node:fs'
|
||||
import { createServer } from 'node:http'
|
||||
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
@@ -94,6 +95,8 @@ async function signInAgainst(
|
||||
sessionResult?: Record<string, unknown>
|
||||
authConfig?: AntigravityChatAuthConfig
|
||||
realLaunchSources?: boolean
|
||||
/** A new server asks to sign in again, as after Google grants fewer scopes than requested. */
|
||||
savedSignInUnusable?: boolean
|
||||
} = {}
|
||||
) {
|
||||
vi.spyOn(ANTIGRAVITY_LAUNCH_SPEC.managedRuntime, 'pin').mockReturnValue(PIN)
|
||||
@@ -104,24 +107,42 @@ async function signInAgainst(
|
||||
)
|
||||
folders.push(stateDirectory)
|
||||
const folder = join(stateDirectory, 'antigravity-chat')
|
||||
const agent = new AcpScriptedAgent()
|
||||
const stderr = new PassThrough()
|
||||
const [browserDone, sessionOpen] = [deferred<void>(), deferred<void>()]
|
||||
agent.on('authenticate', (frame) => {
|
||||
void output().then((text) => (options.stream === 'stdout' ? agent.stdout : stderr).write(text))
|
||||
void browserDone.promise.then(() => agent.reply(frame, {}))
|
||||
})
|
||||
agent.on('session/new', (frame) => {
|
||||
void sessionOpen.promise.then(async () => {
|
||||
const { cwd } = z.object({ cwd: z.string() }).parse(frame.params)
|
||||
await mkdir(join(folder, 'antigravity-acp', 'brain', SESSION), { recursive: true })
|
||||
await mkdir(join(folder, 'antigravity-acp', 'conversations'), { recursive: true })
|
||||
await writeFile(sessionFile(folder, '.db'), '')
|
||||
await writeFile(sessionFile(folder, '.meta'), JSON.stringify({ cwd: options.metaCwd ?? cwd }))
|
||||
agent.reply(frame, { ...options.sessionResult, sessionId: SESSION })
|
||||
// Each launch is a new server process that holds only what the sign-in saved.
|
||||
const spawnServer = () => {
|
||||
const agent = new AcpScriptedAgent()
|
||||
const stderr = new PassThrough()
|
||||
const signInOutput = () =>
|
||||
void output().then((text) =>
|
||||
(options.stream === 'stdout' ? agent.stdout : stderr).write(text)
|
||||
)
|
||||
let authenticatedHere = false
|
||||
agent.on('authenticate', (frame) => {
|
||||
signInOutput()
|
||||
void browserDone.promise.then(() => {
|
||||
authenticatedHere = true
|
||||
agent.reply(frame, {})
|
||||
})
|
||||
})
|
||||
})
|
||||
const child = fakeServer(agent, stderr)
|
||||
agent.on('session/new', (frame) => {
|
||||
if (options.savedSignInUnusable && !authenticatedHere) {
|
||||
signInOutput()
|
||||
return
|
||||
}
|
||||
void sessionOpen.promise.then(async () => {
|
||||
const { cwd } = z.object({ cwd: z.string() }).parse(frame.params)
|
||||
await mkdir(join(folder, 'antigravity-acp', 'brain', SESSION), { recursive: true })
|
||||
await mkdir(join(folder, 'antigravity-acp', 'conversations'), { recursive: true })
|
||||
await writeFile(sessionFile(folder, '.db'), '')
|
||||
await writeFile(
|
||||
sessionFile(folder, '.meta'),
|
||||
JSON.stringify({ cwd: options.metaCwd ?? cwd })
|
||||
)
|
||||
agent.reply(frame, { ...options.sessionResult, sessionId: SESSION })
|
||||
})
|
||||
})
|
||||
return fakeServer(agent, stderr)
|
||||
}
|
||||
// Satisfy runtime resolution from PATH without downloading.
|
||||
const bin = join(stateDirectory, 'bin')
|
||||
await mkdir(bin)
|
||||
@@ -159,19 +180,16 @@ async function signInAgainst(
|
||||
}),
|
||||
stopLiveChats: async () => {},
|
||||
connect: vi.fn<ConnectAcpAgent<AcpAgentConnection>>((launch, connectionOptions) => {
|
||||
const connection = createAcpAgentConnection(launch, connectionOptions, () => child)
|
||||
const connection = createAcpAgentConnection(launch, connectionOptions, spawnServer)
|
||||
options.configure?.(connection)
|
||||
return connection
|
||||
})
|
||||
}
|
||||
const { flowId } = startAntigravityChatSignIn(host, DESKTOP)
|
||||
return {
|
||||
agent,
|
||||
folder,
|
||||
flowId,
|
||||
host,
|
||||
child,
|
||||
stderr,
|
||||
finishBrowser: () => browserDone.resolve(),
|
||||
openSession: () => sessionOpen.resolve()
|
||||
}
|
||||
@@ -291,3 +309,28 @@ it('signs in from the address a browser on another computer ended on', async ()
|
||||
listener.close()
|
||||
}
|
||||
})
|
||||
|
||||
it('fails, and drops the token, when a new server cannot use the saved sign-in', async () => {
|
||||
vi.spyOn(console, 'warn').mockImplementation(() => {})
|
||||
const { flowId, folder, host, finishBrowser, openSession } = await signInAgainst(
|
||||
printed(GOOGLE_LINK),
|
||||
{ savedSignInUnusable: true }
|
||||
)
|
||||
expect(await stateAfter(flowId, 'starting')).toMatchObject({ phase: 'waiting' })
|
||||
const token = join(folder, 'antigravity-acp', 'acp_token.json')
|
||||
await mkdir(join(folder, 'antigravity-acp'), { recursive: true })
|
||||
await writeFile(token, '{}')
|
||||
const ended = Promise.withResolvers<AntigravityChatSignInStatus['flow']>()
|
||||
const { close } = await follow(({ flow }) => {
|
||||
if (flow?.flowId === flowId && (flow.phase === 'failed' || flow.phase === 'signedIn')) {
|
||||
ended.resolve(flow)
|
||||
}
|
||||
})
|
||||
finishBrowser()
|
||||
openSession()
|
||||
expect(await ended.promise.finally(close)).toMatchObject({ phase: 'failed' })
|
||||
expect(existsSync(token)).toBe(false)
|
||||
// Each server's exit removes its own temp folder, so the verifier must not share the first's.
|
||||
const temps = host.connect.mock.calls.map(([launch]) => launch.env?.TMPDIR)
|
||||
expect(new Set(temps).size).toBe(2)
|
||||
})
|
||||
|
||||
@@ -18,15 +18,14 @@ import {
|
||||
type AcpLaunchSettings
|
||||
} from '../acp/launch/acp-structured-launch-resolution'
|
||||
import { prepareAcpLaunch } from '../acp/launch/acp-structured-launch-preparation'
|
||||
import { AcpAgentError, AcpConnectionClosedError } from '../acp/transport/acp-errors'
|
||||
import { AcpConnectionClosedError } from '../acp/transport/acp-errors'
|
||||
import { captureSignInModelPublisher } from './antigravity-sign-in-models'
|
||||
import { SIGN_IN_FAILED, antigravitySignInFailure } from './antigravity-sign-in-failure'
|
||||
import { antigravitySignInFailure } from './antigravity-sign-in-failure'
|
||||
import type { structuredAgentHostLaunchSources } from '../runtime/agent-session/launch/structured-agent-launch-support'
|
||||
import {
|
||||
AntigravitySignInCloseUnprovenError,
|
||||
AntigravitySignInSentence,
|
||||
antigravityChatSignIn,
|
||||
closeAntigravitySignInOwner
|
||||
antigravityChatSignIn
|
||||
} from './antigravity-chat-account'
|
||||
import {
|
||||
antigravitySignInCallback,
|
||||
@@ -34,6 +33,7 @@ import {
|
||||
type AntigravitySignInPending
|
||||
} from './antigravity-sign-in-callback'
|
||||
import { removeAntigravitySignInSessionFiles } from './antigravity-sign-in-session-files'
|
||||
import { antigravitySignInServers } from './antigravity-sign-in-server'
|
||||
import { antigravitySignInUrl } from './antigravity-sign-in-url'
|
||||
|
||||
// Match the server’s browser wait.
|
||||
@@ -43,8 +43,6 @@ const SECOND_LINK = {
|
||||
error: 'Antigravity started more than one Google sign-in request.'
|
||||
} as const
|
||||
const NOT_ACTIVE = 'This sign-in is no longer active in this client.'
|
||||
const SESSION_FAILED =
|
||||
'Antigravity authenticated, but could not initialize a session or load models.'
|
||||
|
||||
type Phase = accountTypes.AntigravityChatSignInState['phase']
|
||||
type Flow = {
|
||||
@@ -178,14 +176,18 @@ async function signIn(current: Flow, host: AntigravityChatSignInHost): Promise<v
|
||||
})
|
||||
// Reuse chat launch resolution without downloading a runtime.
|
||||
const launch = await prepareAcpLaunch(resolve, closed)
|
||||
const connect = await acpPrivateTempConnect(deps, closed)
|
||||
const home = launch.env.GEMINI_HOME
|
||||
const cwd = await mkdtemp(join(tmpdir(), 'orca-antigravity-sign-in-'))
|
||||
let connection: AcpAgentConnection | null = null
|
||||
// Wait for proven exit and session ownership before deleting files.
|
||||
const owned = { sessionId: '', exited: false, done: false, disposed: false }
|
||||
const serverLaunch = {
|
||||
...launch,
|
||||
args: launch.spec.args({ fullAccess: false, pluginDir: null }),
|
||||
cwd
|
||||
}
|
||||
const liveServers = new Set<AcpAgentConnection>()
|
||||
// Wait for every server's proven exit and session ownership before deleting files.
|
||||
const owned = { sessionId: '', done: false, disposed: false }
|
||||
const disposeWhenGone = async (): Promise<void> => {
|
||||
if (!owned.exited || !owned.done || owned.disposed) {
|
||||
if (liveServers.size > 0 || !owned.done || owned.disposed) {
|
||||
return
|
||||
}
|
||||
owned.disposed = true
|
||||
@@ -194,24 +196,25 @@ async function signIn(current: Flow, host: AntigravityChatSignInHost): Promise<v
|
||||
console.warn('[antigravity] sign-in session files not removed:', error)
|
||||
)
|
||||
}
|
||||
const servers = antigravitySignInServers({
|
||||
connectServer: () => acpPrivateTempConnect(deps, closed),
|
||||
home,
|
||||
launch: serverLaunch,
|
||||
signal,
|
||||
closed,
|
||||
spawned: (server) => {
|
||||
liveServers.add(server)
|
||||
server.onExit(() => {
|
||||
liveServers.delete(server)
|
||||
void disposeWhenGone()
|
||||
})
|
||||
}
|
||||
})
|
||||
try {
|
||||
connection = connect(
|
||||
{ ...launch, args: launch.spec.args({ fullAccess: false, pluginDir: null }), cwd },
|
||||
{
|
||||
clientInfo: { name: 'orca', version: '1' },
|
||||
signIn: { ...ANTIGRAVITY_LAUNCH_SPEC.signIn, link: (link) => receiveLink(current, link) }
|
||||
}
|
||||
)
|
||||
const server = connection
|
||||
server.onExit(() => {
|
||||
owned.exited = true
|
||||
void disposeWhenGone()
|
||||
})
|
||||
const stop = (): void => void server.close().catch(() => false)
|
||||
signal.addEventListener('abort', stop, { once: true })
|
||||
try {
|
||||
const watch = { ...spec.signIn, link: (link: string) => receiveLink(current, link) }
|
||||
await servers.run(watch, async (server) => {
|
||||
const method = resolveAntigravityChatAuthConfig(launch.antigravityChatAuth).method
|
||||
const initialized = await connection.initialize()
|
||||
const initialized = await server.initialize()
|
||||
closed()
|
||||
if (
|
||||
initialized.authMethods &&
|
||||
@@ -219,25 +222,23 @@ async function signIn(current: Flow, host: AntigravityChatSignInHost): Promise<v
|
||||
) {
|
||||
throw new AntigravitySignInSentence(spec.authMethodUnavailableMessage)
|
||||
}
|
||||
await connection.authenticate(method)
|
||||
publish(current, { phase: 'verifying' })
|
||||
// Authentication alone does not prove a chat can start.
|
||||
const started = await connection.start({ cwd, mcpServers: [] }).catch((error: unknown) => {
|
||||
const plain = error instanceof AcpAgentError && error.code === -32603
|
||||
throw plain && antigravitySignInFailure(error) === SIGN_IN_FAILED
|
||||
? new AntigravitySignInSentence(SESSION_FAILED)
|
||||
: error
|
||||
})
|
||||
owned.sessionId = started.sessionId
|
||||
await server.authenticate(method)
|
||||
current.pending = undefined
|
||||
publishModels(accountHome, started, !connection.exited)
|
||||
} finally {
|
||||
signal.removeEventListener('abort', stop)
|
||||
await closeAntigravitySignInOwner(home, server)
|
||||
}
|
||||
})
|
||||
closed()
|
||||
publish(current, { phase: 'verifying' })
|
||||
const { started, live } = await servers.startOnSavedSignIn(
|
||||
spec,
|
||||
(sessionId) => (owned.sessionId = sessionId)
|
||||
)
|
||||
publishModels(accountHome, started, live)
|
||||
} finally {
|
||||
owned.done = true
|
||||
owned.exited ||= !connection || connection.exited
|
||||
for (const server of liveServers) {
|
||||
if (server.exited) {
|
||||
liveServers.delete(server)
|
||||
}
|
||||
}
|
||||
await disposeWhenGone()
|
||||
}
|
||||
}
|
||||
@@ -263,7 +264,6 @@ function ownFlow(owner: string, flowId: string): Flow {
|
||||
}
|
||||
return current
|
||||
}
|
||||
|
||||
/** Await cleanup so the next chat start can acquire the launch gate. */
|
||||
export async function cancelAntigravityChatSignIn(
|
||||
owner: string,
|
||||
@@ -306,7 +306,6 @@ export async function completeAntigravityChatSignIn(
|
||||
}
|
||||
return readAntigravityChatSignInStatus(owner).flow
|
||||
}
|
||||
|
||||
export const subscribeAntigravityChatSignIn = (onChange: () => void): (() => void) =>
|
||||
antigravityChatSignIn.subscribe(onChange)
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ export const ANTIGRAVITY_HOST_ACP_MINIMUM_VERSION = '1.5.2'
|
||||
const AGY_HOME_FOLDER = '.gemini'
|
||||
/** Approves tools, not plans; the check launches with it, so a build without it stays managed. */
|
||||
export const AGY_SKIP_PERMISSIONS_FLAG = '--dangerously-skip-permissions'
|
||||
const PROBE_TIMEOUT_MS = 5_000
|
||||
// agy.exe took 6-7s to list sessions while Orca started, and Windows has no managed fallback.
|
||||
const PROBE_TIMEOUT_MS = process.platform === 'win32' ? 15_000 : 5_000
|
||||
const RECHECK_MS = 5 * 60_000
|
||||
|
||||
export function isCompatibleAntigravityHostAcp(initialized: InitializeResponse): boolean {
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import { rm } from 'node:fs/promises'
|
||||
import { join } from 'node:path'
|
||||
import type { AcpLaunchSpec } from '../acp/launch/acp-launch-contract'
|
||||
import { acpSessionStartMeta } from '../acp/launch/acp-session-meta'
|
||||
import type { AcpAgentConnection, AcpSignInWatch } from '../acp/process/acp-agent-connection'
|
||||
import type { ConnectAcpAgent } from '../acp/process/acp-structured-connection'
|
||||
import { AcpAgentError, AcpSignInPromptError } from '../acp/transport/acp-errors'
|
||||
import { ANTIGRAVITY_ACP_HOME } from '../../shared/agent-session/lifecycle/provider-handles/antigravity-session-origin'
|
||||
import { AntigravitySignInSentence, closeAntigravitySignInOwner } from './antigravity-chat-account'
|
||||
import { SIGN_IN_FAILED, antigravitySignInFailure } from './antigravity-sign-in-failure'
|
||||
|
||||
const SESSION_FAILED =
|
||||
'Antigravity authenticated, but could not initialize a session or load models.'
|
||||
const SAVED_SIGN_IN_UNUSABLE =
|
||||
"Google sign-in finished, but Antigravity can't use the saved sign-in. Start sign-in again and allow every permission Google asks for."
|
||||
|
||||
type SignInServerInput = {
|
||||
/** A new private temp folder per server: each server's exit removes its own. */
|
||||
connectServer: () => Promise<ConnectAcpAgent<AcpAgentConnection>>
|
||||
home: string
|
||||
launch: Parameters<ConnectAcpAgent<AcpAgentConnection>>[0] & { cwd: string }
|
||||
signal: AbortSignal
|
||||
closed: () => void
|
||||
/** Every server, so cleanup can wait for each one's exit. */
|
||||
spawned: (server: AcpAgentConnection) => void
|
||||
}
|
||||
|
||||
/** Sign-in's server processes; each call returns only after its server's close is accepted. */
|
||||
export function antigravitySignInServers({
|
||||
connectServer,
|
||||
home,
|
||||
launch,
|
||||
signal,
|
||||
closed,
|
||||
spawned
|
||||
}: SignInServerInput) {
|
||||
const run = async <T>(
|
||||
watch: AcpSignInWatch,
|
||||
body: (server: AcpAgentConnection) => Promise<T>
|
||||
): Promise<T> => {
|
||||
const connect = await connectServer()
|
||||
const server = connect(launch, { clientInfo: { name: 'orca', version: '1' }, signIn: watch })
|
||||
spawned(server)
|
||||
const stop = (): void => void server.close().catch(() => false)
|
||||
signal.addEventListener('abort', stop, { once: true })
|
||||
try {
|
||||
return await body(server)
|
||||
} finally {
|
||||
signal.removeEventListener('abort', stop)
|
||||
await closeAntigravitySignInOwner(home, server)
|
||||
}
|
||||
}
|
||||
|
||||
// Only a server holding just the saved sign-in proves later chats can use it: Google can grant
|
||||
// fewer scopes than requested, and the server then saves a token it can never refresh.
|
||||
const startOnSavedSignIn = (
|
||||
spec: AcpLaunchSpec & { signIn: AcpSignInWatch },
|
||||
// Before close, so a server whose exit is unproven still hands over its session's files.
|
||||
started: (sessionId: string) => void
|
||||
) =>
|
||||
run({ read: spec.signIn.read, answered: spec.signIn.answered }, async (server) => {
|
||||
await server.initialize()
|
||||
closed()
|
||||
const session = await server
|
||||
.start({ cwd: launch.cwd, mcpServers: [], ...acpSessionStartMeta(spec) })
|
||||
.catch((error: unknown) => {
|
||||
const plain = error instanceof AcpAgentError && error.code === -32603
|
||||
throw plain && antigravitySignInFailure(error) === SIGN_IN_FAILED
|
||||
? new AntigravitySignInSentence(SESSION_FAILED)
|
||||
: error
|
||||
})
|
||||
started(session.sessionId)
|
||||
return { started: session, live: !server.exited }
|
||||
}).catch(async (error: unknown) => {
|
||||
// Only the server asking for a browser sign-in proves the token unusable; other refusals keep
|
||||
// their own wording. An unusable token would still keep new chats off the host's own agy.
|
||||
if (!(error instanceof AcpSignInPromptError)) {
|
||||
throw error
|
||||
}
|
||||
await rm(join(home, ANTIGRAVITY_ACP_HOME, 'acp_token.json'), { force: true })
|
||||
throw new AntigravitySignInSentence(SAVED_SIGN_IN_UNUSABLE, { cause: error })
|
||||
})
|
||||
|
||||
return { run, startOnSavedSignIn }
|
||||
}
|
||||
@@ -52,7 +52,8 @@ function acpChatProgram(spec: AcpLaunchSpec): StructuredAgentChatProgram {
|
||||
? {
|
||||
hostAlternative: async (shellEnv, settings) =>
|
||||
(await selectAcpHostAccountHome(spec, shellEnv, getProfileUserDataPath(), settings)) !==
|
||||
null
|
||||
null,
|
||||
...(managedRuntime ? { onlyHostAlternative: () => managedRuntime.pin() === null } : {})
|
||||
}
|
||||
: {})
|
||||
}
|
||||
|
||||
+2
@@ -116,6 +116,8 @@ export type StructuredAgentChatProgram = {
|
||||
env: Record<string, string>,
|
||||
settings: AcpHostBackendSettings
|
||||
) => Promise<boolean>
|
||||
/** Whether no release Orca can install runs here, so chats start only on `hostAlternative`. */
|
||||
onlyHostAlternative?: () => boolean
|
||||
}
|
||||
|
||||
export type StructuredAgentRuntimeMetadata = StructuredAgentCliConversations & {
|
||||
|
||||
@@ -11,6 +11,7 @@ import { onAgentsRefreshedOnHost } from '../../../preflight/agents-refreshed-on-
|
||||
import {
|
||||
observeStructuredAgentLaunch,
|
||||
resolveHostStructuredAgentLaunchEnvironment,
|
||||
structuredAgentHostAlternativeReady,
|
||||
type LaunchEnvironmentSettings
|
||||
} from './structured-agent-launch-support'
|
||||
import {
|
||||
@@ -50,10 +51,16 @@ const HOST_LOCATION: AgentSessionExecutionLocation = {
|
||||
type HealthRuntime = Parameters<typeof observeStructuredAgentLaunch>[2]
|
||||
|
||||
async function observeHostAgent(
|
||||
{ definition: { agent }, supportsLocation }: StructuredAgentRuntimeMetadata,
|
||||
{ definition: { agent }, supportsLocation, chatProgram }: StructuredAgentRuntimeMetadata,
|
||||
runtime: HealthRuntime
|
||||
): Promise<AgentSessionAgentAvailability> {
|
||||
if (!supportsLocation(HOST_LOCATION)) {
|
||||
if (chatProgram?.onlyHostAlternative?.() && supportsLocation(HOST_LOCATION)) {
|
||||
const ready = await structuredAgentHostAlternativeReady(agent, runtime).catch(() => null)
|
||||
if (ready !== false) {
|
||||
return { agent, state: ready ? 'available' : 'unknown' }
|
||||
}
|
||||
}
|
||||
if (!supportsLocation(HOST_LOCATION) || chatProgram?.onlyHostAlternative?.()) {
|
||||
const reason = structuredChatUnavailableOnPlatform(agent, process.platform)
|
||||
? 'windows'
|
||||
: 'agent'
|
||||
|
||||
@@ -78,13 +78,30 @@ export async function observeStructuredAgentLaunch(
|
||||
)
|
||||
}
|
||||
|
||||
/** Whether a new chat would start on the host's own program, as its account home selects one. */
|
||||
export async function structuredAgentHostAlternativeReady(
|
||||
agent: string,
|
||||
runtime: LaunchSettingsRuntime
|
||||
): Promise<boolean> {
|
||||
const program = structuredAgentRuntimeMetadata(agent)?.chatProgram
|
||||
if (!program?.hostAlternative) {
|
||||
return false
|
||||
}
|
||||
const settings = runtime.requireStore().getSettings()
|
||||
const env = await resolveHostStructuredAgentLaunchEnvironment(agent, settings)
|
||||
return program.hostAlternative(env, settings).catch(() => false)
|
||||
}
|
||||
|
||||
/** Admission's answer in the workspace `cwd` names: only a too-old or unstartable binary keeps the
|
||||
* terminal. */
|
||||
* terminal, or, where Orca installs no release, a host program that cannot serve the chat. */
|
||||
export async function structuredAgentSupportsLaunch(
|
||||
agent: string,
|
||||
cwd: () => Promise<string>,
|
||||
runtime: LaunchSettingsRuntime
|
||||
): Promise<boolean> {
|
||||
if (structuredAgentRuntimeMetadata(agent)?.chatProgram?.onlyHostAlternative?.()) {
|
||||
return structuredAgentHostAlternativeReady(agent, runtime)
|
||||
}
|
||||
try {
|
||||
const release = await observeStructuredAgentLaunch(agent, cwd, runtime, true)
|
||||
return release === null || launchableRelease(release)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/** Google publishes no Windows Antigravity chat server Orca can run (#30817); relax this once one ships. */
|
||||
export function structuredChatUnavailableOnPlatform(
|
||||
agent: string,
|
||||
platform: string | null | undefined
|
||||
_agent: string,
|
||||
_platform: string | null | undefined
|
||||
): boolean {
|
||||
return agent === 'antigravity' && platform === 'win32'
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user