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

Function loadConversationForResume

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

Source from the content-addressed store, hash-verified

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

Callers 3

runFunction · 0.85
onSelectFunction · 0.85
loadInitialMessagesFunction · 0.85

Calls 15

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