Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tidy-camels-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"roo-cline": patch
---

Add a switch_mode tool to allow Roo to propose switching modes
70 changes: 70 additions & 0 deletions src/core/Cline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}` : ""}]`
}
}

Expand Down Expand Up @@ -2006,6 +2008,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
Expand Down
8 changes: 8 additions & 0 deletions src/core/assistant-message/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" | ...)
Expand All @@ -47,6 +48,8 @@ export const toolParamNames = [
"diff",
"start_line",
"end_line",
"mode_slug",
"reason",
] as const

export type ToolParamName = (typeof toolParamNames)[number]
Expand Down Expand Up @@ -114,3 +117,8 @@ export interface AttemptCompletionToolUse extends ToolUse {
name: "attempt_completion"
params: Partial<Pick<Record<ToolParamName, string>, "result" | "command">>
}

export interface SwitchModeToolUse extends ToolUse {
name: "switch_mode"
params: Partial<Pick<Record<ToolParamName, string>, "mode_slug" | "reason">>
}
170 changes: 170 additions & 0 deletions src/core/prompts/__tests__/__snapshots__/system.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,23 @@ I've updated the CSS
<command>open index.html</command>
</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:
- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect")
- reason: (optional) The reason for switching modes
Usage:
<switch_mode>
<mode_slug>Mode slug here</mode_slug>
<reason>Reason for switching here</reason>
</switch_mode>

Example: Requesting to switch to code mode
<switch_mode>
<mode_slug>code</mode_slug>
<reason>Need to make code changes</reason>
</switch_mode>

# Tool Use Guidelines

1. In <thinking> tags, assess what information you already have and what information you need to proceed with the task.
Expand Down Expand Up @@ -466,6 +483,23 @@ I've updated the CSS
<command>open index.html</command>
</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:
- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect")
- reason: (optional) The reason for switching modes
Usage:
<switch_mode>
<mode_slug>Mode slug here</mode_slug>
<reason>Reason for switching here</reason>
</switch_mode>

Example: Requesting to switch to code mode
<switch_mode>
<mode_slug>code</mode_slug>
<reason>Need to make code changes</reason>
</switch_mode>

# Tool Use Guidelines

1. In <thinking> tags, assess what information you already have and what information you need to proceed with the task.
Expand Down Expand Up @@ -751,6 +785,23 @@ I've updated the CSS
<command>open index.html</command>
</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:
- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect")
- reason: (optional) The reason for switching modes
Usage:
<switch_mode>
<mode_slug>Mode slug here</mode_slug>
<reason>Reason for switching here</reason>
</switch_mode>

Example: Requesting to switch to code mode
<switch_mode>
<mode_slug>code</mode_slug>
<reason>Need to make code changes</reason>
</switch_mode>

# Tool Use Guidelines

1. In <thinking> tags, assess what information you already have and what information you need to proceed with the task.
Expand Down Expand Up @@ -1082,6 +1133,23 @@ I've updated the CSS
<command>open index.html</command>
</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:
- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect")
- reason: (optional) The reason for switching modes
Usage:
<switch_mode>
<mode_slug>Mode slug here</mode_slug>
<reason>Reason for switching here</reason>
</switch_mode>

Example: Requesting to switch to code mode
<switch_mode>
<mode_slug>code</mode_slug>
<reason>Need to make code changes</reason>
</switch_mode>

# Tool Use Guidelines

1. In <thinking> tags, assess what information you already have and what information you need to proceed with the task.
Expand Down Expand Up @@ -1419,6 +1487,23 @@ I've updated the CSS
<command>open index.html</command>
</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:
- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect")
- reason: (optional) The reason for switching modes
Usage:
<switch_mode>
<mode_slug>Mode slug here</mode_slug>
<reason>Reason for switching here</reason>
</switch_mode>

Example: Requesting to switch to code mode
<switch_mode>
<mode_slug>code</mode_slug>
<reason>Need to make code changes</reason>
</switch_mode>

# Tool Use Guidelines

