MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / loadAllLogsFromSessionFile

Function loadAllLogsFromSessionFile

src/utils/sessionStorage.ts:4713–4809  ·  view source on GitHub ↗
(
  sessionFile: string,
  projectPathOverride?: string,
)

Source from the content-addressed store, hash-verified

4711 * Builds a LogOption for each leaf message in the file.
4712 */
4713export async function loadAllLogsFromSessionFile(
4714 sessionFile: string,
4715 projectPathOverride?: string,
4716): Promise<LogOption[]> {
4717 const {
4718 messages,
4719 summaries,
4720 customTitles,
4721 tags,
4722 agentNames,
4723 agentColors,
4724 agentSettings,
4725 prNumbers,
4726 prUrls,
4727 prRepositories,
4728 modes,
4729 fileHistorySnapshots,
4730 attributionSnapshots,
4731 contentReplacements,
4732 leafUuids,
4733 } = await loadTranscriptFile(sessionFile, { keepAllLeaves: true })
4734
4735 if (messages.size === 0) return []
4736
4737 const leafMessages: TranscriptMessage[] = []
4738 // Build parentUuid → children index once (O(n)), so trailing-message lookup is O(1) per leaf
4739 const childrenByParent = new Map<UUID, TranscriptMessage[]>()
4740 for (const msg of messages.values()) {
4741 if (leafUuids.has(msg.uuid)) {
4742 leafMessages.push(msg)
4743 } else if (msg.parentUuid) {
4744 const siblings = childrenByParent.get(msg.parentUuid)
4745 if (siblings) {
4746 siblings.push(msg)
4747 } else {
4748 childrenByParent.set(msg.parentUuid, [msg])
4749 }
4750 }
4751 }
4752
4753 const logs: LogOption[] = []
4754
4755 for (const leafMessage of leafMessages) {
4756 const chain = buildConversationChain(messages, leafMessage)
4757 if (chain.length === 0) continue
4758
4759 // Append trailing messages that are children of the leaf
4760 const trailingMessages = childrenByParent.get(leafMessage.uuid)
4761 if (trailingMessages) {
4762 // ISO-8601 UTC timestamps are lexically sortable
4763 trailingMessages.sort((a, b) =>
4764 a.timestamp < b.timestamp ? -1 : a.timestamp > b.timestamp ? 1 : 0,
4765 )
4766 chain.push(...trailingMessages)
4767 }
4768
4769 const firstMessage = chain[0]!
4770 const sessionId = leafMessage.sessionId as UUID

Callers 2

getLogsWithoutIndexFunction · 0.85
generateUsageReportFunction · 0.85

Calls 11

loadTranscriptFileFunction · 0.85
buildConversationChainFunction · 0.85
removeExtraFieldsFunction · 0.85
countVisibleMessagesFunction · 0.85
setMethod · 0.80
extractFirstPromptFunction · 0.70
getMethod · 0.65
hasMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected