From ba4caf4f0079ffbca1a94e75917dbdde6f270c58 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Sun, 1 Sep 2024 01:41:43 -0400 Subject: [PATCH] Remove max requests per task settings option --- src/ClaudeDev.ts | 31 ------------ src/providers/ClaudeDevProvider.ts | 24 +--------- src/shared/Constants.ts | 1 - src/shared/ExtensionMessage.ts | 2 - src/shared/WebviewMessage.ts | 1 - webview-ui/src/components/ChatRow.tsx | 17 ------- webview-ui/src/components/ChatView.tsx | 9 ---- webview-ui/src/components/SettingsView.tsx | 48 ++----------------- .../src/context/ExtensionStateContext.tsx | 2 - webview-ui/src/utils/mockMessages.ts | 6 --- webview-ui/src/utils/validate.ts | 12 +---- 11 files changed, 6 insertions(+), 147 deletions(-) delete mode 100644 src/shared/Constants.ts diff --git a/src/ClaudeDev.ts b/src/ClaudeDev.ts index 79083e9..6cd23f0 100644 --- a/src/ClaudeDev.ts +++ b/src/ClaudeDev.ts @@ -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") diff --git a/src/providers/ClaudeDevProvider.ts b/src/providers/ClaudeDevProvider.ts index ab94f7c..f16b6a1 100644 --- a/src/providers/ClaudeDevProvider.ts +++ b/src/providers/ClaudeDevProvider.ts @@ -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("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, this.getGlobalState("vertexProjectId") as Promise, this.getGlobalState("vertexRegion") as Promise, - this.getGlobalState("maxRequestsPerTask") as Promise, this.getGlobalState("lastShownAnnouncementId") as Promise, this.getGlobalState("customInstructions") as Promise, this.getGlobalState("alwaysAllowReadOnly") as Promise, @@ -654,7 +635,6 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider { vertexProjectId, vertexRegion, }, - maxRequestsPerTask, lastShownAnnouncementId, customInstructions, alwaysAllowReadOnly: alwaysAllowReadOnly ?? false, diff --git a/src/shared/Constants.ts b/src/shared/Constants.ts deleted file mode 100644 index d2a182d..0000000 --- a/src/shared/Constants.ts +++ /dev/null @@ -1 +0,0 @@ -export const DEFAULT_MAX_REQUESTS_PER_TASK = 20 \ No newline at end of file diff --git a/src/shared/ExtensionMessage.ts b/src/shared/ExtensionMessage.ts index 410936e..57574f2 100644 --- a/src/shared/ExtensionMessage.ts +++ b/src/shared/ExtensionMessage.ts @@ -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" diff --git a/src/shared/WebviewMessage.ts b/src/shared/WebviewMessage.ts index afddd82..d8a4762 100644 --- a/src/shared/WebviewMessage.ts +++ b/src/shared/WebviewMessage.ts @@ -3,7 +3,6 @@ import { ApiConfiguration, ApiProvider } from "./api" export interface WebviewMessage { type: | "apiConfiguration" - | "maxRequestsPerTask" | "customInstructions" | "alwaysAllowReadOnly" | "webviewDidLaunch" diff --git a/webview-ui/src/components/ChatRow.tsx b/webview-ui/src/components/ChatRow.tsx index 65ef0ce..9bdc47f 100644 --- a/webview-ui/src/components/ChatRow.tsx +++ b/webview-ui/src/components/ChatRow.tsx @@ -57,13 +57,6 @@ const ChatRow: React.FC = ({ ) switch (type) { - case "request_limit_reached": - return [ - , - Max Requests Reached, - ] case "error": return [ = ({ switch (message.ask) { case "tool": return renderTool(message, headerStyle) - case "request_limit_reached": - return ( - <> -
- {icon} - {title} -
-

{message.text}

