Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

style(cron): apply rustfmt formatting to cron module

Steven Enamakel950b1ed9e947
diff --git a/crates/openhuman-core/src/cron/channel_bridge.rs b/crates/openhuman-core/src/cron/channel_bridge.rs
index a884a58264..1dcc1180c3 100644
--- a/crates/openhuman-core/src/cron/channel_bridge.rs
+++ b/crates/openhuman-core/src/cron/channel_bridge.rs
@@ -10,8 +10,8 @@
use std::collections::HashMap;
use std::sync::{Arc, Mutex, RwLock};
-use tinychannels_bus::{Channel, SendMessage};
use tinyagents_session::transcript::TranscriptMessage;
+use tinychannels_bus::{Channel, SendMessage};
/// Same shape as `channels::context::ConversationHistoryMap`, spelled out so
/// cron does not depend on the feature-gated `channels` module.
@@ -63,10 +63,7 @@ pub fn history_messages(history_key: &str) -> Vec<(String, String)> {
tracing::debug!("[cron] channel history requested but no channel bridge registered");
return Vec::new();
};
- let histories = bridge
- .histories
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ let histories = bridge.histories.lock().unwrap_or_else(|e| e.into_inner());
histories
.get(history_key)
.map(|turns| {
@@ -87,10 +84,7 @@ pub fn append_assistant_message(history_key: &str, text: &str) -> bool {
return false;
};
let max = MAX_HISTORY.load(std::sync::atomic::Ordering::Relaxed);
- let mut histories = bridge
- .histories
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ let mut histories = bridge.histories.lock().unwrap_or_else(|e| e.into_inner());
let turns = histories.entry(history_key.to_string()).or_default();
turns.push(TranscriptMessage::assistant(text));
while turns.len() > max {
diff --git a/crates/openhuman-core/src/cron/job_builder.rs b/crates/openhuman-core/src/cron/job_builder.rs
index 4f0a16cadb..6b1f8916b5 100644
--- a/crates/openhuman-core/src/cron/job_builder.rs
+++ b/crates/openhuman-core/src/cron/job_builder.rs
@@ -68,7 +68,11 @@ pub fn check_origin_requirements(
if origin.is_some() {
return Ok(());
}
- if delivery.mode.trim().eq_ignore_ascii_case(delivery_mode::ORIGIN) {
+ if delivery
+ .mode
+ .trim()
+ .eq_ignore_ascii_case(delivery_mode::ORIGIN)
+ {
return Err(
"delivery mode 'origin' needs the conversation the job is created from; this \
job has none (use 'proactive' or 'announce')"
@@ -180,7 +184,10 @@ pub fn create_agent_job(
check_origin_requirements(&session_target, &delivery, origin.as_ref())?;
let uses_origin = matches!(session_target, SessionTarget::Current)
- || delivery.mode.trim().eq_ignore_ascii_case(delivery_mode::ORIGIN);
+ || delivery
+ .mode
+ .trim()
+ .eq_ignore_ascii_case(delivery_mode::ORIGIN);
let origin = origin.filter(|_| uses_origin);
tracing::debug!(
diff --git a/crates/openhuman-core/src/cron/job_builder_tests.rs b/crates/openhuman-core/src/cron/job_builder_tests.rs
index bd7728d2d8..cde5b8d5b8 100644
--- a/crates/openhuman-core/src/cron/job_builder_tests.rs
+++ b/crates/openhuman-core/src/cron/job_builder_tests.rs
@@ -77,7 +77,10 @@ fn explicit_delivery_and_target_win_and_drop_the_unused_origin() {
let job = create_agent_job(&config(&tmp), i, Some(web())).unwrap();
assert_eq!(job.session_target, SessionTarget::Isolated);
assert_eq!(job.delivery.mode, "none");
- assert_eq!(job.origin, None, "nothing uses the origin, so it is not kept");
+ assert_eq!(
+ job.origin, None,
+ "nothing uses the origin, so it is not kept"
+ );
}
#[test]
diff --git a/crates/openhuman-core/src/cron/mod.rs b/crates/openhuman-core/src/cron/mod.rs
index 302f8ce768..572864689b 100644
--- a/crates/openhuman-core/src/cron/mod.rs
+++ b/crates/openhuman-core/src/cron/mod.rs
@@ -33,19 +33,19 @@ pub use schemas::{
};
#[allow(unused_imports)]
pub use store::{
- add_agent_job, add_agent_job_from_spec, add_agent_job_with_definition, add_flow_schedule_job, add_job, add_shell_job,
- clear_all_jobs, dedup_named_jobs, delete_queued_runs, due_jobs, find_flow_schedule_job,
- get_job, list_jobs, list_runs, record_last_run, record_run, record_run_with_delivery, remove_job, reschedule_after_run,
- update_job,
+ add_agent_job, add_agent_job_from_spec, add_agent_job_with_definition, add_flow_schedule_job,
+ add_job, add_shell_job, clear_all_jobs, dedup_named_jobs, delete_queued_runs, due_jobs,
+ find_flow_schedule_job, get_job, list_jobs, list_runs, record_last_run, record_run,
+ record_run_with_delivery, remove_job, reschedule_after_run, update_job,
};
#[allow(unused_imports)]
pub use tinyflows_schedule::schedule::{
next_run_for_schedule, normalize_expression, runs_closer_than, schedule_cron_expression,
validate_agent_schedule, validate_schedule, TooFrequent, MIN_AGENT_JOB_INTERVAL,
};
+pub use tinyflows_schedule::types::delivery_mode;
pub use tinyflows_schedule::types::{
ActiveHours, CronJob, CronJobPatch, CronRun, DeliveryConfig, DeliveryStatus, JobOrigin,
JobType, Schedule, SessionTarget,
};
-pub use tinyflows_schedule::types::delivery_mode;
pub use tinyflows_sqlite::schedule::AgentJobSpec;
diff --git a/crates/openhuman-core/src/cron/origin.rs b/crates/openhuman-core/src/cron/origin.rs
index 59b1b12434..8d019acf9e 100644
--- a/crates/openhuman-core/src/cron/origin.rs
+++ b/crates/openhuman-core/src/cron/origin.rs
@@ -140,8 +140,7 @@ pub(crate) fn is_self_scoped_agent_job(args: &Value, turn: Option<&AgentTurnOrig
match mode.as_str() {
delivery_mode::ORIGIN => true,
delivery_mode::ANNOUNCE => {
- non_empty_str(delivery, "channel")
- .is_some_and(|c| c.eq_ignore_ascii_case(&channel))
+ non_empty_str(delivery, "channel").is_some_and(|c| c.eq_ignore_ascii_case(&channel))
&& non_empty_str(delivery, "to") == Some(reply_target.as_str())
}
_ => false,
diff --git a/crates/openhuman-core/src/cron/origin_tests.rs b/crates/openhuman-core/src/cron/origin_tests.rs
index 965ea40473..9b4985bbcd 100644
--- a/crates/openhuman-core/src/cron/origin_tests.rs
+++ b/crates/openhuman-core/src/cron/origin_tests.rs
@@ -1,6 +1,6 @@
use super::*;
-use crate::cron::Schedule;
use crate::agent::turn_origin::{with_origin, TrustedAutomationSource};
+use crate::cron::Schedule;
use serde_json::json;
fn channel_turn(history_key: Option<&str>) -> AgentTurnOrigin {
@@ -162,7 +162,8 @@ fn gate_skipped_for_default_origin_delivery() {
fn gate_skipped_for_explicit_origin_mode_and_matching_announce() {
let origin_mode = json!({"job_type": "agent", "prompt": "p", "delivery": {"mode": "origin"}});
assert!(is_self_scoped_agent_job(&origin_mode, Some(&ch())));
- let announce = json!({"prompt": "p", "delivery": {"mode": "announce", "channel": "Telegram", "to": "42"}});
+ let announce =
+ json!({"prompt": "p", "delivery": {"mode": "announce", "channel": "Telegram", "to": "42"}});
assert!(is_self_scoped_agent_job(&announce, Some(&ch())));
}
@@ -195,7 +196,10 @@ fn gate_kept_for_non_channel_turns() {
assert!(!is_self_scoped_agent_job(&args, None));
assert!(!is_self_scoped_agent_job(&args, Some(&web_turn("t"))));
assert!(!is_self_scoped_agent_job(&args, Some(&channel_turn(None))));
- assert!(!is_self_scoped_agent_job(&args, Some(&AgentTurnOrigin::Cli)));
+ assert!(!is_self_scoped_agent_job(
+ &args,
+ Some(&AgentTurnOrigin::Cli)
+ ));
}
#[tokio::test]
diff --git a/crates/openhuman-core/src/cron/scheduler/agent_run.rs b/crates/openhuman-core/src/cron/scheduler/agent_run.rs
index d4343e7aa2..bf91eeb13a 100644
--- a/crates/openhuman-core/src/cron/scheduler/agent_run.rs
+++ b/crates/openhuman-core/src/cron/scheduler/agent_run.rs
@@ -2,8 +2,8 @@
//! (definition selection) and the single scheduled turn.
use super::delivery::is_morning_briefing_job;
-use super::origin_context::build_run_prompt;
use super::failure_classification::classify_agent_anyhow_for_user;
+use super::origin_context::build_run_prompt;
use crate::agent::OpenHumanSessionHost;
use crate::config::Config;
use crate::core::bus::BUS;
diff --git a/crates/openhuman-core/src/cron/scheduler/delivery.rs b/crates/openhuman-core/src/cron/scheduler/delivery.rs
index ff6a54d806..68cfadca19 100644
--- a/crates/openhuman-core/src/cron/scheduler/delivery.rs
+++ b/crates/openhuman-core/src/cron/scheduler/delivery.rs
@@ -3,10 +3,10 @@
use super::agent_run::EMPTY_AGENT_OUTPUT;
use super::failure_classification::AGENT_JOB_USER_FAILURE_MESSAGE;
+use super::origin_delivery::{deliver_to_origin, is_suppressed_output};
use crate::config::Config;
use crate::core::bus::BUS;
use crate::core::events::DomainEvent;
-use super::origin_delivery::{deliver_to_origin, is_suppressed_output};
use crate::cron::{delivery_mode, CronJob, DeliveryConfig, DeliveryStatus, JobType};
use anyhow::Result;
use chrono::Utc;
diff --git a/crates/openhuman-core/src/cron/scheduler/origin_context.rs b/crates/openhuman-core/src/cron/scheduler/origin_context.rs
index 1eeea00bd8..beccdac1d5 100644
--- a/crates/openhuman-core/src/cron/scheduler/origin_context.rs
+++ b/crates/openhuman-core/src/cron/scheduler/origin_context.rs
@@ -36,10 +36,7 @@ pub(crate) fn bounded_tail(
continue;
}
if remaining >= 80 {
- let cut: String = line
- .chars()
- .skip(len - (remaining - 1))
- .collect::<String>();
+ let cut: String = line.chars().skip(len - (remaining - 1)).collect::<String>();
picked.push(format!("…{cut}"));
}
break;
@@ -61,7 +58,11 @@ async fn origin_messages(config: &Config, origin: &JobOrigin) -> Vec<(String, St
Ok(messages) => messages
.into_iter()
.map(|m| {
- let role = if m.sender == "user" { "user" } else { "assistant" };
+ let role = if m.sender == "user" {
+ "user"
+ } else {
+ "assistant"
+ };
(role.to_string(), m.content)
})
.collect(),
@@ -77,12 +78,7 @@ async fn origin_messages(config: &Config, origin: &JobOrigin) -> Vec<(String, St
/// Prompt for a `current` run: tagged task, unattended preamble, the bounded
/// context tail (when there is one), then the task itself.
-pub(crate) fn compose_current_prompt(
- job_id: &str,
- name: &str,
- prompt: &str,
- tail: &str,
-) -> String {
+pub(crate) fn compose_current_prompt(job_id: &str, name: &str, prompt: &str, tail: &str) -> String {
let mut out = format!("[cron:{job_id} {name}] {UNATTENDED_PREAMBLE}\n\n");
if !tail.is_empty() {
out.push_str("Recent conversation this task was created in (context only):\n");
diff --git a/crates/openhuman-core/src/cron/scheduler/origin_context_tests.rs b/crates/openhuman-core/src/cron/scheduler/origin_context_tests.rs
index 53d62f3f84..9f7a4afa54 100644
--- a/crates/openhuman-core/src/cron/scheduler/origin_context_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler/origin_context_tests.rs
@@ -7,7 +7,12 @@ fn m(role: &str, text: &str) -> (String, String) {
#[test]
fn tail_keeps_the_newest_messages_in_order() {
let msgs: Vec<_> = (0..15)
- .map(|i| m(if i % 2 == 0 { "user" } else { "assistant" }, &format!("msg{i}")))
+ .map(|i| {
+ m(
+ if i % 2 == 0 { "user" } else { "assistant" },
+ &format!("msg{i}"),
+ )
+ })
.collect();
let tail = bounded_tail(&msgs, 10, 1400);
let lines: Vec<_> = tail.lines().collect();
@@ -19,9 +24,17 @@ fn tail_keeps_the_newest_messages_in_order() {
#[test]
fn tail_is_bounded_by_characters_and_keeps_the_newest() {
let long = "x".repeat(1000);
- let msgs = vec![m("user", "old one"), m("user", &long), m("assistant", &long)];
+ let msgs = vec![
+ m("user", "old one"),
+ m("user", &long),
+ m("assistant", &long),
+ ];
let tail = bounded_tail(&msgs, 10, 1400);
- assert!(tail.chars().count() <= 1400 + 1, "len {}", tail.chars().count());
+ assert!(
+ tail.chars().count() <= 1400 + 1,
+ "len {}",
+ tail.chars().count()
+ );
assert!(tail.ends_with(&"x".repeat(100)));
assert!(tail.lines().last().unwrap().starts_with("assistant: "));
assert!(!tail.contains("old one"));
diff --git a/crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rs b/crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rs
index 2eaa2fc239..5c73af2e6b 100644
--- a/crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rs
@@ -87,9 +87,11 @@ async fn no_reply_is_suppressed_without_writing_anything() {
.await
.unwrap();
assert_eq!(status, DeliveryStatus::Suppressed);
- assert!(conversations::get_messages(cfg.workspace_dir.clone(), "t-1")
- .unwrap()
- .is_empty());
+ assert!(
+ conversations::get_messages(cfg.workspace_dir.clone(), "t-1")
+ .unwrap()
+ .is_empty()
+ );
}
#[tokio::test]
@@ -114,7 +116,9 @@ async fn web_delivery_stores_one_row_under_the_run_reply_id_and_is_idempotent()
assert_eq!(messages[0].content, "Drink water!");
assert_eq!(messages[0].sender, "agent");
- deliver_to_origin(&cfg, &j, "run-2", "Again!").await.unwrap();
+ deliver_to_origin(&cfg, &j, "run-2", "Again!")
+ .await
+ .unwrap();
assert_eq!(
conversations::get_messages(cfg.workspace_dir.clone(), "t-1")
.unwrap()
diff --git a/crates/openhuman-core/src/cron/scheduler/run_record.rs b/crates/openhuman-core/src/cron/scheduler/run_record.rs
index b27ab79951..b83a95e250 100644
--- a/crates/openhuman-core/src/cron/scheduler/run_record.rs
+++ b/crates/openhuman-core/src/cron/scheduler/run_record.rs
@@ -5,7 +5,8 @@ use super::delivery::deliver_run;
use crate::config::Config;
use crate::cron::{
record_last_run, record_run_with_delivery, remove_job, reschedule_after_run, runs_closer_than,
- update_job, CronJob, DeliveryStatus, CronJobPatch, JobType, Schedule, TooFrequent, MIN_AGENT_JOB_INTERVAL,
+ update_job, CronJob, CronJobPatch, DeliveryStatus, JobType, Schedule, TooFrequent,
+ MIN_AGENT_JOB_INTERVAL,
};
use chrono::{DateTime, Utc};
@@ -20,8 +21,16 @@ pub(super) async fn persist_job_result(
finished_at: DateTime<Utc>,
) -> bool {
let run_id = uuid::Uuid::new_v4().to_string();
- persist_job_result_for_run(config, job, &run_id, success, output, started_at, finished_at)
- .await
+ persist_job_result_for_run(
+ config,
+ job,
+ &run_id,
+ success,
+ output,
+ started_at,
+ finished_at,
+ )
+ .await
}
pub(super) async fn persist_job_result_for_run(
diff --git a/crates/openhuman-core/src/cron/schemas.rs b/crates/openhuman-core/src/cron/schemas.rs
index 41f1ca3de5..944ac9da2f 100644
--- a/crates/openhuman-core/src/cron/schemas.rs
+++ b/crates/openhuman-core/src/cron/schemas.rs
@@ -362,7 +362,9 @@ fn handle_add(params: Map<String, Value>) -> ControllerFuture {
origin
.is_none()
.then(crate::cron::DeliveryConfig::default)
- .or_else(|| Some(crate::cron::job_builder::default_delivery(origin.as_ref())))
+ .or_else(|| {
+ Some(crate::cron::job_builder::default_delivery(origin.as_ref()))
+ })
});
let delivery_cfg = delivery.clone().unwrap_or_default();
crate::cron::job_builder::check_origin_requirements(
diff --git a/crates/openhuman-core/src/cron/store.rs b/crates/openhuman-core/src/cron/store.rs
index 1743be82c2..374d6bcb3f 100644
--- a/crates/openhuman-core/src/cron/store.rs
+++ b/crates/openhuman-core/src/cron/store.rs
@@ -8,8 +8,8 @@
use crate::config::Config;
use anyhow::Result;
use chrono::{DateTime, Utc};
-use tinyflows_schedule::{CronJob, CronJobPatch, CronRun, DeliveryConfig, Schedule, SessionTarget};
use tinyflows_schedule::DeliveryStatus;
+use tinyflows_schedule::{CronJob, CronJobPatch, CronRun, DeliveryConfig, Schedule, SessionTarget};
use tinyflows_sqlite::schedule::{self as upstream, AgentJobSpec, CronStoreOptions};
/// Builds the store options from the host config: `<workspace>/cron/jobs.db`,
diff --git a/crates/openhuman-core/src/cron/tools/add_tests.rs b/crates/openhuman-core/src/cron/tools/add_tests.rs
index 1dda7d00fa..fab09006a6 100644
--- a/crates/openhuman-core/src/cron/tools/add_tests.rs
+++ b/crates/openhuman-core/src/cron/tools/add_tests.rs
@@ -1,6 +1,6 @@
use super::*;
-use crate::cron::job_builder::validate_delivery;
use crate::config::Config;
+use crate::cron::job_builder::validate_delivery;
use crate::cron::ActiveHours;
use crate::security::AutonomyLevel;
use tempfile::TempDir;
diff --git a/crates/openhuman-core/src/cron/tools/run.rs b/crates/openhuman-core/src/cron/tools/run.rs
index fdf7669650..0358d6d605 100644
--- a/crates/openhuman-core/src/cron/tools/run.rs
+++ b/crates/openhuman-core/src/cron/tools/run.rs
@@ -90,8 +90,7 @@ impl Tool for CronRunTool {
let started_at = Utc::now();
let run_id = uuid::Uuid::new_v4().to_string();
- let (success, output) =
- cron::scheduler::execute_job_now(&self.config, &job, &run_id).await;
+ let (success, output) = cron::scheduler::execute_job_now(&self.config, &job, &run_id).await;
let finished_at = Utc::now();
let duration_ms = (finished_at - started_at).num_milliseconds();
let status = if success { "ok" } else { "error" };