|
1 | 1 | #[cfg(unix)] |
2 | | -mod unix { |
3 | | - mod escalate_client; |
4 | | - mod escalate_protocol; |
5 | | - mod escalate_server; |
6 | | - mod escalation_policy; |
7 | | - mod socket; |
8 | | - mod stopwatch; |
9 | | - |
10 | | - pub use self::escalate_client::run; |
11 | | - pub use self::escalate_protocol::EscalateAction; |
12 | | - pub use self::escalate_server::EscalationPolicyFactory; |
13 | | - pub use self::escalate_server::ExecParams; |
14 | | - pub use self::escalate_server::ExecResult; |
15 | | - pub use self::escalate_server::run_escalate_server; |
16 | | - pub use self::escalation_policy::EscalationPolicy; |
17 | | - pub use self::stopwatch::Stopwatch; |
18 | | -} |
| 2 | +pub mod unix; |
19 | 3 |
|
20 | 4 | #[cfg(unix)] |
21 | 5 | pub use unix::*; |
| 6 | + |
| 7 | +#[cfg(unix)] |
| 8 | +pub use unix::escalate_client::run; |
| 9 | +#[cfg(unix)] |
| 10 | +pub use unix::escalate_protocol::EscalateAction; |
| 11 | +#[cfg(unix)] |
| 12 | +pub use unix::escalate_server::EscalationPolicyFactory; |
| 13 | +#[cfg(unix)] |
| 14 | +pub use unix::escalate_server::ExecParams; |
| 15 | +#[cfg(unix)] |
| 16 | +pub use unix::escalate_server::ExecResult; |
| 17 | +#[cfg(unix)] |
| 18 | +pub use unix::escalation_policy::EscalationPolicy; |
| 19 | +#[cfg(unix)] |
| 20 | +pub use unix::stopwatch::Stopwatch; |
| 21 | + |
| 22 | +#[cfg(unix)] |
| 23 | +mod legacy_api { |
| 24 | + use std::collections::HashMap; |
| 25 | + use std::path::Path; |
| 26 | + use std::path::PathBuf; |
| 27 | + use std::sync::Arc; |
| 28 | + use std::time::Duration; |
| 29 | + |
| 30 | + use codex_execpolicy::Policy; |
| 31 | + use codex_protocol::config_types::WindowsSandboxLevel; |
| 32 | + use codex_protocol::models::SandboxPermissions as ProtocolSandboxPermissions; |
| 33 | + use tokio::sync::RwLock; |
| 34 | + use tokio_util::sync::CancellationToken; |
| 35 | + |
| 36 | + use crate::unix::escalate_server::EscalationPolicyFactory; |
| 37 | + use crate::unix::escalate_server::ExecParams; |
| 38 | + use crate::unix::escalate_server::ExecResult; |
| 39 | + use crate::unix::escalate_server::SandboxState; |
| 40 | + use crate::unix::escalate_server::ShellCommandExecutor; |
| 41 | + |
| 42 | + struct CoreShellCommandExecutor; |
| 43 | + |
| 44 | + #[async_trait::async_trait] |
| 45 | + impl ShellCommandExecutor for CoreShellCommandExecutor { |
| 46 | + async fn run( |
| 47 | + &self, |
| 48 | + command: Vec<String>, |
| 49 | + cwd: PathBuf, |
| 50 | + env: HashMap<String, String>, |
| 51 | + cancel_rx: CancellationToken, |
| 52 | + sandbox_state: &SandboxState, |
| 53 | + ) -> anyhow::Result<ExecResult> { |
| 54 | + let result = codex_core::exec::process_exec_tool_call( |
| 55 | + codex_core::exec::ExecParams { |
| 56 | + command, |
| 57 | + cwd, |
| 58 | + expiration: codex_core::exec::ExecExpiration::Cancellation(cancel_rx), |
| 59 | + env, |
| 60 | + network: None, |
| 61 | + sandbox_permissions: ProtocolSandboxPermissions::UseDefault, |
| 62 | + windows_sandbox_level: WindowsSandboxLevel::Disabled, |
| 63 | + justification: None, |
| 64 | + arg0: None, |
| 65 | + }, |
| 66 | + &sandbox_state.sandbox_policy, |
| 67 | + &sandbox_state.sandbox_cwd, |
| 68 | + &sandbox_state.codex_linux_sandbox_exe, |
| 69 | + sandbox_state.use_linux_sandbox_bwrap, |
| 70 | + None, |
| 71 | + ) |
| 72 | + .await?; |
| 73 | + |
| 74 | + Ok(ExecResult { |
| 75 | + exit_code: result.exit_code, |
| 76 | + output: result.aggregated_output.text, |
| 77 | + duration: result.duration, |
| 78 | + timed_out: result.timed_out, |
| 79 | + }) |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + #[allow(clippy::too_many_arguments)] |
| 84 | + pub async fn run_escalate_server( |
| 85 | + exec_params: ExecParams, |
| 86 | + sandbox_state: &codex_core::SandboxState, |
| 87 | + shell_program: impl AsRef<Path>, |
| 88 | + execve_wrapper: impl AsRef<Path>, |
| 89 | + policy: Arc<RwLock<Policy>>, |
| 90 | + escalation_policy_factory: impl EscalationPolicyFactory, |
| 91 | + effective_timeout: Duration, |
| 92 | + ) -> anyhow::Result<ExecResult> { |
| 93 | + let sandbox_state = SandboxState { |
| 94 | + sandbox_policy: sandbox_state.sandbox_policy.clone(), |
| 95 | + codex_linux_sandbox_exe: sandbox_state.codex_linux_sandbox_exe.clone(), |
| 96 | + sandbox_cwd: sandbox_state.sandbox_cwd.clone(), |
| 97 | + use_linux_sandbox_bwrap: sandbox_state.use_linux_sandbox_bwrap, |
| 98 | + }; |
| 99 | + crate::unix::escalate_server::run_escalate_server( |
| 100 | + exec_params, |
| 101 | + &sandbox_state, |
| 102 | + shell_program, |
| 103 | + execve_wrapper, |
| 104 | + policy, |
| 105 | + escalation_policy_factory, |
| 106 | + effective_timeout, |
| 107 | + &CoreShellCommandExecutor, |
| 108 | + ) |
| 109 | + .await |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +#[cfg(unix)] |
| 114 | +pub use legacy_api::run_escalate_server; |
0 commit comments