Remove max requests per task settings option

This commit is contained in:
Saoud Rizwan
2024-09-01 01:41:43 -04:00
parent fdcec81814
commit ba4caf4f00
11 changed files with 6 additions and 147 deletions

View File

@@ -18,7 +18,6 @@ import { ApiConfiguration } from "./shared/api"
import { ClaudeRequestResult } from "./shared/ClaudeRequestResult"
import { combineApiRequests } from "./shared/combineApiRequests"
import { combineCommandSequences } from "./shared/combineCommandSequences"
import { DEFAULT_MAX_REQUESTS_PER_TASK } from "./shared/Constants"
import { ClaudeAsk, ClaudeMessage, ClaudeSay, ClaudeSayTool } from "./shared/ExtensionMessage"
import { getApiMetrics } from "./shared/getApiMetrics"
import { HistoryItem } from "./shared/HistoryItem"
@@ -250,10 +249,8 @@ type UserContent = Array<
export class ClaudeDev {
readonly taskId: string
private api: ApiHandler
private maxRequestsPerTask: number
private customInstructions?: string
private alwaysAllowReadOnly: boolean
private requestCount = 0
apiConversationHistory: Anthropic.MessageParam[] = []
claudeMessages: ClaudeMessage[] = []
private askResponse?: ClaudeAskResponse
@@ -268,7 +265,6 @@ export class ClaudeDev {
constructor(
provider: ClaudeDevProvider,
apiConfiguration: ApiConfiguration,
maxRequestsPerTask?: number,
customInstructions?: string,
alwaysAllowReadOnly?: boolean,
task?: string,
@@ -277,7 +273,6 @@ export class ClaudeDev {
) {
this.providerRef = new WeakRef(provider)
this.api = buildApiHandler(apiConfiguration)
this.maxRequestsPerTask = maxRequestsPerTask ?? DEFAULT_MAX_REQUESTS_PER_TASK
this.customInstructions = customInstructions
this.alwaysAllowReadOnly = alwaysAllowReadOnly ?? false
@@ -296,10 +291,6 @@ export class ClaudeDev {
this.api = buildApiHandler(apiConfiguration)
}
updateMaxRequestsPerTask(maxRequestsPerTask: number | undefined) {
this.maxRequestsPerTask = maxRequestsPerTask ?? DEFAULT_MAX_REQUESTS_PER_TASK
}
updateCustomInstructions(customInstructions: string | undefined) {
this.customInstructions = customInstructions
}
@@ -1395,27 +1386,6 @@ ${this.customInstructions.trim()}
}
await this.addToApiConversationHistory({ role: "user", content: userContent })
if (this.requestCount >= this.maxRequestsPerTask) {
const { response } = await this.ask(
"request_limit_reached",
`Claude Dev has reached the maximum number of requests for this task. Would you like to reset the count and allow him to proceed?`
)
if (response === "yesButtonTapped") {
this.requestCount = 0
} else {
await this.addToApiConversationHistory({
role: "assistant",
content: [
{
type: "text",
text: "Failure: I have reached the request limit for this task. Do you have a new task for me?",
},
],
})
return { didEndLoop: true, inputTokens: 0, outputTokens: 0 }
}
}
if (!this.shouldSkipNextApiReqStartedMessage) {
await this.say(
@@ -1430,7 +1400,6 @@ ${this.customInstructions.trim()}
}
try {
const response = await this.attemptApiRequest()
this.requestCount++
if (this.abort) {
throw new Error("ClaudeDev instance aborted")

View File

@@ -22,7 +22,6 @@ type GlobalStateKey =
| "awsRegion"
| "vertexProjectId"
| "vertexRegion"
| "maxRequestsPerTask"
| "lastShownAnnouncementId"
| "customInstructions"
| "alwaysAllowReadOnly"
@@ -166,11 +165,10 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
async initClaudeDevWithTask(task?: string, images?: string[]) {
await this.clearTask() // ensures that an exising task doesn't exist before starting a new one, although this shouldn't be possible since user must clear task before starting a new one
const { maxRequestsPerTask, apiConfiguration, customInstructions, alwaysAllowReadOnly } = await this.getState()
const { apiConfiguration, customInstructions, alwaysAllowReadOnly } = await this.getState()
this.claudeDev = new ClaudeDev(
this,
apiConfiguration,
maxRequestsPerTask,
customInstructions,
alwaysAllowReadOnly,
task,
@@ -180,11 +178,10 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
async initClaudeDevWithHistoryItem(historyItem: HistoryItem) {
await this.clearTask()
const { maxRequestsPerTask, apiConfiguration, customInstructions, alwaysAllowReadOnly } = await this.getState()
const { apiConfiguration, customInstructions, alwaysAllowReadOnly } = await this.getState()
this.claudeDev = new ClaudeDev(
this,
apiConfiguration,
maxRequestsPerTask,
customInstructions,
alwaysAllowReadOnly,
undefined,
@@ -329,18 +326,6 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
}
await this.postStateToWebview()
break
case "maxRequestsPerTask":
let result: number | undefined = undefined
if (message.text && message.text.trim()) {
const num = Number(message.text)
if (!isNaN(num)) {
result = num
}
}
await this.updateGlobalState("maxRequestsPerTask", result)
this.claudeDev?.updateMaxRequestsPerTask(result)
await this.postStateToWebview()
break
case "customInstructions":
// User may be clearing the field
await this.updateGlobalState("customInstructions", message.text || undefined)
@@ -489,7 +474,6 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
async getStateToPostToWebview() {
const {
apiConfiguration,
maxRequestsPerTask,
lastShownAnnouncementId,
customInstructions,
alwaysAllowReadOnly,
@@ -498,7 +482,6 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
return {
version: this.context.extension?.packageJSON?.version ?? "",
apiConfiguration,
maxRequestsPerTask,
customInstructions,
alwaysAllowReadOnly,
themeName: vscode.workspace.getConfiguration("workbench").get<string>("colorTheme"),
@@ -606,7 +589,6 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
awsRegion,
vertexProjectId,
vertexRegion,
maxRequestsPerTask,
lastShownAnnouncementId,
customInstructions,
alwaysAllowReadOnly,
@@ -621,7 +603,6 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
this.getGlobalState("awsRegion") as Promise<string | undefined>,
this.getGlobalState("vertexProjectId") as Promise<string | undefined>,
this.getGlobalState("vertexRegion") as Promise<string | undefined>,
this.getGlobalState("maxRequestsPerTask") as Promise<number | undefined>,
this.getGlobalState("lastShownAnnouncementId") as Promise<string | undefined>,
this.getGlobalState("customInstructions") as Promise<string | undefined>,
this.getGlobalState("alwaysAllowReadOnly") as Promise<boolean | undefined>,
@@ -654,7 +635,6 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
vertexProjectId,
vertexRegion,
},
maxRequestsPerTask,
lastShownAnnouncementId,
customInstructions,
alwaysAllowReadOnly: alwaysAllowReadOnly ?? false,

View File

@@ -1 +0,0 @@
export const DEFAULT_MAX_REQUESTS_PER_TASK = 20

View File

@@ -15,7 +15,6 @@ export interface ExtensionMessage {
export interface ExtensionState {
version: string
apiConfiguration?: ApiConfiguration
maxRequestsPerTask?: number
customInstructions?: string
alwaysAllowReadOnly?: boolean
themeName?: string
@@ -35,7 +34,6 @@ export interface ClaudeMessage {
}
export type ClaudeAsk =
| "request_limit_reached"
| "followup"
| "command"
| "command_output"

View File

@@ -3,7 +3,6 @@ import { ApiConfiguration, ApiProvider } from "./api"
export interface WebviewMessage {
type:
| "apiConfiguration"
| "maxRequestsPerTask"
| "customInstructions"
| "alwaysAllowReadOnly"
| "webviewDidLaunch"