pub fn policy_auto_approves(policy: &str) -> bool {
matches!(policy, "auto-always" | "auto-session")
}
pub fn check_approval_policy() -> Option<(bool, bool)> {
match crate::config::Config::load() {
Ok(cfg) => {
if policy_auto_approves(&cfg.agent.approval_policy) {
tracing::debug!(
"Approval policy is '{}' — auto-approving",
cfg.agent.approval_policy
);
Some((true, true))
} else {
None
}
}
Err(e) => {
tracing::warn!("Failed to load config for approval check: {}", e);
None
}
}
}
pub fn persist_auto_session_policy() {
match crate::config::Config::write_key("agent", "approval_policy", "auto-session") {
Ok(_) => tracing::info!("Persisted approval_policy = auto-session to config.toml"),
Err(e) => tracing::error!("Failed to persist approval_policy to config.toml: {}", e),
}
}
pub fn persist_auto_always_policy() {
match crate::config::Config::write_key("agent", "approval_policy", "auto-always") {
Ok(_) => tracing::info!("Persisted approval_policy = auto-always to config.toml"),
Err(e) => tracing::error!("Failed to persist approval_policy to config.toml: {}", e),
}
}