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-cli / src / platform.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | use std::path::PathBuf; |
| 17 | |
| 18 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 19 | pub enum PlatformKind { |
| 20 | DgxSpark, |
| 21 | Linux, |
| 22 | MacOS, |
| 23 | Windows, |
| 24 | } |
| 25 | |
| 26 | #[derive(Debug, Clone)] |
| 27 | pub struct PlatformContext { |
| 28 | pub kind: PlatformKind, |
| 29 | pub hostname: String, |
| 30 | pub current_user: String, |
| 31 | pub home_dir: PathBuf, |
| 32 | pub default_workspaces: Vec<PathBuf>, |
| 33 | } |
| 34 | |
| 35 | impl PlatformContext { |
| 36 | pub fn detect() -> Self { |
| 37 | let hostname = std::env::var("HOSTNAME") |
| 38 | .or_else(|_| std::fs::read_to_string("/etc/hostname").map(|s| s.trim().to_string())) |
| 39 | .unwrap_or_else(|_| "localhost".to_string()); |
| 40 | |
| 41 | let current_user = std::env::var("USER") |
| 42 | .or_else(|_| std::env::var("USERNAME")) |
| 43 | .unwrap_or_else(|_| "user".to_string()); |
| 44 | |
| 45 | let home_dir = std::env::var("HOME") |
| 46 | .or_else(|_| std::env::var("USERPROFILE")) |
| 47 | .map(PathBuf::from) |
| 48 | .unwrap_or_else(|_| PathBuf::from("/")); |
| 49 | |
| 50 | let is_spark = hostname.to_lowercase().contains("spark") |
| 51 | || std::path::Path::new("/etc/spark-release").exists() |
| 52 | || std::env::var("SPARK_HARDWARE") |
| 53 | .map(|v| v == "1") |
| 54 | .unwrap_or(false); |
| 55 | |
| 56 | let kind = if is_spark { |
| 57 | PlatformKind::DgxSpark |
| 58 | } else if cfg!(target_os = "macos") { |
| 59 | PlatformKind::MacOS |
| 60 | } else if cfg!(target_os = "windows") { |
| 61 | PlatformKind::Windows |
| 62 | } else { |
| 63 | PlatformKind::Linux |
| 64 | }; |
| 65 | |
| 66 | let mut default_workspaces = Vec::new(); |
| 67 | |
| 68 | if let Ok(env_ws) = std::env::var("AIEN_WORKSPACES") { |
| 69 | for part in env_ws.split(':') { |
| 70 | if !part.trim().is_empty() { |
| 71 | default_workspaces.push(PathBuf::from(part.trim())); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | default_workspaces.push(home_dir.join("workspace")); |
| 77 | default_workspaces.push(home_dir.join("atlas-prime-workspace")); |
| 78 | default_workspaces.push(home_dir.join("basecamp")); |
| 79 | default_workspaces.push(home_dir.join("spark-neural-os")); |
| 80 | default_workspaces.push(home_dir.join("skills")); |
| 81 | |
| 82 | if let Ok(cwd) = std::env::current_dir() { |
| 83 | if !default_workspaces.iter().any(|p| p == &cwd) { |
| 84 | default_workspaces.push(cwd); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | Self { |
| 89 | kind, |
| 90 | hostname, |
| 91 | current_user, |
| 92 | home_dir, |
| 93 | default_workspaces, |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | pub fn is_dgx_spark(&self) -> bool { |
| 98 | self.kind == PlatformKind::DgxSpark |
| 99 | } |
| 100 | } |