- - ) case "command": const splitMessage = (text: string) => { const outputIndex = text.indexOf(COMMAND_OUTPUT_STRING) diff --git a/webview-ui/src/components/ChatView.tsx b/webview-ui/src/components/ChatView.tsx index e7ea912..a60f4f9 100644 --- a/webview-ui/src/components/ChatView.tsx +++ b/webview-ui/src/components/ChatView.tsx @@ -95,13 +95,6 @@ const ChatView = ({ switch (lastMessage.type) { case "ask": switch (lastMessage.ask) { - case "request_limit_reached": - setTextAreaDisabled(true) - setClaudeAsk("request_limit_reached") - setEnableButtons(true) - setPrimaryButtonText("Proceed") - setSecondaryButtonText("Start New Task") - break case "api_req_failed": setTextAreaDisabled(true) setClaudeAsk("api_req_failed") @@ -257,7 +250,6 @@ const ChatView = ({ */ const handlePrimaryButtonClick = () => { switch (claudeAsk) { - case "request_limit_reached": case "api_req_failed": case "command": case "command_output": @@ -280,7 +272,6 @@ const ChatView = ({ const handleSecondaryButtonClick = () => { switch (claudeAsk) { - case "request_limit_reached": case "api_req_failed": startNewTask() break diff --git a/webview-ui/src/components/SettingsView.tsx b/webview-ui/src/components/SettingsView.tsx index d6fb27b..480919b 100644 --- a/webview-ui/src/components/SettingsView.tsx +++ b/webview-ui/src/components/SettingsView.tsx @@ -2,12 +2,11 @@ import { VSCodeButton, VSCodeCheckbox, VSCodeLink, - VSCodeTextArea, - VSCodeTextField, + VSCodeTextArea } from "@vscode/webview-ui-toolkit/react" import { useEffect, useState } from "react" import { useExtensionState } from "../context/ExtensionStateContext" -import { validateApiConfiguration, validateMaxRequestsPerTask } from "../utils/validate" +import { validateApiConfiguration } from "../utils/validate" import { vscode } from "../utils/vscode" import ApiOptions from "./ApiOptions" @@ -21,28 +20,20 @@ const SettingsView = ({ onDone }: SettingsViewProps) => { const { apiConfiguration, version, - maxRequestsPerTask, customInstructions, setCustomInstructions, alwaysAllowReadOnly, setAlwaysAllowReadOnly, } = useExtensionState() const [apiErrorMessage, setApiErrorMessage] = useState(undefined) - const [maxRequestsErrorMessage, setMaxRequestsErrorMessage] = useState(undefined) - const [maxRequestsPerTaskString, setMaxRequestsPerTaskString] = useState( - maxRequestsPerTask?.toString() || "" - ) const handleSubmit = () => { const apiValidationResult = validateApiConfiguration(apiConfiguration) - const maxRequestsValidationResult = validateMaxRequestsPerTask(maxRequestsPerTaskString) setApiErrorMessage(apiValidationResult) - setMaxRequestsErrorMessage(maxRequestsValidationResult) - if (!apiValidationResult && !maxRequestsValidationResult) { + if (!apiValidationResult) { vscode.postMessage({ type: "apiConfiguration", apiConfiguration }) - vscode.postMessage({ type: "maxRequestsPerTask", text: maxRequestsPerTaskString }) vscode.postMessage({ type: "customInstructions", text: customInstructions }) vscode.postMessage({ type: "alwaysAllowReadOnly", bool: alwaysAllowReadOnly }) onDone() @@ -53,10 +44,6 @@ const SettingsView = ({ onDone }: SettingsViewProps) => { setApiErrorMessage(undefined) }, [apiConfiguration]) - useEffect(() => { - setMaxRequestsErrorMessage(undefined) - }, [maxRequestsPerTask]) - // validate as soon as the component is mounted /* useEffect will use stale values of variables if they are not included in the dependency array. so trying to use useEffect with a dependency array of only one value for example will use any other variables' old values. In most cases you don't want this, and should opt to use react-use hooks. @@ -141,35 +128,6 @@ const SettingsView = ({ onDone }: SettingsViewProps) => {

-
- setMaxRequestsPerTaskString(e.target?.value ?? "")}> - Maximum # Requests Per Task - -

- If Claude Dev reaches this limit, it will pause and ask for your permission before making - additional requests. -

- {maxRequestsErrorMessage && ( -

- {maxRequestsErrorMessage} -

- )} -
- {IS_DEV && ( <>
Debug
diff --git a/webview-ui/src/context/ExtensionStateContext.tsx b/webview-ui/src/context/ExtensionStateContext.tsx index e346229..3f076b9 100644 --- a/webview-ui/src/context/ExtensionStateContext.tsx +++ b/webview-ui/src/context/ExtensionStateContext.tsx @@ -8,7 +8,6 @@ interface ExtensionStateContextType extends ExtensionState { didHydrateState: boolean showWelcome: boolean setApiConfiguration: (config: ApiConfiguration) => void - setMaxRequestsPerTask: (value?: number) => void setCustomInstructions: (value?: string) => void setAlwaysAllowReadOnly: (value: boolean) => void setShowAnnouncement: (value: boolean) => void @@ -52,7 +51,6 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode didHydrateState, showWelcome, setApiConfiguration: (value) => setState((prevState) => ({ ...prevState, apiConfiguration: value })), - setMaxRequestsPerTask: (value) => setState((prevState) => ({ ...prevState, maxRequestsPerTask: value })), setCustomInstructions: (value) => setState((prevState) => ({ ...prevState, customInstructions: value })), setAlwaysAllowReadOnly: (value) => setState((prevState) => ({ ...prevState, alwaysAllowReadOnly: value })), setShowAnnouncement: (value) => setState((prevState) => ({ ...prevState, shouldShowAnnouncement: value })), diff --git a/webview-ui/src/utils/mockMessages.ts b/webview-ui/src/utils/mockMessages.ts index d45be62..bce069a 100644 --- a/webview-ui/src/utils/mockMessages.ts +++ b/webview-ui/src/utils/mockMessages.ts @@ -204,12 +204,6 @@ export const mockMessages: ClaudeMessage[] = [ say: "text", text: "Great! The tests for the TodoList component have passed. All functionalities, including the new delete feature, are working as expected.", }, - { - ts: Date.now() - 2200000, - type: "ask", - ask: "request_limit_reached", - text: "You've reached the maximum number of requests for this task. Would you like to continue or start a new task?", - }, { ts: Date.now() - 2100000, type: "say", diff --git a/webview-ui/src/utils/validate.ts b/webview-ui/src/utils/validate.ts index 2bbfc94..4812495 100644 --- a/webview-ui/src/utils/validate.ts +++ b/webview-ui/src/utils/validate.ts @@ -26,14 +26,4 @@ export function validateApiConfiguration(apiConfiguration?: ApiConfiguration): s } } return undefined -} - -export function validateMaxRequestsPerTask(maxRequestsPerTask?: string): string | undefined { - if (maxRequestsPerTask && maxRequestsPerTask.trim()) { - const num = Number(maxRequestsPerTask) - if (isNaN(num) || num < 3 || num > 100) { - return "Maximum requests must be between 3 and 100" - } - } - return undefined -} +} \ No newline at end of file