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

Function editTextFileCallback

pkg/aiusechat/tools_writefile.go:311–346  ·  view source on GitHub ↗
(input any, toolUseData *uctypes.UIMessageDataToolUse)

Source from the content-addressed store, hash-verified

309}
310
311func 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
348func GetEditTextFileToolDefinition() uctypes.ToolDefinition {
349 return uctypes.ToolDefinition{

Callers

nothing calls this directly

Calls 5

ExpandHomeDirFunction · 0.92
MakeFileBackupFunction · 0.92
ReplaceInFileFunction · 0.92
parseEditTextFileInputFunction · 0.85
validateTextFileFunction · 0.85

Tested by

no test coverage detected