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

Function buildConversationChain

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

Source from the content-addressed store, hash-verified

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