Skip to main content

ralph_workflow/executor/
command.rs

1//! Imperative command builder utilities.
2//!
3//! Process command construction is inherently imperative.
4
5use std::collections::HashMap;
6use std::path::Path;
7use std::process::Command;
8
9/// Build a Command with all configuration applied.
10pub fn build_command(
11    command: &str,
12    args: &[&str],
13    env: &[(String, String)],
14    workdir: Option<&Path>,
15) -> Command {
16    let mut cmd = Command::new(command);
17    cmd.args(args);
18    for (key, value) in env {
19        cmd.env(key, value);
20    }
21    if let Some(dir) = workdir {
22        cmd.current_dir(dir);
23    }
24    cmd
25}
26
27/// Build an agent command with default environment variables.
28pub fn build_agent_command(
29    command: &str,
30    args: &[String],
31    env: &HashMap<String, String>,
32    prompt: &str,
33) -> Command {
34    let mut cmd = Command::new(command);
35    cmd.args(args.iter().map(String::as_str));
36    for (k, v) in env {
37        cmd.env(k, v);
38    }
39    cmd.arg(prompt);
40    cmd.env("PYTHONUNBUFFERED", "1");
41    cmd.env("NODE_ENV", "production");
42    cmd
43}
44
45/// Internal agent command builder for trait default implementation.
46pub fn build_agent_command_internal(
47    command: &str,
48    args: &[String],
49    env: &HashMap<String, String>,
50    prompt: &str,
51) -> Command {
52    build_agent_command(command, args, env, prompt)
53}