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
99 changes: 58 additions & 41 deletions src/core/webview/ClineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1265,47 +1265,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
break
case "getSystemPrompt":
try {
const {
apiConfiguration,
customModePrompts,
customInstructions,
preferredLanguage,
browserViewportSize,
diffEnabled,
mcpEnabled,
fuzzyMatchThreshold,
experiments,
enableMcpServerCreation,
} = await this.getState()

// Create diffStrategy based on current model and settings
const diffStrategy = getDiffStrategy(
apiConfiguration.apiModelId || apiConfiguration.openRouterModelId || "",
fuzzyMatchThreshold,
Experiments.isEnabled(experiments, EXPERIMENT_IDS.DIFF_STRATEGY),
)
const cwd =
vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) || ""

const mode = message.mode ?? defaultModeSlug
const customModes = await this.customModesManager.getCustomModes()

const systemPrompt = await SYSTEM_PROMPT(
this.context,
cwd,
apiConfiguration.openRouterModelInfo?.supportsComputerUse ?? false,
mcpEnabled ? this.mcpHub : undefined,
diffStrategy,
browserViewportSize ?? "900x600",
mode,
customModePrompts,
customModes,
customInstructions,
preferredLanguage,
diffEnabled,
experiments,
enableMcpServerCreation,
)
const systemPrompt = await generateSystemPrompt(message)

await this.postMessageToWebview({
type: "systemPrompt",
Expand All @@ -1319,6 +1279,19 @@ export class ClineProvider implements vscode.WebviewViewProvider {
vscode.window.showErrorMessage("Failed to get system prompt")
}
break
case "copySystemPrompt":
try {
const systemPrompt = await generateSystemPrompt(message)

await vscode.env.clipboard.writeText(systemPrompt)
await vscode.window.showInformationMessage("System prompt successfully copied to clipboard")
} catch (error) {
this.outputChannel.appendLine(
`Error getting system prompt: ${JSON.stringify(error, Object.getOwnPropertyNames(error), 2)}`,
)
vscode.window.showErrorMessage("Failed to get system prompt")
}
break
case "searchCommits": {
const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0)
if (cwd) {
Expand Down Expand Up @@ -1524,6 +1497,50 @@ export class ClineProvider implements vscode.WebviewViewProvider {
null,
this.disposables,
)

const generateSystemPrompt = async (message: WebviewMessage) => {
const {
apiConfiguration,
customModePrompts,
customInstructions,
preferredLanguage,
browserViewportSize,
diffEnabled,
mcpEnabled,
fuzzyMatchThreshold,
experiments,
enableMcpServerCreation,
} = await this.getState()

// Create diffStrategy based on current model and settings
const diffStrategy = getDiffStrategy(
apiConfiguration.apiModelId || apiConfiguration.openRouterModelId || "",
fuzzyMatchThreshold,
Experiments.isEnabled(experiments, EXPERIMENT_IDS.DIFF_STRATEGY),
)
const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) || ""

const mode = message.mode ?? defaultModeSlug
const customModes = await this.customModesManager.getCustomModes()

const systemPrompt = await SYSTEM_PROMPT(
this.context,
cwd,
apiConfiguration.openRouterModelInfo?.supportsComputerUse ?? false,
mcpEnabled ? this.mcpHub : undefined,
diffStrategy,
browserViewportSize ?? "900x600",
mode,
customModePrompts,
customModes,
customInstructions,
preferredLanguage,
diffEnabled,
experiments,
enableMcpServerCreation,
)
return systemPrompt
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/shared/WebviewMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export interface WebviewMessage {
| "updateSupportPrompt"
| "resetSupportPrompt"
| "getSystemPrompt"
| "copySystemPrompt"
| "systemPrompt"
| "enhancementApiConfigId"
| "updateExperimental"
Expand Down
40 changes: 26 additions & 14 deletions webview-ui/src/components/prompts/PromptsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -852,23 +852,35 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
paddingBottom: "40px",
marginBottom: "20px",
borderBottom: "1px solid var(--vscode-input-border)",
display: "flex",
justifyContent: "flex-start",
}}>
<VSCodeButton
appearance="primary"
onClick={() => {
const currentMode = getCurrentMode()
if (currentMode) {
<div style={{ display: "flex", gap: "8px" }}>
<VSCodeButton
appearance="primary"
onClick={() => {
const currentMode = getCurrentMode()
if (currentMode) {
vscode.postMessage({
type: "getSystemPrompt",
mode: currentMode.slug,
})
}
}}
data-testid="preview-prompt-button">
Preview System Prompt
</VSCodeButton>
<VSCodeButton
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding an accessibility attribute (e.g. an aria-label) to the copy system prompt button to improve accessibility, since the button only displays an icon.

appearance="icon"
title="Copy system prompt to clipboard"
onClick={() => {
vscode.postMessage({
type: "getSystemPrompt",
mode: currentMode.slug,
type: "copySystemPrompt",
text: selectedPromptContent,
})
}
}}
data-testid="preview-prompt-button">
Preview System Prompt
</VSCodeButton>
}}
data-testid="copy-prompt-button">
<span className="codicon codicon-copy"></span>
</VSCodeButton>
</div>
</div>

<div
Expand Down
Loading