Improve auto-approve menu design and remove unnecessary options (#7180)
This commit is contained in:
1 parent
1cfff0a45f
commit
9b1dc5bd92
56 files changed
+322
-739
No files matched your search
@@ -189,7 +189,7 @@ func renderAutoApprovalSettings(value interface{}, censor bool) error {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Print other fields normally (enabled, maxRequests, enableNotifications, favorites)
|
||||
// Print other fields normally (enabled, enableNotifications, favorites)
|
||||
fmt.Printf(" %s: %s\n", camelToKebab(key), formatValue(val, key, censor))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,8 +52,6 @@ func (h *AskHandler) Handle(msg *types.ClineMessage, dc *DisplayContext) error {
|
||||
return h.handleResumeCompletedTask(msg, dc)
|
||||
case string(types.AskTypeMistakeLimitReached):
|
||||
return h.handleMistakeLimitReached(msg, dc)
|
||||
case string(types.AskTypeAutoApprovalMaxReached):
|
||||
return h.handleAutoApprovalMaxReached(msg, dc)
|
||||
case string(types.AskTypeBrowserActionLaunch):
|
||||
return h.handleBrowserActionLaunch(msg, dc)
|
||||
case string(types.AskTypeUseMcpServer):
|
||||
@@ -255,25 +253,6 @@ func (h *AskHandler) handleMistakeLimitReached(msg *types.ClineMessage, dc *Disp
|
||||
return dc.Renderer.RenderMessage("ERROR", fmt.Sprintf("Mistake Limit Reached: %s. Approval required.", msg.Text), true)
|
||||
}
|
||||
|
||||
// handleAutoApprovalMaxReached handles auto-approval max reached
|
||||
func (h *AskHandler) handleAutoApprovalMaxReached(msg *types.ClineMessage, dc *DisplayContext) error {
|
||||
if dc.SystemRenderer != nil {
|
||||
details := make(map[string]string)
|
||||
if msg.Text != "" {
|
||||
details["reason"] = msg.Text
|
||||
}
|
||||
dc.SystemRenderer.RenderError(
|
||||
"warning",
|
||||
"Auto-Approval Limit Reached",
|
||||
"The maximum number of auto-approved requests has been reached. Manual approval is now required.",
|
||||
details,
|
||||
)
|
||||
fmt.Printf("\n**Approval required to continue.**\n")
|
||||
return nil
|
||||
}
|
||||
return dc.Renderer.RenderMessage("WARNING", fmt.Sprintf("Auto-approval limit reached: %s. Approval required.", msg.Text), true)
|
||||
}
|
||||
|
||||
// handleBrowserActionLaunch handles browser action launch requests
|
||||
func (h *AskHandler) handleBrowserActionLaunch(msg *types.ClineMessage, dc *DisplayContext) error {
|
||||
url := strings.TrimSpace(msg.Text)
|
||||
|
||||
@@ -282,7 +282,6 @@ func (m *Manager) CheckSendEnabled(ctx context.Context) error {
|
||||
errorTypes := []string{
|
||||
string(types.AskTypeAPIReqFailed), // "api_req_failed"
|
||||
string(types.AskTypeMistakeLimitReached), // "mistake_limit_reached"
|
||||
string(types.AskTypeAutoApprovalMaxReached), // "auto_approval_max_req_reached"
|
||||
}
|
||||
|
||||
isError := false
|
||||
@@ -1243,7 +1242,6 @@ func (m *Manager) UpdateTaskAutoApprovalAction(ctx context.Context, actionKey st
|
||||
|
||||
settings := &cline.Settings{
|
||||
AutoApprovalSettings: &cline.AutoApprovalSettings{
|
||||
Enabled: boolPtr(true),
|
||||
Actions: &cline.AutoApprovalActions{},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -416,18 +416,6 @@ func setNestedField(settings *cline.Settings, parentField string, childFields ma
|
||||
func setAutoApprovalSettings(settings *cline.AutoApprovalSettings, fields map[string]string) error {
|
||||
for key, value := range fields {
|
||||
switch key {
|
||||
case "enabled":
|
||||
val, err := parseBool(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
settings.Enabled = boolPtr(val)
|
||||
case "max_requests":
|
||||
val, err := parseInt32(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
settings.MaxRequests = int32Ptr(val)
|
||||
case "enable_notifications":
|
||||
val, err := parseBool(value)
|
||||
if err != nil {
|
||||
|
||||
@@ -37,17 +37,16 @@ const (
|
||||
type AskType string
|
||||
|
||||
const (
|
||||
AskTypeFollowup AskType = "followup"
|
||||
AskTypePlanModeRespond AskType = "plan_mode_respond"
|
||||
AskTypeCommand AskType = "command"
|
||||
AskTypeCommandOutput AskType = "command_output"
|
||||
AskTypeCompletionResult AskType = "completion_result"
|
||||
AskTypeTool AskType = "tool"
|
||||
AskTypeAPIReqFailed AskType = "api_req_failed"
|
||||
AskTypeResumeTask AskType = "resume_task"
|
||||
AskTypeResumeCompletedTask AskType = "resume_completed_task"
|
||||
AskTypeMistakeLimitReached AskType = "mistake_limit_reached"
|
||||
AskTypeAutoApprovalMaxReached AskType = "auto_approval_max_req_reached"
|
||||
AskTypeFollowup AskType = "followup"
|
||||
AskTypePlanModeRespond AskType = "plan_mode_respond"
|
||||
AskTypeCommand AskType = "command"
|
||||
AskTypeCommandOutput AskType = "command_output"
|
||||
AskTypeCompletionResult AskType = "completion_result"
|
||||
AskTypeTool AskType = "tool"
|
||||
AskTypeAPIReqFailed AskType = "api_req_failed"
|
||||
AskTypeResumeTask AskType = "resume_task"
|
||||
AskTypeResumeCompletedTask AskType = "resume_completed_task"
|
||||
AskTypeMistakeLimitReached AskType = "mistake_limit_reached"
|
||||
AskTypeBrowserActionLaunch AskType = "browser_action_launch"
|
||||
AskTypeUseMcpServer AskType = "use_mcp_server"
|
||||
AskTypeNewTask AskType = "new_task"
|
||||
@@ -247,8 +246,6 @@ func convertProtoAskType(askType cline.ClineAsk) string {
|
||||
return string(AskTypeResumeCompletedTask)
|
||||
case cline.ClineAsk_MISTAKE_LIMIT_REACHED:
|
||||
return string(AskTypeMistakeLimitReached)
|
||||
case cline.ClineAsk_AUTO_APPROVAL_MAX_REQ_REACHED:
|
||||
return string(AskTypeAutoApprovalMaxReached)
|
||||
case cline.ClineAsk_BROWSER_ACTION_LAUNCH:
|
||||
return string(AskTypeBrowserActionLaunch)
|
||||
case cline.ClineAsk_USE_MCP_SERVER:
|
||||
|
||||
+4
-10
@@ -46,11 +46,8 @@ message AutoApprovalActions {
|
||||
// Auto approval settings for task execution
|
||||
message AutoApprovalSettings {
|
||||
int32 version = 1;
|
||||
optional bool enabled = 2;
|
||||
AutoApprovalActions actions = 3;
|
||||
optional int32 max_requests = 4;
|
||||
optional bool enable_notifications = 5;
|
||||
repeated string favorites = 6;
|
||||
AutoApprovalActions actions = 2;
|
||||
optional bool enable_notifications = 3;
|
||||
}
|
||||
|
||||
message Secrets {
|
||||
@@ -283,11 +280,8 @@ message ResetStateRequest {
|
||||
message AutoApprovalSettingsRequest {
|
||||
Metadata metadata = 1;
|
||||
int32 version = 2;
|
||||
bool enabled = 3;
|
||||
AutoApprovalActions actions = 4;
|
||||
int32 max_requests = 5;
|
||||
bool enable_notifications = 6;
|
||||
repeated string favorites = 7;
|
||||
AutoApprovalActions actions = 3;
|
||||
bool enable_notifications = 4;
|
||||
}
|
||||
|
||||
enum TelemetrySettingEnum {
|
||||
|
||||
@@ -26,13 +26,12 @@ enum ClineAsk {
|
||||
RESUME_TASK = 7;
|
||||
RESUME_COMPLETED_TASK = 8;
|
||||
MISTAKE_LIMIT_REACHED = 9;
|
||||
AUTO_APPROVAL_MAX_REQ_REACHED = 10;
|
||||
BROWSER_ACTION_LAUNCH = 11;
|
||||
USE_MCP_SERVER = 12;
|
||||
NEW_TASK = 13;
|
||||
CONDENSE = 14;
|
||||
REPORT_BUG = 15;
|
||||
SUMMARIZE_TASK = 16;
|
||||
BROWSER_ACTION_LAUNCH = 10;
|
||||
USE_MCP_SERVER = 11;
|
||||
NEW_TASK = 12;
|
||||
CONDENSE = 13;
|
||||
REPORT_BUG = 14;
|
||||
SUMMARIZE_TASK = 15;
|
||||
}
|
||||
|
||||
// Enum for ClineSay types
|
||||
|
||||
@@ -19,10 +19,7 @@ export async function updateAutoApprovalSettings(controller: Controller, request
|
||||
const settings = {
|
||||
...currentSettings,
|
||||
...(request.version !== undefined && { version: request.version }),
|
||||
...(request.enabled !== undefined && { enabled: request.enabled }),
|
||||
...(request.maxRequests !== undefined && { maxRequests: request.maxRequests }),
|
||||
...(request.enableNotifications !== undefined && { enableNotifications: request.enableNotifications }),
|
||||
...(request.favorites && request.favorites.length > 0 && { favorites: request.favorites }),
|
||||
actions: {
|
||||
...currentSettings.actions,
|
||||
...(request.actions
|
||||
@@ -31,16 +28,6 @@ export async function updateAutoApprovalSettings(controller: Controller, request
|
||||
},
|
||||
}
|
||||
|
||||
if (controller.task) {
|
||||
const maxRequestsChanged =
|
||||
controller.stateManager.getGlobalSettingsKey("autoApprovalSettings").maxRequests !== settings.maxRequests
|
||||
|
||||
// Reset counter if max requests limit changed
|
||||
if (maxRequestsChanged) {
|
||||
controller.task.resetConsecutiveAutoApprovedRequestsCount()
|
||||
}
|
||||
}
|
||||
|
||||
controller.stateManager.setGlobalState("autoApprovalSettings", settings)
|
||||
|
||||
await controller.postStateToWebview()
|
||||
|
||||
@@ -87,13 +87,9 @@ export async function updateSettingsCli(controller: Controller, request: UpdateS
|
||||
const mergedSettings = {
|
||||
...currentAutoApprovalSettings,
|
||||
...(autoApprovalSettings.version !== undefined && { version: autoApprovalSettings.version }),
|
||||
...(autoApprovalSettings.enabled !== undefined && { enabled: autoApprovalSettings.enabled }),
|
||||
...(autoApprovalSettings.maxRequests !== undefined && { maxRequests: autoApprovalSettings.maxRequests }),
|
||||
...(autoApprovalSettings.enableNotifications !== undefined && {
|
||||
enableNotifications: autoApprovalSettings.enableNotifications,
|
||||
}),
|
||||
...(autoApprovalSettings.favorites &&
|
||||
autoApprovalSettings.favorites.length > 0 && { favorites: autoApprovalSettings.favorites }),
|
||||
actions: {
|
||||
...currentAutoApprovalSettings.actions,
|
||||
...(autoApprovalSettings.actions
|
||||
|
||||
@@ -76,13 +76,9 @@ export async function updateTaskSettings(controller: Controller, request: Update
|
||||
const mergedSettings = {
|
||||
...currentAutoApprovalSettings,
|
||||
...(autoApprovalSettings.version !== undefined && { version: autoApprovalSettings.version }),
|
||||
...(autoApprovalSettings.enabled !== undefined && { enabled: autoApprovalSettings.enabled }),
|
||||
...(autoApprovalSettings.maxRequests !== undefined && { maxRequests: autoApprovalSettings.maxRequests }),
|
||||
...(autoApprovalSettings.enableNotifications !== undefined && {
|
||||
enableNotifications: autoApprovalSettings.enableNotifications,
|
||||
}),
|
||||
...(autoApprovalSettings.favorites &&
|
||||
autoApprovalSettings.favorites.length > 0 && { favorites: autoApprovalSettings.favorites }),
|
||||
actions: {
|
||||
...currentAutoApprovalSettings.actions,
|
||||
...(autoApprovalSettings.actions
|
||||
|
||||
@@ -43,13 +43,9 @@ export async function newTask(controller: Controller, request: NewTaskRequest):
|
||||
return {
|
||||
...globalSettings,
|
||||
...(incomingSettings.version !== undefined && { version: incomingSettings.version }),
|
||||
...(incomingSettings.enabled !== undefined && { enabled: incomingSettings.enabled }),
|
||||
...(incomingSettings.maxRequests !== undefined && { maxRequests: incomingSettings.maxRequests }),
|
||||
...(incomingSettings.enableNotifications !== undefined && {
|
||||
enableNotifications: incomingSettings.enableNotifications,
|
||||
}),
|
||||
...(incomingSettings.favorites &&
|
||||
incomingSettings.favorites.length > 0 && { favorites: incomingSettings.favorites }),
|
||||
actions: {
|
||||
...globalSettings.actions,
|
||||
...(incomingSettings.actions
|
||||
|
||||
@@ -42,9 +42,6 @@ Otherwise, if you have not completed the task and do not need additional informa
|
||||
tooManyMistakes: (feedback?: string) =>
|
||||
`You seem to be having trouble proceeding. The user has provided the following feedback to help guide you:\n<feedback>\n${feedback}\n</feedback>`,
|
||||
|
||||
autoApprovalMaxReached: (feedback?: string) =>
|
||||
`Auto-approval limit reached. The user has provided the following feedback to help guide you:\n<feedback>\n${feedback}\n</feedback>`,
|
||||
|
||||
missingToolParameterError: (paramName: string) =>
|
||||
`Missing value for required parameter '${paramName}'. Please retry with complete response.\n\n${toolUseInstructionsReminder}`,
|
||||
|
||||
|
||||
@@ -39,9 +39,6 @@ export class TaskState {
|
||||
didAlreadyUseTool = false
|
||||
didEditFile: boolean = false
|
||||
|
||||
// Consecutive request tracking
|
||||
consecutiveAutoApprovedRequestsCount: number = 0
|
||||
|
||||
// Error tracking
|
||||
consecutiveMistakeCount: number = 0
|
||||
didAutomaticallyRetryFailedApiRequest = false
|
||||
|
||||
+1
-57
@@ -497,10 +497,6 @@ export class Task {
|
||||
)
|
||||
}
|
||||
|
||||
public resetConsecutiveAutoApprovedRequestsCount(): void {
|
||||
this.taskState.consecutiveAutoApprovedRequestsCount = 0
|
||||
}
|
||||
|
||||
// Communicate with webview
|
||||
|
||||
// partial has three valid states true (partial message), false (completion of partial message), undefined (individual complete message)
|
||||
@@ -1130,7 +1126,6 @@ export class Task {
|
||||
includeFileDetails = false // we only need file details the first time
|
||||
|
||||
// The way this agentic loop works is that cline will be given a task that he then calls tools to complete. unless there's an attempt_completion call, we keep responding back to him with his tool's responses until he either attempt_completion or does not use anymore tools. If he does not use anymore tools, we ask him to consider if he's completed the task and then call attempt_completion, otherwise proceed with completing the task.
|
||||
// There is a MAX_REQUESTS_PER_TASK limit to prevent infinite requests, but Cline is prompted to finish the task as efficiently as he can.
|
||||
|
||||
//const totalCost = this.calculateApiCost(totalInputTokens, totalOutputTokens)
|
||||
if (didEndLoop) {
|
||||
@@ -2171,7 +2166,7 @@ export class Task {
|
||||
|
||||
if (this.taskState.consecutiveMistakeCount >= this.stateManager.getGlobalSettingsKey("maxConsecutiveMistakes")) {
|
||||
const autoApprovalSettings = this.stateManager.getGlobalSettingsKey("autoApprovalSettings")
|
||||
if (autoApprovalSettings.enabled && autoApprovalSettings.enableNotifications) {
|
||||
if (autoApprovalSettings.enableNotifications) {
|
||||
showSystemNotification({
|
||||
subtitle: "Error",
|
||||
message: "Cline is having trouble. Would you like to continue the task?",
|
||||
@@ -2215,57 +2210,6 @@ export class Task {
|
||||
this.taskState.autoRetryAttempts = 0 // need to reset this if the user chooses to manually retry after the mistake limit is reached
|
||||
}
|
||||
|
||||
const autoApprovalSettings = this.stateManager.getGlobalSettingsKey("autoApprovalSettings")
|
||||
|
||||
if (
|
||||
!this.stateManager.getGlobalSettingsKey("yoloModeToggled") &&
|
||||
autoApprovalSettings.enabled &&
|
||||
this.taskState.consecutiveAutoApprovedRequestsCount >= autoApprovalSettings.maxRequests
|
||||
) {
|
||||
if (autoApprovalSettings.enableNotifications) {
|
||||
showSystemNotification({
|
||||
subtitle: "Max Requests Reached",
|
||||
message: `Cline has auto-approved ${autoApprovalSettings.maxRequests.toString()} API requests.`,
|
||||
})
|
||||
}
|
||||
const { response, text, images, files } = await this.ask(
|
||||
"auto_approval_max_req_reached",
|
||||
`Cline has auto-approved ${autoApprovalSettings.maxRequests.toString()} API requests. Would you like to reset the count and proceed with the task?`,
|
||||
)
|
||||
// if we get past the promise it means the user approved and did not start a new task
|
||||
this.taskState.consecutiveAutoApprovedRequestsCount = 0
|
||||
|
||||
// Process user feedback if provided
|
||||
if (response === "messageResponse") {
|
||||
// Display the user's message in the chat UI
|
||||
await this.say("user_feedback", text, images, files)
|
||||
|
||||
// This userContent is for the *next* API call.
|
||||
const feedbackUserContent: UserContent = []
|
||||
feedbackUserContent.push({
|
||||
type: "text",
|
||||
text: formatResponse.autoApprovalMaxReached(text),
|
||||
})
|
||||
if (images && images.length > 0) {
|
||||
feedbackUserContent.push(...formatResponse.imageBlocks(images))
|
||||
}
|
||||
|
||||
let fileContentString = ""
|
||||
if (files && files.length > 0) {
|
||||
fileContentString = await processFilesIntoText(files)
|
||||
}
|
||||
|
||||
if (fileContentString) {
|
||||
feedbackUserContent.push({
|
||||
type: "text",
|
||||
text: fileContentString,
|
||||
})
|
||||
}
|
||||
|
||||
userContent = feedbackUserContent
|
||||
}
|
||||
}
|
||||
|
||||
// get previous api req's index to check token usage and determine if we need to truncate conversation history
|
||||
const previousApiReqIndex = findLastIndex(this.messageStateHandler.getClineMessages(), (m) => m.say === "api_req_started")
|
||||
|
||||
|
||||
@@ -62,30 +62,28 @@ export class AutoApprove {
|
||||
|
||||
const autoApprovalSettings = this.stateManager.getGlobalSettingsKey("autoApprovalSettings")
|
||||
|
||||
if (autoApprovalSettings.enabled) {
|
||||
switch (toolName) {
|
||||
case ClineDefaultTool.FILE_READ:
|
||||
case ClineDefaultTool.LIST_FILES:
|
||||
case ClineDefaultTool.LIST_CODE_DEF:
|
||||
case ClineDefaultTool.SEARCH:
|
||||
return [autoApprovalSettings.actions.readFiles, autoApprovalSettings.actions.readFilesExternally ?? false]
|
||||
case ClineDefaultTool.NEW_RULE:
|
||||
case ClineDefaultTool.FILE_NEW:
|
||||
case ClineDefaultTool.FILE_EDIT:
|
||||
return [autoApprovalSettings.actions.editFiles, autoApprovalSettings.actions.editFilesExternally ?? false]
|
||||
case ClineDefaultTool.BASH:
|
||||
return [
|
||||
autoApprovalSettings.actions.executeSafeCommands ?? false,
|
||||
autoApprovalSettings.actions.executeAllCommands ?? false,
|
||||
]
|
||||
case ClineDefaultTool.BROWSER:
|
||||
return autoApprovalSettings.actions.useBrowser
|
||||
case ClineDefaultTool.WEB_FETCH:
|
||||
return autoApprovalSettings.actions.useBrowser
|
||||
case ClineDefaultTool.MCP_ACCESS:
|
||||
case ClineDefaultTool.MCP_USE:
|
||||
return autoApprovalSettings.actions.useMcp
|
||||
}
|
||||
switch (toolName) {
|
||||
case ClineDefaultTool.FILE_READ:
|
||||
case ClineDefaultTool.LIST_FILES:
|
||||
case ClineDefaultTool.LIST_CODE_DEF:
|
||||
case ClineDefaultTool.SEARCH:
|
||||
return [autoApprovalSettings.actions.readFiles, autoApprovalSettings.actions.readFilesExternally ?? false]
|
||||
case ClineDefaultTool.NEW_RULE:
|
||||
case ClineDefaultTool.FILE_NEW:
|
||||
case ClineDefaultTool.FILE_EDIT:
|
||||
return [autoApprovalSettings.actions.editFiles, autoApprovalSettings.actions.editFilesExternally ?? false]
|
||||
case ClineDefaultTool.BASH:
|
||||
return [
|
||||
autoApprovalSettings.actions.executeSafeCommands ?? false,
|
||||
autoApprovalSettings.actions.executeAllCommands ?? false,
|
||||
]
|
||||
case ClineDefaultTool.BROWSER:
|
||||
return autoApprovalSettings.actions.useBrowser
|
||||
case ClineDefaultTool.WEB_FETCH:
|
||||
return autoApprovalSettings.actions.useBrowser
|
||||
case ClineDefaultTool.MCP_ACCESS:
|
||||
case ClineDefaultTool.MCP_USE:
|
||||
return autoApprovalSettings.actions.useMcp
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ClineAsk, ClineAskUseMcpServer } from "@shared/ExtensionMessage"
|
||||
import { telemetryService } from "@/services/telemetry"
|
||||
import { ClineDefaultTool } from "@/shared/tools"
|
||||
import type { ToolResponse } from "../../index"
|
||||
import { showNotificationForApprovalIfAutoApprovalEnabled } from "../../utils"
|
||||
import { showNotificationForApproval } from "../../utils"
|
||||
import type { IFullyManagedTool } from "../ToolExecutorCoordinator"
|
||||
import type { TaskConfig } from "../types/TaskConfig"
|
||||
import type { StronglyTypedUIHelpers } from "../types/UIHelpers"
|
||||
@@ -73,9 +73,6 @@ export class AccessMcpResourceHandler implements IFullyManagedTool {
|
||||
// Auto-approval flow
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("ask", "use_mcp_server")
|
||||
await config.callbacks.say("use_mcp_server", completeMessage, undefined, undefined, false)
|
||||
if (!config.yoloModeToggled) {
|
||||
config.taskState.consecutiveAutoApprovedRequestsCount++
|
||||
}
|
||||
|
||||
// Capture telemetry
|
||||
telemetryService.captureToolUsage(config.ulid, block.name, config.api.getModel().id, true, true)
|
||||
@@ -84,11 +81,7 @@ export class AccessMcpResourceHandler implements IFullyManagedTool {
|
||||
const notificationMessage = `Cline wants to access ${uri || "unknown resource"} on ${server_name || "unknown server"}`
|
||||
|
||||
// Show notification
|
||||
showNotificationForApprovalIfAutoApprovalEnabled(
|
||||
notificationMessage,
|
||||
config.autoApprovalSettings.enabled,
|
||||
config.autoApprovalSettings.enableNotifications,
|
||||
)
|
||||
showNotificationForApproval(notificationMessage, config.autoApprovalSettings.enableNotifications)
|
||||
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("say", "use_mcp_server")
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import { telemetryService } from "@/services/telemetry"
|
||||
import { ClineDefaultTool } from "@/shared/tools"
|
||||
import { isLocatedInWorkspace } from "@/utils/path"
|
||||
import type { ToolResponse } from "../../index"
|
||||
import { showNotificationForApprovalIfAutoApprovalEnabled } from "../../utils"
|
||||
import { showNotificationForApproval } from "../../utils"
|
||||
import type { IFullyManagedTool } from "../ToolExecutorCoordinator"
|
||||
import type { ToolValidator } from "../ToolValidator"
|
||||
import type { TaskConfig } from "../types/TaskConfig"
|
||||
@@ -946,15 +946,13 @@ export class ApplyPatchHandler implements IFullyManagedTool {
|
||||
|
||||
if (shouldAutoApprove) {
|
||||
await config.callbacks.say("tool", messageStr, undefined, undefined, false)
|
||||
config.taskState.consecutiveAutoApprovedRequestsCount++
|
||||
telemetryService.captureToolUsage(config.ulid, block.name, config.api.getModel().id, true, true)
|
||||
return true
|
||||
}
|
||||
|
||||
const fileCount = Object.keys(JSON.parse(messageStr).content.match(/\d+/)?.[0] || "0").length
|
||||
showNotificationForApprovalIfAutoApprovalEnabled(
|
||||
showNotificationForApproval(
|
||||
`Cline wants to apply a patch to ${fileCount} file(s)`,
|
||||
config.autoApprovalSettings.enabled,
|
||||
config.autoApprovalSettings.enableNotifications,
|
||||
)
|
||||
|
||||
|
||||
@@ -40,8 +40,8 @@ export class AskFollowupQuestionToolHandler implements IToolHandler, IPartialBlo
|
||||
}
|
||||
config.taskState.consecutiveMistakeCount = 0
|
||||
|
||||
// Show notification if auto-approval is enabled
|
||||
if (config.autoApprovalSettings.enabled && config.autoApprovalSettings.enableNotifications) {
|
||||
// Show notification if enabled
|
||||
if (config.autoApprovalSettings.enableNotifications) {
|
||||
showSystemNotification({
|
||||
subtitle: "Cline has a question...",
|
||||
message: question.replace(/\n/g, " "),
|
||||
|
||||
@@ -52,8 +52,8 @@ export class AttemptCompletionHandler implements IToolHandler, IPartialBlockHand
|
||||
|
||||
config.taskState.consecutiveMistakeCount = 0
|
||||
|
||||
// Show notification if auto-approval is enabled
|
||||
if (config.autoApprovalSettings.enabled && config.autoApprovalSettings.enableNotifications) {
|
||||
// Show notification if enabled
|
||||
if (config.autoApprovalSettings.enableNotifications) {
|
||||
showSystemNotification({
|
||||
subtitle: "Task Completed",
|
||||
message: result.replace(/\n/g, " "),
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ClineDefaultTool } from "@/shared/tools"
|
||||
import { ToolUse } from "../../../assistant-message"
|
||||
import { formatResponse } from "../../../prompts/responses"
|
||||
import { ToolResponse } from "../.."
|
||||
import { showNotificationForApprovalIfAutoApprovalEnabled } from "../../utils"
|
||||
import { showNotificationForApproval } from "../../utils"
|
||||
import type { IFullyManagedTool } from "../ToolExecutorCoordinator"
|
||||
import type { TaskConfig } from "../types/TaskConfig"
|
||||
import type { StronglyTypedUIHelpers } from "../types/UIHelpers"
|
||||
@@ -92,14 +92,10 @@ export class BrowserToolHandler implements IFullyManagedTool {
|
||||
if (autoApprover.shouldAutoApproveTool(block.name)) {
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("ask", "browser_action_launch")
|
||||
await config.callbacks.say("browser_action_launch", url, undefined, undefined, false)
|
||||
if (!config.yoloModeToggled) {
|
||||
config.taskState.consecutiveAutoApprovedRequestsCount++
|
||||
}
|
||||
} else {
|
||||
// Show notification for approval if auto approval enabled
|
||||
showNotificationForApprovalIfAutoApprovalEnabled(
|
||||
// Show notification for approval if enabled
|
||||
showNotificationForApproval(
|
||||
`Cline wants to use a browser and launch ${url}`,
|
||||
config.autoApprovalSettings.enabled,
|
||||
config.autoApprovalSettings.enableNotifications,
|
||||
)
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("say", "browser_action_launch")
|
||||
|
||||
@@ -30,8 +30,8 @@ export class CondenseHandler implements IToolHandler, IPartialBlockHandler {
|
||||
|
||||
config.taskState.consecutiveMistakeCount = 0
|
||||
|
||||
// Show notification if auto-approval is enabled
|
||||
if (config.autoApprovalSettings.enabled && config.autoApprovalSettings.enableNotifications) {
|
||||
// Show notification if enabled
|
||||
if (config.autoApprovalSettings.enableNotifications) {
|
||||
showSystemNotification({
|
||||
subtitle: "Cline wants to condense the conversation...",
|
||||
message: `Cline is suggesting to condense your conversation with: ${context}`,
|
||||
|
||||
@@ -9,7 +9,7 @@ import { fixModelHtmlEscaping } from "@utils/string"
|
||||
import { telemetryService } from "@/services/telemetry"
|
||||
import { ClineDefaultTool } from "@/shared/tools"
|
||||
import type { ToolResponse } from "../../index"
|
||||
import { showNotificationForApprovalIfAutoApprovalEnabled } from "../../utils"
|
||||
import { showNotificationForApproval } from "../../utils"
|
||||
import type { IFullyManagedTool } from "../ToolExecutorCoordinator"
|
||||
import type { ToolValidator } from "../ToolValidator"
|
||||
import type { TaskConfig } from "../types/TaskConfig"
|
||||
@@ -153,16 +153,12 @@ export class ExecuteCommandToolHandler implements IFullyManagedTool {
|
||||
// Auto-approve flow
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("ask", "command")
|
||||
await config.callbacks.say("command", actualCommand, undefined, undefined, false)
|
||||
if (!config.yoloModeToggled) {
|
||||
config.taskState.consecutiveAutoApprovedRequestsCount++
|
||||
}
|
||||
didAutoApprove = true
|
||||
telemetryService.captureToolUsage(config.ulid, block.name, config.api.getModel().id, true, true, workspaceContext)
|
||||
} else {
|
||||
// Manual approval flow
|
||||
showNotificationForApprovalIfAutoApprovalEnabled(
|
||||
showNotificationForApproval(
|
||||
`Cline wants to execute a command: ${actualCommand}`,
|
||||
config.autoApprovalSettings.enabled,
|
||||
config.autoApprovalSettings.enableNotifications,
|
||||
)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import { formatResponse } from "@/core/prompts/responses"
|
||||
import { telemetryService } from "@/services/telemetry"
|
||||
import { ClineDefaultTool } from "@/shared/tools"
|
||||
import type { ToolResponse } from "../../index"
|
||||
import { showNotificationForApprovalIfAutoApprovalEnabled } from "../../utils"
|
||||
import { showNotificationForApproval } from "../../utils"
|
||||
import type { IFullyManagedTool } from "../ToolExecutorCoordinator"
|
||||
import type { ToolValidator } from "../ToolValidator"
|
||||
import type { TaskConfig } from "../types/TaskConfig"
|
||||
@@ -81,9 +81,6 @@ export class ListCodeDefinitionNamesToolHandler implements IFullyManagedTool {
|
||||
// Auto-approval flow
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("ask", "tool")
|
||||
await config.callbacks.say("tool", completeMessage, undefined, undefined, false)
|
||||
if (!config.yoloModeToggled) {
|
||||
config.taskState.consecutiveAutoApprovedRequestsCount++
|
||||
}
|
||||
|
||||
// Capture telemetry
|
||||
telemetryService.captureToolUsage(config.ulid, block.name, config.api.getModel().id, true, true)
|
||||
@@ -92,11 +89,7 @@ export class ListCodeDefinitionNamesToolHandler implements IFullyManagedTool {
|
||||
const notificationMessage = `Cline wants to analyze code definitions in ${getWorkspaceBasename(absolutePath, "ListCodeDefinitionNamesToolHandler.notification")}`
|
||||
|
||||
// Show notification
|
||||
showNotificationForApprovalIfAutoApprovalEnabled(
|
||||
notificationMessage,
|
||||
config.autoApprovalSettings.enabled,
|
||||
config.autoApprovalSettings.enableNotifications,
|
||||
)
|
||||
showNotificationForApproval(notificationMessage, config.autoApprovalSettings.enableNotifications)
|
||||
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("say", "tool")
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { arePathsEqual, getReadablePath, isLocatedInWorkspace } from "@utils/pat
|
||||
import { telemetryService } from "@/services/telemetry"
|
||||
import { ClineDefaultTool } from "@/shared/tools"
|
||||
import type { ToolResponse } from "../../index"
|
||||
import { showNotificationForApprovalIfAutoApprovalEnabled } from "../../utils"
|
||||
import { showNotificationForApproval } from "../../utils"
|
||||
import type { IFullyManagedTool } from "../ToolExecutorCoordinator"
|
||||
import type { ToolValidator } from "../ToolValidator"
|
||||
import type { TaskConfig } from "../types/TaskConfig"
|
||||
@@ -98,9 +98,6 @@ export class ListFilesToolHandler implements IFullyManagedTool {
|
||||
// Auto-approval flow
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("ask", "tool")
|
||||
await config.callbacks.say("tool", completeMessage, undefined, undefined, false)
|
||||
if (!config.yoloModeToggled) {
|
||||
config.taskState.consecutiveAutoApprovedRequestsCount++
|
||||
}
|
||||
|
||||
// Capture telemetry
|
||||
telemetryService.captureToolUsage(config.ulid, block.name, config.api.getModel().id, true, true, workspaceContext)
|
||||
@@ -109,11 +106,7 @@ export class ListFilesToolHandler implements IFullyManagedTool {
|
||||
const notificationMessage = `Cline wants to view directory ${getWorkspaceBasename(absolutePath, "ListFilesToolHandler.notification")}/`
|
||||
|
||||
// Show notification
|
||||
showNotificationForApprovalIfAutoApprovalEnabled(
|
||||
notificationMessage,
|
||||
config.autoApprovalSettings.enabled,
|
||||
config.autoApprovalSettings.enableNotifications,
|
||||
)
|
||||
showNotificationForApproval(notificationMessage, config.autoApprovalSettings.enableNotifications)
|
||||
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("say", "tool")
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ export class NewTaskHandler implements IToolHandler, IPartialBlockHandler {
|
||||
|
||||
config.taskState.consecutiveMistakeCount = 0
|
||||
|
||||
// Show notification if auto-approval is enabled
|
||||
if (config.autoApprovalSettings.enabled && config.autoApprovalSettings.enableNotifications) {
|
||||
// Show notification if enabled
|
||||
if (config.autoApprovalSettings.enableNotifications) {
|
||||
showSystemNotification({
|
||||
subtitle: "Cline wants to start a new task...",
|
||||
message: `Cline is suggesting to start a new task with: ${context}`,
|
||||
|
||||
@@ -8,7 +8,7 @@ import { telemetryService } from "@/services/telemetry"
|
||||
import { ClineSayTool } from "@/shared/ExtensionMessage"
|
||||
import { ClineDefaultTool } from "@/shared/tools"
|
||||
import type { ToolResponse } from "../../index"
|
||||
import { showNotificationForApprovalIfAutoApprovalEnabled } from "../../utils"
|
||||
import { showNotificationForApproval } from "../../utils"
|
||||
import type { IFullyManagedTool } from "../ToolExecutorCoordinator"
|
||||
import type { ToolValidator } from "../ToolValidator"
|
||||
import type { TaskConfig } from "../types/TaskConfig"
|
||||
@@ -96,9 +96,6 @@ export class ReadFileToolHandler implements IFullyManagedTool {
|
||||
// Auto-approval flow
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("ask", "tool")
|
||||
await config.callbacks.say("tool", completeMessage, undefined, undefined, false)
|
||||
if (!config.yoloModeToggled) {
|
||||
config.taskState.consecutiveAutoApprovedRequestsCount++
|
||||
}
|
||||
|
||||
// Capture telemetry
|
||||
telemetryService.captureToolUsage(config.ulid, block.name, config.api.getModel().id, true, true, workspaceContext)
|
||||
@@ -107,11 +104,7 @@ export class ReadFileToolHandler implements IFullyManagedTool {
|
||||
const notificationMessage = `Cline wants to read ${getWorkspaceBasename(absolutePath, "ReadFileToolHandler.notification")}`
|
||||
|
||||
// Show notification
|
||||
showNotificationForApprovalIfAutoApprovalEnabled(
|
||||
notificationMessage,
|
||||
config.autoApprovalSettings.enabled,
|
||||
config.autoApprovalSettings.enableNotifications,
|
||||
)
|
||||
showNotificationForApproval(notificationMessage, config.autoApprovalSettings.enableNotifications)
|
||||
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("say", "tool")
|
||||
|
||||
|
||||
@@ -64,8 +64,8 @@ export class ReportBugHandler implements IToolHandler, IPartialBlockHandler {
|
||||
|
||||
config.taskState.consecutiveMistakeCount = 0
|
||||
|
||||
// Show notification if auto-approval is enabled
|
||||
if (config.autoApprovalSettings.enabled && config.autoApprovalSettings.enableNotifications) {
|
||||
// Show notification if enabled
|
||||
if (config.autoApprovalSettings.enableNotifications) {
|
||||
showSystemNotification({
|
||||
subtitle: "Cline wants to create a github issue...",
|
||||
message: `Cline is suggesting to create a github issue with the title: ${title}`,
|
||||
|
||||
@@ -10,7 +10,7 @@ import { telemetryService } from "@/services/telemetry"
|
||||
import { ClineSayTool } from "@/shared/ExtensionMessage"
|
||||
import { ClineDefaultTool } from "@/shared/tools"
|
||||
import type { ToolResponse } from "../../index"
|
||||
import { showNotificationForApprovalIfAutoApprovalEnabled } from "../../utils"
|
||||
import { showNotificationForApproval } from "../../utils"
|
||||
import type { IFullyManagedTool } from "../ToolExecutorCoordinator"
|
||||
import type { ToolValidator } from "../ToolValidator"
|
||||
import type { TaskConfig } from "../types/TaskConfig"
|
||||
@@ -304,9 +304,6 @@ export class SearchFilesToolHandler implements IFullyManagedTool {
|
||||
// Auto-approval flow
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("ask", "tool")
|
||||
await config.callbacks.say("tool", completeMessage, undefined, undefined, false)
|
||||
if (!config.yoloModeToggled) {
|
||||
config.taskState.consecutiveAutoApprovedRequestsCount++
|
||||
}
|
||||
|
||||
// Capture telemetry
|
||||
telemetryService.captureToolUsage(config.ulid, block.name, config.api.getModel().id, true, true, workspaceContext)
|
||||
@@ -315,11 +312,7 @@ export class SearchFilesToolHandler implements IFullyManagedTool {
|
||||
const notificationMessage = `Cline wants to search files for ${regex}`
|
||||
|
||||
// Show notification
|
||||
showNotificationForApprovalIfAutoApprovalEnabled(
|
||||
notificationMessage,
|
||||
config.autoApprovalSettings.enabled,
|
||||
config.autoApprovalSettings.enableNotifications,
|
||||
)
|
||||
showNotificationForApproval(notificationMessage, config.autoApprovalSettings.enableNotifications)
|
||||
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("say", "tool")
|
||||
|
||||
|
||||
@@ -102,9 +102,6 @@ export class SummarizeTaskHandler implements IToolHandler, IPartialBlockHandler
|
||||
const { absolutePath, displayPath } =
|
||||
typeof pathResult === "string" ? { absolutePath: pathResult, displayPath: relPath } : pathResult
|
||||
|
||||
// Increment counter for successful auto-approved read
|
||||
config.taskState.consecutiveAutoApprovedRequestsCount++
|
||||
|
||||
// Read file content, we dont allow images to be read here
|
||||
// This throws if an image or if we can't read the file, implicitly skipping
|
||||
const fileContent = await extractFileContent(absolutePath, false)
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ClineAsk, ClineAskUseMcpServer } from "@shared/ExtensionMessage"
|
||||
import { telemetryService } from "@/services/telemetry"
|
||||
import { ClineDefaultTool } from "@/shared/tools"
|
||||
import type { ToolResponse } from "../../index"
|
||||
import { showNotificationForApprovalIfAutoApprovalEnabled } from "../../utils"
|
||||
import { showNotificationForApproval } from "../../utils"
|
||||
import type { IFullyManagedTool } from "../ToolExecutorCoordinator"
|
||||
import type { TaskConfig } from "../types/TaskConfig"
|
||||
import type { StronglyTypedUIHelpers } from "../types/UIHelpers"
|
||||
@@ -88,9 +88,6 @@ export class UseMcpToolHandler implements IFullyManagedTool {
|
||||
// Auto-approval flow
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("ask", "use_mcp_server")
|
||||
await config.callbacks.say("use_mcp_server", completeMessage, undefined, undefined, false)
|
||||
if (!config.yoloModeToggled) {
|
||||
config.taskState.consecutiveAutoApprovedRequestsCount++
|
||||
}
|
||||
|
||||
// Capture telemetry
|
||||
telemetryService.captureToolUsage(config.ulid, block.name, config.api.getModel().id, true, true)
|
||||
@@ -99,11 +96,7 @@ export class UseMcpToolHandler implements IFullyManagedTool {
|
||||
const notificationMessage = `Cline wants to use ${tool_name || "unknown tool"} on ${server_name || "unknown server"}`
|
||||
|
||||
// Show notification
|
||||
showNotificationForApprovalIfAutoApprovalEnabled(
|
||||
notificationMessage,
|
||||
config.autoApprovalSettings.enabled,
|
||||
config.autoApprovalSettings.enableNotifications,
|
||||
)
|
||||
showNotificationForApproval(notificationMessage, config.autoApprovalSettings.enableNotifications)
|
||||
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("say", "use_mcp_server")
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { telemetryService } from "@/services/telemetry"
|
||||
import { ToolUse } from "../../../assistant-message"
|
||||
import { formatResponse } from "../../../prompts/responses"
|
||||
import { ToolResponse } from "../.."
|
||||
import { showNotificationForApprovalIfAutoApprovalEnabled } from "../../utils"
|
||||
import { showNotificationForApproval } from "../../utils"
|
||||
import type { IFullyManagedTool } from "../ToolExecutorCoordinator"
|
||||
import type { TaskConfig } from "../types/TaskConfig"
|
||||
import type { StronglyTypedUIHelpers } from "../types/UIHelpers"
|
||||
@@ -59,15 +59,11 @@ export class WebFetchToolHandler implements IFullyManagedTool {
|
||||
// Auto-approve flow
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("ask", "tool")
|
||||
await config.callbacks.say("tool", completeMessage, undefined, undefined, false)
|
||||
if (!config.yoloModeToggled) {
|
||||
config.taskState.consecutiveAutoApprovedRequestsCount++
|
||||
}
|
||||
telemetryService.captureToolUsage(config.ulid, "web_fetch", config.api.getModel().id, true, true)
|
||||
} else {
|
||||
// Manual approval flow
|
||||
showNotificationForApprovalIfAutoApprovalEnabled(
|
||||
showNotificationForApproval(
|
||||
`Cline wants to fetch content from ${url}`,
|
||||
config.autoApprovalSettings.enabled,
|
||||
config.autoApprovalSettings.enableNotifications,
|
||||
)
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("say", "tool")
|
||||
|
||||
@@ -12,7 +12,7 @@ import { fixModelHtmlEscaping, removeInvalidChars } from "@utils/string"
|
||||
import { telemetryService } from "@/services/telemetry"
|
||||
import { ClineDefaultTool } from "@/shared/tools"
|
||||
import type { ToolResponse } from "../../index"
|
||||
import { showNotificationForApprovalIfAutoApprovalEnabled } from "../../utils"
|
||||
import { showNotificationForApproval } from "../../utils"
|
||||
import type { IFullyManagedTool } from "../ToolExecutorCoordinator"
|
||||
import type { ToolValidator } from "../ToolValidator"
|
||||
import type { TaskConfig } from "../types/TaskConfig"
|
||||
@@ -167,9 +167,6 @@ export class WriteToFileToolHandler implements IFullyManagedTool {
|
||||
// Auto-approval flow
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("ask", "tool")
|
||||
await config.callbacks.say("tool", completeMessage, undefined, undefined, false)
|
||||
if (!config.yoloModeToggled) {
|
||||
config.taskState.consecutiveAutoApprovedRequestsCount++
|
||||
}
|
||||
|
||||
// Capture telemetry
|
||||
telemetryService.captureToolUsage(config.ulid, block.name, config.api.getModel().id, true, true, workspaceContext)
|
||||
@@ -181,11 +178,7 @@ export class WriteToFileToolHandler implements IFullyManagedTool {
|
||||
const notificationMessage = `Cline wants to ${fileExists ? "edit" : "create"} ${getWorkspaceBasename(relPath, "WriteToFile.notification")}`
|
||||
|
||||
// Show notification
|
||||
showNotificationForApprovalIfAutoApprovalEnabled(
|
||||
notificationMessage,
|
||||
config.autoApprovalSettings.enabled,
|
||||
config.autoApprovalSettings.enableNotifications,
|
||||
)
|
||||
showNotificationForApproval(notificationMessage, config.autoApprovalSettings.enableNotifications)
|
||||
|
||||
await config.callbacks.removeLastPartialMessageIfExistsWithType("say", "tool")
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { ClineDefaultTool } from "@shared/tools"
|
||||
import type { ClineAskResponse } from "@shared/WebviewMessage"
|
||||
import { telemetryService } from "@/services/telemetry"
|
||||
import type { ToolParamName, ToolUse } from "../../../assistant-message"
|
||||
import { showNotificationForApprovalIfAutoApprovalEnabled } from "../../utils"
|
||||
import { showNotificationForApproval } from "../../utils"
|
||||
import { removeClosingTag } from "../utils/ToolConstants"
|
||||
import type { TaskConfig } from "./TaskConfig"
|
||||
|
||||
@@ -61,11 +61,7 @@ export function createUIHelpers(config: TaskConfig): StronglyTypedUIHelpers {
|
||||
telemetryService.captureToolUsage(config.ulid, toolName, config.api.getModel().id, autoApproved, approved)
|
||||
},
|
||||
showNotificationIfEnabled: (message: string) => {
|
||||
showNotificationForApprovalIfAutoApprovalEnabled(
|
||||
message,
|
||||
config.autoApprovalSettings.enabled,
|
||||
config.autoApprovalSettings.enableNotifications,
|
||||
)
|
||||
showNotificationForApproval(message, config.autoApprovalSettings.enableNotifications)
|
||||
},
|
||||
getConfig: () => config,
|
||||
}
|
||||
|
||||
@@ -5,12 +5,8 @@ import { ClineApiReqCancelReason, ClineApiReqInfo } from "@/shared/ExtensionMess
|
||||
import { calculateApiCostAnthropic } from "@/utils/cost"
|
||||
import { MessageStateHandler } from "./message-state"
|
||||
|
||||
export const showNotificationForApprovalIfAutoApprovalEnabled = (
|
||||
message: string,
|
||||
autoApprovalSettingsEnabled: boolean,
|
||||
notificationsEnabled: boolean,
|
||||
) => {
|
||||
if (autoApprovalSettingsEnabled && notificationsEnabled) {
|
||||
export const showNotificationForApproval = (message: string, notificationsEnabled: boolean) => {
|
||||
if (notificationsEnabled) {
|
||||
showSystemNotification({
|
||||
subtitle: "Approval Required",
|
||||
message,
|
||||
|
||||
@@ -54,7 +54,6 @@ async function updateAutoApprovalSettings(controller?: Controller) {
|
||||
// Enable all actions
|
||||
const updatedSettings: AutoApprovalSettings = {
|
||||
...(autoApprovalSettings || DEFAULT_AUTO_APPROVAL_SETTINGS),
|
||||
enabled: true,
|
||||
actions: {
|
||||
readFiles: true,
|
||||
readFilesExternally: true,
|
||||
@@ -65,7 +64,6 @@ async function updateAutoApprovalSettings(controller?: Controller) {
|
||||
useBrowser: false, // Keep browser disabled for tests
|
||||
useMcp: false, // Keep MCP disabled for tests
|
||||
},
|
||||
maxRequests: 10000, // Increase max requests for tests
|
||||
}
|
||||
|
||||
controller?.stateManager.setGlobalState("autoApprovalSettings", updatedSettings)
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
export interface AutoApprovalSettings {
|
||||
// Version for race condition prevention (incremented on every change)
|
||||
version: number
|
||||
// Whether auto-approval is enabled
|
||||
// Legacy field - kept for backward compatibility with older extension versions
|
||||
// Auto-approve is now always enabled by default
|
||||
enabled: boolean
|
||||
// Legacy field - kept for backward compatibility with older extension versions
|
||||
// Favorites feature has been removed
|
||||
favorites: string[]
|
||||
// Legacy field - kept for backward compatibility with older extension versions
|
||||
// Max requests limit feature has been removed
|
||||
maxRequests: number
|
||||
// Individual action permissions
|
||||
actions: {
|
||||
readFiles: boolean // Read files and directories in the working directory
|
||||
@@ -15,14 +22,14 @@ export interface AutoApprovalSettings {
|
||||
useMcp: boolean // Use MCP servers
|
||||
}
|
||||
// Global settings
|
||||
maxRequests: number // Maximum number of auto-approved requests
|
||||
enableNotifications: boolean // Show notifications for approval and task completion
|
||||
favorites: string[] // IDs of actions favorited by the user for quick access
|
||||
}
|
||||
|
||||
export const DEFAULT_AUTO_APPROVAL_SETTINGS: AutoApprovalSettings = {
|
||||
version: 1,
|
||||
enabled: true,
|
||||
enabled: true, // Legacy field - always true by default
|
||||
favorites: [], // Legacy field - kept as empty array
|
||||
maxRequests: 20, // Legacy field - kept for backward compatibility
|
||||
actions: {
|
||||
readFiles: true,
|
||||
readFilesExternally: false,
|
||||
@@ -31,9 +38,7 @@ export const DEFAULT_AUTO_APPROVAL_SETTINGS: AutoApprovalSettings = {
|
||||
executeSafeCommands: true,
|
||||
executeAllCommands: false,
|
||||
useBrowser: false,
|
||||
useMcp: false,
|
||||
useMcp: true,
|
||||
},
|
||||
maxRequests: 20,
|
||||
enableNotifications: false,
|
||||
favorites: ["enableAutoApprove", "readFiles", "editFiles"],
|
||||
}
|
||||
@@ -128,7 +128,6 @@ export type ClineAsk =
|
||||
| "resume_task"
|
||||
| "resume_completed_task"
|
||||
| "mistake_limit_reached"
|
||||
| "auto_approval_max_req_reached"
|
||||
| "browser_action_launch"
|
||||
| "use_mcp_server"
|
||||
| "new_task"
|
||||
|
||||
@@ -19,7 +19,6 @@ function convertClineAskToProtoEnum(ask: AppClineAsk | undefined): ClineAsk | un
|
||||
resume_task: ClineAsk.RESUME_TASK,
|
||||
resume_completed_task: ClineAsk.RESUME_COMPLETED_TASK,
|
||||
mistake_limit_reached: ClineAsk.MISTAKE_LIMIT_REACHED,
|
||||
auto_approval_max_req_reached: ClineAsk.AUTO_APPROVAL_MAX_REQ_REACHED,
|
||||
browser_action_launch: ClineAsk.BROWSER_ACTION_LAUNCH,
|
||||
use_mcp_server: ClineAsk.USE_MCP_SERVER,
|
||||
new_task: ClineAsk.NEW_TASK,
|
||||
@@ -53,7 +52,6 @@ function convertProtoEnumToClineAsk(ask: ClineAsk): AppClineAsk | undefined {
|
||||
[ClineAsk.RESUME_TASK]: "resume_task",
|
||||
[ClineAsk.RESUME_COMPLETED_TASK]: "resume_completed_task",
|
||||
[ClineAsk.MISTAKE_LIMIT_REACHED]: "mistake_limit_reached",
|
||||
[ClineAsk.AUTO_APPROVAL_MAX_REQ_REACHED]: "auto_approval_max_req_reached",
|
||||
[ClineAsk.BROWSER_ACTION_LAUNCH]: "browser_action_launch",
|
||||
[ClineAsk.USE_MCP_SERVER]: "use_mcp_server",
|
||||
[ClineAsk.NEW_TASK]: "new_task",
|
||||
|
||||
@@ -400,8 +400,6 @@ export const AutoApprovalEnabled: Story = {
|
||||
autoApprovalSettings: {
|
||||
...DEFAULT_AUTO_APPROVAL_SETTINGS,
|
||||
enabled: true,
|
||||
maxRequestsPerTask: 10,
|
||||
maxRequestsPerHour: 50,
|
||||
},
|
||||
}),
|
||||
],
|
||||
@@ -626,13 +624,6 @@ export const NewTaskWithContext = quickStory(
|
||||
"Start a new task with the current conversation context",
|
||||
"Shows new task creation with context preservation option.",
|
||||
)
|
||||
export const AutoApprovalMaxReached = quickStory(
|
||||
"Auto-approval Limit",
|
||||
"auto_approval_max_req_reached",
|
||||
"Cline has auto-approved 5 API requests. Would you like to reset the count and proceed with the task?",
|
||||
"Shows auto-approval limit reached state with Proceed/Start New Task options.",
|
||||
"Cline has auto-approved 5 API requests. Would you like to reset the count and proceed with the task?",
|
||||
)
|
||||
export const ApiRequestActive: Story = {
|
||||
decorators: [
|
||||
createStoryDecorator({
|
||||
|
||||
@@ -396,16 +396,6 @@ export const ChatRowContent = memo(
|
||||
}}></span>,
|
||||
<span style={{ color: errorColor, fontWeight: "bold" }}>Cline is having trouble...</span>,
|
||||
]
|
||||
case "auto_approval_max_req_reached":
|
||||
return [
|
||||
<span
|
||||
className="codicon codicon-warning"
|
||||
style={{
|
||||
color: errorColor,
|
||||
marginBottom: "-1.5px",
|
||||
}}></span>,
|
||||
<span style={{ color: errorColor, fontWeight: "bold" }}>Maximum Requests Reached</span>,
|
||||
]
|
||||
case "command":
|
||||
return [
|
||||
<span
|
||||
@@ -1703,8 +1693,6 @@ export const ChatRowContent = memo(
|
||||
switch (message.ask) {
|
||||
case "mistake_limit_reached":
|
||||
return <ErrorRow errorType="mistake_limit_reached" message={message} />
|
||||
case "auto_approval_max_req_reached":
|
||||
return <ErrorRow errorType="auto_approval_max_req_reached" message={message} />
|
||||
case "completion_result":
|
||||
if (message.text) {
|
||||
const hasChanges = message.text.endsWith(COMPLETION_RESULT_CHANGES_FLAG) ?? false
|
||||
|
||||
@@ -71,7 +71,7 @@ export const Default: Story = {
|
||||
argTypes: {
|
||||
errorType: {
|
||||
control: { type: "select" },
|
||||
options: ["error", "mistake_limit_reached", "auto_approval_max_req_reached", "diff_error", "clineignore_error"],
|
||||
options: ["error", "mistake_limit_reached", "diff_error", "clineignore_error"],
|
||||
description: "Type of error to display",
|
||||
},
|
||||
message: {
|
||||
|
||||
@@ -54,13 +54,6 @@ describe("ErrorRow", () => {
|
||||
expect(screen.getByText("Mistake limit reached")).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it("renders auto approval max requests error", () => {
|
||||
const maxReqMessage = { ...mockMessage, text: "Max requests reached" }
|
||||
render(<ErrorRow errorType="auto_approval_max_req_reached" message={maxReqMessage} />)
|
||||
|
||||
expect(screen.getByText("Max requests reached")).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it("renders diff error", () => {
|
||||
render(<ErrorRow errorType="diff_error" message={mockMessage} />)
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ const _errorColor = "var(--vscode-errorForeground)"
|
||||
|
||||
interface ErrorRowProps {
|
||||
message: ClineMessage
|
||||
errorType: "error" | "mistake_limit_reached" | "auto_approval_max_req_reached" | "diff_error" | "clineignore_error"
|
||||
errorType: "error" | "mistake_limit_reached" | "diff_error" | "clineignore_error"
|
||||
apiRequestFailedMessage?: string
|
||||
apiReqStreamingFailedMessage?: string
|
||||
}
|
||||
@@ -21,7 +21,6 @@ const ErrorRow = memo(({ message, errorType, apiRequestFailedMessage, apiReqStre
|
||||
switch (errorType) {
|
||||
case "error":
|
||||
case "mistake_limit_reached":
|
||||
case "auto_approval_max_req_reached":
|
||||
// Handle API request errors with special error parsing
|
||||
if (apiRequestFailedMessage || apiReqStreamingFailedMessage) {
|
||||
// FIXME: ClineError parsing should not be applied to non-Cline providers, but it seems we're using clineErrorMessage below in the default error display
|
||||
|
||||
@@ -1,47 +1,40 @@
|
||||
import { useMemo, useRef, useState } from "react"
|
||||
import { CODE_BLOCK_BG_COLOR } from "@/components/common/CodeBlock"
|
||||
import { StringRequest } from "@shared/proto/cline/common"
|
||||
import { useRef, useState } from "react"
|
||||
import { useExtensionState } from "@/context/ExtensionStateContext"
|
||||
import { useAutoApproveActions } from "@/hooks/useAutoApproveActions"
|
||||
import { UiServiceClient } from "@/services/grpc-client"
|
||||
import { getAsVar, VSC_TITLEBAR_INACTIVE_FOREGROUND } from "@/utils/vscStyles"
|
||||
import AutoApproveMenuItem from "./AutoApproveMenuItem"
|
||||
import AutoApproveModal from "./AutoApproveModal"
|
||||
import { ACTION_METADATA, NOTIFICATIONS_SETTING } from "./constants"
|
||||
import { ACTION_METADATA } from "./constants"
|
||||
|
||||
interface AutoApproveBarProps {
|
||||
style?: React.CSSProperties
|
||||
}
|
||||
|
||||
const AutoApproveBar = ({ style }: AutoApproveBarProps) => {
|
||||
const { autoApprovalSettings } = useExtensionState()
|
||||
const { isChecked, isFavorited, updateAction } = useAutoApproveActions()
|
||||
const { autoApprovalSettings, yoloModeToggled, navigateToSettings } = useExtensionState()
|
||||
|
||||
const [isModalVisible, setIsModalVisible] = useState(false)
|
||||
const buttonRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
const favorites = useMemo(() => autoApprovalSettings.favorites || [], [autoApprovalSettings.favorites])
|
||||
const handleNavigateToFeatures = async (e: React.MouseEvent) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
|
||||
// Render a favorited item with a checkbox
|
||||
const renderFavoritedItem = (favId: string) => {
|
||||
const actions = [...ACTION_METADATA.flatMap((a) => [a, a.subAction]), NOTIFICATIONS_SETTING]
|
||||
const action = actions.find((a) => a?.id === favId)
|
||||
if (!action) {
|
||||
return null
|
||||
}
|
||||
navigateToSettings()
|
||||
|
||||
return (
|
||||
<AutoApproveMenuItem
|
||||
action={action}
|
||||
condensed={true}
|
||||
isChecked={isChecked}
|
||||
isFavorited={isFavorited}
|
||||
onToggle={updateAction}
|
||||
showIcon={false}
|
||||
/>
|
||||
)
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
await UiServiceClient.scrollToSettings(StringRequest.create({ value: "features" }))
|
||||
} catch (error) {
|
||||
console.error("Error scrolling to features settings:", error)
|
||||
}
|
||||
}, 300)
|
||||
}
|
||||
|
||||
const getQuickAccessItems = () => {
|
||||
const notificationsEnabled = autoApprovalSettings.enableNotifications
|
||||
const getEnabledActionsText = () => {
|
||||
const baseClasses = isModalVisible
|
||||
? "text-foreground truncate"
|
||||
: "text-muted-foreground group-hover:text-foreground truncate"
|
||||
const enabledActionsNames = Object.keys(autoApprovalSettings.actions).filter(
|
||||
(key) => autoApprovalSettings.actions[key as keyof typeof autoApprovalSettings.actions],
|
||||
)
|
||||
@@ -49,51 +42,126 @@ const AutoApproveBar = ({ style }: AutoApproveBarProps) => {
|
||||
return ACTION_METADATA.flatMap((a) => [a, a.subAction]).find((a) => a?.id === action)
|
||||
})
|
||||
|
||||
const minusFavorites = enabledActions.filter((action) => !favorites.includes(action?.id ?? "") && action?.shortName)
|
||||
// Filter out parent actions if their subaction is also enabled (show only subaction)
|
||||
const actionsToShow = enabledActions.filter((action) => {
|
||||
if (!action?.shortName) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (notificationsEnabled) {
|
||||
minusFavorites.push(NOTIFICATIONS_SETTING)
|
||||
// If this is a parent action and its subaction is enabled, skip it
|
||||
if (action.subAction?.id && enabledActionsNames.includes(action.subAction.id)) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
if (actionsToShow.length === 0) {
|
||||
return <span className={baseClasses}>None</span>
|
||||
}
|
||||
|
||||
return [
|
||||
...favorites.map((favId) => renderFavoritedItem(favId)),
|
||||
minusFavorites.length > 0 ? (
|
||||
<span className="text-muted opacity-60" key="separator">
|
||||
✓
|
||||
</span>
|
||||
) : null,
|
||||
...minusFavorites.map((action, index) => (
|
||||
<span className="text-muted opacity-60" key={action?.id}>
|
||||
{action?.shortName}
|
||||
{index < minusFavorites.length - 1 && ","}
|
||||
</span>
|
||||
)),
|
||||
]
|
||||
return (
|
||||
<span className={baseClasses}>
|
||||
{actionsToShow.map((action, index) => (
|
||||
<span key={action?.id}>
|
||||
{action?.shortName}
|
||||
{index < actionsToShow.length - 1 && ", "}
|
||||
</span>
|
||||
))}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
const borderColor = `color-mix(in srgb, ${getAsVar(VSC_TITLEBAR_INACTIVE_FOREGROUND)} 20%, transparent)`
|
||||
const borderGradient = `linear-gradient(to bottom, ${borderColor} 0%, transparent 50%)`
|
||||
const bgGradient = `linear-gradient(to bottom, color-mix(in srgb, var(--vscode-sideBar-background) 96%, white) 0%, transparent 80%)`
|
||||
|
||||
// If YOLO mode is enabled, show disabled message
|
||||
if (yoloModeToggled) {
|
||||
return (
|
||||
<div
|
||||
className="mx-3.5 select-none break-words relative"
|
||||
style={{
|
||||
borderTop: `0.5px solid ${borderColor}`,
|
||||
borderRadius: "4px 4px 0 0",
|
||||
background: bgGradient,
|
||||
opacity: 0.5,
|
||||
...style,
|
||||
}}>
|
||||
{/* Left border gradient */}
|
||||
<div
|
||||
className="absolute left-0 pointer-events-none"
|
||||
style={{
|
||||
width: 0.5,
|
||||
top: 3,
|
||||
height: "100%",
|
||||
background: borderGradient,
|
||||
}}
|
||||
/>
|
||||
{/* Right border gradient */}
|
||||
<div
|
||||
className="absolute right-0 top-0 pointer-events-none"
|
||||
style={{
|
||||
width: 0.5,
|
||||
top: 3,
|
||||
height: "100%",
|
||||
background: borderGradient,
|
||||
}}
|
||||
/>
|
||||
|
||||
<div className="pt-4 pb-3.5 px-3.5">
|
||||
<div className="text-sm mb-1">Auto-approve: YOLO</div>
|
||||
<div className="text-muted-foreground text-xs">
|
||||
YOLO mode is enabled.{" "}
|
||||
<span className="underline cursor-pointer hover:text-foreground" onClick={handleNavigateToFeatures}>
|
||||
Disable it in Settings
|
||||
</span>
|
||||
.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className="px-3.5 mx-3.5 select-none rounded-tl-sm rounded-tr-sm overflow-y-auto break-words"
|
||||
className="mx-3.5 select-none break-words relative"
|
||||
style={{
|
||||
borderTop: `0.5px solid color-mix(in srgb, ${getAsVar(VSC_TITLEBAR_INACTIVE_FOREGROUND)} 20%, transparent)`,
|
||||
backgroundColor: isModalVisible ? CODE_BLOCK_BG_COLOR : "transparent",
|
||||
borderTop: `0.5px solid ${borderColor}`,
|
||||
borderRadius: "4px 4px 0 0",
|
||||
background: bgGradient,
|
||||
...style,
|
||||
}}>
|
||||
{/* Left border gradient */}
|
||||
<div
|
||||
className="cursor-pointer py-1 pr-1 flex items-center justify-between gap-2"
|
||||
className="absolute left-0 pointer-events-none"
|
||||
style={{
|
||||
width: 0.5,
|
||||
top: 3,
|
||||
height: "100%",
|
||||
background: borderGradient,
|
||||
}}
|
||||
/>
|
||||
{/* Right border gradient */}
|
||||
<div
|
||||
className="absolute right-0 top-0 pointer-events-none"
|
||||
style={{
|
||||
width: 0.5,
|
||||
top: 3,
|
||||
height: "100%",
|
||||
background: borderGradient,
|
||||
}}
|
||||
/>
|
||||
|
||||
<div
|
||||
className="group cursor-pointer pt-3 pb-3.5 pr-2 px-3.5 flex items-center justify-between gap-0"
|
||||
onClick={() => {
|
||||
setIsModalVisible((prev) => !prev)
|
||||
}}
|
||||
ref={buttonRef}>
|
||||
<div
|
||||
className="flex flex-nowrap items-center overflow-x-auto gap-1 whitespace-nowrap"
|
||||
style={{
|
||||
msOverflowStyle: "none",
|
||||
scrollbarWidth: "none",
|
||||
WebkitOverflowScrolling: "touch",
|
||||
}}>
|
||||
<span>Auto-approve:</span>
|
||||
{getQuickAccessItems()}
|
||||
<div className="flex flex-nowrap items-center gap-1 min-w-0 flex-1">
|
||||
<span className="whitespace-nowrap">Auto-approve:</span>
|
||||
{getEnabledActionsText()}
|
||||
</div>
|
||||
{isModalVisible ? (
|
||||
<span className="codicon codicon-chevron-down" />
|
||||
@@ -106,7 +174,6 @@ const AutoApproveBar = ({ style }: AutoApproveBarProps) => {
|
||||
ACTION_METADATA={ACTION_METADATA}
|
||||
buttonRef={buttonRef}
|
||||
isVisible={isModalVisible}
|
||||
NOTIFICATIONS_SETTING={NOTIFICATIONS_SETTING}
|
||||
setIsVisible={setIsModalVisible}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -8,11 +8,9 @@ import { ActionMetadata } from "./types"
|
||||
interface AutoApproveMenuItemProps {
|
||||
action: ActionMetadata
|
||||
isChecked: (action: ActionMetadata) => boolean
|
||||
isFavorited?: (action: ActionMetadata) => boolean
|
||||
onToggle: (action: ActionMetadata, checked: boolean) => Promise<void>
|
||||
onToggleFavorite?: (actionId: string) => Promise<void>
|
||||
condensed?: boolean
|
||||
showIcon?: boolean
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
const SubOptionAnimateIn = styled.div<{ show: boolean }>`
|
||||
@@ -30,72 +28,40 @@ const ActionButtonContainer = styled.div`
|
||||
padding: 2px;
|
||||
`
|
||||
|
||||
const AutoApproveMenuItem = ({
|
||||
action,
|
||||
isChecked,
|
||||
isFavorited,
|
||||
onToggle,
|
||||
onToggleFavorite,
|
||||
condensed = false,
|
||||
showIcon = true,
|
||||
}: AutoApproveMenuItemProps) => {
|
||||
const AutoApproveMenuItem = ({ action, isChecked, onToggle, showIcon = true, disabled = false }: AutoApproveMenuItemProps) => {
|
||||
const checked = isChecked(action)
|
||||
const favorited = isFavorited?.(action)
|
||||
|
||||
const onChange = async (e: Event) => {
|
||||
if (disabled) {
|
||||
return
|
||||
}
|
||||
e.stopPropagation()
|
||||
await onToggle(action, !checked)
|
||||
}
|
||||
|
||||
const content = (
|
||||
<div className="w-full">
|
||||
<div className="w-full" style={{ opacity: disabled ? 0.5 : 1 }}>
|
||||
<ActionButtonContainer className="w-full">
|
||||
<Tooltip>
|
||||
<TooltipContent showArrow={false}>{action.description}</TooltipContent>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
className={cn("w-full flex text-sm items-center justify-start text-foreground gap-2")}
|
||||
disabled={disabled}
|
||||
onClick={(e) => onChange(e as unknown as Event)}
|
||||
size="icon"
|
||||
style={{ cursor: disabled ? "not-allowed" : "pointer" }}
|
||||
variant="icon">
|
||||
{onToggleFavorite && !condensed && (
|
||||
<Tooltip>
|
||||
<TooltipContent showArrow={false}>
|
||||
{favorited ? "Remove from quick-access menu" : "Add to quick-access menu"}
|
||||
</TooltipContent>
|
||||
<TooltipTrigger asChild>
|
||||
<span
|
||||
className={cn("p-0.5 codicon", {
|
||||
"codicon-star-full text-(--vscode-terminal-ansiYellow)": favorited,
|
||||
"codicon-star-empty text-description opacity-60": !favorited,
|
||||
})}
|
||||
onClick={async (e) => {
|
||||
e.stopPropagation()
|
||||
if (action.id === "enableAll") {
|
||||
return
|
||||
}
|
||||
await onToggleFavorite?.(action.id)
|
||||
}}
|
||||
/>
|
||||
</TooltipTrigger>
|
||||
</Tooltip>
|
||||
)}
|
||||
<VSCodeCheckbox checked={checked} />
|
||||
<VSCodeCheckbox checked={checked} disabled={disabled} />
|
||||
{showIcon && <span className={`codicon ${action.icon} icon`}></span>}
|
||||
<span className="label">{condensed ? action.shortName : action.label}</span>
|
||||
<span className="label">{action.label}</span>
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
</Tooltip>
|
||||
</ActionButtonContainer>
|
||||
{action.subAction && !condensed && (
|
||||
{action.subAction && (
|
||||
<SubOptionAnimateIn show={checked}>
|
||||
<AutoApproveMenuItem
|
||||
action={action.subAction}
|
||||
isChecked={isChecked}
|
||||
isFavorited={isFavorited}
|
||||
onToggle={onToggle}
|
||||
onToggleFavorite={onToggleFavorite}
|
||||
/>
|
||||
<AutoApproveMenuItem action={action.subAction} isChecked={isChecked} onToggle={onToggle} />
|
||||
</SubOptionAnimateIn>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
|
||||
import { XIcon } from "lucide-react"
|
||||
import { StringRequest } from "@shared/proto/cline/common"
|
||||
import React, { useEffect, useRef, useState } from "react"
|
||||
import { useClickAway, useWindowSize } from "react-use"
|
||||
import { CODE_BLOCK_BG_COLOR } from "@/components/common/CodeBlock"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
|
||||
import { useClickAway } from "react-use"
|
||||
import { useExtensionState } from "@/context/ExtensionStateContext"
|
||||
import { useAutoApproveActions } from "@/hooks/useAutoApproveActions"
|
||||
import { UiServiceClient } from "@/services/grpc-client"
|
||||
import { getAsVar, VSC_TITLEBAR_INACTIVE_FOREGROUND } from "@/utils/vscStyles"
|
||||
import AutoApproveMenuItem from "./AutoApproveMenuItem"
|
||||
import { ActionMetadata } from "./types"
|
||||
@@ -18,24 +15,31 @@ interface AutoApproveModalProps {
|
||||
setIsVisible: (visible: boolean) => void
|
||||
buttonRef: React.RefObject<HTMLDivElement>
|
||||
ACTION_METADATA: ActionMetadata[]
|
||||
NOTIFICATIONS_SETTING: ActionMetadata
|
||||
}
|
||||
|
||||
const AutoApproveModal: React.FC<AutoApproveModalProps> = ({
|
||||
isVisible,
|
||||
setIsVisible,
|
||||
buttonRef,
|
||||
ACTION_METADATA,
|
||||
NOTIFICATIONS_SETTING,
|
||||
}) => {
|
||||
const { autoApprovalSettings } = useExtensionState()
|
||||
const { isChecked, isFavorited, toggleFavorite, updateAction, updateMaxRequests } = useAutoApproveActions()
|
||||
const AutoApproveModal: React.FC<AutoApproveModalProps> = ({ isVisible, setIsVisible, buttonRef, ACTION_METADATA }) => {
|
||||
const { navigateToSettings } = useExtensionState()
|
||||
const { isChecked, updateAction } = useAutoApproveActions()
|
||||
|
||||
const handleNotificationsLinkClick = async (e: React.MouseEvent) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
|
||||
// Navigate to settings
|
||||
navigateToSettings()
|
||||
|
||||
// Scroll to general section
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
await UiServiceClient.scrollToSettings(StringRequest.create({ value: "general" }))
|
||||
} catch (error) {
|
||||
console.error("Error scrolling to general settings:", error)
|
||||
}
|
||||
}, 300)
|
||||
}
|
||||
|
||||
const modalRef = useRef<HTMLDivElement>(null)
|
||||
const itemsContainerRef = useRef<HTMLDivElement>(null)
|
||||
const { width: viewportWidth, height: viewportHeight } = useWindowSize()
|
||||
const [arrowPosition, setArrowPosition] = useState(0)
|
||||
const [menuPosition, setMenuPosition] = useState(0)
|
||||
const [containerWidth, setContainerWidth] = useState(0)
|
||||
|
||||
useClickAway(modalRef, (e) => {
|
||||
@@ -46,18 +50,6 @@ const AutoApproveModal: React.FC<AutoApproveModalProps> = ({
|
||||
setIsVisible(false)
|
||||
})
|
||||
|
||||
// Calculate positions for modal and arrow
|
||||
useEffect(() => {
|
||||
if (isVisible && buttonRef.current) {
|
||||
const buttonRect = buttonRef.current.getBoundingClientRect()
|
||||
const buttonCenter = buttonRect.left + buttonRect.width / 2
|
||||
const rightPosition = document.documentElement.clientWidth - buttonCenter - 5
|
||||
|
||||
setArrowPosition(rightPosition)
|
||||
setMenuPosition(buttonRect.top + 1)
|
||||
}
|
||||
}, [isVisible, viewportWidth, viewportHeight, buttonRef])
|
||||
|
||||
// Track container width for responsive layout
|
||||
useEffect(() => {
|
||||
if (!isVisible) {
|
||||
@@ -89,152 +81,46 @@ const AutoApproveModal: React.FC<AutoApproveModalProps> = ({
|
||||
return null
|
||||
}
|
||||
|
||||
// Calculate safe positioning to prevent overflow while preserving original position
|
||||
const calculateModalStyle = () => {
|
||||
// Original positioning: bottom: calc(100vh - ${menuPosition}px + 6px)
|
||||
const originalBottom = viewportHeight - menuPosition + 6
|
||||
|
||||
// Calculate the available space from the button to the top of the viewport
|
||||
const availableSpace = viewportHeight - originalBottom
|
||||
|
||||
// Set a minimum top margin to prevent the modal from touching the top edge
|
||||
const minTopMargin = 15
|
||||
|
||||
// Calculate the maximum height the modal can have
|
||||
// Use the full available space minus the top margin, but also respect the original constraint
|
||||
const maxAvailableHeight = availableSpace - minTopMargin
|
||||
const originalMaxHeight = viewportHeight - 100
|
||||
|
||||
// Use the smaller of the two to ensure we don't overflow but still use full height when possible
|
||||
let finalMaxHeight: number
|
||||
|
||||
if (menuPosition <= minTopMargin) {
|
||||
// Button is very close to the top, use all available space
|
||||
finalMaxHeight = maxAvailableHeight
|
||||
} else {
|
||||
// Normal case: use the original max height unless it would cause overflow
|
||||
finalMaxHeight = Math.min(originalMaxHeight, maxAvailableHeight)
|
||||
}
|
||||
|
||||
return {
|
||||
bottom: `${originalBottom}px`,
|
||||
maxHeight: `${Math.max(finalMaxHeight, 200)}px`, // Ensure minimum usable height
|
||||
background: CODE_BLOCK_BG_COLOR,
|
||||
overscrollBehavior: "contain" as const,
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="overflow-hidden" ref={modalRef}>
|
||||
<div ref={modalRef}>
|
||||
{/* Expanded menu content - renders directly below the bar */}
|
||||
<div
|
||||
className="fixed left-3.5 right-3.5 border border-(--vscode-editorGroup-border) rounded z-20 flex flex-col"
|
||||
style={calculateModalStyle()}>
|
||||
className="overflow-y-auto pb-3 px-3.5 overscroll-contain"
|
||||
style={{
|
||||
maxHeight: "60vh",
|
||||
}}>
|
||||
<div className="mb-2.5 text-muted-foreground text-xs cursor-pointer" onClick={() => setIsVisible(false)}>
|
||||
Let Cline take these actions without asking for approval.{" "}
|
||||
<span
|
||||
className="underline cursor-pointer hover:text-foreground"
|
||||
onClick={handleNotificationsLinkClick}
|
||||
style={{ textDecoration: "underline" }}>
|
||||
Configure notification settings
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="fixed w-3.5 h-3.5 z-0 rotate-45 border-r border-b border-(--vscode-editorGroup-border) bg-code"
|
||||
className="relative mb-2 w-full"
|
||||
ref={itemsContainerRef}
|
||||
style={{
|
||||
bottom: `calc(100vh - ${menuPosition}px)`,
|
||||
right: arrowPosition,
|
||||
}}
|
||||
/>
|
||||
{/* Scrollable content container */}
|
||||
<div className="overflow-y-auto p-3 flex-1 min-h-0 overscroll-contain w-full">
|
||||
<div className="flex justify-between items-center mb-3 w-full">
|
||||
<Tooltip>
|
||||
<TooltipContent side="top">
|
||||
Auto-approve allows Cline to perform the following actions without asking for permission. Please
|
||||
use with caution and only enable if you understand the risks.
|
||||
</TooltipContent>
|
||||
<TooltipTrigger>
|
||||
<div className="text-md font-semibold mb-1">Auto-approve Settings</div>
|
||||
</TooltipTrigger>
|
||||
</Tooltip>
|
||||
<Button onClick={() => setIsVisible(false)} size="icon" variant="icon">
|
||||
<XIcon />
|
||||
</Button>
|
||||
</div>
|
||||
columnCount: containerWidth > breakpoint ? 2 : 1,
|
||||
columnGap: "4px",
|
||||
}}>
|
||||
{/* Vertical separator line - only visible in two-column mode */}
|
||||
{containerWidth > breakpoint && (
|
||||
<div
|
||||
className="absolute left-1/2 top-0 bottom-0 opacity-20"
|
||||
style={{
|
||||
background: getAsVar(VSC_TITLEBAR_INACTIVE_FOREGROUND),
|
||||
transform: "translateX(-50%)", // Center the line
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="mb-2.5">
|
||||
<span className="text-foreground font-medium">Actions:</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="relative mb-6 w-full"
|
||||
ref={itemsContainerRef}
|
||||
style={{
|
||||
columnCount: containerWidth > breakpoint ? 2 : 1,
|
||||
columnGap: "4px",
|
||||
}}>
|
||||
{/* Vertical separator line - only visible in two-column mode */}
|
||||
{containerWidth > breakpoint && (
|
||||
<div
|
||||
className="absolute left-1/2 top-0 bottom-0 opacity-20"
|
||||
style={{
|
||||
background: getAsVar(VSC_TITLEBAR_INACTIVE_FOREGROUND),
|
||||
transform: "translateX(-50%)", // Center the line
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* All items in a single list - CSS Grid will handle the column distribution */}
|
||||
{ACTION_METADATA.map((action) => (
|
||||
<AutoApproveMenuItem
|
||||
action={action}
|
||||
isChecked={isChecked}
|
||||
isFavorited={isFavorited}
|
||||
key={action.id}
|
||||
onToggle={updateAction}
|
||||
onToggleFavorite={toggleFavorite}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mb-2.5">
|
||||
<span className="font-medium">Quick Settings:</span>
|
||||
</div>
|
||||
|
||||
<AutoApproveMenuItem
|
||||
action={NOTIFICATIONS_SETTING}
|
||||
isChecked={isChecked}
|
||||
isFavorited={isFavorited}
|
||||
key={NOTIFICATIONS_SETTING.id}
|
||||
onToggle={updateAction}
|
||||
onToggleFavorite={toggleFavorite}
|
||||
/>
|
||||
|
||||
<Tooltip>
|
||||
<TooltipContent side="top">
|
||||
Cline will automatically make this many API requests before asking for approval to proceed with the
|
||||
task.
|
||||
</TooltipContent>
|
||||
<TooltipTrigger>
|
||||
<div className="flex items-center pl-1.5 my-2">
|
||||
<span className="codicon codicon-settings text-[#CCCCCC] text-[14px]" />
|
||||
<span className="text-base font-medium ml-2">Max Requests:</span>
|
||||
<VSCodeTextField
|
||||
className="flex-1 w-full pr-[35px] ml-4"
|
||||
onInput={async (e) => {
|
||||
const input = e.target as HTMLInputElement
|
||||
// Remove any non-numeric characters
|
||||
input.value = input.value.replace(/[^0-9]/g, "")
|
||||
const value = parseInt(input.value)
|
||||
if (!Number.isNaN(value) && value > 0) {
|
||||
await updateMaxRequests(value)
|
||||
}
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
// Prevent non-numeric keys (except for backspace, delete, arrows)
|
||||
if (
|
||||
!/^\d$/.test(e.key) &&
|
||||
!["Backspace", "Delete", "ArrowLeft", "ArrowRight"].includes(e.key)
|
||||
) {
|
||||
e.preventDefault()
|
||||
}
|
||||
}}
|
||||
value={autoApprovalSettings.maxRequests.toString()}
|
||||
/>
|
||||
</div>
|
||||
</TooltipTrigger>
|
||||
</Tooltip>
|
||||
{/* All items in a single list - CSS Grid will handle the column distribution */}
|
||||
{ACTION_METADATA.map((action) => (
|
||||
<AutoApproveMenuItem action={action} isChecked={isChecked} key={action.id} onToggle={updateAction} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,20 +1,6 @@
|
||||
import { ActionMetadata } from "./types"
|
||||
|
||||
export const ACTION_METADATA: ActionMetadata[] = [
|
||||
{
|
||||
id: "enableAutoApprove",
|
||||
label: "Enable auto-approve",
|
||||
shortName: "Enabled",
|
||||
description: "Toggle the auto-approve feature on or off.",
|
||||
icon: "codicon-play-circle",
|
||||
},
|
||||
{
|
||||
id: "enableAll",
|
||||
label: "Toggle all",
|
||||
shortName: "All",
|
||||
description: "Toggle all actions on or off.",
|
||||
icon: "codicon-checklist",
|
||||
},
|
||||
{
|
||||
id: "readFiles",
|
||||
label: "Read project files",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { AutoApprovalSettings } from "@shared/AutoApprovalSettings"
|
||||
|
||||
export interface ActionMetadata {
|
||||
id: keyof AutoApprovalSettings["actions"] | "enableNotifications" | "enableAll" | "enableAutoApprove"
|
||||
id: keyof AutoApprovalSettings["actions"] | "enableNotifications"
|
||||
label: string
|
||||
shortName: string
|
||||
description: string
|
||||
|
||||
@@ -62,7 +62,6 @@ export function useMessageHandlers(messages: ClineMessage[], chatState: ChatStat
|
||||
case "resume_task":
|
||||
case "resume_completed_task":
|
||||
case "mistake_limit_reached":
|
||||
case "auto_approval_max_req_reached":
|
||||
case "api_req_failed":
|
||||
case "new_task":
|
||||
case "condense":
|
||||
|
||||
@@ -24,7 +24,7 @@ describe("getButtonConfig", () => {
|
||||
|
||||
// Test error recovery states
|
||||
describe("Error Recovery States", () => {
|
||||
const errorStates = ["api_req_failed", "mistake_limit_reached", "auto_approval_max_req_reached"]
|
||||
const errorStates = ["api_req_failed", "mistake_limit_reached"]
|
||||
|
||||
errorStates.forEach((errorState) => {
|
||||
it(`returns correct config for ${errorState}`, () => {
|
||||
|
||||
@@ -47,14 +47,6 @@ export const BUTTON_CONFIGS: Record<string, ButtonConfig> = {
|
||||
primaryAction: "proceed",
|
||||
secondaryAction: "new_task",
|
||||
},
|
||||
auto_approval_max_req_reached: {
|
||||
sendingDisabled: false,
|
||||
enableButtons: true,
|
||||
primaryText: "Proceed",
|
||||
secondaryText: "Start New Task",
|
||||
primaryAction: "proceed",
|
||||
secondaryAction: "new_task",
|
||||
},
|
||||
|
||||
// Tool approval states - most common during task execution
|
||||
tool_approve: {
|
||||
@@ -207,7 +199,7 @@ export const BUTTON_CONFIGS: Record<string, ButtonConfig> = {
|
||||
},
|
||||
}
|
||||
|
||||
const errorTypes = ["api_req_failed", "mistake_limit_reached", "auto_approval_max_req_reached"]
|
||||
const errorTypes = ["api_req_failed", "mistake_limit_reached"]
|
||||
|
||||
/**
|
||||
* Determines button configuration based on message type and state
|
||||
@@ -235,8 +227,6 @@ export function getButtonConfig(message: ClineMessage | undefined, _mode: Mode =
|
||||
return BUTTON_CONFIGS.api_req_failed
|
||||
case "mistake_limit_reached":
|
||||
return BUTTON_CONFIGS.mistake_limit_reached
|
||||
case "auto_approval_max_req_reached":
|
||||
return BUTTON_CONFIGS.auto_approval_max_req_reached
|
||||
|
||||
// Tool approval (most common)
|
||||
case "tool": {
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ const McpToolRow = ({ tool, serverName }: McpToolRowProps) => {
|
||||
<span className="codicon codicon-symbol-method" style={{ marginRight: "6px" }}></span>
|
||||
<span style={{ fontWeight: 500 }}>{tool.name}</span>
|
||||
</div>
|
||||
{serverName && autoApprovalSettings.enabled && autoApprovalSettings.actions.useMcp && (
|
||||
{serverName && autoApprovalSettings.actions.useMcp && (
|
||||
<VSCodeCheckbox checked={tool.autoApprove ?? false} data-tool={tool.name} onChange={handleAutoApproveChange}>
|
||||
Auto-approve
|
||||
</VSCodeCheckbox>
|
||||
|
||||
@@ -340,16 +340,17 @@ const ServerRow = ({
|
||||
flexDirection: "column",
|
||||
gap: "8px",
|
||||
width: "100%",
|
||||
paddingTop: "8px",
|
||||
}}>
|
||||
{server.tools.map((tool) => (
|
||||
<McpToolRow key={tool.name} serverName={server.name} tool={tool} />
|
||||
))}
|
||||
{server.name && autoApprovalSettings.enabled && autoApprovalSettings.actions.useMcp && (
|
||||
{server.name && autoApprovalSettings.actions.useMcp && (
|
||||
<VSCodeCheckbox
|
||||
checked={server.tools.every((tool) => tool.autoApprove)}
|
||||
data-tool="all-tools"
|
||||
onChange={handleAutoApproveChange}
|
||||
style={{ marginBottom: -10 }}>
|
||||
style={{ marginTop: "4px", marginBottom: "4px" }}>
|
||||
Auto-approve all tools
|
||||
</VSCodeCheckbox>
|
||||
)}
|
||||
@@ -374,6 +375,7 @@ const ServerRow = ({
|
||||
flexDirection: "column",
|
||||
gap: "8px",
|
||||
width: "100%",
|
||||
paddingTop: "8px",
|
||||
}}>
|
||||
{[...(server.resourceTemplates || []), ...(server.resources || [])].map((item) => (
|
||||
<McpResourceRow
|
||||
|
||||
@@ -416,8 +416,9 @@ const FeatureSettingsSection = ({ renderSectionHeader }: FeatureSettingsSectionP
|
||||
</Tooltip>
|
||||
|
||||
<p className="text-xs text-(--vscode-errorForeground)">
|
||||
EXPERIMENTAL & DANGEROUS: This mode disables safety checks and user confirmations. Cline will
|
||||
automatically approve all actions without asking. Use with extreme caution.
|
||||
This mode disables safety checks and user confirmations. Cline will automatically approve all actions
|
||||
without asking. This special mode does not use plan mode or ask questions, and it is recommended to
|
||||
enable all auto-approve actions instead.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { VSCodeCheckbox, VSCodeLink } from "@vscode/webview-ui-toolkit/react"
|
||||
import { updateAutoApproveSettings } from "@/components/chat/auto-approve-menu/AutoApproveSettingsAPI"
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
|
||||
import { useExtensionState } from "@/context/ExtensionStateContext"
|
||||
import PreferredLanguageSetting from "../PreferredLanguageSetting"
|
||||
@@ -10,7 +11,7 @@ interface GeneralSettingsSectionProps {
|
||||
}
|
||||
|
||||
const GeneralSettingsSection = ({ renderSectionHeader }: GeneralSettingsSectionProps) => {
|
||||
const { telemetrySetting, remoteConfigSettings } = useExtensionState()
|
||||
const { telemetrySetting, remoteConfigSettings, autoApprovalSettings } = useExtensionState()
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -18,6 +19,25 @@ const GeneralSettingsSection = ({ renderSectionHeader }: GeneralSettingsSectionP
|
||||
<Section>
|
||||
<PreferredLanguageSetting />
|
||||
|
||||
<div className="mb-[5px]" id="enable-notifications">
|
||||
<VSCodeCheckbox
|
||||
checked={autoApprovalSettings.enableNotifications}
|
||||
onChange={async (e: any) => {
|
||||
const checked = e.target.checked === true
|
||||
await updateAutoApproveSettings({
|
||||
...autoApprovalSettings,
|
||||
version: (autoApprovalSettings.version ?? 1) + 1,
|
||||
enableNotifications: checked,
|
||||
})
|
||||
}}>
|
||||
Enable notifications
|
||||
</VSCodeCheckbox>
|
||||
|
||||
<p className="text-sm mt-[5px] text-description">
|
||||
Receive system notifications when Cline requires approval to proceed or when a task is completed.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="mb-[5px]">
|
||||
<Tooltip>
|
||||
<TooltipContent hidden={remoteConfigSettings?.telemetrySetting === undefined}>
|
||||
|
||||
@@ -11,12 +11,8 @@ export function useAutoApproveActions() {
|
||||
const isChecked = useCallback(
|
||||
(action: ActionMetadata): boolean => {
|
||||
switch (action.id) {
|
||||
case "enableAll":
|
||||
return Object.values(autoApprovalSettings.actions).every(Boolean)
|
||||
case "enableNotifications":
|
||||
return autoApprovalSettings.enableNotifications
|
||||
case "enableAutoApprove":
|
||||
return autoApprovalSettings.enabled
|
||||
default:
|
||||
return autoApprovalSettings.actions[action.id] ?? false
|
||||
}
|
||||
@@ -24,52 +20,12 @@ export function useAutoApproveActions() {
|
||||
[autoApprovalSettings],
|
||||
)
|
||||
|
||||
// Check if action is favorited
|
||||
const isFavorited = useCallback(
|
||||
(action: ActionMetadata): boolean => {
|
||||
const favorites = autoApprovalSettings.favorites || []
|
||||
return favorites.includes(action.id)
|
||||
},
|
||||
[autoApprovalSettings.favorites],
|
||||
)
|
||||
|
||||
// Toggle favorite status
|
||||
const toggleFavorite = useCallback(
|
||||
async (actionId: string) => {
|
||||
const currentFavorites = autoApprovalSettings.favorites || []
|
||||
let newFavorites: string[]
|
||||
|
||||
if (currentFavorites.includes(actionId)) {
|
||||
newFavorites = currentFavorites.filter((id) => id !== actionId)
|
||||
} else {
|
||||
newFavorites = [...currentFavorites, actionId]
|
||||
}
|
||||
|
||||
await updateAutoApproveSettings({
|
||||
...autoApprovalSettings,
|
||||
version: (autoApprovalSettings.version ?? 1) + 1,
|
||||
favorites: newFavorites,
|
||||
})
|
||||
},
|
||||
[autoApprovalSettings],
|
||||
)
|
||||
|
||||
// Update action state
|
||||
const updateAction = useCallback(
|
||||
async (action: ActionMetadata, value: boolean) => {
|
||||
const actionId = action.id
|
||||
const subActionId = action.subAction?.id
|
||||
|
||||
if (actionId === "enableAutoApprove") {
|
||||
await updateAutoApproveEnabled(value)
|
||||
return
|
||||
}
|
||||
|
||||
if (actionId === "enableAll" || subActionId === "enableAll") {
|
||||
await toggleAll(action, value)
|
||||
return
|
||||
}
|
||||
|
||||
if (actionId === "enableNotifications" || subActionId === "enableNotifications") {
|
||||
await updateNotifications(action, value)
|
||||
return
|
||||
@@ -81,7 +37,6 @@ export function useAutoApproveActions() {
|
||||
}
|
||||
|
||||
if (value === false && subActionId) {
|
||||
// @ts-expect-error: TODO: See how we can fix this
|
||||
newActions[subActionId] = false
|
||||
}
|
||||
|
||||
@@ -89,57 +44,10 @@ export function useAutoApproveActions() {
|
||||
newActions[action.parentActionId as keyof AutoApprovalSettings["actions"]] = true
|
||||
}
|
||||
|
||||
// Check if this will result in any enabled actions
|
||||
const willHaveEnabledActions = Object.values(newActions).some(Boolean)
|
||||
|
||||
await updateAutoApproveSettings({
|
||||
...autoApprovalSettings,
|
||||
version: (autoApprovalSettings.version ?? 1) + 1,
|
||||
actions: newActions,
|
||||
enabled: willHaveEnabledActions,
|
||||
})
|
||||
},
|
||||
[autoApprovalSettings],
|
||||
)
|
||||
|
||||
// Update max requests
|
||||
const updateMaxRequests = useCallback(
|
||||
async (maxRequests: number) => {
|
||||
await updateAutoApproveSettings({
|
||||
...autoApprovalSettings,
|
||||
version: (autoApprovalSettings.version ?? 1) + 1,
|
||||
maxRequests,
|
||||
})
|
||||
},
|
||||
[autoApprovalSettings],
|
||||
)
|
||||
|
||||
// Update auto-approve enabled state
|
||||
const updateAutoApproveEnabled = useCallback(
|
||||
async (checked: boolean) => {
|
||||
await updateAutoApproveSettings({
|
||||
...autoApprovalSettings,
|
||||
version: (autoApprovalSettings.version ?? 1) + 1,
|
||||
enabled: checked,
|
||||
})
|
||||
},
|
||||
[autoApprovalSettings],
|
||||
)
|
||||
|
||||
// Toggle all actions
|
||||
const toggleAll = useCallback(
|
||||
async (_action: ActionMetadata, checked: boolean) => {
|
||||
const actions = { ...autoApprovalSettings.actions }
|
||||
|
||||
for (const action of Object.keys(actions)) {
|
||||
actions[action as keyof AutoApprovalSettings["actions"]] = checked
|
||||
}
|
||||
|
||||
await updateAutoApproveSettings({
|
||||
...autoApprovalSettings,
|
||||
version: (autoApprovalSettings.version ?? 1) + 1,
|
||||
actions,
|
||||
enabled: checked,
|
||||
})
|
||||
},
|
||||
[autoApprovalSettings],
|
||||
@@ -161,12 +69,7 @@ export function useAutoApproveActions() {
|
||||
|
||||
return {
|
||||
isChecked,
|
||||
isFavorited,
|
||||
toggleFavorite,
|
||||
updateAction,
|
||||
updateMaxRequests,
|
||||
updateAutoApproveEnabled,
|
||||
toggleAll,
|
||||
updateNotifications,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user