pitboard-core 0.22.0

The engine behind Pitboard: switches Claude Code, Codex and Claude Desktop between accounts by parking and restoring their logins. Its API serves Pitboard's own front ends.
Documentation
//! Where Antigravity keeps its login (`agy_login_item`, `agy_token_files`).

use crate::context::{Context, Environment};
use crate::host::Os;
use std::path::PathBuf;

/// go-keyring's user for Antigravity's login, under [`service`].
pub(crate) const USER: &str = "antigravity";

/// The service agy keeps its login under. A test's own, where it named one.
pub(crate) fn service(ctx: &Context) -> String {
    #[cfg(any(test, feature = "test-support"))]
    if let Some(service) = &ctx.agy_service {
        return service.clone();
    }
    let _ = ctx;
    "gemini".to_owned()
}

/// `.gemini` in the home, where every surface keeps its files: `HOME`, or `USERPROFILE` on
/// Windows, as Go's `os.UserHomeDir` reads them.
pub(crate) fn gemini_dir(ctx: &Context) -> PathBuf {
    ctx.home.join(".gemini")
}

/// The CLI's own token file, with its default `--gemini_dir` and `--app_data_dir`.
pub(crate) fn cli_file(ctx: &Context) -> PathBuf {
    gemini_dir(ctx)
        .join("antigravity-cli")
        .join("antigravity-oauth-token")
}

/// The language server's, which the App, `agy --hub` and the server inside the CLI read.
pub(crate) fn server_file(ctx: &Context) -> PathBuf {
    gemini_dir(ctx).join("jetski-standalone-oauth-token")
}

/// The files that say agy found its keyring wanting and keeps its login in its token files.
pub(crate) fn markers(ctx: &Context) -> [PathBuf; 2] {
    let marker = "antigravity-keyring-unavailable";
    [
        gemini_dir(ctx)
            .join("antigravity-cli")
            .join("cache")
            .join(marker),
        gemini_dir(ctx).join("cache").join(marker),
    ]
}

/// Whether agy, started with `env`, keeps its login in files alone whatever its keyring holds
/// (`agy_files_only`): `AGY_CLI_FORCE_FILE_TOKEN_STORAGE` true, and on Linux no session bus,
/// a sign-in over SSH, or WSL.
pub(crate) fn files_only(env: &Environment) -> bool {
    let forced = env
        .text("AGY_CLI_FORCE_FILE_TOKEN_STORAGE")
        .is_some_and(|value| matches!(value, "1" | "t" | "T" | "true" | "TRUE" | "True"));
    let linux_without = env.os() == Os::Linux
        && (env
            .text("DBUS_SESSION_BUS_ADDRESS")
            .is_none_or(str::is_empty)
            || ["SSH_TTY", "SSH_CLIENT", "SSH_CONNECTION"]
                .into_iter()
                .any(|name| env.set(name))
            || ["WSL_DISTRO_NAME", "WSL_INTEROP"]
                .into_iter()
                .any(|name| env.set(name)));
    forced || linux_without
}

/// Where agy's installer puts it (getting-started page, read on 28 November 2026).
pub(crate) fn install_places(env: &Environment) -> Vec<PathBuf> {
    let standalone = match env.os() {
        Os::MacOs | Os::Linux => Some(env.home().join(".local").join("bin")),
        Os::Windows => env.named_folder("LOCALAPPDATA").map(|mut dir| {
            dir.extend(["agy", "bin"]);
            dir
        }),
    };
    standalone
        .into_iter()
        .chain(env.os().package_bins(env))
        .collect()
}

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

    #[test]
    fn agy_keeps_files_alone_where_its_environment_says() {
        let on = |os, vars: &[(&str, &str)]| files_only(&Environment::on(os, vars.to_vec()));
        let bus = ("DBUS_SESSION_BUS_ADDRESS", "unix:path=/run/user/1000/bus");
        assert!(!on(Os::MacOs, &[]));
        assert!(!on(Os::Linux, &[bus]));
        assert!(on(Os::Linux, &[]), "no session bus");
        assert!(on(Os::Linux, &[bus, ("SSH_CONNECTION", "a b c d")]));
        assert!(on(Os::Linux, &[bus, ("WSL_DISTRO_NAME", "Ubuntu")]));
        assert!(on(
            Os::MacOs,
            &[("AGY_CLI_FORCE_FILE_TOKEN_STORAGE", "true")]
        ));
        assert!(!on(
            Os::Windows,
            &[("AGY_CLI_FORCE_FILE_TOKEN_STORAGE", "no")]
        ));
        assert!(
            !on(Os::MacOs, &[("SSH_CONNECTION", "a b c d")]),
            "Linux's rule only"
        );
    }
}