cli_agents/lib.rs
1//! # cli-agents
2//!
3//! Build agentic apps on top of your users' existing AI subscriptions.
4//!
5//! Instead of requiring API keys or managing token costs, `cli-agents` spawns
6//! the AI CLI tools users already have installed — Claude Code, Codex, or
7//! Gemini CLI — and provides a unified interface for streaming events,
8//! tool calls, cancellation, and structured results.
9//!
10//! ## Quick start
11//!
12//! ```no_run
13//! use cli_agents::{run, RunOptions, StreamEvent, CliName};
14//! use std::sync::Arc;
15//!
16//! #[tokio::main]
17//! async fn main() {
18//! let opts = RunOptions {
19//! cli: Some(CliName::Claude),
20//! task: "What is 2+2?".into(),
21//! skip_permissions: true,
22//! ..Default::default()
23//! };
24//!
25//! let handle = run(opts, Some(Arc::new(|event: StreamEvent| {
26//! match &event {
27//! StreamEvent::TextDelta { text } => print!("{text}"),
28//! StreamEvent::Done { result } => println!("\n\nDone: {:?}", result.success),
29//! _ => {}
30//! }
31//! })));
32//!
33//! let result = handle.result.await.unwrap().unwrap();
34//! println!("Success: {}", result.success);
35//! }
36//! ```
37
38pub mod adapters;
39pub mod discovery;
40pub mod error;
41pub mod events;
42pub mod runner;
43pub mod types;
44
45/// Default max stdout buffer size: 10 MB.
46///
47/// Shared across all adapters to prevent OOM if a CLI produces unexpectedly
48/// large output. Override per-run via [`RunOptions::max_output_bytes`].
49pub const DEFAULT_MAX_OUTPUT_BYTES: usize = 10 * 1024 * 1024;
50
51// Re-export primary API
52pub use error::{Error, Result};
53pub use events::{Severity, StreamEvent};
54pub use runner::{RunHandle, run};
55pub use types::{
56 ClaudeOptions, CliName, CodexOptions, GeminiOptions, McpServer, McpTransport, ProviderOptions,
57 RunOptions, RunResult, RunStats,
58};