Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/blob/main/crates/aien-switchboard/src/cli.rs # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / crates / aien-switchboard / src / cli.rs` 136 lines ยท 4398 bytes Raw Blame History 1 //! The `switchboard` command line: `accounts`, `launch `, `doctor`. 2 //! 3 //! Everything the command touches comes in as arguments (environment, working 4 //! folder, spawner, version probe, output streams) so tests drive it with 5 //! fakes and a temp HOME. 6 7 use crate::account::Credential; 8 use crate::doctor::{doctor, VersionProbe}; 9 use crate::launch::{claude_profiles, launch, Env, Spawner}; 10 use crate::rules::RuleTable; 11 use std::ffi::OsStr; 12 use std::io::Write; 13 use std::path::{Path, PathBuf}; 14 15 const USAGE: &str = "usage: switchboard [--rules FILE] 16 17 commands: 18 accounts list the accounts in the rule file 19 launch open claude in that profile's own settings folder 20 doctor check the setup (never reads a secret) 21 22 The rule file defaults to $HOME/.switchboard/rules.toml."; 23 24 /// Exit codes: 0 done, 1 the command failed, 2 usage error. `launch` returns 25 /// the exit code of `claude`. 26 pub fn run( 27 args: &[String], 28 env: &Env, 29 cwd: &Path, 30 spawner: &mut dyn Spawner, 31 probe: &mut dyn VersionProbe, 32 out: &mut dyn Write, 33 err: &mut dyn Write, 34 ) -> i32 { 35 let mut rules_path: Option = None; 36 let mut rest: Vec<&str> = Vec::new(); 37 let mut it = args.iter(); 38 while let Some(a) = it.next() { 39 match a.as_str() { 40 "--rules" => match it.next() { 41 Some(p) => rules_path = Some(PathBuf::from(p)), 42 None => return usage(err, "--rules needs a file"), 43 }, 44 "-h" | "--help" | "help" => { 45 let _ = writeln!(out, "{USAGE}"); 46 return 0; 47 } 48 other => rest.push(other), 49 } 50 } 51 let (cmd, alias) = match rest.as_slice() { 52 ["accounts"] => ("accounts", None), 53 ["doctor"] => ("doctor", None), 54 ["launch", alias] => ("launch", Some(*alias)), 55 [] => return usage(err, "no command given"), 56 ["launch"] => return usage(err, "launch needs a profile alias"), 57 _ => return usage(err, &format!("unexpected arguments: {}", rest.join(" "))), 58 }; 59 60 let path = match rules_path.or_else(|| default_rules_path(env)) { 61 Some(p) => p, 62 None => return usage(err, "HOME is not set; pass --rules FILE"), 63 }; 64 let rules = match RuleTable::from_path(&path) { 65 Ok(r) => r, 66 Err(e) => { 67 let _ = writeln!(err, "switchboard: {e}"); 68 return 1; 69 } 70 }; 71 72 match (cmd, alias) { 73 ("accounts", _) => { 74 accounts(&rules, out); 75 0 76 } 77 ("doctor", _) => { 78 let report = doctor(&rules, env, cwd, probe); 79 let _ = writeln!(out, "rule file: {}\n{report}", path.display()); 80 i32::from(report.failed()) 81 } 82 (_, Some(alias)) => { 83 let _ = writeln!(err, "switchboard: opening profile {alias}"); 84 match launch(&rules, alias, env, spawner) { 85 Ok(code) => code, 86 Err(e) => { 87 let _ = writeln!(err, "switchboard: {e}"); 88 1 89 } 90 } 91 } 92 _ => usage(err, "unknown command"), 93 } 94 } 95 96 fn usage(err: &mut dyn Write, why: &str) -> i32 { 97 let _ = writeln!(err, "switchboard: {why}\n\n{USAGE}"); 98 2 99 } 100 101 fn default_rules_path(env: &Env) -> Option { 102 let home = env.get(OsStr::new("HOME"))?; 103 Some(Path::new(home).join(".switchboard").join("rules.toml")) 104 } 105 106 fn accounts(rules: &RuleTable, out: &mut dyn Write) { 107 let launchable: Vec<&str> = claude_profiles(rules) 108 .iter() 109 .map(|(a, _)| a.id.as_str()) 110 .collect(); 111 let _ = writeln!( 112 out, 113 "{:<16} {:<11} {:<8} {:<7} WHERE", 114 "ID", "PROVIDER", "PROGRAM", "LAUNCH" 115 ); 116 for a in rules.accounts() { 117 let where_ = match &a.credential { 118 Credential::SettingsFolder(p) => format!("folder {}", p.display()), 119 Credential::KeyRef(k) => format!("vault key name {k}"), 120 Credential::None => "no login needed".to_string(), 121 }; 122 let can = if launchable.contains(&a.id.as_str()) { 123 "yes" 124 } else { 125 "-" 126 }; 127 let _ = writeln!( 128 out, 129 "{:<16} {:<11} {:<8} {:<7} {where_}", 130 a.id.as_str(), 131 a.provider.as_str(), 132 a.program, 133 can 134 ); 135 } 136 }