MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / buildConversationChain

Function buildConversationChain

src/utils/sessionStorage.ts:2106–2131  ·  view source on GitHub ↗
(
  messages: Map<UUID, TranscriptMessage>,
  leafMessage: TranscriptMessage,
)

Source from the content-addressed store, hash-verified

2104 * @returns Array of messages from root to leaf
2105 */
2106export function buildConversationChain(
2107 messages: Map<UUID, TranscriptMessage>,
2108 leafMessage: TranscriptMessage,
2109): TranscriptMessage[] {
2110 const transcript: TranscriptMessage[] = []
2111 const seen = new Set<UUID>()
2112 let currentMsg: TranscriptMessage | undefined = leafMessage
2113 while (currentMsg) {
2114 if (seen.has(currentMsg.uuid)) {
2115 logError(
2116 new Error(
2117 `Cycle detected in parentUuid chain at message ${currentMsg.uuid}. Returning partial transcript.`,
2118 ),
2119 )
2120 logEvent('tengu_chain_parent_cycle', {})
2121 break
2122 }
2123 seen.add(currentMsg.uuid)
2124 transcript.push(currentMsg)
2125 currentMsg = currentMsg.parentUuid
2126 ? messages.get(currentMsg.parentUuid)
2127 : undefined
2128 }
2129 transcript.reverse()
2130 return recoverOrphanedParallelToolResults(messages, transcript, seen)
2131}
2132
2133/**
2134 * Post-pass for buildConversationChain: recover sibling assistant blocks and

Callers 6

loadTranscriptFromFileFunction · 0.85
loadFullLogFunction · 0.85
getLastSessionLogFunction · 0.85
getAgentTranscriptFunction · 0.85

Calls 7

logEventFunction · 0.85
logErrorFunction · 0.70
getMethod · 0.65
hasMethod · 0.45
addMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected