(
filePath: string,
opts?: { keepAllLeaves?: boolean },
)
| 3564 | * Returns the messages, summaries, custom titles, tags, file history snapshots, and attribution snapshots. |
| 3565 | */ |
| 3566 | export async function loadTranscriptFile( |
| 3567 | filePath: string, |
| 3568 | opts?: { keepAllLeaves?: boolean }, |
| 3569 | ): Promise<{ |
| 3570 | messages: Map<UUID, TranscriptMessage> |
| 3571 | summaries: Map<UUID, string> |
| 3572 | customTitles: Map<UUID, string> |
| 3573 | tags: Map<UUID, string> |
| 3574 | agentNames: Map<UUID, string> |
| 3575 | agentColors: Map<UUID, string> |
| 3576 | agentSettings: Map<UUID, string> |
| 3577 | prNumbers: Map<UUID, number> |
| 3578 | prUrls: Map<UUID, string> |
| 3579 | prRepositories: Map<UUID, string> |
| 3580 | modes: Map<UUID, string> |
| 3581 | worktreeStates: Map<UUID, PersistedWorktreeSession | null> |
| 3582 | goals: Map<UUID, GoalState> |
| 3583 | fileHistorySnapshots: Map<UUID, FileHistorySnapshotMessage> |
| 3584 | attributionSnapshots: Map<UUID, AttributionSnapshotMessage> |
| 3585 | contentReplacements: Map<UUID, ContentReplacementRecord[]> |
| 3586 | agentContentReplacements: Map<AgentId, ContentReplacementRecord[]> |
| 3587 | contextCollapseCommits: ContextCollapseCommitEntry[] |
| 3588 | contextCollapseSnapshot: ContextCollapseSnapshotEntry | undefined |
| 3589 | leafUuids: Set<UUID> |
| 3590 | }> { |
| 3591 | const messages = new Map<UUID, TranscriptMessage>() |
| 3592 | const summaries = new Map<UUID, string>() |
| 3593 | const customTitles = new Map<UUID, string>() |
| 3594 | const tags = new Map<UUID, string>() |
| 3595 | const agentNames = new Map<UUID, string>() |
| 3596 | const agentColors = new Map<UUID, string>() |
| 3597 | const agentSettings = new Map<UUID, string>() |
| 3598 | const prNumbers = new Map<UUID, number>() |
| 3599 | const prUrls = new Map<UUID, string>() |
| 3600 | const prRepositories = new Map<UUID, string>() |
| 3601 | const modes = new Map<UUID, string>() |
| 3602 | const worktreeStates = new Map<UUID, PersistedWorktreeSession | null>() |
| 3603 | const goals = new Map<UUID, GoalState>() |
| 3604 | const fileHistorySnapshots = new Map<UUID, FileHistorySnapshotMessage>() |
| 3605 | const attributionSnapshots = new Map<UUID, AttributionSnapshotMessage>() |
| 3606 | const contentReplacements = new Map<UUID, ContentReplacementRecord[]>() |
| 3607 | const agentContentReplacements = new Map< |
| 3608 | AgentId, |
| 3609 | ContentReplacementRecord[] |
| 3610 | >() |
| 3611 | // Array, not Map — commit order matters (nested collapses). |
| 3612 | const contextCollapseCommits: ContextCollapseCommitEntry[] = [] |
| 3613 | // Last-wins — later entries supersede. |
| 3614 | let contextCollapseSnapshot: ContextCollapseSnapshotEntry | undefined |
| 3615 | |
| 3616 | try { |
| 3617 | // For large transcripts, avoid materializing megabytes of stale content. |
| 3618 | // Single forward chunked read: attribution-snapshot lines are skipped at |
| 3619 | // the fd level (never buffered), compact boundaries truncate the |
| 3620 | // accumulator in-stream. Peak allocation is the OUTPUT size, not the |
| 3621 | // file size — a 151 MB session that is 84% stale attr-snaps allocates |
| 3622 | // ~32 MB instead of 159+64 MB. This matters because mimalloc does not |
| 3623 | // return those pages to the OS even after JS-level GC frees the backing |
no test coverage detected