Skip to main content

trustee_core/
config.rs

1//! Configuration parsing for trustee-core.
2//!
3//! Parses `[tui.auto_handoff]` settings from merged TOML config.
4
5use crate::types::AutoHandoffConfig;
6
7/// Parse auto-handoff configuration from a TOML config string.
8///
9/// Reads `[tui.auto_handoff]` section for `enabled` and `context_threshold`.
10/// Returns default values if the section is missing or malformed.
11pub fn parse_auto_handoff_config(config_toml: &str) -> AutoHandoffConfig {
12    let mut config = AutoHandoffConfig::default();
13
14    if let Ok(table) = config_toml.parse::<toml::Value>() {
15        if let Some(tui) = table.get("tui").and_then(|v| v.as_table()) {
16            if let Some(ah) = tui.get("auto_handoff").and_then(|v| v.as_table()) {
17                if let Some(enabled) = ah.get("enabled").and_then(|v| v.as_bool()) {
18                    config.enabled = enabled;
19                }
20                if let Some(threshold) = ah.get("context_threshold").and_then(|v| v.as_integer()) {
21                    config.context_threshold = threshold as usize;
22                }
23            }
24        }
25    }
26
27    config
28}