Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(core): move DomainSet into its own module

Steven Enamakel8d7042bbd2bf
diff --git a/crates/openhuman-core/src/agent/orchestration/background_completions.rs b/crates/openhuman-core/src/agent/orchestration/background_completions.rs
index 99b139e938..124cd38c90 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_completions.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_completions.rs
@@ -359,7 +359,7 @@ pub(crate) async fn record_awaiting_input(
}
/// Drop every workspace's router and all process-local state about them. Called
-/// when the core stops (`CoreRuntime::exit_cleanup`), so the completion logs'
+/// when the core server stops (`openhuman_rpc::server::serve`), so the completion logs'
/// file handles close before a data reset removes their directory (Windows
/// refuses to delete an open file) and a later boot starts from the logs alone.
/// A delivery still in flight keeps its own router handle until it finishes; the
diff --git a/crates/openhuman-core/src/core/runtime/builder.rs b/crates/openhuman-core/src/core/runtime/builder.rs
index 6025443393..b62f4673cf 100644
--- a/crates/openhuman-core/src/core/runtime/builder.rs
+++ b/crates/openhuman-core/src/core/runtime/builder.rs
@@ -25,10 +25,11 @@
use std::sync::Arc;
use crate::config::Config;
-use crate::core::all::DomainGroup;
use crate::core::runtime::context::CoreContext;
use crate::core::types::HostKind;
+pub use super::domain_set::DomainSet;
+
/// Selects which background services and transports a [`CoreRuntime`] runs.
///
/// Each flag is independent. Presets cover the common hosts:
@@ -150,293 +151,6 @@ impl ServiceSet {
}
}
-/// Selects which domain *families* exist at runtime on a [`CoreRuntime`] (#4796).
-///
-/// Sibling of [`ServiceSet`]: where `ServiceSet` selects background services and
-/// transports, `DomainSet` selects which controller/tool/store/subscriber
-/// surfaces are live. Each flag is an independent [`DomainGroup`]; presets cover
-/// the common hosts:
-/// [`DomainSet::full`] (every family — today's behavior, the default),
-/// [`DomainSet::harness`] (agent + memory + threads + config + security only —
-/// the embeddable agent core used by `examples/embed_headless.rs`), and
-/// [`DomainSet::none`] (all domain families disabled; transport built-ins and
-/// always-on core infrastructure still run).
-///
-/// `full()` is byte-identical to pre-#4796 registration, so the desktop shell
-/// and standalone CLI are unchanged. Per-gate Cargo `[features]` (children
-/// #4797–#4804) narrow the *compile-time* surface further; this struct is the
-/// *runtime* axis they compose with.
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub struct DomainSet {
- /// Agent definition/registry/experience, orchestration, session DB/import.
- pub agent: bool,
- /// Documents, knowledge graph, memory tree/sources/sync/diff/goals.
- pub memory: bool,
- /// Conversation threads, per-thread goals, todos.
- pub threads: bool,
- /// Persisted runtime configuration.
- pub config: bool,
- /// Encryption, keyring consent, security policy, approval, plan-review.
- pub security: bool,
- /// Saved automation workflows (tinyflows graphs).
- pub flows: bool,
- /// SKILL.md skills, skill runtime, skill registry.
- pub skills: bool,
- /// MCP client subsystem (Smithery registry, local servers, audit).
- pub mcp: bool,
- /// Messaging channels + webview bridges (web channel, whatsapp data, …).
- pub channels: bool,
- /// Wallet, high-level web3 surface, x402 machine payments.
- pub web3: bool,
- /// Speech-to-text / text-to-speech, audio toolkit.
- pub voice: bool,
- /// Image/video media generation. NOTE: today this gates only the
- /// `media_generate_*` **agent tools** — no controller/store/subscriber is
- /// tagged `Media` (there is no `media` RPC namespace yet), so a custom set
- /// with `media: false, platform: true` drops the media tools while any
- /// future backing controller would stay live. Fold the media-generation
- /// controller into this group when it lands.
- pub media: bool,
- /// Model inference: providers, routing, local engines, embeddings.
- pub inference: bool,
- /// External connectors (Composio, calendar, file storage, task sources).
- pub integrations: bool,
- /// Background initiative: scheduled cron jobs.
- pub automation: bool,
- /// Code-execution substrate: Node/Python runtimes, pool, sandbox.
- pub runtimes: bool,
- /// Desktop-shell-facing surfaces.
- pub desktop: bool,
- /// Clients of the hosted TinyHumans backend.
- pub hosted: bool,
- /// Loadable native modules: the module host, registry and `modules` RPC.
- pub modules: bool,
- /// Everything not in a named family — always on in `full()`.
- pub platform: bool,
-}
-
-impl DomainSet {
- /// Every family on — today's behavior and the [`CoreBuilder`] default.
- /// Registration is byte-identical to pre-#4796.
- pub fn full() -> Self {
- Self {
- agent: true,
- memory: true,
- threads: true,
- config: true,
- security: true,
- flows: true,
- skills: true,
- mcp: true,
- channels: true,
- web3: true,
- voice: true,
- media: true,
- inference: true,
- integrations: true,
- automation: true,
- runtimes: true,
- desktop: true,
- hosted: true,
- modules: true,
- platform: true,
- }
- }
-
- /// The embeddable agent core: agent + memory + threads + config + security.
- /// Every gate family AND `platform` are off. Used by
- /// `examples/embed_headless.rs`.
- pub fn harness() -> Self {
- Self {
- agent: true,
- memory: true,
- threads: true,
- config: true,
- security: true,
- flows: false,
- skills: false,
- mcp: false,
- channels: false,
- web3: false,
- voice: false,
- media: false,
- inference: false,
- integrations: false,
- automation: false,
- runtimes: false,
- desktop: false,
- hosted: false,
- modules: false,
- platform: false,
- }
- }
-
- /// A long-lived embedded host: the harness core plus the workflow engine
- /// and the supporting
- /// runtime, automation, integration, and platform surfaces it needs.
- ///
- /// Named for the *shape* rather than any downstream consumer — the core
- /// does not know which host embeds it, and a preset naming one would invert
- /// that. Suits any process that drives the core in-process through the
- /// typed facade and owns its own presentation layer.
- ///
- /// Deliberately NOT built on [`DomainSet::harness`]: that preset sets
- /// `platform: false`, which drops credentials, config, cron, task_sources
- /// and todos, and leaves `channels` off — but `channel.web_chat` is tagged
- /// `DomainGroup::Channels` and an embedded host drives chat turns through it.
- ///
- /// `flows: true` keeps the tinyflows engine and boot reconciliation on;
- /// reconciliation keys off
- /// `ctx.domains().flows` rather than a `ServiceSet` flag.
- ///
- /// An embedded host supplies its own harness wrappers, networking and
- /// routing, so `web3` / `voice` / `media` / `mcp` stay off.
- pub fn embedded() -> Self {
- Self {
- agent: true,
- memory: true,
- threads: true,
- config: true,
- security: true,
- flows: true,
- skills: true,
- mcp: false,
- channels: true,
- web3: false,
- voice: false,
- media: false,
- inference: true,
- integrations: true,
- automation: true,
- runtimes: true,
- desktop: false,
- hosted: false,
- modules: false,
- platform: true,
- }
- }
-
- /// The kernel floor: threads, config, security — and nothing else.
- ///
- /// Distinct from [`DomainSet::none`], which is "no domains at all". This is
- /// "the minimum a host needs before opting a subsystem back in", so an
- /// embedder can request kernel + exactly one family. `agent` and `memory`
- /// are OFF on purpose: they are the two largest subsystems and the ones an
- /// alternative driver would replace, so a host that wants them says so.
- ///
- /// See `examples/embed_kernel.rs`.
- pub fn kernel() -> Self {
- Self {
- agent: false,
- memory: false,
- threads: true,
- config: true,
- security: true,
- flows: false,
- skills: false,
- mcp: false,
- channels: false,
- web3: false,
- voice: false,
- media: false,
- inference: false,
- integrations: false,
- automation: false,
- runtimes: false,
- desktop: false,
- hosted: false,
- modules: false,
- platform: false,
- }
- }
-
- /// Nothing on — every family disabled.
- pub fn none() -> Self {
- Self {
- agent: false,
- memory: false,
- threads: false,
- config: false,
- security: false,
- flows: false,
- skills: false,
- mcp: false,
- channels: false,
- web3: false,
- voice: false,
- media: false,
- inference: false,
- integrations: false,
- automation: false,
- runtimes: false,
- desktop: false,
- hosted: false,
- modules: false,
- platform: false,
- }
- }
-
- /// Whether the given [`DomainGroup`] is enabled in this set.
- pub fn allows(&self, group: DomainGroup) -> bool {
- match group {
- DomainGroup::Agent => self.agent,
- DomainGroup::Memory => self.memory,
- DomainGroup::Threads => self.threads,
- DomainGroup::Config => self.config,
- DomainGroup::Security => self.security,
- DomainGroup::Flows => self.flows,
- DomainGroup::Skills => self.skills,
- DomainGroup::Mcp => self.mcp,
- DomainGroup::Channels => self.channels,
- DomainGroup::Web3 => self.web3,
- DomainGroup::Voice => self.voice,
- DomainGroup::Media => self.media,
- DomainGroup::Inference => self.inference,
- DomainGroup::Integrations => self.integrations,
- DomainGroup::Automation => self.automation,
- DomainGroup::Runtimes => self.runtimes,
- DomainGroup::Desktop => self.desktop,
- DomainGroup::Hosted => self.hosted,
- DomainGroup::Modules => self.modules,
- DomainGroup::Platform => self.platform,
- }
- }
-
- /// Field-wise AND with `other`: a family is on in the result only if it
- /// was on in both.
- ///
- /// Used to clamp a derived context's requested domains to what the
- /// parent context actually registered — see
- /// [`CoreContext::derive_with`](crate::core::runtime::CoreContext::derive_with).
- /// A derived overlay is meant to *narrow* the parent, never state a
- /// family the parent never registered back into existence.
- #[must_use]
- pub fn intersect(&self, other: &DomainSet) -> DomainSet {
- DomainSet {
- agent: self.agent && other.agent,
- memory: self.memory && other.memory,
- threads: self.threads && other.threads,
- config: self.config && other.config,
- security: self.security && other.security,
- flows: self.flows && other.flows,
- skills: self.skills && other.skills,
- mcp: self.mcp && other.mcp,
- channels: self.channels && other.channels,
- web3: self.web3 && other.web3,
- voice: self.voice && other.voice,
- media: self.media && other.media,
- inference: self.inference && other.inference,
- integrations: self.integrations && other.integrations,
- automation: self.automation && other.automation,
- runtimes: self.runtimes && other.runtimes,
- desktop: self.desktop && other.desktop,
- hosted: self.hosted && other.hosted,
- modules: self.modules && other.modules,
- platform: self.platform && other.platform,
- }
- }
-}
-
/// How the per-process RPC bearer token is seeded.
pub enum TokenSource {
/// An in-memory bearer supplied by the embedder (the Tauri shell hands its
@@ -774,9 +488,6 @@ impl CoreRuntime {
/// to stop either: the user runs Ollama / LM Studio / MLX themselves and
/// OpenHuman never spawns it.
pub async fn exit_cleanup(&self) {
- // Close the per-workspace background-completion logs (still replayable
- // from disk on the next boot).
- crate::agent::orchestration::release_background_completion_stores();
log::debug!("[core] shutdown: exit cleanup done (no owned local runtime to stop)");
}
diff --git a/crates/openhuman-rpc/src/server/serve.rs b/crates/openhuman-rpc/src/server/serve.rs
index 7f014161b1..fca8b4304c 100644
--- a/crates/openhuman-rpc/src/server/serve.rs
+++ b/crates/openhuman-rpc/src/server/serve.rs
@@ -193,6 +193,9 @@ pub async fn serve(
}
runtime.exit_cleanup().await;
+ // Close the per-workspace background-completion logs (they replay from disk
+ // on the next boot) so a data reset can delete the workspace directory.
+ openhuman_core::agent::orchestration::release_background_completion_stores();
served?;
Ok(())