diff --git a/.changeset/tidy-camels-roll.md b/.changeset/tidy-camels-roll.md new file mode 100644 index 0000000000..610122f3c8 --- /dev/null +++ b/.changeset/tidy-camels-roll.md @@ -0,0 +1,5 @@ +--- +"roo-cline": patch +--- + +Add a switch_mode tool to allow Roo to propose switching modes diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 9e569babd4..bd3acf2d3b 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -1022,6 +1022,8 @@ export class Cline { return `[${block.name} for '${block.params.question}']` case "attempt_completion": return `[${block.name}]` + case "switch_mode": + return `[${block.name} to '${block.params.mode_slug}'${block.params.reason ? ` because: ${block.params.reason}` : ""}]` } } @@ -2014,6 +2016,74 @@ export class Cline { break } } + case "switch_mode": { + const mode_slug: string | undefined = block.params.mode_slug + const reason: string | undefined = block.params.reason + try { + if (block.partial) { + const partialMessage = JSON.stringify({ + tool: "switchMode", + mode: removeClosingTag("mode_slug", mode_slug), + reason: removeClosingTag("reason", reason), + }) + await this.ask("tool", partialMessage, block.partial).catch(() => {}) + break + } else { + if (!mode_slug) { + this.consecutiveMistakeCount++ + pushToolResult(await this.sayAndCreateMissingParamError("switch_mode", "mode_slug")) + break + } + this.consecutiveMistakeCount = 0 + + // Verify the mode exists + const targetMode = getModeBySlug( + mode_slug, + (await this.providerRef.deref()?.getState())?.customModes, + ) + if (!targetMode) { + pushToolResult(formatResponse.toolError(`Invalid mode: ${mode_slug}`)) + break + } + + // Check if already in requested mode + const currentMode = + (await this.providerRef.deref()?.getState())?.mode ?? defaultModeSlug + if (currentMode === mode_slug) { + pushToolResult(`Already in ${targetMode.name} mode.`) + break + } + + const completeMessage = JSON.stringify({ + tool: "switchMode", + mode: mode_slug, + reason, + }) + + const didApprove = await askApproval("tool", completeMessage) + if (!didApprove) { + break + } + + // Switch the mode + const provider = this.providerRef.deref() + if (provider) { + await provider.updateGlobalState("mode", mode_slug) + await provider.postStateToWebview() + } + pushToolResult( + `Successfully switched from ${getModeBySlug(currentMode)?.name ?? currentMode} mode to ${ + targetMode.name + } mode${reason ? ` because: ${reason}` : ""}.`, + ) + break + } + } catch (error) { + await handleError("switching mode", error) + break + } + } + case "attempt_completion": { /* this.consecutiveMistakeCount = 0 diff --git a/src/core/assistant-message/index.ts b/src/core/assistant-message/index.ts index 353e7b8d0a..56e5e6662d 100644 --- a/src/core/assistant-message/index.ts +++ b/src/core/assistant-message/index.ts @@ -21,6 +21,7 @@ export const toolUseNames = [ "access_mcp_resource", "ask_followup_question", "attempt_completion", + "switch_mode", ] as const // Converts array of tool call names into a union type ("execute_command" | "read_file" | ...) @@ -47,6 +48,8 @@ export const toolParamNames = [ "diff", "start_line", "end_line", + "mode_slug", + "reason", ] as const export type ToolParamName = (typeof toolParamNames)[number] @@ -114,3 +117,8 @@ export interface AttemptCompletionToolUse extends ToolUse { name: "attempt_completion" params: Partial, "result" | "command">> } + +export interface SwitchModeToolUse extends ToolUse { + name: "switch_mode" + params: Partial, "mode_slug" | "reason">> +} diff --git a/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap b/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap index 53f34cd6b0..8801e45d36 100644 --- a/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap +++ b/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap @@ -181,6 +181,23 @@ I've updated the CSS open index.html +## 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: +- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect") +- reason: (optional) The reason for switching modes +Usage: + +Mode slug here +Reason for switching here + + +Example: Requesting to switch to code mode + +code +Need to make code changes + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. @@ -469,6 +486,23 @@ I've updated the CSS open index.html +## 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: +- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect") +- reason: (optional) The reason for switching modes +Usage: + +Mode slug here +Reason for switching here + + +Example: Requesting to switch to code mode + +code +Need to make code changes + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. @@ -757,6 +791,23 @@ I've updated the CSS open index.html +## 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: +- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect") +- reason: (optional) The reason for switching modes +Usage: + +Mode slug here +Reason for switching here + + +Example: Requesting to switch to code mode + +code +Need to make code changes + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. @@ -1091,6 +1142,23 @@ I've updated the CSS open index.html +## 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: +- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect") +- reason: (optional) The reason for switching modes +Usage: + +Mode slug here +Reason for switching here + + +Example: Requesting to switch to code mode + +code +Need to make code changes + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. @@ -1431,6 +1499,23 @@ I've updated the CSS open index.html +## 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: +- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect") +- reason: (optional) The reason for switching modes +Usage: + +Mode slug here +Reason for switching here + + +Example: Requesting to switch to code mode + +code +Need to make code changes + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. @@ -2129,6 +2214,23 @@ I've updated the CSS open index.html +## 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: +- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect") +- reason: (optional) The reason for switching modes +Usage: + +Mode slug here +Reason for switching here + + +Example: Requesting to switch to code mode + +code +Need to make code changes + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. @@ -2480,6 +2582,23 @@ I've updated the CSS open index.html +## 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: +- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect") +- reason: (optional) The reason for switching modes +Usage: + +Mode slug here +Reason for switching here + + +Example: Requesting to switch to code mode + +code +Need to make code changes + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. @@ -2768,6 +2887,23 @@ I've updated the CSS open index.html +## 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: +- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect") +- reason: (optional) The reason for switching modes +Usage: + +Mode slug here +Reason for switching here + + +Example: Requesting to switch to code mode + +code +Need to make code changes + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. @@ -3099,6 +3235,23 @@ I've updated the CSS open index.html +## 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: +- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect") +- reason: (optional) The reason for switching modes +Usage: + +Mode slug here +Reason for switching here + + +Example: Requesting to switch to code mode + +code +Need to make code changes + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. @@ -3373,6 +3526,23 @@ I've updated the CSS open index.html +## 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: +- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect") +- reason: (optional) The reason for switching modes +Usage: + +Mode slug here +Reason for switching here + + +Example: Requesting to switch to code mode + +code +Need to make code changes + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. diff --git a/src/core/prompts/tools/index.ts b/src/core/prompts/tools/index.ts index ebff65d3a0..b704f4f206 100644 --- a/src/core/prompts/tools/index.ts +++ b/src/core/prompts/tools/index.ts @@ -9,6 +9,7 @@ import { getAskFollowupQuestionDescription } from "./ask-followup-question" import { getAttemptCompletionDescription } from "./attempt-completion" import { getUseMcpToolDescription } from "./use-mcp-tool" import { getAccessMcpResourceDescription } from "./access-mcp-resource" +import { getSwitchModeDescription } from "./switch-mode" import { DiffStrategy } from "../../diff/DiffStrategy" import { McpHub } from "../../../services/mcp/McpHub" import { Mode, ModeConfig, getModeConfig, isToolAllowedForMode, getGroupName } from "../../../shared/modes" @@ -28,6 +29,7 @@ const toolDescriptionMap: Record string | undefined> attempt_completion: () => getAttemptCompletionDescription(), use_mcp_tool: (args) => getUseMcpToolDescription(args), access_mcp_resource: (args) => getAccessMcpResourceDescription(args), + switch_mode: () => getSwitchModeDescription(), apply_diff: (args) => args.diffStrategy ? args.diffStrategy.getToolDescription({ cwd: args.cwd, toolOptions: args.toolOptions }) : "", } @@ -97,4 +99,5 @@ export { getAttemptCompletionDescription, getUseMcpToolDescription, getAccessMcpResourceDescription, + getSwitchModeDescription, } diff --git a/src/core/prompts/tools/switch-mode.ts b/src/core/prompts/tools/switch-mode.ts new file mode 100644 index 0000000000..a8c64d1e10 --- /dev/null +++ b/src/core/prompts/tools/switch-mode.ts @@ -0,0 +1,18 @@ +export function getSwitchModeDescription(): string { + return `## 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: +- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect") +- reason: (optional) The reason for switching modes +Usage: + +Mode slug here +Reason for switching here + + +Example: Requesting to switch to code mode + +code +Need to make code changes +` +} diff --git a/src/shared/ExtensionMessage.ts b/src/shared/ExtensionMessage.ts index ed5d78c04f..88724e6f77 100644 --- a/src/shared/ExtensionMessage.ts +++ b/src/shared/ExtensionMessage.ts @@ -166,11 +166,14 @@ export interface ClineSayTool { | "listFilesRecursive" | "listCodeDefinitionNames" | "searchFiles" + | "switchMode" path?: string diff?: string content?: string regex?: string filePattern?: string + mode?: string + reason?: string } // must keep in sync with system prompt diff --git a/src/shared/tool-groups.ts b/src/shared/tool-groups.ts index 306db69120..96c9f03951 100644 --- a/src/shared/tool-groups.ts +++ b/src/shared/tool-groups.ts @@ -15,6 +15,7 @@ export const TOOL_DISPLAY_NAMES = { access_mcp_resource: "access mcp resources", ask_followup_question: "ask questions", attempt_completion: "complete tasks", + switch_mode: "switch modes", } as const // Define available tool groups @@ -29,7 +30,7 @@ export const TOOL_GROUPS: Record = { export type ToolGroup = keyof typeof TOOL_GROUPS // Tools that are always available to all modes -export const ALWAYS_AVAILABLE_TOOLS = ["ask_followup_question", "attempt_completion"] as const +export const ALWAYS_AVAILABLE_TOOLS = ["ask_followup_question", "attempt_completion", "switch_mode"] as const // Tool name types for type safety export type ToolName = keyof typeof TOOL_DISPLAY_NAMES diff --git a/webview-ui/src/components/chat/ChatRow.tsx b/webview-ui/src/components/chat/ChatRow.tsx index 74a677289e..27579479fd 100644 --- a/webview-ui/src/components/chat/ChatRow.tsx +++ b/webview-ui/src/components/chat/ChatRow.tsx @@ -443,6 +443,27 @@ export const ChatRowContent = ({ // // // ) + case "switchMode": + return ( + <> +
+ {toolIcon("symbol-enum")} + + {message.type === "ask" ? ( + <> + Roo wants to switch to {tool.mode} mode + {tool.reason ? ` because: ${tool.reason}` : ""} + + ) : ( + <> + Roo switched to {tool.mode} mode + {tool.reason ? ` because: ${tool.reason}` : ""} + + )} + +
+ + ) default: return null }