|
@@ -17,6 +17,8 @@ import { findLast } from "../../shared/array"
|
|
|
import { ApiConfigMeta, ExtensionMessage } from "../../shared/ExtensionMessage"
|
|
import { ApiConfigMeta, ExtensionMessage } from "../../shared/ExtensionMessage"
|
|
|
import { HistoryItem } from "../../shared/HistoryItem"
|
|
import { HistoryItem } from "../../shared/HistoryItem"
|
|
|
import { WebviewMessage } from "../../shared/WebviewMessage"
|
|
import { WebviewMessage } from "../../shared/WebviewMessage"
|
|
|
|
|
+import { defaultPrompts } from "../../shared/modes"
|
|
|
|
|
+import { SYSTEM_PROMPT, addCustomInstructions } from "../prompts/system"
|
|
|
import { fileExistsAtPath } from "../../utils/fs"
|
|
import { fileExistsAtPath } from "../../utils/fs"
|
|
|
import { Cline } from "../Cline"
|
|
import { Cline } from "../Cline"
|
|
|
import { openMention } from "../mentions"
|
|
import { openMention } from "../mentions"
|
|
@@ -28,7 +30,7 @@ import { enhancePrompt } from "../../utils/enhance-prompt"
|
|
|
import { getCommitInfo, searchCommits, getWorkingState } from "../../utils/git"
|
|
import { getCommitInfo, searchCommits, getWorkingState } from "../../utils/git"
|
|
|
import { ConfigManager } from "../config/ConfigManager"
|
|
import { ConfigManager } from "../config/ConfigManager"
|
|
|
import { Mode } from "../prompts/types"
|
|
import { Mode } from "../prompts/types"
|
|
|
-import { codeMode } from "../prompts/system"
|
|
|
|
|
|
|
+import { codeMode, CustomPrompts } from "../../shared/modes"
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
|
|
https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
|
|
@@ -93,6 +95,8 @@ type GlobalStateKey =
|
|
|
| "listApiConfigMeta"
|
|
| "listApiConfigMeta"
|
|
|
| "mode"
|
|
| "mode"
|
|
|
| "modeApiConfigs"
|
|
| "modeApiConfigs"
|
|
|
|
|
+ | "customPrompts"
|
|
|
|
|
+ | "enhancementApiConfigId"
|
|
|
|
|
|
|
|
export const GlobalFileNames = {
|
|
export const GlobalFileNames = {
|
|
|
apiConversationHistory: "api_conversation_history.json",
|
|
apiConversationHistory: "api_conversation_history.json",
|
|
@@ -111,7 +115,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
private cline?: Cline
|
|
private cline?: Cline
|
|
|
private workspaceTracker?: WorkspaceTracker
|
|
private workspaceTracker?: WorkspaceTracker
|
|
|
mcpHub?: McpHub
|
|
mcpHub?: McpHub
|
|
|
- private latestAnnouncementId = "dec-10-2024" // update to some unique identifier when we add a new announcement
|
|
|
|
|
|
|
+ private latestAnnouncementId = "jan-13-2025-custom-prompt" // update to some unique identifier when we add a new announcement
|
|
|
configManager: ConfigManager
|
|
configManager: ConfigManager
|
|
|
|
|
|
|
|
constructor(
|
|
constructor(
|
|
@@ -727,6 +731,32 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
|
|
|
|
|
await this.postStateToWebview()
|
|
await this.postStateToWebview()
|
|
|
break
|
|
break
|
|
|
|
|
+ case "updatePrompt":
|
|
|
|
|
+ if (message.promptMode && message.customPrompt !== undefined) {
|
|
|
|
|
+ const existingPrompts = await this.getGlobalState("customPrompts") || {}
|
|
|
|
|
+
|
|
|
|
|
+ const updatedPrompts = {
|
|
|
|
|
+ ...existingPrompts,
|
|
|
|
|
+ [message.promptMode]: message.customPrompt
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ await this.updateGlobalState("customPrompts", updatedPrompts)
|
|
|
|
|
+
|
|
|
|
|
+ // Get current state and explicitly include customPrompts
|
|
|
|
|
+ const currentState = await this.getState()
|
|
|
|
|
+
|
|
|
|
|
+ const stateWithPrompts = {
|
|
|
|
|
+ ...currentState,
|
|
|
|
|
+ customPrompts: updatedPrompts
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Post state with prompts
|
|
|
|
|
+ this.view?.webview.postMessage({
|
|
|
|
|
+ type: "state",
|
|
|
|
|
+ state: stateWithPrompts
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ break
|
|
|
case "deleteMessage": {
|
|
case "deleteMessage": {
|
|
|
const answer = await vscode.window.showInformationMessage(
|
|
const answer = await vscode.window.showInformationMessage(
|
|
|
"What would you like to delete?",
|
|
"What would you like to delete?",
|
|
@@ -797,16 +827,28 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
await this.updateGlobalState("screenshotQuality", message.value)
|
|
await this.updateGlobalState("screenshotQuality", message.value)
|
|
|
await this.postStateToWebview()
|
|
await this.postStateToWebview()
|
|
|
break
|
|
break
|
|
|
|
|
+ case "enhancementApiConfigId":
|
|
|
|
|
+ await this.updateGlobalState("enhancementApiConfigId", message.text)
|
|
|
|
|
+ await this.postStateToWebview()
|
|
|
|
|
+ break
|
|
|
case "enhancePrompt":
|
|
case "enhancePrompt":
|
|
|
if (message.text) {
|
|
if (message.text) {
|
|
|
try {
|
|
try {
|
|
|
- const { apiConfiguration } = await this.getState()
|
|
|
|
|
- const enhanceConfig = {
|
|
|
|
|
- ...apiConfiguration,
|
|
|
|
|
- apiProvider: "openrouter" as const,
|
|
|
|
|
- openRouterModelId: "gpt-4o",
|
|
|
|
|
|
|
+ const { apiConfiguration, customPrompts, listApiConfigMeta, enhancementApiConfigId } = await this.getState()
|
|
|
|
|
+
|
|
|
|
|
+ // Try to get enhancement config first, fall back to current config
|
|
|
|
|
+ let configToUse: ApiConfiguration = apiConfiguration
|
|
|
|
|
+ if (enhancementApiConfigId) {
|
|
|
|
|
+ const config = listApiConfigMeta?.find(c => c.id === enhancementApiConfigId)
|
|
|
|
|
+ if (config?.name) {
|
|
|
|
|
+ const loadedConfig = await this.configManager.LoadConfig(config.name)
|
|
|
|
|
+ if (loadedConfig.apiProvider) {
|
|
|
|
|
+ configToUse = loadedConfig
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- const enhancedPrompt = await enhancePrompt(enhanceConfig, message.text)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const enhancedPrompt = await enhancePrompt(configToUse, message.text, customPrompts?.enhance)
|
|
|
await this.postMessageToWebview({
|
|
await this.postMessageToWebview({
|
|
|
type: "enhancedPrompt",
|
|
type: "enhancedPrompt",
|
|
|
text: enhancedPrompt
|
|
text: enhancedPrompt
|
|
@@ -814,11 +856,37 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error("Error enhancing prompt:", error)
|
|
console.error("Error enhancing prompt:", error)
|
|
|
vscode.window.showErrorMessage("Failed to enhance prompt")
|
|
vscode.window.showErrorMessage("Failed to enhance prompt")
|
|
|
|
|
+ await this.postMessageToWebview({
|
|
|
|
|
+ type: "enhancedPrompt"
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
break
|
|
break
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ case "getSystemPrompt":
|
|
|
|
|
+ try {
|
|
|
|
|
+ const { apiConfiguration, customPrompts, customInstructions, preferredLanguage, browserViewportSize, mcpEnabled } = await this.getState()
|
|
|
|
|
+ const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) || ''
|
|
|
|
|
+
|
|
|
|
|
+ const fullPrompt = await SYSTEM_PROMPT(
|
|
|
|
|
+ cwd,
|
|
|
|
|
+ apiConfiguration.openRouterModelInfo?.supportsComputerUse ?? false,
|
|
|
|
|
+ mcpEnabled ? this.mcpHub : undefined,
|
|
|
|
|
+ undefined,
|
|
|
|
|
+ browserViewportSize ?? "900x600",
|
|
|
|
|
+ message.mode,
|
|
|
|
|
+ customPrompts
|
|
|
|
|
+ ) + await addCustomInstructions(customInstructions ?? '', cwd, preferredLanguage)
|
|
|
|
|
+
|
|
|
|
|
+ await this.postMessageToWebview({
|
|
|
|
|
+ type: "systemPrompt",
|
|
|
|
|
+ text: fullPrompt,
|
|
|
|
|
+ mode: message.mode
|
|
|
|
|
+ })
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error("Error getting system prompt:", error)
|
|
|
|
|
+ vscode.window.showErrorMessage("Failed to get system prompt")
|
|
|
|
|
+ }
|
|
|
|
|
+ break
|
|
|
case "searchCommits": {
|
|
case "searchCommits": {
|
|
|
const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0)
|
|
const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0)
|
|
|
if (cwd) {
|
|
if (cwd) {
|
|
@@ -1482,6 +1550,8 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
currentApiConfigName,
|
|
currentApiConfigName,
|
|
|
listApiConfigMeta,
|
|
listApiConfigMeta,
|
|
|
mode,
|
|
mode,
|
|
|
|
|
+ customPrompts,
|
|
|
|
|
+ enhancementApiConfigId,
|
|
|
} = await this.getState()
|
|
} = await this.getState()
|
|
|
|
|
|
|
|
const allowedCommands = vscode.workspace
|
|
const allowedCommands = vscode.workspace
|
|
@@ -1500,11 +1570,11 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
uriScheme: vscode.env.uriScheme,
|
|
uriScheme: vscode.env.uriScheme,
|
|
|
clineMessages: this.cline?.clineMessages || [],
|
|
clineMessages: this.cline?.clineMessages || [],
|
|
|
taskHistory: (taskHistory || [])
|
|
taskHistory: (taskHistory || [])
|
|
|
- .filter((item) => item.ts && item.task)
|
|
|
|
|
- .sort((a, b) => b.ts - a.ts),
|
|
|
|
|
|
|
+ .filter((item: HistoryItem) => item.ts && item.task)
|
|
|
|
|
+ .sort((a: HistoryItem, b: HistoryItem) => b.ts - a.ts),
|
|
|
soundEnabled: soundEnabled ?? false,
|
|
soundEnabled: soundEnabled ?? false,
|
|
|
diffEnabled: diffEnabled ?? true,
|
|
diffEnabled: diffEnabled ?? true,
|
|
|
- shouldShowAnnouncement: false, // lastShownAnnouncementId !== this.latestAnnouncementId,
|
|
|
|
|
|
|
+ shouldShowAnnouncement: lastShownAnnouncementId !== this.latestAnnouncementId,
|
|
|
allowedCommands,
|
|
allowedCommands,
|
|
|
soundVolume: soundVolume ?? 0.5,
|
|
soundVolume: soundVolume ?? 0.5,
|
|
|
browserViewportSize: browserViewportSize ?? "900x600",
|
|
browserViewportSize: browserViewportSize ?? "900x600",
|
|
@@ -1519,6 +1589,8 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
currentApiConfigName: currentApiConfigName ?? "default",
|
|
currentApiConfigName: currentApiConfigName ?? "default",
|
|
|
listApiConfigMeta: listApiConfigMeta ?? [],
|
|
listApiConfigMeta: listApiConfigMeta ?? [],
|
|
|
mode: mode ?? codeMode,
|
|
mode: mode ?? codeMode,
|
|
|
|
|
+ customPrompts: customPrompts ?? {},
|
|
|
|
|
+ enhancementApiConfigId,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1630,6 +1702,8 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
listApiConfigMeta,
|
|
listApiConfigMeta,
|
|
|
mode,
|
|
mode,
|
|
|
modeApiConfigs,
|
|
modeApiConfigs,
|
|
|
|
|
+ customPrompts,
|
|
|
|
|
+ enhancementApiConfigId,
|
|
|
] = await Promise.all([
|
|
] = await Promise.all([
|
|
|
this.getGlobalState("apiProvider") as Promise<ApiProvider | undefined>,
|
|
this.getGlobalState("apiProvider") as Promise<ApiProvider | undefined>,
|
|
|
this.getGlobalState("apiModelId") as Promise<string | undefined>,
|
|
this.getGlobalState("apiModelId") as Promise<string | undefined>,
|
|
@@ -1686,6 +1760,8 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
this.getGlobalState("listApiConfigMeta") as Promise<ApiConfigMeta[] | undefined>,
|
|
this.getGlobalState("listApiConfigMeta") as Promise<ApiConfigMeta[] | undefined>,
|
|
|
this.getGlobalState("mode") as Promise<Mode | undefined>,
|
|
this.getGlobalState("mode") as Promise<Mode | undefined>,
|
|
|
this.getGlobalState("modeApiConfigs") as Promise<Record<Mode, string> | undefined>,
|
|
this.getGlobalState("modeApiConfigs") as Promise<Record<Mode, string> | undefined>,
|
|
|
|
|
+ this.getGlobalState("customPrompts") as Promise<CustomPrompts | undefined>,
|
|
|
|
|
+ this.getGlobalState("enhancementApiConfigId") as Promise<string | undefined>,
|
|
|
])
|
|
])
|
|
|
|
|
|
|
|
let apiProvider: ApiProvider
|
|
let apiProvider: ApiProvider
|
|
@@ -1786,6 +1862,8 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
currentApiConfigName: currentApiConfigName ?? "default",
|
|
currentApiConfigName: currentApiConfigName ?? "default",
|
|
|
listApiConfigMeta: listApiConfigMeta ?? [],
|
|
listApiConfigMeta: listApiConfigMeta ?? [],
|
|
|
modeApiConfigs: modeApiConfigs ?? {} as Record<Mode, string>,
|
|
modeApiConfigs: modeApiConfigs ?? {} as Record<Mode, string>,
|
|
|
|
|
+ customPrompts: customPrompts ?? {},
|
|
|
|
|
+ enhancementApiConfigId,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|