From 07f50e63a3da9e2148e7c6d7ceba008b80263f7c Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:18:29 -0400 Subject: [PATCH] Persist API conversation history locally instead of in state as there seems to be an issue with some messages not being stringifyable --- package-lock.json | 4 ++-- package.json | 2 +- src/ClaudeDev.ts | 1 - src/providers/ClaudeDevProvider.ts | 29 ++++++++++++++++++++--------- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9a1b936..2769529 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "claude-dev", - "version": "1.0.84", + "version": "1.0.85", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "claude-dev", - "version": "1.0.84", + "version": "1.0.85", "license": "MIT", "dependencies": { "@anthropic-ai/sdk": "^0.24.3", diff --git a/package.json b/package.json index 353c9c8..9808420 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "claude-dev", "displayName": "Claude Dev", "description": "Autonomous software engineer right in your IDE, capable of creating/editing files, executing commands, and more with your permission every step of the way.", - "version": "1.0.84", + "version": "1.0.85", "icon": "icon.png", "engines": { "vscode": "^1.84.0" diff --git a/src/ClaudeDev.ts b/src/ClaudeDev.ts index 0721ecb..0f7ce94 100644 --- a/src/ClaudeDev.ts +++ b/src/ClaudeDev.ts @@ -41,7 +41,6 @@ RULES path.join(os.homedir(), "Desktop") } - Your current working directory is '${process.cwd()}', and you cannot \`cd\` into a different directory to complete a task. You are stuck operating from '${process.cwd()}', so be sure to pass in the appropriate 'path' parameter when using tools that require a path. -- If you do not know the contents of an existing file you need to edit, use the read_file tool to help you make informed changes. However if you have already read or written to this file before, you can assume its contents have not changed since then so you would not need to call the read_file tool beforehand. - When editing files, always provide the complete file content in your response, regardless of the extent of changes. The system handles diff generation automatically. - Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. - When creating a new project (such as an app, website, or any software project), unless the user specifies otherwise, organize all new files within a dedicated project directory. Use appropriate file paths when writing files, as the write_to_file tool will automatically create any necessary directories. Structure the project logically, adhering to best practices for the specific type of project being created. Unless otherwise specified, new projects should be easily run without additional setup, for example most projects can be built in HTML, CSS, and JavaScript - which you can open in a browser. diff --git a/src/providers/ClaudeDevProvider.ts b/src/providers/ClaudeDevProvider.ts index e56df58..2564ade 100644 --- a/src/providers/ClaudeDevProvider.ts +++ b/src/providers/ClaudeDevProvider.ts @@ -440,22 +440,33 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider { // conversation history to send in API requests + /* + It seems that some API messages do not comply with vscode state requirements. Either the Anthropic library is manipulating these values somehow in the backend in a way thats creating cyclic references, or the API returns a function or a Symbol as part of the message content. + VSCode docs about state: "The value must be JSON-stringifyable ... value — A value. MUST not contain cyclic references." + For now we'll store the conversation history in memory, and if we need to store in state directly we'd need to do a manual conversion to ensure proper json stringification. + */ + private apiConversationHistory: Anthropic.MessageParam[] = [] + async getApiConversationHistory(): Promise { - const history = (await this.getGlobalState( - this.getApiConversationHistoryStateKey() - )) as Anthropic.MessageParam[] - return history || [] + // const history = (await this.getGlobalState( + // this.getApiConversationHistoryStateKey() + // )) as Anthropic.MessageParam[] + // return history || [] + return this.apiConversationHistory } async setApiConversationHistory(history: Anthropic.MessageParam[] | undefined) { - await this.updateGlobalState(this.getApiConversationHistoryStateKey(), history) + // await this.updateGlobalState(this.getApiConversationHistoryStateKey(), history) + this.apiConversationHistory = history || [] } async addMessageToApiConversationHistory(message: Anthropic.MessageParam): Promise { - const history = await this.getApiConversationHistory() - history.push(message) - await this.setApiConversationHistory(history) - return history + // const history = await this.getApiConversationHistory() + // history.push(message) + // await this.setApiConversationHistory(history) + // return history + this.apiConversationHistory.push(message) + return this.apiConversationHistory } /*