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