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
refactor(memory): split memory module into focused submodules
Steven Enamakel74dd8589b7c5
diff --git a/crates/openhuman-core/src/memory/channels.rs b/crates/openhuman-core/src/memory/channels.rsindex a31dad6231..8d25b8e8eb 100644--- a/crates/openhuman-core/src/memory/channels.rs+++ b/crates/openhuman-core/src/memory/channels.rs@@ -33,13 +33,9 @@ fn read(workspace_dir: &Path) -> BTreeMap<String, BTreeSet<String>> {fn write(workspace_dir: &Path, all: &BTreeMap<String, BTreeSet<String>>) {let file = path(workspace_dir);- let result = file- .parent()- .map_or(Ok(()), std::fs::create_dir_all)- .and_then(|()| {- let json = serde_json::to_vec_pretty(all).map_err(std::io::Error::other)?;- std::fs::write(&file, json)- });+ let result = serde_json::to_vec_pretty(all)+ .map_err(std::io::Error::other)+ .and_then(|json| crate::memory::files::write_private(&file, &json));if let Err(error) = result {tracing::warn!(%error, "[memory:channels] writing channel threads failed");}diff --git a/crates/openhuman-core/src/memory/layout_migration/state.rs b/crates/openhuman-core/src/memory/layout_migration/state.rsindex 6e3f496451..06a0c8b779 100644--- a/crates/openhuman-core/src/memory/layout_migration/state.rs+++ b/crates/openhuman-core/src/memory/layout_migration/state.rs@@ -121,11 +121,11 @@ pub fn save(workspace_dir: &Path, state: &MigrationState) -> MemoryResult<()> {let file = path(workspace_dir);let write = || -> std::io::Result<()> {if let Some(dir) = file.parent() {- std::fs::create_dir_all(dir)?;+ crate::memory::files::create_private_dir_all(dir)?;}let temp = file.with_extension("json.tmp");let bytes = serde_json::to_vec_pretty(state).map_err(std::io::Error::other)?;- let mut out = std::fs::File::create(&temp)?;+ let mut out = crate::memory::files::create_private(&temp)?;std::io::Write::write_all(&mut out, &bytes)?;out.sync_all()?;std::fs::rename(&temp, &file)diff --git a/crates/openhuman-core/src/memory/lifecycle/jobs.rs b/crates/openhuman-core/src/memory/lifecycle/jobs.rsindex 4521a6be6f..e96f76f898 100644--- a/crates/openhuman-core/src/memory/lifecycle/jobs.rs+++ b/crates/openhuman-core/src/memory/lifecycle/jobs.rs@@ -109,13 +109,9 @@ fn read(workspace_dir: &Path) -> JobQueue {fn write(workspace_dir: &Path, queue: &JobQueue) {let file = path(workspace_dir);- let result = file- .parent()- .map_or(Ok(()), std::fs::create_dir_all)- .and_then(|()| {- let json = serde_json::to_vec_pretty(queue).map_err(std::io::Error::other)?;- std::fs::write(&file, json)- });+ let result = serde_json::to_vec_pretty(queue)+ .map_err(std::io::Error::other)+ .and_then(|json| crate::memory::files::write_private(&file, &json));if let Err(error) = result {tracing::warn!(%error, "[memory:jobs] writing the job queue failed");}diff --git a/crates/openhuman-core/src/memory/mod.rs b/crates/openhuman-core/src/memory/mod.rsindex 2b90c191f4..37ab131fc8 100644--- a/crates/openhuman-core/src/memory/mod.rs+++ b/crates/openhuman-core/src/memory/mod.rs@@ -29,6 +29,7 @@ pub(crate) mod convert;pub mod engine;pub mod error;pub mod explore;+pub(crate) mod files;pub mod guard;pub mod import;pub mod layout_migration;diff --git a/crates/openhuman-core/src/memory/sources/roots.rs b/crates/openhuman-core/src/memory/sources/roots.rsindex 0d9da66897..e4056bb12f 100644--- a/crates/openhuman-core/src/memory/sources/roots.rs+++ b/crates/openhuman-core/src/memory/sources/roots.rs@@ -49,10 +49,10 @@ fn save(workspace_dir: &Path, all: &Roots) -> std::io::Result<()> {let file = path(workspace_dir);let temp = file.with_extension("json.tmp");if let Some(parent) = file.parent() {- std::fs::create_dir_all(parent)?;+ crate::memory::files::create_private_dir_all(parent)?;}let json = serde_json::to_vec_pretty(all).map_err(std::io::Error::other)?;- let mut out = std::fs::File::create(&temp)?;+ let mut out = crate::memory::files::create_private(&temp)?;std::io::Write::write_all(&mut out, &json)?;// On disk before it replaces the old file, so a power loss cannot// leave a renamed file with unwritten contents.diff --git a/crates/openhuman-core/src/memory/sources/state.rs b/crates/openhuman-core/src/memory/sources/state.rsindex b17e2cd6cd..bcc3b9fcfd 100644--- a/crates/openhuman-core/src/memory/sources/state.rs+++ b/crates/openhuman-core/src/memory/sources/state.rs@@ -47,13 +47,9 @@ fn read_all(workspace_dir: &Path) -> BTreeMap<String, SourceState> {fn write_all(workspace_dir: &Path, all: &BTreeMap<String, SourceState>) {let file = path(workspace_dir);- let result = file- .parent()- .map_or(Ok(()), std::fs::create_dir_all)- .and_then(|()| {- let json = serde_json::to_vec_pretty(all).map_err(std::io::Error::other)?;- std::fs::write(&file, json)- });+ let result = serde_json::to_vec_pretty(all)+ .map_err(std::io::Error::other)+ .and_then(|json| crate::memory::files::write_private(&file, &json));if let Err(error) = result {tracing::warn!(error = %error, "[memory:sources] writing sync state failed");}diff --git a/crates/openhuman-core/src/memory/sources/versions.rs b/crates/openhuman-core/src/memory/sources/versions.rsindex 9ecbdc26fc..7ae0044b86 100644--- a/crates/openhuman-core/src/memory/sources/versions.rs+++ b/crates/openhuman-core/src/memory/sources/versions.rs@@ -87,10 +87,10 @@ fn save(workspace_dir: &Path, versions: &Versions) -> bool {let temp = file.with_extension("json.tmp");let result = file.parent()- .map_or(Ok(()), std::fs::create_dir_all)+ .map_or(Ok(()), crate::memory::files::create_private_dir_all).and_then(|()| {let json = serde_json::to_vec(versions).map_err(std::io::Error::other)?;- std::fs::write(&temp, json)?;+ crate::memory::files::write_private(&temp, &json)?;std::fs::rename(&temp, &file)});if let Err(error) = &result {