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_urls_in_text`] / [`Redactor::urls_in_text`]
12//! (explicit prose URL spans), [`redact_argv`] / [`Redactor::argv`] (command lines) —
13//! `Redactor` carries custom `secret_names`/`url_names`/`policy`
14//! - Output rendering: [`render`] — the single `value × format × options → String` entry point
15//! for JSON, YAML, and plain (logfmt) output
16//! - Parse utilities: [`normalize_utc_offset`], [`is_valid_rfc3339_date`],
17//! [`is_valid_rfc3339_time`], [`is_valid_rfc3339`], [`is_valid_bcp47`]
18//! - Closed-world CLI compiler: [`CliSpec`], [`CommandSpec`], [`ArgSpec`],
19//! [`Combination`], and [`OutputSpec`] generate parsing, typed
20//! [`ResolvedInvocation`] values, output plans, and help-v2 from one registry.
21//! - Established CLI utilities: [`cli_parse_output`], [`cli_parse_log_filters`]
22//! (returns [`LogFilters`]), [`CliEmitter`], and [`write_raw`].
23//! - Domain errors and validation: [`ErrorSpec`] / [`ErrorCatalog`] declare
24//! stable public errors; [`lint_value`] and the `assert_*` helpers validate
25//! real serialized values in tests.
26//! - Documents: [`document::Document`] provides source-preserving in-memory
27//! edits and typed [`document::Document::decode`]; [`document::DocumentFile`]
28//! adds capped reads, safe first creation, atomic commits, and
29//! [`document::DocumentFile::edit_and_validate`].
30//! - (feature `skill`): [`skill::validate_skill`] / [`skill::validate_skill_named`] — strict
31//! Agent Skills `SKILL.md` front-matter validation
32//! - (feature `skill-admin`): [`skill::run_skill_admin`] — install/uninstall/status a spore's
33//! embedded Agent Skill across Codex, Claude Code, opencode, and Hermes; returns a typed
34//! [`skill::SkillReport`]
35//! - (feature `tracing`): [`afdata_tracing::AfdataLayer`] is a composable AFDATA
36//! logging layer with injectable writers and a nested-value
37//! [`afdata_tracing::StructuredLogHandle`]; [`afdata_tracing::try_init`] is
38//! the global-subscriber convenience entry point.
39//!
40//! The shared cross-language contract (which of these exist, under what name, in each of
41//! Rust/Python/TypeScript/Go) is tracked in `spec/api-surface.json` and cross-checked by
42//! `scripts/validate_api_surface.py`.
43
44#[cfg(feature = "tracing")]
45pub mod afdata_tracing;
46
47#[cfg(feature = "stream-redirect")]
48pub mod stream_redirect;
49
50#[cfg(feature = "skill-admin")]
51#[path = "skill.rs"]
52mod skill_admin;
53
54#[cfg(feature = "skill")]
55#[path = "skill_validation.rs"]
56pub mod skill;
57
58/// Format-independent document values (dot-path access, typed coercion, and
59/// pluggable JSON/TOML/YAML/dotenv/INI backends, plus a read-only Markdown
60/// block reader).
61pub mod document;
62
63mod error_catalog;
64
65// The closed-world CLI compiler: spec types, build gates, argv resolution, and
66// the help-v2 model. Nothing else in this crate may reference it — only the
67// adapter below does — which `cargo build --no-default-features` proves.
68#[cfg(feature = "cli")]
69mod cli_spec;
70
71// The AFDATA CLI surface: output format parsing, the emitter, and version
72// payloads.
73#[cfg(feature = "cli")]
74mod cli;
75
76// The one place the compiler and AFDATA meet.
77#[cfg(feature = "cli")]
78mod cli_afdata;
79
80mod formatting;
81mod lint;
82mod output;
83mod protocol;
84mod redaction;
85mod validation;
86
87#[cfg(feature = "cli")]
88pub use cli::{
89 CliEmitter, CliEmitterError, LogFilters, build_cli_version, cli_parse_log_filters,
90 cli_parse_output, cli_render_version, write_raw,
91};
92#[cfg(feature = "cli")]
93pub use cli_afdata::{
94 build_afdata_cli, cli_error_event, cli_help_event, cli_invocation_invalid_event,
95 cli_version_event, render_cli_reference,
96};
97#[cfg(feature = "cli")]
98pub use cli_spec::{
99 ArgSpec, ArgSyntax, ArgValueType, BoundCliSpec, BoundInvocation, BoundOutcome, BuiltCliSpec,
100 CliError, CliErrorRule, CliHelpV2, CliOutcome, CliShape, CliSpec, CliSpecError, CliValue,
101 Combination, CommandSpec, ExitCodeSpec, FixedValue, OutputLifecycle, OutputPlan, OutputSpec,
102 ResolvedDocs, ResolvedHelp, ResolvedInvocation, ResolvedVersion, SyntheticInvocation,
103};
104pub use error_catalog::{ErrorCatalog, ErrorCatalogError, ErrorSpec};
105pub use formatting::render;
106pub use lint::{
107 LintFinding, LintOptions, LintSeverity, RedactionCanaryError, assert_no_lint_findings,
108 assert_no_lint_findings_with_options, assert_redaction_canary_absent, assert_strict_event,
109 lint_value,
110};
111pub use output::OutputFormat;
112#[cfg(feature = "cli")]
113pub use output::OutputTo;
114pub use protocol::{
115 BuildError, DecodedError, DecodedEvent, DecodedLog, DecodedProgress, DecodedResult,
116 ErrorBuilder, Event, EventDecodeError, LogBuilder, LogLevel, ProgressBuilder,
117 ProtocolViolation, ResultBuilder, build_cli_error, decode_protocol_event, json_error, json_log,
118 json_progress, json_result, validate_protocol_event, validate_protocol_stream,
119};
120pub use redaction::{
121 OutputOptions, PlainStyle, RedactionPolicy, Redactor, redact_argv, redact_url_secrets,
122 redact_urls_in_text, redacted_value,
123};
124pub use validation::{
125 is_valid_bcp47, is_valid_rfc3339, is_valid_rfc3339_date, is_valid_rfc3339_time,
126 normalize_utc_offset,
127};
128
129#[cfg(test)]
130pub(crate) use formatting::{extract_currency_code, format_bytes_human, format_with_commas};
131
132#[cfg(test)]
133mod tests;