artifactize-provider 0.29.0

Managed credentials, model discovery and direct HTTP turns for Artifactize.
Documentation
//! The agent catalog both stacks read: every coding-agent CLI artifactize knows, how a person
//! signs in to it, how its Chat runs over ACP and how its Review runs, and the API providers
//! artifactize calls itself. It is static data: nothing here starts a process.

use crate::names::HttpProvider;

/// A coding-agent CLI. A person sets it up by signing in to the CLI itself; what it can do
/// (Chat, Review) follows from this entry, never from a switch.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Agent {
    /// The catalog ID: a Chat target's agent and, for an agent that can review, an eval's
    /// `backend`.
    pub id: &'static str,
    pub name: &'static str,
    /// The CLI the person installs and signs in to.
    pub program: &'static str,
    /// Who keeps the login: the CLI itself, never artifactize.
    pub kept_by: &'static str,
    /// Where the CLI's own installation instructions are.
    pub install_url: &'static str,
    pub sign_in: SignIn,
    pub chat: Chat,
    pub review: Review,
}

/// How a person signs in to an agent's CLI.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SignIn {
    /// The CLI has commands of its own for each step: the arguments after its program.
    Commands {
        status: &'static [&'static str],
        login: &'static [&'static str],
        logout: &'static [&'static str],
    },
    /// The CLI signs in through its ACP mode, with these arguments after its program.
    Acp { login: &'static [&'static str] },
    /// The CLI signs in only in its own interactive terminal: the person runs this there.
    Terminal { command: &'static str },
}

/// How an agent's Chat runs over ACP.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Chat {
    /// The CLI speaks ACP itself, with these arguments after its program.
    Native { args: &'static [&'static str] },
    /// A separate adapter program speaks ACP for the CLI; `registry` is its official ACP
    /// Registry ID, from which a pinned version is installed when it is not on the `PATH`.
    Adapter {
        program: &'static str,
        registry: &'static str,
    },
}

/// How an agent's Review runs.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Review {
    /// An artifactize reviewer harness runs it, under the CLI's own sign-in.
    Harness(Harness),
    /// It cannot review; the reason is shown beside *Chat only*.
    ChatOnly { reason: &'static str },
}

/// The reviewer harnesses artifactize has.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Harness {
    /// Claude Code in stream-json mode, isolated, under Claude Code's own sign-in.
    ClaudeCode,
    /// The provider's turn driver over the Codex API, with the Codex CLI's own sign-in.
    Codex,
}

