-
Notifications
You must be signed in to change notification settings - Fork 2.6k
refactor: simplify apply_diff XML schema #6812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -106,9 +106,10 @@ export async function applyDiffTool( | |||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if (argsXmlTag) { | ||||||||||||||
| // Parse file entries from XML (new way) | ||||||||||||||
| // Parse file entries from XML | ||||||||||||||
| try { | ||||||||||||||
| const parsed = parseXml(argsXmlTag, ["file.diff.content"]) as ParsedXmlResult | ||||||||||||||
| // Try parsing with simplified schema (no content wrapper) | ||||||||||||||
| const parsed = parseXml(argsXmlTag, ["file.diff"]) as ParsedXmlResult | ||||||||||||||
| const files = Array.isArray(parsed.file) ? parsed.file : [parsed.file].filter(Boolean) | ||||||||||||||
|
|
||||||||||||||
| for (const file of files) { | ||||||||||||||
|
|
@@ -132,8 +133,19 @@ export async function applyDiffTool( | |||||||||||||
| let diffContent: string | ||||||||||||||
| let startLine: number | undefined | ||||||||||||||
|
|
||||||||||||||
| diffContent = diff.content | ||||||||||||||
| startLine = diff.start_line ? parseInt(diff.start_line) : undefined | ||||||||||||||
| // For simplified format, diff is the content directly | ||||||||||||||
| // For legacy format, diff has content and start_line properties | ||||||||||||||
| if (typeof diff === "object" && diff.content) { | ||||||||||||||
| // Legacy format with content wrapper | ||||||||||||||
| diffContent = diff.content | ||||||||||||||
| startLine = diff.start_line ? parseInt(diff.start_line) : undefined | ||||||||||||||
| } else { | ||||||||||||||
| // New simplified format - diff is the content string directly | ||||||||||||||
| diffContent = String(diff) | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a type guard or validation here to ensure
Suggested change
|
||||||||||||||
| // Extract start_line from the diff content if present | ||||||||||||||
| const startLineMatch = diffContent.match(/:start_line:\s*(\d+)/) | ||||||||||||||
| startLine = startLineMatch ? parseInt(startLineMatch[1]) : undefined | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this intentional? The code extracts |
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| operationsMap[filePath].diff.push({ | ||||||||||||||
| content: diffContent, | ||||||||||||||
|
|
@@ -148,16 +160,17 @@ export async function applyDiffTool( | |||||||||||||
| 2. Missing required <file>, <path>, or <diff> tags | ||||||||||||||
| 3. Invalid characters or encoding in the XML | ||||||||||||||
|
|
||||||||||||||
| Expected structure: | ||||||||||||||
| <args> | ||||||||||||||
| <file> | ||||||||||||||
| <path>relative/path/to/file.ext</path> | ||||||||||||||
| <diff> | ||||||||||||||
| <content>diff content here</content> | ||||||||||||||
| <start_line>line number</start_line> | ||||||||||||||
| </diff> | ||||||||||||||
| </file> | ||||||||||||||
| </args> | ||||||||||||||
| Expected structure (simplified): | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message shows the simplified structure, which is great! However, would it be helpful to also mention that the legacy format is still supported for backward compatibility? This could help users who are migrating from the old format. |
||||||||||||||
| <file> | ||||||||||||||
| <path>relative/path/to/file.ext</path> | ||||||||||||||
| <diff> | ||||||||||||||
| <<<<<<< SEARCH | ||||||||||||||
| exact content to find | ||||||||||||||
| ======= | ||||||||||||||
| replacement content | ||||||||||||||
| >>>>>>> REPLACE | ||||||||||||||
| </diff> | ||||||||||||||
| </file> | ||||||||||||||
|
|
||||||||||||||
| Original error: ${errorMessage}` | ||||||||||||||
| cline.consecutiveMistakeCount++ | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this maintains backward compatibility but changes the recommended format, would it be helpful to add a deprecation notice when the legacy format is detected? This could guide users to migrate to the cleaner schema over time. For example: