You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🤖 refactor: split file edit tool errors into user/agent messages
- Add 'note' field to file edit error results for agent-specific guidance
- Introduce EDIT_FAILED_NOTE_PREFIX constant for consistent messaging
- Remove redundant WRITE_DENIED_PREFIX from error messages
- Simplify UI error detection to check success field directly
- Update tool descriptions to warn that edits may fail
Agent notes provide clear failure signals and recovery steps:
- 'EDIT FAILED - file was NOT modified'
- Specific problem explanation
- Concrete remediation (read file, retry with correct params)
This addresses the issue where agents continue after file edit failures
by making failures more explicit upfront (tool descriptions) and providing
targeted recovery guidance (note field) separate from user-facing errors.
_Generated with `cmux`_
@@ -53,6 +56,7 @@ export function handleStringReplace(
53
56
success: false,
54
57
error:
55
58
"old_string not found in file. The text to replace must exist exactly as written in the file.",
59
+
note: `${EDIT_FAILED_NOTE_PREFIX} The old_string does not exist in the file. Read the file first to get the exact current content, then retry.`,
56
60
};
57
61
}
58
62
@@ -63,13 +67,15 @@ export function handleStringReplace(
63
67
return{
64
68
success: false,
65
69
error: `old_string appears ${occurrences} times in the file. Either expand the context to make it unique or set replace_count to ${occurrences} or -1.`,
70
+
note: `${EDIT_FAILED_NOTE_PREFIX} The old_string matched ${occurrences} locations. Add more surrounding context to make it unique, or set replace_count=${occurrences} to replace all occurrences.`,
66
71
};
67
72
}
68
73
69
74
if(replaceCount>occurrences&&replaceCount!==-1){
70
75
return{
71
76
success: false,
72
77
error: `replace_count is ${replaceCount} but old_string only appears ${occurrences} time(s) in the file.`,
78
+
note: `${EDIT_FAILED_NOTE_PREFIX} The replace_count=${replaceCount} is too high. Retry with replace_count=${occurrences} or -1.`,
73
79
};
74
80
}
75
81
@@ -123,13 +129,15 @@ export function handleLineReplace(
123
129
return{
124
130
success: false,
125
131
error: `start_line must be >= 1 (received ${args.start_line}).`,
132
+
note: `${EDIT_FAILED_NOTE_PREFIX} Line numbers must be >= 1.`,
126
133
};
127
134
}
128
135
129
136
if(args.end_line<args.start_line){
130
137
return{
131
138
success: false,
132
139
error: `end_line must be >= start_line (received start ${args.start_line}, end ${args.end_line}).`,
140
+
note: `${EDIT_FAILED_NOTE_PREFIX} The end_line must be >= start_line.`,
133
141
};
134
142
}
135
143
@@ -139,6 +147,7 @@ export function handleLineReplace(
139
147
return{
140
148
success: false,
141
149
error: `start_line ${args.start_line} exceeds current file length (${lines.length}).`,
150
+
note: `${EDIT_FAILED_NOTE_PREFIX} The file has ${lines.length} lines. Read the file to get current content, then retry.`,
142
151
};
143
152
}
144
153
@@ -149,6 +158,7 @@ export function handleLineReplace(
149
158
return{
150
159
success: false,
151
160
error: `expected_lines validation failed. Current lines [${currentRange.join("\n")}] differ from expected [${args.expected_lines.join("\n")}].`,
161
+
note: `${EDIT_FAILED_NOTE_PREFIX} The file content changed since you last read it. Read the file again and retry.`,
0 commit comments