import { VSCodeButton, VSCodeTextArea, VSCodeDropdown, VSCodeOption } from "@vscode/webview-ui-toolkit/react" import { useExtensionState } from "../../context/ExtensionStateContext" import { defaultPrompts, modes, Mode, PromptComponent, getRoleDefinition } from "../../../../src/shared/modes" import { vscode } from "../../utils/vscode" import React, { useState, useEffect } from "react" type PromptsViewProps = { onDone: () => void } const AGENT_MODES = modes.map((mode) => ({ id: mode.slug, label: mode.name, })) const PromptsView = ({ onDone }: PromptsViewProps) => { const { customPrompts, listApiConfigMeta, enhancementApiConfigId, setEnhancementApiConfigId, mode, customInstructions, setCustomInstructions, preferredLanguage, setPreferredLanguage, } = useExtensionState() const [testPrompt, setTestPrompt] = useState("") const [isEnhancing, setIsEnhancing] = useState(false) const [activeTab, setActiveTab] = useState(mode) const [isDialogOpen, setIsDialogOpen] = useState(false) const [selectedPromptContent, setSelectedPromptContent] = useState("") const [selectedPromptTitle, setSelectedPromptTitle] = useState("") useEffect(() => { const handler = (event: MessageEvent) => { const message = event.data if (message.type === "enhancedPrompt") { if (message.text) { setTestPrompt(message.text) } setIsEnhancing(false) } else if (message.type === "systemPrompt") { if (message.text) { setSelectedPromptContent(message.text) setSelectedPromptTitle(`System Prompt (${message.mode} mode)`) setIsDialogOpen(true) } } } window.addEventListener("message", handler) return () => window.removeEventListener("message", handler) }, []) type AgentMode = string const updateAgentPrompt = (mode: Mode, promptData: PromptComponent) => { const existingPrompt = customPrompts?.[mode] const updatedPrompt = typeof existingPrompt === "object" ? { ...existingPrompt, ...promptData } : promptData // Only include properties that differ from defaults if (updatedPrompt.roleDefinition === getRoleDefinition(mode)) { delete updatedPrompt.roleDefinition } vscode.postMessage({ type: "updatePrompt", promptMode: mode, customPrompt: updatedPrompt, }) } const updateEnhancePrompt = (value: string | undefined) => { vscode.postMessage({ type: "updateEnhancedPrompt", text: value, }) } const handleAgentPromptChange = (mode: AgentMode, e: Event | React.FormEvent) => { const value = (e as CustomEvent)?.detail?.target?.value || ((e as any).target as HTMLTextAreaElement).value updateAgentPrompt(mode, { roleDefinition: value.trim() || undefined }) } const handleEnhancePromptChange = (e: Event | React.FormEvent) => { const value = (e as CustomEvent)?.detail?.target?.value || ((e as any).target as HTMLTextAreaElement).value const trimmedValue = value.trim() if (trimmedValue !== defaultPrompts.enhance) { updateEnhancePrompt(trimmedValue || undefined) } } const handleAgentReset = (mode: AgentMode) => { const existingPrompt = customPrompts?.[mode] updateAgentPrompt(mode, { ...(typeof existingPrompt === "object" ? existingPrompt : {}), roleDefinition: undefined, }) } const handleEnhanceReset = () => { updateEnhancePrompt(undefined) } const getAgentPromptValue = (mode: Mode): string => { const prompt = customPrompts?.[mode] return typeof prompt === "object" ? (prompt.roleDefinition ?? getRoleDefinition(mode)) : getRoleDefinition(mode) } const getEnhancePromptValue = (): string => { const enhance = customPrompts?.enhance const defaultEnhance = typeof defaultPrompts.enhance === "string" ? defaultPrompts.enhance : "" return typeof enhance === "string" ? enhance : defaultEnhance } const handleTestEnhancement = () => { if (!testPrompt.trim()) return setIsEnhancing(true) vscode.postMessage({ type: "enhancePrompt", text: testPrompt, }) } return (

Prompts

Done
Preferred Language

Select the language that Cline should use for communication.

Custom Instructions for All Modes
These instructions apply to all modes. They provide a base set of behaviors that can be enhanced by mode-specific instructions below.
{ const value = (e as CustomEvent)?.detail?.target?.value || ((e as any).target as HTMLTextAreaElement).value setCustomInstructions(value || undefined) vscode.postMessage({ type: "customInstructions", text: value.trim() || undefined, }) }} rows={4} resize="vertical" style={{ width: "100%" }} data-testid="global-custom-instructions-textarea" />
Instructions can also be loaded from{" "} vscode.postMessage({ type: "openFile", text: "./.clinerules", values: { create: true, content: "", }, }) }> .clinerules {" "} in your workspace.

