Skip to content

Commit 795c3c0

Browse files
committed
feat: add 'Add and Run' button for allowed commands (#5290)
- Added new 'Add and Run' button in ChatView that appears when hovering over code blocks containing allowed commands - Button extracts commands from code blocks and adds them to allowed commands list - Automatically switches to Settings view after adding commands - Added comprehensive test coverage for the new functionality - Updated all locale files with new translation keys - Added utility function to extract command patterns from code blocks This implementation allows users to quickly add commands from AI responses to their allowed commands list with a single click.
1 parent 70726bc commit 795c3c0

30 files changed

+1761
-346
lines changed

src/core/assistant-message/presentAssistantMessage.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,41 @@ export async function presentAssistantMessage(cline: Task) {
271271
isProtected || false,
272272
)
273273

274+
// Handle "Add & Run" button for command approval
275+
if (response === "addAndRunButtonClicked" && type === "command") {
276+
// The text field contains the extracted command pattern when "Add & Run" is clicked
277+
if (text) {
278+
// Add the command pattern to allowed commands
279+
const provider = cline.providerRef.deref()
280+
if (provider) {
281+
// Get current allowed commands
282+
const currentState = await provider.getState()
283+
const currentAllowedCommands = currentState.allowedCommands || []
284+
285+
// Add the new pattern if it's not already in the list
286+
if (!currentAllowedCommands.includes(text)) {
287+
const updatedCommands = [...currentAllowedCommands, text]
288+
289+
// Update global state using contextProxy
290+
await provider.contextProxy.setValue("allowedCommands", updatedCommands)
291+
292+
// Also update workspace settings
293+
const vscode = await import("vscode")
294+
const { Package } = await import("../../shared/package")
295+
await vscode.workspace
296+
.getConfiguration(Package.name)
297+
.update("allowedCommands", updatedCommands, vscode.ConfigurationTarget.Global)
298+
299+
// Post state update to webview
300+
await provider.postStateToWebview()
301+
}
302+
}
303+
}
304+
305+
// Return true to indicate approval and continue with command execution
306+
return true
307+
}
308+
274309
if (response !== "yesButtonClicked") {
275310
// Handle both messageResponse and noButtonClicked with text.
276311
if (text) {

0 commit comments

Comments
 (0)