Skip to content

Commit 31b7c51

Browse files
authored
docs(prompt): enhance apply_diff tool instructions to improve Gemini model success rate (#619)
* docs(prompt): enhance apply_diff tool instructions for Gemini model success * docs: add PR description for issue 611 * docs(plan): align PR description plan with actual changes by removing AGENTS.md reference * docs(prompt): soften :start_line: to strongly recommended and untrack gitignored plan Addresses PR #619 review feedback from edelauna: - :start_line: is optional in the multi-search-replace parser, so describe it as strongly recommended rather than required (truthful while preserving compliance for smaller models). - Remove plans/improve-apply-diff-prompt.pr.md from tracking; plans/ is gitignored. - Align changeset summary with the corrected wording.
1 parent e8acc6a commit 31b7c51

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"zoo-code": patch
3+
---
4+
5+
Enhance the `apply_diff` tool description and parameter instructions to recommend `:start_line:` with exact syntax and emphasize copy-paste exact matching requirements, improving success rates for Gemini Flash and other smaller/faster models.

src/core/prompts/tools/native-tools/apply_diff.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ import type OpenAI from "openai"
22

33
const APPLY_DIFF_DESCRIPTION = `Apply precise, targeted modifications to an existing file using one or more search/replace blocks. This tool is for surgical edits only; the 'SEARCH' block must exactly match the existing content, including whitespace and indentation. To make multiple targeted changes, provide multiple SEARCH/REPLACE blocks in the 'diff' parameter. Use the 'read_file' tool first if you are not confident in the exact content to search for.`
44

5-
const DIFF_PARAMETER_DESCRIPTION = `A string containing one or more search/replace blocks defining the changes. The ':start_line:' is required and indicates the starting line number of the original content. You must not add a start line for the replacement content. Each block must follow this format:
5+
const DIFF_PARAMETER_DESCRIPTION = `A string containing one or more search/replace blocks defining the changes. The ':start_line:' is strongly recommended and indicates the starting line number of the original content. You must not add a start line for the replacement content. Each block must follow this format:
66
<<<<<<< SEARCH
77
:start_line:[line_number]
88
-------
99
[exact content to find]
1010
=======
1111
[new content to replace with]
12-
>>>>>>> REPLACE`
12+
>>>>>>> REPLACE
13+
14+
CRITICAL:
15+
- The ':start_line:[line_number]' header is strongly recommended for accurate matching. When provided, 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'.
16+
- Copy the exact lines from the source file for a 100% string match including all whitespace, indentation, and newlines.
17+
- Ensure the separator '-------' is on its own line immediately following ':start_line:[line_number]' with a newline.`
1318

1419
export const apply_diff = {
1520
type: "function",

0 commit comments

Comments
 (0)