refactor(tools): Migrate shell tool name to a centralized constant (#11418)

This commit is contained in:
Abhi
2025-10-17 21:07:26 -04:00
committed by GitHub
parent cedf0235a1
commit 2ef38065c7
8 changed files with 38 additions and 33 deletions
+12 -12
View File
@@ -8,13 +8,13 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import * as os from 'node:os';
import * as path from 'node:path';
import {
ShellTool,
EditTool,
WriteFileTool,
DEFAULT_GEMINI_MODEL,
DEFAULT_GEMINI_MODEL_AUTO,
OutputFormat,
type GeminiCLIExtension,
SHELL_TOOL_NAME,
} from '@google/gemini-cli-core';
import {
loadCliConfig,
@@ -740,7 +740,7 @@ describe('mergeMcpServers', () => {
});
describe('mergeExcludeTools', () => {
const defaultExcludes = [ShellTool.Name, EditTool.Name, WriteFileTool.Name];
const defaultExcludes = [SHELL_TOOL_NAME, EditTool.Name, WriteFileTool.Name];
const originalIsTTY = process.stdin.isTTY;
beforeEach(() => {
@@ -981,7 +981,7 @@ describe('Approval mode tool exclusion logic', () => {
);
const excludedTools = config.getExcludeTools();
expect(excludedTools).toContain(ShellTool.Name);
expect(excludedTools).toContain(SHELL_TOOL_NAME);
expect(excludedTools).toContain(EditTool.Name);
expect(excludedTools).toContain(WriteFileTool.Name);
});
@@ -1008,7 +1008,7 @@ describe('Approval mode tool exclusion logic', () => {
);
const excludedTools = config.getExcludeTools();
expect(excludedTools).toContain(ShellTool.Name);
expect(excludedTools).toContain(SHELL_TOOL_NAME);
expect(excludedTools).toContain(EditTool.Name);
expect(excludedTools).toContain(WriteFileTool.Name);
});
@@ -1035,7 +1035,7 @@ describe('Approval mode tool exclusion logic', () => {
);
const excludedTools = config.getExcludeTools();
expect(excludedTools).toContain(ShellTool.Name);
expect(excludedTools).toContain(SHELL_TOOL_NAME);
expect(excludedTools).not.toContain(EditTool.Name);
expect(excludedTools).not.toContain(WriteFileTool.Name);
});
@@ -1062,7 +1062,7 @@ describe('Approval mode tool exclusion logic', () => {
);
const excludedTools = config.getExcludeTools();
expect(excludedTools).not.toContain(ShellTool.Name);
expect(excludedTools).not.toContain(SHELL_TOOL_NAME);
expect(excludedTools).not.toContain(EditTool.Name);
expect(excludedTools).not.toContain(WriteFileTool.Name);
});
@@ -1082,7 +1082,7 @@ describe('Approval mode tool exclusion logic', () => {
);
const excludedTools = config.getExcludeTools();
expect(excludedTools).not.toContain(ShellTool.Name);
expect(excludedTools).not.toContain(SHELL_TOOL_NAME);
expect(excludedTools).not.toContain(EditTool.Name);
expect(excludedTools).not.toContain(WriteFileTool.Name);
});
@@ -1113,7 +1113,7 @@ describe('Approval mode tool exclusion logic', () => {
);
const excludedTools = config.getExcludeTools();
expect(excludedTools).not.toContain(ShellTool.Name);
expect(excludedTools).not.toContain(SHELL_TOOL_NAME);
expect(excludedTools).not.toContain(EditTool.Name);
expect(excludedTools).not.toContain(WriteFileTool.Name);
}
@@ -1142,7 +1142,7 @@ describe('Approval mode tool exclusion logic', () => {
const excludedTools = config.getExcludeTools();
expect(excludedTools).toContain('custom_tool'); // From settings
expect(excludedTools).toContain(ShellTool.Name); // From approval mode
expect(excludedTools).toContain(SHELL_TOOL_NAME); // From approval mode
expect(excludedTools).not.toContain(EditTool.Name); // Should be allowed in auto_edit
expect(excludedTools).not.toContain(WriteFileTool.Name); // Should be allowed in auto_edit
});
@@ -2087,7 +2087,7 @@ describe('loadCliConfig tool exclusions', () => {
'test-session',
argv,
);
expect(config.getExcludeTools()).not.toContain(ShellTool.Name);
expect(config.getExcludeTools()).not.toContain(SHELL_TOOL_NAME);
});
it('should not exclude shell tool in non-interactive mode when --allowed-tools="run_shell_command" is set', async () => {
@@ -2108,7 +2108,7 @@ describe('loadCliConfig tool exclusions', () => {
'test-session',
argv,
);
expect(config.getExcludeTools()).not.toContain(ShellTool.Name);
expect(config.getExcludeTools()).not.toContain(SHELL_TOOL_NAME);
});
it('should not exclude shell tool in non-interactive mode when --allowed-tools="ShellTool(wc)" is set', async () => {
@@ -2129,7 +2129,7 @@ describe('loadCliConfig tool exclusions', () => {
'test-session',
argv,
);
expect(config.getExcludeTools()).not.toContain(ShellTool.Name);
expect(config.getExcludeTools()).not.toContain(SHELL_TOOL_NAME);
});
});
+4 -4
View File
@@ -29,10 +29,10 @@ import {
DEFAULT_GEMINI_EMBEDDING_MODEL,
DEFAULT_MEMORY_FILE_FILTERING_OPTIONS,
FileDiscoveryService,
ShellTool,
EditTool,
WRITE_FILE_TOOL_NAME,
SHELL_TOOL_NAMES,
SHELL_TOOL_NAME,
resolveTelemetrySettings,
FatalConfigError,
getPty,
@@ -352,7 +352,7 @@ function createToolExclusionFilter(
allowedToolsSet: Set<string>,
) {
return (tool: string): boolean => {
if (tool === ShellTool.Name) {
if (tool === SHELL_TOOL_NAME) {
// If any of the allowed tools is ShellTool (even with subcommands), don't exclude it.
return !allowedTools.some((allowed) =>
SHELL_TOOL_NAMES.some((shellName) => allowed.startsWith(shellName)),
@@ -505,11 +505,11 @@ export async function loadCliConfig(
const extraExcludes: string[] = [];
if (!interactive && !argv.experimentalAcp) {
const defaultExcludes = [
ShellTool.Name,
SHELL_TOOL_NAME,
EditTool.Name,
WRITE_FILE_TOOL_NAME,
];
const autoEditExcludes = [ShellTool.Name];
const autoEditExcludes = [SHELL_TOOL_NAME];
const toolExclusionFilter = createToolExclusionFilter(
allowedTools,
+2 -2
View File
@@ -19,7 +19,7 @@ import {
// Write tools
EditTool,
MemoryTool,
ShellTool,
SHELL_TOOL_NAME,
WRITE_FILE_TOOL_NAME,
WEB_FETCH_TOOL_NAME,
WebSearchTool,
@@ -47,7 +47,7 @@ const READ_ONLY_TOOLS = new Set([
const WRITE_TOOLS = new Set([
EditTool.Name,
MemoryTool.Name,
ShellTool.Name,
SHELL_TOOL_NAME,
WRITE_FILE_TOOL_NAME,
WEB_FETCH_TOOL_NAME,
]);