MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / getLastSessionLog

Function getLastSessionLog

source code/utils/sessionStorage.ts:3871–3934  ·  view source on GitHub ↗
(
  sessionId: UUID,
)

Source from the content-addressed store, hash-verified

3869}
3870
3871export async function getLastSessionLog(
3872 sessionId: UUID,
3873): Promise<LogOption | null> {
3874 // Single read: load all session data at once instead of reading the file twice
3875 const {
3876 messages,
3877 summaries,
3878 customTitles,
3879 tags,
3880 agentSettings,
3881 worktreeStates,
3882 fileHistorySnapshots,
3883 attributionSnapshots,
3884 contentReplacements,
3885 contextCollapseCommits,
3886 contextCollapseSnapshot,
3887 } = await loadSessionFile(sessionId)
3888 if (messages.size === 0) return null
3889 // Prime getSessionMessages cache so recordTranscript (called after REPL
3890 // mount on --resume) skips a second full file load. -170~227ms on large sessions.
3891 // Guard: only prime if cache is empty. Mid-session callers (e.g. IssueFeedback)
3892 // may call getLastSessionLog on the current session — overwriting a live cache
3893 // with a stale disk snapshot would lose unflushed UUIDs and break dedup.
3894 if (!getSessionMessages.cache.has(sessionId)) {
3895 getSessionMessages.cache.set(
3896 sessionId,
3897 Promise.resolve(new Set(messages.keys())),
3898 )
3899 }
3900
3901 // Find the most recent non-sidechain message
3902 const lastMessage = findLatestMessage(messages.values(), m => !m.isSidechain)
3903 if (!lastMessage) return null
3904
3905 // Build the transcript chain from the last message
3906 const transcript = buildConversationChain(messages, lastMessage)
3907
3908 const summary = summaries.get(lastMessage.uuid)
3909 const customTitle = customTitles.get(lastMessage.sessionId as UUID)
3910 const tag = tags.get(lastMessage.sessionId as UUID)
3911 const agentSetting = agentSettings.get(sessionId)
3912 return {
3913 ...convertToLogOption(
3914 transcript,
3915 0,
3916 summary,
3917 customTitle,
3918 buildFileHistorySnapshotChain(fileHistorySnapshots, transcript),
3919 tag,
3920 getTranscriptPathForSession(sessionId),
3921 buildAttributionSnapshotChain(attributionSnapshots, transcript),
3922 agentSetting,
3923 contentReplacements.get(sessionId) ?? [],
3924 ),
3925 worktreeSession: worktreeStates.get(sessionId),
3926 contextCollapseCommits: contextCollapseCommits.filter(
3927 e => e.sessionId === sessionId,
3928 ),

Callers 2

callFunction · 0.85

Calls 12

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

Tested by

no test coverage detected