Skip to main content

codex_runtime/runtime/api/
command_exec_api.rs

1use crate::runtime::core::Runtime;
2use crate::runtime::errors::RpcError;
3use crate::runtime::rpc_contract::methods;
4
5use super::wire::{command_exec_params_to_wire, deserialize_result, serialize_params};
6use super::*;
7
8impl Runtime {
9    /// Run one standalone command in the app-server sandbox.
10    /// Allocation: JSON params + decoded response payload.
11    /// Complexity: O(n), n = argv/env size + buffered output size.
12    pub async fn command_exec(
13        &self,
14        p: CommandExecParams,
15    ) -> Result<CommandExecResponse, RpcError> {
16        let response = self
17            .call_validated(methods::COMMAND_EXEC, command_exec_params_to_wire(&p))
18            .await?;
19        deserialize_result(methods::COMMAND_EXEC, response)
20    }
21
22    /// Write stdin bytes to a running standalone command or close stdin.
23    /// Allocation: serialized params + empty response object.
24    /// Complexity: O(n), n = payload size.
25    pub async fn command_exec_write(
26        &self,
27        p: CommandExecWriteParams,
28    ) -> Result<CommandExecWriteResponse, RpcError> {
29        let params = serialize_params(methods::COMMAND_EXEC_WRITE, &p)?;
30        let response = self
31            .call_validated(methods::COMMAND_EXEC_WRITE, params)
32            .await?;
33        deserialize_result(methods::COMMAND_EXEC_WRITE, response)
34    }
35
36    /// Resize one PTY-backed standalone command by client process id.
37    /// Allocation: serialized params + empty response object.
38    /// Complexity: O(1).
39    pub async fn command_exec_resize(
40        &self,
41        p: CommandExecResizeParams,
42    ) -> Result<CommandExecResizeResponse, RpcError> {
43        let params = serialize_params(methods::COMMAND_EXEC_RESIZE, &p)?;
44        let response = self
45            .call_validated(methods::COMMAND_EXEC_RESIZE, params)
46            .await?;
47        deserialize_result(methods::COMMAND_EXEC_RESIZE, response)
48    }
49
50    /// Terminate one standalone command by client process id.
51    /// Allocation: serialized params + empty response object.
52    /// Complexity: O(1).
53    pub async fn command_exec_terminate(
54        &self,
55        p: CommandExecTerminateParams,
56    ) -> Result<CommandExecTerminateResponse, RpcError> {
57        let params = serialize_params(methods::COMMAND_EXEC_TERMINATE, &p)?;
58        let response = self
59            .call_validated(methods::COMMAND_EXEC_TERMINATE, params)
60            .await?;
61        deserialize_result(methods::COMMAND_EXEC_TERMINATE, response)
62    }
63}