Add auto approval max requests functionality

This commit is contained in:
Saoud Rizwan 2024-12-17 17:46:39 -08:00
parent 93af89dbf9
commit 0045126054
5 changed files with 51 additions and 2 deletions

View file

@ -73,6 +73,7 @@ export class Cline {
private askResponseText?: string
private askResponseImages?: string[]
private lastMessageTs?: number
private consecutiveAutoApprovedRequestsCount: number = 0
private consecutiveMistakeCount: number = 0
private providerRef: WeakRef<ClineProvider>
private abort: boolean = false
@ -1192,6 +1193,7 @@ export class Cline {
if (this.shouldAutoApproveTool(block.name)) {
await this.say("tool", completeMessage, undefined, false)
this.consecutiveAutoApprovedRequestsCount++
} else {
const didApprove = await askApproval("tool", completeMessage)
if (!didApprove) {
@ -1274,6 +1276,7 @@ export class Cline {
} satisfies ClineSayTool)
if (this.shouldAutoApproveTool(block.name)) {
await this.say("tool", completeMessage, undefined, false) // need to be sending partialValue bool, since undefined has its own purpose in that the message is treated neither as a partial or completion of a partial, but as a single complete message
this.consecutiveAutoApprovedRequestsCount++
} else {
const didApprove = await askApproval("tool", completeMessage)
if (!didApprove) {
@ -1326,6 +1329,7 @@ export class Cline {
} satisfies ClineSayTool)
if (this.shouldAutoApproveTool(block.name)) {
await this.say("tool", completeMessage, undefined, false)
this.consecutiveAutoApprovedRequestsCount++
} else {
const didApprove = await askApproval("tool", completeMessage)
if (!didApprove) {
@ -1375,6 +1379,7 @@ export class Cline {
} satisfies ClineSayTool)
if (this.shouldAutoApproveTool(block.name)) {
await this.say("tool", completeMessage, undefined, false)
this.consecutiveAutoApprovedRequestsCount++
} else {
const didApprove = await askApproval("tool", completeMessage)
if (!didApprove) {
@ -1431,6 +1436,7 @@ export class Cline {
} satisfies ClineSayTool)
if (this.shouldAutoApproveTool(block.name)) {
await this.say("tool", completeMessage, undefined, false)
this.consecutiveAutoApprovedRequestsCount++
} else {
const didApprove = await askApproval("tool", completeMessage)
if (!didApprove) {
@ -1506,6 +1512,7 @@ export class Cline {
if (this.shouldAutoApproveTool(block.name)) {
await this.say("browser_action_launch", url, undefined, false)
this.consecutiveAutoApprovedRequestsCount++
} else {
const didApprove = await askApproval("browser_action_launch", url)
if (!didApprove) {
@ -1649,6 +1656,7 @@ export class Cline {
if (!requiresApproval && this.shouldAutoApproveTool(block.name)) {
await this.say("command", command, undefined, false)
this.consecutiveAutoApprovedRequestsCount++
} else {
const didApprove = await askApproval(
"command",
@ -1741,6 +1749,7 @@ export class Cline {
if (this.shouldAutoApproveTool(block.name)) {
await this.say("use_mcp_server", completeMessage, undefined, false)
this.consecutiveAutoApprovedRequestsCount++
} else {
const didApprove = await askApproval("use_mcp_server", completeMessage)
if (!didApprove) {
@ -1821,6 +1830,7 @@ export class Cline {
if (this.shouldAutoApproveTool(block.name)) {
await this.say("use_mcp_server", completeMessage, undefined, false)
this.consecutiveAutoApprovedRequestsCount++
} else {
const didApprove = await askApproval("use_mcp_server", completeMessage)
if (!didApprove) {
@ -2075,6 +2085,18 @@ export class Cline {
this.consecutiveMistakeCount = 0
}
if (
this.autoApprovalSettings.enabled &&
this.consecutiveAutoApprovedRequestsCount >= this.autoApprovalSettings.maxRequests
) {
await this.ask(
"auto_approval_max_req_reached",
`Cline has auto-approved ${this.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.consecutiveAutoApprovedRequestsCount = 0
}
// get previous api req's index to check token usage and determine if we need to truncate conversation history
const previousApiReqIndex = findLastIndex(this.clineMessages, (m) => m.say === "api_req_started")

View file

@ -68,6 +68,7 @@ export type ClineAsk =
| "resume_task"
| "resume_completed_task"
| "mistake_limit_reached"
| "auto_approval_max_req_reached"
| "browser_action_launch"
| "use_mcp_server"

View file

@ -267,7 +267,8 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
fontSize: "12px",
marginBottom: "10px",
}}>
Cline will make this many API requests before asking for approval to proceed with the task.
Cline will automatically make this many API requests before asking for approval to proceed with
the task.
</div>
<div style={{ margin: "6px 0" }}>
<VSCodeCheckbox

View file

@ -119,6 +119,13 @@ export const ChatRowContent = ({
style={{ color: errorColor, marginBottom: "-1.5px" }}></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 [
isCommandExecuting ? (
@ -886,7 +893,16 @@ export const ChatRowContent = ({
<p style={{ ...pStyle, color: "var(--vscode-errorForeground)" }}>{message.text}</p>
</>
)
case "auto_approval_max_req_reached":
return (
<>
<div style={headerStyle}>
{icon}
{title}
</div>
<p style={{ ...pStyle, color: "var(--vscode-errorForeground)" }}>{message.text}</p>
</>
)
case "completion_result":
if (message.text) {
return (

View file

@ -89,6 +89,13 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
setPrimaryButtonText("Proceed Anyways")
setSecondaryButtonText("Start New Task")
break
case "auto_approval_max_req_reached":
setTextAreaDisabled(true)
setClineAsk("auto_approval_max_req_reached")
setEnableButtons(true)
setPrimaryButtonText("Proceed")
setSecondaryButtonText("Start New Task")
break
case "followup":
setTextAreaDisabled(isPartial)
setClineAsk("followup")
@ -305,6 +312,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
case "use_mcp_server":
case "resume_task":
case "mistake_limit_reached":
case "auto_approval_max_req_reached":
vscode.postMessage({ type: "askResponse", askResponse: "yesButtonClicked" })
break
case "completion_result":
@ -331,6 +339,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
switch (clineAsk) {
case "api_req_failed":
case "mistake_limit_reached":
case "auto_approval_max_req_reached":
startNewTask()
break
case "command":