mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-29 22:44:45 -07:00
refactor(tools): Move all tool names into tool-names.ts (#11493)
This commit is contained in:
@@ -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 {
|
||||
EditTool,
|
||||
WriteFileTool,
|
||||
DEFAULT_GEMINI_MODEL,
|
||||
DEFAULT_GEMINI_MODEL_AUTO,
|
||||
OutputFormat,
|
||||
type GeminiCLIExtension,
|
||||
SHELL_TOOL_NAME,
|
||||
WRITE_FILE_TOOL_NAME,
|
||||
EDIT_TOOL_NAME,
|
||||
} from '@google/gemini-cli-core';
|
||||
import { loadCliConfig, parseArguments, type CliArgs } from './config.js';
|
||||
import type { Settings } from './settings.js';
|
||||
@@ -739,7 +739,11 @@ describe('mergeMcpServers', () => {
|
||||
});
|
||||
|
||||
describe('mergeExcludeTools', () => {
|
||||
const defaultExcludes = [SHELL_TOOL_NAME, EditTool.Name, WriteFileTool.Name];
|
||||
const defaultExcludes = [
|
||||
SHELL_TOOL_NAME,
|
||||
EDIT_TOOL_NAME,
|
||||
WRITE_FILE_TOOL_NAME,
|
||||
];
|
||||
const originalIsTTY = process.stdin.isTTY;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -981,8 +985,8 @@ describe('Approval mode tool exclusion logic', () => {
|
||||
|
||||
const excludedTools = config.getExcludeTools();
|
||||
expect(excludedTools).toContain(SHELL_TOOL_NAME);
|
||||
expect(excludedTools).toContain(EditTool.Name);
|
||||
expect(excludedTools).toContain(WriteFileTool.Name);
|
||||
expect(excludedTools).toContain(EDIT_TOOL_NAME);
|
||||
expect(excludedTools).toContain(WRITE_FILE_TOOL_NAME);
|
||||
});
|
||||
|
||||
it('should exclude all interactive tools in non-interactive mode with explicit default approval mode', async () => {
|
||||
@@ -1008,8 +1012,8 @@ describe('Approval mode tool exclusion logic', () => {
|
||||
|
||||
const excludedTools = config.getExcludeTools();
|
||||
expect(excludedTools).toContain(SHELL_TOOL_NAME);
|
||||
expect(excludedTools).toContain(EditTool.Name);
|
||||
expect(excludedTools).toContain(WriteFileTool.Name);
|
||||
expect(excludedTools).toContain(EDIT_TOOL_NAME);
|
||||
expect(excludedTools).toContain(WRITE_FILE_TOOL_NAME);
|
||||
});
|
||||
|
||||
it('should exclude only shell tools in non-interactive mode with auto_edit approval mode', async () => {
|
||||
@@ -1035,8 +1039,8 @@ describe('Approval mode tool exclusion logic', () => {
|
||||
|
||||
const excludedTools = config.getExcludeTools();
|
||||
expect(excludedTools).toContain(SHELL_TOOL_NAME);
|
||||
expect(excludedTools).not.toContain(EditTool.Name);
|
||||
expect(excludedTools).not.toContain(WriteFileTool.Name);
|
||||
expect(excludedTools).not.toContain(EDIT_TOOL_NAME);
|
||||
expect(excludedTools).not.toContain(WRITE_FILE_TOOL_NAME);
|
||||
});
|
||||
|
||||
it('should exclude no interactive tools in non-interactive mode with yolo approval mode', async () => {
|
||||
@@ -1062,8 +1066,8 @@ describe('Approval mode tool exclusion logic', () => {
|
||||
|
||||
const excludedTools = config.getExcludeTools();
|
||||
expect(excludedTools).not.toContain(SHELL_TOOL_NAME);
|
||||
expect(excludedTools).not.toContain(EditTool.Name);
|
||||
expect(excludedTools).not.toContain(WriteFileTool.Name);
|
||||
expect(excludedTools).not.toContain(EDIT_TOOL_NAME);
|
||||
expect(excludedTools).not.toContain(WRITE_FILE_TOOL_NAME);
|
||||
});
|
||||
|
||||
it('should exclude no interactive tools in non-interactive mode with legacy yolo flag', async () => {
|
||||
@@ -1082,8 +1086,8 @@ describe('Approval mode tool exclusion logic', () => {
|
||||
|
||||
const excludedTools = config.getExcludeTools();
|
||||
expect(excludedTools).not.toContain(SHELL_TOOL_NAME);
|
||||
expect(excludedTools).not.toContain(EditTool.Name);
|
||||
expect(excludedTools).not.toContain(WriteFileTool.Name);
|
||||
expect(excludedTools).not.toContain(EDIT_TOOL_NAME);
|
||||
expect(excludedTools).not.toContain(WRITE_FILE_TOOL_NAME);
|
||||
});
|
||||
|
||||
it('should not exclude interactive tools in interactive mode regardless of approval mode', async () => {
|
||||
@@ -1113,8 +1117,8 @@ describe('Approval mode tool exclusion logic', () => {
|
||||
|
||||
const excludedTools = config.getExcludeTools();
|
||||
expect(excludedTools).not.toContain(SHELL_TOOL_NAME);
|
||||
expect(excludedTools).not.toContain(EditTool.Name);
|
||||
expect(excludedTools).not.toContain(WriteFileTool.Name);
|
||||
expect(excludedTools).not.toContain(EDIT_TOOL_NAME);
|
||||
expect(excludedTools).not.toContain(WRITE_FILE_TOOL_NAME);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1142,8 +1146,8 @@ describe('Approval mode tool exclusion logic', () => {
|
||||
const excludedTools = config.getExcludeTools();
|
||||
expect(excludedTools).toContain('custom_tool'); // From settings
|
||||
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
|
||||
expect(excludedTools).not.toContain(EDIT_TOOL_NAME); // Should be allowed in auto_edit
|
||||
expect(excludedTools).not.toContain(WRITE_FILE_TOOL_NAME); // Should be allowed in auto_edit
|
||||
});
|
||||
|
||||
it('should throw an error for invalid approval mode values in loadCliConfig', async () => {
|
||||
|
||||
@@ -29,13 +29,13 @@ import {
|
||||
DEFAULT_GEMINI_EMBEDDING_MODEL,
|
||||
DEFAULT_MEMORY_FILE_FILTERING_OPTIONS,
|
||||
FileDiscoveryService,
|
||||
EditTool,
|
||||
WRITE_FILE_TOOL_NAME,
|
||||
SHELL_TOOL_NAMES,
|
||||
SHELL_TOOL_NAME,
|
||||
resolveTelemetrySettings,
|
||||
FatalConfigError,
|
||||
getPty,
|
||||
EDIT_TOOL_NAME,
|
||||
} from '@google/gemini-cli-core';
|
||||
import type { Settings } from './settings.js';
|
||||
|
||||
@@ -506,7 +506,7 @@ export async function loadCliConfig(
|
||||
if (!interactive && !argv.experimentalAcp) {
|
||||
const defaultExcludes = [
|
||||
SHELL_TOOL_NAME,
|
||||
EditTool.Name,
|
||||
EDIT_TOOL_NAME,
|
||||
WRITE_FILE_TOOL_NAME,
|
||||
];
|
||||
const autoEditExcludes = [SHELL_TOOL_NAME];
|
||||
|
||||
@@ -10,30 +10,30 @@ import {
|
||||
type PolicyRule,
|
||||
ApprovalMode,
|
||||
// Read-only tools
|
||||
GlobTool,
|
||||
LSTool,
|
||||
GREP_TOOL_NAME,
|
||||
LS_TOOL_NAME,
|
||||
READ_MANY_FILES_TOOL_NAME,
|
||||
READ_FILE_TOOL_NAME,
|
||||
// Write tools
|
||||
EditTool,
|
||||
MemoryTool,
|
||||
SHELL_TOOL_NAME,
|
||||
WRITE_FILE_TOOL_NAME,
|
||||
WEB_FETCH_TOOL_NAME,
|
||||
WebSearchTool,
|
||||
GLOB_TOOL_NAME,
|
||||
EDIT_TOOL_NAME,
|
||||
MEMORY_TOOL_NAME,
|
||||
WEB_SEARCH_TOOL_NAME,
|
||||
} from '@google/gemini-cli-core';
|
||||
import type { Settings } from './settings.js';
|
||||
|
||||
// READ_ONLY_TOOLS is a list of built-in tools that do not modify the user's
|
||||
// files or system state.
|
||||
const READ_ONLY_TOOLS = new Set([
|
||||
GlobTool.Name,
|
||||
GLOB_TOOL_NAME,
|
||||
GREP_TOOL_NAME,
|
||||
LSTool.Name,
|
||||
LS_TOOL_NAME,
|
||||
READ_FILE_TOOL_NAME,
|
||||
READ_MANY_FILES_TOOL_NAME,
|
||||
WebSearchTool.Name,
|
||||
WEB_SEARCH_TOOL_NAME,
|
||||
]);
|
||||
|
||||
// WRITE_TOOLS is a list of built-in tools that can modify the user's files or
|
||||
@@ -43,8 +43,8 @@ const READ_ONLY_TOOLS = new Set([
|
||||
// any tool that isn't read only will require a confirmation unless altered by
|
||||
// config and policy.
|
||||
const WRITE_TOOLS = new Set([
|
||||
EditTool.Name,
|
||||
MemoryTool.Name,
|
||||
EDIT_TOOL_NAME,
|
||||
MEMORY_TOOL_NAME,
|
||||
SHELL_TOOL_NAME,
|
||||
WRITE_FILE_TOOL_NAME,
|
||||
WEB_FETCH_TOOL_NAME,
|
||||
@@ -168,7 +168,7 @@ export function createPolicyEngineConfig(
|
||||
});
|
||||
} else if (approvalMode === ApprovalMode.AUTO_EDIT) {
|
||||
rules.push({
|
||||
toolName: EditTool.Name,
|
||||
toolName: EDIT_TOOL_NAME,
|
||||
decision: PolicyDecision.ALLOW,
|
||||
priority: 15, // Higher than write tools (10) to override ASK_USER
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user