Skip to content
Closed
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
2 changes: 2 additions & 0 deletions packages/core/src/services/shellExecutionService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,7 @@ describe('ShellExecutionService environment variables', () => {
const ptyEnv = mockPtySpawn.mock.calls[0][2].env;
expect(ptyEnv).toHaveProperty('MY_TEST_VAR', 'test-value');
expect(ptyEnv).toHaveProperty('GEMINI_CLI', '1');
expect(ptyEnv).toHaveProperty('AGENT', 'gemini');

// Ensure pty process exits
mockPtyProcess.onExit.mock.calls[0][0]({ exitCode: 0, signal: null });
Expand All @@ -1626,6 +1627,7 @@ describe('ShellExecutionService environment variables', () => {
const cpEnv = mockCpSpawn.mock.calls[0][2].env;
expect(cpEnv).toHaveProperty('MY_TEST_VAR', 'test-value');
expect(cpEnv).toHaveProperty('GEMINI_CLI', '1');
expect(cpEnv).toHaveProperty('AGENT', 'gemini');

// Ensure child_process exits
mockChildProcess.emit('exit', 0, null);
Expand Down
17 changes: 16 additions & 1 deletion packages/core/src/services/shellExecutionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ export const GEMINI_CLI_IDENTIFICATION_ENV_VAR = 'GEMINI_CLI';
*/
export const GEMINI_CLI_IDENTIFICATION_ENV_VAR_VALUE = '1';

/**
* A vendor-neutral environment variable that signals to downstream tools
* that they are being executed by an AI agent. The value identifies the
* specific agent (e.g. "gemini").
*/
export const AGENT_IDENTIFICATION_ENV_VAR = 'AGENT';

/**
* The value of {@link AGENT_IDENTIFICATION_ENV_VAR}
*/
export const AGENT_IDENTIFICATION_ENV_VAR_VALUE = 'gemini';

// We want to allow shell outputs that are close to the context window in size.
// 300,000 lines is roughly equivalent to a large context window, ensuring
// we capture significant output from long-running commands.
Expand Down Expand Up @@ -316,6 +328,7 @@ export class ShellExecutionService {
...sanitizeEnvironment(process.env, sanitizationConfig),
[GEMINI_CLI_IDENTIFICATION_ENV_VAR]:
GEMINI_CLI_IDENTIFICATION_ENV_VAR_VALUE,
[AGENT_IDENTIFICATION_ENV_VAR]: AGENT_IDENTIFICATION_ENV_VAR_VALUE,
TERM: 'xterm-256color',
PAGER: 'cat',
GIT_PAGER: 'cat',
Expand Down Expand Up @@ -579,7 +592,9 @@ export class ShellExecutionService {
process.env,
shellExecutionConfig.sanitizationConfig,
),
GEMINI_CLI: '1',
[GEMINI_CLI_IDENTIFICATION_ENV_VAR]:
GEMINI_CLI_IDENTIFICATION_ENV_VAR_VALUE,
[AGENT_IDENTIFICATION_ENV_VAR]: AGENT_IDENTIFICATION_ENV_VAR_VALUE,
TERM: 'xterm-256color',
PAGER: shellExecutionConfig.pager ?? 'cat',
GIT_PAGER: shellExecutionConfig.pager ?? 'cat',
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/tools/mcp-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ import { expandEnvVars } from '../utils/envExpansion.js';
import {
GEMINI_CLI_IDENTIFICATION_ENV_VAR,
GEMINI_CLI_IDENTIFICATION_ENV_VAR_VALUE,
AGENT_IDENTIFICATION_ENV_VAR,
AGENT_IDENTIFICATION_ENV_VAR_VALUE,
} from '../services/shellExecutionService.js';

export const MCP_DEFAULT_TIMEOUT_MSEC = 10 * 60 * 1000; // default to 10 minutes
Expand Down Expand Up @@ -2097,6 +2099,7 @@ export async function createTransport(
const finalEnv: Record<string, string> = {
[GEMINI_CLI_IDENTIFICATION_ENV_VAR]:
GEMINI_CLI_IDENTIFICATION_ENV_VAR_VALUE,
[AGENT_IDENTIFICATION_ENV_VAR]: AGENT_IDENTIFICATION_ENV_VAR_VALUE,
...extensionEnv,
};
for (const [key, value] of Object.entries(sanitizedEnv)) {
Expand Down