MCPcopy Create free account
hub / github.com/Noumena-Network/code / loadAllLogsFromSessionFile

Function loadAllLogsFromSessionFile

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

Source from the content-addressed store, hash-verified

4864 * Builds a LogOption for each leaf message in the file.
4865 */
4866export async function loadAllLogsFromSessionFile(
4867 sessionFile: string,
4868 projectPathOverride?: string,
4869): Promise<LogOption[]> {
4870 const {
4871 messages,
4872 summaries,
4873 customTitles,
4874 tags,
4875 agentNames,
4876 agentColors,
4877 agentSettings,
4878 prNumbers,
4879 prUrls,
4880 prRepositories,
4881 modes,
4882 fileHistorySnapshots,
4883 attributionSnapshots,
4884 contentReplacements,
4885 leafUuids,
4886 } = await loadTranscriptFile(sessionFile, { keepAllLeaves: true })
4887
4888 if (messages.size === 0) return []
4889
4890 const leafMessages: TranscriptMessage[] = []
4891 // Build parentUuid → children index once (O(n)), so trailing-message lookup is O(1) per leaf
4892 const childrenByParent = new Map<UUID, TranscriptMessage[]>()
4893 for (const msg of messages.values()) {
4894 if (leafUuids.has(msg.uuid)) {
4895 leafMessages.push(msg)
4896 } else if (msg.parentUuid) {
4897 const siblings = childrenByParent.get(msg.parentUuid)
4898 if (siblings) {
4899 siblings.push(msg)
4900 } else {
4901 childrenByParent.set(msg.parentUuid, [msg])
4902 }
4903 }
4904 }
4905
4906 const logs: LogOption[] = []
4907
4908 for (const leafMessage of leafMessages) {
4909 const chain = buildConversationChain(messages, leafMessage, {
4910 includeLogicalParents: true,
4911 })
4912 if (chain.length === 0) continue
4913
4914 // Append trailing messages that are children of the leaf
4915 const trailingMessages = childrenByParent.get(leafMessage.uuid)
4916 if (trailingMessages) {
4917 // ISO-8601 UTC timestamps are lexically sortable
4918 trailingMessages.sort((a, b) =>
4919 a.timestamp < b.timestamp ? -1 : a.timestamp > b.timestamp ? 1 : 0,
4920 )
4921 chain.push(...trailingMessages)
4922 }
4923

Callers 3

getLogsWithoutIndexFunction · 0.85
generateUsageReportFunction · 0.85

Calls 10

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

Tested by

no test coverage detected