diff --git a/doc/plugins/PLUGIN_ENVIRONMENT_TASKS.md b/doc/plugins/PLUGIN_ENVIRONMENT_TASKS.md index 79907dd0aa8..69d7cdd7879 100644 --- a/doc/plugins/PLUGIN_ENVIRONMENT_TASKS.md +++ b/doc/plugins/PLUGIN_ENVIRONMENT_TASKS.md @@ -77,7 +77,7 @@ The `credential` field has one of these types: | --- | --- | --- | | `codex-auth-json` | `authJson`: the selected Codex `auth.json` | `codex` | | `claude-env` | `environment`: exactly one of `CLAUDE_CODE_OAUTH_TOKEN` or `ANTHROPIC_API_KEY` | `claude` | -| `provider-env` | `provider` and `environment`: one complete variable set for that provider | `grok`, `copilot` or `opencode` | +| `provider-env` | `provider` and `environment`: one complete variable set for that provider | `grok`, `copilot`, `opencode` or `antigravity` | A `provider-env` credential contains exactly one of these variable sets and no other variable: @@ -87,6 +87,7 @@ other variable: | `grok` | `XAI_API_KEY` | | `copilot` | `COPILOT_GITHUB_TOKEN` | | `opencode` | `OPENROUTER_API_KEY`, or `PAPERCLIP_AI_PROVIDER_URL` with `PAPERCLIP_AI_PROVIDER_KEY` | +| `antigravity` | `GEMINI_API_KEY` | `ENVIRONMENT_TASK_PROVIDER_CREDENTIAL_KEY_SETS` exports this list. A server test checks every set against the names that the Runner forwards to each provider. Every value @@ -94,17 +95,22 @@ is non-empty and contains no NUL byte. The `provider` always matches the Runner harness of the task. Set the variables in the environment of the Runner process. The Runner gives each variable only to its provider. -For `copilot`, also set `PAPERCLIP_ACPX_CREDENTIAL_BINDING` in the Runner -environment. Its value is this JSON object, with the normalized session ID of -the task's PRP identity: +For `copilot` and `antigravity`, also set `PAPERCLIP_ACPX_CREDENTIAL_BINDING` +in the Runner environment. Its value is this JSON object, with the provider as +`agent`, its variable names as `names`, and the normalized session ID of the +task's PRP identity: ```json {"schema":"paperclip.acpx_credential_binding.v1","agent":"copilot","sessionId":"","names":["COPILOT_GITHUB_TOKEN"]} ``` -The Runner refuses a Copilot token without a matching binding. +The Runner refuses a Copilot token or a Gemini API key without a matching +binding. For `antigravity`, the Runner also removes every other `GOOGLE_*` and +`GEMINI_*` variable before it starts the provider, so a configured variable +cannot redirect the key. Core does not send a Grok subscription login. A Grok agent must use an xAI API -key in a plugin environment. +key in a plugin environment. Core does not send a Google sign-in yet. A Google +Antigravity agent must use a Gemini API key in a plugin environment. ## Configured environment diff --git a/doc/plugins/PLUGIN_RUNNER_EXECUTION.md b/doc/plugins/PLUGIN_RUNNER_EXECUTION.md index 361ac89ffd7..36ad51a7ad4 100644 --- a/doc/plugins/PLUGIN_RUNNER_EXECUTION.md +++ b/doc/plugins/PLUGIN_RUNNER_EXECUTION.md @@ -103,11 +103,11 @@ reconciliation for the same task. ## Credentials and tools Core can transfer a selected Codex account, a direct Claude credential, or the -API credential of a Grok, Copilot or OpenCode connection. See +API credential of a Grok, Copilot, OpenCode or Google Antigravity connection. See [typed credentials](PLUGIN_ENVIRONMENT_TASKS.md#typed-credentials). Other managed routes fail closed until they have a typed credential contract. -A Grok subscription login, Claude provider routing, and an OpenCode gateway -without a key also fail closed. +A Grok subscription login, a Google sign-in, Claude provider routing, and an +OpenCode gateway without a key also fail closed. Do not put credentials in task metadata, journals, logs, or errors. Assigned MCP tools run through the Core gateway over PRP. diff --git a/packages/plugins/sdk/src/environment-tasks.ts b/packages/plugins/sdk/src/environment-tasks.ts index ff2beb2c3c6..5682dee1658 100644 --- a/packages/plugins/sdk/src/environment-tasks.ts +++ b/packages/plugins/sdk/src/environment-tasks.ts @@ -60,11 +60,13 @@ export const ENVIRONMENT_TASK_PROVIDER_CREDENTIAL_KEY_SETS = { grok: [["XAI_API_KEY"]], copilot: [["COPILOT_GITHUB_TOKEN"]], opencode: [["OPENROUTER_API_KEY"], ["PAPERCLIP_AI_PROVIDER_URL", "PAPERCLIP_AI_PROVIDER_KEY"]], + antigravity: [["GEMINI_API_KEY"]], } as const satisfies Record; export type PluginEnvironmentTaskCredentialProvider = keyof typeof ENVIRONMENT_TASK_PROVIDER_CREDENTIAL_KEY_SETS; +const providerNames = Object.keys(ENVIRONMENT_TASK_PROVIDER_CREDENTIAL_KEY_SETS) as [PluginEnvironmentTaskCredentialProvider, ...PluginEnvironmentTaskCredentialProvider[]]; const providerCredential = z.object({ type: z.literal("provider-env"), - provider: z.enum(["grok", "copilot", "opencode"]), + provider: z.enum(providerNames), environment: z.record(z.string(), credentialValue), }).strict().superRefine((credential, ctx) => { const names = Object.keys(credential.environment).sort(); diff --git a/packages/plugins/sdk/tests/environment-task-release-resume.test.ts b/packages/plugins/sdk/tests/environment-task-release-resume.test.ts index 50bcc60b9f0..a70ca44cf98 100644 --- a/packages/plugins/sdk/tests/environment-task-release-resume.test.ts +++ b/packages/plugins/sdk/tests/environment-task-release-resume.test.ts @@ -55,6 +55,17 @@ const credentials: [string, unknown, boolean][] = [ ["an unsupported provider", { type: "provider-env", provider: "gemini", environment: { GEMINI_API_KEY: "fixture-gemini" } }, false], ["a provider credential without a provider", { type: "provider-env", environment: { XAI_API_KEY: "fixture-xai" } }, false], ["an extra provider credential field", { type: "provider-env", provider: "grok", environment: { XAI_API_KEY: "fixture-xai" }, home: "/home/agent" }, false], + ["a Gemini API key for Antigravity", { type: "provider-env", provider: "antigravity", environment: { GEMINI_API_KEY: "fixture-gemini" } }, true], + ["an Antigravity sign-in document", { type: "provider-env", provider: "antigravity", + environment: { PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET: "{\"refresh_token\":\"fixture\"}" } }, false], + ["a Gemini API key mixed with a sign-in document", { type: "provider-env", provider: "antigravity", + environment: { GEMINI_API_KEY: "fixture-gemini", PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET: "{\"refresh_token\":\"fixture\"}" } }, false], + ["a Google API key for Antigravity", { type: "provider-env", provider: "antigravity", environment: { GOOGLE_API_KEY: "fixture-google" } }, false], + ["a Gemini API key with Google routing", { type: "provider-env", provider: "antigravity", + environment: { GEMINI_API_KEY: "fixture-gemini", GOOGLE_GEMINI_BASE_URL: "https://router.example.test" } }, false], + ["no Antigravity variable", { type: "provider-env", provider: "antigravity", environment: {} }, false], + ["an empty Gemini API key", { type: "provider-env", provider: "antigravity", environment: { GEMINI_API_KEY: "" } }, false], + ["a Gemini API key for another provider", { type: "provider-env", provider: "copilot", environment: { GEMINI_API_KEY: "fixture-gemini" } }, false], ]; async function invoke(operation: unknown, handler: (params: PluginEnvironmentTaskParams) => Promise) { diff --git a/server/src/__tests__/environment-task-runtime.test.ts b/server/src/__tests__/environment-task-runtime.test.ts index cabd46e3808..b627aac50d0 100644 --- a/server/src/__tests__/environment-task-runtime.test.ts +++ b/server/src/__tests__/environment-task-runtime.test.ts @@ -328,11 +328,12 @@ describe("plugin-provided Runner execution", () => { await expect(executeEnvironmentTask(database(value).db, worker() as never, { companyId: "company", leaseId, operation: { ...operation, credential: { type: "claude-env", environment: { ANTHROPIC_API_KEY: "never-leak" } } } })).rejects.toThrow("validation unavailable"); }); - it.each(["grok", "copilot", "opencode"] as const)("dispatches a %s environment credential only for the matching harness", async harness => { + it.each(["grok", "copilot", "opencode", "antigravity"] as const)("dispatches a %s environment credential only for the matching harness", async harness => { const credentials = { grok: { type: "provider-env" as const, provider: "grok" as const, environment: { XAI_API_KEY: "never-leak" } }, copilot: { type: "provider-env" as const, provider: "copilot" as const, environment: { COPILOT_GITHUB_TOKEN: "never-leak" } }, opencode: { type: "provider-env" as const, provider: "opencode" as const, environment: { OPENROUTER_API_KEY: "never-leak" } }, + antigravity: { type: "provider-env" as const, provider: "antigravity" as const, environment: { GEMINI_API_KEY: "never-leak" } }, }; const operation = { ...submit, runner: { ...submit.runner, harness }, accountIdentity: "account", credential: credentials[harness] }; const validated = () => { @@ -341,8 +342,15 @@ describe("plugin-provided Runner execution", () => { return value; }; const accepted = worker(); - await expect(executeEnvironmentTask(database(validated()).db, accepted as never, { companyId: "company", leaseId, operation })).resolves.toMatchObject({ kind: "accepted" }); + const store = database(validated()); + await expect(executeEnvironmentTask(store.db, accepted as never, { companyId: "company", leaseId, operation })).resolves.toMatchObject({ kind: "accepted" }); expect(accepted.call).toHaveBeenCalledOnce(); + expect(JSON.stringify(store.sets.map(set => new PgDialect().sqlToQuery(set.metadata as never).params))).not.toContain("never-leak"); + const failing = worker(); + failing.call.mockRejectedValue(Object.assign(new Error("submit failed for never-leak"), { data: operation })); + const error = await executeEnvironmentTask(database(validated()).db, failing as never, { companyId: "company", leaseId, operation }).catch(caught => caught); + expect(JSON.stringify({ ...error, message: error.message })).not.toContain("never-leak"); + expect(error.cause).toBeUndefined(); const denied = worker(); await expect(executeEnvironmentTask(database(validated()).db, denied as never, { companyId: "company", leaseId, operation: { ...operation, credential: credentials[harness === "grok" ? "copilot" : "grok"] } })).rejects.toThrow("validation unavailable"); diff --git a/server/src/__tests__/plugin-runner-credential-names.test.ts b/server/src/__tests__/plugin-runner-credential-names.test.ts index 43b0433cbfb..c295f1eae9f 100644 --- a/server/src/__tests__/plugin-runner-credential-names.test.ts +++ b/server/src/__tests__/plugin-runner-credential-names.test.ts @@ -22,6 +22,8 @@ describe("plugin Runner provider credential names", () => { it("reads the Runner's Rust allowlists", () => { expect(rustAcpxCredentialNames("copilot")).toContain("COPILOT_GITHUB_TOKEN"); expect(rustCandidateAgents).toContain("copilot"); + expect(rustAcpxCredentialNames("antigravity")).toContain("GEMINI_API_KEY"); + expect(rustCandidateAgents).toContain("antigravity"); expect(rustOpenCodeNames).toContain("OPENROUTER_API_KEY"); }); @@ -48,4 +50,20 @@ describe("plugin Runner provider credential names", () => { expect(spawned[name], `${name} reaches the ${agent} process`).toBe(environment[name]); } }); + + it("still strips Google and Gemini routing variables from the Antigravity process", () => { + const routing = { GOOGLE_API_KEY: "fixture-google", GOOGLE_APPLICATION_CREDENTIALS: "/controller/private/adc.json", + GOOGLE_CLOUD_PROJECT: "fixture-project", GOOGLE_GEMINI_BASE_URL: "https://router.example.test", GEMINI_HOME: "/controller/private/gemini" }; + const environment = { GEMINI_API_KEY: "fixture-gemini", ...routing, PAPERCLIP_CONFIGURED_ENV_KEYS: JSON.stringify(Object.keys(routing)) }; + const binding = createAcpxCredentialBinding(environment, "antigravity", "session"); + const host = createAcpxSidecarHostEnvironment({ ...environment, [ACPX_CREDENTIAL_BINDING_ENV]: binding }, "antigravity", "session"); + const spawned = createSanitizedAcpxSpawnInput(host, "antigravity").env; + expect(JSON.parse(binding!).names).toEqual(["GEMINI_API_KEY"]); + expect(host.GEMINI_API_KEY).toBe("fixture-gemini"); + expect(spawned.GEMINI_API_KEY).toBe("fixture-gemini"); + for (const name of Object.keys(routing)) { + expect(host[name], `${name} is removed at sidecar admission`).toBeUndefined(); + expect(spawned[name], `${name} never reaches the Antigravity process`).toBeUndefined(); + } + }); }); diff --git a/server/src/services/native-runtime/plugin-runner-credentials.test.ts b/server/src/services/native-runtime/plugin-runner-credentials.test.ts index d2e1a1ed8a1..19c68e36b61 100644 --- a/server/src/services/native-runtime/plugin-runner-credentials.test.ts +++ b/server/src/services/native-runtime/plugin-runner-credentials.test.ts @@ -40,6 +40,36 @@ describe("plugin Runner selected credentials", () => { }); }); +describe("plugin Runner Google Antigravity credentials", () => { + const signIn = "{\"refresh_token\":\"fixture-refresh\"}"; + it("transfers only the selected Gemini API key", async () => { + const transfer = await preparePluginRunnerCredentials({ provider: "antigravity", identity: "revision", accountIdentity: "account", + environment: { GEMINI_API_KEY: "fixture-gemini", GOOGLE_API_KEY: "fixture-google", GOOGLE_APPLICATION_CREDENTIALS: "/controller/private/adc.json", + GOOGLE_GEMINI_BASE_URL: "https://router.example.test", GEMINI_HOME: "/controller/private/gemini", XAI_API_KEY: "fixture-xai", + HOME: "/controller/private", OTHER_SECRET: "fixture-unrelated" } }); + expect(transfer).toEqual({ accountIdentity: "account", credential: { type: "provider-env", provider: "antigravity", environment: { GEMINI_API_KEY: "fixture-gemini" } } }); + expect(transfer.needsWriteback).toBeUndefined(); + expect(transfer.onCredentials).toBeUndefined(); + }); + it.each([ + ["a Google sign-in", { PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET: signIn }], + ["a Google sign-in beside a Gemini API key", { GEMINI_API_KEY: "fixture-gemini", PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET: signIn }], + ["no key", {}], + ["an empty key", { GEMINI_API_KEY: "" }], + ["a blank key", { GEMINI_API_KEY: " " }], + ["only a Google API key", { GOOGLE_API_KEY: "fixture-google" }], + ] as const)("refuses %s because only a Gemini API key can be transferred", async (_name, environment) => { + const result = preparePluginRunnerCredentials({ provider: "antigravity", identity: "revision", environment }); + await expect(result).rejects.toThrow("Google Antigravity only with a Gemini API key"); + await result.catch((error: Error) => expect(error.message).not.toContain("fixture")); + }); + it("fails closed for an invalid Gemini API key without echoing it", async () => { + const result = preparePluginRunnerCredentials({ provider: "antigravity", identity: "revision", environment: { GEMINI_API_KEY: "fixture\0gemini" } }); + await expect(result).rejects.toThrow("Plugin Runner selected credential unavailable"); + await result.catch((error: Error) => expect(error.message).not.toContain("fixture")); + }); +}); + describe("plugin Runner provider environment credentials", () => { const blanks = { XAI_API_KEY: "", COPILOT_GITHUB_TOKEN: "", OPENROUTER_API_KEY: "", PAPERCLIP_AI_PROVIDER_URL: "", PAPERCLIP_AI_PROVIDER_KEY: "", ANTHROPIC_API_KEY: "", HOME: "/controller/private", GROK_HOME: "/controller/private/provider", OTHER_SECRET: "fixture-unrelated" }; diff --git a/server/src/services/native-runtime/plugin-runner-credentials.ts b/server/src/services/native-runtime/plugin-runner-credentials.ts index b4060632cdb..5c8b558b682 100644 --- a/server/src/services/native-runtime/plugin-runner-credentials.ts +++ b/server/src/services/native-runtime/plugin-runner-credentials.ts @@ -7,6 +7,8 @@ import { } from "@paperclipai/plugin-sdk"; import { readLocalAiCredentialFile } from "../local-ai-credential-file.js"; +const ANTIGRAVITY_SIGN_IN_ENV = "PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET"; + interface PreparedPluginRunnerCredentials { githubBroker?: { url: string; token: string }; accountIdentity?: string; @@ -51,12 +53,15 @@ export async function preparePluginRunnerCredentials(input: { .flatMap(key => input.environment[key] ? [[key, input.environment[key]]] : [])); return { ...github, accountIdentity, credential: environmentTaskCredentialSchema.parse({ type: "claude-env", environment }) }; } - if (input.provider === "grok" || input.provider === "copilot" || input.provider === "opencode") { + if (input.provider === "grok" || input.provider === "copilot" || input.provider === "opencode" || input.provider === "antigravity") { const provider: PluginEnvironmentTaskCredentialProvider = input.provider; if (provider === "grok") { if (input.environment.XAI_BASE_URL) throw new Error("Plugin Runner does not support the selected provider routing"); if (!input.environment.XAI_API_KEY) throw new Error("Plugin Runner supports Grok only with an xAI API key. Grok subscription login is not supported."); } + if (provider === "antigravity" && (input.environment[ANTIGRAVITY_SIGN_IN_ENV] || !input.environment.GEMINI_API_KEY?.trim())) { + throw new Error("Plugin Runner supports Google Antigravity only with a Gemini API key. Google sign-in is not supported."); + } const names = new Set(ENVIRONMENT_TASK_PROVIDER_CREDENTIAL_KEY_SETS[provider].flat()); const environment = Object.fromEntries([...names] .flatMap(key => input.environment[key] ? [[key, input.environment[key]]] : [])); diff --git a/tests/runner-e2e/source-sdk-public-inputs.json b/tests/runner-e2e/source-sdk-public-inputs.json index d51364e61b7..b804278051b 100644 --- a/tests/runner-e2e/source-sdk-public-inputs.json +++ b/tests/runner-e2e/source-sdk-public-inputs.json @@ -13,7 +13,7 @@ "packages/plugins/sdk/src/environment-stop-error.ts": "b0e03f8aa2b2170ba095da5c7138050fced3f3cb", "packages/plugins/sdk/src/environment-sync-error.ts": "7d6a51a95da49a7da4525aebbab6382dc5c44ae8", "packages/plugins/sdk/src/environment-task-error.ts": "98aae8a06743b38884b68cb9a3ec44c57b34c0e4", - "packages/plugins/sdk/src/environment-tasks.ts": "ff2beb2c3c6af2e6b84bad8701367d8aee3c755d", + "packages/plugins/sdk/src/environment-tasks.ts": "5682dee1658ad44f61f8480ef22a3a8e80eedf8f", "packages/plugins/sdk/src/host-client-factory.ts": "e0301c390ea13f2340b669383f07af2455e48c8a", "packages/plugins/sdk/src/idle-drain.test.ts": "cc59f7881e7d46c89395a1d93d74f6c6b9b0a64a", "packages/plugins/sdk/src/idle-drain.ts": "ae6e4c6be4657a3d541396922b3bc551b8db557f",