注册机制

所有 built-in tool 在启动时通过 tools.RegisterAllWithDeps() 注册(internal/tools/register.go)。

Deps 结构注入外部依赖:

type Deps struct {
    SkillRegistry *skills.SkillRegistry
    MCPManager    *mcp.MCPManager
    TaskManager   *tasks.TaskManager
    AgentRunner   AgentRunner   // 接口:RunSubagent()
    SkillRunner   SkillRunner   // 接口:RunSubagent()
}

全部内置 Tool 列表

Tool 名目录说明
Bashbash/执行 shell 命令
Readfile_read/读取文件内容
Editfile_edit/文件内容替换
Writefile_write/写入文件
Globglob/文件 glob 匹配
Grepgrep/文件内容搜索
NotebookEditnotebook_edit/Jupyter notebook 编辑
WebFetchweb_fetch/抓取 URL 内容
WebSearchweb_search/网络搜索(FeedCoop API)
FeedCoopfeed_coop/FeedCoop 搜索接口
Agentagent/启动子 agent
Skillskill/执行 skill
AskUserask_user/向用户提问(需交互)
Briefbrief/生成摘要
EnterPlanModeenter_plan_mode/进入 plan mode
ExitPlanModeexit_plan_mode/退出 plan mode
SendMessagesend_message/发送消息
TaskOutputtask_output/获取后台任务输出
TodoWritetodo_write/创建/更新 todo 列表
ToolSearchtool_search/搜索可用工具
ListMCPResourceslist_mcp_resources/列出 MCP resource
ReadMCPResourceread_mcp_resource/读取 MCP resource
PowerShellpowershell/Windows PowerShell(仅 Windows)

Tool 接口

每个 tool 实现 toolbase.Tool 接口(internal/toolbase/toolbase.go):

  • Name() — tool 标识符(LLM 调用时用此名称)
  • Description() — 工具描述(注入 system prompt)
  • Prompt() — 详细使用说明(优先于 Description 注入)
  • IsEnabled() — 是否在当前环境可用
  • RequiresUserInteraction() — 是否强制需要用户交互(bypass-immune)
  • CheckPermissions(input, ctx) — 权限检查
  • Execute(ctx, input, toolCtx) — 执行逻辑

执行流程

internal/tools/execution.go 封装单次 tool 执行:

1. 从 registry 查找 tool
2. 反序列化 input JSON
3. 运行 PreToolUse hooks
4. HasPermissionsToUseToolFull()
5. 如需用户确认 → 等待(非 headless)或 deny(headless)
6. tool.Execute()
7. 运行 PostToolUse hooks
8. 返回 tool_result

沙箱

internal/sandbox/ 对 Bash tool 的 shell 执行实现平台差异沙箱:

  • macOS:使用 sandbox-exec
  • Linux:可选 seccomp/namespace 隔离
  • Windows:无沙箱

相关页面