(
filePath: string,
opts?: { keepAllLeaves?: boolean },
)
| 3499 | * Returns the messages, summaries, custom titles, tags, file history snapshots, and attribution snapshots. |
| 3500 | */ |
| 3501 | export async function loadTranscriptFile( |
| 3502 | filePath: string, |
| 3503 | opts?: { keepAllLeaves?: boolean }, |
| 3504 | ): Promise<{ |
| 3505 | messages: Map<UUID, TranscriptMessage> |
| 3506 | summaries: Map<UUID, string> |
| 3507 | customTitles: Map<UUID, string> |
| 3508 | tags: Map<UUID, string> |
| 3509 | agentNames: Map<UUID, string> |
| 3510 | agentColors: Map<UUID, string> |
| 3511 | agentSettings: Map<UUID, string> |
| 3512 | prNumbers: Map<UUID, number> |
| 3513 | prUrls: Map<UUID, string> |
| 3514 | prRepositories: Map<UUID, string> |
| 3515 | modes: Map<UUID, string> |
| 3516 | worktreeStates: Map<UUID, PersistedWorktreeSession | null> |
| 3517 | fileHistorySnapshots: Map<UUID, FileHistorySnapshotMessage> |
| 3518 | attributionSnapshots: Map<UUID, AttributionSnapshotMessage> |
| 3519 | contentReplacements: Map<UUID, ContentReplacementRecord[]> |
| 3520 | agentContentReplacements: Map<AgentId, ContentReplacementRecord[]> |
| 3521 | contextCollapseCommits: ContextCollapseCommitEntry[] |
| 3522 | contextCollapseSnapshot: ContextCollapseSnapshotEntry | undefined |
| 3523 | leafUuids: Set<UUID> |
| 3524 | }> { |
| 3525 | const messages = new Map<UUID, TranscriptMessage>() |
| 3526 | const summaries = new Map<UUID, string>() |
| 3527 | const customTitles = new Map<UUID, string>() |
| 3528 | const tags = new Map<UUID, string>() |
| 3529 | const agentNames = new Map<UUID, string>() |
| 3530 | const agentColors = new Map<UUID, string>() |
| 3531 | const agentSettings = new Map<UUID, string>() |
| 3532 | const prNumbers = new Map<UUID, number>() |
| 3533 | const prUrls = new Map<UUID, string>() |
| 3534 | const prRepositories = new Map<UUID, string>() |
| 3535 | const modes = new Map<UUID, string>() |
| 3536 | const worktreeStates = new Map<UUID, PersistedWorktreeSession | null>() |
| 3537 | const fileHistorySnapshots = new Map<UUID, FileHistorySnapshotMessage>() |
| 3538 | const attributionSnapshots = new Map<UUID, AttributionSnapshotMessage>() |
| 3539 | const contentReplacements = new Map<UUID, ContentReplacementRecord[]>() |
| 3540 | const agentContentReplacements = new Map< |
| 3541 | AgentId, |
| 3542 | ContentReplacementRecord[] |
| 3543 | >() |
| 3544 | // Array, not Map — commit order matters (nested collapses). |
| 3545 | const contextCollapseCommits: ContextCollapseCommitEntry[] = [] |
| 3546 | // Last-wins — later entries supersede. |
| 3547 | let contextCollapseSnapshot: ContextCollapseSnapshotEntry | undefined |
| 3548 | |
| 3549 | try { |
| 3550 | // For large transcripts, avoid materializing megabytes of stale content. |
| 3551 | // Single forward chunked read: attribution-snapshot lines are skipped at |
| 3552 | // the fd level (never buffered), compact boundaries truncate the |
| 3553 | // accumulator in-stream. Peak allocation is the OUTPUT size, not the |
| 3554 | // file size — a 151 MB session that is 84% stale attr-snaps allocates |
| 3555 | // ~32 MB instead of 159+64 MB. This matters because mimalloc does not |
| 3556 | // return those pages to the OS even after JS-level GC frees the backing |
| 3557 | // buffers (measured: arrayBuffers=0 after Bun.gc(true) but RSS stuck at |
| 3558 | // ~316 MB on the old scan+strip path vs ~155 MB here). |
no test coverage detected