MCPcopy Index your code
hub / github.com/codeaashu/claude-code / partitionToolCalls

Function partitionToolCalls

src/services/tools/toolOrchestration.ts:91–116  ·  view source on GitHub ↗

* Partition tool calls into batches where each batch is either: * 1. A single non-read-only tool, or * 2. Multiple consecutive read-only tools

(
  toolUseMessages: ToolUseBlock[],
  toolUseContext: ToolUseContext,
)

Source from the content-addressed store, hash-verified

89 * 2. Multiple consecutive read-only tools
90 */
91function partitionToolCalls(
92 toolUseMessages: ToolUseBlock[],
93 toolUseContext: ToolUseContext,
94): Batch[] {
95 return toolUseMessages.reduce((acc: Batch[], toolUse) => {
96 const tool = findToolByName(toolUseContext.options.tools, toolUse.name)
97 const parsedInput = tool?.inputSchema.safeParse(toolUse.input)
98 const isConcurrencySafe = parsedInput?.success
99 ? (() => {
100 try {
101 return Boolean(tool?.isConcurrencySafe(parsedInput.data))
102 } catch {
103 // If isConcurrencySafe throws (e.g., due to shell-quote parse failure),
104 // treat as not concurrency-safe to be conservative
105 return false
106 }
107 })()
108 : false
109 if (isConcurrencySafe && acc[acc.length - 1]?.isConcurrencySafe) {
110 acc[acc.length - 1]!.blocks.push(toolUse)
111 } else {
112 acc.push({ isConcurrencySafe, blocks: [toolUse] })
113 }
114 return acc
115 }, [])
116}
117
118async function* runToolsSerially(
119 toolUseMessages: ToolUseBlock[],

Callers 1

runToolsFunction · 0.85

Calls 2

findToolByNameFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected