use systemprompt_identifiers::ServiceName;
mod control;
mod error;
mod ports;
mod spawn;
#[cfg(unix)]
mod posix;
#[cfg(windows)]
mod winnt;
#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "linux")]
use linux::live_environ;
#[cfg(target_os = "linux")]
pub use linux::{is_zombie, live_pid_is_subprocess};
#[cfg(target_os = "macos")]
mod darwin;
#[cfg(target_os = "macos")]
use darwin::live_environ;
#[cfg(target_os = "macos")]
pub use darwin::{is_zombie, live_pid_is_subprocess};
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
mod unsupported;
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
use unsupported::live_environ;
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
pub use unsupported::{is_zombie, live_pid_is_subprocess};
pub use control::{
StopOutcome, Termination, is_running, owns, pids_listening_on, process_group, stop_owned,
terminate_gracefully, terminate_group_gracefully,
};
pub use error::SupervisionError;
pub use ports::{parse_lsof_pids, parse_netstat_listeners};
pub use spawn::{
ApiServerStamp, mark_child, place_in_own_process_group, spawn_owned_supervised,
spawn_supervised, stamp_api_server,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ChildKind {
Agent,
Mcp,
Api,
}
impl ChildKind {
#[must_use]
pub const fn marker_env(self) -> &'static str {
match self {
Self::Agent => systemprompt_models::subprocess::AGENT_NAME_ENV,
Self::Mcp => systemprompt_models::subprocess::MCP_SERVICE_ID_ENV,
Self::Api => systemprompt_models::subprocess::API_SERVER_ENV,
}
}
#[must_use]
pub fn identifies(self, environ: &[u8], service: &ServiceName) -> bool {
match self {
Self::Agent | Self::Mcp => systemprompt_models::subprocess::environ_identifies_child(
environ,
self.marker_env(),
service,
),
Self::Api => {
systemprompt_models::subprocess::environ_identifies_api_server(environ, service)
},
}
}
}
#[must_use]
pub fn api_server_service() -> ServiceName {
ServiceName::new(systemprompt_models::subprocess::API_SERVER_SERVICE)
}