Files
claude-code/src/hooks/useMergedTools.ts
claude-code-best fcbc882232 chore: 清理 src 下 113 项未使用导入和死代码
删除未使用的文件(BuiltinStatusLine.tsx、4 个重复的 .ts stub)、
移除约 55 个文件中未使用的 React 导入、
清理约 50 处未使用的导入/变量/参数。
净减少 ~296 行代码,precheck 4077 测试全部通过。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-05 20:05:15 +08:00

44 lines
1.6 KiB
TypeScript

// biome-ignore-all assist/source/organizeImports: ANT-ONLY import markers must not be reordered
import { useMemo } from 'react'
import type { Tools, ToolPermissionContext } from '../Tool.js'
import { assembleToolPool } from '../tools.js'
import { mergeAndFilterTools } from '../utils/toolPool.js'
/**
* React hook that assembles the full tool pool for the REPL.
*
* Uses assembleToolPool() (the shared pure function used by both REPL and runAgent)
* to combine built-in tools with MCP tools, applying deny rules and deduplication.
* Any extra initialTools are merged on top.
*
* @param initialTools - Extra tools to include (built-in + startup MCP from props).
* These are merged with the assembled pool and take precedence in deduplication.
* @param mcpTools - MCP tools discovered dynamically (from mcp state)
* @param toolPermissionContext - Permission context for filtering
*/
export function useMergedTools(
initialTools: Tools,
mcpTools: Tools,
toolPermissionContext: ToolPermissionContext,
): Tools {
let replBridgeEnabled = false
let replBridgeOutboundOnly = false
return useMemo(() => {
// assembleToolPool is the shared function that both REPL and runAgent use.
// It handles: getTools() + MCP deny-rule filtering + dedup + MCP CLI exclusion.
const assembled = assembleToolPool(toolPermissionContext, mcpTools)
return mergeAndFilterTools(
initialTools,
assembled,
toolPermissionContext.mode,
)
}, [
initialTools,
mcpTools,
toolPermissionContext,
replBridgeEnabled,
replBridgeOutboundOnly,
])
}