Files
optimclaw/src/config/routines.rs
T
Illia PolosukhinandClaude Opus 4.6 f1fa303abc feat(config): unify all settings to DB > env > default priority
Previously only LLM settings used DB-first priority while all other
subsystems (agent, channels, tunnel, heartbeat, embeddings, sandbox,
wasm, safety, builder, transcription, routines, skills, hygiene,
search) used env-first. This made web UI settings changes unreliable
for non-LLM config — env vars would silently override DB values.

Now all subsystems follow the same priority: DB > env > TOML > default.

- Add db_first_or_default, db_first_bool, db_first_optional_string,
  db_first_option helpers to config/helpers.rs with shadow warnings
- Flip 10 Group 1 resolvers (agent, channels, tunnel, heartbeat,
  embeddings, sandbox, wasm, safety, builder, transcription) from
  parse_optional_env/parse_bool_env to db_first_* equivalents
- Add Settings structs for 4 Group 2 resolvers (routines, skills,
  hygiene, search) that previously had no DB persistence
- Update Config::build() call sites and cli/doctor.rs caller
- Security-sensitive fields stay env-only: allow_local_tools,
  allow_full_access, cost/rate limits, auth tokens, API keys
- Bootstrap configs (database, secrets) stay env-only

Closes #1119 (partial — config unification phases 1-2)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
2026-03-27 23:04:14 -07:00

79 lines
2.9 KiB
Rust

use crate::config::helpers::{db_first_bool, db_first_or_default};
use crate::error::ConfigError;
use crate::settings::Settings;
/// Routines configuration.
#[derive(Debug, Clone)]
pub struct RoutineConfig {
/// Whether the routines system is enabled.
pub enabled: bool,
/// How often (seconds) to poll for cron routines that need firing.
pub cron_check_interval_secs: u64,
/// Max routines executing concurrently across all users.
pub max_concurrent_routines: usize,
/// Default cooldown between fires (seconds).
pub default_cooldown_secs: u64,
/// Max output tokens for lightweight routine LLM calls.
pub max_lightweight_tokens: u32,
/// Enable tool execution in lightweight routines (default: true).
pub lightweight_tools_enabled: bool,
/// Max tool iterations for lightweight routines (default: 3, max: 5).
pub lightweight_max_iterations: u32,
}
impl Default for RoutineConfig {
fn default() -> Self {
Self {
enabled: true,
cron_check_interval_secs: 15,
max_concurrent_routines: 10,
default_cooldown_secs: 300,
max_lightweight_tokens: 4096,
lightweight_tools_enabled: true,
lightweight_max_iterations: 3,
}
}
}
impl RoutineConfig {
pub(crate) fn resolve(settings: &Settings) -> Result<Self, ConfigError> {
let defaults = crate::settings::RoutineSettings::default();
let rs = &settings.routines;
let max_iterations: u32 = db_first_or_default(
&rs.lightweight_max_iterations,
&defaults.lightweight_max_iterations,
"ROUTINES_LIGHTWEIGHT_MAX_ITERATIONS",
)?;
Ok(Self {
enabled: db_first_bool(rs.enabled, defaults.enabled, "ROUTINES_ENABLED")?,
cron_check_interval_secs: db_first_or_default(
&rs.cron_check_interval_secs,
&defaults.cron_check_interval_secs,
"ROUTINES_CRON_INTERVAL",
)?,
max_concurrent_routines: db_first_or_default(
&rs.max_concurrent_routines,
&defaults.max_concurrent_routines,
"ROUTINES_MAX_CONCURRENT",
)?,
default_cooldown_secs: db_first_or_default(
&rs.default_cooldown_secs,
&defaults.default_cooldown_secs,
"ROUTINES_DEFAULT_COOLDOWN",
)?,
max_lightweight_tokens: db_first_or_default(
&rs.max_lightweight_tokens,
&defaults.max_lightweight_tokens,
"ROUTINES_MAX_TOKENS",
)?,
lightweight_tools_enabled: db_first_bool(
rs.lightweight_tools_enabled,
defaults.lightweight_tools_enabled,
"ROUTINES_LIGHTWEIGHT_TOOLS",
)?,
lightweight_max_iterations: max_iterations.min(5), // cap at 5
})
}
}