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

Function loadAllLogsFromSessionFile

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

Source from the content-addressed store, hash-verified

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

Callers 2

getLogsWithoutIndexFunction · 0.85
generateUsageReportFunction · 0.85

Calls 12

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

Tested by

no test coverage detected