Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@ const AntigravityProviderCapabilitiesV2 = {
},
} satisfies OrchestrationV2ProviderCapabilities;

/** Thread variables reach the driver here; `makeAntigravityAcpRuntime` never reads them. */
export type AntigravityAdapterV2RuntimeInput = Omit<
AntigravityAcpRuntimeInput,
"spawn" | "childProcessSpawner"
> & { readonly processEnvironment?: NodeJS.ProcessEnv };

export interface AntigravityAdapterV2Options {
readonly instanceId: ProviderInstanceId;
readonly selfInvocation: SelfInvocation;
readonly makeRuntime: (
input: Omit<AntigravityAcpRuntimeInput, "spawn" | "childProcessSpawner">,
input: AntigravityAdapterV2RuntimeInput,
) => Effect.Effect<
AcpSessionRuntime.AcpSessionRuntime["Service"],
EffectAcpErrors.AcpError | ProviderSetupError,
Expand Down
84 changes: 83 additions & 1 deletion apps/server/src/provider/Drivers/AntigravityDriver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
import { expect, it } from "@effect/vitest";
import {
ANTIGRAVITY_DEFAULT_MODEL,
EnvironmentId,
ProviderInstanceId,
ProviderSessionId,
ThreadId,
Expand Down Expand Up @@ -57,7 +58,12 @@ function shellQuote(value: string): string {
}

const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
options: { readonly config?: Partial<AntigravitySettings>; readonly enabled?: boolean } = {},
options: {
readonly config?: Partial<AntigravitySettings>;
readonly enabled?: boolean;
/** Extra instance variables, such as ones a parent T3 turn already exported. */
readonly environment?: ReadonlyArray<{ readonly name: string; readonly value: string }>;
} = {},
) {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
Expand Down Expand Up @@ -136,6 +142,7 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
args: ReadonlyArray<string>;
cwd: string | undefined;
extendEnv: boolean | undefined;
environment: Record<string, string | undefined>;
profileDirectory: string | undefined;
harnessPath: string | undefined;
forceFileStorage: string | undefined;
Expand Down Expand Up @@ -191,6 +198,7 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
args: command.args.map(String),
cwd: command.options.cwd,
extendEnv: command.options.extendEnv,
environment: Object.fromEntries(Object.keys(environment).map((name) => [name, env(name)])),
profileDirectory: env("GEMINI_HOME"),
harnessPath: env("ANTIGRAVITY_HARNESS_PATH"),
forceFileStorage: env("AGY_ACP_FORCE_FILE_STORAGE"),
Expand Down Expand Up @@ -221,6 +229,7 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
{ name: "GEMINI_HOME", value: "/must-not-be-used" },
{ name: "ANTIGRAVITY_HARNESS_PATH", value: "/must-not-be-used" },
{ name: "BROWSER", value: "must-not-run" },
...(options.environment ?? []),
].map((variable) => ({ ...variable, sensitive: false })),
}).pipe(
Effect.provide(layerInstallation),
Expand Down Expand Up @@ -447,6 +456,79 @@ it.layer(layerTest)("AntigravityDriver", (it) => {
}),
);

