diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 00000000000..ae09fd9b30d --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,5 @@ +# AGENTS.md + +This file provides guidance to agents when working with code in this repository. + +- Settings View Pattern: When working on `SettingsView`, inputs must bind to the local `cachedState`, NOT the live `useExtensionState()`. The `cachedState` acts as a buffer for user edits, isolating them from the `ContextProxy` source-of-truth until the user explicitly clicks "Save". Wiring inputs directly to the live state causes race conditions. diff --git a/webview-ui/src/components/settings/PromptsSettings.tsx b/webview-ui/src/components/settings/PromptsSettings.tsx index ea9e8ed4766..ce27db44e4e 100644 --- a/webview-ui/src/components/settings/PromptsSettings.tsx +++ b/webview-ui/src/components/settings/PromptsSettings.tsx @@ -23,6 +23,8 @@ import { SearchableSetting } from "./SearchableSetting" interface PromptsSettingsProps { customSupportPrompts: Record setCustomSupportPrompts: (prompts: Record) => void + customCondensingPrompt?: string + setCustomCondensingPrompt?: (value: string) => void includeTaskHistoryInEnhance?: boolean setIncludeTaskHistoryInEnhance?: (value: boolean) => void } @@ -30,6 +32,8 @@ interface PromptsSettingsProps { const PromptsSettings = ({ customSupportPrompts, setCustomSupportPrompts, + customCondensingPrompt: propsCustomCondensingPrompt, + setCustomCondensingPrompt: propsSetCustomCondensingPrompt, includeTaskHistoryInEnhance: propsIncludeTaskHistoryInEnhance, setIncludeTaskHistoryInEnhance: propsSetIncludeTaskHistoryInEnhance, }: PromptsSettingsProps) => { @@ -40,12 +44,16 @@ const PromptsSettings = ({ setEnhancementApiConfigId, condensingApiConfigId, setCondensingApiConfigId, - customCondensingPrompt, - setCustomCondensingPrompt, + customCondensingPrompt: contextCustomCondensingPrompt, + setCustomCondensingPrompt: contextSetCustomCondensingPrompt, includeTaskHistoryInEnhance: contextIncludeTaskHistoryInEnhance, setIncludeTaskHistoryInEnhance: contextSetIncludeTaskHistoryInEnhance, } = useExtensionState() + // Use props if provided, otherwise fall back to context + const customCondensingPrompt = propsCustomCondensingPrompt ?? contextCustomCondensingPrompt + const setCustomCondensingPrompt = propsSetCustomCondensingPrompt ?? contextSetCustomCondensingPrompt + // Use props if provided, otherwise fall back to context const includeTaskHistoryInEnhance = propsIncludeTaskHistoryInEnhance ?? contextIncludeTaskHistoryInEnhance ?? true const setIncludeTaskHistoryInEnhance = propsSetIncludeTaskHistoryInEnhance ?? contextSetIncludeTaskHistoryInEnhance @@ -76,10 +84,6 @@ const PromptsSettings = ({ if (type === "CONDENSE") { setCustomCondensingPrompt(finalValue ?? supportPrompt.default.CONDENSE) - vscode.postMessage({ - type: "updateCondensingPrompt", - text: finalValue ?? supportPrompt.default.CONDENSE, - }) // Also update the customSupportPrompts to trigger change detection const updatedPrompts = { ...customSupportPrompts } if (finalValue === undefined) { @@ -102,10 +106,6 @@ const PromptsSettings = ({ const handleSupportReset = (type: SupportPromptType) => { if (type === "CONDENSE") { setCustomCondensingPrompt(supportPrompt.default.CONDENSE) - vscode.postMessage({ - type: "updateCondensingPrompt", - text: supportPrompt.default.CONDENSE, - }) // Also update the customSupportPrompts to trigger change detection const updatedPrompts = { ...customSupportPrompts } delete updatedPrompts[type] diff --git a/webview-ui/src/components/settings/SettingsView.tsx b/webview-ui/src/components/settings/SettingsView.tsx index d86007e80fe..6c9ee47d1cb 100644 --- a/webview-ui/src/components/settings/SettingsView.tsx +++ b/webview-ui/src/components/settings/SettingsView.tsx @@ -900,6 +900,10 @@ const SettingsView = forwardRef(({ onDone, t + setCachedStateField("customCondensingPrompt", value) + } includeTaskHistoryInEnhance={includeTaskHistoryInEnhance} setIncludeTaskHistoryInEnhance={(value) => setCachedStateField("includeTaskHistoryInEnhance", value)