feat: improve apply_code tool with isolated API context for diff generation #6166
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses the subtle but important difference pointed out by @CberYellowstone in issue #6159. The original proposal emphasized creating a truly isolated, dedicated process for diff generation in the apply_code tool.
Changes
Created isolated API handler for Stage 2: Instead of reusing the main Cline API instance, Stage 2 now creates its own isolated API handler using buildApiHandler(). This ensures complete separation from the main conversation context.
Hardcoded optimized system prompt: The diff generation stage now uses a hardcoded, specialized system prompt focused solely on generating accurate diffs, without any conversational elements.
Clean context without conversation history: Stage 2 receives only the essential information (original file content and new code) without any conversation history or additional context that could influence the diff generation.
Updated tests: All tests have been updated to reflect the new implementation and are passing.
Key Differences from Previous Implementation
The previous implementation reused the main Cline API instance with a modified system prompt. This new implementation creates a completely separate API handler, ensuring true isolation as originally proposed.
Testing
Fixes #6159
Important
Introduces
apply_codetool for improved code application using a two-stage process with isolated API context, updates settings, descriptions, and tests.apply_codetool inapplyCodeTool.tsfor code changes using a two-stage process: code generation and diff generation.buildApiHandler()for isolated API context in diff generation.presentAssistantMessage.tsto handleapply_codetool execution.getApplyCodeDescription()inapply-code.tsfor tool description.index.tsto includeapply_codein tool descriptions.applyEnabledsetting inprovider-settings.tsto control tool availability.tool.tsto includeapply_codein tool names.applyCodeTool.spec.tsfor unit tests covering parameter validation, API workflow, error handling, and user approval.ExtensionMessage.tsandtools.tsto includeapply_codein relevant interfaces and constants.This description was created by
for 832d297. You can customize this summary. It will automatically update as commits are pushed.