(
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>
},
)
| 5129 | } |
| 5130 | |
| 5131 | async function loadInitialMessages( |
| 5132 | setAppState: (f: (prev: AppState) => AppState) => void, |
| 5133 | options: { |
| 5134 | continue: boolean | undefined |
| 5135 | teleport: string | true | null | undefined |
| 5136 | resume: string | boolean | undefined |
| 5137 | resumeSessionAt: string | undefined |
| 5138 | forkSession: boolean | undefined |
| 5139 | outputFormat: string | undefined |
| 5140 | sessionStartHooksPromise?: ReturnType<typeof processSessionStartHooks> |
| 5141 | restoredWorkerState: Promise<SessionExternalMetadata | null> |
| 5142 | }, |
| 5143 | ): Promise<LoadInitialMessagesResult> { |
| 5144 | const persistSession = !isSessionPersistenceDisabled() |
| 5145 | // Handle continue in print mode |
| 5146 | if (options.continue) { |
| 5147 | try { |
| 5148 | logEvent('tengu_continue_print', {}) |
| 5149 | |
| 5150 | const result = await loadConversationForResume( |
| 5151 | undefined /* sessionId */, |
| 5152 | undefined /* file path */, |
| 5153 | ) |
| 5154 | if (result) { |
| 5155 | // Match coordinator mode to the resumed session's mode |
| 5156 | if (feature('COORDINATOR_MODE') && coordinatorModeModule) { |
| 5157 | const warning = coordinatorModeModule.matchSessionMode(result.mode) |
| 5158 | if (warning) { |
| 5159 | process.stderr.write(warning + '\n') |
| 5160 | // Refresh agent definitions to reflect the mode switch |
| 5161 | const { |
| 5162 | getAgentDefinitionsWithOverrides, |
| 5163 | getActiveAgentsFromList, |
| 5164 | } = |
| 5165 | // eslint-disable-next-line @typescript-eslint/no-require-imports |
| 5166 | require('@claude-code-best/builtin-tools/tools/AgentTool/loadAgentsDir.js') as typeof import('@claude-code-best/builtin-tools/tools/AgentTool/loadAgentsDir.js') |
| 5167 | getAgentDefinitionsWithOverrides.cache.clear?.() |
| 5168 | const freshAgentDefs = await getAgentDefinitionsWithOverrides( |
| 5169 | getCwd(), |
| 5170 | ) |
| 5171 | |
| 5172 | setAppState(prev => ({ |
| 5173 | ...prev, |
| 5174 | agentDefinitions: { |
| 5175 | ...freshAgentDefs, |
| 5176 | allAgents: freshAgentDefs.allAgents, |
| 5177 | activeAgents: getActiveAgentsFromList(freshAgentDefs.allAgents), |
| 5178 | }, |
| 5179 | })) |
| 5180 | } |
| 5181 | } |
| 5182 | |
| 5183 | // Reuse the resumed session's ID |
| 5184 | if (!options.forkSession) { |
| 5185 | if (result.sessionId) { |
| 5186 | switchSession( |
| 5187 | asSessionId(result.sessionId), |
| 5188 | result.fullPath ? dirname(result.fullPath) : null, |
no test coverage detected