The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(runtime): add runtime mode selection
Steven Enamakel07ec71f1c52e
diff --git a/crates/openhuman-core/src/core/runtime/mode.rs b/crates/openhuman-core/src/core/runtime/mode.rsnew file mode 100644index 0000000000..e7071b3882--- /dev/null+++ b/crates/openhuman-core/src/core/runtime/mode.rs@@ -0,0 +1,90 @@+//! Which operating mode this process serves.+//!+//! | [`Mode`] | Who the process serves |+//! | --- | --- |+//! | [`Mode::SingleUser`] | One user on their own machine — the desktop app, the CLI, embedders. Today's behaviour and the default. |+//! | [`Mode::Saas`] | Many users through a trusted gateway, one embedded agent per user, with closed defaults. |+//!+//! The mode is a property of the **process**, fixed the first time a SaaS core+//! boots ([`lock_mode`]) and never part of any user's `Config`: a mode a+//! config write or an RPC could flip would let a caller reopen everything SaaS+//! closes. Code that must behave differently asks [`is_saas`], which reads an+//! unset slot as `SingleUser`, so a process that never boots SaaS takes no new+//! branch.++use std::str::FromStr;+use std::sync::OnceLock;++/// The operating mode of a process.+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]+pub enum Mode {+ /// One user per process: today's desktop, CLI and embed behaviour.+ #[default]+ SingleUser,+ /// Many users per process, each served as their own agent.+ Saas,+}++impl Mode {+ /// Stable tag for logs and CLI flags.+ pub fn tag(self) -> &'static str {+ match self {+ Mode::SingleUser => "single-user",+ Mode::Saas => "saas",+ }+ }+}++impl std::fmt::Display for Mode {+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {+ f.write_str(self.tag())+ }+}++impl FromStr for Mode {+ type Err = String;++ fn from_str(raw: &str) -> Result<Self, Self::Err> {+ match raw.trim().to_ascii_lowercase().as_str() {+ "single-user" | "single_user" | "singleuser" | "single" => Ok(Mode::SingleUser),+ "saas" => Ok(Mode::Saas),+ other => Err(format!(+ "unknown mode `{other}` (expected `single-user` or `saas`)"+ )),+ }+ }+}++static MODE: OnceLock<Mode> = OnceLock::new();++/// The mode this process runs in; `SingleUser` until a SaaS core boots.+pub fn current_mode() -> Mode {+ MODE.get().copied().unwrap_or_default()+}++/// Whether this process serves many users.+pub fn is_saas() -> bool {+ current_mode() == Mode::Saas+}++/// Fix the process mode. Locking the mode it already has is a no-op; locking+/// a different one fails, because one process never serves both shapes.+pub(crate) fn lock_mode(mode: Mode) -> Result<(), String> {+ lock_in(&MODE, mode)+}++fn lock_in(slot: &OnceLock<Mode>, mode: Mode) -> Result<(), String> {+ let locked = *slot.get_or_init(|| mode);+ if locked == mode {+ log::info!("[mode] process mode locked to {mode}");+ Ok(())+ } else {+ Err(format!(+ "this process is already running in {locked} mode; it cannot switch to {mode}"+ ))+ }+}++#[cfg(test)]+#[path = "mode_tests.rs"]+mod tests;