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): add scoped memory access
Steven Enamakeld269295a158e
diff --git a/crates/openhuman-core/src/memory/mod.rs b/crates/openhuman-core/src/memory/mod.rsindex 37ab131fc8..d1648e8af8 100644--- a/crates/openhuman-core/src/memory/mod.rs+++ b/crates/openhuman-core/src/memory/mod.rs@@ -34,6 +34,7 @@ pub mod guard;pub mod import;pub mod layout_migration;pub mod lifecycle;+pub mod local_root;pub mod ops;pub mod schemas;pub mod scope;diff --git a/crates/openhuman-core/src/memory/scope.rs b/crates/openhuman-core/src/memory/scope.rsindex 46e10ed1b5..49b98dcfbd 100644--- a/crates/openhuman-core/src/memory/scope.rs+++ b/crates/openhuman-core/src/memory/scope.rs@@ -188,35 +188,28 @@ pub fn layout_is_v3(config: &Config) -> bool {}/// The engine scope root of the person `config` belongs to: `user:<id>`-/// for a TinyHumans account (its 24-hex id), `user:local-<digest>` for a-/// local session (hashed, so no device name reaches the engine), and `None`-/// before anyone signs in. Read from where the config lives-/// (`<root>/users/<id>/config.toml`).+/// for a TinyHumans account (its 24-hex id), `user:local-<install id>` for a+/// local session (a random id recorded in the workspace, or the older+/// hostname-derived root an existing install already keeps memory under;+/// see [`super::local_root`]), and `None` before anyone signs in. Read from+/// where the config lives (`<root>/users/<id>/config.toml`).#[must_use]pub fn user_root(config: &Config) -> Option<String> {let dir = config.config_path.parent()?;if dir.parent()?.file_name()? != "users" {return None;}- user_root_for(dir.file_name()?.to_str()?)-}--/// [`user_root`] for the user id `id`.-fn user_root_for(id: &str) -> Option<String> {- use sha2::{Digest, Sha256};+ let id = dir.file_name()?.to_str()?;if id.is_empty() || id == crate::config::PRE_LOGIN_USER_ID {return None;}+ account_root(id).or_else(|| super::local_root::resolve(config, id))+}++/// `user:<id>` when `id` is a TinyHumans account id (24 hex digits).+fn account_root(id: &str) -> Option<String> {let account = id.len() == 24 && id.bytes().all(|b| b.is_ascii_hexdigit());- if account {- return Some(format!("user:{}", id.to_ascii_lowercase()));- }- let digest: String = Sha256::digest(id.as_bytes())- .iter()- .take(8)- .map(|byte| format!("{byte:02x}"))- .collect();- Some(format!("user:local-{digest}"))+ account.then(|| format!("user:{}", id.to_ascii_lowercase()))}/// Switches the memory of the person `config` belongs to to layout v3:diff --git a/crates/openhuman-core/src/memory/scope_tests.rs b/crates/openhuman-core/src/memory/scope_tests.rsindex adb4192aac..9dc9479939 100644--- a/crates/openhuman-core/src/memory/scope_tests.rs+++ b/crates/openhuman-core/src/memory/scope_tests.rs@@ -113,18 +113,31 @@ fn validate_root_accepts_nodes_and_refuses_junk() {}#[test]-fn a_user_root_is_the_account_id_or_a_hashed_local_id() {+fn an_account_root_is_the_lowercased_account_id() {assert_eq!(- user_root_for("6512AB0F6512ab0f6512ab0f").as_deref(),+ account_root("6512AB0F6512ab0f6512ab0f").as_deref(),Some("user:6512ab0f6512ab0f6512ab0f"));- let local = user_root_for("local-megamind-macbook").unwrap();- assert!(local.starts_with("user:local-"), "{local}");- assert_eq!(local.len(), "user:local-".len() + 16);- assert!(!local.contains("megamind"), "no device name: {local}");- assert_eq!(Some(local), user_root_for("local-megamind-macbook"));- assert_eq!(user_root_for(crate::config::PRE_LOGIN_USER_ID), None);- assert_eq!(user_root_for(""), None);+ assert_eq!(account_root("local-megamind-macbook"), None);+ assert_eq!(account_root(""), None);+}++#[test]+fn a_local_session_root_is_a_recorded_install_id_not_the_hostname() {+ let tmp = tempfile::tempdir().unwrap();+ let user_dir = tmp.path().join("users").join("local-megamind-macbook");+ let mut config = Config::default();+ config.config_path = user_dir.join("config.toml");+ config.workspace_dir = user_dir.join("workspace");+ let root = user_root(&config).unwrap();+ assert!(root.starts_with("user:local-"), "{root}");+ assert!(!root.contains("megamind"), "{root}");+ assert_ne!(+ root,+ crate::memory::local_root::legacy_root("local-megamind-macbook"),+ "a fresh install does not derive its root from the hostname"+ );+ assert_eq!(user_root(&config).as_deref(), Some(root.as_str()));}#[test]