MCPcopy Create free account
hub / github.com/Noumena-Network/code / loadConversationForResume

Function loadConversationForResume

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

Source from the content-addressed store, hash-verified

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

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