MCPcopy
hub / github.com/claude-code-best/claude-code / loadConversationForResume

Function loadConversationForResume

src/utils/conversationRecovery.ts:485–630  ·  view source on GitHub ↗
(
  source: string | LogOption | undefined,
  sourceJsonlFile: string | undefined,
)

Source from the content-addressed store, hash-verified

483 * @returns Object containing the deserialized messages and the original log, or null if not found
484 */
485export async function loadConversationForResume(
486 source: string | LogOption | undefined,
487 sourceJsonlFile: string | undefined,
488): Promise<{
489 messages: Message[]
490 turnInterruptionState: TurnInterruptionState
491 fileHistorySnapshots?: FileHistorySnapshot[]
492 attributionSnapshots?: AttributionSnapshotMessage[]
493 contentReplacements?: ContentReplacementRecord[]
494 contextCollapseCommits?: ContextCollapseCommitEntry[]
495 contextCollapseSnapshot?: ContextCollapseSnapshotEntry
496 sessionId: UUID | undefined
497 // Session metadata for restoring agent context
498 agentName?: string
499 agentColor?: string
500 agentSetting?: string
501 customTitle?: string
502 tag?: string
503 mode?: 'coordinator' | 'normal'
504 worktreeSession?: PersistedWorktreeSession | null
505 prNumber?: number
506 prUrl?: string
507 prRepository?: string
508 // Full path to the session file (for cross-directory resume)
509 fullPath?: string
510 // Goal state for hydration on resume
511 goal?: import('../types/logs.js').GoalState
512} | null> {
513 try {
514 let log: LogOption | null = null
515 let messages: Message[] | null = null
516 let sessionId: UUID | undefined
517
518 if (source === undefined) {
519 // --continue: most recent session, skipping live --bg/daemon sessions
520 // that are actively writing their own transcript.
521 const logsPromise = loadMessageLogs()
522 let skip = new Set<string>()
523 if (feature('BG_SESSIONS')) {
524 try {
525 const { listAllLiveSessions } = await import('./udsClient.js')
526 const live = await listAllLiveSessions()
527 skip = new Set(
528 live.flatMap(s =>
529 s.kind && s.kind !== 'interactive' && s.sessionId
530 ? [s.sessionId]
531 : [],
532 ),
533 )
534 } catch {
535 // UDS unavailable — treat all sessions as continuable
536 }
537 }
538 const logs = await logsPromise
539 log =
540 logs.find(l => {
541 const id = getSessionIdFromLog(l)
542 return !id || !skip.has(id)

Callers 3

runFunction · 0.85
onSelectFunction · 0.85
loadInitialMessagesFunction · 0.85

Calls 15

loadMessageLogsFunction · 0.85
listAllLiveSessionsFunction · 0.85
getSessionIdFromLogFunction · 0.85
getLastSessionLogFunction · 0.85
isLiteLogFunction · 0.85
loadFullLogFunction · 0.85
copyPlanForResumeFunction · 0.85
asSessionIdFunction · 0.85
copyFileHistoryForResumeFunction · 0.85
checkResumeConsistencyFunction · 0.85

Tested by

no test coverage detected