Skip to content

Commit 18fe01b

Browse files
committed
Add 'copySystemPrompt' functionality and refactor system prompt generation
1 parent 4aa43d0 commit 18fe01b

File tree

3 files changed

+85
-55
lines changed

3 files changed

+85
-55
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 58 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,47 +1265,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
12651265
break
12661266
case "getSystemPrompt":
12671267
try {
1268-
const {
1269-
apiConfiguration,
1270-
customModePrompts,
1271-
customInstructions,
1272-
preferredLanguage,
1273-
browserViewportSize,
1274-
diffEnabled,
1275-
mcpEnabled,
1276-
fuzzyMatchThreshold,
1277-
experiments,
1278-
enableMcpServerCreation,
1279-
} = await this.getState()
1280-
1281-
// Create diffStrategy based on current model and settings
1282-
const diffStrategy = getDiffStrategy(
1283-
apiConfiguration.apiModelId || apiConfiguration.openRouterModelId || "",
1284-
fuzzyMatchThreshold,
1285-
Experiments.isEnabled(experiments, EXPERIMENT_IDS.DIFF_STRATEGY),
1286-
)
1287-
const cwd =
1288-
vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) || ""
1289-
1290-
const mode = message.mode ?? defaultModeSlug
1291-
const customModes = await this.customModesManager.getCustomModes()
1292-
1293-
const systemPrompt = await SYSTEM_PROMPT(
1294-
this.context,
1295-
cwd,
1296-
apiConfiguration.openRouterModelInfo?.supportsComputerUse ?? false,
1297-
mcpEnabled ? this.mcpHub : undefined,
1298-
diffStrategy,
1299-
browserViewportSize ?? "900x600",
1300-
mode,
1301-
customModePrompts,
1302-
customModes,
1303-
customInstructions,
1304-
preferredLanguage,
1305-
diffEnabled,
1306-
experiments,
1307-
enableMcpServerCreation,
1308-
)
1268+
const systemPrompt = await generateSystemPrompt(message)
13091269

13101270
await this.postMessageToWebview({
13111271
type: "systemPrompt",
@@ -1319,6 +1279,19 @@ export class ClineProvider implements vscode.WebviewViewProvider {
13191279
vscode.window.showErrorMessage("Failed to get system prompt")
13201280
}
13211281
break
1282+
case "copySystemPrompt":
1283+
try {
1284+
const systemPrompt = await generateSystemPrompt(message)
1285+
1286+
await vscode.env.clipboard.writeText(systemPrompt)
1287+
await vscode.window.showInformationMessage("System prompt successfully copied to clipboard")
1288+
} catch (error) {
1289+
this.outputChannel.appendLine(
1290+
`Error getting system prompt: ${JSON.stringify(error, Object.getOwnPropertyNames(error), 2)}`,
1291+
)
1292+
vscode.window.showErrorMessage("Failed to get system prompt")
1293+
}
1294+
break
13221295
case "searchCommits": {
13231296
const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0)
13241297
if (cwd) {
@@ -1524,6 +1497,50 @@ export class ClineProvider implements vscode.WebviewViewProvider {
15241497
null,
15251498
this.disposables,
15261499
)
1500+
1501+
const generateSystemPrompt = async (message: WebviewMessage) => {
1502+
const {
1503+
apiConfiguration,
1504+
customModePrompts,
1505+
customInstructions,
1506+
preferredLanguage,
1507+
browserViewportSize,
1508+
diffEnabled,
1509+
mcpEnabled,
1510+
fuzzyMatchThreshold,
1511+
experiments,
1512+
enableMcpServerCreation,
1513+
} = await this.getState()
1514+
1515+
// Create diffStrategy based on current model and settings
1516+
const diffStrategy = getDiffStrategy(
1517+
apiConfiguration.apiModelId || apiConfiguration.openRouterModelId || "",
1518+
fuzzyMatchThreshold,
1519+
Experiments.isEnabled(experiments, EXPERIMENT_IDS.DIFF_STRATEGY),
1520+
)
1521+
const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) || ""
1522+
1523+
const mode = message.mode ?? defaultModeSlug
1524+
const customModes = await this.customModesManager.getCustomModes()
1525+
1526+
const systemPrompt = await SYSTEM_PROMPT(
1527+
this.context,
1528+
cwd,
1529+
apiConfiguration.openRouterModelInfo?.supportsComputerUse ?? false,
1530+
mcpEnabled ? this.mcpHub : undefined,
1531+
diffStrategy,
1532+
browserViewportSize ?? "900x600",
1533+
mode,
1534+
customModePrompts,
1535+
customModes,
1536+
customInstructions,
1537+
preferredLanguage,
1538+
diffEnabled,
1539+
experiments,
1540+
enableMcpServerCreation,
1541+
)
1542+
return systemPrompt
1543+
}
15271544
}
15281545

15291546
/**

src/shared/WebviewMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export interface WebviewMessage {
8181
| "updateSupportPrompt"
8282
| "resetSupportPrompt"
8383
| "getSystemPrompt"
84+
| "copySystemPrompt"
8485
| "systemPrompt"
8586
| "enhancementApiConfigId"
8687
| "updateExperimental"

webview-ui/src/components/prompts/PromptsView.tsx

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -852,23 +852,35 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
852852
paddingBottom: "40px",
853853
marginBottom: "20px",
854854
borderBottom: "1px solid var(--vscode-input-border)",
855-
display: "flex",
856-
justifyContent: "flex-start",
857855
}}>
858-
<VSCodeButton
859-
appearance="primary"
860-
onClick={() => {
861-
const currentMode = getCurrentMode()
862-
if (currentMode) {
856+
<div style={{ display: "flex", gap: "8px" }}>
857+
<VSCodeButton
858+
appearance="primary"
859+
onClick={() => {
860+
const currentMode = getCurrentMode()
861+
if (currentMode) {
862+
vscode.postMessage({
863+
type: "getSystemPrompt",
864+
mode: currentMode.slug,
865+
})
866+
}
867+
}}
868+
data-testid="preview-prompt-button">
869+
Preview System Prompt
870+
</VSCodeButton>
871+
<VSCodeButton
872+
appearance="icon"
873+
title="Copy system prompt to clipboard"
874+
onClick={() => {
863875
vscode.postMessage({
864-
type: "getSystemPrompt",
865-
mode: currentMode.slug,
876+
type: "copySystemPrompt",
877+
text: selectedPromptContent,
866878
})
867-
}
868-
}}
869-
data-testid="preview-prompt-button">
870-
Preview System Prompt
871-
</VSCodeButton>
879+
}}
880+
data-testid="copy-prompt-button">
881+
<span className="codicon codicon-copy"></span>
882+
</VSCodeButton>
883+
</div>
872884
</div>
873885

874886
<div

0 commit comments

Comments
 (0)