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: move inline test modules to separate files
Steven Enamakel0ca6b26df95c
diff --git a/crates/openhuman-core/src/agent/learning/linkedin_enrichment.rs b/crates/openhuman-core/src/agent/learning/linkedin_enrichment.rsindex 565d98e2c5..5cc78f069e 100644--- a/crates/openhuman-core/src/agent/learning/linkedin_enrichment.rs+++ b/crates/openhuman-core/src/agent/learning/linkedin_enrichment.rs@@ -21,11 +21,13 @@ use regex::Regex;use serde_json::json;use std::sync::LazyLock;-use gmail_discovery::search_gmail_for_linkedin;pub use gmail_discovery::scrape_linkedin_profile;-use memory_persistence::{persist_linkedin_profile, persist_linkedin_url_only, profile_memory_writer};-use profile_markdown::{write_profile_md, write_profile_md_url_only};+use gmail_discovery::search_gmail_for_linkedin;+use memory_persistence::{+ persist_linkedin_profile, persist_linkedin_url_only, profile_memory_writer,+};pub use profile_markdown::{render_profile_markdown, summarise_profile_with_llm};+use profile_markdown::{write_profile_md, write_profile_md_url_only};#[cfg(test)]#[path = "linkedin_enrichment_tests.rs"]diff --git a/crates/openhuman-core/src/agent/learning/linkedin_enrichment/profile_markdown.rs b/crates/openhuman-core/src/agent/learning/linkedin_enrichment/profile_markdown.rsindex 0481d91737..d660bd5b4c 100644--- a/crates/openhuman-core/src/agent/learning/linkedin_enrichment/profile_markdown.rs+++ b/crates/openhuman-core/src/agent/learning/linkedin_enrichment/profile_markdown.rs@@ -42,13 +42,12 @@ pub(super) async fn write_profile_md(/// Ask the backend LLM to distil the raw LinkedIn Markdown into a/// concise, high-signal profile document suitable for agent context.pub async fn summarise_profile_with_llm(config: &Config, raw_md: &str) -> anyhow::Result<String> {- let (model_chat, _) =- crate::inference::provider::create_chat_model_from_string_with_model_id(- "summarization",- "openhuman",- config,- 0.3,- )?;+ let (model_chat, _) = crate::inference::provider::create_chat_model_from_string_with_model_id(+ "summarization",+ "openhuman",+ config,+ 0.3,+ )?;let system = "\You are a profile analyst. You will receive a user's LinkedIn profile in Markdown format. \diff --git a/crates/openhuman-core/src/agent/learning/schemas/cache_helpers.rs b/crates/openhuman-core/src/agent/learning/schemas/cache_helpers.rsindex 01a5672f4b..b57374953c 100644--- a/crates/openhuman-core/src/agent/learning/schemas/cache_helpers.rs+++ b/crates/openhuman-core/src/agent/learning/schemas/cache_helpers.rs@@ -10,9 +10,7 @@ pub(super) async fn get_cache() -> Result<crate::agent::learning::cache::FacetCalet guard = crate::memory::ops::guard::active_memory_guard().await.map_err(|e| format!("memory unavailable: {e}"))?;- Ok(crate::agent::learning::cache::FacetCache::new(- guard,- ))+ Ok(crate::agent::learning::cache::FacetCache::new(guard))}/// Build the full facet key from class string + key suffix.diff --git a/crates/openhuman-core/src/agent/learning/schemas/facet_handlers.rs b/crates/openhuman-core/src/agent/learning/schemas/facet_handlers.rsindex d4fc5fba50..0360ecf899 100644--- a/crates/openhuman-core/src/agent/learning/schemas/facet_handlers.rs+++ b/crates/openhuman-core/src/agent/learning/schemas/facet_handlers.rs@@ -328,10 +328,9 @@ pub(super) fn handle_reset_cache(_params: Map<String, Value>) -> ControllerFuturlet cache = get_cache().await?;- let (deleted, pinned_preserved) =- crate::agent::learning::cache::reset_non_pinned(&cache)- .await- .map_err(|e| format!("reset_cache failed: {e:#}"))?;+ let (deleted, pinned_preserved) = crate::agent::learning::cache::reset_non_pinned(&cache)+ .await+ .map_err(|e| format!("reset_cache failed: {e:#}"))?;tracing::info!("[learning.reset_cache] deleted={deleted} pinned_preserved={pinned_preserved}"diff --git a/crates/openhuman-core/src/agent/learning/schemas/profile_handlers.rs b/crates/openhuman-core/src/agent/learning/schemas/profile_handlers.rsindex 3ae15afc1a..5ed167c4eb 100644--- a/crates/openhuman-core/src/agent/learning/schemas/profile_handlers.rs+++ b/crates/openhuman-core/src/agent/learning/schemas/profile_handlers.rs@@ -16,10 +16,12 @@ pub(super) fn handle_linkedin_enrichment(params: Map<String, Value>) -> Controll.and_then(Value::as_str).map(str::to_string);let config = config_rpc::load_config_with_timeout().await?;- let result =- crate::agent::learning::linkedin_enrichment::run_linkedin_enrichment(&config, preset_profile_url)- .await- .map_err(|e| format!("linkedin enrichment failed: {e:#}"))?;+ let result = crate::agent::learning::linkedin_enrichment::run_linkedin_enrichment(+ &config,+ preset_profile_url,+ )+ .await+ .map_err(|e| format!("linkedin enrichment failed: {e:#}"))?;let payload = serde_json::json!({"profile_url": result.profile_url,@@ -47,9 +49,11 @@ pub(super) fn handle_save_profile(params: Map<String, Value>) -> ControllerFuturlet config = config_rpc::load_config_with_timeout().await?;let body = if summarize {- crate::agent::learning::linkedin_enrichment::summarise_profile_with_llm(&config, &markdown)- .await- .map_err(|e| format!("LLM summarisation failed: {e:#}"))?+ crate::agent::learning::linkedin_enrichment::summarise_profile_with_llm(+ &config, &markdown,+ )+ .await+ .map_err(|e| format!("LLM summarisation failed: {e:#}"))?} else {markdown};diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents.rsindex 1f2b3dbc28..88ce2c7e9a 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents.rs@@ -61,12 +61,12 @@ mod wait;#[path = "running_subagents_tests.rs"]mod tests;+#[cfg(test)]+pub(crate) use cancel::prune;pub(crate) use cancel::{cancel_all, cancel_by_session, cancel_by_session_in_workspace, cancel_by_task,cancel_for_thread, CancelledSubagent,};-#[cfg(test)]-pub(crate) use cancel::prune;pub(crate) use registry::{register, status_channel, SubagentResumeRef, SubagentStatus};pub(crate) use resolve::{resume_ref_for_task, resume_ref_for_task_in_workspace, task_id_for_session,@@ -75,7 +75,7 @@ pub(crate) use resolve::{pub(crate) use roster::{active_subagents_context_block, snapshot_for_parent, SubagentSnapshot};pub use steering::{steer, SteerError};pub(crate) use steering::{steer_control, steer_directive, SteerDirectiveError, SteeringDirective};+pub(crate) use task_ledger::{reconcile_orphaned_tasks_on_boot, task_record_for_task_in_workspace};#[cfg(test)]pub(crate) use task_ledger::{record_spawned, task_records};-pub(crate) use task_ledger::{reconcile_orphaned_tasks_on_boot, task_record_for_task_in_workspace};pub(crate) use wait::{wait, wait_in_workspace, WaitError, WaitOutcome};diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rsindex 3374092c0b..c3d183aa1f 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rs@@ -84,8 +84,7 @@ pub(crate) const DETACHED_LEDGER_TIMEOUT_MS: u64 = 120_000;static REGISTRY: OnceLock<DetachedTaskRegistry<RunningSubagentMetadata, SubagentStatus>> =OnceLock::new();-pub(crate) fn registry() -> &'static DetachedTaskRegistry<RunningSubagentMetadata, SubagentStatus>-{+pub(crate) fn registry() -> &'static DetachedTaskRegistry<RunningSubagentMetadata, SubagentStatus> {REGISTRY.get_or_init(|| {DetachedTaskRegistry::new(shared_steering_registry().clone(),diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/roster.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/roster.rsindex 8d2fcb47f8..c791c0d9bd 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/roster.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/roster.rs@@ -85,28 +85,27 @@ pub(crate) fn active_subagents_context_block(let store = crate::agent::orchestration::subagent_sessions::SubagentSessionStore {workspace_dir: workspace_dir.to_path_buf(),};- let durable: Vec<_> =- match crate::agent::orchestration::subagent_sessions::list_for_parent(- &store,- parent_session,- None,- ) {- Ok(sessions) => sessions- .into_iter()- .filter(|s| {- use crate::agent::orchestration::subagent_sessions::DurableSubagentStatus;- s.status != DurableSubagentStatus::Closed- && !live_session_ids.contains(&s.subagent_session_id)- })- .take(DURABLE_ROSTER_CAP)- .collect(),- Err(err) => {- log::warn!(+ let durable: Vec<_> = match crate::agent::orchestration::subagent_sessions::list_for_parent(+ &store,+ parent_session,+ None,+ ) {+ Ok(sessions) => sessions+ .into_iter()+ .filter(|s| {+ use crate::agent::orchestration::subagent_sessions::DurableSubagentStatus;+ s.status != DurableSubagentStatus::Closed+ && !live_session_ids.contains(&s.subagent_session_id)+ })+ .take(DURABLE_ROSTER_CAP)+ .collect(),+ Err(err) => {+ log::warn!("[running_subagents] durable roster load failed parent_session={parent_session} error={err}");- Vec::new()- }- };+ Vec::new()+ }+ };if workers.is_empty() && durable.is_empty() {return None;diff --git a/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/dispatch.rs b/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/dispatch.rsindex ee5aaf2793..d4312532ad 100644--- a/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/dispatch.rs+++ b/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/dispatch.rs@@ -126,7 +126,6 @@ async fn create_spawn_parallel_worktree(}}-pub(crate) async fn stage_spawn_parallel_workers_from_defs(parent_session: &str,progress_sink: Option<&Sender<AgentProgress>>,diff --git a/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/graph.rs b/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/graph.rsindex 7b9965a1b8..a34f492a80 100644--- a/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/graph.rs+++ b/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/graph.rs@@ -76,8 +76,9 @@ enum SpawnParallelUpdate {Collected(SpawnParallelCollected),}-type SpawnParallelNodeFuture =- Pin<Box<dyn Future<Output = tinyagents_harness::Result<NodeResult<SpawnParallelUpdate>>> + Send>>;+type SpawnParallelNodeFuture = Pin<+ Box<dyn Future<Output = tinyagents_harness::Result<NodeResult<SpawnParallelUpdate>>> + Send>,+>;fn phase_node(phase: &'static str,diff --git a/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/staging.rs b/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/staging.rsindex 1f0693a3af..a43a3c99bd 100644--- a/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/staging.rs+++ b/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/staging.rs@@ -11,8 +11,8 @@//! The rejection sentences stay here, which is why the crate reports conflicts//! as data.-use std::path::PathBuf;use std::collections::HashMap;+use std::path::PathBuf;use tinyagents_graph::parallel::{parse_relative_claim_paths, plan_shared_workspace_dispatch, ClaimConflict, ClaimPathError,@@ -225,7 +225,6 @@ fn shared_workspace_write_claim(Ok(Some(paths))}-pub(crate) fn snapshot_agent_definitions(registry: &AgentDefinitionRegistry,) -> HashMap<String, AgentDefinition> {@@ -454,4 +453,3 @@ pub(crate) fn with_ownership_boundary(prompt: &str, ownership: Option<&str>) ->None => prompt.to_string(),}}-diff --git a/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/tool.rs b/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/tool.rsindex e2c4f4b678..2c34bfc94d 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/tool.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/tool.rs@@ -10,7 +10,9 @@ use async_trait::async_trait;use serde_json::json;use tinytools::ToolRunContext;-use super::scout_run::{already_prepared_context_bundle, run_context_scout_with_catalog_and_workspace};+use super::scout_run::{+ already_prepared_context_bundle, run_context_scout_with_catalog_and_workspace,+};/// Spawns the `context_scout` sub-agent to collect context and propose a plan.pub struct AgentPrepareContextTool;@@ -50,12 +52,11 @@ impl AgentPrepareContextTool {};let visible = &parent.visible_tool_names;let specs: &[std::sync::Arc<crate::tools::ToolSpec>] =- if parent.visible_tool_specs.is_empty()- {- &parent.all_tool_specs- } else {- &parent.visible_tool_specs- };+ if parent.visible_tool_specs.is_empty() {+ &parent.all_tool_specs+ } else {+ &parent.visible_tool_specs+ };let mut out = String::with_capacity(2048);for spec in specs.iter() {if spec.name == "agent_prepare_context" {@@ -88,7 +89,11 @@ impl AgentPrepareContextTool {/// Build the scout's task prompt: the request, optional focus, and the/// parent tool catalogue the scout draws its recommendations from.- pub(super) fn build_scout_prompt(question: &str, focus: Option<&str>, tool_catalog: &str) -> String {+ pub(super) fn build_scout_prompt(+ question: &str,+ focus: Option<&str>,+ tool_catalog: &str,+ ) -> String {let mut prompt = String::with_capacity(question.len() + tool_catalog.len() + 512);let _ = writeln!(prompt, "[Request]\n{question}\n");if let Some(focus) = focus.filter(|f| !f.trim().is_empty()) {diff --git a/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/phase_exec.rs b/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/phase_exec.rsindex 6ce078a2ad..b713993f3e 100644--- a/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/phase_exec.rs+++ b/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/phase_exec.rs@@ -11,11 +11,11 @@ use tinyagents_harness::TinyAgentsError;use tinyagents_session::run_ledger::{get_workflow_run, WorkflowRunStatus};+use super::super::types::{WorkflowDefinition, WorkflowPhase};use super::cancel::lookup_cancel_token;use super::state::{persist, phase_prompt, set_phase_reason, set_phase_status, upstream_outputs};use super::state::{PHASE_COMPLETED, PHASE_FAILED, PHASE_RUNNING};use super::LOG_TARGET;-use super::super::types::{WorkflowDefinition, WorkflowPhase};use crate::config::Config;/// One worker's outcome from the intra-phase graph fan-out (seediff --git a/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/state.rs b/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/state.rsindex ff46c04896..1cb2f713a2 100644--- a/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/state.rs+++ b/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/state.rs@@ -5,7 +5,9 @@use anyhow::{Context, Result};use serde_json::{json, Value};-use tinyagents_session::run_ledger::{upsert_workflow_run, WorkflowRun, WorkflowRunStatus, WorkflowRunUpsert};+use tinyagents_session::run_ledger::{+ upsert_workflow_run, WorkflowRun, WorkflowRunStatus, WorkflowRunUpsert,+};use super::super::types::{WorkflowDefinition, WorkflowPhase};use crate::config::Config;@@ -156,7 +158,10 @@ pub(super) fn phase_prompt(/// The synthesize phase's combined output becomes the run summary. Falls back/// to the last completed phase's output if no phase is literally named/// `synthesize`.-pub(super) fn synthesize_summary(definition: &WorkflowDefinition, phase_states: &Value) -> Option<String> {+pub(super) fn synthesize_summary(+ definition: &WorkflowDefinition,+ phase_states: &Value,+) -> Option<String> {let pick = |name: &str| -> Option<String> {let outputs = phase_states.get(name)diff --git a/crates/openhuman-core/src/memory/guard/test_support/fixtures.rs b/crates/openhuman-core/src/memory/guard/test_support/fixtures.rsindex f4cea4baae..ca52855606 100644--- a/crates/openhuman-core/src/memory/guard/test_support/fixtures.rs+++ b/crates/openhuman-core/src/memory/guard/test_support/fixtures.rs@@ -287,3 +287,5 @@ pub fn namespace_hit(chunk_id: None,supporting_relations: Vec::new(),taint: MemoryTaint::default(),+ }+}diff --git a/crates/openhuman-rpc/src/lib.rs b/crates/openhuman-rpc/src/lib.rsindex 1b632aab47..5db9217047 100644--- a/crates/openhuman-rpc/src/lib.rs+++ b/crates/openhuman-rpc/src/lib.rs@@ -113,92 +113,5 @@ pub fn apply_log_envelope(value: serde_json::Value, logs: Vec<String>) -> serde_}#[cfg(test)]-mod tests {- use super::*;- use serde_json::json;-- #[test]- fn new_preserves_value_and_logs() {- let outcome: RpcOutcome<i64> = RpcOutcome::new(7, vec!["a".into(), "b".into()]);- assert_eq!(outcome.value, 7);- assert_eq!(outcome.logs, vec!["a".to_string(), "b".to_string()]);- }-- #[test]- fn single_log_stores_exactly_one_log() {- let outcome = RpcOutcome::single_log(json!({"ok": true}), "hello");- assert_eq!(outcome.logs.len(), 1);- assert_eq!(outcome.logs[0], "hello");- assert_eq!(outcome.value, json!({"ok": true}));- }-- #[test]- fn single_log_accepts_string_and_str_via_into() {- let a = RpcOutcome::single_log(json!(1), "static str");- let b = RpcOutcome::single_log(json!(1), String::from("owned string"));- assert_eq!(a.logs[0], "static str");- assert_eq!(b.logs[0], "owned string");- }-- #[test]- fn into_cli_compatible_json_no_logs_returns_bare_value() {- let outcome = RpcOutcome::<serde_json::Value>::new(json!({"x": 1}), vec![]);- let out = outcome.into_cli_compatible_json().unwrap();- assert_eq!(out, json!({"x": 1}));- assert!(out.get("logs").is_none());- }-- #[test]- fn into_cli_compatible_json_with_logs_wraps_in_envelope() {- let outcome = RpcOutcome::single_log(json!(42), "did something");- let out = outcome.into_cli_compatible_json().unwrap();- assert_eq!(out["result"], json!(42));- assert_eq!(out["logs"], json!(["did something"]));- // And only those two keys exist.- assert_eq!(out.as_object().unwrap().len(), 2);- }-- #[test]- fn into_cli_compatible_json_serializes_typed_value() {- #[derive(serde::Serialize)]- struct Payload<'a> {- name: &'a str,- count: u32,- }- let outcome = RpcOutcome::new(- Payload {- name: "atlas",- count: 3,- },- vec![],- );- let out = outcome.into_cli_compatible_json().unwrap();- assert_eq!(out, json!({"name": "atlas", "count": 3}));- }-- #[test]- fn into_cli_compatible_json_treats_null_value_as_bare_when_no_logs() {- let outcome: RpcOutcome<Option<i32>> = RpcOutcome::new(None, vec![]);- let out = outcome.into_cli_compatible_json().unwrap();- assert!(out.is_null());- }-- #[test]- fn into_cli_compatible_json_preserves_log_order() {- let outcome = RpcOutcome::new(- json!({"ok": true}),- vec!["first".into(), "second".into(), "third".into()],- );- let out = outcome.into_cli_compatible_json().unwrap();- assert_eq!(out["logs"], json!(["first", "second", "third"]));- }-- #[test]- fn into_cli_compatible_json_empty_string_logs_still_envelope() {- // An empty log string is still a log — envelope shape must kick in.- let outcome = RpcOutcome::new(json!("x"), vec!["".into()]);- let out = outcome.into_cli_compatible_json().unwrap();- assert!(out.get("result").is_some());- assert_eq!(out["logs"], json!([""]));- }-}+#[path = "lib_tests.rs"]+mod tests;diff --git a/crates/openhuman-rpc/src/structured_error.rs b/crates/openhuman-rpc/src/structured_error.rsindex 0dc2c7ce26..2f03b0a5cf 100644--- a/crates/openhuman-rpc/src/structured_error.rs+++ b/crates/openhuman-rpc/src/structured_error.rs@@ -66,43 +66,5 @@ impl StructuredRpcError {}#[cfg(test)]-mod tests {- use super::*;- use serde_json::json;-- #[test]- fn encode_then_decode_round_trips() {- let original = StructuredRpcError {- message: "thread thread-123 not found".to_string(),- data: Some(json!({ "kind": "ThreadNotFound", "thread_id": "thread-123" })),- expected_user_state: true,- };- let encoded = original.encode();- assert!(- encoded.starts_with(STRUCTURED_RPC_ERROR_SENTINEL),- "encoded string must carry the sentinel prefix"- );- let decoded = StructuredRpcError::decode(&encoded).expect("decoded");- assert_eq!(decoded, original);- }-- #[test]- fn decode_returns_none_for_plain_strings() {- assert!(StructuredRpcError::decode("plain error").is_none());- assert!(StructuredRpcError::decode("").is_none());- assert!(StructuredRpcError::decode("__OPENHUMAN_STRUCTURED_RPC_ERROR_V1__").is_none());- }-- #[test]- fn decode_returns_none_for_corrupt_envelope() {- let bad = format!("{STRUCTURED_RPC_ERROR_SENTINEL}not-json");- assert!(StructuredRpcError::decode(&bad).is_none());- }-- #[test]- fn expected_user_state_defaults_to_false_when_absent() {- let raw = format!("{STRUCTURED_RPC_ERROR_SENTINEL}{{\"message\":\"x\",\"data\":null}}");- let decoded = StructuredRpcError::decode(&raw).expect("decoded");- assert!(!decoded.expected_user_state);- }-}+#[path = "structured_error_tests.rs"]+mod tests;