refactor(core): 重命名 grep_content 工具为 grep
- 重命名 grep_content.ts 为 grep.ts - 更新工具名称从 grep_content 改为 grep - 更新所有引用该工具的代码和测试文件 - 更新描述文件名称
This commit is contained in:
@@ -49,7 +49,7 @@ export const codeReviewerAgent: Omit<AgentInfo, 'name'> = {
|
||||
'read_file',
|
||||
'list_directory',
|
||||
'search_files',
|
||||
'grep_content',
|
||||
'grep',
|
||||
'git_status',
|
||||
'git_diff',
|
||||
],
|
||||
|
||||
@@ -46,7 +46,7 @@ export const exploreAgent: Omit<AgentInfo, 'name'> = {
|
||||
|
||||
## 可用工具
|
||||
- **glob**: 文件模式匹配 (*.ts, src/**/*.tsx)
|
||||
- **grep_content**: 代码内容搜索
|
||||
- **grep**: 代码内容搜索
|
||||
- **read_file**: 读取文件内容
|
||||
- **search_files**: 文件名搜索
|
||||
- **list_directory**: 目录列表
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { AgentInfo } from '../types.js';
|
||||
*
|
||||
* 使用 ${variable} 语法支持动态变量替换:
|
||||
* - ${tools.glob} -> glob
|
||||
* - ${tools.grep} -> grep_content
|
||||
* - ${tools.grep} -> grep
|
||||
* - ${tools.read} -> read_file
|
||||
* - ${tools.bash} -> bash
|
||||
* - ${plan.planFilePath} -> 计划文件路径
|
||||
@@ -92,7 +92,7 @@ export const planAgent: Omit<AgentInfo, 'name'> = {
|
||||
'list_directory',
|
||||
'search_files',
|
||||
'glob',
|
||||
'grep_content',
|
||||
'grep',
|
||||
'get_file_info',
|
||||
// Git 只读
|
||||
'git_status',
|
||||
|
||||
@@ -242,7 +242,7 @@ export function render(
|
||||
*/
|
||||
export const DEFAULT_TOOL_NAMES: ToolNameMapping = {
|
||||
glob: 'glob',
|
||||
grep: 'grep_content',
|
||||
grep: 'grep',
|
||||
read: 'read_file',
|
||||
write: 'write_file',
|
||||
edit: 'edit_file',
|
||||
|
||||
+4
-4
@@ -11,11 +11,11 @@ interface GrepMatch {
|
||||
content: string;
|
||||
}
|
||||
|
||||
export const grepContentTool: ToolWithMetadata = {
|
||||
name: 'grep_content',
|
||||
description: loadDescription('grep_content'),
|
||||
export const grepTool: ToolWithMetadata = {
|
||||
name: 'grep',
|
||||
description: loadDescription('grep'),
|
||||
metadata: {
|
||||
name: 'grep_content',
|
||||
name: 'grep',
|
||||
category: 'filesystem',
|
||||
description: '在文件内容中搜索文本',
|
||||
keywords: ['grep', 'search', 'content', 'text', 'find', 'regex', '搜索', '内容', '文本', '查找', '正则'],
|
||||
@@ -11,7 +11,7 @@ export { createDirectoryTool } from './create_directory.js';
|
||||
// 搜索
|
||||
export { searchFilesTool } from './search_files.js';
|
||||
export { globTool } from './glob.js';
|
||||
export { grepContentTool } from './grep_content.js';
|
||||
export { grepTool } from './grep.js';
|
||||
|
||||
// 文件信息
|
||||
export { getFileInfoTool } from './get_file_info.js';
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
createDirectoryTool,
|
||||
searchFilesTool,
|
||||
globTool,
|
||||
grepContentTool,
|
||||
grepTool,
|
||||
getFileInfoTool,
|
||||
moveFileTool,
|
||||
copyFileTool,
|
||||
@@ -90,7 +90,7 @@ const allToolsWithMetadata: ToolWithMetadata[] = [
|
||||
createDirectoryTool,
|
||||
searchFilesTool,
|
||||
globTool,
|
||||
grepContentTool,
|
||||
grepTool,
|
||||
getFileInfoTool,
|
||||
moveFileTool,
|
||||
copyFileTool,
|
||||
|
||||
@@ -18,7 +18,7 @@ const TOOL_CATEGORY_MAP: Record<string, string> = {
|
||||
create_directory: 'filesystem',
|
||||
search_files: 'filesystem',
|
||||
glob: 'filesystem',
|
||||
grep_content: 'filesystem',
|
||||
grep: 'filesystem',
|
||||
get_file_info: 'filesystem',
|
||||
move_file: 'filesystem',
|
||||
copy_file: 'filesystem',
|
||||
|
||||
@@ -45,7 +45,7 @@ export const enterPlanModeTool: ToolWithMetadata = {
|
||||
|
||||
计划模式中的限制:
|
||||
进入后只能使用只读工具:
|
||||
✅ read_file, list_directory, search_files, grep_content
|
||||
✅ read_file, list_directory, search_files, grep
|
||||
✅ web_search, web_extract
|
||||
✅ task(探索代理)
|
||||
✅ ask_user_question
|
||||
|
||||
@@ -49,7 +49,7 @@ describe('Prompt Template System', () => {
|
||||
it('should handle multiple variables in one template', () => {
|
||||
const template = 'Use ${tools.glob}, ${tools.grep}, and ${tools.read}';
|
||||
const result = renderTemplate(template, context);
|
||||
expect(result).toBe('Use glob, grep_content, and read_file');
|
||||
expect(result).toBe('Use glob, grep, and read_file');
|
||||
});
|
||||
|
||||
it('should handle ternary expressions - false condition', () => {
|
||||
@@ -103,7 +103,7 @@ describe('Prompt Template System', () => {
|
||||
it('should create context with default tool names', () => {
|
||||
const ctx = createDefaultContext();
|
||||
expect(ctx.tools.glob).toBe('glob');
|
||||
expect(ctx.tools.grep).toBe('grep_content');
|
||||
expect(ctx.tools.grep).toBe('grep');
|
||||
expect(ctx.tools.read).toBe('read_file');
|
||||
expect(ctx.tools.write).toBe('write_file');
|
||||
expect(ctx.tools.bash).toBe('bash');
|
||||
@@ -117,7 +117,7 @@ describe('Prompt Template System', () => {
|
||||
},
|
||||
});
|
||||
expect(ctx.tools.glob).toBe('custom_glob');
|
||||
expect(ctx.tools.grep).toBe('grep_content'); // Others unchanged
|
||||
expect(ctx.tools.grep).toBe('grep'); // Others unchanged
|
||||
});
|
||||
|
||||
it('should set default plan values', () => {
|
||||
|
||||
+20
-20
@@ -21,35 +21,35 @@ vi.mock('../../../../src/tools/load_description.js', () => ({
|
||||
loadDescription: vi.fn(() => '在文件内容中搜索文本'),
|
||||
}));
|
||||
|
||||
import { grepContentTool } from '../../../../src/tools/filesystem/grep_content.js';
|
||||
import { grepTool } from '../../../../src/tools/filesystem/grep.js';
|
||||
import * as fs from 'fs/promises';
|
||||
import { getPermissionManager } from '../../../../src/permission/index.js';
|
||||
|
||||
describe('grepContentTool - 内容搜索工具', () => {
|
||||
describe('grepTool - 内容搜索工具', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('工具定义', () => {
|
||||
it('有正确的名称', () => {
|
||||
expect(grepContentTool.name).toBe('grep_content');
|
||||
expect(grepTool.name).toBe('grep');
|
||||
});
|
||||
|
||||
it('有正确的元数据', () => {
|
||||
expect(grepContentTool.metadata.category).toBe('filesystem');
|
||||
expect(grepContentTool.metadata.keywords).toContain('grep');
|
||||
expect(grepContentTool.metadata.keywords).toContain('search');
|
||||
expect(grepContentTool.metadata.keywords).toContain('content');
|
||||
expect(grepTool.metadata.category).toBe('filesystem');
|
||||
expect(grepTool.metadata.keywords).toContain('grep');
|
||||
expect(grepTool.metadata.keywords).toContain('search');
|
||||
expect(grepTool.metadata.keywords).toContain('content');
|
||||
});
|
||||
|
||||
it('定义了必需参数', () => {
|
||||
expect(grepContentTool.parameters.directory.required).toBe(true);
|
||||
expect(grepContentTool.parameters.pattern.required).toBe(true);
|
||||
expect(grepTool.parameters.directory.required).toBe(true);
|
||||
expect(grepTool.parameters.pattern.required).toBe(true);
|
||||
});
|
||||
|
||||
it('定义了可选参数', () => {
|
||||
expect(grepContentTool.parameters.file_pattern.required).toBe(false);
|
||||
expect(grepContentTool.parameters.max_results.required).toBe(false);
|
||||
expect(grepTool.parameters.file_pattern.required).toBe(false);
|
||||
expect(grepTool.parameters.max_results.required).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -60,7 +60,7 @@ describe('grepContentTool - 内容搜索工具', () => {
|
||||
] as any);
|
||||
vi.mocked(fs.readFile).mockResolvedValue('const hello = "world";\nconst foo = "bar";');
|
||||
|
||||
const result = await grepContentTool.execute({
|
||||
const result = await grepTool.execute({
|
||||
directory: '.',
|
||||
pattern: 'hello',
|
||||
});
|
||||
@@ -76,7 +76,7 @@ describe('grepContentTool - 内容搜索工具', () => {
|
||||
] as any);
|
||||
vi.mocked(fs.readFile).mockResolvedValue('const foo = "bar";');
|
||||
|
||||
const result = await grepContentTool.execute({
|
||||
const result = await grepTool.execute({
|
||||
directory: '.',
|
||||
pattern: 'notfound',
|
||||
});
|
||||
@@ -92,7 +92,7 @@ describe('grepContentTool - 内容搜索工具', () => {
|
||||
] as any);
|
||||
vi.mocked(fs.readFile).mockResolvedValue('const hello = "world";');
|
||||
|
||||
const result = await grepContentTool.execute({
|
||||
const result = await grepTool.execute({
|
||||
directory: '.',
|
||||
pattern: 'hello',
|
||||
file_pattern: '*.ts',
|
||||
@@ -112,7 +112,7 @@ describe('grepContentTool - 内容搜索工具', () => {
|
||||
'hello1\nhello2\nhello3\nhello4\nhello5'
|
||||
);
|
||||
|
||||
const result = await grepContentTool.execute({
|
||||
const result = await grepTool.execute({
|
||||
directory: '.',
|
||||
pattern: 'hello',
|
||||
max_results: 2,
|
||||
@@ -135,7 +135,7 @@ describe('grepContentTool - 内容搜索工具', () => {
|
||||
] as any);
|
||||
vi.mocked(fs.readFile).mockResolvedValue('const test = 1;');
|
||||
|
||||
await grepContentTool.execute({
|
||||
await grepTool.execute({
|
||||
directory: '.',
|
||||
pattern: 'test',
|
||||
});
|
||||
@@ -153,7 +153,7 @@ describe('grepContentTool - 内容搜索工具', () => {
|
||||
}),
|
||||
} as any);
|
||||
|
||||
const result = await grepContentTool.execute({
|
||||
const result = await grepTool.execute({
|
||||
directory: '/protected',
|
||||
pattern: 'test',
|
||||
});
|
||||
@@ -171,7 +171,7 @@ describe('grepContentTool - 内容搜索工具', () => {
|
||||
}),
|
||||
} as any);
|
||||
|
||||
const result = await grepContentTool.execute({
|
||||
const result = await grepTool.execute({
|
||||
directory: '.',
|
||||
pattern: 'test',
|
||||
});
|
||||
@@ -194,7 +194,7 @@ describe('grepContentTool - 内容搜索工具', () => {
|
||||
] as any);
|
||||
vi.mocked(fs.readFile).mockResolvedValue('const test = 1;');
|
||||
|
||||
const result = await grepContentTool.execute({
|
||||
const result = await grepTool.execute({
|
||||
directory: '.',
|
||||
pattern: 'test',
|
||||
});
|
||||
@@ -210,7 +210,7 @@ describe('grepContentTool - 内容搜索工具', () => {
|
||||
} as any);
|
||||
vi.mocked(fs.readdir).mockResolvedValue([]);
|
||||
|
||||
await grepContentTool.execute({
|
||||
await grepTool.execute({
|
||||
directory: 'src',
|
||||
pattern: 'test',
|
||||
});
|
||||
@@ -167,7 +167,7 @@ describe('loadDescription', () => {
|
||||
{ tool: 'list_directory', category: 'filesystem' },
|
||||
{ tool: 'create_directory', category: 'filesystem' },
|
||||
{ tool: 'search_files', category: 'filesystem' },
|
||||
{ tool: 'grep_content', category: 'filesystem' },
|
||||
{ tool: 'grep', category: 'filesystem' },
|
||||
{ tool: 'get_file_info', category: 'filesystem' },
|
||||
{ tool: 'move_file', category: 'filesystem' },
|
||||
{ tool: 'copy_file', category: 'filesystem' },
|
||||
|
||||
@@ -116,12 +116,12 @@ describe('toolSearchTool', () => {
|
||||
|
||||
it('搜索结果格式化正确', async () => {
|
||||
vi.mocked(toolRegistry.search).mockReturnValue([
|
||||
{ name: 'grep_content', description: '搜索文件内容', category: 'filesystem' },
|
||||
{ name: 'grep', description: '搜索文件内容', category: 'filesystem' },
|
||||
] as any);
|
||||
|
||||
const result = await toolSearchTool.execute({ query: 'grep' });
|
||||
|
||||
expect(result.output).toContain('- grep_content: 搜索文件内容 [filesystem]');
|
||||
expect(result.output).toContain('- grep: 搜索文件内容 [filesystem]');
|
||||
});
|
||||
|
||||
it('多个搜索结果正确排列', async () => {
|
||||
|
||||
Reference in New Issue
Block a user