Introduce exec process capability traits

Add a narrow ExecProcess trait for process lifecycle RPCs and expose it
from Environment behind an ExecutorEnvironment trait. Keep the first cut
behavior-preserving by delegating remote mode to the existing
ExecServerClient and returning an unavailable process stub for default
local Environment values.

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
starr-openai
2026-03-19 14:18:10 -07:00
co-authored by Codex
parent 668330acc1
commit 952b7212b3
4 changed files with 126 additions and 0 deletions
+62
View File
@@ -1,8 +1,24 @@
use crate::ExecServerClient;
use crate::ExecServerError;
use crate::ExecServerEvent;
use crate::ExecProcess;
use crate::ExecutorEnvironment;
use crate::RemoteExecServerConnectArgs;
use crate::protocol::ExecParams;
use crate::protocol::ExecResponse;
use crate::protocol::ReadParams;
use crate::protocol::ReadResponse;
use crate::protocol::TerminateResponse;
use crate::protocol::WriteResponse;
use crate::fs;
use crate::fs::ExecutorFileSystem;
use async_trait::async_trait;
use tokio::sync::broadcast;
#[derive(Debug)]
struct UnavailableExecProcess;
static UNAVAILABLE_EXEC_PROCESS: UnavailableExecProcess = UnavailableExecProcess;
#[derive(Clone, Default)]
pub struct Environment {
@@ -56,11 +72,57 @@ impl Environment {
self.remote_exec_server_client.as_ref()
}
pub fn process(&self) -> &(dyn ExecProcess + '_) {
self.remote_exec_server_client
.as_ref()
.map_or(&UNAVAILABLE_EXEC_PROCESS as &dyn ExecProcess, |client| client)
}
pub fn get_filesystem(&self) -> impl ExecutorFileSystem + use<> {
fs::LocalFileSystem
}
}
impl ExecutorEnvironment for Environment {
fn process(&self) -> &(dyn ExecProcess + '_) {
self.process()
}
}
#[async_trait]
impl ExecProcess for UnavailableExecProcess {
async fn start(&self, _params: ExecParams) -> Result<ExecResponse, ExecServerError> {
Err(unavailable_exec_process_error())
}
async fn read(&self, _params: ReadParams) -> Result<ReadResponse, ExecServerError> {
Err(unavailable_exec_process_error())
}
async fn write(
&self,
_process_id: &str,
_chunk: Vec<u8>,
) -> Result<WriteResponse, ExecServerError> {
Err(unavailable_exec_process_error())
}
async fn terminate(&self, _process_id: &str) -> Result<TerminateResponse, ExecServerError> {
Err(unavailable_exec_process_error())
}
fn subscribe_events(&self) -> broadcast::Receiver<ExecServerEvent> {
let (_tx, rx) = broadcast::channel(1);
rx
}
}
fn unavailable_exec_process_error() -> ExecServerError {
ExecServerError::Protocol(
"exec process capability is unavailable for a local default Environment".to_string(),
)
}
#[cfg(test)]
mod tests {
use super::Environment;