it.effect.skipIf(windowsHost)(
"gives a thread session its own T3 thread and MCP fallback environment",
() =>
Effect.gen(function* () {
const h = yield* makeHarness({
environment: [
{ name: "T3CODE_THREAD_ID", value: "thread-antigravity-ambient" },
{ name: "T3_ACP_MCP_ENDPOINT", value: "http://127.0.0.1:9/ambient" },
{ name: "T3_ACP_MCP_AUTHORIZATION", value: "Bearer ambient-token" },
{ name: "T3_ACP_MCP_NODE", value: "/ambient/node" },
{ name: "T3_ACP_MCP_ENTRYPOINT", value: "/ambient/entrypoint.mjs" },
],
});
yield* h.refresh();
const endpoint = "http://127.0.0.1:43126/mcp";
const threadId = ThreadId.make("thread-antigravity-process-environment");
yield* (yield* McpProviderSessions.McpProviderSessions).set({
environmentId: EnvironmentId.make("environment-antigravity-process-environment"),
threadId,
providerSessionId: "mcp-session-antigravity-process-environment",
providerInstanceId: h.instance.instanceId,
endpoint,
authorizationHeader: "Bearer antigravity-thread-token",
browserToolsAvailable: false,
});
// Running from source, the fallback entrypoint is this process's script.
const entrypoint = h.path.resolve(process.argv[1]!);
yield* Effect.scoped(
Effect.gen(function* () {
const workspace = yield* h.fs.makeTempDirectoryScoped({ prefix: "t3-ag-environment-" });
const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
runtimeMode: "approval-required",
interactionMode: "default",
cwd: workspace,
});
const modelSelection = { instanceId: h.instance.instanceId, model: "gemini-test-low" };
const session = yield* h.instance.orchestrationAdapter.openSession({
threadId,
providerSessionId: ProviderSessionId.make(
"provider-session-antigravity-process-environment",
),
modelSelection,
runtimePolicy,
});
yield* session.ensureThread({ threadId, modelSelection, runtimePolicy });
}),
);

// Gemini Enterprise can strip the native MCP servers, and the documented `acp-mcp-call`
// fallback reads these from the shell.
const agentLaunches = h.launches.filter(
(launch) => launch.command === h.first.executablePath,
);
expect(agentLaunches).toHaveLength(2);
expect(agentLaunches[1]?.environment).toMatchObject({
T3CODE_THREAD_ID: threadId,
T3_ACP_MCP_ENDPOINT: endpoint,
T3_ACP_MCP_AUTHORIZATION: "Bearer antigravity-thread-token",
T3_ACP_MCP_NODE: process.execPath,
T3_ACP_MCP_ENTRYPOINT: entrypoint,
});
// Model refresh and sign-in launches are not part of a thread.
expect(agentLaunches[0]?.environment).toMatchObject({
T3CODE_THREAD_ID: "thread-antigravity-ambient",
T3_ACP_MCP_ENDPOINT: "http://127.0.0.1:9/ambient",
T3_ACP_MCP_AUTHORIZATION: "Bearer ambient-token",
T3_ACP_MCP_NODE: "/ambient/node",
T3_ACP_MCP_ENTRYPOINT: "/ambient/entrypoint.mjs",
});
yield* h.assertClosed;
}),
);

it.effect.skipIf(windowsHost)(
"closes refresh processes and clears account metadata when Google sign-in is required",
() =>
Expand Down
23 changes: 17 additions & 6 deletions apps/server/src/provider/Drivers/AntigravityDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ import {
} from "../acp/AntigravitySessionFiles.ts";
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests";
import { makeAntigravityAdapterV2 } from "../../orchestration-v2/Adapters/AntigravityAdapterV2.ts";
import {
makeAntigravityAdapterV2,
type AntigravityAdapterV2RuntimeInput,
} from "../../orchestration-v2/Adapters/AntigravityAdapterV2.ts";
import { makeAcpNativeLoggerFactory } from "@t3tools/provider-acp/server/nativeLogging";
import { ProviderDriverError } from "../Errors.ts";
import { makeAntigravityProvider } from "../AntigravityProvider.ts";
Expand Down Expand Up @@ -198,7 +201,7 @@ export const AntigravityDriver: ProviderDriver<
);

const makeRuntime = Effect.fn("AntigravityDriver.makeRuntime")(function* (
input: Omit<AntigravityAcpRuntimeInput, "spawn" | "childProcessSpawner">,
input: AntigravityAdapterV2RuntimeInput,
): Effect.fn.Return<
AcpSessionRuntime.AcpSessionRuntime["Service"],
AcpErrors.AcpError | ProviderSetupError,
Expand Down Expand Up @@ -267,16 +270,23 @@ export const AntigravityDriver: ProviderDriver<
),
),
);
// `buildAntigravityAcpSpawnInput` sets `extendEnv: false`, so thread variables only reach the
// agent's shell through `baseEnv`.
const { processEnvironment: threadEnvironment, ...runtimeInput } = input;
const spawnEnvironment =
threadEnvironment === undefined
? processEnvironment
: { ...processEnvironment, ...threadEnvironment };
const runtime = yield* makeAntigravityAcpRuntime({
...input,
...runtimeInput,
runtimeVersion: executable.version,
authMethod: auth.authMethod,
childProcessSpawner: spawner,
spawn: buildAntigravityAcpSpawnInput({
installation: executable,
profile,
cwd: input.cwd,
baseEnv: processEnvironment,
cwd: runtimeInput.cwd,
baseEnv: spawnEnvironment,
auth,
runtimeTempDirectory,
}),
Expand All @@ -291,7 +301,8 @@ export const AntigravityDriver: ProviderDriver<
.start()
.pipe(
Effect.tapError((cause): Effect.Effect<void> =>
input.onAuthorizationUrl === undefined && isAntigravitySignInRequiredError(cause)
runtimeInput.onAuthorizationUrl === undefined &&
isAntigravitySignInRequiredError(cause)
? provider.onAuthRequired
: Effect.void,
),
Expand Down
Loading