Skip to content

Conversation

@daniel-lxs
Copy link
Member

Summary

This PR simplifies the XML schema for the apply_diff tool by removing unnecessary complexity and improving clarity.

Changes

1. Removed Backticks from XML Content

  • Before: XML content blocks contained triple backticks (```) mixing markdown syntax with XML
  • After: Clean XML without backticks, making parsing more straightforward

2. Eliminated Redundant args Wrapper

  • Before: <args><file>...</file></args>
  • After: <file>...</file> (files are direct children)

3. Removed Duplicate start_line Specification

  • Before: start_line could be specified both as XML element and within content
  • After: Only use in-content markers (:start_line:) when needed

4. Simplified Diff Structure

  • Before: <diff><content>...</content></diff>
  • After: <diff>...</diff> (content directly in diff element)

Example of New Schema

<apply_diff>
<file>
  <path>example.py</path>
  <diff>
<<<<<<< SEARCH
def old_function():
    return 'old'
=======
def new_function():
    return 'new'
>>>>>>> REPLACE
  </diff>
</file>
</apply_diff>

Benefits

  1. Cleaner Schema: No mixing of markdown and XML syntax
  2. Simpler Parsing: Fewer nested elements to parse
  3. Less Redundancy: Single way to specify metadata
  4. Better Error Messages: Clearer structure makes errors easier to understand
  5. Backward Compatibility: Legacy format still supported

Testing

  • Updated parsing logic to handle new schema
  • Maintained backward compatibility with old format
  • Updated tool descriptions and examples
  • Manual testing with various diff scenarios

Breaking Changes

While backward compatibility is maintained, this changes the recommended XML schema format for the apply_diff tool. Documentation and examples have been updated accordingly.

- Remove backticks from XML content blocks in tool descriptions
- Eliminate redundant args wrapper from XML structure
- Remove duplicate start_line specification (keep only in-content markers)
- Update parsing logic to handle simplified schema
- Maintain backward compatibility with legacy format

BREAKING CHANGE: The apply_diff tool now uses a simplified XML schema without backticks inside content blocks and without the args wrapper. The diff content is now placed directly in the diff element.
Copy link
Contributor

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! I've reviewed the changes and have some suggestions for improvement. Overall, this is a good refactoring that simplifies the XML schema as intended. The backward compatibility implementation looks solid, and the cleaner schema will make the tool easier to use.

diffContent = String(diff)
// Extract start_line from the diff content if present
const startLineMatch = diffContent.match(/:start_line:\s*(\d+)/)
startLine = startLineMatch ? parseInt(startLineMatch[1]) : undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? The code extracts :start_line: from the diff content here, but the documentation in multi-file-search-replace.ts no longer mentions this format. Should we update the documentation to clarify that :start_line: can still be used within the diff content for cases where it's needed?

</diff>
</file>
</args>
Expected structure (simplified):
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

startLine = diff.start_line ? parseInt(diff.start_line) : undefined
} else {
// New simplified format - diff is the content string directly
diffContent = String(diff)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a type guard or validation here to ensure diff is actually a string in the simplified format case. While String(diff) works, explicit type checking would make the code more robust:

Suggested change
diffContent = String(diff)
// New simplified format - diff is the content string directly
if (typeof diff !== 'string') {
throw new Error('Invalid diff format: expected string for simplified format');
}
diffContent = diff;

// For legacy format, diff has content and start_line properties
if (typeof diff === "object" && diff.content) {
// Legacy format with content wrapper
diffContent = diff.content
Copy link
Contributor

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:

Suggested change
diffContent = diff.content
// Legacy format with content wrapper
console.warn('[Deprecation] The <content> wrapper in apply_diff is deprecated. Please use the simplified format with diff content directly.');
diffContent = diff.content

@daniel-lxs
Copy link
Member Author

This broke the tool

@daniel-lxs daniel-lxs closed this Aug 7, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 7, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Aug 7, 2025
@hannesrudolph
Copy link
Collaborator

This is the best solution! 👍

After investigating the issue thoroughly, this PR provides the cleanest fix. By removing the backticks entirely from the XML examples, we eliminate the root cause of the parsing errors without needing:

The simplified schema is much cleaner and more maintainable. This should be the preferred solution for fixing issue #4852.

Summary of approaches:

I recommend merging this PR and closing the others.

@Avinm
Copy link

Avinm commented Aug 7, 2025

Not sure if it's related, but I found that RooCode fails on this prompt:

Can you create test.md with the below lines verbatim?
```mermaid
```

It just writes an empty file. Would this fix it?

@daniel-lxs daniel-lxs deleted the simplify-apply-diff-xml-schema branch August 7, 2025 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants