Skip to content

Commit 4476607

Browse files
committed
feat: remove args param to avoid claude tool call format error
1 parent 83c0633 commit 4476607

File tree

4 files changed

+82
-92
lines changed

4 files changed

+82
-92
lines changed

src/core/prompts/tools/schemas/apply-diff-schema.ts

Lines changed: 43 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -158,61 +158,53 @@ When applying the diffs, be extra careful to remember to change any closing brac
158158
ALWAYS make as many changes in a single 'apply_diff' request as possible using multiple SEARCH/REPLACE blocks`,
159159
parameters: [
160160
{
161-
name: "args",
162-
type: "object",
163-
description: "Container for the file modification arguments.",
161+
name: "file",
162+
type: "array",
163+
description: `One or more file change objects.`,
164164
required: true,
165-
properties: {
166-
file: {
167-
name: "file",
168-
type: "array",
169-
description: `One or more file change objects.`,
170-
required: true,
171-
items: {
172-
name: "fileItem",
173-
type: "object",
174-
description: "A file modification object containing the path and diff operations.",
165+
items: {
166+
name: "fileItem",
167+
type: "object",
168+
description: "A file modification object containing the path and diff operations.",
169+
required: true,
170+
properties: {
171+
path: {
172+
name: "path",
173+
type: "string",
174+
description: `The path of the file to modify (relative to the current workspace directory ${args.cwd})`,
175175
required: true,
176-
properties: {
177-
path: {
178-
name: "path",
179-
type: "string",
180-
description: `The path of the file to modify (relative to the current workspace directory ${args.cwd})`,
181-
required: true,
182-
},
183-
diff: {
184-
name: "diff",
185-
type: "array",
186-
description: "One or more diff elements containing.",
187-
required: true,
188-
items: {
189-
name: "diffItem",
190-
type: "object",
176+
},
177+
diff: {
178+
name: "diff",
179+
type: "array",
180+
description: "One or more diff elements containing.",
181+
required: true,
182+
items: {
183+
name: "diffItem",
184+
type: "object",
185+
description:
186+
"A single search-and-replace operation. This object contains the search criteria and the replacement content.",
187+
required: true,
188+
properties: {
189+
search: {
190+
name: "search",
191+
type: "string",
191192
description:
192-
"A single search-and-replace operation. This object contains the search criteria and the replacement content.",
193+
"SEARCH BLOCK. MUST exactly match existing content including whitespace and indentation.",
194+
required: true,
195+
},
196+
replace: {
197+
name: "replace",
198+
type: "string",
199+
description: "REPLACE BLOCK.",
193200
required: true,
194-
properties: {
195-
search: {
196-
name: "search",
197-
type: "string",
198-
description:
199-
"SEARCH BLOCK. MUST exactly match existing content including whitespace and indentation.",
200-
required: true,
201-
},
202-
replace: {
203-
name: "replace",
204-
type: "string",
205-
description: "REPLACE BLOCK.",
206-
required: true,
207-
},
208-
start_line: {
209-
name: "start_line",
210-
type: "number",
211-
description:
212-
"The line number of original content where the search block starts",
213-
required: false,
214-
},
215-
},
201+
},
202+
start_line: {
203+
name: "start_line",
204+
type: "number",
205+
description:
206+
"The line number of original content where the search block starts",
207+
required: false,
216208
},
217209
},
218210
},

src/core/prompts/tools/schemas/read-file-schema.ts

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,44 +29,36 @@ ${
2929
${isMultipleReadsEnabled ? `- When you need to read more than ${maxConcurrentReads} files, prioritize the most critical files first, then use subsequent read_file requests for additional files` : ""}`,
3030
parameters: [
3131
{
32-
name: "args",
33-
type: "object",
34-
description: "Contains one or more file elements, where each file contains.",
32+
name: "file",
33+
type: "array",
34+
description: `An array of file objects to read, with an optional line range. Reading multiple files (within the ${maxConcurrentReads}-file limit).`,
3535
required: true,
36-
properties: {
37-
file: {
38-
name: "file",
39-
type: "array",
40-
description: `An array of file objects to read, with an optional line range. Reading multiple files (within the ${maxConcurrentReads}-file limit).`,
41-
required: true,
42-
items: {
43-
name: "fileItem",
44-
type: "object",
45-
description: "A file object",
36+
items: {
37+
name: "fileItem",
38+
type: "object",
39+
description: "A file object",
40+
required: true,
41+
properties: {
42+
path: {
43+
name: "path",
44+
type: "string",
45+
description: `File path (relative to workspace directory ${args.cwd}).`,
4646
required: true,
47-
properties: {
48-
path: {
49-
name: "path",
50-
type: "string",
51-
description: `File path (relative to workspace directory ${args.cwd}).`,
52-
required: true,
53-
},
54-
...(partialReadsEnabled
55-
? {
56-
line_range: {
57-
name: "line_range",
58-
type: "array",
59-
description: `One or more line range elements in format "start-end" (1-based, inclusive).`,
60-
required: false,
61-
items: {
62-
name: "text",
63-
type: "string",
64-
},
65-
},
66-
}
67-
: {}),
68-
},
6947
},
48+
...(partialReadsEnabled
49+
? {
50+
line_range: {
51+
name: "line_range",
52+
type: "array",
53+
description: `One or more line range elements in format "start-end" (1-based, inclusive).`,
54+
required: false,
55+
items: {
56+
name: "text",
57+
type: "string",
58+
},
59+
},
60+
}
61+
: {}),
7062
},
7163
},
7264
},

src/core/tools/multiApplyDiffTool.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,19 @@ export async function applyDiffTool(
105105
return
106106
}
107107

108-
if (argsXmlTag) {
108+
if (argsXmlTag || block.toolUseId) {
109109
// Parse file entries from XML (new way)
110110
try {
111111
let files = [] as any[]
112-
if (!block.toolUseId) {
112+
if (argsXmlTag) {
113113
// IMPORTANT: We use parseXmlForDiff here instead of parseXml to prevent HTML entity decoding
114114
// This ensures exact character matching when comparing parsed content against original file content
115115
// Without this, special characters like & would be decoded to & causing diff mismatches
116116
const parsed = parseXmlForDiff(argsXmlTag, ["file.diff.content"]) as ParsedXmlResult
117117
files = Array.isArray(parsed.file) ? parsed.file : [parsed.file].filter(Boolean)
118118
} else {
119119
const input = block.toolUseParam?.input as any
120-
const args = input.args
120+
const args = input
121121
files = Array.isArray(args?.file) ? args?.file : [args?.file].filter(Boolean)
122122
}
123123

src/core/tools/readFileTool.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,17 @@ export async function readFileTool(
125125

126126
const fileEntries: FileEntry[] = []
127127

128-
if (argsXmlTag) {
128+
if (argsXmlTag || block.toolUseId) {
129129
// Parse file entries from XML (new multi-file format)
130130
try {
131-
const parsed = parseXml(argsXmlTag) as any
132-
const files = Array.isArray(parsed.file) ? parsed.file : [parsed.file].filter(Boolean)
131+
let files: any[] = []
132+
if (argsXmlTag) {
133+
const parsed = parseXml(argsXmlTag) as any
134+
files = Array.isArray(parsed.file) ? parsed.file : [parsed.file].filter(Boolean)
135+
} else {
136+
const params: any = block.toolUseParam?.input
137+
files = params?.file || []
138+
}
133139

134140
for (const file of files) {
135141
if (!file.path) continue // Skip if no path in a file entry

0 commit comments

Comments
 (0)