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

Function loadConversationForResume

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

Source from the content-addressed store, hash-verified

457 * @returns Object containing the deserialized messages and the original log, or null if not found
458 */
459export async function loadConversationForResume(
460 source: string | LogOption | undefined,
461 sourceJsonlFile: string | undefined,
462): Promise<{
463 messages: Message[]
464 turnInterruptionState: TurnInterruptionState
465 fileHistorySnapshots?: FileHistorySnapshot[]
466 attributionSnapshots?: AttributionSnapshotMessage[]
467 contentReplacements?: ContentReplacementRecord[]
468 contextCollapseCommits?: ContextCollapseCommitEntry[]
469 contextCollapseSnapshot?: ContextCollapseSnapshotEntry
470 sessionId: UUID | undefined
471 // Session metadata for restoring agent context
472 agentName?: string
473 agentColor?: string
474 agentSetting?: string
475 customTitle?: string
476 tag?: string
477 mode?: 'coordinator' | 'normal'
478 worktreeSession?: PersistedWorktreeSession | null
479 prNumber?: number
480 prUrl?: string
481 prRepository?: string
482 // Full path to the session file (for cross-directory resume)
483 fullPath?: string
484} | null> {
485 try {
486 let log: LogOption | null = null
487 let messages: Message[] | null = null
488 let sessionId: UUID | undefined
489
490 if (source === undefined) {
491 // --continue: most recent session, skipping live --bg/daemon sessions
492 // that are actively writing their own transcript.
493 const logsPromise = loadMessageLogs()
494 let skip = new Set<string>()
495 if (feature('BG_SESSIONS')) {
496 try {
497 const { listAllLiveSessions } = await import('./udsClient.js')
498 const live = await listAllLiveSessions()
499 skip = new Set(
500 live.flatMap(s =>
501 s.kind && s.kind !== 'interactive' && s.sessionId
502 ? [s.sessionId]
503 : [],
504 ),
505 )
506 } catch {
507 // UDS unavailable — treat all sessions as continuable
508 }
509 }
510 const logs = await logsPromise
511 log =
512 logs.find(l => {
513 const id = getSessionIdFromLog(l)
514 return !id || !skip.has(id)
515 }) ?? null
516 } else if (sourceJsonlFile) {

Callers 3

runFunction · 0.85
onSelectFunction · 0.85
loadInitialMessagesFunction · 0.85

Calls 15

loadMessageLogsFunction · 0.85
featureFunction · 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