( sessionFile: string, projectPathOverride?: string, )
| 4642 | * Builds a LogOption for each leaf message in the file. |
| 4643 | */ |
| 4644 | export async function loadAllLogsFromSessionFile( |
| 4645 | sessionFile: string, |
| 4646 | projectPathOverride?: string, |
| 4647 | ): Promise<LogOption[]> { |
| 4648 | const { |
| 4649 | messages, |
| 4650 | summaries, |
| 4651 | customTitles, |
| 4652 | tags, |
| 4653 | agentNames, |
| 4654 | agentColors, |
| 4655 | agentSettings, |
| 4656 | prNumbers, |
| 4657 | prUrls, |
| 4658 | prRepositories, |
| 4659 | modes, |
| 4660 | fileHistorySnapshots, |
| 4661 | attributionSnapshots, |
| 4662 | contentReplacements, |
| 4663 | leafUuids, |
| 4664 | } = await loadTranscriptFile(sessionFile, { keepAllLeaves: true }) |
| 4665 | |
| 4666 | if (messages.size === 0) return [] |
| 4667 | |
| 4668 | const leafMessages: TranscriptMessage[] = [] |
| 4669 | // Build parentUuid → children index once (O(n)), so trailing-message lookup is O(1) per leaf |
| 4670 | const childrenByParent = new Map<UUID, TranscriptMessage[]>() |
| 4671 | for (const msg of messages.values()) { |
| 4672 | if (leafUuids.has(msg.uuid)) { |
| 4673 | leafMessages.push(msg) |
| 4674 | } else if (msg.parentUuid) { |
| 4675 | const siblings = childrenByParent.get(msg.parentUuid) |
| 4676 | if (siblings) { |
| 4677 | siblings.push(msg) |
| 4678 | } else { |
| 4679 | childrenByParent.set(msg.parentUuid, [msg]) |
| 4680 | } |
| 4681 | } |
| 4682 | } |
| 4683 | |
| 4684 | const logs: LogOption[] = [] |
| 4685 | |
| 4686 | for (const leafMessage of leafMessages) { |
| 4687 | const chain = buildConversationChain(messages, leafMessage) |
| 4688 | if (chain.length === 0) continue |
| 4689 | |
| 4690 | // Append trailing messages that are children of the leaf |
| 4691 | const trailingMessages = childrenByParent.get(leafMessage.uuid) |
| 4692 | if (trailingMessages) { |
| 4693 | // ISO-8601 UTC timestamps are lexically sortable |
| 4694 | trailingMessages.sort((a, b) => |
| 4695 | a.timestamp < b.timestamp ? -1 : a.timestamp > b.timestamp ? 1 : 0, |
| 4696 | ) |
| 4697 | chain.push(...trailingMessages) |
| 4698 | } |
| 4699 | |
| 4700 | const firstMessage = chain[0]! |
| 4701 | const sessionId = leafMessage.sessionId as UUID |
no test coverage detected