feat: make attempt_completion tool conditional based on task context

- Add isOrchestrated flag to Task class to track subtask context
- Always include attempt_completion for orchestrated subtasks
- Make attempt_completion optional for standard tasks via allowAttemptCompletion setting
- Default behavior excludes attempt_completion for standard tasks
- Add comprehensive tests for conditional inclusion logic
- Update UI components to expose the new setting
- Update snapshots to reflect new default behavior

Fixes #7529
This commit is contained in:
Roo Code 2025-08-29 14:55:44 +00:00
parent 1d46bd1bbc
commit 263d260e74
26 changed files with 339 additions and 249 deletions

View file

@ -62,6 +62,7 @@ export const globalSettingsSchema = z.object({
alwaysAllowFollowupQuestions: z.boolean().optional(),
followupAutoApproveTimeoutMs: z.number().optional(),
alwaysAllowUpdateTodoList: z.boolean().optional(),
allowAttemptCompletion: z.boolean().optional(),
allowedCommands: z.array(z.string()).optional(),
deniedCommands: z.array(z.string()).optional(),
commandExecutionTimeout: z.number().optional(),

View file

@ -288,25 +288,6 @@ Example:
</follow_up>
</ask_followup_question>
## attempt_completion
Description: After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.
IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in <thinking></thinking> tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool.
Parameters:
- result: (required) The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.
Usage:
<attempt_completion>
<result>
Your final result description here
</result>
</attempt_completion>
Example: Requesting to attempt completion with a result
<attempt_completion>
<result>
I've updated the CSS
</result>
</attempt_completion>
## switch_mode
Description: Request to switch to a different mode. This tool allows modes to request switching to another mode when needed, such as switching to Code mode to make code changes. The user must approve the mode switch.
Parameters:

View file

@ -185,25 +185,6 @@ Example:
</follow_up>
</ask_followup_question>
## attempt_completion
Description: After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.
IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in <thinking></thinking> tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool.
Parameters:
- result: (required) The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.
Usage:
<attempt_completion>
<result>
Your final result description here
</result>
</attempt_completion>
Example: Requesting to attempt completion with a result
<attempt_completion>
<result>
I've updated the CSS
</result>
</attempt_completion>
## switch_mode
Description: Request to switch to a different mode. This tool allows modes to request switching to another mode when needed, such as switching to Code mode to make code changes. The user must approve the mode switch.
Parameters:

View file

@ -287,25 +287,6 @@ Example:
</follow_up>
</ask_followup_question>
## attempt_completion
Description: After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.
IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in <thinking></thinking> tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool.
Parameters:
- result: (required) The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.
Usage:
<attempt_completion>
<result>
Your final result description here
</result>
</attempt_completion>
Example: Requesting to attempt completion with a result
<attempt_completion>
<result>
I've updated the CSS
</result>
</attempt_completion>
## switch_mode
Description: Request to switch to a different mode. This tool allows modes to request switching to another mode when needed, such as switching to Code mode to make code changes. The user must approve the mode switch.
Parameters:

View file

@ -337,25 +337,6 @@ Example:
</follow_up>
</ask_followup_question>
## attempt_completion
Description: After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.
IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in <thinking></thinking> tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool.
Parameters:
- result: (required) The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.
Usage:
<attempt_completion>
<result>
Your final result description here
</result>
</attempt_completion>
Example: Requesting to attempt completion with a result
<attempt_completion>
<result>
I've updated the CSS
</result>
</attempt_completion>
## switch_mode
Description: Request to switch to a different mode. This tool allows modes to request switching to another mode when needed, such as switching to Code mode to make code changes. The user must approve the mode switch.
Parameters:

View file

@ -293,25 +293,6 @@ Example:
</follow_up>
</ask_followup_question>
## attempt_completion
Description: After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.
IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in <thinking></thinking> tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool.
Parameters:
- result: (required) The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.
Usage:
<attempt_completion>
<result>
Your final result description here
</result>
</attempt_completion>
Example: Requesting to attempt completion with a result
<attempt_completion>
<result>
I've updated the CSS
</result>
</attempt_completion>
## switch_mode
Description: Request to switch to a different mode. This tool allows modes to request switching to another mode when needed, such as switching to Code mode to make code changes. The user must approve the mode switch.
Parameters:

View file

@ -288,25 +288,6 @@ Example:
</follow_up>
</ask_followup_question>
## attempt_completion
Description: After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.
IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in <thinking></thinking> tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool.
Parameters:
- result: (required) The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.
Usage:
<attempt_completion>
<result>
Your final result description here
</result>
</attempt_completion>
Example: Requesting to attempt completion with a result
<attempt_completion>
<result>
I've updated the CSS
</result>
</attempt_completion>
## switch_mode
Description: Request to switch to a different mode. This tool allows modes to request switching to another mode when needed, such as switching to Code mode to make code changes. The user must approve the mode switch.
Parameters:

View file

@ -341,25 +341,6 @@ Example:
</follow_up>
</ask_followup_question>
## attempt_completion
Description: After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.
IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in <thinking></thinking> tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool.
Parameters:
- result: (required) The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.
Usage:
<attempt_completion>
<result>
Your final result description here
</result>
</attempt_completion>
Example: Requesting to attempt completion with a result
<attempt_completion>
<result>
I've updated the CSS
</result>
</attempt_completion>
## switch_mode
Description: Request to switch to a different mode. This tool allows modes to request switching to another mode when needed, such as switching to Code mode to make code changes. The user must approve the mode switch.
Parameters:

View file

@ -288,25 +288,6 @@ Example:
</follow_up>
</ask_followup_question>
## attempt_completion
Description: After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.
IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in <thinking></thinking> tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool.
Parameters:
- result: (required) The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.
Usage:
<attempt_completion>
<result>
Your final result description here
</result>
</attempt_completion>
Example: Requesting to attempt completion with a result
<attempt_completion>
<result>
I've updated the CSS
</result>
</attempt_completion>
## switch_mode
Description: Request to switch to a different mode. This tool allows modes to request switching to another mode when needed, such as switching to Code mode to make code changes. The user must approve the mode switch.
Parameters:

View file

@ -376,25 +376,6 @@ Example:
</follow_up>
</ask_followup_question>
## attempt_completion
Description: After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.
IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in <thinking></thinking> tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool.
Parameters:
- result: (required) The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.
Usage:
<attempt_completion>
<result>
Your final result description here
</result>
</attempt_completion>
Example: Requesting to attempt completion with a result
<attempt_completion>
<result>
I've updated the CSS
</result>
</attempt_completion>
## switch_mode
Description: Request to switch to a different mode. This tool allows modes to request switching to another mode when needed, such as switching to Code mode to make code changes. The user must approve the mode switch.
Parameters:

View file

@ -288,25 +288,6 @@ Example:
</follow_up>
</ask_followup_question>
## attempt_completion
Description: After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.
IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in <thinking></thinking> tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool.
Parameters:
- result: (required) The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.
Usage:
<attempt_completion>
<result>
Your final result description here
</result>
</attempt_completion>
Example: Requesting to attempt completion with a result
<attempt_completion>
<result>
I've updated the CSS
</result>
</attempt_completion>
## switch_mode
Description: Request to switch to a different mode. This tool allows modes to request switching to another mode when needed, such as switching to Code mode to make code changes. The user must approve the mode switch.
Parameters:

View file

@ -341,25 +341,6 @@ Example:
</follow_up>
</ask_followup_question>
## attempt_completion
Description: After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.
IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in <thinking></thinking> tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool.
Parameters:
- result: (required) The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.
Usage:
<attempt_completion>
<result>
Your final result description here
</result>
</attempt_completion>
Example: Requesting to attempt completion with a result
<attempt_completion>
<result>
I've updated the CSS
</result>
</attempt_completion>
## switch_mode
Description: Request to switch to a different mode. This tool allows modes to request switching to another mode when needed, such as switching to Code mode to make code changes. The user must approve the mode switch.
Parameters:

View file

@ -337,25 +337,6 @@ Example:
</follow_up>
</ask_followup_question>
## attempt_completion
Description: After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.
IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in <thinking></thinking> tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool.
Parameters:
- result: (required) The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.
Usage:
<attempt_completion>
<result>
Your final result description here
</result>
</attempt_completion>
Example: Requesting to attempt completion with a result
<attempt_completion>
<result>
I've updated the CSS
</result>
</attempt_completion>
## switch_mode
Description: Request to switch to a different mode. This tool allows modes to request switching to another mode when needed, such as switching to Code mode to make code changes. The user must approve the mode switch.
Parameters:

View file

@ -288,25 +288,6 @@ Example:
</follow_up>
</ask_followup_question>
## attempt_completion
Description: After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.
IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in <thinking></thinking> tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool.
Parameters:
- result: (required) The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.
Usage:
<attempt_completion>
<result>
Your final result description here
</result>
</attempt_completion>
Example: Requesting to attempt completion with a result
<attempt_completion>
<result>
I've updated the CSS
</result>
</attempt_completion>
## switch_mode
Description: Request to switch to a different mode. This tool allows modes to request switching to another mode when needed, such as switching to Code mode to make code changes. The user must approve the mode switch.
Parameters:

View file

@ -62,6 +62,7 @@ async function generatePrompt(
settings?: SystemPromptSettings,
todoList?: TodoItem[],
modelId?: string,
isOrchestrated?: boolean,
): Promise<string> {
if (!context) {
throw new Error("Extension context is required for generating system prompt")
@ -108,6 +109,7 @@ ${getToolDescriptionsForMode(
settings,
enableMcpServerCreation,
modelId,
isOrchestrated,
)}
${getToolUseGuidelinesSection(codeIndexManager)}
@ -153,6 +155,7 @@ export const SYSTEM_PROMPT = async (
settings?: SystemPromptSettings,
todoList?: TodoItem[],
modelId?: string,
isOrchestrated?: boolean,
): Promise<string> => {
if (!context) {
throw new Error("Extension context is required for generating system prompt")
@ -225,5 +228,6 @@ ${customInstructions}`
settings,
todoList,
modelId,
isOrchestrated,
)
}

View file

@ -0,0 +1,275 @@
import { getToolDescriptionsForMode } from "../index"
describe("attempt_completion conditional inclusion", () => {
const mockCwd = "/test/path"
const mockSupportsComputerUse = false
describe("for orchestrated tasks", () => {
it("should always include attempt_completion tool when isOrchestrated is true", () => {
const result = getToolDescriptionsForMode(
"code",
mockCwd,
mockSupportsComputerUse,
undefined, // codeIndexManager
undefined, // diffStrategy
undefined, // browserViewportSize
undefined, // mcpHub
undefined, // customModes
undefined, // experiments
undefined, // partialReadsEnabled
{ allowAttemptCompletion: false }, // settings with allowAttemptCompletion disabled
undefined, // enableMcpServerCreation
undefined, // modelId
true, // isOrchestrated = true
)
expect(result).toContain("## attempt_completion")
expect(result).toContain("After each tool use, the user will respond with the result")
})
it("should include attempt_completion even when allowAttemptCompletion is false", () => {
const result = getToolDescriptionsForMode(
"code",
mockCwd,
mockSupportsComputerUse,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
{ allowAttemptCompletion: false },
undefined,
undefined,
true, // isOrchestrated = true
)
expect(result).toContain("## attempt_completion")
})
it("should include attempt_completion even when allowAttemptCompletion is undefined", () => {
const result = getToolDescriptionsForMode(
"code",
mockCwd,
mockSupportsComputerUse,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
{}, // settings without allowAttemptCompletion
undefined,
undefined,
true, // isOrchestrated = true
)
expect(result).toContain("## attempt_completion")
})
})
describe("for standard (non-orchestrated) tasks", () => {
it("should exclude attempt_completion when isOrchestrated is false and allowAttemptCompletion is false", () => {
const result = getToolDescriptionsForMode(
"code",
mockCwd,
mockSupportsComputerUse,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
{ allowAttemptCompletion: false },
undefined,
undefined,
false, // isOrchestrated = false
)
expect(result).not.toContain("## attempt_completion")
expect(result).not.toContain("After each tool use, the user will respond with the result")
})
it("should exclude attempt_completion when isOrchestrated is undefined and allowAttemptCompletion is false", () => {
const result = getToolDescriptionsForMode(
"code",
mockCwd,
mockSupportsComputerUse,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
{ allowAttemptCompletion: false },
undefined,
undefined,
undefined, // isOrchestrated = undefined (defaults to false)
)
expect(result).not.toContain("## attempt_completion")
})
it("should exclude attempt_completion by default when allowAttemptCompletion is undefined", () => {
const result = getToolDescriptionsForMode(
"code",
mockCwd,
mockSupportsComputerUse,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
{}, // settings without allowAttemptCompletion
undefined,
undefined,
false, // isOrchestrated = false
)
expect(result).not.toContain("## attempt_completion")
})
it("should include attempt_completion when allowAttemptCompletion is explicitly true", () => {
const result = getToolDescriptionsForMode(
"code",
mockCwd,
mockSupportsComputerUse,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
{ allowAttemptCompletion: true }, // explicitly enabled
undefined,
undefined,
false, // isOrchestrated = false
)
expect(result).toContain("## attempt_completion")
expect(result).toContain("After each tool use, the user will respond with the result")
})
it("should include attempt_completion when isOrchestrated is undefined but allowAttemptCompletion is true", () => {
const result = getToolDescriptionsForMode(
"code",
mockCwd,
mockSupportsComputerUse,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
{ allowAttemptCompletion: true },
undefined,
undefined,
undefined, // isOrchestrated = undefined
)
expect(result).toContain("## attempt_completion")
})
})
describe("edge cases", () => {
it("should handle null settings gracefully", () => {
const result = getToolDescriptionsForMode(
"code",
mockCwd,
mockSupportsComputerUse,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
null as any, // null settings
undefined,
undefined,
false,
)
// Should exclude attempt_completion by default
expect(result).not.toContain("## attempt_completion")
})
it("should handle undefined settings gracefully", () => {
const result = getToolDescriptionsForMode(
"code",
mockCwd,
mockSupportsComputerUse,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined, // undefined settings
undefined,
undefined,
false,
)
// Should exclude attempt_completion by default
expect(result).not.toContain("## attempt_completion")
})
})
describe("interaction with different modes", () => {
const testModes = ["code", "architect", "ask", "debug"]
testModes.forEach((mode) => {
it(`should respect orchestration flag in ${mode} mode`, () => {
// Orchestrated task should include attempt_completion
const orchestratedResult = getToolDescriptionsForMode(
mode,
mockCwd,
mockSupportsComputerUse,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
{ allowAttemptCompletion: false },
undefined,
undefined,
true,
)
expect(orchestratedResult).toContain("## attempt_completion")
// Non-orchestrated task with setting disabled should exclude it
const standardResult = getToolDescriptionsForMode(
mode,
mockCwd,
mockSupportsComputerUse,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
{ allowAttemptCompletion: false },
undefined,
undefined,
false,
)
expect(standardResult).not.toContain("## attempt_completion")
})
})
})
})

View file

@ -74,6 +74,7 @@ export function getToolDescriptionsForMode(
settings?: Record<string, any>,
enableMcpServerCreation?: boolean,
modelId?: string,
isOrchestrated?: boolean,
): string {
const config = getModeConfig(mode, customModes)
const args: ToolArgs = {
@ -118,6 +119,13 @@ export function getToolDescriptionsForMode(
// Add always available tools
ALWAYS_AVAILABLE_TOOLS.forEach((tool) => tools.add(tool))
// Conditionally include attempt_completion based on task context
// For orchestrated subtasks, always include it
// For standard tasks, check user setting (default is to exclude)
if (!isOrchestrated && settings?.allowAttemptCompletion !== true) {
tools.delete("attempt_completion")
}
// Conditionally exclude codebase_search if feature is disabled or not configured
if (
!codeIndexManager ||

View file

@ -6,4 +6,5 @@ export interface SystemPromptSettings {
todoListEnabled: boolean
useAgentRules: boolean
newTaskRequireTodos: boolean
allowAttemptCompletion?: boolean
}

View file

@ -128,6 +128,7 @@ export type TaskOptions = {
taskNumber?: number
onCreated?: (task: Task) => void
initialTodos?: TodoItem[]
isOrchestrated?: boolean
}
export class Task extends EventEmitter<TaskEvents> implements TaskLike {
@ -141,6 +142,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
readonly parentTask: Task | undefined = undefined
readonly taskNumber: number
readonly workspacePath: string
readonly isOrchestrated: boolean
/**
* The mode associated with this task. Persisted across sessions
@ -291,6 +293,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
taskNumber = -1,
onCreated,
initialTodos,
isOrchestrated = false,
}: TaskOptions) {
super()
@ -312,6 +315,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
this.instanceId = crypto.randomUUID().slice(0, 8)
this.taskNumber = -1
this.isOrchestrated = isOrchestrated
this.rooIgnoreController = new RooIgnoreController(this.cwd)
this.rooProtectedController = new RooProtectedController(this.cwd)
@ -2225,6 +2229,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
maxConcurrentFileReads,
maxReadFileLine,
apiConfiguration,
allowAttemptCompletion,
} = state ?? {}
return await (async () => {
@ -2258,9 +2263,11 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
newTaskRequireTodos: vscode.workspace
.getConfiguration("roo-cline")
.get<boolean>("newTaskRequireTodos", false),
allowAttemptCompletion,
},
undefined, // todoList
this.api.getModel().id,
this.isOrchestrated,
)
})()
}

View file

@ -122,8 +122,10 @@ export async function newTaskTool(
cline.pausedModeSlug = (await provider.getState()).mode ?? defaultModeSlug
// Create new task instance first (this preserves parent's current mode in its history)
// Mark this as an orchestrated subtask so it will include attempt_completion tool
const newCline = await provider.createTask(unescapedMessage, undefined, cline, {
initialTodos: todoItems,
isOrchestrated: true,
})
if (!newCline) {
pushToolResult(t("tools:newTask.errors.policy_restriction"))

View file

@ -756,6 +756,7 @@ export class ClineProvider
| "consecutiveMistakeLimit"
| "experiments"
| "initialTodos"
| "isOrchestrated"
>
> = {},
) {
@ -790,6 +791,7 @@ export class ClineProvider
onCreated: this.taskCreationCallback,
enableBridge: BridgeOrchestrator.isEnabled(cloudUserInfo, remoteControlEnabled),
initialTodos: options.initialTodos,
isOrchestrated: options.isOrchestrated,
...options,
})
@ -1685,6 +1687,7 @@ export class ClineProvider
alwaysAllowWriteOutsideWorkspace,
alwaysAllowWriteProtected,
alwaysAllowExecute,
allowAttemptCompletion,
allowedCommands,
deniedCommands,
alwaysAllowBrowser,
@ -1784,6 +1787,7 @@ export class ClineProvider
alwaysAllowWriteOutsideWorkspace: alwaysAllowWriteOutsideWorkspace ?? false,
alwaysAllowWriteProtected: alwaysAllowWriteProtected ?? false,
alwaysAllowExecute: alwaysAllowExecute ?? false,
allowAttemptCompletion: allowAttemptCompletion ?? false,
alwaysAllowBrowser: alwaysAllowBrowser ?? false,
alwaysAllowMcp: alwaysAllowMcp ?? false,
alwaysAllowModeSwitch: alwaysAllowModeSwitch ?? false,
@ -1982,6 +1986,7 @@ export class ClineProvider
alwaysAllowWriteOutsideWorkspace: stateValues.alwaysAllowWriteOutsideWorkspace ?? false,
alwaysAllowWriteProtected: stateValues.alwaysAllowWriteProtected ?? false,
alwaysAllowExecute: stateValues.alwaysAllowExecute ?? false,
allowAttemptCompletion: stateValues.allowAttemptCompletion ?? false,
alwaysAllowBrowser: stateValues.alwaysAllowBrowser ?? false,
alwaysAllowMcp: stateValues.alwaysAllowMcp ?? false,
alwaysAllowModeSwitch: stateValues.alwaysAllowModeSwitch ?? false,

View file

@ -221,6 +221,7 @@ export type ExtensionState = Pick<
| "alwaysAllowSubtasks"
| "alwaysAllowExecute"
| "alwaysAllowUpdateTodoList"
| "allowAttemptCompletion"
| "allowedCommands"
| "deniedCommands"
| "allowedMaxRequests"

View file

@ -21,6 +21,7 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
autoApprovalEnabled,
setAutoApprovalEnabled,
alwaysApproveResubmit,
allowAttemptCompletion,
setAlwaysAllowReadOnly,
setAlwaysAllowWrite,
setAlwaysAllowExecute,
@ -31,19 +32,21 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
setAlwaysApproveResubmit,
setAlwaysAllowFollowupQuestions,
setAlwaysAllowUpdateTodoList,
setAllowAttemptCompletion,
} = useExtensionState()
const { t } = useAppTranslation()
const baseToggles = useAutoApprovalToggles()
// AutoApproveMenu needs alwaysApproveResubmit in addition to the base toggles
// AutoApproveMenu needs alwaysApproveResubmit and allowAttemptCompletion in addition to the base toggles
const toggles = useMemo(
() => ({
...baseToggles,
alwaysApproveResubmit: alwaysApproveResubmit,
allowAttemptCompletion: allowAttemptCompletion,
}),
[baseToggles, alwaysApproveResubmit],
[baseToggles, alwaysApproveResubmit, allowAttemptCompletion],
)
const { hasEnabledOptions, effectiveAutoApprovalEnabled } = useAutoApprovalState(toggles, autoApprovalEnabled)
@ -84,6 +87,9 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
case "alwaysAllowUpdateTodoList":
setAlwaysAllowUpdateTodoList(value)
break
case "allowAttemptCompletion":
setAllowAttemptCompletion(value)
break
}
// Check if we need to update the master auto-approval state
@ -119,6 +125,7 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
setAlwaysApproveResubmit,
setAlwaysAllowFollowupQuestions,
setAlwaysAllowUpdateTodoList,
setAllowAttemptCompletion,
setAutoApprovalEnabled,
],
)

View file

@ -16,6 +16,7 @@ type AutoApproveToggles = Pick<
| "alwaysAllowExecute"
| "alwaysAllowFollowupQuestions"
| "alwaysAllowUpdateTodoList"
| "allowAttemptCompletion"
>
export type AutoApproveSetting = keyof AutoApproveToggles
@ -99,6 +100,13 @@ export const autoApproveSettingsConfig: Record<AutoApproveSetting, AutoApproveCo
icon: "checklist",
testId: "always-allow-update-todo-list-toggle",
},
allowAttemptCompletion: {
key: "allowAttemptCompletion",
labelKey: "settings:autoApprove.attemptCompletion.label",
descriptionKey: "settings:autoApprove.attemptCompletion.description",
icon: "check",
testId: "allow-attempt-completion-toggle",
},
}
type AutoApproveToggleProps = AutoApproveToggles & {

View file

@ -145,6 +145,8 @@ export interface ExtensionStateContextType extends ExtensionState {
routerModels?: RouterModels
alwaysAllowUpdateTodoList?: boolean
setAlwaysAllowUpdateTodoList: (value: boolean) => void
allowAttemptCompletion?: boolean
setAllowAttemptCompletion: (value: boolean) => void
includeDiagnosticMessages?: boolean
setIncludeDiagnosticMessages: (value: boolean) => void
maxDiagnosticMessages?: number
@ -250,6 +252,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
},
codebaseIndexModels: { ollama: {}, openai: {} },
alwaysAllowUpdateTodoList: true,
allowAttemptCompletion: false,
includeDiagnosticMessages: true,
maxDiagnosticMessages: 50,
})
@ -304,6 +307,13 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
if ((newState as any).followupAutoApproveTimeoutMs !== undefined) {
setFollowupAutoApproveTimeoutMs((newState as any).followupAutoApproveTimeoutMs)
}
// Update allowAttemptCompletion if present in state message
if ((newState as any).allowAttemptCompletion !== undefined) {
setState((prevState) => ({
...prevState,
allowAttemptCompletion: (newState as any).allowAttemptCompletion,
}))
}
// Update includeTaskHistoryInEnhance if present in state message
if ((newState as any).includeTaskHistoryInEnhance !== undefined) {
setIncludeTaskHistoryInEnhance((newState as any).includeTaskHistoryInEnhance)
@ -514,6 +524,10 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
setAlwaysAllowUpdateTodoList: (value) => {
setState((prevState) => ({ ...prevState, alwaysAllowUpdateTodoList: value }))
},
allowAttemptCompletion: state.allowAttemptCompletion,
setAllowAttemptCompletion: (value) => {
setState((prevState) => ({ ...prevState, allowAttemptCompletion: value }))
},
includeDiagnosticMessages: state.includeDiagnosticMessages,
setIncludeDiagnosticMessages: (value) => {
setState((prevState) => ({ ...prevState, includeDiagnosticMessages: value }))

View file

@ -195,6 +195,10 @@
"label": "Todo",
"description": "Automatically update the to-do list without requiring approval"
},
"allowAttemptCompletion": {
"label": "Completion",
"description": "Allow Roo to use the attempt_completion tool to end tasks. When disabled, tasks continue until you manually stop them"
},
"apiRequestLimit": {
"title": "Max Count",
"unlimited": "Unlimited"