From 7b4ad310ad17504c3fae6b33b7fddadf4b028f69 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Fri, 4 Oct 2024 17:49:45 -0400 Subject: [PATCH] Remove partial xml tag from end of text content --- src/core/ClaudeDev.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/core/ClaudeDev.ts b/src/core/ClaudeDev.ts index def89d9..7cdef9c 100644 --- a/src/core/ClaudeDev.ts +++ b/src/core/ClaudeDev.ts @@ -781,9 +781,30 @@ export class ClaudeDev { const block = cloneDeep(this.assistantMessageContent[this.currentStreamingContentIndex]) // need to create copy bc while stream is updating the array, it could be updating the reference block properties too switch (block.type) { - case "text": - await this.say("text", block.content, undefined, block.partial) + case "text": { + let content = block.content + if (block.partial && content) { + // Remove partial XML tag at the very end of the content + const lastOpenBracketIndex = content.lastIndexOf("<") + if (lastOpenBracketIndex !== -1) { + const possibleTag = content.slice(lastOpenBracketIndex) + // Check if there's a '>' after the last '<' (i.e., if the tag is complete) + const hasCloseBracket = possibleTag.includes(">") + if (!hasCloseBracket) { + // Extract the potential tag name + const tagContent = possibleTag.slice(1).trim() + // Check if tagContent is likely an incomplete tag name (letters and underscores only) + const isLikelyTagName = /^[a-zA-Z_]+$/.test(tagContent) + // If the tag is incomplete and at the end, remove it from the content + if (isLikelyTagName) { + content = content.slice(0, lastOpenBracketIndex).trim() + } + } + } + } + await this.say("text", content, undefined, block.partial) break + } case "tool_use": const toolDescription = () => { switch (block.name) {