rho-coding-agent 3.13.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
//! Which login session the daemon runs in, where the OS has more than one
//! kind (macOS): the user's GUI login, or a session without GUI access such
//! as an ssh login's. macOS lets only processes in the GUI login use the
//! login keychain, so `gh`, 1Password's SSH agent, and every other keychain
//! reader fail in a daemon outside it.
//!
//! A restart in place keeps the daemon's session, so a daemon started from
//! an ssh login stays outside the GUI login until it is stopped and started
//! again from where a new daemon lands in it ([`restart_moves_into_gui`]).

use serde::{Deserialize, Serialize};

use super::{lock::DaemonRecord, platform};

/// The login session a process runs in on macOS.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub(crate) enum LoginSession {
    /// The user's GUI login (launchd's `Aqua` session), where processes can
    /// use the login keychain.
    Gui,
    /// A session without GUI access, as an ssh login's (launchd's
    /// `Background` session), where they cannot.
    Background,
}

/// Whether restarting the daemon `record` names in place would keep it
/// outside the user's GUI login, while a daemon started from this process
/// would run in it. `rho daemon restart` then stops it and starts one
/// instead, and `rho doctor` says so.
pub(crate) fn restart_moves_into_gui(record: &DaemonRecord) -> bool {
    record.session == Some(LoginSession::Background)
        && platform::session_of_new_daemon() == Some(LoginSession::Gui)
}