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
docs(cron): add README for cron module
Steven Enamakel64f27aa7098e
diff --git a/crates/openhuman-core/src/cron/README.md b/crates/openhuman-core/src/cron/README.mdindex 634ef189e6..0076a80efa 100644--- a/crates/openhuman-core/src/cron/README.md+++ b/crates/openhuman-core/src/cron/README.md@@ -4,54 +4,56 @@ Scheduled-job runtime. Owns cron-expression and human-delay parsing, the persist## Public surface-- `pub struct CronJob` / `pub struct CronJobPatch` / `pub struct CronRun` / `pub enum JobType` / `pub enum Schedule` / `pub enum SessionTarget` / `pub struct DeliveryConfig` — `types.rs` — durable job + run model.+- `pub struct CronJob` / `pub struct CronJobPatch` / `pub struct CronRun` / `pub struct ActiveHours` / `pub enum JobType` / `pub enum Schedule` (`Cron` / `At` / `Every`) / `pub enum SessionTarget` / `pub struct DeliveryConfig` — `types.rs` — durable job + run model.- `pub fn add_once` / `pub fn add_once_at` / `pub fn parse_human_delay` / `pub fn pause_job` / `pub fn resume_job` / `pub fn update_cron_job` — `ops.rs` (also re-exported as `pub use ops as rpc`).-- `pub fn schedule_cron_expression` / `pub fn next_run_for_schedule` / `pub fn normalize_expression` / `pub fn validate_schedule` / `pub fn validate_agent_schedule` / `pub fn runs_closer_than` / `pub const MIN_AGENT_JOB_INTERVAL` — `schedule.rs`.+- `pub fn schedule_cron_expression` / `pub fn next_run_for_schedule` / `pub fn normalize_expression` / `pub fn validate_schedule` / `pub fn validate_agent_schedule` / `pub fn runs_closer_than` / `pub struct TooFrequent` / `pub const MIN_AGENT_JOB_INTERVAL` — `schedule.rs`.- `pub fn add_job` / `pub fn add_agent_job` / `pub fn add_agent_job_with_definition` / `pub fn add_shell_job` / `pub fn add_flow_schedule_job` / `pub fn find_flow_schedule_job` / `pub fn due_jobs` / `pub fn get_job` / `pub fn list_jobs` / `pub fn list_runs` / `pub fn record_last_run` / `pub fn record_run` / `pub fn remove_job` / `pub fn reschedule_after_run` / `pub fn update_job` — `store.rs` (split into `store_part_01.rs` / `store_part_02.rs` via `include!`).-- `pub mod scheduler` (`pub async fn run(config: Config)`) — `scheduler.rs`, split into `scheduler_part_01.rs` (poll loop, `run`), `scheduler_part_02.rs` (per-job-type execution, `run_agent_job`), `scheduler_part_03.rs` (`deliver_if_configured`) via `include!`.-- `pub mod scheduler_gate` — host-condition gating (battery / AC / thermal) for whether a due job may run now; see its own [README](scheduler_gate/README.md).-- `pub mod seed` — `seed.rs` — install built-in jobs on first launch.-- `pub mod bus` — `bus.rs` — `CronDeliverySubscriber` for the event bus.-- `pub mod tools` — `tools.rs` + `tools/` — agent-facing tools: `CronAddTool`, `CronListTool`, `CronUpdateTool`, `CronRemoveTool`, `CronRunTool`, `CronRunsTool`, and the collapsed `CronTool` / `CRON_TOOL_NAME` (see `tools/collapsed.rs` for why all six stay registered as hidden schemas behind the one advertised tool).-- RPC namespace `cron`: `add`, `list`, `update`, `remove`, `run`, `runs` — `schemas.rs` (re-exported via `all_cron_controller_schemas` / `all_cron_registered_controllers`).+- `pub mod scheduler` (`pub async fn run(config: Config)`) — `scheduler.rs`, split via `include!` into `scheduler_part_01.rs` (poll loop, `run`, failure classifiers), `scheduler_part_02.rs` (`execute_job_with_retry`, per-job-type execution, `run_agent_job`, `build_agent_for_cron_job`, `run_flow_schedule_job`) and `scheduler_part_03.rs` (`deliver_if_configured`, `run_job_command_with_timeout`).+- `pub mod scheduler_gate` — throttles *background* LLM work (memory digests, embeddings, summarisation) on host power / CPU signals via `current_policy()` / `wait_for_capacity()`. It lives here for historical reasons; the cron poll loop does not consult it, and its consumers are `modules/memory_host.rs` and `security/credentials/`. See its own [README](scheduler_gate/README.md).+- `pub mod seed` — `seed.rs` — `seed_proactive_agents` installs the built-in proactive jobs when onboarding flips to completed (`config/ops/ui.rs`); `prune_retired_jobs` removes rows for removed features on boot and workspace activation.+- `pub mod bus` — `bus.rs` — `CronDeliverySubscriber` (`cron::delivery`) consumes `CronDeliveryRequested` and sends through the named `tinychannels_bus::Channel`.+- `pub mod tools` — `tools.rs` + `tools/` — agent-facing tools: `CronAddTool`, `CronListTool`, `CronUpdateTool`, `CronRemoveTool`, `CronRunTool`, `CronRunsTool`, and the collapsed `CronTool` / `CRON_TOOL_NAME`. `tools/collapsed.rs` explains why the six stay registered as hidden schemas behind the one advertised tool; see also [tools/README.md](tools/README.md).+- RPC namespace `cron`: `add`, `list`, `update`, `remove`, `run`, `runs` — `schemas.rs` (aggregated as `all_cron_controller_schemas` / `all_cron_registered_controllers`).## Job types-- **`shell`** — runs a command under `SecurityPolicy::from_config`.+- **`shell`** — `run_job_command_with_timeout` refuses the command unless the scheduler's `SecurityPolicy` (built once in `scheduler::run` via `SecurityPolicy::from_config`) passes `can_act`, `is_rate_limited`, and `is_command_allowed`; a `blocked by security policy:` result is never retried.- **`agent`** — the scheduler builds an `Agent` directly and runs a turn (see below); it does not go through `agent::triage`.-- **`flow`** — a `flows::Flow` schedule-trigger binding created by `flows::ops::flows_set_enabled` via `add_flow_schedule_job`. Its `command` column carries the bound flow's id; on fire the scheduler publishes `DomainEvent::FlowScheduleTick { flow_id }` instead of running anything itself. `flows::bus::FlowTriggerSubscriber` does the actual dispatch. Never created via the `cron_add` agent tool.+- **`flow`** — a `flows::Flow` schedule-trigger binding. `flows/ops_part_06.rs::bind_schedule_trigger` creates it via `add_flow_schedule_job` (idempotent through `find_flow_schedule_job`) from both `flows_set_enabled` and `reconcile_schedule_triggers_on_boot`. Its `command` column carries the bound flow's id; on fire `run_flow_schedule_job` publishes `DomainEvent::FlowScheduleTick { flow_id }` instead of running anything itself. `flows::bus::FlowTriggerSubscriber` does the actual dispatch. Never created via the `cron_add` agent tool, whose `job_type` enum is `shell` / `agent` only.### Agent jobs-`scheduler_part_02.rs::run_agent_job` builds the `Agent` for a job: `Agent::from_config` by default, `Agent::from_config_for_agent` when `job.agent_id` names a registered definition, or `Agent::from_config_for_agent_with_profile` when a profile applies — the same profile-aware path `agent::profiles` and the interactive dispatcher use, so a cron run inherits the same tool/permission shape as an interactive session with that agent. A per-job `model` override is applied to a cloned `Config` before building. The built agent then runs the prefixed prompt (`[cron:<id> <name>] <prompt>`) as a normal turn; failures are classified (session-expired, insufficient-credits, security-policy) to decide whether the run is retried.+`run_agent_job` prefixes the prompt (`[cron:<id> <name>] <prompt>`), applies a per-job `model` override to a cloned `Config`, and, when `job.agent_id` names a definition in `AgentDefinitionRegistry`, applies that definition's model hint, iteration cap, and prompt body. `build_agent_for_cron_job` then picks the constructor: `Agent::from_config_for_agent_with_profile` when `job.profile_id` still resolves through `agent::profiles::load_profiles` (the same profile-aware path the task dispatcher uses, so the run inherits the profile's SOUL, memory scope, and tool/skill/MCP allowlists), `Agent::from_config_for_agent` when only `agent_id` is set (falling back to `Agent::from_config` if the definition fails to build), or `Agent::from_config` otherwise. A deleted profile is warned about and the job runs profile-less.++`execute_job_with_retry` wraps every job type with `config.reliability.scheduler_retries` attempts and exponential backoff. For agent jobs it classifies failures before retrying: backend session-expired, provider insufficient-credits (402), managed-backend budget-exhausted (400), API-key-unset, and local-LLM-unreachable all halt the loop immediately and suppress the retries-exhausted error report. The user-facing message is a canned string from `classify_agent_anyhow_for_user`; the raw error goes only to observability.## Event bus-Cron publishes through `core/bus.rs` using variants declared in `core/events.rs`: `DomainEvent::CronJobTriggered`, `CronJobCompleted`, `CronDeliveryRequested`, `ProactiveMessageRequested` (shared with the proactive-message pipeline), and `FlowScheduleTick`.+Cron publishes through `core/bus.rs` using variants declared in `core/events.rs`: `DomainEvent::CronJobTriggered` and `CronJobCompleted` (around each execution), `CronDeliveryRequested` and `ProactiveMessageRequested` (from `deliver_if_configured`; the latter is shared with the proactive-message pipeline), and `FlowScheduleTick`.## Calls into-- `crates/openhuman-core/src/agent/` — `Agent::from_config[_for_agent[_with_profile]]` for agent jobs; `agent::harness::definition::AgentDefinitionRegistry` to resolve `agent_id` overrides; `agent::profiles` for profile-aware construction.-- `crates/openhuman-core/src/security/` — `SecurityPolicy::from_config` sandboxes shell jobs.-- `crates/openhuman-core/src/config/` — `Config` provides poll interval, workspace dir, autonomy policy, and per-job model overrides.+- `crates/openhuman-core/src/agent/` — `Agent::from_config[_for_agent[_with_profile]]` for agent jobs; `agent::harness::definition::AgentDefinitionRegistry` to resolve `agent_id`; `agent::profiles::load_profiles` to resolve `profile_id`.+- `crates/openhuman-core/src/security/` — `SecurityPolicy::from_config` gates shell jobs.+- `crates/openhuman-core/src/config/` — `Config` provides poll interval, workspace dir, autonomy policy, retry counts, and per-job model overrides.- `crates/openhuman-core/src/inference/` — `provider::create_chat_model_with_model_id` resolves workload-hint model specs on agent-definition overrides.-- `crates/openhuman-core/src/platform/health/` — `health::bus::register_health_subscriber` on startup.-- `crates/openhuman-core/src/channels/` — `bus.rs` fans delivery events into channels; `channels::proactive` handles `ProactiveMessageRequested`.-- `crates/openhuman-core/src/flows/` — `flows::bus::FlowTriggerSubscriber` consumes `FlowScheduleTick`.+- `crates/openhuman-core/src/platform/health/` — `health::bus::register_health_subscriber` on scheduler startup.- `crates/openhuman-core/src/core/bus.rs` / `core/events.rs` — the process-wide event bus and `DomainEvent` variants cron publishes.## Called by-- `crates/openhuman-core/src/tools/impl/system/schedule.rs` — `schedule` tool exposes one-shot cron scheduling to agents.-- `crates/openhuman-core/src/core/all.rs` — controller registry wires `all_cron_*`.-- `crates/openhuman-core/src/flows/ops.rs` — `flows_set_enabled` creates/removes flow schedule jobs via `add_flow_schedule_job`.-- Channel and agent runtimes consume `Cron*` and `ProactiveMessageRequested` events via the bus.+- `crates/openhuman-core/src/core/runtime/services.rs` — spawns `cron::scheduler::run` as the `cron` background service (`ServiceSet::cron`).+- `crates/openhuman-core/src/core/all.rs` — controller registry wires `all_cron_registered_controllers`.+- `crates/openhuman-core/src/tools/impl/system/schedule.rs` — the `schedule` tool exposes recurring and one-shot scheduling to agents on top of `cron::{list_jobs, get_job, …}`.+- `crates/openhuman-core/src/channels/runtime/startup_part_01.rs` — registers `cron::bus::CronDeliverySubscriber` with the channel map; `channels::proactive::ProactiveMessageSubscriber` handles `ProactiveMessageRequested`.+- `crates/openhuman-core/src/flows/ops_part_06.rs` — `bind_schedule_trigger` / `unbind_schedule_trigger` create and remove flow schedule jobs; `flows::bus::FlowTriggerSubscriber` consumes `FlowScheduleTick`.+- `crates/openhuman-core/src/config/ops/ui.rs`, `desktop/app_state/`, `security/credentials/` — call `seed::seed_proactive_agents` / `seed::prune_retired_jobs`.## Delivery modes-A cron job's `DeliveryConfig.mode` decides where its output ends up:+A cron job's `DeliveryConfig.mode` decides where its output ends up. `DeliveryConfig::default()` is `none`; the `cron_add` tool substitutes `proactive` when an agent job is created without a `delivery` block.-- **`proactive`** (default for agent jobs) — `deliver_if_configured` publishes+- **`proactive`** — `deliver_if_configured` publishes`DomainEvent::ProactiveMessageRequested`. The proactive subscriber(`channels::proactive`) always pushes to the in-app web stream and additionallymirrors to `channels_config.active_channel` when set. Use for jobs whose@@ -64,8 +66,8 @@ A cron job's `DeliveryConfig.mode` decides where its output ends up:channel's `allowed_users` to reject cross-tenant targets.- **`none`** — silent; output is stored in `last_output` only.-The `[Channel context]` block injected by `channels::runtime::dispatch` for-non-web inbound turns instructs the model to default to `announce` with the+The `[Channel context]` block built in `channels/runtime/dispatch/helpers.rs`+for non-web inbound turns instructs the model to default to `announce` with thecurrent channel + reply target — that is the routing path for the Telegram"remind me to drink water" use case in #928.@@ -73,9 +75,9 @@ current channel + reply target — that is the routing path for the TelegramAn agent job is a full inference turn per run, so `schedule.rs` enforces a floorof `MIN_AGENT_JOB_INTERVAL` (5 minutes) between consecutive runs of an agent job.-`validate_agent_schedule` is applied by `add_agent_job*` and by `update_job`-whenever an agent job's schedule is set, so every creation path (`cron_add`-tool, `cron.add` RPC, the one-shot `schedule` tool, the settings form) gets the+`validate_agent_schedule` is applied in `store.rs` by `add_agent_job*` and by+`update_job` whenever an agent job's schedule is set, so every creation path+(`cron_add` tool, `cron.add` / `cron.update` RPC, the `schedule` tool) gets thesame rejection, and the message names the two runs that would be too close.Shell and flow jobs are not subject to it.@@ -89,6 +91,6 @@ that evidence on each run instead (#6158).## Tests-- Unit: `ops_tests.rs`, `scheduler_tests_part_01_tests.rs` .. `_04_tests.rs`, `store_tests.rs` + `store_tests_part_01_tests.rs`, `schedule_tests.rs`, `types_tests.rs`, `seed_tests.rs`, `bus_tests.rs`.-- Schema/parsing coverage lives inside `schemas_tests.rs`.-- Tool coverage: `cron::tools::{add,list,remove,run,runs,update}::tests` and `collapsed_tests.rs` (announce-mode `allowed_users` checks, action dispatch, permission resolution).+- Unit: `ops_tests.rs`, `scheduler_tests.rs` (shared fixtures; `#[path]`-includes `scheduler_tests_part_01_tests.rs` .. `_04_tests.rs`), `store_tests.rs` (+ `store_tests_part_01_tests.rs`), `schedule_tests.rs`, `types_tests.rs`, `seed_tests.rs`, `bus_tests.rs`.+- Schema/parsing coverage lives in `schemas_tests.rs`.+- Tool coverage: `tools/{add,list,remove,run,runs,update}_tests.rs` (announce-mode `allowed_users` checks live in `add_tests.rs`) and `tools/collapsed_tests.rs` (action enum, merged schema, per-action permission resolution).