Skip to content

Commit 6e92707

Browse files
committed
fix: auto-approval settings now properly apply during active tasks
- Modified askApproval function in presentAssistantMessage.ts to check auto-approval settings before asking user - Added logic to determine which auto-approval setting applies based on tool type - Handle file path checks for inside/outside workspace auto-approval variants - Fixed TypeScript errors by properly handling different ClineAsk types Fixes #8641
1 parent 6b8c21f commit 6e92707

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

src/core/assistant-message/presentAssistantMessage.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,89 @@ export async function presentAssistantMessage(cline: Task) {
279279
progressStatus?: ToolProgressStatus,
280280
isProtected?: boolean,
281281
) => {
282+
// Check auto-approval settings before asking user
283+
const state = await cline.providerRef.deref()?.getState()
284+
285+
// Check if we should auto-approve based on tool type and settings
286+
if (state) {
287+
let shouldAutoApprove = false
288+
289+
// Handle tool approval
290+
if (type === "tool" && partialMessage) {
291+
try {
292+
const toolInfo = JSON.parse(partialMessage)
293+
const toolName = toolInfo.tool || block.name
294+
295+
// Check for read-only file operations
296+
if (
297+
toolName === "readFile" ||
298+
toolName === "list_files" ||
299+
toolName === "search_files" ||
300+
toolName === "list_code_definition_names"
301+
) {
302+
if (toolInfo.isOutsideWorkspace) {
303+
shouldAutoApprove = state.alwaysAllowReadOnlyOutsideWorkspace ?? false
304+
} else {
305+
shouldAutoApprove = state.alwaysAllowReadOnly ?? false
306+
}
307+
}
308+
// Check for write file operations
309+
else if (
310+
toolName === "writeFile" ||
311+
toolName === "write_to_file" ||
312+
toolName === "apply_diff" ||
313+
toolName === "insert_content" ||
314+
toolName === "search_and_replace"
315+
) {
316+
if (isProtected) {
317+
shouldAutoApprove = state.alwaysAllowWriteProtected ?? false
318+
} else if (toolInfo.isOutsideWorkspace) {
319+
shouldAutoApprove = state.alwaysAllowWriteOutsideWorkspace ?? false
320+
} else {
321+
shouldAutoApprove = state.alwaysAllowWrite ?? false
322+
}
323+
}
324+
// Check for command execution
325+
else if (toolName === "execute_command") {
326+
shouldAutoApprove = state.alwaysAllowExecute ?? false
327+
}
328+
// Check for browser actions
329+
else if (toolName === "browser_action") {
330+
shouldAutoApprove = state.alwaysAllowBrowser ?? false
331+
}
332+
// Check for follow-up questions
333+
else if (toolName === "ask_followup_question") {
334+
shouldAutoApprove = state.alwaysAllowFollowupQuestions ?? false
335+
}
336+
// Check for todo list updates
337+
else if (toolName === "update_todo_list") {
338+
shouldAutoApprove = state.alwaysAllowUpdateTodoList ?? false
339+
}
340+
} catch (error) {
341+
// If parsing fails or any error occurs, fall through to normal approval flow
342+
console.debug("Error checking auto-approval settings for tool:", error)
343+
}
344+
}
345+
// Handle command approval
346+
else if (type === "command") {
347+
shouldAutoApprove = state.alwaysAllowExecute ?? false
348+
}
349+
// Handle browser action launch
350+
else if (type === "browser_action_launch") {
351+
shouldAutoApprove = state.alwaysAllowBrowser ?? false
352+
}
353+
// Handle MCP server usage
354+
else if (type === "use_mcp_server") {
355+
shouldAutoApprove = state.alwaysAllowMcp ?? false
356+
}
357+
358+
if (shouldAutoApprove) {
359+
// Auto-approve without asking user
360+
return true
361+
}
362+
}
363+
364+
// Normal approval flow - ask the user
282365
const { response, text, images } = await cline.ask(
283366
type,
284367
partialMessage,

0 commit comments

Comments
 (0)