MCPcopy Create free account
hub / github.com/HELPMEEADICE/doge-code / getLastSessionLog

Function getLastSessionLog

src/utils/sessionStorage.ts:3915–3978  ·  view source on GitHub ↗
(
  sessionId: UUID,
)

Source from the content-addressed store, hash-verified

3913}
3914
3915export async function getLastSessionLog(
3916 sessionId: UUID,
3917): Promise<LogOption | null> {
3918 // Single read: load all session data at once instead of reading the file twice
3919 const {
3920 messages,
3921 summaries,
3922 customTitles,
3923 tags,
3924 agentSettings,
3925 worktreeStates,
3926 fileHistorySnapshots,
3927 attributionSnapshots,
3928 contentReplacements,
3929 contextCollapseCommits,
3930 contextCollapseSnapshot,
3931 } = await loadSessionFile(sessionId)
3932 if (messages.size === 0) return null
3933 // Prime getSessionMessages cache so recordTranscript (called after REPL
3934 // mount on --resume) skips a second full file load. -170~227ms on large sessions.
3935 // Guard: only prime if cache is empty. Mid-session callers (e.g. IssueFeedback)
3936 // may call getLastSessionLog on the current session — overwriting a live cache
3937 // with a stale disk snapshot would lose unflushed UUIDs and break dedup.
3938 if (!getSessionMessages.cache.has(sessionId)) {
3939 getSessionMessages.cache.set(
3940 sessionId,
3941 Promise.resolve(new Set(messages.keys())),
3942 )
3943 }
3944
3945 // Find the most recent non-sidechain message
3946 const lastMessage = findLatestMessage(messages.values(), m => !m.isSidechain)
3947 if (!lastMessage) return null
3948
3949 // Build the transcript chain from the last message
3950 const transcript = buildConversationChain(messages, lastMessage)
3951
3952 const summary = summaries.get(lastMessage.uuid)
3953 const customTitle = customTitles.get(lastMessage.sessionId as UUID)
3954 const tag = tags.get(lastMessage.sessionId as UUID)
3955 const agentSetting = agentSettings.get(sessionId)
3956 return {
3957 ...convertToLogOption(
3958 transcript,
3959 0,
3960 summary,
3961 customTitle,
3962 buildFileHistorySnapshotChain(fileHistorySnapshots, transcript),
3963 tag,
3964 getTranscriptPathForSession(sessionId),
3965 buildAttributionSnapshotChain(attributionSnapshots, transcript),
3966 agentSetting,
3967 contentReplacements.get(sessionId) ?? [],
3968 ),
3969 worktreeSession: worktreeStates.get(sessionId),
3970 contextCollapseCommits: contextCollapseCommits.filter(
3971 e => e.sessionId === sessionId,
3972 ),

Callers 2

callFunction · 0.85

Calls 12

loadSessionFileFunction · 0.85
findLatestMessageFunction · 0.85
buildConversationChainFunction · 0.85
convertToLogOptionFunction · 0.85
resolveMethod · 0.80
setMethod · 0.65
keysMethod · 0.65
getMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected