( sessionFile: string, projectPathOverride?: string, )
| 4597 | * Builds a LogOption for each leaf message in the file. |
| 4598 | */ |
| 4599 | export async function loadAllLogsFromSessionFile( |
| 4600 | sessionFile: string, |
| 4601 | projectPathOverride?: string, |
| 4602 | ): Promise<LogOption[]> { |
| 4603 | const { |
| 4604 | messages, |
| 4605 | summaries, |
| 4606 | customTitles, |
| 4607 | tags, |
| 4608 | agentNames, |
| 4609 | agentColors, |
| 4610 | agentSettings, |
| 4611 | prNumbers, |
| 4612 | prUrls, |
| 4613 | prRepositories, |
| 4614 | modes, |
| 4615 | fileHistorySnapshots, |
| 4616 | attributionSnapshots, |
| 4617 | contentReplacements, |
| 4618 | leafUuids, |
| 4619 | } = await loadTranscriptFile(sessionFile, { keepAllLeaves: true }) |
| 4620 | |
| 4621 | if (messages.size === 0) return [] |
| 4622 | |
| 4623 | const leafMessages: TranscriptMessage[] = [] |
| 4624 | // Build parentUuid → children index once (O(n)), so trailing-message lookup is O(1) per leaf |
| 4625 | const childrenByParent = new Map<UUID, TranscriptMessage[]>() |
| 4626 | for (const msg of messages.values()) { |
| 4627 | if (leafUuids.has(msg.uuid)) { |
| 4628 | leafMessages.push(msg) |
| 4629 | } else if (msg.parentUuid) { |
| 4630 | const siblings = childrenByParent.get(msg.parentUuid) |
| 4631 | if (siblings) { |
| 4632 | siblings.push(msg) |
| 4633 | } else { |
| 4634 | childrenByParent.set(msg.parentUuid, [msg]) |
| 4635 | } |
| 4636 | } |
| 4637 | } |
| 4638 | |
| 4639 | const logs: LogOption[] = [] |
| 4640 | |
| 4641 | for (const leafMessage of leafMessages) { |
| 4642 | const chain = buildConversationChain(messages, leafMessage) |
| 4643 | if (chain.length === 0) continue |
| 4644 | |
| 4645 | // Append trailing messages that are children of the leaf |
| 4646 | const trailingMessages = childrenByParent.get(leafMessage.uuid) |
| 4647 | if (trailingMessages) { |
| 4648 | // ISO-8601 UTC timestamps are lexically sortable |
| 4649 | trailingMessages.sort((a, b) => |
| 4650 | a.timestamp < b.timestamp ? -1 : a.timestamp > b.timestamp ? 1 : 0, |
| 4651 | ) |
| 4652 | chain.push(...trailingMessages) |
| 4653 | } |
| 4654 | |
| 4655 | const firstMessage = chain[0]! |
| 4656 | const sessionId = leafMessage.sessionId as UUID |
no test coverage detected