From e66b0853b35997bc81f3e6ebc2a34bce6d55d2e4 Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Sat, 15 Feb 2025 01:13:21 -0500 Subject: [PATCH] Make sure the agent knows about all available modes with the correct overrides --- src/core/prompts/sections/modes.ts | 10 ++++++---- src/shared/modes.ts | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/core/prompts/sections/modes.ts b/src/core/prompts/sections/modes.ts index 8babe2d5a2..eff950c2c2 100644 --- a/src/core/prompts/sections/modes.ts +++ b/src/core/prompts/sections/modes.ts @@ -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 { 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) diff --git a/src/shared/modes.ts b/src/shared/modes.ts index 1bba7e87c8..72f7785f13 100644 --- a/src/shared/modes.ts +++ b/src/shared/modes.ts @@ -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 = Object.freeze( ), ) +// Helper function to get all modes with their prompt overrides from extension state +export async function getAllModesWithPrompts(context: vscode.ExtensionContext): Promise { + const customModes = (await context.globalState.get("customModes")) || [] + const customModePrompts = (await context.globalState.get("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)