MCPcopy Create free account
hub / github.com/GongShichen/LuminaCode / runInlineShell

Method runInlineShell

skills/prompt_processor.go:202–231  ·  view source on GitHub ↗
(command, cwd, executable string)

Source from the content-addressed store, hash-verified

200
201func (p *PromptProcessor) runInlineShell(command, cwd, executable string) (string, error) {
202 runCWD := cwd
203 if runCWD == "" {
204 runCWD = p.Config.CWD
205 }
206 timeout := time.Duration(p.Config.ShellTimeoutSeconds * float64(time.Second))
207 ctx, cancel := context.WithTimeout(context.Background(), timeout)
208 defer cancel()
209 argv := shellArgv(command, executable)
210 cmd := exec.CommandContext(ctx, argv[0], argv[1:]...)
211 cmd.Dir = runCWD
212 var stdout, stderr strings.Builder
213 cmd.Stdout = &stdout
214 cmd.Stderr = &stderr
215 err := cmd.Run()
216 if ctx.Err() == context.DeadlineExceeded {
217 return "", fmt.Errorf("Inline shell command timed out after %ss: %s", pythonFloatString(p.Config.ShellTimeoutSeconds), command)
218 }
219 if err != nil {
220 if cmd.ProcessState == nil {
221 return "", err
222 }
223 return "", fmt.Errorf("Inline shell command failed (%d): %s\n%s", cmd.ProcessState.ExitCode(), command, strings.TrimSpace(strings.ToValidUTF8(stderr.String(), "\uFFFD")))
224 }
225 out := strings.TrimSpace(strings.ToValidUTF8(stdout.String(), "\uFFFD"))
226 if len([]byte(out)) > p.Config.ShellMaxOutputBytes {
227 return "", fmt.Errorf("Inline shell command output exceeded %d bytes: %s", p.Config.ShellMaxOutputBytes, command)
228 }
229 return out, nil
230}
231
232func shellArgv(command, executable string) []string {
233 return bashpkg.ShellArgv(command, executable)
234}

Callers 1

executeInlineShellMethod · 0.95

Calls 4

shellArgvFunction · 0.85
pythonFloatStringFunction · 0.85
RunMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected