From 3dd6e431df057af47b96990d0c9c6477ccfbe452 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Thu, 24 Jul 2025 10:13:00 -0700 Subject: feat: add GEMINI_CLI environment variable to spawned shell commands (#4791) --- packages/core/src/tools/shell.test.ts | 20 ++++++++++++++++++++ packages/core/src/tools/shell.ts | 8 ++++++++ 2 files changed, 28 insertions(+) (limited to 'packages/core/src') diff --git a/packages/core/src/tools/shell.test.ts b/packages/core/src/tools/shell.test.ts index f358f972..0dff776f 100644 --- a/packages/core/src/tools/shell.test.ts +++ b/packages/core/src/tools/shell.test.ts @@ -514,4 +514,24 @@ describe('ShellTool Bug Reproduction', () => { undefined, ); }); + + it('should pass GEMINI_CLI environment variable to executed commands', async () => { + config = { + getCoreTools: () => undefined, + getExcludeTools: () => undefined, + getDebugMode: () => false, + getGeminiClient: () => ({}) as GeminiClient, + getTargetDir: () => '.', + getSummarizeToolOutputConfig: () => ({}), + } as unknown as Config; + shellTool = new ShellTool(config); + + const abortSignal = new AbortController().signal; + const result = await shellTool.execute( + { command: 'echo "$GEMINI_CLI"' }, + abortSignal, + ); + + expect(result.returnDisplay).toBe('1\n'); + }); }); diff --git a/packages/core/src/tools/shell.ts b/packages/core/src/tools/shell.ts index af514546..44df5ece 100644 --- a/packages/core/src/tools/shell.ts +++ b/packages/core/src/tools/shell.ts @@ -322,11 +322,19 @@ Process Group PGID: Process group started or \`(none)\``, stdio: ['ignore', 'pipe', 'pipe'], // detached: true, // ensure subprocess starts its own process group (esp. in Linux) cwd: path.resolve(this.config.getTargetDir(), params.directory || ''), + env: { + ...process.env, + GEMINI_CLI: '1', + }, }) : spawn('bash', ['-c', command], { stdio: ['ignore', 'pipe', 'pipe'], detached: true, // ensure subprocess starts its own process group (esp. in Linux) cwd: path.resolve(this.config.getTargetDir(), params.directory || ''), + env: { + ...process.env, + GEMINI_CLI: '1', + }, }); let exited = false; -- cgit v1.2.3