In order to expose Codex via an MCP server, I realized that we should be taking `cwd` as a parameter rather than assuming `std::env::current_dir()` as the `cwd`. Specifically, the user may want to start a session in a directory other than the one where the MCP server has been started. This PR makes `cwd: PathBuf` a required field of `Session` and threads it all the way through, though I think there is still an issue with not honoring `workdir` for `apply_patch`, which is something we also had to fix in the TypeScript version: https://github.com/openai/codex/pull/556. This also adds `-C`/`--cd` to change the cwd via the command line. To test, I ran: ``` cargo run --bin codex -- exec -C /tmp 'show the output of ls' ``` and verified it showed the contents of my `/tmp` folder instead of `$PWD`.
19 lines
719 B
Rust
19 lines
719 B
Rust
use codex_core::exec::create_seatbelt_command;
|
|
use codex_core::protocol::SandboxPolicy;
|
|
|
|
pub async fn run_seatbelt(
|
|
command: Vec<String>,
|
|
sandbox_policy: SandboxPolicy,
|
|
) -> anyhow::Result<()> {
|
|
let cwd = std::env::current_dir().expect("failed to get cwd");
|
|
let seatbelt_command = create_seatbelt_command(command, &sandbox_policy, &cwd);
|
|
let status = tokio::process::Command::new(seatbelt_command[0].clone())
|
|
.args(&seatbelt_command[1..])
|
|
.spawn()
|
|
.map_err(|e| anyhow::anyhow!("Failed to spawn command: {}", e))?
|
|
.wait()
|
|
.await
|
|
.map_err(|e| anyhow::anyhow!("Failed to wait for command: {}", e))?;
|
|
std::process::exit(status.code().unwrap_or(1));
|
|
}
|