Skip to content

Commit dde1668

Browse files
committed
working pass
1 parent 00a3738 commit dde1668

File tree

8 files changed

+119
-27
lines changed

8 files changed

+119
-27
lines changed

packages/types/src/global-settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export const globalSettingsSchema = z.object({
139139
customModePrompts: customModePromptsSchema.optional(),
140140
customSupportPrompts: customSupportPromptsSchema.optional(),
141141
enhancementApiConfigId: z.string().optional(),
142+
includeTaskHistoryInEnhance: z.boolean().optional(),
142143
historyPreviewCollapsed: z.boolean().optional(),
143144
profileThresholds: z.record(z.string(), z.number()).optional(),
144145
hasOpenedModeSelector: z.boolean().optional(),

src/core/webview/ClineProvider.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,7 @@ export class ClineProvider
15111511
followupAutoApproveTimeoutMs,
15121512
includeDiagnosticMessages,
15131513
maxDiagnosticMessages,
1514+
includeTaskHistoryInEnhance,
15141515
} = await this.getState()
15151516

15161517
const telemetryKey = process.env.POSTHOG_API_KEY
@@ -1635,6 +1636,7 @@ export class ClineProvider
16351636
followupAutoApproveTimeoutMs: followupAutoApproveTimeoutMs ?? 60000,
16361637
includeDiagnosticMessages: includeDiagnosticMessages ?? true,
16371638
maxDiagnosticMessages: maxDiagnosticMessages ?? 50,
1639+
includeTaskHistoryInEnhance: includeTaskHistoryInEnhance ?? false,
16381640
}
16391641
}
16401642

@@ -1805,6 +1807,8 @@ export class ClineProvider
18051807
// Add diagnostic message settings
18061808
includeDiagnosticMessages: stateValues.includeDiagnosticMessages ?? true,
18071809
maxDiagnosticMessages: stateValues.maxDiagnosticMessages ?? 50,
1810+
// Add includeTaskHistoryInEnhance setting
1811+
includeTaskHistoryInEnhance: stateValues.includeTaskHistoryInEnhance ?? false,
18081812
}
18091813
}
18101814

