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

Function buildConversationChain

source code/utils/sessionStorage.ts:2071–2096  ·  view source on GitHub ↗
(
  messages: Map<UUID, TranscriptMessage>,
  leafMessage: TranscriptMessage,
)

Source from the content-addressed store, hash-verified

2069 * @returns Array of messages from root to leaf
2070 */
2071export function buildConversationChain(
2072 messages: Map<UUID, TranscriptMessage>,
2073 leafMessage: TranscriptMessage,
2074): TranscriptMessage[] {
2075 const transcript: TranscriptMessage[] = []
2076 const seen = new Set<UUID>()
2077 let currentMsg: TranscriptMessage | undefined = leafMessage
2078 while (currentMsg) {
2079 if (seen.has(currentMsg.uuid)) {
2080 logError(
2081 new Error(
2082 `Cycle detected in parentUuid chain at message ${currentMsg.uuid}. Returning partial transcript.`,
2083 ),
2084 )
2085 logEvent('tengu_chain_parent_cycle', {})
2086 break
2087 }
2088 seen.add(currentMsg.uuid)
2089 transcript.push(currentMsg)
2090 currentMsg = currentMsg.parentUuid
2091 ? messages.get(currentMsg.parentUuid)
2092 : undefined
2093 }
2094 transcript.reverse()
2095 return recoverOrphanedParallelToolResults(messages, transcript, seen)
2096}
2097
2098/**
2099 * Post-pass for buildConversationChain: recover sibling assistant blocks and

Callers 6

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

Calls 6

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

Tested by

no test coverage detected