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;
let cli = AgentCli::new("ops", "Agent-native operations CLI")
.command(
Command::new("status", "System health")
.usage("ops status")
.handler(|_req, _ctx| {
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(["ops", "status"]);
assert_eq!(run.exit_code(), 0);Structs§
- Action
Param - Metadata for a templated
next_actionparameter. - Agent
Cli - Agent-native CLI runtime.
- 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.
- 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§
- Envelope
- Unified envelope enum.
- 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
Invocation. - truncate_
lines_ with_ file - Truncate lines to
max_linesand, when truncated, write full output to a temp file.