diff --git a/src/agents/cli-runner.spawn.test.ts b/src/agents/cli-runner.spawn.test.ts index 04e7ccab1cd2..4045196f3b79 100644 --- a/src/agents/cli-runner.spawn.test.ts +++ b/src/agents/cli-runner.spawn.test.ts @@ -3623,11 +3623,13 @@ ${JSON.stringify({ it("formats CLI auth env diagnostics as key names without secret values", () => { vi.stubEnv("ANTHROPIC_API_KEY", "sk-ant-host"); vi.stubEnv("ANTHROPIC_API_TOKEN", "token-host"); + vi.stubEnv("GEMINI_CLI_SYSTEM_SETTINGS_PATH", "/tmp/host-gemini-settings.json"); vi.stubEnv("OPENAI_API_KEY", "sk-openai-host"); const log = buildCliEnvAuthLog({ ANTHROPIC_API_TOKEN: "token-child", CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST: "1", + GEMINI_CLI_HOME: "/tmp/child-gemini-home", OPENAI_API_KEY: "sk-openai-child", }); @@ -3638,8 +3640,12 @@ ${JSON.stringify({ expect(log).toMatch(/child=.*CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST/); expect(log).toMatch(/child=.*OPENAI_API_KEY/); expect(log).toMatch(/cleared=.*ANTHROPIC_API_KEY/); + expect(log).toMatch(/runtimeHost=.*GEMINI_CLI_SYSTEM_SETTINGS_PATH/); + expect(log).toMatch(/runtimeChild=.*GEMINI_CLI_HOME/); + expect(log).toMatch(/runtimeCleared=.*GEMINI_CLI_SYSTEM_SETTINGS_PATH/); expect(log).not.toContain("sk-ant-host"); expect(log).not.toContain("token-child"); + expect(log).not.toContain("/tmp/child-gemini-home"); expect(log).not.toContain("sk-openai-child"); }); diff --git a/src/agents/cli-runner/execute.ts b/src/agents/cli-runner/execute.ts index 297d37a1378e..6e1749b37188 100644 --- a/src/agents/cli-runner/execute.ts +++ b/src/agents/cli-runner/execute.ts @@ -312,6 +312,8 @@ const CLI_ENV_AUTH_LOG_KEYS = [ "OPENROUTER_API_KEY", ] as const; +const CLI_ENV_RUNTIME_LOG_KEYS = ["GEMINI_CLI_HOME", "GEMINI_CLI_SYSTEM_SETTINGS_PATH"] as const; + const CLI_BACKEND_PRESERVE_ENV = "OPENCLAW_LIVE_CLI_BACKEND_PRESERVE_ENV"; function parseCliBackendPreserveEnv(raw: string | undefined): Set { @@ -346,6 +348,13 @@ function listPresentCliAuthEnvKeys(env: Record): str }); } +function listPresentCliRuntimeEnvKeys(env: Record): string[] { + return CLI_ENV_RUNTIME_LOG_KEYS.filter((key) => { + const value = env[key]; + return typeof value === "string" && value.length > 0; + }); +} + function formatCliEnvKeyList(keys: readonly string[]): string { return keys.length > 0 ? keys.join(",") : "none"; } @@ -405,10 +414,17 @@ export function buildCliEnvAuthLog(childEnv: Record): string { const childKeys = listPresentCliAuthEnvKeys(childEnv); const childKeySet = new Set(childKeys); const clearedKeys = hostKeys.filter((key) => !childKeySet.has(key)); + const runtimeHostKeys = listPresentCliRuntimeEnvKeys(process.env); + const runtimeChildKeys = listPresentCliRuntimeEnvKeys(childEnv); + const runtimeChildKeySet = new Set(runtimeChildKeys); + const runtimeClearedKeys = runtimeHostKeys.filter((key) => !runtimeChildKeySet.has(key)); return [ `host=${formatCliEnvKeyList(hostKeys)}`, `child=${formatCliEnvKeyList(childKeys)}`, `cleared=${formatCliEnvKeyList(clearedKeys)}`, + `runtimeHost=${formatCliEnvKeyList(runtimeHostKeys)}`, + `runtimeChild=${formatCliEnvKeyList(runtimeChildKeys)}`, + `runtimeCleared=${formatCliEnvKeyList(runtimeClearedKeys)}`, ].join(" "); }