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
//! Whether anything holds a tool's login, for a tool whose login moves only while nothing
//! does: an app that writes its own back as it quits, or a program that renews it from memory.

use crate::context::Context;
use crate::host::Listed;

pub(crate) enum Open {
    No,
    Yes(Vec<Listed>),
    // why the process list did not read
    Unknown(String),
}

/// What of this user's processes `holds` counts: one list, read once, so a process that starts
/// between two looks is never half counted.
pub(crate) fn open(ctx: &Context, holds: impl Fn(&Listed, &[Listed]) -> bool) -> Open {
    let all = match ctx.host().listing() {
        Ok(all) => all,
        Err(why) => return Open::Unknown(why),
    };
    let running: Vec<Listed> = all.iter().filter(|one| holds(one, &all)).cloned().collect();
    if running.is_empty() {
        Open::No
    } else {
        Open::Yes(running)
    }
}

/// Each process `listed`, as a sentence names one: `agy (pid 812)`.
pub(crate) fn named(listed: &[Listed]) -> Vec<String> {
    listed
        .iter()
        .map(|one| {
            let name = one.path.file_name().unwrap_or(one.path.as_os_str());
            format!("{} (pid {})", name.to_string_lossy(), one.pid)
        })
        .collect()
}