Tool 系统是 Claude Code 的核心,负责工具的定义、注册、发现和过滤。本计划覆盖 src/Tool.ts 中的工具接口与工具函数、src/tools.ts 中的注册/过滤逻辑,以及各工具目录下可独立测试的纯函数。
| 文件 | 关键导出 |
|---|---|
src/Tool.ts |
buildTool, toolMatchesName, findToolByName, getEmptyToolPermissionContext, filterToolProgressMessages |
src/tools.ts |
parseToolPreset, filterToolsByDenyRules, getAllBaseTools, getTools, assembleToolPool |
src/tools/shared/gitOperationTracking.ts |
parseGitCommitId, detectGitOperation |
src/tools/shared/spawnMultiAgent.ts |
resolveTeammateModel, generateUniqueTeammateName |
src/tools/GrepTool/GrepTool.ts |
applyHeadLimit, formatLimitInfo(内部辅助函数) |
src/tools/FileEditTool/utils.ts |
字符串匹配/补丁相关纯函数 |
{ behavior: 'allow', updatedInput }{ name: 'Bash' } 匹配 'Bash'{ name: 'Bash' } 不匹配 'Read'{ name: 'Bash', aliases: ['BashTool'] } 匹配 'BashTool'{ name: 'Bash' } 不匹配 'BashTool'{ name: 'Bash', aliases: [] } 不匹配 'BashTool'{ toolName: 'Bash' } 应移除 Bash{ toolName: 'Bash', ruleContent: 'rm -rf' } 不移除 Bash(只在运行时阻止特定命令)mcp__server 应移除该 server 下所有工具[main abc1234] message 中提取 abc1234[feature/foo abc1234] 等git commit 时识别为 commitgit push 时识别| 依赖 | Mock 方式 | 说明 |
|---|---|---|
bun:bundle (feature) |
已 polyfill 为 () => false |
不需额外 mock |
process.env |
bun:test mock |
测试 USER_TYPE、NODE_ENV、CLAUDE_CODE_SIMPLE |
getDenyRuleForTool |
mock module | filterToolsByDenyRules 测试中需控制返回值 |
isToolSearchEnabledOptimistic |
mock module | getAllBaseTools 中条件加载 |
放在 tests/integration/tool-chain.test.ts: