MCPcopy Create free account
hub / github.com/53AI/53AIHub / executeWriteFileWithPathNormalizer

Function executeWriteFileWithPathNormalizer

api/service/tools/executor.go:995–1072  ·  view source on GitHub ↗
(ctx context.Context, args map[string]interface{}, normalizePath func(string) (string, error), toolName string)

Source from the content-addressed store, hash-verified

993}
994
995func executeWriteFileWithPathNormalizer(ctx context.Context, args map[string]interface{}, normalizePath func(string) (string, error), toolName string) (*ToolResult, error) {
996 path, ok := args["path"].(string)
997 if !ok || strings.TrimSpace(path) == "" {
998 return nil, fmt.Errorf("missing path argument")
999 }
1000 path, err := normalizePath(path)
1001 if err != nil {
1002 return nil, err
1003 }
1004 content, ok := args["content"].(string)
1005 if !ok {
1006 return nil, fmt.Errorf("missing content argument")
1007 }
1008 appendMode := false
1009 if v, exists := args["append"]; exists {
1010 appendMode = parseBoolValue(v)
1011 }
1012 createIfMissing := true
1013 if v, exists := args["create_if_missing"]; exists {
1014 createIfMissing = parseBoolValue(v)
1015 }
1016 cwd := resolveSandboxCWD(ctx, args)
1017 if _, err := normalizeSandboxRelativePath(cwd); err != nil {
1018 return nil, err
1019 }
1020 content = normalizeSandboxTextContentForPath(path, content)
1021
1022 req := sandboxclient.FileWriteRequest{
1023 Path: path,
1024 Content: content,
1025 Append: appendMode,
1026 SessionID: resolveSandboxSessionID(ctx, args),
1027 Cwd: cwd,
1028 }
1029 if files, err := buildSkillFilesForSandbox(ctx); err != nil {
1030 logger.Warnf(ctx, "Failed to build skill files for %s: %v", toolName, err)
1031 } else if len(files) > 0 {
1032 req.Files = files
1033 }
1034 if err := ensureSandboxSessionSeeded(ctx, req.SessionID, req.Cwd); err != nil {
1035 return nil, err
1036 }
1037 if !createIfMissing {
1038 if _, readErr := getSandboxClient().ReadFile(ctx, sandboxclient.FileReadRequest{
1039 Path: req.Path,
1040 SessionID: req.SessionID,
1041 Cwd: req.Cwd,
1042 }); readErr != nil {
1043 if isSandboxFileNotFound(readErr) {
1044 return nil, fmt.Errorf("target file does not exist and create_if_missing=false: %s", req.Path)
1045 }
1046 return nil, wrapSandboxServiceError(readErr)
1047 }
1048 }
1049 resp, err := getSandboxClient().WriteFile(ctx, req)
1050 if err != nil {
1051 return nil, wrapSandboxServiceError(err)
1052 }

Callers 2

executeWriteFileFunction · 0.85
executePrepareInputFileFunction · 0.85

Calls 15

parseBoolValueFunction · 0.85
resolveSandboxCWDFunction · 0.85
resolveSandboxSessionIDFunction · 0.85
getSandboxClientFunction · 0.85
isSandboxFileNotFoundFunction · 0.85
wrapSandboxServiceErrorFunction · 0.85

Tested by

no test coverage detected