From 6e66d73a2cbadb979fea7bbd3bf90ad82f52c169 Mon Sep 17 00:00:00 2001 From: devxpain <170700110+devxpain@users.noreply.github.com> Date: Tue, 3 Jun 2025 18:43:23 +0800 Subject: [PATCH] fix(modes): prevent missing role definition when selecting default mode - Previously, `getModeSelection` could pick `promptComponent` as the active mode even if it lacked a `roleDefinition`. - This resulted in an empty `roleDefinition` being returned, overriding potentially valid role definitions from built-in modes. - The logic now only considers `promptComponent` if it provides a `roleDefinition`, ensuring that a proper role definition is always selected if available from custom, prompt, or built-in modes. --- src/shared/modes.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/shared/modes.ts b/src/shared/modes.ts index c735118f66..d7c4706e6d 100644 --- a/src/shared/modes.ts +++ b/src/shared/modes.ts @@ -171,17 +171,14 @@ export function findModeBySlug(slug: string, modes: readonly ModeConfig[] | unde * If neither is found, the default mode is used. */ export function getModeSelection(mode: string, promptComponent?: PromptComponent, customModes?: ModeConfig[]) { - const customMode = findModeBySlug(mode, customModes) - const builtInMode = findModeBySlug(mode, modes) - - const modeToUse = customMode || promptComponent || builtInMode - - const roleDefinition = modeToUse?.roleDefinition || "" - const baseInstructions = modeToUse?.customInstructions || "" + const modeToUse = + findModeBySlug(mode, customModes) || + (promptComponent?.roleDefinition ? promptComponent : undefined) || + findModeBySlug(mode, modes) return { - roleDefinition, - baseInstructions, + roleDefinition: modeToUse?.roleDefinition || "", + baseInstructions: modeToUse?.customInstructions || "", } }