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

Function getLastSessionLog

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

Source from the content-addressed store, hash-verified

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

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