Expand description
Agent-native CLI primitives for Rust.
This crate enforces an agent-first response model:
- JSON envelopes for every command
- HATEOAS
next_actionsfor follow-up affordances - self-documenting command tree from root/help
- NDJSON streaming helpers with terminal result/error events
- context-safe truncation helpers for large output
§Example
ⓘ
use agcli::{AgentCli, Command, CommandOutput, ExecutionContext, NextAction};
use serde_json::json;
#[tokio::main]
async fn main() {
let cli = AgentCli::new("ops", "Agent-native operations CLI")
.command(
Command::new("status", "System health")
.usage("ops status")
.handler(|_req, _ctx| Box::pin(async move {
Ok(CommandOutput::new(json!({ "healthy": true })).next_action(
NextAction::new("ops status", "Re-check health"),
))
})),
);
let mut ctx = ExecutionContext::default();
let run = cli.run_argv_with_context(["ops", "status"], &mut ctx).await;
assert_eq!(run.exit_code(), 0);
}Structs§
- Action
Param - Metadata for a templated
next_actionparameter. - Agent
Cli - Agent-native CLI runtime.
- Audit
Finding - A single problem discovered by
crate::AgentCli::audit. - Audit
Report - The result of a static audit pass.
- Check
- A single named health check with the exit code to use if it fails.
- Check
Result - Outcome of a single
Check. - Command
- CLI command definition.
- Command
Error - Error payload returned from a command handler.
- Command
Output - Success payload returned from a command handler.
- Command
Request - Runtime request passed to each command handler.
- Error
Body - Machine-readable error payload.
- Error
Envelope - Error response envelope.
- Execution
- Executed CLI result wrapper.
- Execution
Context - Mutable state shared across command invocations.
- Exit
Code - Typed process exit codes for agent self-correction.
- Invocation
- Parsed command-line invocation.
- Ndjson
Emitter - Stateful NDJSON event emitter that enforces terminal
result/errorsemantics. - Next
Action - HATEOAS action template that tells an agent what to run next.
- Success
Envelope - Success response envelope.
- Truncated
Entries - Context-safe result for potentially large line-oriented output.
Enums§
- Audit
Severity - Severity of an
AuditFinding. - Check
Status - The three outcomes of a
Check. Serialized into thedoctorreport as the lowercasestatusstring on each check entry. - Envelope
- Unified envelope enum.
- Flush
Policy - Controls when the emitter flushes the underlying writer.
- LogLevel
- Log level for stream events.
- Parse
Invocation Error - Invocation parser failure.
- Step
Status - Step lifecycle status for stream events.
- Stream
Emit Error - NDJSON emit failure.
- Stream
Event - Typed NDJSON stream event.
Functions§
- parse_
invocation - Parse argv into an
Invocationwithout any boolean-flag schema. - parse_
invocation_ with_ bool_ flags - Parse argv into an
Invocation, treating any flag for whichis_boolreturnstrueas a pure boolean (it never consumes the next token). - read_
stdin - Read all of stdin to a string. Pairs with the
--stdinconvention so a handler can accept piped input:if req.wants_stdin() { read_stdin().await }. - reserved_
flag_ names - Every framework-reserved flag name (without the leading
--), for runtime discovery. These names are reserved wheneverAgentCli::reserved_flagsis enabled (the default): the framework parses and acts on them on every command.selectis a value flag; the others are parsed as booleans anywhere on the line. - truncate_
lines_ with_ file - Truncate to the last
max_lineslines and, when truncated, write the full output to a temp file (seeTruncatedEntriesfor the tail/droppedsemantics and the file’s ownership rules).