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 rendering: [`render`] — the single `value × format × options → String` entry point
13//! for JSON, YAML, and plain (logfmt) output
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//! [`build_cli_error`], [`build_cli_version`], [`cli_render_version`]
18//! - (feature `cli` or `cli-help`): [`cli_handle_version_or_continue`] (needs a `&clap::Command`
19//! to recognize the caller's own value-taking global flags)
20//! - (feature `cli-help`): configurable clap help rendering via [`cli_render_help_with_options`]
21//! and [`cli_handle_help_or_continue`]
22//! - (feature `cli-help-markdown`): [`cli_render_help_markdown`] — recursive Markdown help
23//! - (feature `skill`): [`skill::validate_skill`] / [`skill::validate_skill_named`] — strict
24//! Agent Skills `SKILL.md` front-matter validation
25//! - (feature `skill-admin`): [`skill::run_skill_admin`] — install/uninstall/status a spore's
26//! embedded Agent Skill across Codex, Claude Code, opencode, and Hermes; returns a typed
27//! [`skill::SkillReport`]
28//! - (feature `tracing`): [`afdata_tracing::try_init`] initializes an AFDATA stdout logging
29//! layer with configurable format and redaction; also [`afdata_tracing::LogFormat`]
30//!
31//! The shared cross-language contract (which of these exist, under what name, in each of
32//! Rust/Python/TypeScript/Go) is tracked in `spec/api-surface.json` and cross-checked by
33//! `scripts/validate_api_surface.py`.
34
35#[cfg(feature = "tracing")]
36pub mod afdata_tracing;
37
38#[cfg(feature = "stream-redirect")]
39pub mod stream_redirect;
40
41#[cfg(feature = "skill-admin")]
42#[path = "skill.rs"]
43mod skill_admin;
44
45#[cfg(feature = "skill")]
46#[path = "skill_validation.rs"]
47pub mod skill;
48
49/// Format-independent document values (dot-path access, typed coercion, and
50/// pluggable JSON/TOML/YAML/dotenv/INI backends).
51pub mod document;
52
53mod cli;
54mod formatting;
55#[cfg(feature = "cli-help")]
56mod help;
57mod protocol;
58mod redaction;
59mod validation;
60
61#[cfg(any(feature = "cli", feature = "cli-help"))]
62pub use cli::cli_handle_version_or_continue;
63pub use cli::{
64 CliEmitter, CliEmitterError, LogFilters, OutputFormat, OutputTo, build_cli_version,
65 cli_parse_log_filters, cli_parse_output, cli_render_version,
66};
67pub use formatting::render;
68#[cfg(feature = "cli-help")]
69pub use help::{
70 HelpConfig, HelpFormat, HelpOptions, HelpScope, cli_handle_help_or_continue, cli_render_help,
71 cli_render_help_markdown, cli_render_help_with_options,
72};
73pub use protocol::{
74 BuildError, DecodedError, DecodedEvent, DecodedLog, DecodedProgress, DecodedResult,
75 ErrorBuilder, Event, EventDecodeError, LogBuilder, LogLevel, ProgressBuilder,
76 ProtocolViolation, ResultBuilder, build_cli_error, decode_protocol_event, json_error, json_log,
77 json_progress, json_result, validate_protocol_event, validate_protocol_stream,
78};
79pub use redaction::{
80 OutputOptions, PlainStyle, RedactionPolicy, Redactor, redact_url_secrets, redacted_value,
81};
82pub use validation::{
83 is_valid_bcp47, is_valid_rfc3339, is_valid_rfc3339_date, is_valid_rfc3339_time,
84 normalize_utc_offset,
85};
86
87#[cfg(test)]
88pub(crate) use formatting::{extract_currency_code, format_bytes_human, format_with_commas};
89
90#[cfg(test)]
91mod tests;