(ctx context.Context, args map[string]interface{})
| 870 | } |
| 871 | |
| 872 | func 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) |
no test coverage detected