Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jul 24, 2025

This PR implements the apply_code tool as proposed in issue #6159, providing a more reliable alternative to apply_diff for code modifications.

Summary

The apply_code tool uses a two-stage approach to improve code modification reliability:

  1. Stage 1: Creative code generation based on instructions (without diff context noise)
  2. Stage 2: Focused diff generation with clean context

Changes

  • Added new applyCodeTool.ts that implements the two-stage workflow
  • Added applyEnabled configuration option to enable/disable the feature (opt-in)
  • Updated tool type definitions and registries across the codebase
  • Created tool description document for the system prompt
  • Added comprehensive unit tests for the new functionality
  • Integrated with existing diff application infrastructure

Key Benefits

  • Separates creative code generation from technical diff creation
  • Reduces errors caused by noisy conversational contexts
  • Uses structured JSON output for reliable parsing
  • Maintains backward compatibility (opt-in feature)
  • Leverages existing diff tools for actual file modifications

Testing

  • Added comprehensive test suite covering all edge cases
  • Verified existing tests still pass (no regressions)
  • Tests cover parameter validation, feature flags, file operations, and error handling

Closes #6159


Important

Introduces apply_code tool for two-stage code generation and diff application, with configuration, integration, and comprehensive testing.

  • Behavior:
    • Implements apply_code tool in applyCodeTool.ts for two-stage code generation and diff application.
    • Adds applyEnabled config option in provider-settings.ts to enable/disable the tool.
    • Integrates apply_code with existing infrastructure in presentAssistantMessage.ts.
  • Tool Descriptions:
    • Adds getApplyCodeDescription() in apply-code.ts.
    • Updates tool.ts and index.ts to include apply_code in tool registries.
  • Testing:
    • Adds applyCodeTool.spec.ts with comprehensive tests for parameter validation, feature flags, file operations, and error handling.
  • Misc:
    • Updates ExtensionMessage.ts and tools.ts to support new tool parameters and types.

This description was created by Ellipsis for d875f22. You can customize this summary. It will automatically update as commits are pushed.

- Add new apply_code tool that uses a two-stage approach:
  1. Creative code generation based on instructions
  2. Focused diff generation with clean context
- Add applyEnabled configuration option to enable/disable the feature
- Update tool descriptions and type definitions
- Add comprehensive tests for the new tool
- Integrate with existing diff application infrastructure

This addresses issue #6159 by providing a more reliable alternative
to apply_diff that separates creative code generation from technical
diff creation, reducing errors from noisy conversational contexts.
@roomote roomote bot requested review from cte, jr and mrubens as code owners July 24, 2025 09:59
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. Enhancement New feature or request labels Jul 24, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 24, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jul 25, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jul 25, 2025
@daniel-lxs
Copy link
Member

This is basically generating a unified diff, models are not good at generating or applying unified diff, if anything this should rewrite an updated file.

@daniel-lxs daniel-lxs closed this Jul 28, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Jul 28, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request PR - Needs Preliminary Review size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Proposal: Implement a "Apply" Feature like Cursor's

4 participants