(input any, toolUseData *uctypes.UIMessageDataToolUse)
| 309 | } |
| 310 | |
| 311 | func editTextFileCallback(input any, toolUseData *uctypes.UIMessageDataToolUse) (any, error) { |
| 312 | params, err := parseEditTextFileInput(input) |
| 313 | if err != nil { |
| 314 | return nil, err |
| 315 | } |
| 316 | |
| 317 | expandedPath, err := wavebase.ExpandHomeDir(params.Filename) |
| 318 | if err != nil { |
| 319 | return nil, fmt.Errorf("failed to expand path: %w", err) |
| 320 | } |
| 321 | |
| 322 | if !filepath.IsAbs(expandedPath) { |
| 323 | return nil, fmt.Errorf("path must be absolute, got relative path: %s", params.Filename) |
| 324 | } |
| 325 | |
| 326 | _, err = validateTextFile(expandedPath, "edit", true) |
| 327 | if err != nil { |
| 328 | return nil, err |
| 329 | } |
| 330 | |
| 331 | backupPath, err := filebackup.MakeFileBackup(expandedPath) |
| 332 | if err != nil { |
| 333 | return nil, fmt.Errorf("failed to create backup: %w", err) |
| 334 | } |
| 335 | toolUseData.WriteBackupFileName = backupPath |
| 336 | |
| 337 | err = fileutil.ReplaceInFile(expandedPath, params.Edits) |
| 338 | if err != nil { |
| 339 | return nil, err |
| 340 | } |
| 341 | |
| 342 | return map[string]any{ |
| 343 | "success": true, |
| 344 | "message": fmt.Sprintf("Successfully edited %s with %d changes", params.Filename, len(params.Edits)), |
| 345 | }, nil |
| 346 | } |
| 347 | |
| 348 | func GetEditTextFileToolDefinition() uctypes.ToolDefinition { |
| 349 | return uctypes.ToolDefinition{ |
nothing calls this directly
no test coverage detected