kaeru 0.1.0

Reopens your terminal tabs, and the coding agent sessions in them, after the terminal closes or the computer restarts.
//! The user's options, which the picker's options screen and
//! `kaeru install` change. They are kept in `config.toml`, whose place
//! docs/architecture.md gives.

use serde::{Deserialize, Serialize};

use crate::engine::rules::SingleWindowClose;

/// The user's options. A missing option has its default value, so that a
/// config file from an older version keeps working.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default, rename_all = "kebab-case")]
pub struct Config {
    /// Whether tabs that ran an agent session are offered, to come back with
    /// the session resumed.
    pub offer_agents: bool,
    /// Whether tabs that ran only a shell are offered.
    pub offer_shells: bool,
    /// Whether the first new tab shows the picker when tabs are waiting.
    /// Without it, new tabs only mention them.
    pub ask_on_start: bool,
    /// What closing a single-window terminal means.
    pub single_window_close: SingleWindowClose,
    /// Whether the tabs that kaeru tracks start Codex with `--no-daemon`, so
    /// that its sessions run in their tab and kaeru knows exactly which tab
    /// each one is in. `kaeru install` asks about it.
    pub codex_no_daemon: bool,
}

impl Default for Config {
    fn default() -> Self {
        Config {
            offer_agents: true,
            offer_shells: true,
            ask_on_start: true,
            single_window_close: SingleWindowClose::Forget,
            codex_no_daemon: false,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn missing_options_have_their_defaults() {
        let config: Config = toml::from_str("offer-shells = false").unwrap();
        assert_eq!(
            config,
            Config {
                offer_shells: false,
                ..Config::default()
            }
        );
    }

    #[test]
    fn options_survive_a_round_trip_through_toml() {
        let config = Config {
            ask_on_start: false,
            single_window_close: SingleWindowClose::Offer,
            codex_no_daemon: true,
            ..Config::default()
        };
        let text = toml::to_string(&config).unwrap();
        assert!(text.contains("single-window-close = \"offer\""));
        assert!(text.contains("codex-no-daemon = true"));
        assert_eq!(toml::from_str::<Config>(&text).unwrap(), config);
    }
}