feat: 实现 Tool Search 基础设施层(CORE_TOOLS 白名单 + TF-IDF 索引 + ExecuteTool + 搜索增强)

- 新增 CORE_TOOLS 白名单常量(31 个核心工具),重构 isDeferredTool 为白名单制判定
- 新建 TF-IDF 工具索引模块(toolIndex.ts),复用 localSearch.ts 算法函数
- 新建 ExecuteTool 跨 API provider 统一工具执行入口
- 增强 ToolSearchTool:TF-IDF 搜索路径、discover: 模式、并行搜索合并、文本模式回退
- 新增 27 个单元测试,precheck 零错误通过(4108 tests pass)

Co-Authored-By: glm-5.1[1m] <zai-org@claude-code-best.win>
This commit is contained in:
claude-code-best
2026-05-08 22:29:15 +08:00
parent 02dd796706
commit 7be08f53bd
34 changed files with 4040 additions and 90 deletions

View File

@@ -68,6 +68,9 @@ import {
const skillPrefetch = feature('EXPERIMENTAL_SKILL_SEARCH')
? (require('./services/skillSearch/prefetch.js') as typeof import('./services/skillSearch/prefetch.js'))
: null
const toolSearchPrefetch = feature('EXPERIMENTAL_TOOL_SEARCH')
? (require('./services/toolSearch/prefetch.js') as typeof import('./services/toolSearch/prefetch.js'))
: null
const _jobClassifier = feature('TEMPLATES')
? (require('./jobs/classifier.js') as typeof import('./jobs/classifier.js'))
: null
@@ -482,6 +485,10 @@ async function* queryLoop(
messages,
toolUseContext,
)
const pendingToolPrefetch = toolSearchPrefetch?.startToolSearchPrefetch(
toolUseContext.options.tools ?? [],
messages,
)
yield { type: 'stream_request_start' }
@@ -1917,6 +1924,17 @@ async function* queryLoop(
}
}
// Inject prefetched tool discovery.
if (toolSearchPrefetch && pendingToolPrefetch) {
const toolAttachments =
await toolSearchPrefetch.collectToolSearchPrefetch(pendingToolPrefetch)
for (const att of toolAttachments) {
const msg = createAttachmentMessage(att)
yield msg
toolResults.push(msg)
}
}
// Remove only commands that were actually consumed as attachments.
// Prompt and task-notification commands are converted to attachments above.
const claimedCommandSet = new Set(claimedConsumedCommands)