/// The built-in agents, in the order Settings lists them.
pub const AGENTS: &[Agent] = &[
    Agent {
        id: "claude",
        name: "Claude",
        program: "claude",
        kept_by: "Claude Code",
        install_url: "https://docs.anthropic.com/en/docs/claude-code/setup",
        sign_in: SignIn::Commands {
            status: &["auth", "status", "--json"],
            login: &["auth", "login"],
            logout: &["auth", "logout"],
        },
        chat: Chat::Adapter {
            program: "claude-agent-acp",
            registry: "claude-acp",
        },
        review: Review::Harness(Harness::ClaudeCode),
    },
    Agent {
        id: "codex",
        name: "Codex",
        program: "codex",
        kept_by: "Codex CLI",
        install_url: "https://developers.openai.com/codex/cli",
        sign_in: SignIn::Commands {
            status: &["login", "status"],
            login: &["login"],
            logout: &["logout"],
        },
        chat: Chat::Adapter {
            program: "codex-acp",
            registry: "codex-acp",
        },
        review: Review::Harness(Harness::Codex),
    },
    Agent {
        id: "antigravity",
        name: "Antigravity",
        program: "agy",
        kept_by: "Antigravity CLI",
        install_url: "https://antigravity.google/",
        sign_in: SignIn::Acp {
            login: &["acp", "--login"],
        },
        chat: Chat::Native { args: &["acp"] },
        review: Review::ChatOnly {
            reason: "Antigravity allows no third-party harness.",
        },
    },
    Agent {
        id: "opencode",
        name: "OpenCode",
        program: "opencode",
        kept_by: "OpenCode",
        install_url: "https://opencode.ai/docs/",
        sign_in: SignIn::Terminal {
            command: "opencode auth login",
        },
        chat: Chat::Native { args: &["acp"] },
        review: Review::ChatOnly {
            reason: "artifactize has no reviewer harness for OpenCode yet.",
        },
    },
    Agent {
        id: "copilot",
        name: "Copilot",
        program: "copilot",
        kept_by: "GitHub Copilot CLI",
        install_url: "https://docs.github.com/copilot/how-tos/set-up/install-copilot-cli",
        sign_in: SignIn::Terminal {
            command: "copilot, then /login",
        },
        chat: Chat::Native { args: &["--acp"] },
        review: Review::ChatOnly {
            reason: "artifactize has no reviewer harness for Copilot yet.",
        },
    },
    Agent {
        id: "cursor",
        name: "Cursor",
        program: "cursor-agent",
        kept_by: "Cursor Agent",
        install_url: "https://cursor.com/docs/cli/installation",
        sign_in: SignIn::Commands {
            status: &["status"],
            login: &["login"],
            logout: &["logout"],
        },
        chat: Chat::Native { args: &["acp"] },
        review: Review::ChatOnly {
            reason: "artifactize has no reviewer harness for Cursor yet.",
        },
    },
    Agent {
        id: "goose",
        name: "Goose",
        program: "goose",
        kept_by: "Goose",
        install_url: "https://block.github.io/goose/docs/getting-started/installation",
        sign_in: SignIn::Terminal {
            command: "goose configure",
        },
        chat: Chat::Native { args: &["acp"] },
        review: Review::ChatOnly {
            reason: "artifactize has no reviewer harness for Goose yet.",
        },
    },
    Agent {
        id: "pi",
        name: "pi",
        program: "pi",
        kept_by: "pi",
        install_url: "https://www.npmjs.com/package/@earendil-works/pi-coding-agent",
        sign_in: SignIn::Terminal {
            command: "pi, then /login",
        },
        chat: Chat::Adapter {
            program: "pi-acp",
            registry: "pi-acp",
        },
        review: Review::ChatOnly {
            reason: "artifactize has no reviewer harness for pi yet.",
        },
    },
];

/// Earlier names of built-in agents, still accepted where a saved name or a declaration
/// carries one: an eval's `backend = "claude-agent"` and Chat's retired ACP preset IDs.
const FORMER_IDS: &[(&str, &str)] = &[
    ("claude-agent", "claude"),
    ("claude-acp", "claude"),
    ("codex-acp", "codex"),
];

/// The built-in agent with this ID, or with an earlier name of it.
pub fn agent(id: &str) -> Option<&'static Agent> {
    let id = FORMER_IDS
        .iter()
        .find_map(|(former, current)| (*former == id).then_some(*current))
        .unwrap_or(id);
    AGENTS.iter().find(|agent| agent.id == id)
}

/// The built-in agent that reviews with this harness.
pub fn reviewer(harness: Harness) -> &'static Agent {
    AGENTS
        .iter()
        .find(|agent| agent.review == Review::Harness(harness))
        .expect("every harness belongs to one built-in agent")
}

/// An API provider artifactize calls itself, for Chat and Review alike.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ApiProvider {
    pub provider: HttpProvider,
    pub name: &'static str,
}

/// The built-in API providers, in the order Settings lists them. Codex is an agent, not an
/// API provider: its Review uses the Codex CLI's sign-in and its Chat runs over ACP.
pub const API_PROVIDERS: &[ApiProvider] = &[
    ApiProvider {
        provider: HttpProvider::Openai,
        name: "OpenAI",
    },
    ApiProvider {
        provider: HttpProvider::Anthropic,
        name: "Anthropic",
    },
    ApiProvider {
        provider: HttpProvider::Gemini,
        name: "Gemini API",
    },
];

#[cfg(test)]
mod tests;