EditFileSchema is the OpenAI tool definition for edit_file. The description steers the model toward edit_file over write_file for small changes so it stops rewriting whole documents to fix a typo.
()
| 74 | return fmt.Sprintf("edited %s: -%d +%d bytes", path, len(oldString), len(newString)) |
| 75 | } |
| 76 | |
| 77 | // differsOnlyInWhitespace reports whether oldString matches content at exactly |
| 78 | // one spot once every whitespace run is collapsed: i.e. the sole mismatch is |
| 79 | // indentation/tabs/newlines. Bounded with spaces so a match can't straddle a |
| 80 | // token boundary and mislabel an unrelated near-miss. |
| 81 | func differsOnlyInWhitespace(content, oldString string) bool { |
| 82 | norm := func(s string) string { return " " + strings.Join(strings.Fields(s), " ") + " " } |
| 83 | return strings.Count(norm(content), norm(oldString)) == 1 |
| 84 | } |
| 85 | |
| 86 | // fuzzyWhitespaceEdit applies old_string when its whitespace-collapsed token |
| 87 | // sequence matches a run of WHOLE content lines at exactly one place: the |
| 88 | // retyped-indentation failure (Aider measured flexible application cutting |
| 89 | // edit errors ~9x; pi and opencode ship the same fallback). Whole lines only, |
| 90 | // so the splice boundary is a line boundary and every surrounding byte is |
| 91 | // preserved exactly; a mid-line fragment or a 0/2+ match returns ok=false and |
| 92 | // leaves the instructive failure to the caller. new_string goes in as given - |
| 93 | // those are the bytes the model meant to write, same as an exact match. |
| 94 | func fuzzyWhitespaceEdit(path, content, oldString, newString string) (string, bool) { |
| 95 | want := strings.Fields(oldString) |
| 96 | if len(want) == 0 { |
| 97 | return "", false |
| 98 | } |
| 99 | lines := strings.Split(content, "\n") |
| 100 | matches, matchStart, matchEnd := 0, -1, -1 |
| 101 | for i := range lines { |
| 102 | if len(strings.Fields(lines[i])) == 0 { |
| 103 | continue // a match starts on a non-blank line, keeping the region tight |
| 104 | } |
| 105 | if end := fuzzyMatchAt(lines, i, want); end >= 0 { |
no outgoing calls