use std::{
collections::BTreeMap, ffi::OsString, future::Future, path::PathBuf, pin::Pin, time::Duration,
};
use tokio_util::sync::CancellationToken;
use crate::platform;
#[derive(Debug, Clone)]
pub struct Launch {
pub program: PathBuf,
pub args: Vec<OsString>,
pub cwd: PathBuf,
pub timeout: Duration,
pub output_limit: usize,
}
#[derive(Debug)]
pub struct Finished {
pub status: std::process::ExitStatus,
pub stdout: Vec<u8>,
pub stderr: Vec<u8>,
pub truncated: bool,
}
#[derive(Debug, thiserror::Error)]
pub enum LaunchError {
#[error("timed out")]
TimedOut,
#[error("Tool call was cancelled.")]
Cancelled,
#[error("{0}")]
Failed(String),
}
pub type Running<'a> = Pin<Box<dyn Future<Output = Result<Finished, LaunchError>> + Send + 'a>>;
pub trait Launcher: Sync {
fn run<'a>(&'a self, launch: Launch, cancellation: &'a CancellationToken) -> Running<'a>;
}
pub struct Standalone;
impl Launcher for Standalone {
fn run<'a>(&'a self, launch: Launch, cancellation: &'a CancellationToken) -> Running<'a> {
Box::pin(platform::process::run(launch, cancellation))
}
}
pub fn passed_environment() -> BTreeMap<OsString, OsString> {
platform::process::passed_environment()
}