feat(core): 增强 General 和 Explore Agent 预设

General Agent:
- 添加详细的 prompt 引导子代理行为
- 禁用 todo_read/todo_write(避免与父 Agent 冲突)
- 增加 maxSteps 到 20

Explore Agent:
- 支持 thoroughness 参数 (quick/medium/thorough)
- 启用只读 bash 命令(ls, tree, find, git log 等)
- 禁用写入工具和 Todo 工具
- bash 默认策略改为 deny(比 Plan 更严格)
- 添加详细的探索深度指导 prompt

Plan Agent:
- 添加 web: 'ask' 权限配置
This commit is contained in:
2025-12-15 22:01:53 +08:00
parent 35d87a04fb
commit df811395f8
3 changed files with 182 additions and 21 deletions
+143 -19
View File
@@ -2,30 +2,104 @@ import type { AgentInfo } from '../types.js';
/**
* 探索 Agent
* 快速探索代码库,搜索文件和代码结构(只读)
* 子代理模式,快速探索代码库,搜索文件和代码结构(只读)
*
* 特性:
* - 强大的搜索能力:Glob/Grep/Read
* - 只读 bash 命令:ls, tree, find, git log 等
* - thoroughness 参数:控制探索深度
* - 禁用写入和 Todo 工具
*
* 使用方式(通过 Task 工具):
* - quick: 快速搜索,找到关键文件即可
* - medium: 中等深度,分析代码结构
* - thorough: 深度探索,完整理解架构
*/
export const exploreAgent: Omit<AgentInfo, 'name'> = {
description: '快速探索代码库,搜索文件和代码结构(只读)',
description: '快速探索代码库,搜索文件和代码结构(只读)。支持 thoroughness 参数: quick/medium/thorough',
mode: 'subagent',
prompt: `你是一个代码探索专家。你的任务是快速搜索和理解代码库结构
prompt: `你是一个代码探索专家,作为子代理被调用来搜索和分析代码库。
规则:
- 只做搜索和读取操作,禁止修改任何文件
- 使用 search_files、grep_content、read_file、list_directory 工具来探索代码
- 提供清晰、结构化的分析结果
- 关注代码结构、依赖关系和关键实现
## 角色说明
你的任务是快速、准确地探索代码库,找到相关文件和代码结构。
输出格式:
- 使用 Markdown 格式组织信息
- 列出关键文件和它们的作用
- 总结代码结构和设计模式`,
## 探索深度 (thoroughness)
根据任务描述中的深度要求调整你的行为:
### quick (快速)
- 目标:快速定位关键文件
- 策略:使用 glob 模式匹配,grep 关键词搜索
- 步骤:2-5 步
- 输出:文件列表 + 简要说明
### medium (中等)
- 目标:理解代码结构和关系
- 策略:搜索 + 读取关键文件 + 分析依赖
- 步骤:5-10 步
- 输出:结构分析 + 关键实现说明
### thorough (深度)
- 目标:完整理解架构和设计
- 策略:全面搜索 + 深入阅读 + 跨文件分析
- 步骤:10-20 步
- 输出:详细架构文档 + 设计模式 + 建议
## 可用工具
- **glob**: 文件模式匹配 (*.ts, src/**/*.tsx)
- **grep_content**: 代码内容搜索
- **read_file**: 读取文件内容
- **search_files**: 文件名搜索
- **list_directory**: 目录列表
- **bash**: 只读命令 (ls, tree, find, git log/status/diff)
## 工作原则
1. **效率优先** - 先用 glob/grep 定位,再 read 确认
2. **结构化输出** - 使用 Markdown 组织结果
3. **关注重点** - 找到关键文件和核心逻辑
4. **避免冗余** - 不要读取无关文件
## 输出格式
\`\`\`markdown
## 探索结果
### 关键文件
- \`path/to/file.ts\` - 描述作用
### 代码结构
[结构说明]
### 发现
[关键发现和建议]
\`\`\`
## 限制
- 只读操作,禁止修改任何文件
- 不要管理 Todo 列表
- 不要调用 Task 工具`,
tools: {
enabled: [
'read_file',
'list_directory',
'search_files',
'grep_content',
'get_file_info',
disabled: [
// 禁用所有写入操作
'write_file',
'edit_file',
'delete_file',
'move_file',
'copy_file',
'create_directory',
'multi_edit',
// 禁用 Todo(由父 Agent 管理)
'todo_read',
'todo_write',
// 禁用 Git 写操作
'git_add',
'git_commit',
'git_push',
'git_pull',
'git_checkout',
'git_stash',
// 禁用 checkpoint
'checkpoint_create',
'checkpoint_restore',
'undo',
],
noTask: true,
},
@@ -37,7 +111,57 @@ export const exploreAgent: Omit<AgentInfo, 'name'> = {
delete: 'deny',
},
bash: {
enabled: false,
enabled: true,
rules: [
// ============ 文件查看 - 允许 ============
{ pattern: 'ls', action: 'allow' },
{ pattern: 'ls *', action: 'allow' },
{ pattern: 'pwd', action: 'allow' },
{ pattern: 'cat *', action: 'allow' },
{ pattern: 'head *', action: 'allow' },
{ pattern: 'tail *', action: 'allow' },
// ============ 搜索 - 允许 ============
{ pattern: 'find *', action: 'allow' },
{ pattern: 'grep *', action: 'allow' },
{ pattern: 'rg *', action: 'allow' },
{ pattern: 'tree', action: 'allow' },
{ pattern: 'tree *', action: 'allow' },
// ============ 文件信息 - 允许 ============
{ pattern: 'wc *', action: 'allow' },
{ pattern: 'stat *', action: 'allow' },
{ pattern: 'file *', action: 'allow' },
{ pattern: 'du *', action: 'allow' },
{ pattern: 'which *', action: 'allow' },
// ============ Git 只读 - 允许 ============
{ pattern: 'git status', action: 'allow' },
{ pattern: 'git status *', action: 'allow' },
{ pattern: 'git diff', action: 'allow' },
{ pattern: 'git diff *', action: 'allow' },
{ pattern: 'git log', action: 'allow' },
{ pattern: 'git log *', action: 'allow' },
{ pattern: 'git show *', action: 'allow' },
{ pattern: 'git branch', action: 'allow' },
{ pattern: 'git branch *', action: 'allow' },
{ pattern: 'git ls-files*', action: 'allow' },
// ============ 所有写操作 - 拒绝 ============
{ pattern: 'rm *', action: 'deny' },
{ pattern: 'mv *', action: 'deny' },
{ pattern: 'cp *', action: 'deny' },
{ pattern: 'mkdir *', action: 'deny' },
{ pattern: 'touch *', action: 'deny' },
{ pattern: 'chmod *', action: 'deny' },
{ pattern: 'git add *', action: 'deny' },
{ pattern: 'git commit *', action: 'deny' },
{ pattern: 'git push *', action: 'deny' },
{ pattern: 'git checkout *', action: 'deny' },
{ pattern: '* > *', action: 'deny' },
{ pattern: '* >> *', action: 'deny' },
],
default: 'deny', // 其他命令默认拒绝(比 Plan 更严格)
},
git: {
read: 'allow',
+37 -2
View File
@@ -2,13 +2,48 @@ import type { AgentInfo } from '../types.js';
/**
* 通用 Agent
* 适合复杂的多步骤任务、代码搜索和问题研究
* 子代理模式,适合复杂的多步骤任务、代码搜索和问题研究
*
* 特性:
* - 禁用 TodoRead/TodoWrite(避免与父 Agent 冲突)
* - 禁止嵌套 Task(防止无限递归)
* - 完整的文件读写和 bash 权限
*/
export const generalAgent: Omit<AgentInfo, 'name'> = {
description: '通用 Agent,适合复杂的多步骤任务、代码搜索和问题研究',
mode: 'subagent',
prompt: `你是一个通用的 AI 编程助手,作为子代理被调用来处理复杂任务。
## 角色说明
你被父 Agent 通过 Task 工具调用,负责处理需要多步骤的复杂任务。
## 工作原则
1. **专注任务** - 只完成分配给你的具体任务,不要偏离
2. **高效执行** - 使用合适的工具快速完成任务
3. **清晰输出** - 提供结构化的结果,便于父 Agent 使用
4. **避免冗余** - 不要重复父 Agent 已完成的工作
## 可用能力
- 文件读写和编辑
- 代码搜索和分析
- Bash 命令执行
- Git 操作
## 限制
- 不要管理 Todo 列表(由父 Agent 管理)
- 不要调用 Task 工具(避免无限嵌套)
## 输出格式
完成任务后,提供:
1. 执行摘要
2. 关键发现或修改
3. 需要父 Agent 注意的事项(如有)`,
tools: {
disabled: [
'todo_read',
'todo_write',
],
noTask: true, // 禁止嵌套调用 Task
},
maxSteps: 15,
maxSteps: 20,
};
+2
View File
@@ -22,6 +22,7 @@ export const planAgent: Omit<AgentInfo, 'name'> = {
## 可用工具
- read_file, grep_content, search_files: 代码搜索
- bash: 只读命令 (ls, grep, find, git log/diff/status...)
- web_search, web_extract: 网络搜索和网页内容提取(需用户允许)
- plan_mode_respond: 输出结构化计划
## 工作流程
@@ -183,6 +184,7 @@ export const planAgent: Omit<AgentInfo, 'name'> = {
write: 'deny',
dangerous: 'deny',
},
web: 'ask', // 网络搜索和网页提取需要用户允许
},
model: {
temperature: 0.5,