agent_first_data/lib.rs
1//! Agent-First Data (AFDATA) output formatting and protocol templates.
2//!
3//! Public APIs, grouped by concern (see each item's own docs for details;
4//! the full symbol list is the crate root's own rustdoc index, not repeated
5//! here — it drifts out of sync with a hand-maintained count otherwise):
6//! - Protocol v1 builders: [`json_result`], [`json_error`], [`json_progress`], [`json_log`]
7//! (each returns a builder; call `.build()`)
8//! - Protocol reader: [`decode_protocol_event`] parses and strict-validates one protocol
9//! line into a typed [`DecodedEvent`]
10//! - Redaction: [`redacted_value`] / [`Redactor::value`] (JSON values), [`redact_url_secrets`] /
11//! [`Redactor::url`] (URL strings) — `Redactor` carries custom `secret_names`/`policy`
12//! - Output formatters: [`output_json`], [`output_yaml`], [`output_plain`] and their
13//! `_with_options` variants
14//! - Parse utilities: [`parse_size`], [`normalize_utc_offset`], [`is_valid_rfc3339_date`],
15//! [`is_valid_rfc3339_time`]
16//! - CLI helpers: [`cli_parse_output`], [`cli_parse_log_filters`] (returns [`LogFilters`]),
17//! [`cli_output`], [`cli_output_with_options`], [`build_cli_error`], [`build_cli_version`],
18//! [`cli_render_version`], [`cli_handle_version_or_continue`]
19//! - (feature `cli-help`): configurable clap help rendering via [`cli_render_help_with_options`]
20//! and [`cli_handle_help_or_continue`]
21//! - (feature `cli-help-markdown`): [`cli_render_help_markdown`] — recursive Markdown help
22//! - (feature `skill-admin`): [`skill::run_skill_admin`] — install/uninstall/status a spore's
23//! embedded Agent Skill across Codex, Claude Code, opencode, and Hermes; returns a typed
24//! [`skill::SkillReport`]
25//! - (feature `tracing`): [`afdata_tracing::try_init`] initializes an AFDATA stdout logging
26//! layer with configurable format and redaction; also [`afdata_tracing::LogFormat`]
27//!
28//! The shared cross-language contract (which of these exist, under what name, in each of
29//! Rust/Python/TypeScript/Go) is tracked in `spec/api-surface.json` and cross-checked by
30//! `scripts/validate_api_surface.py`.
31
32#[cfg(feature = "tracing")]
33pub mod afdata_tracing;
34
35#[cfg(feature = "stream-redirect")]
36pub mod stream_redirect;
37
38#[cfg(feature = "skill-admin")]
39pub mod skill;
40
41mod cli;
42mod formatting;
43#[cfg(feature = "cli-help")]
44mod help;
45mod protocol;
46mod redaction;
47mod validation;
48
49pub use cli::{
50 CliEmitter, CliEmitterError, CliProtocolMode, LogFilters, OutputFormat, VersionConfig,
51 build_cli_version, cli_handle_version_or_continue, cli_output, cli_output_with_options,
52 cli_parse_log_filters, cli_parse_output, cli_render_version,
53};
54pub use formatting::{
55 output_json, output_json_with_options, output_plain, output_plain_with_options, output_yaml,
56 output_yaml_with_options,
57};
58#[cfg(feature = "cli-help")]
59pub use help::{
60 HelpConfig, HelpFormat, HelpOptions, HelpScope, cli_handle_help_or_continue, cli_render_help,
61 cli_render_help_markdown, cli_render_help_with_options,
62};
63pub use protocol::{
64 BuildError, DecodedError, DecodedEvent, DecodedLog, DecodedProgress, DecodedResult,
65 ErrorBuilder, Event, EventDecodeError, LogBuilder, LogLevel, ProgressBuilder, ResultBuilder,
66 build_cli_error, decode_protocol_event, json_error, json_log, json_progress, json_result,
67 validate_protocol_event, validate_protocol_stream,
68};
69pub use redaction::{
70 OutputOptions, OutputStyle, RedactionPolicy, Redactor, redact_url_secrets, redacted_value,
71};
72pub use validation::{
73 is_valid_rfc3339_date, is_valid_rfc3339_time, normalize_utc_offset, parse_size,
74};
75
76#[cfg(test)]
77pub(crate) use formatting::{extract_currency_code, format_bytes_human, format_with_commas};
78
79#[cfg(test)]
80mod tests;