mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 22:05:50 +00:00
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:
53
src/hooks/useToolSearchHint.ts
Normal file
53
src/hooks/useToolSearchHint.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import * as React from 'react'
|
||||
import {
|
||||
subscribeToToolSearchPrefetch,
|
||||
getToolSearchPrefetchSnapshot,
|
||||
clearToolSearchPrefetchResults,
|
||||
type ToolDiscoveryResult,
|
||||
} from 'src/services/toolSearch/prefetch.js'
|
||||
|
||||
type ToolSearchHintItem = {
|
||||
name: string
|
||||
description: string
|
||||
score: number
|
||||
}
|
||||
|
||||
type ToolSearchHintResult = {
|
||||
tools: ToolSearchHintItem[]
|
||||
visible: boolean
|
||||
handleSelect: (toolName: string) => void
|
||||
handleDismiss: () => void
|
||||
}
|
||||
|
||||
const MAX_HINT_SCORE = 0.15
|
||||
const MAX_HINT_TOOLS = 3
|
||||
|
||||
export function useToolSearchHint(): ToolSearchHintResult {
|
||||
const prefetchResult = React.useSyncExternalStore(
|
||||
subscribeToToolSearchPrefetch,
|
||||
getToolSearchPrefetchSnapshot,
|
||||
)
|
||||
|
||||
const tools: ToolSearchHintItem[] = React.useMemo(() => {
|
||||
if (prefetchResult.length === 0) return []
|
||||
return prefetchResult
|
||||
.slice(0, MAX_HINT_TOOLS)
|
||||
.map((r: ToolDiscoveryResult) => ({
|
||||
name: r.name,
|
||||
description: r.description.slice(0, 60),
|
||||
score: r.score,
|
||||
}))
|
||||
}, [prefetchResult])
|
||||
|
||||
const visible = tools.length > 0 && (tools[0]?.score ?? 0) >= MAX_HINT_SCORE
|
||||
|
||||
const handleSelect = React.useCallback((_toolName: string) => {
|
||||
clearToolSearchPrefetchResults()
|
||||
}, [])
|
||||
|
||||
const handleDismiss = React.useCallback(() => {
|
||||
clearToolSearchPrefetchResults()
|
||||
}, [])
|
||||
|
||||
return { tools, visible, handleSelect, handleDismiss }
|
||||
}
|
||||
Reference in New Issue
Block a user