neosian 3.0.2

The state layer for LLM agents, as one static binary: the record, memory and the state process
//! The exact sign-in answers of the clients whose failures are plain text:
//! Cursor's, Vibe's and Muse Code's (X5b, X6a, X6b).

/// `muse usage --json` signed out (captured, record/investigation-2026-11-29/
/// streams/muse-usage-signed-out.stderr.txt).
pub(super) const MUSE_SIGNED_OUT: &str = "muse usage: not logged in: run `muse login` first";
/// A Muse turn without credentials: exit 1, nothing on stdout, this line on
/// stderr, then the configuration path (captured, muse-signed-out.stderr.txt).
pub(super) const MUSE_TURN_SIGNED_OUT: &str =
    "missing meta credentials: run `muse login` or set META_API_KEY";

const CURSOR_EXPIRED: &str = "Authentication failed: your Cursor credentials or API key are invalid or expired.\nIf you set CURSOR_API_KEY, check that it is correct, or run `cursor-agent login` to re-authenticate.";

/// Cursor's `models` without a usable sign-in: no credential at all
/// (captured on a stale sign-in, record/x5b-2026-11-28/captures), or one
/// refused as invalid or expired (its source). The command name in quotes
/// is the one Cursor was invoked as.
pub(super) fn cursor_signed_out(stderr: &str) -> bool {
    let said = stderr.trim();
    let missing = said
        .strip_prefix("Error: Authentication required. Run '")
        .is_some_and(|rest| {
            rest.ends_with(
                " login', pass --api-key/--auth-token, or set CURSOR_API_KEY/CURSOR_AUTH_TOKEN.",
            ) && !rest.contains('\n')
        });
    missing || said == CURSOR_EXPIRED
}

/// Cursor's print mode without a usable sign-in: empty stdout, exit 1 and
/// this line on stderr (captured, record/investigation-2026-11-28/streams/
/// cursor-agent-auth-error.txt), with the command name it was invoked as.
pub(super) fn cursor_turn_signed_out(line: &str) -> bool {
    line.strip_prefix("Error: Authentication required. Please run '")
        .and_then(|rest| {
            rest.strip_suffix(" login' first, or set CURSOR_API_KEY environment variable.")
        })
        .is_some_and(|name| !name.is_empty() && !name.contains(char::is_whitespace))
}

/// Vibe without a key for the model's provider: exit 1, nothing on stdout,
/// and this line on stderr (captured for Mistral, record/investigation-
/// 2026-11-28/streams/vibe-signed-out.stderr.txt; other providers name
/// their own variable).
pub(super) fn vibe_turn_signed_out(line: &str) -> bool {
    let named =
        |word: &str, allowed: fn(char) -> bool| !word.is_empty() && word.chars().all(allowed);
    line.strip_prefix("Error: Missing ")
        .and_then(|rest| rest.strip_suffix(" provider"))
        .and_then(|rest| rest.split_once(" environment variable for "))
        .is_some_and(|(var, provider)| {
            named(var, |c| {
                c.is_ascii_uppercase() || c.is_ascii_digit() || c == '_'
            }) && named(provider, |c| {
                c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-'
            })
        })
}