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(config): apply environment overrides to module settings
Steven Enamakelebf0149a257b
diff --git a/crates/openhuman-core/src/config/schema/load/env_overlay.rs b/crates/openhuman-core/src/config/schema/load/env_overlay.rsindex 0a0e49a655..6dea83ef70 100644--- a/crates/openhuman-core/src/config/schema/load/env_overlay.rs+++ b/crates/openhuman-core/src/config/schema/load/env_overlay.rs@@ -4,6 +4,7 @@//! config section's overrides live in a submodule below.mod dictation_context;+mod modules;mod embeddings;mod observability;mod proxy;@@ -248,6 +249,7 @@ impl Config {self.apply_observability_env(env);self.apply_embedding_env(env);self.apply_update_env(env);+ self.apply_modules_env(env);self.apply_dictation_env(env);self.apply_context_env(env);diff --git a/crates/openhuman-core/src/config/schema/load/env_overlay/modules.rs b/crates/openhuman-core/src/config/schema/load/env_overlay/modules.rsnew file mode 100644index 0000000000..7bcb4e1656--- /dev/null+++ b/crates/openhuman-core/src/config/schema/load/env_overlay/modules.rs@@ -0,0 +1,54 @@+//! Env overrides for the module source (`[modules] source`).+//!+//! `OPENHUMAN_MODULE_SOURCE` sets the global mode; `OPENHUMAN_MODULE_SOURCE_<ID>`+//! (id upper-cased, non-alphanumerics as `_`) sets one module and beats both the+//! global mode and a `[[modules.overrides]]` entry for that id.++use crate::config::schema::load::env::EnvLookup;+use crate::config::schema::{Config, ModuleOverride, ModuleSourceMode};++/// Name of the global module-source variable.+pub const MODULE_SOURCE_ENV: &str = "OPENHUMAN_MODULE_SOURCE";++/// Name of the per-module variable for `id`.+#[must_use]+pub fn module_source_env_for(id: &str) -> String {+ let suffix: String = id+ .chars()+ .map(|c| {+ if c.is_ascii_alphanumeric() {+ c.to_ascii_uppercase()+ } else {+ '_'+ }+ })+ .collect();+ format!("{MODULE_SOURCE_ENV}_{suffix}")+}++impl Config {+ pub(super) fn apply_modules_env<E: EnvLookup + ?Sized>(&mut self, env: &E) {+ if let Some(raw) = env.get(MODULE_SOURCE_ENV) {+ match ModuleSourceMode::parse(&raw) {+ Some(mode) => self.modules.source = mode,+ None => tracing::warn!(+ "[modules] ignoring invalid {MODULE_SOURCE_ENV} (valid: release, linked, source)"+ ),+ }+ }+ for record in crate::modules::registry::ALL {+ let key = module_source_env_for(record.id);+ let Some(raw) = env.get(&key) else { continue };+ let Some(mode) = ModuleSourceMode::parse(&raw) else {+ tracing::warn!(+ "[modules] ignoring invalid {key} (valid: release, linked, source)"+ );+ continue;+ };+ self.modules.overrides.retain(|entry| entry.id != record.id);+ self.modules+ .overrides+ .push(ModuleOverride::with_source(record.id, mode));+ }+ }+}diff --git a/crates/openhuman-core/src/config/schema/mod.rs b/crates/openhuman-core/src/config/schema/mod.rsindex e2d8f7b620..5fff13cd59 100644--- a/crates/openhuman-core/src/config/schema/mod.rs+++ b/crates/openhuman-core/src/config/schema/mod.rs@@ -97,7 +97,7 @@ pub use memory::{MemoryEngineSettings, MemoryLayoutMode, MemoryRecallConfig, MemorySourceConfig,MemorySourceKind, MEMORY_CORTEXDB_KEY_NAME,};-pub use modules::{ModuleOverride, ModulesConfig};+pub use modules::{ModuleOverride, ModuleSourceMode, ModulesConfig};pub use observability::{AgentTracingBackend, AgentTracingConfig, ObservabilityConfig};pub use privacy::{PrivacyConfig, PrivacyMode};pub use proxy::{diff --git a/crates/openhuman-core/src/config/schema/modules.rs b/crates/openhuman-core/src/config/schema/modules.rsindex 3ac8761ef1..c961fe9ee8 100644--- a/crates/openhuman-core/src/config/schema/modules.rs+++ b/crates/openhuman-core/src/config/schema/modules.rs@@ -44,6 +44,14 @@ pub struct ModulesConfig {/// acceptable only because it is the operator's own file, named by the/// operator's own config.pub overrides: Vec<ModuleOverride>,++ /// Where modules come from when no per-module override says otherwise.+ ///+ /// `release` (the default, and the only mode CI and shipped builds use) is+ /// the pinned, digest-checked GitHub release. `linked` and `source` are for+ /// local development and local tests. Overridden by+ /// `OPENHUMAN_MODULE_SOURCE`.+ pub source: ModuleSourceMode,}impl Default for ModulesConfig {@@ -53,16 +61,102 @@ impl Default for ModulesConfig {allow_download: defaults::default_true(),install_dir: None,overrides: Vec::new(),+ source: ModuleSourceMode::default(),}}}-/// A local artifact standing in for one registry entry.+/// Where a module is resolved from.+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema)]+#[serde(rename_all = "lowercase")]+pub enum ModuleSourceMode {+ /// The registry-pinned, digest-checked GitHub release. The default.+ #[default]+ Release,+ /// The in-process factory registered by `openhuman-modules-linked`. Local+ /// development only; falls back to `release` when no factory is registered.+ Linked,+ /// A locally built artifact. Local development only; falls back to+ /// `release` when none is available.+ Source,+}++impl ModuleSourceMode {+ /// Parse a user-supplied value (`release`, `linked`, `source`).+ #[must_use]+ pub fn parse(raw: &str) -> Option<Self> {+ match raw.trim().to_ascii_lowercase().as_str() {+ "release" => Some(Self::Release),+ "linked" => Some(Self::Linked),+ "source" => Some(Self::Source),+ _ => None,+ }+ }++ /// Stable lowercase name, as written in config and logs.+ #[must_use]+ pub const fn as_str(self) -> &'static str {+ match self {+ Self::Release => "release",+ Self::Linked => "linked",+ Self::Source => "source",+ }+ }+}++/// A local artifact, or a source mode, standing in for one registry entry.+///+/// Exactly one of `path` and `source` is set; an entry with both or neither is+/// ignored with a warning (see [`ModuleOverride::validate`]). `{ id, path }`+/// entries written before `source` existed keep parsing unchanged.#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]#[serde(deny_unknown_fields)]pub struct ModuleOverride {/// Registry id this override replaces, e.g. `tinydocs`.pub id: String,/// Absolute path to a platform library (`.so` / `.dylib` / `.dll`).- pub path: String,+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub path: Option<String>,+ /// Source mode for just this module, beating `[modules] source`.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub source: Option<ModuleSourceMode>,+}++impl ModuleOverride {+ /// An override pointing at a local library.+ #[must_use]+ pub fn with_path(id: impl Into<String>, path: impl Into<String>) -> Self {+ Self {+ id: id.into(),+ path: Some(path.into()),+ source: None,+ }+ }++ /// An override selecting a source mode.+ #[must_use]+ pub fn with_source(id: impl Into<String>, source: ModuleSourceMode) -> Self {+ Self {+ id: id.into(),+ path: None,+ source: Some(source),+ }+ }++ /// `Ok` when exactly one of `path` and `source` is set.+ ///+ /// # Errors+ ///+ /// A static description of what is wrong; it never echoes the path.+ pub fn validate(&self) -> Result<(), &'static str> {+ match (&self.path, &self.source) {+ (Some(_), None) | (None, Some(_)) => Ok(()),+ (Some(_), Some(_)) => Err("set either `path` or `source`, not both"),+ (None, None) => Err("set one of `path` or `source`"),+ }+ }}++#[cfg(test)]+#[path = "modules_tests.rs"]+mod tests;