//! Command line parts of the `strata-desktop` binary: one module per long-running command. use std::{fs::File, io::Read}; pub(crate) mod node; pub(crate) mod proxy; pub(crate) mod tunnel; pub(crate) mod worker; pub(crate) const HELP: &str = concat!( "strata-desktop hardware\n", "strata-desktop plan REQUIREMENTS.json [--hardware SNAPSHOT.json]\n", "strata-desktop remote-inspect SSH_PROFILE.json\n", "strata-desktop ssh-tunnel TUNNEL_PROFILE.json\n", "strata-desktop remote-install INSTALL.json\n", "strata-desktop remote-activate ACTIVATION.json\n", "strata-desktop validate-worker WORKER.json\n", "strata-desktop gateway POOL.json\n", "strata-desktop node --listen 127.0.0.1:0 --token-env ENV [--pool POOL.json | --worker-profile FILE ", "[--journal PRIVATE_PATH] | --stdio-lifetime]\n", "strata-desktop node-proxy --listen 127.0.0.1:18765 --node 127.0.0.1:18766 --token-env ENV\n", "strata-desktop worker --node 127.0.0.1:18766 --token-env ENV status|start UUID|stop UUID|operation UUID\n", "Inventory and planning are read-only. Gateway serves configured loopback workers; it does not start or ", "replace models." ); pub(crate) fn read_json( path: &str, ) -> Result> { let mut data = Vec::new(); File::open(path)? .take(1024 * 1024 + 1) .read_to_end(&mut data)?; if data.len() > 1024 * 1024 { return Err("input JSON exceeds 1 MiB".into()); } Ok(serde_json::from_slice(&data)?) } /// A receiver that fires once standard input reaches end of file (the parent process is gone). pub(crate) fn stdin_closed() -> tokio::sync::oneshot::Receiver<()> { let (closed_tx, closed_rx) = tokio::sync::oneshot::channel(); std::thread::spawn(move || { let mut byte = [0]; while std::io::stdin().read(&mut byte).is_ok_and(|n| n > 0) {} let _ = closed_tx.send(()); }); closed_rx }