Skip to content

Commit 1f7be76

Browse files
feat: Move condense prompt editor to Context Management tab (#10909)
1 parent f7bf7a4 commit 1f7be76

4 files changed

Lines changed: 85 additions & 8 deletions

File tree

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

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
import { HTMLAttributes } from "react"
22
import React from "react"
33
import { useAppTranslation } from "@/i18n/TranslationContext"
4-
import { VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react"
4+
import { VSCodeCheckbox, VSCodeTextArea } from "@vscode/webview-ui-toolkit/react"
55
import { FoldVertical } from "lucide-react"
66

7+
import { supportPrompt } from "@roo/support-prompt"
8+
79
import { cn } from "@/lib/utils"
8-
import { Input, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Slider, Button } from "@/components/ui"
10+
import {
11+
Input,
12+
Select,
13+
SelectContent,
14+
SelectItem,
15+
SelectTrigger,
16+
SelectValue,
17+
Slider,
18+
Button,
19+
StandardTooltip,
20+
} from "@/components/ui"
921

1022
import { SetCachedStateField } from "./types"
1123
import { SectionHeader } from "./SectionHeader"
@@ -32,6 +44,8 @@ type ContextManagementSettingsProps = HTMLAttributes<HTMLDivElement> & {
3244
includeCurrentTime?: boolean
3345
includeCurrentCost?: boolean
3446
maxGitStatusFiles?: number
47+
customSupportPrompts: Record<string, string | undefined>
48+
setCustomSupportPrompts: (prompts: Record<string, string | undefined>) => void
3549
setCachedStateField: SetCachedStateField<
3650
| "autoCondenseContext"
3751
| "autoCondenseContextPercent"
@@ -73,12 +87,37 @@ export const ContextManagementSettings = ({
7387
includeCurrentTime,
7488
includeCurrentCost,
7589
maxGitStatusFiles,
90+
customSupportPrompts,
91+
setCustomSupportPrompts,
7692
className,
7793
...props
7894
}: ContextManagementSettingsProps) => {
7995
const { t } = useAppTranslation()
8096
const [selectedThresholdProfile, setSelectedThresholdProfile] = React.useState<string>("default")
8197

98+
// Helper function to get the CONDENSE prompt value
99+
const getCondensePromptValue = (): string => {
100+
return supportPrompt.get(customSupportPrompts, "CONDENSE")
101+
}
102+
103+
// Helper function to update the CONDENSE prompt
104+
const updateCondensePrompt = (value: string | undefined) => {
105+
const updatedPrompts = { ...customSupportPrompts }
106+
if (value === undefined) {
107+
delete updatedPrompts["CONDENSE"]
108+
} else {
109+
updatedPrompts["CONDENSE"] = value
110+
}
111+
setCustomSupportPrompts(updatedPrompts)
112+
}
113+
114+
// Helper function to reset the CONDENSE prompt to default
115+
const handleCondenseReset = () => {
116+
const updatedPrompts = { ...customSupportPrompts }
117+
delete updatedPrompts["CONDENSE"]
118+
setCustomSupportPrompts(updatedPrompts)
119+
}
120+
82121
// Helper function to get the current threshold value based on selected profile
83122
const getCurrentThresholdValue = () => {
84123
if (selectedThresholdProfile === "default") {
@@ -470,6 +509,38 @@ export const ContextManagementSettings = ({
470509
</SearchableSetting>
471510
</Section>
472511
<Section className="pt-2">
512+
{/* Context Condensing Prompt Editor */}
513+
<SearchableSetting
514+
settingId="context-condense-prompt"
515+
section="contextManagement"
516+
label={t("prompts:supportPrompts.types.CONDENSE.label")}>
517+
<div className="flex justify-between items-center mb-1">
518+
<label className="block font-medium">{t("prompts:supportPrompts.types.CONDENSE.label")}</label>
519+
<StandardTooltip content={t("prompts:supportPrompts.resetPrompt", { promptType: "CONDENSE" })}>
520+
<Button variant="ghost" size="icon" onClick={handleCondenseReset}>
521+
<span className="codicon codicon-discard"></span>
522+
</Button>
523+
</StandardTooltip>
524+
</div>
525+
<div className="text-sm text-vscode-descriptionForeground mb-2">
526+
{t("prompts:supportPrompts.types.CONDENSE.description")}
527+
</div>
528+
<VSCodeTextArea
529+
resize="vertical"
530+
value={getCondensePromptValue()}
531+
onInput={(e) => {
532+
const value =
533+
(e as unknown as CustomEvent)?.detail?.target?.value ??
534+
((e as any).target as HTMLTextAreaElement).value
535+
updateCondensePrompt(value)
536+
}}
537+
rows={6}
538+
className="w-full"
539+
data-testid="condense-prompt-textarea"
540+
/>
541+
</SearchableSetting>
542+
543+
{/* Auto Condense Context */}
473544
<SearchableSetting
474545
settingId="context-auto-condense"
475546
section="contextManagement"

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,13 @@ const PromptsSettings = ({
117117
<SelectValue placeholder={t("settings:common.select")} />
118118
</SelectTrigger>
119119
<SelectContent>
120-
{Object.keys(supportPrompt.default).map((type) => (
121-
<SelectItem key={type} value={type} data-testid={`${type}-option`}>
122-
{t(`prompts:supportPrompts.types.${type}.label`)}
123-
</SelectItem>
124-
))}
120+
{Object.keys(supportPrompt.default)
121+
.filter((type) => type !== "CONDENSE")
122+
.map((type) => (
123+
<SelectItem key={type} value={type} data-testid={`${type}-option`}>
124+
{t(`prompts:supportPrompts.types.${type}.label`)}
125+
</SelectItem>
126+
))}
125127
</SelectContent>
126128
</Select>
127129
<div className="text-sm text-vscode-descriptionForeground mt-1">

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,8 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
863863
includeCurrentTime={includeCurrentTime}
864864
includeCurrentCost={includeCurrentCost}
865865
maxGitStatusFiles={maxGitStatusFiles}
866+
customSupportPrompts={customSupportPrompts || {}}
867+
setCustomSupportPrompts={setCustomSupportPromptsField}
866868
setCachedStateField={setCachedStateField}
867869
/>
868870
)}

webview-ui/src/components/settings/__tests__/ContextManagementSettings.spec.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ vi.mock("@/components/ui", () => ({
5656
SelectValue: ({ children, ...props }: any) => <div {...props}>{children}</div>,
5757
SelectContent: ({ children, ...props }: any) => <div {...props}>{children}</div>,
5858
SelectItem: ({ children, ...props }: any) => <div {...props}>{children}</div>,
59+
StandardTooltip: ({ children, content }: any) => <div title={content}>{children}</div>,
5960
}))
6061

6162
// Mock vscode utilities - this is necessary since we're not in a VSCode environment
@@ -87,7 +88,6 @@ describe("ContextManagementSettings", () => {
8788
const defaultProps = {
8889
autoCondenseContext: false,
8990
autoCondenseContextPercent: 80,
90-
customCondensingPrompt: undefined,
9191
listApiConfigMeta: [],
9292
maxOpenTabsContext: 20,
9393
maxWorkspaceFiles: 200,
@@ -98,6 +98,8 @@ describe("ContextManagementSettings", () => {
9898
includeDiagnosticMessages: true,
9999
maxDiagnosticMessages: 50,
100100
writeDelayMs: 1000,
101+
customSupportPrompts: {},
102+
setCustomSupportPrompts: vi.fn(),
101103
setCachedStateField: vi.fn(),
102104
}
103105

0 commit comments

Comments
 (0)