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(storage): add document store import and snapshot support
Steven Enamakelfd4bfafc8b1e
diff --git a/crates/openhuman-core/src/desktop/notifications/mod.rs b/crates/openhuman-core/src/desktop/notifications/mod.rsindex 320ff86251..2ebb8067b4 100644--- a/crates/openhuman-core/src/desktop/notifications/mod.rs+++ b/crates/openhuman-core/src/desktop/notifications/mod.rs@@ -27,6 +27,7 @@ pub mod rpc;pub mod schemas;pub mod store;mod store_documents;+pub(crate) use store_documents::import_source;pub mod types;pub use bus::{diff --git a/crates/openhuman-core/src/desktop/notifications/store_documents.rs b/crates/openhuman-core/src/desktop/notifications/store_documents.rsindex a7a5c26280..559d4d4df7 100644--- a/crates/openhuman-core/src/desktop/notifications/store_documents.rs+++ b/crates/openhuman-core/src/desktop/notifications/store_documents.rs@@ -57,6 +57,38 @@ const DOMAIN: &str = "notifications::store";/// How long identical content counts as a duplicate.const DEDUP_WINDOW_SECS: i64 = 60;+/// The legacy `notifications.db`, as the storage importer reads it.+///+/// Core notifications are keyed by workspace. The legacy table and the old+/// per-file default both used the fixed [`LOCAL_WORKSPACE`] key; an installed+/// backend may serve several workspaces, so they are re-filed under the real+/// workspace's key, exactly as [`current`] does for new records.+pub(crate) fn import_source() -> crate::storage::import::Source {+ crate::storage::import::Source {+ domain: "notifications",+ db: "notifications/notifications.db",+ collections,+ read_legacy: |scratch, real| {+ super::store::import::read_for(scratch, &workspace_key(&real.workspace_dir))+ },+ rekey: |mut record, config| {+ if record.collection != CORE {+ return record;+ }+ let prefix = core_id(LOCAL_WORKSPACE, "");+ let Some(event_id) = record.id.strip_prefix(&prefix) else {+ return record;+ };+ let workspace = workspace_key(&config.workspace_dir);+ record.id = core_id(&workspace, event_id);+ if let Some(doc) = record.doc.as_object_mut() {+ doc.insert("workspace".into(), serde_json::json!(workspace));+ }+ record+ },+ }+}+fn collections() -> Vec<CollectionSpec> {vec![CollectionSpec::new(NOTIFICATIONS)diff --git a/crates/openhuman-core/src/desktop/notifications/store_import.rs b/crates/openhuman-core/src/desktop/notifications/store_import.rsindex 0b8db94eae..8e53d5bab8 100644--- a/crates/openhuman-core/src/desktop/notifications/store_import.rs+++ b/crates/openhuman-core/src/desktop/notifications/store_import.rs@@ -34,7 +34,13 @@ pub(crate) const TABLES: &[&str] = &[/// Reads every legacy row.pub(crate) fn read(config: &Config) -> Result<Vec<ImportDoc>> {- super::with_connection(config, |conn| read_rows(conn, LOCAL_WORKSPACE))+ read_for(config, LOCAL_WORKSPACE)+}++/// [`read`] with core notifications filed under `workspace` instead of the+/// fixed local key.+pub(crate) fn read_for(config: &Config, workspace: &str) -> Result<Vec<ImportDoc>> {+ super::with_connection(config, |conn| read_rows(conn, workspace))}fn read_rows(conn: &Connection, workspace: &str) -> Result<Vec<ImportDoc>> {diff --git a/crates/openhuman-core/src/integrations/task_sources/mod.rs b/crates/openhuman-core/src/integrations/task_sources/mod.rsindex 08cc1ec252..f9221305cd 100644--- a/crates/openhuman-core/src/integrations/task_sources/mod.rs+++ b/crates/openhuman-core/src/integrations/task_sources/mod.rs@@ -25,6 +25,7 @@ pub mod route;mod schemas;pub mod store;mod store_documents;+pub(crate) use store_documents::import_source;pub mod tools;pub mod types;diff --git a/crates/openhuman-core/src/integrations/task_sources/store_documents.rs b/crates/openhuman-core/src/integrations/task_sources/store_documents.rsindex 5f23be7eb6..fd1b7c6d59 100644--- a/crates/openhuman-core/src/integrations/task_sources/store_documents.rs+++ b/crates/openhuman-core/src/integrations/task_sources/store_documents.rs@@ -36,6 +36,17 @@ pub(super) const SOURCES: &str = "task_sources";pub(super) const INGESTED: &str = "ingested_tasks";const DOMAIN: &str = "task_sources::store";+/// The legacy `sources.db`, as the storage importer reads it.+pub(crate) fn import_source() -> crate::storage::import::Source {+ crate::storage::import::Source {+ domain: "task_sources",+ db: "task_sources/sources.db",+ collections,+ read_legacy: |scratch, _real| super::store::import::read(scratch),+ rekey: |record, _config| record,+ }+}+fn collections() -> Vec<CollectionSpec> {vec![CollectionSpec::new(SOURCES).index(IndexSpec::new("by_created", ["created_ms"])),diff --git a/crates/openhuman-core/src/security/approval/mod.rs b/crates/openhuman-core/src/security/approval/mod.rsindex b3cb6840ed..35756c0f35 100644--- a/crates/openhuman-core/src/security/approval/mod.rs+++ b/crates/openhuman-core/src/security/approval/mod.rs@@ -22,6 +22,7 @@ pub mod rpc;pub mod schemas;pub mod store;mod store_documents;+pub(crate) use store_documents::import_source;pub mod types;pub use gate::{diff --git a/crates/openhuman-core/src/security/approval/store_documents.rs b/crates/openhuman-core/src/security/approval/store_documents.rsindex be26419a35..c69d93fffd 100644--- a/crates/openhuman-core/src/security/approval/store_documents.rs+++ b/crates/openhuman-core/src/security/approval/store_documents.rs@@ -71,6 +71,17 @@ pub(super) fn current(config: &Config) -> Result<Option<Docs>> {Ok(Some(Docs::new(&opened.scoped()?)))}+/// The legacy `approval.db`, as the storage importer reads it.+pub(crate) fn import_source() -> crate::storage::import::Source {+ crate::storage::import::Source {+ domain: "approval",+ db: "approval/approval.db",+ collections,+ read_legacy: |scratch, _real| super::store::import::read(scratch),+ rekey: |record, _config| record,+ }+}+/// The collections the approval store keeps.pub(super) fn collections() -> Vec<CollectionSpec> {vec![diff --git a/crates/openhuman-core/src/security/devices/mod.rs b/crates/openhuman-core/src/security/devices/mod.rsindex 0f0f85409b..f0b670bd91 100644--- a/crates/openhuman-core/src/security/devices/mod.rs+++ b/crates/openhuman-core/src/security/devices/mod.rs@@ -10,6 +10,7 @@ pub mod rpc;pub mod schemas;pub mod store;mod store_documents;+pub(crate) use store_documents::import_source;pub mod tunnel_client;pub mod types;diff --git a/crates/openhuman-core/src/security/devices/store_documents.rs b/crates/openhuman-core/src/security/devices/store_documents.rsindex 2f2ea65e7e..0dc79dfdc2 100644--- a/crates/openhuman-core/src/security/devices/store_documents.rs+++ b/crates/openhuman-core/src/security/devices/store_documents.rs@@ -24,6 +24,17 @@ use crate::storage::DocumentStoreExt;pub(super) const DEVICES: &str = "paired_devices";const DOMAIN: &str = "devices::store";+/// The legacy `devices.db`, as the storage importer reads it.+pub(crate) fn import_source() -> crate::storage::import::Source {+ crate::storage::import::Source {+ domain: "devices",+ db: "devices/devices.db",+ collections,+ read_legacy: |scratch, _real| super::store::import::read(scratch),+ rekey: |record, _config| record,+ }+}+fn collections() -> Vec<CollectionSpec> {vec![CollectionSpec::new(DEVICES).index(IndexSpec::new("by_active", ["revoked", "created_at"]))]}diff --git a/crates/openhuman-core/src/storage/import/snapshot.rs b/crates/openhuman-core/src/storage/import/snapshot.rsindex 701fdeafc0..82434f4ca3 100644--- a/crates/openhuman-core/src/storage/import/snapshot.rs+++ b/crates/openhuman-core/src/storage/import/snapshot.rs@@ -42,10 +42,10 @@ impl Snapshot {}std::fs::copy(source, &db).with_context(|| format!("copy {}", source.display()))?;for suffix in ["-wal", "-shm"] {- let companion = companion(source, suffix);- if companion.is_file() {- std::fs::copy(&companion, companion(&db, suffix))- .with_context(|| format!("copy {}", companion.display()))?;+ let extra = companion(source, suffix);+ if extra.is_file() {+ std::fs::copy(&extra, companion(&db, suffix))+ .with_context(|| format!("copy {}", extra.display()))?;}}Ok(Self { dir, db })diff --git a/crates/openhuman-core/src/storage/mod.rs b/crates/openhuman-core/src/storage/mod.rsindex 99c320a786..e126aeef1f 100644--- a/crates/openhuman-core/src/storage/mod.rs+++ b/crates/openhuman-core/src/storage/mod.rs@@ -26,6 +26,7 @@ pub mod config;pub mod documents;pub mod fence;pub mod fenced_backend;+pub mod import;pub mod lease;mod lease_documents;mod lease_local;