MCPcopy Create free account
hub / github.com/AI45Lab/Code / exec

Method exec

core/src/workspace/local.rs:479–533  ·  view source on GitHub ↗
(&self, request: CommandRequest)

Source from the content-addressed store, hash-verified

477#[async_trait]
478impl WorkspaceCommandRunner for LocalWorkspaceBackend {
479 async fn exec(&self, request: CommandRequest) -> Result<CommandOutput> {
480 #[cfg(windows)]
481 if let Some(output) =
482 crate::tools::builtin::bash::maybe_execute_simple_windows_http_command(&request.command)
483 .await
484 {
485 let exit_code = output
486 .metadata
487 .as_ref()
488 .and_then(|m| m.get("exit_code"))
489 .and_then(|v| v.as_i64())
490 .map(|v| v as i32)
491 .unwrap_or(if output.success { 0 } else { -1 });
492 return Ok(CommandOutput {
493 output: output.content,
494 exit_code,
495 timed_out: false,
496 });
497 }
498
499 let timeout_secs = request.timeout_ms / 1000;
500 let mut child = crate::tools::builtin::bash::spawn_shell(
501 &request.command,
502 &self.root,
503 request.env.as_deref(),
504 )
505 .map_err(|e| anyhow!("Failed to spawn shell: {}", e))?;
506
507 let (output, timed_out) = crate::tools::process::read_process_output(
508 &mut child,
509 timeout_secs,
510 request.output_observer.as_deref(),
511 )
512 .await;
513
514 if timed_out {
515 return Ok(CommandOutput {
516 output,
517 exit_code: -1,
518 timed_out: true,
519 });
520 }
521
522 let status = child
523 .wait()
524 .await
525 .map_err(|e| anyhow!("Failed to wait for shell: {}", e))?;
526 let exit_code = status.code().unwrap_or(-1);
527
528 Ok(CommandOutput {
529 output,
530 exit_code,
531 timed_out: false,
532 })
533 }
534}
535
536impl LocalWorkspaceBackend {

Callers

nothing calls this directly

Calls 4

spawn_shellFunction · 0.85
read_process_outputFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected