Parcourir la source

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

Matt Rubens il y a 10 mois
Parent
commit
e66b0853b3
2 fichiers modifiés avec 20 ajouts et 4 suppressions
  1. 6 4
      src/core/prompts/sections/modes.ts
  2. 14 0
      src/shared/modes.ts

+ 6 - 4
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<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)

+ 14 - 0
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<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)