MCPcopy Create free account
hub / github.com/WJX20/claude-code / getAgentTranscript

Function getAgentTranscript

src/utils/sessionStorage.ts:4191–4237  ·  view source on GitHub ↗
(agentId: AgentId)

Source from the content-addressed store, hash-verified

4189 * or null if not found
4190 */
4191export async function getAgentTranscript(agentId: AgentId): Promise<{
4192 messages: Message[]
4193 contentReplacements: ContentReplacementRecord[]
4194} | null> {
4195 const agentFile = getAgentTranscriptPath(agentId)
4196
4197 try {
4198 const { messages, agentContentReplacements } =
4199 await loadTranscriptFile(agentFile)
4200
4201 // Find messages with matching agentId
4202 const agentMessages = Array.from(messages.values()).filter(
4203 msg => msg.agentId === agentId && msg.isSidechain,
4204 )
4205
4206 if (agentMessages.length === 0) {
4207 return null
4208 }
4209
4210 // Find the most recent leaf message with this agentId
4211 const parentUuids = new Set(agentMessages.map(msg => msg.parentUuid))
4212 const leafMessage = findLatestMessage(
4213 agentMessages,
4214 msg => !parentUuids.has(msg.uuid),
4215 )
4216
4217 if (!leafMessage) {
4218 return null
4219 }
4220
4221 // Build the conversation chain
4222 const transcript = buildConversationChain(messages, leafMessage)
4223
4224 // Filter to only include messages with this agentId
4225 const agentTranscript = transcript.filter(msg => msg.agentId === agentId)
4226
4227 return {
4228 // Convert TranscriptMessage[] to Message[]
4229 messages: agentTranscript.map(
4230 ({ isSidechain, parentUuid, ...msg }) => msg,
4231 ),
4232 contentReplacements: agentContentReplacements.get(agentId) ?? [],
4233 }
4234 } catch {
4235 return null
4236 }
4237}
4238
4239/**
4240 * Extract agent IDs from progress messages in the conversation.

Callers 4

resumeAgentBackgroundFunction · 0.85
loadSubagentTranscriptsFunction · 0.85
REPLFunction · 0.85
runSummaryFunction · 0.85

Calls 6

getAgentTranscriptPathFunction · 0.85
loadTranscriptFileFunction · 0.85
findLatestMessageFunction · 0.85
buildConversationChainFunction · 0.85
hasMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected