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

Function executeRunShell

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

Source from the content-addressed store, hash-verified

870}
871
872func executeRunShell(ctx context.Context, args map[string]interface{}) (*ToolResult, error) {
873 command, ok := args["command"].(string)
874 if !ok || strings.TrimSpace(command) == "" {
875 return nil, fmt.Errorf("missing command argument")
876 }
877
878 timeout := 30
879 if v, exists := args["timeout"]; exists {
880 timeout = parseIntValue(v, timeout)
881 }
882 cwd := resolveSandboxCWD(ctx, args)
883 if _, err := normalizeSandboxRelativePath(cwd); err != nil {
884 return nil, err
885 }
886 req := sandboxclient.ShellRequest{
887 Command: command,
888 Timeout: timeout,
889 SessionID: resolveSandboxSessionID(ctx, args),
890 Cwd: cwd,
891 EnvVars: resolveSandboxEnvVars(ctx, args),
892 }
893 if files, err := buildSkillFilesForSandbox(ctx); err != nil {
894 logger.Warnf(ctx, "Failed to build skill files for shell execution: %v", err)
895 } else if len(files) > 0 {
896 req.Files = files
897 }
898 if err := ensureSandboxSessionSeeded(ctx, req.SessionID, req.Cwd); err != nil {
899 return nil, err
900 }
901
902 resp, err := getSandboxClient().ExecuteShell(ctx, req)
903 if err != nil {
904 return nil, wrapSandboxServiceError(err)
905 }
906 output := formatCommandResult(resp.Stdout, resp.Stderr, resp.ExitCode)
907 if resp.ExitCode != 0 && hasUploadedFilesInContext(ctx) && isLikelyMissingFileError(output) {
908 logger.Warnf(ctx, "run_shell detected missing-file error, trying one upload reseed retry: session=%s, cwd=%s", req.SessionID, req.Cwd)
909 if reseedErr := forceReseedUploadedFiles(ctx, req.SessionID, req.Cwd); reseedErr != nil {
910 logger.Warnf(ctx, "run_shell upload reseed retry skipped due to seed error: %v", reseedErr)
911 } else {
912 retryResp, retryErr := getSandboxClient().ExecuteShell(ctx, req)
913 if retryErr != nil {
914 logger.Warnf(ctx, "run_shell retry after upload reseed failed: %v", retryErr)
915 } else {
916 resp = retryResp
917 output = formatCommandResult(resp.Stdout, resp.Stderr, resp.ExitCode)
918 logger.Infof(ctx, "run_shell retry after upload reseed completed: exit_code=%d", resp.ExitCode)
919 }
920 }
921 }
922
923 return &ToolResult{
924 Output: output,
925 Stderr: resp.Stderr,
926 ExitCode: resp.ExitCode,
927 OutputFiles: func() []OutputFile {
928 outputFiles, snapshot := filterSandboxOutputFilesBySnapshot(loadSandboxOutputSnapshot(ctx), convertSandboxOutputFiles(resp.OutputFiles))
929 rememberSandboxOutputSnapshot(ctx, snapshot)

Callers 2

ExecuteToolWithResultFunction · 0.85
ExecuteToolStreamFunction · 0.85

Calls 15

parseIntValueFunction · 0.85
resolveSandboxCWDFunction · 0.85
resolveSandboxSessionIDFunction · 0.85
resolveSandboxEnvVarsFunction · 0.85
getSandboxClientFunction · 0.85
wrapSandboxServiceErrorFunction · 0.85
formatCommandResultFunction · 0.85
isLikelyMissingFileErrorFunction · 0.85

Tested by

no test coverage detected