Skip to content

Commit 03f2236

Browse files
committed
refactor: Simplify result handling for tool responses in Cline
This update refines the handling of tool responses in the `Cline` class by removing the XML formatting for `read_file` results and consolidating the logic for pushing results to the user message content. The changes ensure that all tool results are processed uniformly, improving code clarity and maintainability.
1 parent 92815f8 commit 03f2236

File tree

1 file changed

+7
-27
lines changed

1 file changed

+7
-27
lines changed

src/core/Cline.ts

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,38 +1438,18 @@ export class Cline extends EventEmitter<ClineEvents> {
14381438
}
14391439

14401440
const pushToolResult = (content: ToolResponse) => {
1441-
if (block.name === "read_file") {
1442-
// Special formatting for read_file results
1443-
const filePath = block.params.path || "unknown/path" // Use fallback if path is missing
1444-
const fileContent =
1445-
typeof content === "string"
1446-
? content || "(tool did not return anything)"
1447-
: "Error: Expected string content for read_file" // read_file should return string
1448-
1449-
const xmlResult = `<file>\n <path>${filePath}</path>\n <content>\n${fileContent}\n </content>\n</file>`
1450-
1441+
this.userMessageContent.push({
1442+
type: "text",
1443+
text: `${toolDescription()} Result:`,
1444+
})
1445+
if (typeof content === "string") {
14511446
this.userMessageContent.push({
14521447
type: "text",
1453-
text: xmlResult,
1448+
text: content || "(tool did not return anything)",
14541449
})
14551450
} else {
1456-
// Original formatting for all other tools
1457-
this.userMessageContent.push({
1458-
type: "text",
1459-
text: `${toolDescription()} Result:`,
1460-
})
1461-
if (typeof content === "string") {
1462-
this.userMessageContent.push({
1463-
type: "text",
1464-
text: content || "(tool did not return anything)",
1465-
})
1466-
} else {
1467-
// Handle potential non-string content for other tools
1468-
this.userMessageContent.push(...content)
1469-
}
1451+
this.userMessageContent.push(...content)
14701452
}
1471-
1472-
// Common logic after pushing result
14731453
// once a tool result has been collected, ignore all other tool uses since we should only ever present one tool result per message
14741454
this.didAlreadyUseTool = true
14751455

0 commit comments

Comments
 (0)