From 114c850e4e1123ac202edf2add6254ebd11c2b23 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Fri, 4 Oct 2024 16:58:04 -0400 Subject: [PATCH] Pre-process file content to remove artifacts --- src/core/ClaudeDev.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/core/ClaudeDev.ts b/src/core/ClaudeDev.ts index 43ee777..def89d9 100644 --- a/src/core/ClaudeDev.ts +++ b/src/core/ClaudeDev.ts @@ -925,6 +925,16 @@ export class ClaudeDev { fileExists = await fileExistsAtPath(absolutePath) this.diffViewProvider.editType = fileExists ? "modify" : "create" } + + // pre-processing newContent for cases where weaker models might add artifacts like markdown codeblock markers (deepseek/llama) or extra escape characters (gemini) + if (newContent.startsWith("```")) { + // this handles cases where it includes language specifiers like ```python ```js + newContent = newContent.split("\n").slice(1).join("\n").trim() + } + if (newContent.endsWith("```")) { + newContent = newContent.split("\n").slice(0, -1).join("\n").trim() + } + const sharedMessageProps: ClaudeSayTool = { tool: fileExists ? "editedExistingFile" : "newFileCreated", path: getReadablePath(cwd, removeClosingTag("path", relPath)), @@ -1596,7 +1606,7 @@ export class ClaudeDev { // stream did not complete tool call, add it as partial if (currentParamName) { // tool call has a parameter that was not completed - currentToolUse.params[currentParamName] = accumulator.slice(currentParamValueStartIndex) + currentToolUse.params[currentParamName] = accumulator.slice(currentParamValueStartIndex).trim() } toolUses.push(currentToolUse) }