Mode-Specific Prompts

{AGENT_MODES.map((tab) => ( ))}
Role Definition
handleAgentReset(activeTab)} data-testid="reset-prompt-button" title="Revert to default">
Define Cline's expertise and personality for this mode. This description shapes how Cline presents itself and approaches tasks.
handleAgentPromptChange(activeTab, e)} rows={4} resize="vertical" style={{ width: "100%" }} data-testid={`${activeTab}-prompt-textarea`} />
Mode-specific Custom Instructions
Add behavioral guidelines specific to {activeTab} mode. These instructions enhance the base behaviors defined above.
{ const prompt = customPrompts?.[activeTab] return typeof prompt === "object" ? (prompt.customInstructions ?? "") : "" })()} onChange={(e) => { const value = (e as CustomEvent)?.detail?.target?.value || ((e as any).target as HTMLTextAreaElement).value const existingPrompt = customPrompts?.[activeTab] updateAgentPrompt(activeTab, { ...(typeof existingPrompt === "object" ? existingPrompt : {}), customInstructions: value.trim() || undefined, }) }} rows={4} resize="vertical" style={{ width: "100%" }} data-testid={`${activeTab}-custom-instructions-textarea`} />
Custom instructions specific to {activeTab} mode can also be loaded from{" "} { // First create/update the file with current custom instructions const defaultContent = `# ${activeTab} Mode Rules\n\nAdd mode-specific rules and guidelines here.` const existingPrompt = customPrompts?.[activeTab] const existingInstructions = typeof existingPrompt === "object" ? existingPrompt.customInstructions : undefined vscode.postMessage({ type: "updatePrompt", promptMode: activeTab, customPrompt: { ...(typeof existingPrompt === "object" ? existingPrompt : {}), customInstructions: existingInstructions || defaultContent, }, }) // Then open the file vscode.postMessage({ type: "openFile", text: `./.clinerules-${activeTab}`, values: { create: true, content: "", }, }) }}> .clinerules-{activeTab} {" "} in your workspace.
{ vscode.postMessage({ type: "getSystemPrompt", mode: activeTab, }) }} data-testid="preview-prompt-button"> Preview System Prompt

Prompt Enhancement

Use prompt enhancement to get tailored suggestions or improvements for your inputs. This ensures Cline understands your intent and provides the best possible responses.
API Configuration
You can select an API configuration to always use for enhancing prompts, or just use whatever is currently selected
{ const value = e.detail?.target?.value || e.target?.value setEnhancementApiConfigId(value) vscode.postMessage({ type: "enhancementApiConfigId", text: value, }) }} style={{ width: "300px" }}> Use currently selected API configuration {(listApiConfigMeta || []).map((config) => ( {config.name} ))}
Enhancement Prompt
This prompt will be used to refine your input when you hit the sparkle icon in chat.
setTestPrompt((e.target as HTMLTextAreaElement).value)} placeholder="Enter a prompt to test the enhancement" rows={3} resize="vertical" style={{ width: "100%" }} data-testid="test-prompt-textarea" />
Preview Prompt Enhancement
{/* Bottom padding */}
{isDialogOpen && (
setIsDialogOpen(false)} style={{ position: "absolute", top: "20px", right: "20px", }}>

{selectedPromptTitle}

								{selectedPromptContent}
							
setIsDialogOpen(false)}>Close
)}
) } export default PromptsView