agcli/lib.rs
1#![allow(clippy::pedantic)]
2//! Agent-native CLI primitives for Rust.
3//!
4//! This crate enforces an agent-first response model:
5//! - JSON envelopes for every command
6//! - HATEOAS `next_actions` for follow-up affordances
7//! - self-documenting command tree from root/help
8//! - NDJSON streaming helpers with terminal result/error events
9//! - context-safe truncation helpers for large output
10//!
11//! # Example
12//!
13//! ```no_run
14//! use agcli::{AgentCli, Command, CommandOutput, ExecutionContext, NextAction};
15//! use serde_json::json;
16//!
17//! let cli = AgentCli::new("ops", "Agent-native operations CLI")
18//! .command(
19//! Command::new("status", "System health")
20//! .usage("ops status")
21//! .handler(|_req, _ctx| {
22//! Ok(CommandOutput::new(json!({ "healthy": true })).next_action(
23//! NextAction::new("ops status", "Re-check health"),
24//! ))
25//! }),
26//! );
27//!
28//! let mut _ctx = ExecutionContext::default();
29//! let run = cli.run_argv(["ops", "status"]);
30//! assert_eq!(run.exit_code(), 0);
31//! ```
32
33mod cli;
34mod envelope;
35mod stream;
36mod truncate;
37
38pub use cli::{
39 AgentCli, Command, CommandError, CommandOutput, CommandRequest, Execution, ExecutionContext,
40 Invocation, ParseInvocationError, parse_invocation,
41};
42pub use envelope::{ActionParam, Envelope, ErrorBody, ErrorEnvelope, NextAction, SuccessEnvelope};
43pub use stream::{LogLevel, NdjsonEmitter, StepStatus, StreamEmitError, StreamEvent};
44pub use truncate::{TruncatedEntries, truncate_lines_with_file};