1. In <thinking> tags, assess what information you already have and what information you need to proceed with the task.
Expand Down Expand Up @@ -2114,6 +2199,23 @@ I've updated the CSS
<command>open index.html</command>
</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:
- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect")
- reason: (optional) The reason for switching modes
Usage:
<switch_mode>
<mode_slug>Mode slug here</mode_slug>
<reason>Reason for switching here</reason>
</switch_mode>

Example: Requesting to switch to code mode
<switch_mode>
<mode_slug>code</mode_slug>
<reason>Need to make code changes</reason>
</switch_mode>

# Tool Use Guidelines

1. In <thinking> tags, assess what information you already have and what information you need to proceed with the task.
Expand Down Expand Up @@ -2462,6 +2564,23 @@ I've updated the CSS
<command>open index.html</command>
</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:
- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect")
- reason: (optional) The reason for switching modes
Usage:
<switch_mode>
<mode_slug>Mode slug here</mode_slug>
<reason>Reason for switching here</reason>
</switch_mode>

Example: Requesting to switch to code mode
<switch_mode>
<mode_slug>code</mode_slug>
<reason>Need to make code changes</reason>
</switch_mode>

# Tool Use Guidelines

1. In <thinking> tags, assess what information you already have and what information you need to proceed with the task.
Expand Down Expand Up @@ -2747,6 +2866,23 @@ I've updated the CSS
<command>open index.html</command>
</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:
- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect")
- reason: (optional) The reason for switching modes
Usage:
<switch_mode>
<mode_slug>Mode slug here</mode_slug>
<reason>Reason for switching here</reason>
</switch_mode>

Example: Requesting to switch to code mode
<switch_mode>
<mode_slug>code</mode_slug>
<reason>Need to make code changes</reason>
</switch_mode>

# Tool Use Guidelines

1. In <thinking> tags, assess what information you already have and what information you need to proceed with the task.
Expand Down Expand Up @@ -3038,6 +3174,23 @@ I've updated the CSS
<command>open index.html</command>
</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:
- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect")
- reason: (optional) The reason for switching modes
Usage:
<switch_mode>
<mode_slug>Mode slug here</mode_slug>
<reason>Reason for switching here</reason>
</switch_mode>

Example: Requesting to switch to code mode
<switch_mode>
<mode_slug>code</mode_slug>
<reason>Need to make code changes</reason>
</switch_mode>

# Tool Use Guidelines

1. In <thinking> tags, assess what information you already have and what information you need to proceed with the task.
Expand Down Expand Up @@ -3272,6 +3425,23 @@ I've updated the CSS
<command>open index.html</command>
</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:
- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect")
- reason: (optional) The reason for switching modes
Usage:
<switch_mode>
<mode_slug>Mode slug here</mode_slug>
<reason>Reason for switching here</reason>
</switch_mode>

Example: Requesting to switch to code mode
<switch_mode>
<mode_slug>code</mode_slug>
<reason>Need to make code changes</reason>
</switch_mode>

# Tool Use Guidelines

1. In <thinking> tags, assess what information you already have and what information you need to proceed with the task.
Expand Down
3 changes: 3 additions & 0 deletions src/core/prompts/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } from "../../../shared/modes"
Expand All @@ -28,6 +29,7 @@ const toolDescriptionMap: Record<string, (args: ToolArgs) => 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 }) : "",
}
Expand Down Expand Up @@ -93,4 +95,5 @@ export {
getAttemptCompletionDescription,
getUseMcpToolDescription,
getAccessMcpResourceDescription,
getSwitchModeDescription,
}
18 changes: 18 additions & 0 deletions src/core/prompts/tools/switch-mode.ts
Original file line number Diff line number Diff line change
@@ -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:
<switch_mode>
<mode_slug>Mode slug here</mode_slug>
<reason>Reason for switching here</reason>
</switch_mode>

Example: Requesting to switch to code mode
<switch_mode>
<mode_slug>code</mode_slug>
<reason>Need to make code changes</reason>
</switch_mode>`
}
Loading
Loading