( initialTools: Tools, assembled: Tools, mode: ToolPermissionContext['mode'], )
| 53 | * @returns Merged, deduplicated, and coordinator-filtered tool array. |
| 54 | */ |
| 55 | export function mergeAndFilterTools( |
| 56 | initialTools: Tools, |
| 57 | assembled: Tools, |
| 58 | mode: ToolPermissionContext['mode'], |
| 59 | ): Tools { |
| 60 | // Merge initialTools on top - they take precedence in deduplication. |
| 61 | // initialTools may include built-in tools (from getTools() in REPL.tsx) which |
| 62 | // overlap with assembled tools. uniqBy handles this deduplication. |
| 63 | // Partition-sort for prompt-cache stability (same as assembleToolPool): |
| 64 | // built-ins must stay a contiguous prefix for the server's cache policy. |
| 65 | const [mcp, builtIn] = partition( |
| 66 | uniqBy([...initialTools, ...assembled], 'name'), |
| 67 | isMcpTool, |
| 68 | ) |
| 69 | const byName = (a: Tool, b: Tool) => a.name.localeCompare(b.name) |
| 70 | const tools = [...builtIn.sort(byName), ...mcp.sort(byName)] |
| 71 | |
| 72 | if (feature('COORDINATOR_MODE') && coordinatorModeModule) { |
| 73 | if (coordinatorModeModule.isCoordinatorMode()) { |
| 74 | return applyCoordinatorToolFilter(tools) |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | return tools |
| 79 | } |
| 80 |
no test coverage detected