llmr 0.1.0

Reach language models across providers, with capabilities you can read before you ask and usage you can trust.
Documentation
//! The Claude Code command line tool.
//!
//! Signs in on this machine and sends every prompt to Anthropic, which is why its reach is
//! [`crate::Reach::LocalCli`] rather than self hosted: the credential is local and the data
//! is not.

use crate::providers::cli::{Envelope, LocalCli, UsageNames};
use std::time::Duration;

/// The program this preset runs.
pub const PROGRAM: &str = "claude";

/// What `claude --output-format json` prints.
///
/// The answer is at `/result` and the usage at `/usage`, spelled the way Anthropic spells it
/// everywhere else.
pub fn envelope() -> Envelope {
    Envelope::at("/result").with_usage("/usage", UsageNames::anthropic())
}

/// A provider that runs the Claude Code tool.
///
/// JSON mode, deliberately. In plain mode the whole document is the answer and the call
/// reports as unmeasured, which every cost report reads as free.
///
/// It knows no models until you name them. A command line tool cannot be asked what it
/// serves, so a provider that answered for every name would turn a typo into a real model.
///
/// [`llmr::Provider::validate`](crate::Provider::validate) probes with `--version`, which
/// establishes that the tool is installed and nothing about the login inside it. That is all
/// this tool answers for free, and a `Ready` from here should be read as no more than that.
///
/// ```no_run
/// use llmr::providers::anthropic::cli;
/// use llmr::{ChatRequest, Message, Provider};
/// use std::time::Duration;
///
/// # async fn example() -> llmr::Result<()> {
/// let claude = cli::provider(Duration::from_secs(300))
///     .serving(["claude-sonnet-5"]);
///
/// let reply = claude
///     .chat(ChatRequest::new("claude-sonnet-5", vec![Message::user("Hello")]))
///     .await?;
/// # Ok(())
/// # }
/// ```
pub fn provider(timeout: Duration) -> LocalCli {
    LocalCli::new(
        "claude-cli",
        PROGRAM,
        ["-p", "--output-format", "json"],
        timeout,
    )
    .reading(envelope())
    .with_model_flag("--model")
    .with_probe(["--version"])
}

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

    #[test]
    fn the_preset_is_probed() {
        // A preset that shipped without one would answer unknown for every user who never
        // read this far, which is the same as not having the method at all.
        //
        // This lives here rather than in `providers::cli` because it is a fact about this
        // preset, not about the runner. The runner's tests are about the runner.
        assert!(provider(Duration::from_secs(60)).probe.is_some());
    }
}