mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-26 13:04:49 -07:00
refactor(core): Centralize tool names to avoid circular dependencies - Edit, Grep, Read (#11434)
This commit is contained in:
@@ -6,9 +6,11 @@
|
||||
|
||||
import type { AgentDefinition } from './types.js';
|
||||
import { LSTool } from '../tools/ls.js';
|
||||
import { ReadFileTool } from '../tools/read-file.js';
|
||||
import { GLOB_TOOL_NAME } from '../tools/tool-names.js';
|
||||
import { GrepTool } from '../tools/grep.js';
|
||||
import {
|
||||
GLOB_TOOL_NAME,
|
||||
GREP_TOOL_NAME,
|
||||
READ_FILE_TOOL_NAME,
|
||||
} from '../tools/tool-names.js';
|
||||
import { DEFAULT_GEMINI_MODEL } from '../config/models.js';
|
||||
import { z } from 'zod';
|
||||
|
||||
@@ -80,7 +82,7 @@ export const CodebaseInvestigatorAgent: AgentDefinition<
|
||||
|
||||
toolConfig: {
|
||||
// Grant access only to read-only tools.
|
||||
tools: [LSTool.Name, ReadFileTool.Name, GLOB_TOOL_NAME, GrepTool.Name],
|
||||
tools: [LSTool.Name, READ_FILE_TOOL_NAME, GLOB_TOOL_NAME, GREP_TOOL_NAME],
|
||||
},
|
||||
|
||||
promptConfig: {
|
||||
|
||||
@@ -9,7 +9,7 @@ import { AgentExecutor, type ActivityCallback } from './executor.js';
|
||||
import { makeFakeConfig } from '../test-utils/config.js';
|
||||
import { ToolRegistry } from '../tools/tool-registry.js';
|
||||
import { LSTool } from '../tools/ls.js';
|
||||
import { ReadFileTool } from '../tools/read-file.js';
|
||||
import { READ_FILE_TOOL_NAME } from '../tools/tool-names.js';
|
||||
import {
|
||||
GeminiChat,
|
||||
StreamEventType,
|
||||
@@ -202,7 +202,9 @@ describe('AgentExecutor', () => {
|
||||
mockConfig = makeFakeConfig();
|
||||
parentToolRegistry = new ToolRegistry(mockConfig);
|
||||
parentToolRegistry.registerTool(new LSTool(mockConfig));
|
||||
parentToolRegistry.registerTool(new ReadFileTool(mockConfig));
|
||||
parentToolRegistry.registerTool(
|
||||
new MockTool({ name: READ_FILE_TOOL_NAME }),
|
||||
);
|
||||
parentToolRegistry.registerTool(MOCK_TOOL_NOT_ALLOWED);
|
||||
|
||||
vi.spyOn(mockConfig, 'getToolRegistry').mockResolvedValue(
|
||||
@@ -242,7 +244,10 @@ describe('AgentExecutor', () => {
|
||||
});
|
||||
|
||||
it('should create an isolated ToolRegistry for the agent', async () => {
|
||||
const definition = createTestDefinition([LSTool.Name, ReadFileTool.Name]);
|
||||
const definition = createTestDefinition([
|
||||
LSTool.Name,
|
||||
READ_FILE_TOOL_NAME,
|
||||
]);
|
||||
const executor = await AgentExecutor.create(
|
||||
definition,
|
||||
mockConfig,
|
||||
@@ -253,7 +258,7 @@ describe('AgentExecutor', () => {
|
||||
|
||||
expect(agentRegistry).not.toBe(parentToolRegistry);
|
||||
expect(agentRegistry.getAllToolNames()).toEqual(
|
||||
expect.arrayContaining([LSTool.Name, ReadFileTool.Name]),
|
||||
expect.arrayContaining([LSTool.Name, READ_FILE_TOOL_NAME]),
|
||||
);
|
||||
expect(agentRegistry.getAllToolNames()).toHaveLength(2);
|
||||
expect(agentRegistry.getTool(MOCK_TOOL_NOT_ALLOWED.name)).toBeUndefined();
|
||||
@@ -801,7 +806,7 @@ describe('AgentExecutor', () => {
|
||||
const badCallId = 'bad_call_1';
|
||||
mockModelResponse([
|
||||
{
|
||||
name: ReadFileTool.Name,
|
||||
name: READ_FILE_TOOL_NAME,
|
||||
args: { path: 'secret.txt' },
|
||||
id: badCallId,
|
||||
},
|
||||
@@ -839,7 +844,7 @@ describe('AgentExecutor', () => {
|
||||
expect.objectContaining({
|
||||
functionResponse: expect.objectContaining({
|
||||
id: badCallId,
|
||||
name: ReadFileTool.Name,
|
||||
name: READ_FILE_TOOL_NAME,
|
||||
response: {
|
||||
error: expect.stringContaining('Unauthorized tool call'),
|
||||
},
|
||||
@@ -853,7 +858,7 @@ describe('AgentExecutor', () => {
|
||||
type: 'ERROR',
|
||||
data: expect.objectContaining({
|
||||
context: 'tool_call_unauthorized',
|
||||
name: ReadFileTool.Name,
|
||||
name: READ_FILE_TOOL_NAME,
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -20,13 +20,15 @@ import { executeToolCall } from '../core/nonInteractiveToolExecutor.js';
|
||||
import { ToolRegistry } from '../tools/tool-registry.js';
|
||||
import type { ToolCallRequestInfo } from '../core/turn.js';
|
||||
import { getDirectoryContextString } from '../utils/environmentContext.js';
|
||||
import { GrepTool } from '../tools/grep.js';
|
||||
import { RipGrepTool } from '../tools/ripGrep.js';
|
||||
import { LSTool } from '../tools/ls.js';
|
||||
import { MemoryTool } from '../tools/memoryTool.js';
|
||||
import { ReadFileTool } from '../tools/read-file.js';
|
||||
import { ReadManyFilesTool } from '../tools/read-many-files.js';
|
||||
import { GLOB_TOOL_NAME, WEB_SEARCH_TOOL_NAME } from '../tools/tool-names.js';
|
||||
import {
|
||||
GLOB_TOOL_NAME,
|
||||
GREP_TOOL_NAME,
|
||||
READ_FILE_TOOL_NAME,
|
||||
READ_MANY_FILES_TOOL_NAME,
|
||||
WEB_SEARCH_TOOL_NAME,
|
||||
} from '../tools/tool-names.js';
|
||||
import { promptIdContext } from '../utils/promptIdContext.js';
|
||||
import { logAgentStart, logAgentFinish } from '../telemetry/loggers.js';
|
||||
import { AgentStartEvent, AgentFinishEvent } from '../telemetry/types.js';
|
||||
@@ -709,11 +711,10 @@ Important Rules:
|
||||
// confirmations for subagents.
|
||||
const allowlist = new Set([
|
||||
LSTool.Name,
|
||||
ReadFileTool.Name,
|
||||
GrepTool.Name,
|
||||
RipGrepTool.Name,
|
||||
READ_FILE_TOOL_NAME,
|
||||
GREP_TOOL_NAME,
|
||||
GLOB_TOOL_NAME,
|
||||
ReadManyFilesTool.Name,
|
||||
READ_MANY_FILES_TOOL_NAME,
|
||||
MemoryTool.Name,
|
||||
WEB_SEARCH_TOOL_NAME,
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user