(
setAppState: (f: (prev: AppState) => AppState) => void,
options: {
continue: boolean | undefined
teleport: string | true | null | undefined
resume: string | boolean | undefined
resumeSessionAt: string | undefined
forkSession: boolean | undefined
outputFormat: string | undefined
sessionStartHooksPromise?: ReturnType<typeof processSessionStartHooks>
restoredWorkerState: Promise<SessionExternalMetadata | null>
},
)
| 4925 | } |
| 4926 | |
| 4927 | async function loadInitialMessages( |
| 4928 | setAppState: (f: (prev: AppState) => AppState) => void, |
| 4929 | options: { |
| 4930 | continue: boolean | undefined |
| 4931 | teleport: string | true | null | undefined |
| 4932 | resume: string | boolean | undefined |
| 4933 | resumeSessionAt: string | undefined |
| 4934 | forkSession: boolean | undefined |
| 4935 | outputFormat: string | undefined |
| 4936 | sessionStartHooksPromise?: ReturnType<typeof processSessionStartHooks> |
| 4937 | restoredWorkerState: Promise<SessionExternalMetadata | null> |
| 4938 | }, |
| 4939 | ): Promise<LoadInitialMessagesResult> { |
| 4940 | const persistSession = !isSessionPersistenceDisabled() |
| 4941 | // Handle continue in print mode |
| 4942 | if (options.continue) { |
| 4943 | try { |
| 4944 | logEvent('ncode_continue_print', {}) |
| 4945 | |
| 4946 | const result = await loadConversationForResume( |
| 4947 | undefined /* sessionId */, |
| 4948 | undefined /* file path */, |
| 4949 | ) |
| 4950 | if (result) { |
| 4951 | // Match coordinator mode to the resumed session's mode |
| 4952 | if (feature('COORDINATOR_MODE') && coordinatorModeModule) { |
| 4953 | const warning = coordinatorModeModule.matchSessionMode(result.mode) |
| 4954 | if (warning) { |
| 4955 | process.stderr.write(warning + '\n') |
| 4956 | // Refresh agent definitions to reflect the mode switch |
| 4957 | const { |
| 4958 | getAgentDefinitionsWithOverrides, |
| 4959 | getActiveAgentsFromList, |
| 4960 | } = |
| 4961 | // eslint-disable-next-line @typescript-eslint/no-require-imports |
| 4962 | require('../tools/AgentTool/loadAgentsDir.js') as typeof import('../tools/AgentTool/loadAgentsDir.js') |
| 4963 | getAgentDefinitionsWithOverrides.cache.clear?.() |
| 4964 | const freshAgentDefs = await getAgentDefinitionsWithOverrides( |
| 4965 | getCwd(), |
| 4966 | ) |
| 4967 | |
| 4968 | setAppState(prev => ({ |
| 4969 | ...prev, |
| 4970 | agentDefinitions: { |
| 4971 | ...freshAgentDefs, |
| 4972 | allAgents: freshAgentDefs.allAgents, |
| 4973 | activeAgents: getActiveAgentsFromList(freshAgentDefs.allAgents), |
| 4974 | }, |
| 4975 | })) |
| 4976 | } |
| 4977 | } |
| 4978 | |
| 4979 | // Reuse the resumed session's ID |
| 4980 | if (!options.forkSession) { |
| 4981 | if (result.sessionId) { |
| 4982 | switchSession( |
| 4983 | asSessionId(result.sessionId), |
| 4984 | result.fullPath ? dirname(result.fullPath) : null, |
no test coverage detected