EditTextFileDryRun applies edits to a file and returns the original and modified content without writing to disk. Takes the same input format as editTextFileCallback.
(input any, fileOverride string)
| 271 | // EditTextFileDryRun applies edits to a file and returns the original and modified content |
| 272 | // without writing to disk. Takes the same input format as editTextFileCallback. |
| 273 | func EditTextFileDryRun(input any, fileOverride string) ([]byte, []byte, error) { |
| 274 | params, err := parseEditTextFileInput(input) |
| 275 | if err != nil { |
| 276 | return nil, nil, err |
| 277 | } |
| 278 | |
| 279 | expandedPath, err := wavebase.ExpandHomeDir(params.Filename) |
| 280 | if err != nil { |
| 281 | return nil, nil, fmt.Errorf("failed to expand path: %w", err) |
| 282 | } |
| 283 | |
| 284 | if !filepath.IsAbs(expandedPath) { |
| 285 | return nil, nil, fmt.Errorf("path must be absolute, got relative path: %s", params.Filename) |
| 286 | } |
| 287 | |
| 288 | _, err = validateTextFile(expandedPath, "edit", true) |
| 289 | if err != nil { |
| 290 | return nil, nil, err |
| 291 | } |
| 292 | |
| 293 | readPath := expandedPath |
| 294 | if fileOverride != "" { |
| 295 | readPath = fileOverride |
| 296 | } |
| 297 | |
| 298 | originalContent, err := os.ReadFile(readPath) |
| 299 | if err != nil { |
| 300 | return nil, nil, fmt.Errorf("failed to read file: %w", err) |
| 301 | } |
| 302 | |
| 303 | modifiedContent, err := fileutil.ApplyEdits(originalContent, params.Edits) |
| 304 | if err != nil { |
| 305 | return nil, nil, err |
| 306 | } |
| 307 | |
| 308 | return originalContent, modifiedContent, nil |
| 309 | } |
| 310 | |
| 311 | func editTextFileCallback(input any, toolUseData *uctypes.UIMessageDataToolUse) (any, error) { |
| 312 | params, err := parseEditTextFileInput(input) |
no test coverage detected