Skip to main content

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), [`redact_argv`] / [`Redactor::argv`] (command lines) —
12//!   `Redactor` carries custom `secret_names`/`policy`
13//! - Output rendering: [`render`] — the single `value × format × options → String` entry point
14//!   for JSON, YAML, and plain (logfmt) output
15//! - Parse utilities: [`normalize_utc_offset`], [`is_valid_rfc3339_date`],
16//!   [`is_valid_rfc3339_time`], [`is_valid_rfc3339`], [`is_valid_bcp47`]
17//! - Closed-world CLI compiler: [`CliSpec`], [`CommandSpec`], [`ArgSpec`],
18//!   [`Combination`], and [`OutputSpec`] generate parsing, typed
19//!   [`ResolvedInvocation`] values, output plans, and help-v2 from one registry.
20//! - Established CLI utilities: [`cli_parse_output`], [`cli_parse_log_filters`]
21//!   (returns [`LogFilters`]), and [`CliEmitter`].
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
48/// Format-independent document values (dot-path access, typed coercion, and
49/// pluggable JSON/TOML/YAML/dotenv/INI backends).
50pub mod document;
51
52// The closed-world CLI compiler: spec types, build gates, argv resolution, and
53// the help-v2 model. Nothing else in this crate may reference it — only the
54// adapter below does — which `cargo build --no-default-features` proves.
55#[cfg(feature = "cli")]
56mod cli_spec;
57
58// The AFDATA CLI surface: output format parsing, the emitter, and version
59// payloads.
60#[cfg(feature = "cli")]
61mod cli;
62
63// The one place the compiler and AFDATA meet.
64#[cfg(feature = "cli")]
65mod cli_afdata;
66
67mod formatting;
68mod protocol;
69mod redaction;
70mod validation;
71
72#[cfg(feature = "cli")]
73pub use cli::{
74    CliEmitter, CliEmitterError, LogFilters, OutputTo, build_cli_version, cli_parse_log_filters,
75    cli_parse_output, cli_render_version,
76};
77#[cfg(feature = "cli")]
78pub use cli_afdata::{
79    build_afdata_cli, cli_error_event, cli_help_event, cli_version_event, render_cli_reference,
80};
81#[cfg(feature = "cli")]
82pub use cli_spec::{
83    ArgSpec, ArgSyntax, ArgValueType, BoundCliSpec, BuiltCliSpec, CliError, CliErrorRule,
84    CliHelpV2, CliOutcome, CliShape, CliSpec, CliSpecError, CliValue, Combination, CommandSpec,
85    FixedValue, OutputLifecycle, OutputPlan, OutputSpec, ResolvedDocs, ResolvedHelp,
86    ResolvedInvocation, ResolvedVersion, SyntheticInvocation,
87};
88pub use formatting::{OutputFormat, render};
89pub use protocol::{
90    BuildError, DecodedError, DecodedEvent, DecodedLog, DecodedProgress, DecodedResult,
91    ErrorBuilder, Event, EventDecodeError, LogBuilder, LogLevel, ProgressBuilder,
92    ProtocolViolation, ResultBuilder, build_cli_error, decode_protocol_event, json_error, json_log,
93    json_progress, json_result, validate_protocol_event, validate_protocol_stream,
94};
95pub use redaction::{
96    OutputOptions, PlainStyle, RedactionPolicy, Redactor, redact_argv, redact_url_secrets,
97    redacted_value,
98};
99pub use validation::{
100    is_valid_bcp47, is_valid_rfc3339, is_valid_rfc3339_date, is_valid_rfc3339_time,
101    normalize_utc_offset,
102};
103
104#[cfg(test)]
105pub(crate) use formatting::{extract_currency_code, format_bytes_human, format_with_commas};
106
107#[cfg(test)]
108mod tests;