MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / buildSubagentLookups

Function buildSubagentLookups

source code/utils/messages.ts:1375–1418  ·  view source on GitHub ↗
(
  messages: { message: AssistantMessage | NormalizedUserMessage }[],
)

Source from the content-addressed store, hash-verified

1373 * `AssistantMessage | NormalizedUserMessage`.
1374 */
1375export function buildSubagentLookups(
1376 messages: { message: AssistantMessage | NormalizedUserMessage }[],
1377): { lookups: MessageLookups; inProgressToolUseIDs: Set<string> } {
1378 const toolUseByToolUseID = new Map<string, ToolUseBlockParam>()
1379 const resolvedToolUseIDs = new Set<string>()
1380 const toolResultByToolUseID = new Map<
1381 string,
1382 NormalizedUserMessage & { type: 'user' }
1383 >()
1384
1385 for (const { message: msg } of messages) {
1386 if (msg.type === 'assistant') {
1387 for (const content of msg.message.content) {
1388 if (content.type === 'tool_use') {
1389 toolUseByToolUseID.set(content.id, content as ToolUseBlockParam)
1390 }
1391 }
1392 } else if (msg.type === 'user') {
1393 for (const content of msg.message.content) {
1394 if (content.type === 'tool_result') {
1395 resolvedToolUseIDs.add(content.tool_use_id)
1396 toolResultByToolUseID.set(content.tool_use_id, msg)
1397 }
1398 }
1399 }
1400 }
1401
1402 const inProgressToolUseIDs = new Set<string>()
1403 for (const id of toolUseByToolUseID.keys()) {
1404 if (!resolvedToolUseIDs.has(id)) {
1405 inProgressToolUseIDs.add(id)
1406 }
1407 }
1408
1409 return {
1410 lookups: {
1411 ...EMPTY_LOOKUPS,
1412 toolUseByToolUseID,
1413 resolvedToolUseIDs,
1414 toolResultByToolUseID,
1415 },
1416 inProgressToolUseIDs,
1417 }
1418}
1419
1420/**
1421 * Get sibling tool use IDs using pre-computed lookup. O(1).

Callers 3

VerboseAgentTranscriptFunction · 0.85

Calls 4

setMethod · 0.80
keysMethod · 0.80
addMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected