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

Function loadTranscriptFile

src/utils/sessionStorage.ts:3473–3814  ·  view source on GitHub ↗
(
  filePath: string,
  opts?: { keepAllLeaves?: boolean },
)

Source from the content-addressed store, hash-verified

3471 * Returns the messages, summaries, custom titles, tags, file history snapshots, and attribution snapshots.
3472 */
3473export async function loadTranscriptFile(
3474 filePath: string,
3475 opts?: { keepAllLeaves?: boolean },
3476): Promise<{
3477 messages: Map<UUID, TranscriptMessage>
3478 summaries: Map<UUID, string>
3479 customTitles: Map<UUID, string>
3480 tags: Map<UUID, string>
3481 agentNames: Map<UUID, string>
3482 agentColors: Map<UUID, string>
3483 agentSettings: Map<UUID, string>
3484 prNumbers: Map<UUID, number>
3485 prUrls: Map<UUID, string>
3486 prRepositories: Map<UUID, string>
3487 modes: Map<UUID, string>
3488 worktreeStates: Map<UUID, PersistedWorktreeSession | null>
3489 fileHistorySnapshots: Map<UUID, FileHistorySnapshotMessage>
3490 attributionSnapshots: Map<UUID, AttributionSnapshotMessage>
3491 contentReplacements: Map<UUID, ContentReplacementRecord[]>
3492 agentContentReplacements: Map<AgentId, ContentReplacementRecord[]>
3493 contextCollapseCommits: ContextCollapseCommitEntry[]
3494 contextCollapseSnapshot: ContextCollapseSnapshotEntry | undefined
3495 leafUuids: Set<UUID>
3496}> {
3497 const messages = new Map<UUID, TranscriptMessage>()
3498 const summaries = new Map<UUID, string>()
3499 const customTitles = new Map<UUID, string>()
3500 const tags = new Map<UUID, string>()
3501 const agentNames = new Map<UUID, string>()
3502 const agentColors = new Map<UUID, string>()
3503 const agentSettings = new Map<UUID, string>()
3504 const prNumbers = new Map<UUID, number>()
3505 const prUrls = new Map<UUID, string>()
3506 const prRepositories = new Map<UUID, string>()
3507 const modes = new Map<UUID, string>()
3508 const worktreeStates = new Map<UUID, PersistedWorktreeSession | null>()
3509 const fileHistorySnapshots = new Map<UUID, FileHistorySnapshotMessage>()
3510 const attributionSnapshots = new Map<UUID, AttributionSnapshotMessage>()
3511 const contentReplacements = new Map<UUID, ContentReplacementRecord[]>()
3512 const agentContentReplacements = new Map<
3513 AgentId,
3514 ContentReplacementRecord[]
3515 >()
3516 // Array, not Map — commit order matters (nested collapses).
3517 const contextCollapseCommits: ContextCollapseCommitEntry[] = []
3518 // Last-wins — later entries supersede.
3519 let contextCollapseSnapshot: ContextCollapseSnapshotEntry | undefined
3520
3521 try {
3522 // For large transcripts, avoid materializing megabytes of stale content.
3523 // Single forward chunked read: attribution-snapshot lines are skipped at
3524 // the fd level (never buffered), compact boundaries truncate the
3525 // accumulator in-stream. Peak allocation is the OUTPUT size, not the
3526 // file size — a 151 MB session that is 84% stale attr-snaps allocates
3527 // ~32 MB instead of 159+64 MB. This matters because mimalloc does not
3528 // return those pages to the OS even after JS-level GC frees the backing
3529 // buffers (measured: arrayBuffers=0 after Bun.gc(true) but RSS stuck at
3530 // ~316 MB on the old scan+strip path vs ~155 MB here).

Callers 7

loadTranscriptFromFileFunction · 0.85
loadFullLogFunction · 0.85
loadSessionFileFunction · 0.85
getAgentTranscriptFunction · 0.85
findUnresolvedToolUseFunction · 0.85

Calls 15

parseJSONLFunction · 0.90
isEnvTruthyFunction · 0.85
statFunction · 0.85
readTranscriptForLoadFunction · 0.85
scanPreBoundaryMetadataFunction · 0.85
readFileFunction · 0.85
walkChainBeforeParseFunction · 0.85
isLegacyProgressEntryFunction · 0.85
isTranscriptMessageFunction · 0.85
isCompactBoundaryMessageFunction · 0.85
applySnipRemovalsFunction · 0.85

Tested by

no test coverage detected