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
chore: files changed crates/openhuman-core/Cargo.toml,crates/openhuman-core/src/config/schema/memory
Steven Enamakel4b9004d8bc7a
diff --git a/crates/openhuman-core/Cargo.toml b/crates/openhuman-core/Cargo.tomlindex a4256f45f8..590849ac75 100644--- a/crates/openhuman-core/Cargo.toml+++ b/crates/openhuman-core/Cargo.toml@@ -219,7 +219,7 @@ tinytools-std = { path = "../../vendor/tinyagents/vendor/tinytools/crates/tinytotinymemory-api = { path = "../../vendor/tinymemory/crates/tinymemory-api", features = ["local-safety"] }tinymemory-tools = { path = "../../vendor/tinymemory/crates/tinymemory-tools" }tinyredact = { path = "../../vendor/tinymemory/crates/tinyredact" }-tinymemory-integrations = { path = "../../vendor/tinymemory/crates/tinymemory-integrations", default-features = false, features = ["cortex", "brain", "sources-network", "safety", "legacy-import"] }+tinymemory-integrations = { path = "../../vendor/tinymemory/crates/tinymemory-integrations", default-features = false, features = ["cortex", "brain", "sources-network", "safety", "legacy-import", "schema"] }# tinyconnectors-bus — the OAuth connector wire contract# (https://github.com/tinyhumansai/tinyconnectors). Payload types and member# names for the connector surface, with no transport and no behaviour: thisdiff --git a/crates/openhuman-core/src/config/schema/memory.rs b/crates/openhuman-core/src/config/schema/memory.rsindex 6abe32fc05..15b3fdbe96 100644--- a/crates/openhuman-core/src/config/schema/memory.rs+++ b/crates/openhuman-core/src/config/schema/memory.rs@@ -61,6 +61,7 @@ use std::fmt;use schemars::JsonSchema;use serde::{Deserialize, Deserializer, Serialize};+pub use tinymemory_integrations::sources::{MemorySourceConfig, MemorySourceKind};/// Keychain entry name of the CortexDB API key.pub const MEMORY_CORTEXDB_KEY_NAME: &str = "memory-cortexdb";@@ -337,78 +338,6 @@ impl Default for MemoryRecallConfig {}}-/// What a document source reads. The `composio` kind was removed: a saved-/// entry of that kind is dropped at load.-#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]-#[serde(rename_all = "snake_case")]-pub enum MemorySourceKind {- /// A local directory, walked recursively.- Folder,- /// One local file.- File,- /// One web page.- Link,- /// A GitHub repository (`owner/repo` or URL).- Github,- /// An RSS or Atom feed.- Rss,-}--impl MemorySourceKind {- /// Every kind, in display order.- pub const ALL: [Self; 5] = [- Self::Folder,- Self::File,- Self::Link,- Self::Github,- Self::Rss,- ];-- /// Wire name.- #[must_use]- pub fn as_str(self) -> &'static str {- match self {- Self::Folder => "folder",- Self::File => "file",- Self::Link => "link",- Self::Github => "github",- Self::Rss => "rss",- }- }-- /// Parses a wire name.- #[must_use]- pub fn parse(raw: &str) -> Option<Self> {- Self::ALL- .into_iter()- .find(|kind| kind.as_str().eq_ignore_ascii_case(raw.trim()))- }-}--/// One `[[memory.sources]]` entry: what to read and how often. Sync state-/// (last run, status, item count) is runtime state kept in the workspace,-/// not here.-#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Hash)]-pub struct MemorySourceConfig {- /// Stable id.- pub id: String,- /// What the source reads.- pub kind: MemorySourceKind,- /// Path, URL, `owner/repo` or feed URL.- pub target: String,- /// Display label.- #[serde(default)]- pub label: String,- /// Minutes between scheduled syncs; unset means on demand only.- #[serde(default, skip_serializing_if = "Option::is_none")]- pub schedule_mins: Option<u32>,- /// The layout root the source's documents are filed under- /// (`team:acme`); unset files them under the configured root, shared by- /// every agent there.- #[serde(default, skip_serializing_if = "Option::is_none")]- pub namespace: Option<String>,-}-/// Decodes `[[memory.sources]]` one entry at a time, dropping (and logging)/// any entry this build cannot read rather than failing the whole config.fn deserialize_sources<'de, D>(deserializer: D) -> Result<Vec<MemorySourceConfig>, D::Error>diff --git a/crates/openhuman-core/src/core/runtime/services.rs b/crates/openhuman-core/src/core/runtime/services.rsindex 957b9e32bb..4deaf6f113 100644--- a/crates/openhuman-core/src/core/runtime/services.rs+++ b/crates/openhuman-core/src/core/runtime/services.rs@@ -412,7 +412,6 @@ pub fn start_bootstrap_jobs(services: ServiceSet, config: &Config) {// jobs (idempotent) and mark sources a killed process left `syncing` idle.if plan.memory_jobs {crate::memory::sources::state::reset_interrupted(&config.workspace_dir);- crate::memory::sources::state::remove_orphaned_connector_files(&config.workspace_dir);if let Err(error) = crate::cron::system_jobs::ensure_memory_jobs(config) {log::warn!("[runtime.bootstrap] seeding memory cron jobs failed: {error}");}diff --git a/crates/openhuman-core/src/memory/sources/mod.rs b/crates/openhuman-core/src/memory/sources/mod.rsindex 4632d406e5..faa84edb8b 100644--- a/crates/openhuman-core/src/memory/sources/mod.rs+++ b/crates/openhuman-core/src/memory/sources/mod.rs@@ -11,6 +11,7 @@ pub mod state;mod sync;use tinymemory_tools::ops::MemoryOps;+use tinymemory_integrations::sources::SourceSpec;use crate::config::schema::{MemorySourceConfig, MemorySourceKind};use crate::config::Config;@@ -54,42 +55,10 @@ pub fn list(config: &Config) -> Vec<SourceView> {.collect()}-/// Normalises a target for `kind`: GitHub accepts `owner/repo` or a URL;-/// network kinds must be http(s) URLs.+/// Normalises a target for `kind` using TinyMemory's source rules.pub fn normalize_target(kind: MemorySourceKind, target: &str) -> Result<String> {- let target = target.trim();- if target.is_empty() {- return Err(Error::InvalidRequest("target must not be empty".into()));- }- match kind {- MemorySourceKind::Folder | MemorySourceKind::File => Ok(target.to_string()),- MemorySourceKind::Github => {- if target.starts_with("http://") || target.starts_with("https://") {- return http_url(target);- }- let mut parts = target.split('/');- match (parts.next(), parts.next(), parts.next()) {- (Some(owner), Some(repo), None) if !owner.is_empty() && !repo.is_empty() => {- Ok(format!("https://github.com/{owner}/{repo}"))- }- _ => Err(Error::InvalidRequest(- ("a GitHub target is `owner/repo` or a repository URL").into(),- )),- }- }- MemorySourceKind::Link | MemorySourceKind::Rss => http_url(target),- }-}--fn http_url(target: &str) -> Result<String> {- let url =- url::Url::parse(target).map_err(|_| Error::InvalidRequest("target is not a URL".into()))?;- if !matches!(url.scheme(), "http" | "https") || url.host_str().is_none() {- return Err(Error::InvalidRequest(- ("target must be an http(s) URL").into(),- ));- }- Ok(url.to_string())+ SourceSpec::normalize_target(kind, target)+ .map_err(|error| Error::InvalidRequest(error.to_string()))}/// Builds a new source from `memory_sources_add` params and appends it to@@ -101,38 +70,25 @@ pub fn apply_add(config: &mut Config, params: &SourcesAddParams) -> Result<Memorparams.kind.trim()))})?;- let target = normalize_target(kind, ¶ms.target)?;- if let Some(mins) = params.schedule_mins {- if mins < MIN_SCHEDULE_MINS {- return Err(Error::InvalidRequest(format!(- "schedule_mins must be at least {MIN_SCHEDULE_MINS}"- )));- }- }- if config- .memory- .sources- .iter()- .any(|source| source.kind == kind && source.target == target)- {- return Err(Error::InvalidRequest(- ("that source is already added").into(),- ));- }+ let spec = SourceSpec {+ kind,+ target: params.target.clone(),+ schedule_mins: params.schedule_mins,+ namespace: params.namespace.clone(),+ };+ let target = spec+ .validate_new(&config.memory.sources)+ .map_err(|error| Error::InvalidRequest(error.to_string()))?;let label = params.label.as_deref().map(str::trim).filter(|label| !label.is_empty()).map_or_else(|| target.clone(), str::to_string);- let namespace = match params.namespace.as_deref().map(str::trim) {- None | Some("") => None,- Some(raw) => Some(- raw.parse::<tinymemory_api::Namespace>()- .map_err(|error| Error::InvalidRequest(error.to_string()))?- .to_string(),- ),- };+ let namespace = spec+ .namespace()+ .map_err(|error| Error::InvalidRequest(error.to_string()))?+ .map(|namespace| namespace.to_string());let source = MemorySourceConfig {id: format!("src-{}", uuid::Uuid::new_v4().simple()),kind,diff --git a/crates/openhuman-core/src/memory/sources/state.rs b/crates/openhuman-core/src/memory/sources/state.rsindex 6b9d15f698..a5fa55adbd 100644--- a/crates/openhuman-core/src/memory/sources/state.rs+++ b/crates/openhuman-core/src/memory/sources/state.rs@@ -111,31 +111,6 @@ pub fn reset_interrupted(workspace_dir: &Path) {}}-/// Files the removed Composio memory sync kept beside the source state.-const ORPHANED_CONNECTOR_FILES: [&str; 2] = ["connector_items.json", "connection_roots.json"];--/// Best-effort removal of the files the removed Composio memory sync left in-/// `<workspace>/memory/`. Nothing reads them any more; a failure is logged-/// and ignored.-pub fn remove_orphaned_connector_files(workspace_dir: &Path) {- let dir = workspace_dir.join("memory");- for name in ORPHANED_CONNECTOR_FILES {- let path = dir.join(name);- match std::fs::remove_file(&path) {- Ok(()) => tracing::debug!(- file = name,- "[memory:sources] removed orphaned connector file"- ),- Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}- Err(error) => tracing::debug!(- file = name,- %error,- "[memory:sources] could not remove orphaned connector file"- ),- }- }-}-#[cfg(test)]#[path = "state_tests.rs"]mod tests;diff --git a/crates/openhuman-core/src/memory/sources/sync.rs b/crates/openhuman-core/src/memory/sources/sync.rsindex 5c9b3c37d8..dd6cc50036 100644--- a/crates/openhuman-core/src/memory/sources/sync.rs+++ b/crates/openhuman-core/src/memory/sources/sync.rs@@ -152,9 +152,8 @@ async fn run(config: &Config, source: &MemorySourceConfig) -> std::result::Resul.await}-/// Files `items` into `layout`'s brain, each under the brain source it-/// belongs to (`memory::brain::brain_node`), stores them through the module,-/// and queues one belief build per node touched. Returns how many were stored.+/// Uses the module to file `items` into `layout`'s brain, and queues its+/// belief-build jobs. Returns how many were stored.pub(crate) async fn place_and_store(config: &Config,bound: &engine::BoundEngine,@@ -163,30 +162,15 @@ pub(crate) async fn place_and_store(layout: &tinymemory_tools::MemoryLayout,) -> std::result::Result<u64, SyncError> {let brain_source = crate::memory::brain::brain_source(kind);- // Placing an item under its brain node is pure, so every one is placed up- // front: the module stores `(node, item)` pairs and reports the nodes hit.- let mut placed = Vec::with_capacity(items.len());- for item in items {- let node = crate::memory::brain::brain_node(config, layout, &brain_source, &item)- .map_err(|error| SyncError::Invalid(error.to_string()))?;- let item = tinymemory_tools::layout::placement::file_into(node.clone(), item);- placed.push((node, item));- }- let stored = module::store_all(bound.engine.as_ref(), source_id, placed).await?;- // An engine that rebuilds beliefs on its own needs no build job.- let automatic =- bound.engine.descriptor().consolidation == tinymemory_api::Consolidation::Automatic;- let jobs = stored- .touched- .into_iter()- .filter(|_| !automatic)- .map(|node| tinymemory_tools::BackgroundJob::BuildBeliefs {- request: tinymemory_api::ConsolidateRequest::new(tinymemory_api::Reach::exact(node))- .kinds([tinymemory_api::ItemKind::Document]),- })- .collect();- crate::memory::lifecycle::jobs::enqueue(config, layout.root(), jobs).await;- Ok(stored.stored)+ let placed = module::store_placed(+ bound.engine.as_ref(),+ source_id,+ items,+ |item| crate::memory::brain::brain_node(config, layout, &brain_source, item),+ )+ .await?;+ crate::memory::lifecycle::jobs::enqueue(config, layout.root(), placed.jobs).await;+ Ok(placed.stored.stored)}/// `memory_sources_sync`: starts a background sync of source `id`, or ofdiff --git a/crates/openhuman-core/src/memory/sources/sync_tests.rs b/crates/openhuman-core/src/memory/sources/sync_tests.rsindex 23712a75c4..e1e81812bf 100644--- a/crates/openhuman-core/src/memory/sources/sync_tests.rs+++ b/crates/openhuman-core/src/memory/sources/sync_tests.rs@@ -394,20 +394,3 @@ async fn github_files_per_repository_only_when_switched_on() {);}-#[test]-fn orphaned_connector_files_are_removed_and_missing_ones_ignored() {- let tmp = tempfile::tempdir().unwrap();- let dir = tmp.path().join("memory");- std::fs::create_dir_all(&dir).unwrap();- std::fs::write(dir.join("connector_items.json"), "{}").unwrap();- std::fs::write(dir.join("connection_roots.json"), "{}").unwrap();- std::fs::write(dir.join("sources_state.json"), "{}").unwrap();- state::remove_orphaned_connector_files(tmp.path());- assert!(!dir.join("connector_items.json").exists());- assert!(!dir.join("connection_roots.json").exists());- assert!(- dir.join("sources_state.json").exists(),- "live state is kept"- );- state::remove_orphaned_connector_files(tmp.path());-}