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

Function executeReadFile

api/service/tools/executor.go:935–985  ·  view source on GitHub ↗
(ctx context.Context, args map[string]interface{})

Source from the content-addressed store, hash-verified

933}
934
935func executeReadFile(ctx context.Context, args map[string]interface{}) (*ToolResult, error) {
936 path, ok := args["path"].(string)
937 if !ok || strings.TrimSpace(path) == "" {
938 return nil, fmt.Errorf("missing path argument")
939 }
940 path, err := normalizeSandboxWorkspacePath(path)
941 if err != nil {
942 return nil, err
943 }
944
945 maxBytes := 0
946 if v, exists := args["max_bytes"]; exists {
947 maxBytes = parseIntValue(v, 0)
948 }
949
950 cwd := resolveSandboxCWD(ctx, args)
951 if _, err := normalizeSandboxRelativePath(cwd); err != nil {
952 return nil, err
953 }
954
955 req := sandboxclient.FileReadRequest{
956 Path: path,
957 SessionID: resolveSandboxSessionID(ctx, args),
958 Cwd: cwd,
959 MaxBytes: maxBytes,
960 }
961 if files, err := buildSkillFilesForSandbox(ctx); err != nil {
962 logger.Warnf(ctx, "Failed to build skill files for read_file: %v", err)
963 } else if len(files) > 0 {
964 req.Files = files
965 }
966 if err := ensureSandboxSessionSeeded(ctx, req.SessionID, req.Cwd); err != nil {
967 return nil, err
968 }
969 resp, err := getSandboxClient().ReadFile(ctx, req)
970 if err != nil {
971 return nil, wrapSandboxServiceError(err)
972 }
973
974 if resp.Content == "" {
975 return &ToolResult{Output: "(Empty file)", ExitCode: 0}, nil
976 }
977 paginated := paginateReadFileContent(resp.Content, args)
978 if strings.TrimSpace(paginated) == "" {
979 return &ToolResult{Output: "(Empty file)", ExitCode: 0}, nil
980 }
981 if paginated != resp.Content {
982 paginated += "\n\n【说明】这是文件预览,省略部分是正常截断,不代表文件损坏。如需更多内容,请通过 offset/limit/tail_lines 继续读取。"
983 }
984 return &ToolResult{Output: paginated, ExitCode: 0}, nil
985}
986
987func executeWriteFile(ctx context.Context, args map[string]interface{}) (*ToolResult, error) {
988 return executeWriteFileWithPathNormalizer(ctx, args, normalizeSandboxRuntimePath, "write_file")

Callers 2

ExecuteToolWithResultFunction · 0.85
ExecuteToolStreamFunction · 0.85

Calls 13

parseIntValueFunction · 0.85
resolveSandboxCWDFunction · 0.85
resolveSandboxSessionIDFunction · 0.85
getSandboxClientFunction · 0.85
wrapSandboxServiceErrorFunction · 0.85
paginateReadFileContentFunction · 0.85
ErrorfMethod · 0.80
WarnfMethod · 0.80

Tested by

no test coverage detected