Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/improve-apply-diff-prompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"zoo-code": patch
---

Enhance the `apply_diff` tool description and parameter instructions to enforce strict `:start_line:` formatting and copy-paste exact matching requirements, improving success rates for Gemini Flash and other smaller/faster models.
35 changes: 35 additions & 0 deletions plans/improve-apply-diff-prompt.pr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
### Related GitHub Issue
Comment thread
awschmeder marked this conversation as resolved.
Outdated

Closes: #611

### Description

This PR enhances the documentation and instructions for the `apply_diff` tool to improve its success rate, particularly for Gemini models. It addresses issues with malformed `:start_line:` syntax and imprecise diff matching by enforcing stricter, clearer requirements in the tool's system instructions.

Note: While the issue notes that adding these guidelines to `AGENTS.md` resolved the issue locally, we have integrated them directly into the core prompts (`src/core/prompts/tools/native-tools/apply_diff.ts`) and have purposely omitted modifying `AGENTS.md` to adhere to repository PR hygiene guidelines.

### Test Procedure

- Verify existing `apply_diff` behavior with `apps/vscode-e2e/src/suite/tools/apply-diff.test.ts`.
- Prompt instructions updated in `src/core/prompts/tools/native-tools/apply_diff.ts`.

### Pre-Submission Checklist

- [x] **Issue Linked**: This PR is linked to an approved GitHub Issue.
- [x] **Scope**: My changes are focused on the linked issue (one major feature/fix per PR).
- [x] **Self-Review**: I have performed a thorough self-review of my code.
- [x] **Testing**: Existing tests cover the functionality; no new functionality requiring tests was added.
- [x] **Documentation Impact**: I have considered if my changes require documentation updates.
- [x] **Contribution Guidelines**: I have read and agree to the [Contributor Guidelines](/CONTRIBUTING.md).

### Documentation Updates

- [ ] No documentation updates are required. (Updates are purely internal prompt instruction refinements).

### Additional Notes

None.

### Get in Touch

Zoo AI Assistant
7 changes: 6 additions & 1 deletion src/core/prompts/tools/native-tools/apply_diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ const DIFF_PARAMETER_DESCRIPTION = `A string containing one or more search/repla
[exact content to find]
=======
[new content to replace with]
>>>>>>> REPLACE`
>>>>>>> REPLACE

CRITICAL:
- The ':start_line:[line_number]' header is strictly required. It must follow the exact syntax ':start_line:[integer]' (for example: ':start_line:220'). Do not write headers with shorthand forms like ':220' or variations like ':start_line=220'.
Comment thread
awschmeder marked this conversation as resolved.
Outdated
- Copy the exact lines from the source file for a 100% string match including all whitespace, indentation, and newlines.
- Ensure the separator '-------' is on its own line immediately following ':start_line:[line_number]' with a newline.`

export const apply_diff = {
type: "function",
Expand Down
Loading