Skip to content

Commit df46f60

Browse files
committed
Power steering
1 parent c4bc1c0 commit df46f60

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

src/core/Cline.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import { parseMentions } from "./mentions"
5454
import { AssistantMessageContent, parseAssistantMessage, ToolParamName, ToolUseName } from "./assistant-message"
5555
import { formatResponse } from "./prompts/responses"
5656
import { SYSTEM_PROMPT } from "./prompts/system"
57-
import { modes, defaultModeSlug, getModeBySlug } from "../shared/modes"
57+
import { modes, defaultModeSlug, getModeBySlug, getFullModeDetails } from "../shared/modes"
5858
import { truncateConversationIfNeeded } from "./sliding-window"
5959
import { ClineProvider, GlobalFileNames } from "./webview/ClineProvider"
6060
import { detectCodeOmission } from "../integrations/editor/detect-omission"
@@ -63,7 +63,7 @@ import { OpenRouterHandler } from "../api/providers/openrouter"
6363
import { McpHub } from "../services/mcp/McpHub"
6464
import crypto from "crypto"
6565
import { insertGroups } from "./diff/insert-groups"
66-
import { EXPERIMENT_IDS, experiments as Experiments } from "../shared/experiments"
66+
import { EXPERIMENT_IDS, experiments as Experiments, ExperimentId } from "../shared/experiments"
6767

6868
const cwd =
6969
vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) ?? path.join(os.homedir(), "Desktop") // may or may not exist but fs checking existence would immediately ask for permission which would be bad UX, need to come up with a better solution
@@ -3235,9 +3235,29 @@ export class Cline {
32353235
details += `\n\n# Current Context Size (Tokens)\n${contextTokens ? `${contextTokens.toLocaleString()} (${contextPercentage}%)` : "(Not available)"}`
32363236

32373237
// Add current mode and any mode-specific warnings
3238-
const { mode, customModes } = (await this.providerRef.deref()?.getState()) ?? {}
3238+
const {
3239+
mode,
3240+
customModes,
3241+
customModePrompts,
3242+
experiments = {} as Record<ExperimentId, boolean>,
3243+
customInstructions: globalCustomInstructions,
3244+
preferredLanguage,
3245+
} = (await this.providerRef.deref()?.getState()) ?? {}
32393246
const currentMode = mode ?? defaultModeSlug
3240-
details += `\n\n# Current Mode\n${currentMode}`
3247+
const modeDetails = await getFullModeDetails(currentMode, customModes, customModePrompts, {
3248+
cwd,
3249+
globalCustomInstructions,
3250+
preferredLanguage,
3251+
})
3252+
details += `\n\n# Current Mode\n`
3253+
details += `<slug>${currentMode}</slug>\n`
3254+
details += `<name>${modeDetails.name}</name>\n`
3255+
if (Experiments.isEnabled(experiments ?? {}, EXPERIMENT_IDS.POWER_STEERING)) {
3256+
details += `<role>${modeDetails.roleDefinition}</role>\n`
3257+
if (modeDetails.customInstructions) {
3258+
details += `<custom_instructions>${modeDetails.customInstructions}</custom_instructions>\n`
3259+
}
3260+
}
32413261

32423262
// Add warning if not in code mode
32433263
if (

src/shared/experiments.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const EXPERIMENT_IDS = {
22
DIFF_STRATEGY: "experimentalDiffStrategy",
33
SEARCH_AND_REPLACE: "search_and_replace",
44
INSERT_BLOCK: "insert_content",
5+
POWER_STEERING: "powerSteering",
56
} as const
67

78
export type ExperimentKey = keyof typeof EXPERIMENT_IDS
@@ -35,6 +36,12 @@ export const experimentConfigsMap: Record<ExperimentKey, ExperimentConfig> = {
3536
"Enable the experimental insert content tool, allowing Roo to insert content at specific line numbers without needing to create a diff.",
3637
enabled: false,
3738
},
39+
POWER_STEERING: {
40+
name: 'Use experimental "power steering" mode',
41+
description:
42+
"When enabled, Roo will remind the model about the details of its current mode definition more frequently. This will lead to stronger adherence to role definitions and custom instructions, but will use additional tokens.",
43+
enabled: false,
44+
},
3845
}
3946

4047
export const experimentDefault = Object.fromEntries(

src/shared/modes.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from "vscode"
22
import { TOOL_GROUPS, ToolGroup, ALWAYS_AVAILABLE_TOOLS } from "./tool-groups"
3+
import { addCustomInstructions } from "../core/prompts/sections/custom-instructions"
34

45
// Mode types
56
export type Mode = string
@@ -262,6 +263,46 @@ export async function getAllModesWithPrompts(context: vscode.ExtensionContext):
262263
}))
263264
}
264265

266+
// Helper function to get complete mode details with all overrides
267+
export async function getFullModeDetails(
268+
modeSlug: string,
269+
customModes?: ModeConfig[],
270+
customModePrompts?: CustomModePrompts,
271+
options?: {
272+
cwd?: string
273+
globalCustomInstructions?: string
274+
preferredLanguage?: string
275+
},
276+
): Promise<ModeConfig> {
277+
// First get the base mode config from custom modes or built-in modes
278+
const baseMode = getModeBySlug(modeSlug, customModes) || modes.find((m) => m.slug === modeSlug) || modes[0]
279+
280+
// Check for any prompt component overrides
281+
const promptComponent = customModePrompts?.[modeSlug]
282+
283+
// Get the base custom instructions
284+
const baseCustomInstructions = promptComponent?.customInstructions || baseMode.customInstructions || ""
285+
286+
// If we have cwd, load and combine all custom instructions
287+
let fullCustomInstructions = baseCustomInstructions
288+
if (options?.cwd) {
289+
fullCustomInstructions = await addCustomInstructions(
290+
baseCustomInstructions,
291+
options.globalCustomInstructions || "",
292+
options.cwd,
293+
modeSlug,
294+
{ preferredLanguage: options.preferredLanguage },
295+
)
296+
}
297+
298+
// Return mode with any overrides applied
299+
return {
300+
...baseMode,
301+
roleDefinition: promptComponent?.roleDefinition || baseMode.roleDefinition,
302+
customInstructions: fullCustomInstructions,
303+
}
304+
}
305+
265306
// Helper function to safely get role definition
266307
export function getRoleDefinition(modeSlug: string, customModes?: ModeConfig[]): string {
267308
const mode = getModeBySlug(modeSlug, customModes)

0 commit comments

Comments
 (0)