| 1370 | } |
| 1371 | |
| 1372 | func (t *ToolSet) handleWriteFile(ctx context.Context, args WriteFileArgs) (*tools.ToolCallResult, error) { |
| 1373 | annotateFilesystemSpan(ctx, "write_file", args.Path) |
| 1374 | resolvedPath, err := t.resolveAndCheckPath(args.Path) |
| 1375 | if err != nil { |
| 1376 | return tools.ResultError(err.Error()), nil |
| 1377 | } |
| 1378 | |
| 1379 | // Create parent directory structure if it doesn't exist |
| 1380 | dir := filepath.Dir(resolvedPath) |
| 1381 | if err := t.mkdirAll(dir, 0o755); err != nil { |
| 1382 | return tools.ResultError(fmt.Sprintf("Error creating directory structure: %s", err)), nil |
| 1383 | } |
| 1384 | |
| 1385 | if err := t.writeFile(resolvedPath, []byte(args.Content), 0o644); err != nil { |
| 1386 | return tools.ResultError(fmt.Sprintf("Error writing file: %s", err)), nil |
| 1387 | } |
| 1388 | |
| 1389 | if err := t.executePostEditCommands(ctx, resolvedPath); err != nil { |
| 1390 | return tools.ResultError(fmt.Sprintf("File written successfully but post-edit command failed: %s", err)), nil |
| 1391 | } |
| 1392 | |
| 1393 | return tools.ResultSuccess(fmt.Sprintf("File written successfully: %s (%d bytes)", args.Path, len(args.Content))), nil |
| 1394 | } |
| 1395 | |
| 1396 | func (t *ToolSet) handleCreateDirectory(ctx context.Context, args CreateDirectoryArgs) (*tools.ToolCallResult, error) { |
| 1397 | annotateFilesystemSpan(ctx, "create_directory", "") |