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(memory): confine memory writes to the workspace
Steven Enamakelc496b3d739e4
diff --git a/crates/openhuman-core/src/memory/confine.rs b/crates/openhuman-core/src/memory/confine.rsindex 454931e547..676ff6923e 100644--- a/crates/openhuman-core/src/memory/confine.rs+++ b/crates/openhuman-core/src/memory/confine.rs@@ -7,8 +7,9 @@//! every namespace, so an RPC or MCP caller could list, read and forget//! another root's memory (another team's, or another host-bound agent's).//!-//! Every RPC now resolves the identity in scope ([`super::scope::resolve_current`]:-//! the agent of a running turn, else the config's own root identity) and:+//! Every RPC resolves the identity the caller passes ([`MemoryIdentity`]; the+//! RPC handlers pass [`MemoryIdentity::root`], the config's own root+//! identity) and://!//! - fills an unset `reach` with that identity's subtree ([`allowed_reach`]);//! - keeps a caller's reach only when it is [`Reach::within`] the allowed@@ -23,17 +24,17 @@ use crate::config::Config;use super::error::{MemoryError, MemoryResult};use super::explore::{self, ExploreParams, ItemsGetParams, ItemsGetView};use super::ops;-use super::scope;+use super::scope::MemoryIdentity;use super::types::{FetchParams, FetchView, ForgetParams, ForgetView, ItemsListParams, ItemsListView, LearnParams,LearnView, RecallParams, RecallView,};-/// What the caller under `config` may read and forget: the subtree of the-/// identity in scope's layout root.+/// What `identity` under `config` may read and forget: the subtree of its+/// layout root.#[must_use]-pub fn allowed_reach(config: &Config) -> Reach {- Reach::subtree(scope::resolve_current(config).root().clone())+pub fn allowed_reach(config: &Config, identity: &MemoryIdentity) -> Reach {+ Reach::subtree(identity.resolve(config).root().clone())}/// `reach` confined to `allowed`: unset becomes `allowed`, a reach within it@@ -73,15 +74,19 @@ pub fn confine_filter(filter: Option<MetaFilter>, allowed: &Reach) -> MemoryResu}/// The metadata a `memory_learn` caller sent, with its namespace inside the-/// identity in scope's layout: an unset namespace (the root) lands at the+/// `identity`'s layout: an unset namespace (the root) lands at the/// layout's learnings node when that is not the root itself.////// # Errors////// [`MemoryError::InvalidRequest`] when the namespace is outside the/// layout's subtree.-pub fn confine_learn_meta(config: &Config, meta: Option<MemoryMeta>) -> MemoryResult<MemoryMeta> {- let resolved = scope::resolve_current(config);+pub fn confine_learn_meta(+ config: &Config,+ identity: &MemoryIdentity,+ meta: Option<MemoryMeta>,+) -> MemoryResult<MemoryMeta> {+ let resolved = identity.resolve(config);let allowed = Reach::subtree(resolved.root().clone());let mut meta = meta.unwrap_or_default();if meta.namespace == Namespace::ROOT {@@ -106,8 +111,12 @@ pub fn confine_learn_meta(config: &Config, meta: Option<MemoryMeta>) -> MemoryRe/// # Errors////// A reach outside the caller's root, or what [`ops::recall`] returns.-pub async fn recall(config: &Config, mut params: RecallParams) -> MemoryResult<RecallView> {- params.filter = Some(confine_filter(params.filter, &allowed_reach(config))?);+pub async fn recall(+ config: &Config,+ identity: &MemoryIdentity,+ mut params: RecallParams,+) -> MemoryResult<RecallView> {+ params.filter = Some(confine_filter(params.filter, &allowed_reach(config, identity))?);ops::recall(config, params).await}@@ -116,8 +125,12 @@ pub async fn recall(config: &Config, mut params: RecallParams) -> MemoryResult<R/// # Errors////// A reach outside the caller's root, or what [`ops::fetch`] returns.-pub async fn fetch(config: &Config, mut params: FetchParams) -> MemoryResult<FetchView> {- params.filter = Some(confine_filter(params.filter, &allowed_reach(config))?);+pub async fn fetch(+ config: &Config,+ identity: &MemoryIdentity,+ mut params: FetchParams,+) -> MemoryResult<FetchView> {+ params.filter = Some(confine_filter(params.filter, &allowed_reach(config, identity))?);ops::fetch(config, params).await}@@ -126,8 +139,12 @@ pub async fn fetch(config: &Config, mut params: FetchParams) -> MemoryResult<Fet/// # Errors////// A namespace outside the caller's root, or what [`ops::learn`] returns.-pub async fn learn(config: &Config, mut params: LearnParams) -> MemoryResult<LearnView> {- params.meta = Some(confine_learn_meta(config, params.meta)?);+pub async fn learn(+ config: &Config,+ identity: &MemoryIdentity,+ mut params: LearnParams,+) -> MemoryResult<LearnView> {+ params.meta = Some(confine_learn_meta(config, identity, params.meta)?);ops::learn(config, params, None).await}@@ -137,8 +154,12 @@ pub async fn learn(config: &Config, mut params: LearnParams) -> MemoryResult<Lea/// # Errors////// A reach outside the caller's root, or what [`ops::forget`] returns.-pub async fn forget(config: &Config, mut params: ForgetParams) -> MemoryResult<ForgetView> {- params.reach = Some(confine_reach(params.reach, &allowed_reach(config))?);+pub async fn forget(+ config: &Config,+ identity: &MemoryIdentity,+ mut params: ForgetParams,+) -> MemoryResult<ForgetView> {+ params.reach = Some(confine_reach(params.reach, &allowed_reach(config, identity))?);ops::forget(config, params).await}@@ -151,10 +172,11 @@ pub async fn forget(config: &Config, mut params: ForgetParams) -> MemoryResult<F/// [`ops::items_list`] returns.pub async fn items_list(config: &Config,+ identity: &MemoryIdentity,mut params: ItemsListParams,) -> MemoryResult<ItemsListView> {let narrowed = explore::narrowed(params.filter.take(), ¶ms.path)?;- params.filter = Some(confine_filter(Some(narrowed), &allowed_reach(config))?);+ params.filter = Some(confine_filter(Some(narrowed), &allowed_reach(config, identity))?);params.path = Vec::new();ops::items_list(config, params).await}@@ -165,9 +187,13 @@ pub async fn items_list(////// A reach outside the caller's root, an invalid path, or what/// [`explore::explore`] returns.-pub async fn explore(config: &Config, mut params: ExploreParams) -> MemoryResult<ExplorePage> {+pub async fn explore(+ config: &Config,+ identity: &MemoryIdentity,+ mut params: ExploreParams,+) -> MemoryResult<ExplorePage> {let narrowed = explore::narrowed(params.filter.take(), ¶ms.path)?;- params.filter = Some(confine_filter(Some(narrowed), &allowed_reach(config))?);+ params.filter = Some(confine_filter(Some(narrowed), &allowed_reach(config, identity))?);params.path = Vec::new();explore::explore(config, params).await}@@ -179,8 +205,12 @@ pub async fn explore(config: &Config, mut params: ExploreParams) -> MemoryResult////// A reach outside the caller's root, or what [`explore::items_get`]/// returns.-pub async fn items_get(config: &Config, mut params: ItemsGetParams) -> MemoryResult<ItemsGetView> {- params.reach = Some(confine_reach(params.reach, &allowed_reach(config))?);+pub async fn items_get(+ config: &Config,+ identity: &MemoryIdentity,+ mut params: ItemsGetParams,+) -> MemoryResult<ItemsGetView> {+ params.reach = Some(confine_reach(params.reach, &allowed_reach(config, identity))?);explore::items_get(config, params).await}diff --git a/crates/openhuman-core/src/memory/schemas/handlers.rs b/crates/openhuman-core/src/memory/schemas/handlers.rsindex aaa3b2f0e5..500e5df525 100644--- a/crates/openhuman-core/src/memory/schemas/handlers.rs+++ b/crates/openhuman-core/src/memory/schemas/handlers.rs@@ -75,28 +75,28 @@ pub(super) fn engine_set(params: Map<String, Value>) -> ControllerFuture {pub(super) fn recall(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {let params = parse::<RecallParams>(params)?;- finish(confine::recall(&load().await?, params).await)+ finish(confine::recall(&load().await?, &MemoryIdentity::root(), params).await)})}pub(super) fn fetch(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {let params = parse::<FetchParams>(params)?;- finish(confine::fetch(&load().await?, params).await)+ finish(confine::fetch(&load().await?, &MemoryIdentity::root(), params).await)})}pub(super) fn learn(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {let params = parse::<LearnParams>(params)?;- finish(confine::learn(&load().await?, params).await)+ finish(confine::learn(&load().await?, &MemoryIdentity::root(), params).await)})}pub(super) fn forget(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {let params = parse::<ForgetParams>(params)?;- finish(confine::forget(&load().await?, params).await)+ finish(confine::forget(&load().await?, &MemoryIdentity::root(), params).await)})}@@ -110,21 +110,21 @@ pub(super) fn erase_all(params: Map<String, Value>) -> ControllerFuture {pub(super) fn items_list(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {let params = parse::<ItemsListParams>(params)?;- finish(confine::items_list(&load().await?, params).await)+ finish(confine::items_list(&load().await?, &MemoryIdentity::root(), params).await)})}pub(super) fn explore(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {let params = parse::<ExploreParams>(params)?;- finish(confine::explore(&load().await?, params).await)+ finish(confine::explore(&load().await?, &MemoryIdentity::root(), params).await)})}pub(super) fn items_get(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {let params = parse::<ItemsGetParams>(params)?;- finish(confine::items_get(&load().await?, params).await)+ finish(confine::items_get(&load().await?, &MemoryIdentity::root(), params).await)})}