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(core): add components gate for runtime component checks
Steven Enamakelc10f9f6147b1
diff --git a/crates/openhuman-core/src/core/all.rs b/crates/openhuman-core/src/core/all.rsindex fad5d9974d..bf41f15082 100644--- a/crates/openhuman-core/src/core/all.rs+++ b/crates/openhuman-core/src/core/all.rs@@ -4,9 +4,7 @@//! controllers (e.g., memory, skills, config) and providing a unified//! interface for both the CLI and RPC layers to invoke them.-use std::future::Future;-use std::pin::Pin;-use std::sync::{Arc, OnceLock, RwLock};+use std::{future::Future, pin::Pin, sync::{Arc, OnceLock, RwLock}};use serde_json::{Map, Value};@@ -47,6 +45,8 @@ impl RegisteredController {}pub use super::domain_group::DomainGroup;+mod components_gate;+pub use components_gate::disabled_component_for_method;/// A [`RegisteredController`] tagged with the [`DomainGroup`] it belongs to.///diff --git a/crates/openhuman-core/src/core/all/components_gate.rs b/crates/openhuman-core/src/core/all/components_gate.rsnew file mode 100644index 0000000000..f8ffb0a7e6--- /dev/null+++ b/crates/openhuman-core/src/core/all/components_gate.rs@@ -0,0 +1,28 @@+//! Which `[components]` switch, if any, hides an RPC method.+//!+//! A family a switch removed answers `COMPONENT_DISABLED:<name>` so the UI and+//! CLI can explain it; a family the host merely left out stays+//! indistinguishable from an unregistered method.++use super::{internal_registry, registry_view, visible};++/// `Some(component)` when `method` is registered but hidden because its+/// component is switched off in the ambient scope. Dispatch asks this before+/// reporting an unknown method.+pub fn disabled_component_for_method(method: &str) -> Option<&'static str> {+ let view = registry_view();+ let grouped = view+ .iter()+ .chain(internal_registry().iter())+ .find(|g| g.controller.rpc_method_name() == method)?;+ if visible(grouped) {+ return None;+ }+ let name = crate::core::runtime::ComponentSet::component_for_group(grouped.group)?;+ let ctx = crate::core::runtime::context::CoreContext::current()?;+ if ctx.components().enabled(name) {+ return None;+ }+ log::debug!("[rpc][component-gate] method '{method}' refused, component '{name}' disabled");+ Some(name)+}diff --git a/crates/openhuman-core/src/core/dispatch.rs b/crates/openhuman-core/src/core/dispatch.rsindex f836fb1967..031a67f1f0 100644--- a/crates/openhuman-core/src/core/dispatch.rs+++ b/crates/openhuman-core/src/core/dispatch.rs@@ -237,9 +237,8 @@ async fn try_registry_dispatch(let Some(schema) = crate::core::all::schema_for_rpc_method(method) else {// Hidden because a `[components]` switch is off: say so, rather than// reporting a method that exists as unknown.- return crate::core::all::disabled_component_for_method(method).map(|name| {- Err(crate::core::runtime::components::component_disabled(name).encode())- });+ return crate::core::all::disabled_component_for_method(method)+ .map(|name| Err(crate::core::runtime::components::component_disabled(name).encode()));};let params_obj = match params_to_object(params) {Ok(params_obj) => params_obj,diff --git a/crates/openhuman-core/src/core/runtime/components_tests.rs b/crates/openhuman-core/src/core/runtime/components_tests.rsindex c6a9cc3187..543efccef8 100644--- a/crates/openhuman-core/src/core/runtime/components_tests.rs+++ b/crates/openhuman-core/src/core/runtime/components_tests.rs@@ -10,8 +10,14 @@ fn off(name: &str) -> ComponentSet {fn all_on_changes_nothing() {let all = ComponentSet::all();assert_eq!(all.narrow_domains(DomainSet::full()), DomainSet::full());- assert_eq!(all.narrow_services(ServiceSet::desktop()), ServiceSet::desktop());- assert_eq!(all.narrow_tool_groups(ToolGroups::advertised()), ToolGroups::advertised());+ assert_eq!(+ all.narrow_services(ServiceSet::desktop()),+ ServiceSet::desktop()+ );+ assert_eq!(+ all.narrow_tool_groups(ToolGroups::advertised()),+ ToolGroups::advertised()+ );}#[test]@@ -63,8 +69,17 @@ fn each_flag_turns_its_tool_groups_off() {#[test]fn config_cannot_widen_a_host_preset() {let all = ComponentSet::all();- for preset in [DomainSet::harness(), DomainSet::kernel(), DomainSet::none(), DomainSet::embedded()] {- assert_eq!(all.narrow_domains(preset), preset, "all-on must be identity");+ for preset in [+ DomainSet::harness(),+ DomainSet::kernel(),+ DomainSet::none(),+ DomainSet::embedded(),+ ] {+ assert_eq!(+ all.narrow_domains(preset),+ preset,+ "all-on must be identity"+ );assert_eq!(all.narrow_domains(preset).intersect(&preset), preset);}// kernel has no flows/mcp/...; components being on must not add them.@@ -75,7 +90,10 @@ fn config_cannot_widen_a_host_preset() {assert_eq!(g.mode("workflows"), GroupMode::Off);// And headless services stay off.assert_eq!(all.narrow_services(ServiceSet::none()), ServiceSet::none());- assert_eq!(all.narrow_services(ServiceSet::headless_api()), ServiceSet::headless_api());+ assert_eq!(+ all.narrow_services(ServiceSet::headless_api()),+ ServiceSet::headless_api()+ );}#[test]diff --git a/tests/components_e2e.rs b/tests/components_e2e.rsindex 855c7d1e0e..893225ed8e 100644--- a/tests/components_e2e.rs+++ b/tests/components_e2e.rs@@ -65,7 +65,9 @@ fn disabled_component_answers_component_disabled_over_json_rpc() {let server = tokio::spawn(async move { axum::serve(listener, app).await });let off = rpc(&base, "openhuman.mcp_clients_status").await;- let err = off.get("error").unwrap_or_else(|| panic!("want error: {off}"));+ let err = off+ .get("error")+ .unwrap_or_else(|| panic!("want error: {off}"));assert_eq!(err.get("message").and_then(Value::as_str),Some("COMPONENT_DISABLED:mcp"),@@ -76,7 +78,10 @@ fn disabled_component_answers_component_disabled_over_json_rpc() {Some("component_disabled"),"{off}");- assert_eq!(err.pointer("/data/component").and_then(Value::as_str), Some("mcp"));+ assert_eq!(+ err.pointer("/data/component").and_then(Value::as_str),+ Some("mcp")+ );// A component left on is untouched.let on = rpc(&base, "openhuman.config_get").await;