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 importers for tinybox, tinyconnectors, tinyjuice, tinymcp, and tinywallet
Steven Enamakel56c7ddc37029
diff --git a/crates/openhuman-core/src/modules/mod.rs b/crates/openhuman-core/src/modules/mod.rsindex 75b5a1e37a..096fe118c6 100644--- a/crates/openhuman-core/src/modules/mod.rs+++ b/crates/openhuman-core/src/modules/mod.rs@@ -170,14 +170,17 @@ pub use types::{LoadPolicy, ModuleRecord, ModuleSource, ModuleState, ModuleStatu/// Imports tinymcp's legacy SQLite files under `data_dir` into the module's/// storage, once per directory. Never fails the caller: an error is logged and/// the import is retried at the next open.-pub async fn import_legacy_mcp(data_dir: &std::path::Path) {+pub async fn import_legacy_mcp(+ ctx: &crate::core::runtime::DispatchCtx,+ data_dir: &std::path::Path,+) {#[cfg(feature = "modules")]- match storage_import_tinymcp::import_legacy(data_dir).await {+ match storage_import_tinymcp::import_legacy(ctx, data_dir).await {Ok(outcome) => log::debug!("[mcp] legacy storage import: {outcome:?}"),Err(error) => log::warn!("[mcp] legacy storage import failed, will retry: {error:#}"),}#[cfg(not(feature = "modules"))]- let _ = data_dir;+ let _ = (ctx, data_dir);}/// What an importer's outcome says about whether it may be skipped next time.@@ -228,6 +231,7 @@ fn imported_once() -> &'static ImportedSet {/// finishes, so a cancelled caller leaves nothing behind.#[cfg(feature = "modules")]async fn import_once<F, T>(+ ctx: &crate::core::runtime::DispatchCtx,kind: &'static str,module_id: &str,dir: &std::path::Path,@@ -237,7 +241,7 @@ whereF: std::future::Future<Output = anyhow::Result<T>>,T: std::fmt::Debug + Settled,{- let scope = match storage_host::current_module_scope(&crate::core::runtime::DispatchCtx::ambient(), module_id) {+ let scope = match storage_host::current_module_scope(ctx, module_id) {Ok(scope) => format!("{scope:?}"),Err(error) => {log::warn!("[{kind}] legacy storage import skipped: {:?}", error.kind());diff --git a/crates/openhuman-core/src/modules/storage_import_tinybox.rs b/crates/openhuman-core/src/modules/storage_import_tinybox.rsindex c6ddc49f5a..2706f9ada9 100644--- a/crates/openhuman-core/src/modules/storage_import_tinybox.rs+++ b/crates/openhuman-core/src/modules/storage_import_tinybox.rs@@ -26,6 +26,7 @@ use serde_json::{json, Value};use tinystoragedrivers::{CollectionSpec, ScopedStorage};use super::storage_grant_tinybox::{JAIL_INDEX_COLLECTION, MODULE_ID};+use crate::core::runtime::DispatchCtx;use super::storage_import_support as support;const LOG_PREFIX: &str = "[tinybox-import]";diff --git a/crates/openhuman-core/src/modules/storage_import_tinyconnectors.rs b/crates/openhuman-core/src/modules/storage_import_tinyconnectors.rsindex ffee50a4a8..5a9193d8a1 100644--- a/crates/openhuman-core/src/modules/storage_import_tinyconnectors.rs+++ b/crates/openhuman-core/src/modules/storage_import_tinyconnectors.rs@@ -27,6 +27,7 @@ use serde_json::{json, Value};use tinystoragedrivers::{CollectionSpec, ScopedStorage};use super::storage_grant_tinyconnectors::{MODULE_ID, PREFS_COLLECTION, TRIGGER_STREAM_PREFIX};+use crate::core::runtime::DispatchCtx;use super::storage_import_support as support;const LOG_PREFIX: &str = "[connectors-import]";diff --git a/crates/openhuman-core/src/modules/storage_import_tinyconnectors_tests.rs b/crates/openhuman-core/src/modules/storage_import_tinyconnectors_tests.rsindex 69f809db19..3e95b8bf42 100644--- a/crates/openhuman-core/src/modules/storage_import_tinyconnectors_tests.rs+++ b/crates/openhuman-core/src/modules/storage_import_tinyconnectors_tests.rs@@ -70,7 +70,7 @@ fn tree_digest(root: &Path) -> Vec<(String, Vec<u8>)> {async fn preferences_and_the_trigger_archive_move_into_the_modules_storage() {let legacy = legacy_state();let scoped = scoped();- let outcome = import_into(&scoped, legacy.path()).await.unwrap();+ let outcome = import_into(&DispatchCtx::host_default(), &scoped, legacy.path()).await.unwrap();// gmail + slack; the corrupt preference, the non-day archive name and the// unparsable archive line are skipped.assert_eq!(@@ -117,7 +117,7 @@ async fn preferences_and_the_trigger_archive_move_into_the_modules_storage() {async fn the_legacy_files_are_left_untouched() {let legacy = legacy_state();let before = tree_digest(legacy.path());- import_into(&scoped(), legacy.path()).await.unwrap();+ import_into(&DispatchCtx::host_default(), &scoped(), legacy.path()).await.unwrap();assert_eq!(tree_digest(legacy.path()), before);}@@ -125,7 +125,7 @@ async fn the_legacy_files_are_left_untouched() {async fn a_second_run_is_a_noop_even_after_the_module_changed_the_data() {let legacy = legacy_state();let scoped = scoped();- import_into(&scoped, legacy.path()).await.unwrap();+ import_into(&DispatchCtx::host_default(), &scoped, legacy.path()).await.unwrap();// The user later deletes a preference; the untouched file must not bring// it back.scoped@@ -134,7 +134,7 @@ async fn a_second_run_is_a_noop_even_after_the_module_changed_the_data() {.await.unwrap();assert_eq!(- import_into(&scoped, legacy.path()).await.unwrap(),+ import_into(&DispatchCtx::host_default(), &scoped, legacy.path()).await.unwrap(),Outcome::AlreadyDone);assert!(scoped@@ -165,7 +165,7 @@ async fn records_the_module_already_wrote_are_never_replaced_or_duplicated() {.await.unwrap();- let outcome = import_into(&scoped, legacy.path()).await.unwrap();+ let outcome = import_into(&DispatchCtx::host_default(), &scoped, legacy.path()).await.unwrap();assert_eq!(outcome,Outcome::Imported {@@ -195,13 +195,13 @@ async fn a_state_directory_without_legacy_files_writes_no_marker() {let empty = tempfile::tempdir().unwrap();let scoped = scoped();assert_eq!(- import_into(&scoped, empty.path()).await.unwrap(),+ import_into(&DispatchCtx::host_default(), &scoped, empty.path()).await.unwrap(),Outcome::NoSource);// Files that show up later (an older build still running) are still taken.let legacy = legacy_state();assert!(matches!(- import_into(&scoped, legacy.path()).await.unwrap(),+ import_into(&DispatchCtx::host_default(), &scoped, legacy.path()).await.unwrap(),Outcome::Imported { .. }));}@@ -216,7 +216,7 @@ async fn an_unreadable_preference_file_is_retried_instead_of_marked_done() {).unwrap();let scoped = scoped();- assert!(import_into(&scoped, legacy.path()).await.is_err());+ assert!(import_into(&DispatchCtx::host_default(), &scoped, legacy.path()).await.is_err());assert!(scoped.documents().get(PREFS_COLLECTION, "gmail")@@ -226,7 +226,7 @@ async fn an_unreadable_preference_file_is_retried_instead_of_marked_done() {std::fs::remove_file(legacy.path().join(PREFS_DIR).join("bad.json")).unwrap();assert!(matches!(- import_into(&scoped, legacy.path()).await.unwrap(),+ import_into(&DispatchCtx::host_default(), &scoped, legacy.path()).await.unwrap(),Outcome::Imported { prefs: 2, .. }));}diff --git a/crates/openhuman-core/src/modules/storage_import_tinyjuice.rs b/crates/openhuman-core/src/modules/storage_import_tinyjuice.rsindex d011e76f70..178a8b1fec 100644--- a/crates/openhuman-core/src/modules/storage_import_tinyjuice.rs+++ b/crates/openhuman-core/src/modules/storage_import_tinyjuice.rs@@ -28,6 +28,7 @@ use serde_json::json;use tinystoragedrivers::{Capability, ScopedStorage};use super::storage_grant_tinyjuice::{CCR_BLOB_PREFIX, MODULE_ID};+use crate::core::runtime::DispatchCtx;use super::storage_import_support as support;const LOG_PREFIX: &str = "[tinyjuice-import]";diff --git a/crates/openhuman-core/src/modules/storage_import_tinyjuice_tests.rs b/crates/openhuman-core/src/modules/storage_import_tinyjuice_tests.rsindex 0df458643f..442d24a4fc 100644--- a/crates/openhuman-core/src/modules/storage_import_tinyjuice_tests.rs+++ b/crates/openhuman-core/src/modules/storage_import_tinyjuice_tests.rs@@ -49,7 +49,7 @@ async fn read(scoped: &ScopedStorage, token: &str) -> Option<String> {async fn originals_within_their_ttl_move_into_the_modules_blobs() {let legacy = legacy_root();let scoped = scoped();- let outcome = import_into(+ let outcome = import_into(&DispatchCtx::host_default(),&scoped,legacy.path(),Some(Duration::from_secs(3600)),@@ -83,7 +83,7 @@ async fn originals_within_their_ttl_move_into_the_modules_blobs() {async fn without_a_ttl_every_readable_original_is_kept() {let legacy = legacy_root();let scoped = scoped();- let outcome = import_into(&scoped, legacy.path(), None, SystemTime::now())+ let outcome = import_into(&DispatchCtx::host_default(), &scoped, legacy.path(), None, SystemTime::now()).await.unwrap();assert_eq!(@@ -100,7 +100,7 @@ async fn without_a_ttl_every_readable_original_is_kept() {#[tokio::test]async fn the_legacy_files_are_left_in_place() {let legacy = legacy_root();- import_into(&scoped(), legacy.path(), None, SystemTime::now())+ import_into(&DispatchCtx::host_default(), &scoped(), legacy.path(), None, SystemTime::now()).await.unwrap();assert_eq!(@@ -123,7 +123,7 @@ async fn a_second_run_is_a_noop_and_a_blob_already_stored_is_kept() {).await.unwrap();- let first = import_into(&scoped, legacy.path(), None, SystemTime::now())+ let first = import_into(&DispatchCtx::host_default(), &scoped, legacy.path(), None, SystemTime::now()).await.unwrap();assert_eq!(@@ -139,7 +139,7 @@ async fn a_second_run_is_a_noop_and_a_blob_already_stored_is_kept() {Some("written by the module"));assert_eq!(- import_into(&scoped, legacy.path(), None, SystemTime::now())+ import_into(&DispatchCtx::host_default(), &scoped, legacy.path(), None, SystemTime::now()).await.unwrap(),Outcome::AlreadyDone@@ -152,7 +152,7 @@ async fn a_missing_directory_writes_no_marker() {let missing = dir.path().join("ccr");let scoped = scoped();assert_eq!(- import_into(&scoped, &missing, None, SystemTime::now())+ import_into(&DispatchCtx::host_default(), &scoped, &missing, None, SystemTime::now()).await.unwrap(),Outcome::NoSource@@ -160,7 +160,7 @@ async fn a_missing_directory_writes_no_marker() {std::fs::create_dir(&missing).unwrap();std::fs::write(missing.join(FRESH), "late").unwrap();assert!(matches!(- import_into(&scoped, &missing, None, SystemTime::now())+ import_into(&DispatchCtx::host_default(), &scoped, &missing, None, SystemTime::now()).await.unwrap(),Outcome::Imported { imported: 1, .. }@@ -188,7 +188,7 @@ async fn a_symlinked_token_is_never_followed_into_storage() {let dir = tempfile::tempdir().unwrap();std::os::unix::fs::symlink(outside.path().join("secret"), dir.path().join(FRESH)).unwrap();let scoped = scoped();- let outcome = import_into(&scoped, dir.path(), None, SystemTime::now())+ let outcome = import_into(&DispatchCtx::host_default(), &scoped, dir.path(), None, SystemTime::now()).await.unwrap();assert!(matches!(diff --git a/crates/openhuman-core/src/modules/storage_import_tinymcp.rs b/crates/openhuman-core/src/modules/storage_import_tinymcp.rsindex 9f3e66f069..e86d31e211 100644--- a/crates/openhuman-core/src/modules/storage_import_tinymcp.rs+++ b/crates/openhuman-core/src/modules/storage_import_tinymcp.rs@@ -35,6 +35,7 @@ use sha2::Digest;use tinystoragedrivers::secrets::{DocumentSecrets, SecretStore};use tinystoragedrivers::{CollectionSpec, DocumentStore, ErrorKind, Precondition, ScopedStorage};+use crate::core::runtime::DispatchCtx;use crate::storage::rusqlite::{self, Connection, OpenFlags};const LOG_PREFIX: &str = "[mcp-import]";diff --git a/crates/openhuman-core/src/modules/storage_import_tinymcp_tests.rs b/crates/openhuman-core/src/modules/storage_import_tinymcp_tests.rsindex d43da434e4..2f413b9291 100644--- a/crates/openhuman-core/src/modules/storage_import_tinymcp_tests.rs+++ b/crates/openhuman-core/src/modules/storage_import_tinymcp_tests.rs@@ -77,7 +77,7 @@ fn digest(path: &Path) -> Vec<u8> {async fn servers_env_and_audit_rows_move_into_the_modules_storage() {let legacy = legacy_dir();let rig = rig();- let outcome = import_into(&rig.scoped, &rig.secrets, legacy.path())+ let outcome = import_into(&DispatchCtx::host_default(), &rig.scoped, &rig.secrets, legacy.path()).await.unwrap();assert_eq!(@@ -141,7 +141,7 @@ async fn servers_env_and_audit_rows_move_into_the_modules_storage() {async fn the_import_runs_once_and_never_resurrects_a_deleted_server() {let legacy = legacy_dir();let rig = rig();- import_into(&rig.scoped, &rig.secrets, legacy.path())+ import_into(&DispatchCtx::host_default(), &rig.scoped, &rig.secrets, legacy.path()).await.unwrap();let docs = rig.scoped.documents();@@ -150,7 +150,7 @@ async fn the_import_runs_once_and_never_resurrects_a_deleted_server() {.await.unwrap();- let again = import_into(&rig.scoped, &rig.secrets, legacy.path())+ let again = import_into(&DispatchCtx::host_default(), &rig.scoped, &rig.secrets, legacy.path()).await.unwrap();assert_eq!(again, Outcome::AlreadyDone);@@ -167,7 +167,7 @@ async fn the_legacy_files_are_left_untouched() {let legacy = legacy_dir();let before = [CLIENTS_DB, AUDIT_DB].map(|path| digest(&legacy.path().join(path)));let rig = rig();- import_into(&rig.scoped, &rig.secrets, legacy.path())+ import_into(&DispatchCtx::host_default(), &rig.scoped, &rig.secrets, legacy.path()).await.unwrap();let after = [CLIENTS_DB, AUDIT_DB].map(|path| digest(&legacy.path().join(path)));@@ -199,7 +199,7 @@ async fn a_record_the_module_already_wrote_is_not_overwritten() {.await.unwrap();- let outcome = import_into(&rig.scoped, &rig.secrets, legacy.path())+ let outcome = import_into(&DispatchCtx::host_default(), &rig.scoped, &rig.secrets, legacy.path()).await.unwrap();assert_eq!(@@ -226,7 +226,7 @@ async fn a_data_dir_with_no_legacy_files_is_a_no_op() {let empty = tempfile::tempdir().unwrap();let rig = rig();assert_eq!(- import_into(&rig.scoped, &rig.secrets, empty.path())+ import_into(&DispatchCtx::host_default(), &rig.scoped, &rig.secrets, empty.path()).await.unwrap(),Outcome::NoSource@@ -244,7 +244,7 @@ async fn an_unreadable_file_writes_no_marker_so_the_next_start_retries() {).unwrap();let rig = rig();- assert!(import_into(&rig.scoped, &rig.secrets, dir.path())+ assert!(import_into(&DispatchCtx::host_default(), &rig.scoped, &rig.secrets, dir.path()).await.is_err());let marker = rigdiff --git a/crates/openhuman-core/src/modules/storage_import_tinywallet.rs b/crates/openhuman-core/src/modules/storage_import_tinywallet.rsindex 9bb486cfa2..7289527029 100644--- a/crates/openhuman-core/src/modules/storage_import_tinywallet.rs+++ b/crates/openhuman-core/src/modules/storage_import_tinywallet.rs@@ -27,6 +27,7 @@ use serde_json::json;use tinystoragedrivers::ScopedStorage;use super::storage_grant_tinywallet::{MODULE_ID, PAYMENTS_STREAM};+use crate::core::runtime::DispatchCtx;use super::storage_import_support as support;const LOG_PREFIX: &str = "[x402-import]";diff --git a/crates/openhuman-core/src/modules/storage_import_tinywallet_tests.rs b/crates/openhuman-core/src/modules/storage_import_tinywallet_tests.rsindex 4b1c3ea6da..3f9ef05843 100644--- a/crates/openhuman-core/src/modules/storage_import_tinywallet_tests.rs+++ b/crates/openhuman-core/src/modules/storage_import_tinywallet_tests.rs@@ -41,7 +41,7 @@ fn digest(path: &Path) -> Vec<u8> {async fn the_payment_history_moves_into_the_modules_stream_in_order() {let legacy = legacy_workspace();let scoped = scoped();- let outcome = import_into(&scoped, legacy.path()).await.unwrap();+ let outcome = import_into(&DispatchCtx::host_default(), &scoped, legacy.path()).await.unwrap();assert_eq!(outcome,Outcome::Imported {@@ -77,7 +77,7 @@ async fn the_legacy_ledger_is_left_untouched() {let legacy = legacy_workspace();let file = legacy.path().join(LEDGER_FILE);let before = digest(&file);- import_into(&scoped(), legacy.path()).await.unwrap();+ import_into(&DispatchCtx::host_default(), &scoped(), legacy.path()).await.unwrap();assert_eq!(digest(&file), before);}@@ -85,9 +85,9 @@ async fn the_legacy_ledger_is_left_untouched() {async fn a_second_run_does_not_repeat_the_history() {let legacy = legacy_workspace();let scoped = scoped();- import_into(&scoped, legacy.path()).await.unwrap();+ import_into(&DispatchCtx::host_default(), &scoped, legacy.path()).await.unwrap();assert_eq!(- import_into(&scoped, legacy.path()).await.unwrap(),+ import_into(&DispatchCtx::host_default(), &scoped, legacy.path()).await.unwrap(),Outcome::AlreadyDone);assert_eq!(scoped.streams().len(PAYMENTS_STREAM).await.unwrap(), 3);@@ -106,7 +106,7 @@ async fn a_stream_the_module_already_wrote_is_not_preceded_by_old_records() {.await.unwrap();assert_eq!(- import_into(&scoped, legacy.path()).await.unwrap(),+ import_into(&DispatchCtx::host_default(), &scoped, legacy.path()).await.unwrap(),Outcome::Imported {payments: 0,skipped: 1@@ -120,12 +120,12 @@ async fn a_workspace_without_a_ledger_writes_no_marker() {let empty = tempfile::tempdir().unwrap();let scoped = scoped();assert_eq!(- import_into(&scoped, empty.path()).await.unwrap(),+ import_into(&DispatchCtx::host_default(), &scoped, empty.path()).await.unwrap(),Outcome::NoSource);let legacy = legacy_workspace();assert!(matches!(- import_into(&scoped, legacy.path()).await.unwrap(),+ import_into(&DispatchCtx::host_default(), &scoped, legacy.path()).await.unwrap(),Outcome::Imported { .. }));}@@ -137,12 +137,12 @@ async fn an_unreadable_ledger_is_retried_instead_of_marked_done() {std::fs::create_dir_all(file.parent().unwrap()).unwrap();std::fs::write(&file, [0xff, 0xfe]).unwrap();let scoped = scoped();- assert!(import_into(&scoped, dir.path()).await.is_err());+ assert!(import_into(&DispatchCtx::host_default(), &scoped, dir.path()).await.is_err());assert_eq!(scoped.streams().len(PAYMENTS_STREAM).await.unwrap(), 0);std::fs::write(&file, format!("{}\n", record("p1", "settled"))).unwrap();assert_eq!(- import_into(&scoped, dir.path()).await.unwrap(),+ import_into(&DispatchCtx::host_default(), &scoped, dir.path()).await.unwrap(),Outcome::Imported {payments: 1,skipped: 0