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

Function loadTranscriptFromFile

src/utils/sessionStorage.ts:2333–2431  ·  view source on GitHub ↗
(
  filePath: string,
)

Source from the content-addressed store, hash-verified

2331 * @throws Error if file doesn't exist or contains invalid data
2332 */
2333export async function loadTranscriptFromFile(
2334 filePath: string,
2335): Promise<LogOption> {
2336 if (filePath.endsWith('.jsonl')) {
2337 const {
2338 messages,
2339 summaries,
2340 customTitles,
2341 tags,
2342 fileHistorySnapshots,
2343 attributionSnapshots,
2344 contextCollapseCommits,
2345 contextCollapseSnapshot,
2346 leafUuids,
2347 contentReplacements,
2348 worktreeStates,
2349 } = await loadTranscriptFile(filePath)
2350
2351 if (messages.size === 0) {
2352 throw new Error('No messages found in JSONL file')
2353 }
2354
2355 // Find the most recent leaf message using pre-computed leaf UUIDs
2356 const leafMessage = findLatestMessage(messages.values(), msg =>
2357 leafUuids.has(msg.uuid),
2358 )
2359
2360 if (!leafMessage) {
2361 throw new Error('No valid conversation chain found in JSONL file')
2362 }
2363
2364 // Build the conversation chain backwards from leaf to root
2365 const transcript = buildConversationChain(messages, leafMessage)
2366
2367 const summary = summaries.get(leafMessage.uuid)
2368 const customTitle = customTitles.get(leafMessage.sessionId as UUID)
2369 const tag = tags.get(leafMessage.sessionId as UUID)
2370 const sessionId = leafMessage.sessionId as UUID
2371 return {
2372 ...convertToLogOption(
2373 transcript,
2374 0,
2375 summary,
2376 customTitle,
2377 buildFileHistorySnapshotChain(fileHistorySnapshots, transcript),
2378 tag,
2379 filePath,
2380 buildAttributionSnapshotChain(attributionSnapshots, transcript),
2381 undefined,
2382 contentReplacements.get(sessionId) ?? [],
2383 ),
2384 contextCollapseCommits: contextCollapseCommits.filter(
2385 e => e.sessionId === sessionId,
2386 ),
2387 contextCollapseSnapshot:
2388 contextCollapseSnapshot?.sessionId === sessionId
2389 ? contextCollapseSnapshot
2390 : undefined,

Callers 1

runFunction · 0.85

Calls 10

loadTranscriptFileFunction · 0.85
findLatestMessageFunction · 0.85
buildConversationChainFunction · 0.85
convertToLogOptionFunction · 0.85
readFileFunction · 0.85
jsonParseFunction · 0.85
getMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected