Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { HTMLAttributes } from "react"
import React from "react"
import { useAppTranslation } from "@/i18n/TranslationContext"
import { VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react"
import { VSCodeCheckbox, VSCodeTextArea } from "@vscode/webview-ui-toolkit/react"
import { FoldVertical } from "lucide-react"

import { supportPrompt } from "@roo/support-prompt"

import { cn } from "@/lib/utils"
import { Input, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Slider, Button } from "@/components/ui"
import {
Input,
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
Slider,
Button,
StandardTooltip,
} from "@/components/ui"

import { SetCachedStateField } from "./types"
import { SectionHeader } from "./SectionHeader"
Expand All @@ -32,6 +44,8 @@ type ContextManagementSettingsProps = HTMLAttributes<HTMLDivElement> & {
includeCurrentTime?: boolean
includeCurrentCost?: boolean
maxGitStatusFiles?: number
customSupportPrompts: Record<string, string | undefined>
setCustomSupportPrompts: (prompts: Record<string, string | undefined>) => void
setCachedStateField: SetCachedStateField<
| "autoCondenseContext"
| "autoCondenseContextPercent"
Expand Down Expand Up @@ -73,12 +87,37 @@ export const ContextManagementSettings = ({
includeCurrentTime,
includeCurrentCost,
maxGitStatusFiles,
customSupportPrompts,
setCustomSupportPrompts,
className,
...props
}: ContextManagementSettingsProps) => {
const { t } = useAppTranslation()
const [selectedThresholdProfile, setSelectedThresholdProfile] = React.useState<string>("default")

// Helper function to get the CONDENSE prompt value
const getCondensePromptValue = (): string => {
return supportPrompt.get(customSupportPrompts, "CONDENSE")
}

// Helper function to update the CONDENSE prompt
const updateCondensePrompt = (value: string | undefined) => {
const updatedPrompts = { ...customSupportPrompts }
if (value === undefined) {
delete updatedPrompts["CONDENSE"]
} else {
updatedPrompts["CONDENSE"] = value
}
setCustomSupportPrompts(updatedPrompts)
}

// Helper function to reset the CONDENSE prompt to default
const handleCondenseReset = () => {
const updatedPrompts = { ...customSupportPrompts }
delete updatedPrompts["CONDENSE"]
setCustomSupportPrompts(updatedPrompts)
}

// Helper function to get the current threshold value based on selected profile
const getCurrentThresholdValue = () => {
if (selectedThresholdProfile === "default") {
Expand Down Expand Up @@ -470,6 +509,38 @@ export const ContextManagementSettings = ({
</SearchableSetting>
</Section>
<Section className="pt-2">
{/* Context Condensing Prompt Editor */}
<SearchableSetting
settingId="context-condense-prompt"
section="contextManagement"
label={t("prompts:supportPrompts.types.CONDENSE.label")}>
<div className="flex justify-between items-center mb-1">
<label className="block font-medium">{t("prompts:supportPrompts.types.CONDENSE.label")}</label>
<StandardTooltip content={t("prompts:supportPrompts.resetPrompt", { promptType: "CONDENSE" })}>
<Button variant="ghost" size="icon" onClick={handleCondenseReset}>
<span className="codicon codicon-discard"></span>
</Button>
</StandardTooltip>
</div>
<div className="text-sm text-vscode-descriptionForeground mb-2">
{t("prompts:supportPrompts.types.CONDENSE.description")}
</div>
<VSCodeTextArea
resize="vertical"
value={getCondensePromptValue()}
onInput={(e) => {
const value =
(e as unknown as CustomEvent)?.detail?.target?.value ??
((e as any).target as HTMLTextAreaElement).value
updateCondensePrompt(value)
}}
rows={6}
className="w-full"
data-testid="condense-prompt-textarea"
/>
</SearchableSetting>

{/* Auto Condense Context */}
<SearchableSetting
settingId="context-auto-condense"
section="contextManagement"
Expand Down
12 changes: 7 additions & 5 deletions webview-ui/src/components/settings/PromptsSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ const PromptsSettings = ({
<SelectValue placeholder={t("settings:common.select")} />
</SelectTrigger>
<SelectContent>
{Object.keys(supportPrompt.default).map((type) => (
<SelectItem key={type} value={type} data-testid={`${type}-option`}>
{t(`prompts:supportPrompts.types.${type}.label`)}
</SelectItem>
))}
{Object.keys(supportPrompt.default)
.filter((type) => type !== "CONDENSE")
.map((type) => (
<SelectItem key={type} value={type} data-testid={`${type}-option`}>
{t(`prompts:supportPrompts.types.${type}.label`)}
</SelectItem>
))}
</SelectContent>
</Select>
<div className="text-sm text-vscode-descriptionForeground mt-1">
Expand Down
2 changes: 2 additions & 0 deletions webview-ui/src/components/settings/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,8 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
includeCurrentTime={includeCurrentTime}
includeCurrentCost={includeCurrentCost}
maxGitStatusFiles={maxGitStatusFiles}
customSupportPrompts={customSupportPrompts || {}}
setCustomSupportPrompts={setCustomSupportPromptsField}
setCachedStateField={setCachedStateField}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ vi.mock("@/components/ui", () => ({
SelectValue: ({ children, ...props }: any) => <div {...props}>{children}</div>,
SelectContent: ({ children, ...props }: any) => <div {...props}>{children}</div>,
SelectItem: ({ children, ...props }: any) => <div {...props}>{children}</div>,
StandardTooltip: ({ children, content }: any) => <div title={content}>{children}</div>,
}))

// Mock vscode utilities - this is necessary since we're not in a VSCode environment
Expand Down Expand Up @@ -87,7 +88,6 @@ describe("ContextManagementSettings", () => {
const defaultProps = {
autoCondenseContext: false,
autoCondenseContextPercent: 80,
customCondensingPrompt: undefined,
listApiConfigMeta: [],
maxOpenTabsContext: 20,
maxWorkspaceFiles: 200,
Expand All @@ -98,6 +98,8 @@ describe("ContextManagementSettings", () => {
includeDiagnosticMessages: true,
maxDiagnosticMessages: 50,
writeDelayMs: 1000,
customSupportPrompts: {},
setCustomSupportPrompts: vi.fn(),
setCachedStateField: vi.fn(),
}

Expand Down
Loading