Make sure the agent knows about all available modes with the correct overrides

This commit is contained in:
Matt Rubens 2025-02-15 01:13:21 -05:00
parent ffec4c60d4
commit e66b0853b3
2 changed files with 20 additions and 4 deletions

View file

@ -1,20 +1,22 @@
import * as path from "path"
import * as vscode from "vscode"
import { promises as fs } from "fs"
import { modes, ModeConfig } from "../../../shared/modes"
import { ModeConfig, getAllModesWithPrompts } from "../../../shared/modes"
export async function getModesSection(context: vscode.ExtensionContext): Promise<string> {
const settingsDir = path.join(context.globalStorageUri.fsPath, "settings")
await fs.mkdir(settingsDir, { recursive: true })
const customModesPath = path.join(settingsDir, "cline_custom_modes.json")
// Get all modes with their overrides from extension state
const allModes = await getAllModesWithPrompts(context)
return `====
MODES
- When referring to modes, always use their display names. The built-in modes are:
${modes.map((mode: ModeConfig) => ` * "${mode.name}" mode - ${mode.roleDefinition.split(".")[0]}`).join("\n")}
Custom modes will be referred to by their configured name property.
- These are the currently available modes:
${allModes.map((mode: ModeConfig) => ` * "${mode.name}" mode (${mode.slug}) - ${mode.roleDefinition.split(".")[0]}`).join("\n")}
- Custom modes can be configured in two ways:
1. Globally via '${customModesPath}' (created automatically on startup)

View file

@ -1,3 +1,4 @@
import * as vscode from "vscode"
import { TOOL_GROUPS, ToolGroup, ALWAYS_AVAILABLE_TOOLS } from "./tool-groups"
// Mode types
@ -239,6 +240,19 @@ export const defaultPrompts: Readonly<CustomModePrompts> = Object.freeze(
),
)
// Helper function to get all modes with their prompt overrides from extension state
export async function getAllModesWithPrompts(context: vscode.ExtensionContext): Promise<ModeConfig[]> {
const customModes = (await context.globalState.get<ModeConfig[]>("customModes")) || []
const customModePrompts = (await context.globalState.get<CustomModePrompts>("customModePrompts")) || {}
const allModes = getAllModes(customModes)
return allModes.map((mode) => ({
...mode,
roleDefinition: customModePrompts[mode.slug]?.roleDefinition ?? mode.roleDefinition,
customInstructions: customModePrompts[mode.slug]?.customInstructions ?? mode.customInstructions,
}))
}
// Helper function to safely get role definition
export function getRoleDefinition(modeSlug: string, customModes?: ModeConfig[]): string {
const mode = getModeBySlug(modeSlug, customModes)