MCPcopy
hub / github.com/kodu-ai/claude-coder / executeRequest

Method executeRequest

extension/src/api/api-handler.ts:125–213  ·  view source on GitHub ↗
({ shouldResetContext }: { shouldResetContext: boolean })

Source from the content-addressed store, hash-verified

123 await this.pullLatestApi()
124
125 const executeRequest = async ({ shouldResetContext }: { shouldResetContext: boolean }) => {
126 let conversationHistory =
127 apiConversationHistory ??
128 (await provider.koduDev?.getStateManager().apiHistoryManager.getSavedApiConversationHistory())
129
130 let baseSystem = [await this.getCurrentPrompts()]
131 if (customSystemPrompt?.systemPrompt) {
132 if (Array.isArray(customSystemPrompt.systemPrompt)) {
133 baseSystem = customSystemPrompt.systemPrompt
134 } else {
135 baseSystem = [customSystemPrompt.systemPrompt]
136 }
137 }
138 if (this.getModelId() === "claude-3-7-sonnet-20250219") {
139 const globalStateManager = GlobalStateManager.getInstance()
140 const thinking = globalStateManager.getGlobalState("thinking")
141 // we are going to add more critical instructions to the system prompt
142 if (thinking?.type === "enabled") {
143 baseSystem.push(`<critical_instructions>
144 In every message output you should document your current step, finalized reasoning and thoughts, your next steps, and any other relevant information.
145 This must be present in every message and should be concise and to the point.
146 You don't need to write <thinking> tags. instead you should write <thinking_summary> and <execution_plan> tags in every message.
147 so format every response as following:
148 <thinking_summary>
149 A summary of your current thoughts, reasoning, and next steps.
150 </thinking_summary>
151 <execution_plan>
152 Your plan of execution, what you are going to do next, and how you are going to do it.
153 </execution_plan>
154 <kodu_action>...the best tool call for this step...</kodu_action>
155 </critical_instructions>`)
156 }
157 }
158
159 let criticalMsg: string | undefined = mainPrompts.criticalMsg
160 if (customSystemPrompt) {
161 criticalMsg = customSystemPrompt.automaticReminders
162 }
163 // we want to replace {{task}} with the current task if it exists in the critical message
164 if (criticalMsg) {
165 const firstRequest = conversationHistory.at(0)?.content
166 const firstRequestTextBlock = Array.isArray(firstRequest)
167 ? firstRequest.find(isTextBlock)?.text
168 : firstRequest
169 if (firstRequestTextBlock && criticalMsg.includes("{{task}}")) {
170 criticalMsg = criticalMsg.replace("{{task}}", this.getTaskText(firstRequestTextBlock))
171 }
172 }
173 if (shouldResetContext) {
174 // Compress the context and retry
175 const result = await manageContextWindow(provider.koduDev!, this.api, (s, msg, ...args) =>
176 this.log(s, msg, ...args)
177 )
178 if (result === "chat_finished") {
179 throw new KoduError({ code: 413 })
180 }
181 }
182 // Process conversation history using our external utility

Callers

nothing calls this directly

Calls 12

getCurrentPromptsMethod · 0.95
getModelIdMethod · 0.95
getTaskTextMethod · 0.95
logMethod · 0.95
manageContextWindowFunction · 0.90
getGlobalStateMethod · 0.80
createMessageStreamMethod · 0.65
getStateManagerMethod · 0.45
getInstanceMethod · 0.45

Tested by

no test coverage detected