fix(edit): point empty-replace error at operation=delete

A replace with empty new_content failed with a bare 'new_content is required' message, leaving the model to guess. Append a hint to use operation=delete when the intent is removal. Adds TestValidateReplaceEmptySuggestsDelete.
This commit is contained in:
2026-06-20 00:33:31 +01:00
parent b0c1fc0480
commit 5827290ece
2 changed files with 21 additions and 1 deletions
+5 -1
View File
@@ -270,7 +270,11 @@ func (e *Engine) validateBaseEdit(edit *ASTEdit) error {
switch edit.Operation {
case EditReplace, EditInsertBefore, EditInsertAfter:
if edit.NewContent == "" {
return errors.NewInvalidEditError(fmt.Sprintf("new_content is required for %s operation", edit.Operation))
msg := fmt.Sprintf("new_content is required for %s operation", edit.Operation)
if edit.Operation == EditReplace {
msg += " (to remove content instead, use operation=delete)"
}
return errors.NewInvalidEditError(msg)
}
case EditDelete:
// new_content not required