loopflow 0.9.10

Run steps and flows with coding agents
Documentation
use serde::Deserialize;
use std::path::PathBuf;

#[derive(Deserialize)]
struct Credentials {
    jwt: Option<String>,
    token: Option<String>,
}

/// Load JWT from `~/.lf/credentials.json`.
///
/// Checks both `jwt` and `token` fields, returns first non-empty one.
pub fn load_jwt() -> Option<String> {
    let credentials_path = credentials_path();
    if !credentials_path.exists() {
        return None;
    }

    let content = std::fs::read_to_string(&credentials_path).ok()?;
    let creds: Credentials = serde_json::from_str(&content).ok()?;

    creds
        .jwt
        .or(creds.token)
        .filter(|t| !t.trim().is_empty())
        .map(|t| t.trim().to_string())
}

fn credentials_path() -> PathBuf {
    dirs::home_dir()
        .unwrap_or_else(|| PathBuf::from("."))
        .join(".lf")
        .join("credentials.json")
}