diff --git a/src/ClaudeDev.ts b/src/ClaudeDev.ts index 5e65dd6..673a1cf 100644 --- a/src/ClaudeDev.ts +++ b/src/ClaudeDev.ts @@ -78,19 +78,6 @@ Operating System: ${osName()} Default Shell: ${defaultShell} Home Directory: ${os.homedir()} Current Working Directory: ${cwd} -VSCode Visible Files: ${ - vscode.window.visibleTextEditors - ?.map((editor) => editor.document?.uri?.fsPath) - .filter(Boolean) - .join(", ") || "(No files open)" - } -VSCode Opened Tabs: ${ - vscode.window.tabGroups.all - .flatMap((group) => group.tabs) - .map((tab) => (tab.input as vscode.TabInputText)?.uri?.fsPath) - .filter(Boolean) - .join(", ") || "(No tabs open)" - } ` const cwd = @@ -349,7 +336,10 @@ export class ClaudeDev { this.apiConversationHistory = [] await this.providerRef.deref()?.postStateToWebview() - let textBlock: Anthropic.TextBlockParam = { type: "text", text: `Task: \"${task}\"` } + let textBlock: Anthropic.TextBlockParam = { + type: "text", + text: `\n${task}\n\n${this.getPotentiallyRelevantDetails()}`, // cannot be sent with system prompt since it's cached and these details can change + } let imageBlocks: Anthropic.ImageBlockParam[] = this.formatImagesIntoBlocks(images) // TODO: create tools that let Claude interact with VSCode (e.g. open a file, list open files, etc.) @@ -500,10 +490,7 @@ export class ClaudeDev { } if (response === "messageResponse") { await this.say("user_feedback", text, images) - return this.formatIntoToolResponse( - `The user denied this operation and provided the following feedback:\n\"${text}\"`, - images - ) + return this.formatIntoToolResponse(this.formatGenericToolFeedback(text), images) } return "The user denied this operation." } @@ -540,10 +527,7 @@ export class ClaudeDev { } if (response === "messageResponse") { await this.say("user_feedback", text, images) - return this.formatIntoToolResponse( - `The user denied this operation and provided the following feedback:\n\"${text}\"`, - images - ) + return this.formatIntoToolResponse(this.formatGenericToolFeedback(text), images) } return "The user denied this operation." } @@ -590,10 +574,7 @@ export class ClaudeDev { if (response !== "yesButtonTapped") { if (response === "messageResponse") { await this.say("user_feedback", text, images) - return this.formatIntoToolResponse( - `The user denied this operation and provided the following feedback:\n\"${text}\"`, - images - ) + return this.formatIntoToolResponse(this.formatGenericToolFeedback(text), images) } return "The user denied this operation." } @@ -628,10 +609,7 @@ export class ClaudeDev { if (response !== "yesButtonTapped") { if (response === "messageResponse") { await this.say("user_feedback", text, images) - return this.formatIntoToolResponse( - `The user denied this operation and provided the following feedback:\n\"${text}\"`, - images - ) + return this.formatIntoToolResponse(this.formatGenericToolFeedback(text), images) } return "The user denied this operation." } @@ -671,10 +649,7 @@ export class ClaudeDev { if (response !== "yesButtonTapped") { if (response === "messageResponse") { await this.say("user_feedback", text, images) - return this.formatIntoToolResponse( - `The user denied this operation and provided the following feedback:\n\"${text}\"`, - images - ) + return this.formatIntoToolResponse(this.formatGenericToolFeedback(text), images) } return "The user denied this operation." } @@ -760,10 +735,7 @@ export class ClaudeDev { if (response !== "yesButtonTapped") { if (response === "messageResponse") { await this.say("user_feedback", text, images) - return this.formatIntoToolResponse( - `The user denied this operation and provided the following feedback:\n\"${text}\"`, - images - ) + return this.formatIntoToolResponse(this.formatGenericToolFeedback(text), images) } return "The user denied this operation." } @@ -792,10 +764,7 @@ export class ClaudeDev { if (response !== "yesButtonTapped") { if (response === "messageResponse") { await this.say("user_feedback", text, images) - return this.formatIntoToolResponse( - `The user denied this operation and provided the following feedback:\n\"${text}\"`, - images - ) + return this.formatIntoToolResponse(this.formatGenericToolFeedback(text), images) } return "The user denied this operation." } @@ -894,7 +863,7 @@ export class ClaudeDev { } const { text, images } = await this.ask("followup", question) await this.say("user_feedback", text ?? "", images) - return this.formatIntoToolResponse(`User's response:\n\"${text}\"`, images) + return this.formatIntoToolResponse(`\n${text}\n`, images) } async attemptCompletion(result?: string, command?: string): Promise { @@ -923,7 +892,7 @@ export class ClaudeDev { } await this.say("user_feedback", text ?? "", images) return this.formatIntoToolResponse( - `The user is not pleased with the results. Use the feedback they provided to successfully complete the task, and then attempt completion again.\nUser's feedback:\n\"${text}\"`, + `The user is not pleased with the results. Use the feedback they provided to successfully complete the task, and then attempt completion again.\n\n${text}\n`, images ) } @@ -1119,4 +1088,29 @@ ${this.customInstructions.trim()} return { didEndLoop: true, inputTokens: 0, outputTokens: 0 } } } + + // Prompts + + getPotentiallyRelevantDetails() { + // TODO: add more details + return ` +VSCode Visible Files: ${ + vscode.window.visibleTextEditors + ?.map((editor) => editor.document?.uri?.fsPath) + .filter(Boolean) + .join(", ") || "(No files open)" + } +VSCode Opened Tabs: ${ + vscode.window.tabGroups.all + .flatMap((group) => group.tabs) + .map((tab) => (tab.input as vscode.TabInputText)?.uri?.fsPath) + .filter(Boolean) + .join(", ") || "(No tabs open)" + } +` + } + + formatGenericToolFeedback(feedback?: string) { + return `The user denied this operation and provided the following feedback:\n\n${feedback}\n\n\n${this.getPotentiallyRelevantDetails()}` + } }