mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 12:21:13 -05:00
Remove partial closing tags from params
This commit is contained in:
@@ -881,6 +881,27 @@ export class ClaudeDev {
|
|||||||
pushToolResult(formatResponse.toolError(errorString))
|
pushToolResult(formatResponse.toolError(errorString))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If block is partial, remove partial closing tag so its not presented to user
|
||||||
|
const removeClosingTag = (tag: ToolParamName, text?: string) => {
|
||||||
|
if (!block.partial) {
|
||||||
|
return text || ""
|
||||||
|
}
|
||||||
|
if (!text) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
// This regex dynamically constructs a pattern to match the closing tag:
|
||||||
|
// - Optionally matches whitespace before the tag
|
||||||
|
// - Matches '<' or '</' optionally followed by any subset of characters from the tag name
|
||||||
|
const tagRegex = new RegExp(
|
||||||
|
`\\s?<\/?${tag
|
||||||
|
.split("")
|
||||||
|
.map((char) => `(?:${char})?`)
|
||||||
|
.join("")}$`,
|
||||||
|
"g"
|
||||||
|
)
|
||||||
|
return text.replace(tagRegex, "")
|
||||||
|
}
|
||||||
|
|
||||||
switch (block.name) {
|
switch (block.name) {
|
||||||
case "write_to_file": {
|
case "write_to_file": {
|
||||||
const relPath: string | undefined = block.params.path
|
const relPath: string | undefined = block.params.path
|
||||||
@@ -901,7 +922,7 @@ export class ClaudeDev {
|
|||||||
}
|
}
|
||||||
const sharedMessageProps: ClaudeSayTool = {
|
const sharedMessageProps: ClaudeSayTool = {
|
||||||
tool: fileExists ? "editedExistingFile" : "newFileCreated",
|
tool: fileExists ? "editedExistingFile" : "newFileCreated",
|
||||||
path: getReadablePath(cwd, relPath),
|
path: getReadablePath(cwd, removeClosingTag("path", relPath)),
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (block.partial) {
|
if (block.partial) {
|
||||||
@@ -989,7 +1010,7 @@ export class ClaudeDev {
|
|||||||
const relPath: string | undefined = block.params.path
|
const relPath: string | undefined = block.params.path
|
||||||
const sharedMessageProps: ClaudeSayTool = {
|
const sharedMessageProps: ClaudeSayTool = {
|
||||||
tool: "readFile",
|
tool: "readFile",
|
||||||
path: getReadablePath(cwd, relPath),
|
path: getReadablePath(cwd, removeClosingTag("path", relPath)),
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (block.partial) {
|
if (block.partial) {
|
||||||
@@ -1039,7 +1060,7 @@ export class ClaudeDev {
|
|||||||
const recursive = recursiveRaw?.toLowerCase() === "true"
|
const recursive = recursiveRaw?.toLowerCase() === "true"
|
||||||
const sharedMessageProps: ClaudeSayTool = {
|
const sharedMessageProps: ClaudeSayTool = {
|
||||||
tool: !recursive ? "listFilesTopLevel" : "listFilesRecursive",
|
tool: !recursive ? "listFilesTopLevel" : "listFilesRecursive",
|
||||||
path: getReadablePath(cwd, relDirPath),
|
path: getReadablePath(cwd, removeClosingTag("path", relDirPath)),
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (block.partial) {
|
if (block.partial) {
|
||||||
@@ -1087,7 +1108,7 @@ export class ClaudeDev {
|
|||||||
const relDirPath: string | undefined = block.params.path
|
const relDirPath: string | undefined = block.params.path
|
||||||
const sharedMessageProps: ClaudeSayTool = {
|
const sharedMessageProps: ClaudeSayTool = {
|
||||||
tool: "listCodeDefinitionNames",
|
tool: "listCodeDefinitionNames",
|
||||||
path: getReadablePath(cwd, relDirPath),
|
path: getReadablePath(cwd, removeClosingTag("path", relDirPath)),
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (block.partial) {
|
if (block.partial) {
|
||||||
@@ -1138,9 +1159,9 @@ export class ClaudeDev {
|
|||||||
const filePattern: string | undefined = block.params.file_pattern
|
const filePattern: string | undefined = block.params.file_pattern
|
||||||
const sharedMessageProps: ClaudeSayTool = {
|
const sharedMessageProps: ClaudeSayTool = {
|
||||||
tool: "searchFiles",
|
tool: "searchFiles",
|
||||||
path: getReadablePath(cwd, relDirPath),
|
path: getReadablePath(cwd, removeClosingTag("path", relDirPath)),
|
||||||
regex: regex || "",
|
regex: removeClosingTag("regex", regex),
|
||||||
filePattern: filePattern || "",
|
filePattern: removeClosingTag("file_pattern", filePattern),
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (block.partial) {
|
if (block.partial) {
|
||||||
@@ -1192,7 +1213,7 @@ export class ClaudeDev {
|
|||||||
const url: string | undefined = block.params.url
|
const url: string | undefined = block.params.url
|
||||||
const sharedMessageProps: ClaudeSayTool = {
|
const sharedMessageProps: ClaudeSayTool = {
|
||||||
tool: "inspectSite",
|
tool: "inspectSite",
|
||||||
path: url || "",
|
path: removeClosingTag("url", url),
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (block.partial) {
|
if (block.partial) {
|
||||||
@@ -1255,7 +1276,9 @@ export class ClaudeDev {
|
|||||||
const command: string | undefined = block.params.command
|
const command: string | undefined = block.params.command
|
||||||
try {
|
try {
|
||||||
if (block.partial) {
|
if (block.partial) {
|
||||||
await this.ask("command", command || "", block.partial).catch(() => {})
|
await this.ask("command", removeClosingTag("command", command), block.partial).catch(
|
||||||
|
() => {}
|
||||||
|
)
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
if (!command) {
|
if (!command) {
|
||||||
@@ -1287,7 +1310,9 @@ export class ClaudeDev {
|
|||||||
const question: string | undefined = block.params.question
|
const question: string | undefined = block.params.question
|
||||||
try {
|
try {
|
||||||
if (block.partial) {
|
if (block.partial) {
|
||||||
await this.ask("followup", question || "", block.partial).catch(() => {})
|
await this.ask("followup", removeClosingTag("question", question), block.partial).catch(
|
||||||
|
() => {}
|
||||||
|
)
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
if (!question) {
|
if (!question) {
|
||||||
@@ -1341,16 +1366,34 @@ export class ClaudeDev {
|
|||||||
// const secondLastMessage = this.claudeMessages.at(-2)
|
// const secondLastMessage = this.claudeMessages.at(-2)
|
||||||
if (lastMessage && lastMessage.ask === "command") {
|
if (lastMessage && lastMessage.ask === "command") {
|
||||||
// update command
|
// update command
|
||||||
await this.ask("command", command || "", block.partial).catch(() => {})
|
await this.ask(
|
||||||
|
"command",
|
||||||
|
removeClosingTag("command", command),
|
||||||
|
block.partial
|
||||||
|
).catch(() => {})
|
||||||
} else {
|
} else {
|
||||||
// last message is completion_result
|
// last message is completion_result
|
||||||
// we have command string, which means we have the result as well, so finish it (doesnt have to exist yet)
|
// we have command string, which means we have the result as well, so finish it (doesnt have to exist yet)
|
||||||
await this.say("completion_result", result, undefined, false)
|
await this.say(
|
||||||
await this.ask("command", command || "", block.partial).catch(() => {})
|
"completion_result",
|
||||||
|
removeClosingTag("result", result),
|
||||||
|
undefined,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
await this.ask(
|
||||||
|
"command",
|
||||||
|
removeClosingTag("command", command),
|
||||||
|
block.partial
|
||||||
|
).catch(() => {})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// no command, still outputting partial result
|
// no command, still outputting partial result
|
||||||
await this.say("completion_result", result || "", undefined, block.partial)
|
await this.say(
|
||||||
|
"completion_result",
|
||||||
|
removeClosingTag("result", result),
|
||||||
|
undefined,
|
||||||
|
block.partial
|
||||||
|
)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user