({
tools,
commands,
mcpClients,
messages,
readFileState,
getAppState,
setAppState,
customSystemPrompt,
appendSystemPrompt,
thinkingConfig,
agents,
}: {
tools: Tools
commands: Command[]
mcpClients: MCPServerConnection[]
messages: Message[]
readFileState: FileStateCache
getAppState: () => AppState
setAppState: (f: (prev: AppState) => AppState) => void
customSystemPrompt: string | undefined
appendSystemPrompt: string | undefined
thinkingConfig: ThinkingConfig | undefined
agents: AgentDefinition[]
})
| 86 | * the alternative is returning null and failing the side question entirely. |
| 87 | */ |
| 88 | export async function buildSideQuestionFallbackParams({ |
| 89 | tools, |
| 90 | commands, |
| 91 | mcpClients, |
| 92 | messages, |
| 93 | readFileState, |
| 94 | getAppState, |
| 95 | setAppState, |
| 96 | customSystemPrompt, |
| 97 | appendSystemPrompt, |
| 98 | thinkingConfig, |
| 99 | agents, |
| 100 | }: { |
| 101 | tools: Tools |
| 102 | commands: Command[] |
| 103 | mcpClients: MCPServerConnection[] |
| 104 | messages: Message[] |
| 105 | readFileState: FileStateCache |
| 106 | getAppState: () => AppState |
| 107 | setAppState: (f: (prev: AppState) => AppState) => void |
| 108 | customSystemPrompt: string | undefined |
| 109 | appendSystemPrompt: string | undefined |
| 110 | thinkingConfig: ThinkingConfig | undefined |
| 111 | agents: AgentDefinition[] |
| 112 | }): Promise<CacheSafeParams> { |
| 113 | const mainLoopModel = getMainLoopModel() |
| 114 | const appState = getAppState() |
| 115 | |
| 116 | const { defaultSystemPrompt, userContext, systemContext } = |
| 117 | await fetchSystemPromptParts({ |
| 118 | tools, |
| 119 | mainLoopModel, |
| 120 | additionalWorkingDirectories: Array.from( |
| 121 | appState.toolPermissionContext.additionalWorkingDirectories.keys(), |
| 122 | ), |
| 123 | mcpClients, |
| 124 | customSystemPrompt, |
| 125 | }) |
| 126 | |
| 127 | const systemPrompt = asSystemPrompt([ |
| 128 | ...(customSystemPrompt !== undefined |
| 129 | ? [customSystemPrompt] |
| 130 | : defaultSystemPrompt), |
| 131 | ...(appendSystemPrompt ? [appendSystemPrompt] : []), |
| 132 | ]) |
| 133 | |
| 134 | // Strip in-progress assistant message (stop_reason === null) — same guard |
| 135 | // as btw.tsx. The SDK can fire side_question mid-turn. |
| 136 | const last = messages.at(-1) |
| 137 | const forkContextMessages = |
| 138 | last?.type === 'assistant' && last.message!.stop_reason === null |
| 139 | ? messages.slice(0, -1) |
| 140 | : messages |
| 141 | |
| 142 | const toolUseContext: ToolUseContext = { |
| 143 | options: { |
| 144 | commands, |
| 145 | debug: false, |
no test coverage detected