MCPcopy
hub / github.com/wavetermdev/waveterm / EditTextFileDryRun

Function EditTextFileDryRun

pkg/aiusechat/tools_writefile.go:273–309  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
273func 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
311func editTextFileCallback(input any, toolUseData *uctypes.UIMessageDataToolUse) (any, error) {
312 params, err := parseEditTextFileInput(input)

Callers 1

CreateWriteTextFileDiffFunction · 0.85

Calls 5

ExpandHomeDirFunction · 0.92
ApplyEditsFunction · 0.92
parseEditTextFileInputFunction · 0.85
validateTextFileFunction · 0.85
ReadFileMethod · 0.80

Tested by

no test coverage detected