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

Function loadTranscriptFromFile

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

Source from the content-addressed store, hash-verified

2292 * @throws Error if file doesn't exist or contains invalid data
2293 */
2294export async function loadTranscriptFromFile(
2295 filePath: string,
2296): Promise<LogOption> {
2297 if (filePath.endsWith('.jsonl')) {
2298 const {
2299 messages,
2300 summaries,
2301 customTitles,
2302 tags,
2303 fileHistorySnapshots,
2304 attributionSnapshots,
2305 contextCollapseCommits,
2306 contextCollapseSnapshot,
2307 leafUuids,
2308 contentReplacements,
2309 worktreeStates,
2310 } = await loadTranscriptFile(filePath)
2311
2312 if (messages.size === 0) {
2313 throw new Error('No messages found in JSONL file')
2314 }
2315
2316 // Find the most recent leaf message using pre-computed leaf UUIDs
2317 const leafMessage = findLatestMessage(messages.values(), msg =>
2318 leafUuids.has(msg.uuid),
2319 )
2320
2321 if (!leafMessage) {
2322 throw new Error('No valid conversation chain found in JSONL file')
2323 }
2324
2325 // Build the conversation chain backwards from leaf to root
2326 const transcript = buildConversationChain(messages, leafMessage)
2327
2328 const summary = summaries.get(leafMessage.uuid)
2329 const customTitle = customTitles.get(leafMessage.sessionId as UUID)
2330 const tag = tags.get(leafMessage.sessionId as UUID)
2331 const sessionId = leafMessage.sessionId as UUID
2332 return {
2333 ...convertToLogOption(
2334 transcript,
2335 0,
2336 summary,
2337 customTitle,
2338 buildFileHistorySnapshotChain(fileHistorySnapshots, transcript),
2339 tag,
2340 filePath,
2341 buildAttributionSnapshotChain(attributionSnapshots, transcript),
2342 undefined,
2343 contentReplacements.get(sessionId) ?? [],
2344 ),
2345 contextCollapseCommits: contextCollapseCommits.filter(
2346 e => e.sessionId === sessionId,
2347 ),
2348 contextCollapseSnapshot:
2349 contextCollapseSnapshot?.sessionId === sessionId
2350 ? contextCollapseSnapshot
2351 : 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
hasMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected