bamboo_subagent/
launcher.rs1use std::path::PathBuf;
11use std::time::Duration;
12
13use async_trait::async_trait;
14
15use crate::fleet::{spawn_worker, SpawnedChild};
16use crate::provision::ProvisionSpec;
17use crate::transport::TransportResult;
18
19#[async_trait]
24pub trait WorkerLauncher: Send + Sync {
25 async fn launch(&self, spec: &ProvisionSpec, wait: Duration) -> TransportResult<SpawnedChild>;
26}
27
28pub struct LocalSubprocessLauncher {
32 pub worker_bin: PathBuf,
33 pub worker_args: Vec<String>,
34}
35
36impl LocalSubprocessLauncher {
37 pub fn new(worker_bin: impl Into<PathBuf>, worker_args: Vec<String>) -> Self {
38 Self {
39 worker_bin: worker_bin.into(),
40 worker_args,
41 }
42 }
43}
44
45#[async_trait]
46impl WorkerLauncher for LocalSubprocessLauncher {
47 async fn launch(&self, spec: &ProvisionSpec, wait: Duration) -> TransportResult<SpawnedChild> {
48 spawn_worker(&self.worker_bin, &self.worker_args, spec, wait).await
49 }
50}
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
59 fn local_subprocess_launcher_is_a_trait_object() {
60 let launcher = LocalSubprocessLauncher::new("/bin/true", vec!["subagent-worker".into()]);
61 let _dyn: &dyn WorkerLauncher = &launcher;
62 assert_eq!(launcher.worker_bin, PathBuf::from("/bin/true"));
63 assert_eq!(launcher.worker_args, vec!["subagent-worker".to_string()]);
64 }
65}