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