src/core/webview/webviewMessageHandler.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,10 @@ export const webviewMessageHandler = async (
13111311
await updateGlobalState("enhancementApiConfigId", message.text)
13121312
await provider.postStateToWebview()
13131313
break
1314+
case "includeTaskHistoryInEnhance":
1315+
await updateGlobalState("includeTaskHistoryInEnhance", message.bool ?? false)
1316+
await provider.postStateToWebview()
1317+
break
13141318
case "condensingApiConfigId":
13151319
await updateGlobalState("condensingApiConfigId", message.text)
13161320
await provider.postStateToWebview()
@@ -1335,8 +1339,9 @@ export const webviewMessageHandler = async (
13351339
case "enhancePrompt":
13361340
if (message.text) {
13371341
try {
1338-
const { apiConfiguration, customSupportPrompts, listApiConfigMeta, enhancementApiConfigId } =
1339-
await provider.getState()
1342+
const state = await provider.getState()
1343+
const { apiConfiguration, customSupportPrompts, listApiConfigMeta, enhancementApiConfigId } = state
1344+
const includeTaskHistoryInEnhance = (state as any).includeTaskHistoryInEnhance
13401345

13411346
// Try to get enhancement config first, fall back to current config.
13421347
let configToUse: ProviderSettings = apiConfiguration
@@ -1351,9 +1356,38 @@ export const webviewMessageHandler = async (
13511356
}
13521357
}
13531358

1359+
let promptToEnhance = message.text
1360+
1361+
// Include task history if enabled
1362+
if (includeTaskHistoryInEnhance && provider.getCurrentCline()) {
1363+
const currentCline = provider.getCurrentCline()!
1364+
const taskHistory = currentCline.clineMessages
1365+
.filter((msg) => {
1366+
// Include user messages (type: "ask" with text) and assistant messages (type: "say" with say: "text")
1367+
if (msg.type === "ask" && msg.text) {
1368+
return true
1369+
}
1370+
if (msg.type === "say" && msg.say === "text" && msg.text) {
1371+
return true
1372+
}
1373+
return false
1374+
})
1375+
.slice(-10) // Limit to last 10 messages to avoid context explosion
1376+
.map((msg) => {
1377+
const role = msg.type === "ask" ? "User" : "Assistant"
1378+
const content = msg.text || ""
1379+
return `${role}: ${content.slice(0, 500)}${content.length > 500 ? "..." : ""}` // Truncate long messages
1380+
})
1381+
.join("\n")
1382+
1383+
if (taskHistory) {
1384+
promptToEnhance = `${message.text}\n\nUse the following previous conversation context as needed:\n${taskHistory}`
1385+
}
1386+
}
1387+
13541388
const enhancedPrompt = await singleCompletionHandler(
13551389
configToUse,
1356-
supportPrompt.create("ENHANCE", { userInput: message.text }, customSupportPrompts),
1390+
supportPrompt.create("ENHANCE", { userInput: promptToEnhance }, customSupportPrompts),
13571391
)
13581392

13591393
// Capture telemetry for prompt enhancement.

src/shared/WebviewMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export interface WebviewMessage {
140140
| "copySystemPrompt"
141141
| "systemPrompt"
142142
| "enhancementApiConfigId"
143+
| "includeTaskHistoryInEnhance"
143144
| "updateExperimental"
144145
| "autoApprovalEnabled"
145146
| "updateCustomMode"

webview-ui/src/components/settings/PromptsSettings.tsx

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState, useEffect } from "react"
2-
import { VSCodeTextArea } from "@vscode/webview-ui-toolkit/react"
2+
import { VSCodeTextArea, VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react"
33

44
import { supportPrompt, SupportPromptType } from "@roo/support-prompt"
55

@@ -22,9 +22,16 @@ import { MessageSquare } from "lucide-react"
2222
interface PromptsSettingsProps {
2323
customSupportPrompts: Record<string, string | undefined>
2424
setCustomSupportPrompts: (prompts: Record<string, string | undefined>) => void
25+
includeTaskHistoryInEnhance?: boolean
26+
setIncludeTaskHistoryInEnhance?: (value: boolean) => void
2527
}
2628

27-
const PromptsSettings = ({ customSupportPrompts, setCustomSupportPrompts }: PromptsSettingsProps) => {
29+
const PromptsSettings = ({
30+
customSupportPrompts,
31+
setCustomSupportPrompts,
32+
includeTaskHistoryInEnhance: propsIncludeTaskHistoryInEnhance,
33+
setIncludeTaskHistoryInEnhance: propsSetIncludeTaskHistoryInEnhance,
34+
}: PromptsSettingsProps) => {
2835
const { t } = useAppTranslation()
2936
const {
3037
listApiConfigMeta,
@@ -34,8 +41,14 @@ const PromptsSettings = ({ customSupportPrompts, setCustomSupportPrompts }: Prom
3441
setCondensingApiConfigId,
3542
customCondensingPrompt,
3643
setCustomCondensingPrompt,
44+
includeTaskHistoryInEnhance: contextIncludeTaskHistoryInEnhance,
45+
setIncludeTaskHistoryInEnhance: contextSetIncludeTaskHistoryInEnhance,
3746
} = useExtensionState()
3847

48+
// Use props if provided, otherwise fall back to context
49+
const includeTaskHistoryInEnhance = propsIncludeTaskHistoryInEnhance ?? contextIncludeTaskHistoryInEnhance
50+
const setIncludeTaskHistoryInEnhance = propsSetIncludeTaskHistoryInEnhance ?? contextSetIncludeTaskHistoryInEnhance
51+
3952
const [testPrompt, setTestPrompt] = useState("")
4053
const [isEnhancing, setIsEnhancing] = useState(false)
4154
const [activeSupportOption, setActiveSupportOption] = useState<SupportPromptType>("ENHANCE")
@@ -219,28 +232,50 @@ const PromptsSettings = ({ customSupportPrompts, setCustomSupportPrompts }: Prom
219232
</div>
220233

221234
{activeSupportOption === "ENHANCE" && (
222-
<div>
223-
<label className="block font-medium mb-1">
224-
{t("prompts:supportPrompts.enhance.testEnhancement")}
225-
</label>
226-
<VSCodeTextArea
227-
resize="vertical"
228-
value={testPrompt}
229-
onChange={(e) => setTestPrompt((e.target as HTMLTextAreaElement).value)}
230-
placeholder={t("prompts:supportPrompts.enhance.testPromptPlaceholder")}
231-
rows={3}
232-
className="w-full"
233-
data-testid="test-prompt-textarea"
234-
/>
235-
<div className="mt-2 flex justify-start items-center gap-2">
236-
<Button
237-
variant="default"
238-
onClick={handleTestEnhancement}
239-
disabled={isEnhancing}>
240-
{t("prompts:supportPrompts.enhance.previewButton")}
241-
</Button>
235+
<>
236+
<div>
237+
<VSCodeCheckbox
238+
checked={includeTaskHistoryInEnhance || false}
239+
onChange={(e: any) => {
240+
const value = e.target.checked
241+
setIncludeTaskHistoryInEnhance(value)
242+
vscode.postMessage({
243+
type: "includeTaskHistoryInEnhance",
244+
bool: value,
245+
})
246+
}}>
247+
<span className="font-medium">
248+
{t("prompts:supportPrompts.enhance.includeTaskHistory")}
249+
</span>
250+
</VSCodeCheckbox>
251+
<div className="text-vscode-descriptionForeground text-sm mt-1 mb-3">
252+
{t("prompts:supportPrompts.enhance.includeTaskHistoryDescription")}
253+
</div>
242254
</div>
243-
</div>
255+
256+
<div>
257+
<label className="block font-medium mb-1">
258+
{t("prompts:supportPrompts.enhance.testEnhancement")}
259+
</label>
260+
<VSCodeTextArea
261+
resize="vertical"
262+
value={testPrompt}
263+
onChange={(e) => setTestPrompt((e.target as HTMLTextAreaElement).value)}
264+
placeholder={t("prompts:supportPrompts.enhance.testPromptPlaceholder")}
265+
rows={3}
266+
className="w-full"
267+
data-testid="test-prompt-textarea"
268+
/>
269+
<div className="mt-2 flex justify-start items-center gap-2">
270+
<Button
271+
variant="default"
272+
onClick={handleTestEnhancement}
273+
disabled={isEnhancing}>
274+
{t("prompts:supportPrompts.enhance.previewButton")}
275+
</Button>
276+
</div>
277+
</div>
278+
</>
244279
)}
245280
</div>
246281
)}

webview-ui/src/components/settings/SettingsView.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
181181
followupAutoApproveTimeoutMs,
182182
includeDiagnosticMessages,
183183
maxDiagnosticMessages,
184+
includeTaskHistoryInEnhance,
184185
} = cachedState
185186

186187
const apiConfiguration = useMemo(() => cachedState.apiConfiguration ?? {}, [cachedState.apiConfiguration])
@@ -338,6 +339,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
338339
vscode.postMessage({ type: "condensingApiConfigId", text: condensingApiConfigId || "" })
339340
vscode.postMessage({ type: "updateCondensingPrompt", text: customCondensingPrompt || "" })
340341
vscode.postMessage({ type: "updateSupportPrompt", values: customSupportPrompts || {} })
342+
vscode.postMessage({ type: "includeTaskHistoryInEnhance", bool: includeTaskHistoryInEnhance ?? false })
341343
vscode.postMessage({ type: "upsertApiConfiguration", text: currentApiConfigName, apiConfiguration })
342344
vscode.postMessage({ type: "telemetrySetting", text: telemetrySetting })
343345
vscode.postMessage({ type: "profileThresholds", values: profileThresholds })
@@ -705,6 +707,10 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
705707
<PromptsSettings
706708
customSupportPrompts={customSupportPrompts || {}}
707709
setCustomSupportPrompts={setCustomSupportPromptsField}
710+
includeTaskHistoryInEnhance={includeTaskHistoryInEnhance}
711+
setIncludeTaskHistoryInEnhance={(value) =>
712+
setCachedStateField("includeTaskHistoryInEnhance", value)
713+
}
708714
/>
709715
)}
710716

webview-ui/src/context/ExtensionStateContext.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ export interface ExtensionStateContextType extends ExtensionState {
143143
setIncludeDiagnosticMessages: (value: boolean) => void
144144
maxDiagnosticMessages?: number
145145
setMaxDiagnosticMessages: (value: number) => void
146+
includeTaskHistoryInEnhance?: boolean
147+
setIncludeTaskHistoryInEnhance: (value: boolean) => void
146148
}
147149

148150
export const ExtensionStateContext = createContext<ExtensionStateContextType | undefined>(undefined)
@@ -260,6 +262,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
260262
project: {},
261263
global: {},
262264
})
265+
const [includeTaskHistoryInEnhance, setIncludeTaskHistoryInEnhance] = useState(false)
263266

264267
const setListApiConfigMeta = useCallback(
265268
(value: ProviderSettingsEntry[]) => setState((prevState) => ({ ...prevState, listApiConfigMeta: value })),
@@ -293,6 +296,10 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
293296
if ((newState as any).followupAutoApproveTimeoutMs !== undefined) {
294297
setFollowupAutoApproveTimeoutMs((newState as any).followupAutoApproveTimeoutMs)
295298
}
299+
// Update includeTaskHistoryInEnhance if present in state message
300+
if ((newState as any).includeTaskHistoryInEnhance !== undefined) {
301+
setIncludeTaskHistoryInEnhance((newState as any).includeTaskHistoryInEnhance)
302+
}
296303
// Handle marketplace data if present in state message
297304
if (newState.marketplaceItems !== undefined) {
298305
setMarketplaceItems(newState.marketplaceItems)
@@ -503,6 +510,8 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
503510
setMaxDiagnosticMessages: (value) => {
504511
setState((prevState) => ({ ...prevState, maxDiagnosticMessages: value }))
505512
},
513+
includeTaskHistoryInEnhance,
514+
setIncludeTaskHistoryInEnhance,
506515
}
507516

508517
return <ExtensionStateContext.Provider value={contextValue}>{children}</ExtensionStateContext.Provider>

webview-ui/src/i18n/locales/en/prompts.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@
9393
"useCurrentConfig": "Use currently selected API configuration",
9494
"testPromptPlaceholder": "Enter a prompt to test the enhancement",
9595
"previewButton": "Preview Prompt Enhancement",
96-
"testEnhancement": "Test Enhancement"
96+
"testEnhancement": "Test Enhancement",
97+
"includeTaskHistory": "Include task history as context",
98+
"includeTaskHistoryDescription": "When enabled, the last 10 messages from the current conversation will be included as context when enhancing prompts, helping to generate more relevant and context-aware suggestions."
9799
},
98100
"condense": {
99101
"apiConfiguration": "API Configuration for Context Condensing",

0 commit comments

Comments
 (0)