From b86f60fb08ebb00f46943a5279f12c0d3e751594 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Thu, 27 Nov 2025 06:21:28 +0000 Subject: [PATCH] feat: add "Always run enhance prompt" setting for automatic prompt enhancement - Added alwaysRunEnhancePrompt boolean setting to global settings schema - Added toggle control in PromptsSettings component under "Enhance prompt" - Updated ExtensionStateContext to handle the new setting with getter/setter - Modified ChatTextArea to auto-enhance prompts when setting is enabled - Auto-enhancement triggers on Enter keypress for new tasks only - Enhanced text is automatically sent after processing - All existing tests passing with proper null checks for clineMessages Fixes #9649 --- packages/types/src/global-settings.ts | 1 + src/shared/ExtensionMessage.ts | 1 + .../src/components/chat/ChatTextArea.tsx | 28 +++++++++++++++--- .../components/settings/PromptsSettings.tsx | 29 +++++++++++++++++++ .../src/context/ExtensionStateContext.tsx | 10 +++++++ 5 files changed, 65 insertions(+), 4 deletions(-) diff --git a/packages/types/src/global-settings.ts b/packages/types/src/global-settings.ts index 6e61c3950f..8fe5664d52 100644 --- a/packages/types/src/global-settings.ts +++ b/packages/types/src/global-settings.ts @@ -184,6 +184,7 @@ export const globalSettingsSchema = z.object({ customModePrompts: customModePromptsSchema.optional(), customSupportPrompts: customSupportPromptsSchema.optional(), enhancementApiConfigId: z.string().optional(), + alwaysRunEnhancePrompt: z.boolean().optional(), includeTaskHistoryInEnhance: z.boolean().optional(), historyPreviewCollapsed: z.boolean().optional(), reasoningBlockCollapsed: z.boolean().optional(), diff --git a/src/shared/ExtensionMessage.ts b/src/shared/ExtensionMessage.ts index 53327df720..5c7e160846 100644 --- a/src/shared/ExtensionMessage.ts +++ b/src/shared/ExtensionMessage.ts @@ -276,6 +276,7 @@ export type ExtensionState = Pick< | "customModePrompts" | "customSupportPrompts" | "enhancementApiConfigId" + | "alwaysRunEnhancePrompt" | "condensingApiConfigId" | "customCondensingPrompt" | "codebaseIndexConfig" diff --git a/webview-ui/src/components/chat/ChatTextArea.tsx b/webview-ui/src/components/chat/ChatTextArea.tsx index 58f42a367b..1b28389792 100644 --- a/webview-ui/src/components/chat/ChatTextArea.tsx +++ b/webview-ui/src/components/chat/ChatTextArea.tsx @@ -94,6 +94,7 @@ export const ChatTextArea = forwardRef( clineMessages, commands, cloudUserInfo, + alwaysRunEnhancePrompt, } = useExtensionState() // Find the ID and display text for the currently selected API configuration. @@ -123,6 +124,8 @@ export const ChatTextArea = forwardRef( return () => document.removeEventListener("mousedown", handleClickOutside) }, [showDropdown]) + const [pendingSend, setPendingSend] = useState(false) + // Handle enhanced prompt response and search results. useEffect(() => { const messageHandler = (event: MessageEvent) => { @@ -151,6 +154,12 @@ export const ChatTextArea = forwardRef( } setIsEnhancingPrompt(false) + + // If we were waiting to send after enhancement, send now + if (pendingSend) { + setPendingSend(false) + onSend() + } } else if (message.type === "insertTextIntoTextarea") { if (message.text && textAreaRef.current) { // Insert the command text at the current cursor position @@ -201,7 +210,7 @@ export const ChatTextArea = forwardRef( window.addEventListener("message", messageHandler) return () => window.removeEventListener("message", messageHandler) - }, [setInputValue, searchRequestId, inputValue]) + }, [setInputValue, searchRequestId, inputValue, pendingSend, onSend]) const [isDraggingOver, setIsDraggingOver] = useState(false) const [textAreaBaseHeight, setTextAreaBaseHeight] = useState(undefined) @@ -474,10 +483,19 @@ export const ChatTextArea = forwardRef( if (event.key === "Enter" && !event.shiftKey && !isComposing) { event.preventDefault() - - // Always call onSend - let ChatView handle queueing when disabled resetHistoryNavigation() - onSend() + + // Check if we should auto-enhance first + const trimmedInput = inputValue.trim() + if (alwaysRunEnhancePrompt && trimmedInput && clineMessages?.length === 0) { + // This is a new task and auto-enhance is enabled + setIsEnhancingPrompt(true) + setPendingSend(true) + vscode.postMessage({ type: "enhancePrompt" as const, text: trimmedInput }) + } else { + // Normal send without enhancement + onSend() + } } if (event.key === "Backspace" && !isComposing) { @@ -541,6 +559,8 @@ export const ChatTextArea = forwardRef( handleHistoryNavigation, resetHistoryNavigation, commands, + alwaysRunEnhancePrompt, + clineMessages?.length, ], ) diff --git a/webview-ui/src/components/settings/PromptsSettings.tsx b/webview-ui/src/components/settings/PromptsSettings.tsx index bca240c731..a6e45c8060 100644 --- a/webview-ui/src/components/settings/PromptsSettings.tsx +++ b/webview-ui/src/components/settings/PromptsSettings.tsx @@ -38,6 +38,8 @@ const PromptsSettings = ({ listApiConfigMeta, enhancementApiConfigId, setEnhancementApiConfigId, + alwaysRunEnhancePrompt, + setAlwaysRunEnhancePrompt, condensingApiConfigId, setCondensingApiConfigId, customCondensingPrompt, @@ -283,6 +285,33 @@ const PromptsSettings = ({ +
+ ) => { + const target = ( + "target" in e ? e.target : null + ) as HTMLInputElement | null + + if (!target) { + return + } + + setAlwaysRunEnhancePrompt(target.checked) + + vscode.postMessage({ + type: "updateSettings", + updatedSettings: { alwaysRunEnhancePrompt: target.checked }, + }) + }}> + Always run enhance prompt + +
+ Automatically enhance every message before sending it to improve quality and + clarity +
+
+