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: [`normalize_utc_offset`], [`is_valid_rfc3339_date`],
15//! [`is_valid_rfc3339_time`], [`is_valid_rfc3339`], [`is_valid_bcp47`]
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`): [`skill::validate_skill`] / [`skill::validate_skill_named`] — strict
23//! Agent Skills `SKILL.md` front-matter validation
24//! - (feature `skill-admin`): [`skill::run_skill_admin`] — install/uninstall/status a spore's
25//! embedded Agent Skill across Codex, Claude Code, opencode, and Hermes; returns a typed
26//! [`skill::SkillReport`]
27//! - (feature `tracing`): [`afdata_tracing::try_init`] initializes an AFDATA stdout logging
28//! layer with configurable format and redaction; also [`afdata_tracing::LogFormat`]
29//!
30//! The shared cross-language contract (which of these exist, under what name, in each of
31//! Rust/Python/TypeScript/Go) is tracked in `spec/api-surface.json` and cross-checked by
32//! `scripts/validate_api_surface.py`.
33
34#[cfg(feature = "tracing")]
35pub mod afdata_tracing;
36
37#[cfg(feature = "stream-redirect")]
38pub mod stream_redirect;
39
40#[cfg(feature = "skill-admin")]
41#[path = "skill.rs"]
42mod skill_admin;
43
44#[cfg(feature = "skill")]
45#[path = "skill_validation.rs"]
46pub mod skill;
47
48mod cli;
49mod formatting;
50#[cfg(feature = "cli-help")]
51mod help;
52mod protocol;
53mod redaction;
54mod validation;
55
56pub use cli::{
57 CliEmitter, CliEmitterError, CliProtocolMode, LogFilters, OutputFormat, VersionConfig,
58 build_cli_version, cli_handle_version_or_continue, cli_output, cli_output_with_options,
59 cli_parse_log_filters, cli_parse_output, cli_render_version,
60};
61pub use formatting::{
62 output_json, output_json_with_options, output_plain, output_plain_with_options, output_yaml,
63 output_yaml_with_options,
64};
65#[cfg(feature = "cli-help")]
66pub use help::{
67 HelpConfig, HelpFormat, HelpOptions, HelpScope, cli_handle_help_or_continue, cli_render_help,
68 cli_render_help_markdown, cli_render_help_with_options,
69};
70pub use protocol::{
71 BuildError, DecodedError, DecodedEvent, DecodedLog, DecodedProgress, DecodedResult,
72 ErrorBuilder, Event, EventDecodeError, LogBuilder, LogLevel, ProgressBuilder, ResultBuilder,
73 build_cli_error, decode_protocol_event, json_error, json_log, json_progress, json_result,
74 validate_protocol_event, validate_protocol_stream,
75};
76pub use redaction::{
77 OutputOptions, OutputStyle, RedactionPolicy, Redactor, redact_url_secrets, redacted_value,
78};
79pub use validation::{
80 is_valid_bcp47, is_valid_rfc3339, is_valid_rfc3339_date, is_valid_rfc3339_time,
81 normalize_utc_offset,
82};
83
84#[cfg(test)]
85pub(crate) use formatting::{extract_currency_code, format_bytes_human, format_with_commas};
86
87#[cfg(test)]
88mod tests;