(
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>
},
)
| 4891 | } |
| 4892 | |
| 4893 | async function loadInitialMessages( |
| 4894 | setAppState: (f: (prev: AppState) => AppState) => void, |
| 4895 | options: { |
| 4896 | continue: boolean | undefined |
| 4897 | teleport: string | true | null | undefined |
| 4898 | resume: string | boolean | undefined |
| 4899 | resumeSessionAt: string | undefined |
| 4900 | forkSession: boolean | undefined |
| 4901 | outputFormat: string | undefined |
| 4902 | sessionStartHooksPromise?: ReturnType<typeof processSessionStartHooks> |
| 4903 | restoredWorkerState: Promise<SessionExternalMetadata | null> |
| 4904 | }, |
| 4905 | ): Promise<LoadInitialMessagesResult> { |
| 4906 | const persistSession = !isSessionPersistenceDisabled() |
| 4907 | // Handle continue in print mode |
| 4908 | if (options.continue) { |
| 4909 | try { |
| 4910 | logEvent('tengu_continue_print', {}) |
| 4911 | |
| 4912 | const result = await loadConversationForResume( |
| 4913 | undefined /* sessionId */, |
| 4914 | undefined /* file path */, |
| 4915 | ) |
| 4916 | if (result) { |
| 4917 | // Match coordinator mode to the resumed session's mode |
| 4918 | if (feature('COORDINATOR_MODE') && coordinatorModeModule) { |
| 4919 | const warning = coordinatorModeModule.matchSessionMode(result.mode) |
| 4920 | if (warning) { |
| 4921 | process.stderr.write(warning + '\n') |
| 4922 | // Refresh agent definitions to reflect the mode switch |
| 4923 | const { |
| 4924 | getAgentDefinitionsWithOverrides, |
| 4925 | getActiveAgentsFromList, |
| 4926 | } = |
| 4927 | // eslint-disable-next-line @typescript-eslint/no-require-imports |
| 4928 | require('../tools/AgentTool/loadAgentsDir.js') as typeof import('../tools/AgentTool/loadAgentsDir.js') |
| 4929 | getAgentDefinitionsWithOverrides.cache.clear?.() |
| 4930 | const freshAgentDefs = await getAgentDefinitionsWithOverrides( |
| 4931 | getCwd(), |
| 4932 | ) |
| 4933 | |
| 4934 | setAppState(prev => ({ |
| 4935 | ...prev, |
| 4936 | agentDefinitions: { |
| 4937 | ...freshAgentDefs, |
| 4938 | allAgents: freshAgentDefs.allAgents, |
| 4939 | activeAgents: getActiveAgentsFromList(freshAgentDefs.allAgents), |
| 4940 | }, |
| 4941 | })) |
| 4942 | } |
| 4943 | } |
| 4944 | |
| 4945 | // Reuse the resumed session's ID |
| 4946 | if (!options.forkSession) { |
| 4947 | if (result.sessionId) { |
| 4948 | switchSession( |
| 4949 | asSessionId(result.sessionId), |
| 4950 | result.fullPath ? dirname(result.fullPath) : null, |
no test coverage detected