aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / crates / aien-switchboard / src / bin / switchboard.rs
| 1 | //! `switchboard`: list, open and check isolated Claude Code profiles |
| 2 | //! (ADR 0030 phase 1, issue #592). The only place in the crate that starts a |
| 3 | //! process. |
| 4 | |
| 5 | use aien_switchboard::cli; |
| 6 | use aien_switchboard::launch::{LaunchError, LaunchPlan, Spawner}; |
| 7 | use aien_switchboard::{Env, VersionProbe}; |
| 8 | use std::os::unix::process::CommandExt; |
| 9 | use std::path::Path; |
| 10 | use std::process::{Command, Stdio}; |
| 11 | |
| 12 | /// Replaces this process with `claude`, so `claude` owns the terminal and its |
| 13 | /// signals directly. Only returns if the operating system refused. |
| 14 | struct ExecSpawner; |
| 15 | |
| 16 | impl Spawner for ExecSpawner { |
| 17 | fn spawn(&mut self, plan: &LaunchPlan) -> Result<i32, LaunchError> { |
| 18 | let e = Command::new(&plan.program) |
| 19 | .env_clear() |
| 20 | .envs(&plan.env) |
| 21 | .exec(); |
| 22 | Err(LaunchError::Spawn { |
| 23 | program: plan.program.clone(), |
| 24 | message: e.kind().to_string(), |
| 25 | }) |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | /// Runs `<program> --version` with exactly the given environment and no |
| 30 | /// input. |
| 31 | struct CommandProbe; |
| 32 | |
| 33 | impl VersionProbe for CommandProbe { |
| 34 | fn version(&mut self, program: &Path, env: &Env) -> Result<String, String> { |
| 35 | let out = Command::new(program) |
| 36 | .arg("--version") |
| 37 | .env_clear() |
| 38 | .envs(env) |
| 39 | .stdin(Stdio::null()) |
| 40 | .output() |
| 41 | .map_err(|e| e.kind().to_string())?; |
| 42 | if out.status.success() { |
| 43 | Ok(String::from_utf8_lossy(&out.stdout).into_owned()) |
| 44 | } else { |
| 45 | Err(format!("exit status {}", out.status)) |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | fn main() { |
| 51 | let args: Vec<String> = std::env::args().skip(1).collect(); |
| 52 | let env: Env = std::env::vars_os().collect(); |
| 53 | let cwd = match std::env::current_dir() { |
| 54 | Ok(d) => d, |
| 55 | Err(e) => { |
| 56 | eprintln!("switchboard: cannot read the working folder: {}", e.kind()); |
| 57 | std::process::exit(1); |
| 58 | } |
| 59 | }; |
| 60 | let code = cli::run( |
| 61 | &args, |
| 62 | &env, |
| 63 | &cwd, |
| 64 | &mut ExecSpawner, |
| 65 | &mut CommandProbe, |
| 66 | &mut std::io::stdout(), |
| 67 | &mut std::io::stderr(), |
| 68 | ); |
| 69 | std::process::exit(code); |
| 70 | } |