Skip to content

Commit 19df13c

Browse files
authored
Add a warning display when a system prompt override is active (#2804)
1 parent d2e5019 commit 19df13c

File tree

21 files changed

+75
-15
lines changed

21 files changed

+75
-15
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { ACTION_NAMES } from "../CodeActionProvider"
4949
import { Cline, ClineOptions } from "../Cline"
5050
import { getNonce } from "./getNonce"
5151
import { getUri } from "./getUri"
52+
import { getSystemPromptFilePath } from "../prompts/sections/custom-system-prompt"
5253
import { telemetryService } from "../../services/telemetry/TelemetryService"
5354
import { getWorkspacePath } from "../../utils/path"
5455
import { webviewMessageHandler } from "./webviewMessageHandler"
@@ -1161,6 +1162,14 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
11611162
this.postMessageToWebview({ type: "state", state })
11621163
}
11631164

1165+
/**
1166+
* Checks if there is a file-based system prompt override for the given mode
1167+
*/
1168+
async hasFileBasedSystemPromptOverride(mode: Mode): Promise<boolean> {
1169+
const promptFilePath = getSystemPromptFilePath(this.cwd, mode)
1170+
return await fileExistsAtPath(promptFilePath)
1171+
}
1172+
11641173
async getStateToPostToWebview() {
11651174
const {
11661175
apiConfiguration,
@@ -1224,6 +1233,10 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
12241233
const allowedCommands = vscode.workspace.getConfiguration("roo-cline").get<string[]>("allowedCommands") || []
12251234
const cwd = this.cwd
12261235

1236+
// Check if there's a system prompt override for the current mode
1237+
const currentMode = mode ?? defaultModeSlug
1238+
const hasSystemPromptOverride = await this.hasFileBasedSystemPromptOverride(currentMode)
1239+
12271240
return {
12281241
version: this.context.extension?.packageJSON?.version ?? "",
12291242
apiConfiguration,
@@ -1296,6 +1309,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
12961309
renderContext: this.renderContext,
12971310
maxReadFileLine: maxReadFileLine ?? 500,
12981311
settingsImportedAt: this.settingsImportedAt,
1312+
hasSystemPromptOverride,
12991313
}
13001314
}
13011315

src/shared/WebviewMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export interface WebviewMessage {
150150
source?: "global" | "project"
151151
requestId?: string
152152
ids?: string[]
153+
hasSystemPromptOverride?: boolean
153154
}
154155

155156
export const checkoutDiffPayloadSchema = z.object({

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import ChatRow from "./ChatRow"
2727
import ChatTextArea from "./ChatTextArea"
2828
import TaskHeader from "./TaskHeader"
2929
import AutoApproveMenu from "./AutoApproveMenu"
30+
import SystemPromptWarning from "./SystemPromptWarning"
3031
import { AudioType } from "@roo/shared/WebviewMessage"
3132
import { validateCommand } from "@src/utils/command-validation"
3233
import { getAllModes } from "@roo/shared/modes"
@@ -77,6 +78,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
7778
alwaysAllowSubtasks,
7879
customModes,
7980
telemetrySetting,
81+
hasSystemPromptOverride,
8082
} = useExtensionState()
8183

8284
//const task = messages.length > 0 ? (messages[0].say === "task" ? messages[0] : undefined) : undefined) : undefined
@@ -1205,6 +1207,13 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
12051207
onClose={handleTaskCloseButtonClick}
12061208
/>
12071209

1210+
{/* System prompt override warning */}
1211+
{hasSystemPromptOverride && (
1212+
<div className="px-3">
1213+
<SystemPromptWarning />
1214+
</div>
1215+
)}
1216+
12081217
{/* Checkpoint warning message */}
12091218
{showCheckpointWarning && (
12101219
<div className="px-3">
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from "react"
2+
import { useAppTranslation } from "@/i18n/TranslationContext"
3+
4+
export const SystemPromptWarning: React.FC = () => {
5+
const { t } = useAppTranslation()
6+
7+
return (
8+
<div className="flex items-center px-4 py-2 mb-2 text-sm rounded bg-vscode-editorWarning-foreground text-vscode-editor-background">
9+
<div className="flex items-center justify-center w-5 h-5 mr-2">
10+
<span className="codicon codicon-warning" />
11+
</div>
12+
<span>{t("chat:systemPromptWarning")}</span>
13+
</div>
14+
)
15+
}
16+
17+
export default SystemPromptWarning

webview-ui/src/context/ExtensionStateContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface ExtensionStateContextType extends ExtensionState {
1717
showWelcome: boolean
1818
theme: any
1919
mcpServers: McpServer[]
20+
hasSystemPromptOverride?: boolean
2021
currentCheckpoint?: string
2122
filePaths: string[]
2223
openedTabs: Array<{ label: string; isActive: boolean; path?: string }>

webview-ui/src/i18n/locales/ca/chat.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,6 @@
211211
"scrollUp": "Desplaçar amunt",
212212
"close": "Tancar navegador"
213213
}
214-
}
214+
},
215+
"systemPromptWarning": "ADVERTÈNCIA: S'ha activat una substitució personalitzada d'instruccions del sistema. Això pot trencar greument la funcionalitat i causar un comportament impredictible."
215216
}

webview-ui/src/i18n/locales/de/chat.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,6 @@
211211
"scrollUp": "Nach oben scrollen",
212212
"close": "Browser schließen"
213213
}
214-
}
214+
},
215+
"systemPromptWarning": "WARNUNG: Benutzerdefinierte Systemaufforderung aktiv. Dies kann die Funktionalität erheblich beeinträchtigen und zu unvorhersehbarem Verhalten führen."
215216
}

webview-ui/src/i18n/locales/en/chat.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,6 @@
211211
"scrollUp": "Scroll up",
212212
"close": "Close browser"
213213
}
214-
}
214+
},
215+
"systemPromptWarning": "WARNING: Custom system prompt override active. This can severely break functionality and cause unpredictable behavior."
215216
}

webview-ui/src/i18n/locales/es/chat.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,6 @@
211211
"scrollUp": "Desplazar hacia arriba",
212212
"close": "Cerrar navegador"
213213
}
214-
}
214+
},
215+
"systemPromptWarning": "ADVERTENCIA: Anulación de instrucciones del sistema personalizada activa. Esto puede romper gravemente la funcionalidad y causar un comportamiento impredecible."
215216
}

webview-ui/src/i18n/locales/fr/chat.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,6 @@
211211
"scrollUp": "Défiler vers le haut",
212212
"close": "Fermer le navigateur"
213213
}
214-
}
214+
},
215+
"systemPromptWarning": "AVERTISSEMENT : Remplacement d'instructions système personnalisées actif. Cela peut gravement perturber la fonctionnalité et provoquer un comportement imprévisible."
215216
}

0 commit comments

Comments
 (0)