Skip to content

Commit 2a08c7c

Browse files
author
Roo Code
committed
feat: Add toggle for custom mode creation
This commit adds a new setting to allow users to disable custom mode creation, which can help reduce token usage in Roo's prompts. Key changes: Add enableCustomModeCreation setting to global state Conditionally include custom modes documentation in prompt only when enabled Add UI toggle in PromptsView with explanatory text Default the setting to enabled (true) for backward compatibility Update necessary interfaces and message handlers for the new setting The setting is placed in PromptsView rather than SettingsView since it directly relates to the modes functionality managed in that component.
1 parent 10fca7b commit 2a08c7c

File tree

7 files changed

+65
-3
lines changed

7 files changed

+65
-3
lines changed

src/core/prompts/sections/modes.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@ export async function getModesSection(context: vscode.ExtensionContext): Promise
1111
// Get all modes with their overrides from extension state
1212
const allModes = await getAllModesWithPrompts(context)
1313

14-
return `====
14+
// Get enableCustomModeCreation setting from extension state
15+
const enableCustomModeCreation = await context.globalState.get<boolean>("enableCustomModeCreation")
16+
// Default to true if undefined
17+
const shouldEnableCustomModeCreation = enableCustomModeCreation !== undefined ? enableCustomModeCreation : true
18+
19+
let modesContent = `====
1520
1621
MODES
1722
1823
- These are the currently available modes:
19-
${allModes.map((mode: ModeConfig) => ` * "${mode.name}" mode (${mode.slug}) - ${mode.roleDefinition.split(".")[0]}`).join("\n")}
24+
${allModes.map((mode: ModeConfig) => ` * "${mode.name}" mode (${mode.slug}) - ${mode.roleDefinition.split(".")[0]}`).join("\n")}`
25+
26+
// Only include custom modes documentation if the feature is enabled
27+
if (shouldEnableCustomModeCreation) {
28+
modesContent += `
2029
2130
- Custom modes can be configured in two ways:
2231
1. Globally via '${customModesPath}' (created automatically on startup)
@@ -56,4 +65,7 @@ Both files should follow this structure:
5665
}
5766
]
5867
}`
68+
}
69+
70+
return modesContent
5971
}

src/core/webview/ClineProvider.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,10 @@ export class ClineProvider implements vscode.WebviewViewProvider {
14761476
await this.updateGlobalState("enhancementApiConfigId", message.text)
14771477
await this.postStateToWebview()
14781478
break
1479+
case "enableCustomModeCreation":
1480+
await this.updateGlobalState("enableCustomModeCreation", message.bool ?? true)
1481+
await this.postStateToWebview()
1482+
break
14791483
case "autoApprovalEnabled":
14801484
await this.updateGlobalState("autoApprovalEnabled", message.bool ?? false)
14811485
await this.postStateToWebview()

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export interface ExtensionState {
128128
terminalOutputLimit?: number
129129
mcpEnabled: boolean
130130
enableMcpServerCreation: boolean
131+
enableCustomModeCreation?: boolean
131132
mode: Mode
132133
modeApiConfigs?: Record<Mode, string>
133134
enhancementApiConfigId?: string

src/shared/WebviewMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export interface WebviewMessage {
7171
| "terminalOutputLimit"
7272
| "mcpEnabled"
7373
| "enableMcpServerCreation"
74+
| "enableCustomModeCreation"
7475
| "searchCommits"
7576
| "alwaysApproveResubmit"
7677
| "requestDelaySeconds"

src/shared/globalState.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export const GLOBAL_STATE_KEYS = [
8484
"enhancementApiConfigId",
8585
"experiments", // Map of experiment IDs to their enabled state
8686
"autoApprovalEnabled",
87+
"enableCustomModeCreation", // Enable the ability to create custom modes
8788
"customModes", // Array of custom modes
8889
"unboundModelId",
8990
"requestyModelId",

webview-ui/src/components/prompts/PromptsView.tsx

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
7171
preferredLanguage,
7272
setPreferredLanguage,
7373
customModes,
74+
enableCustomModeCreation,
75+
setEnableCustomModeCreation,
7476
} = useExtensionState()
7577

7678
// Memoize modes to preserve array order
@@ -341,6 +343,17 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
341343
return () => document.removeEventListener("click", handleClickOutside)
342344
}, [showConfigMenu])
343345

346+
// Add effect to sync enableCustomModeCreation with backend
347+
useEffect(() => {
348+
if (enableCustomModeCreation !== undefined) {
349+
// Send the value to the extension's global state
350+
vscode.postMessage({
351+
type: "enableCustomModeCreation", // Using dedicated message type
352+
bool: enableCustomModeCreation,
353+
})
354+
}
355+
}, [enableCustomModeCreation])
356+
344357
useEffect(() => {
345358
const handler = (event: MessageEvent) => {
346359
const message = event.data
@@ -541,8 +554,33 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
541554
in your workspace.
542555
</div>
543556
</div>
544-
545557
<div className="mt-5">
558+
{/*
559+
NOTE: This setting is placed in PromptsView rather than SettingsView since it
560+
directly affects the functionality related to modes and custom mode creation,
561+
which are managed in this component. This is an intentional deviation from
562+
the standard pattern described in cline_docs/settings.md.
563+
*/}
564+
<div style={{ marginBottom: 15 }}>
565+
<VSCodeCheckbox
566+
checked={enableCustomModeCreation || false}
567+
onChange={(e: any) => {
568+
// Just update the local state through React context
569+
// The React context will update the global state
570+
setEnableCustomModeCreation(e.target.checked)
571+
}}>
572+
<span style={{ fontWeight: "500" }}>Enable Custom Mode Creation</span>
573+
</VSCodeCheckbox>
574+
<p
575+
style={{
576+
fontSize: "12px",
577+
marginTop: "5px",
578+
color: "var(--vscode-descriptionForeground)",
579+
}}>
580+
When enabled, Roo can help you create project-level custom modes. You can disable this to
581+
reduce Roo's token usage.
582+
</p>
583+
</div>
546584
<div onClick={(e) => e.stopPropagation()} className="flex justify-between items-center mb-3">
547585
<h3 className="text-vscode-foreground m-0">Modes</h3>
548586
<div className="flex gap-2">

webview-ui/src/context/ExtensionStateContext.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export interface ExtensionStateContextType extends ExtensionState {
5252
setMcpEnabled: (value: boolean) => void
5353
enableMcpServerCreation: boolean
5454
setEnableMcpServerCreation: (value: boolean) => void
55+
enableCustomModeCreation?: boolean
56+
setEnableCustomModeCreation: (value: boolean) => void
5557
alwaysApproveResubmit?: boolean
5658
setAlwaysApproveResubmit: (value: boolean) => void
5759
requestDelaySeconds: number
@@ -117,6 +119,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
117119
checkpointStorage: "task",
118120
fuzzyMatchThreshold: 1.0,
119121
preferredLanguage: "English",
122+
enableCustomModeCreation: true,
120123
writeDelayMs: 1000,
121124
browserViewportSize: "900x600",
122125
screenshotQuality: 75,
@@ -273,6 +276,8 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
273276
setCustomSupportPrompts: (value) => setState((prevState) => ({ ...prevState, customSupportPrompts: value })),
274277
setEnhancementApiConfigId: (value) =>
275278
setState((prevState) => ({ ...prevState, enhancementApiConfigId: value })),
279+
setEnableCustomModeCreation: (value) =>
280+
setState((prevState) => ({ ...prevState, enableCustomModeCreation: value })),
276281
setAutoApprovalEnabled: (value) => setState((prevState) => ({ ...prevState, autoApprovalEnabled: value })),
277282
setCustomModes: (value) => setState((prevState) => ({ ...prevState, customModes: value })),
278283
setMaxOpenTabsContext: (value) => setState((prevState) => ({ ...prevState, maxOpenTabsContext: value })),

0 commit comments

Comments
 (0)