agent_policy/lib.rs
1//! # agent-policy
2//!
3//! Schema-first generator for coding-agent repo policies and compatibility files.
4//!
5//! ## Usage
6//!
7//! ```no_run
8//! use camino::Utf8Path;
9//!
10//! let (policy, warnings) = agent_policy::load(Utf8Path::new("agent-policy.yaml"))
11//! .expect("failed to load policy");
12//!
13//! for w in &warnings { eprintln!("warning: {w}"); }
14//! println!("Project: {}", policy.project.name);
15//! ```
16//!
17//! ## Command-line interface
18//!
19//! See the [README](https://github.com/CameronBrooks11/agent-policy) for CLI documentation.
20
21#![deny(clippy::unwrap_used)]
22#![deny(clippy::expect_used)]
23#![warn(clippy::pedantic)]
24#![allow(clippy::module_name_repetitions)]
25
26pub mod cli;
27pub mod commands;
28pub mod error;
29pub mod load;
30pub mod model;
31pub mod render;
32pub(crate) mod util;
33
34pub use error::{Error, Result};
35pub use model::normalized::Policy;
36
37/// Load, validate, and normalize an `agent-policy.yaml` from a file path.
38///
39/// This is the main entry point for the entire load pipeline.
40///
41/// Returns the normalized policy and any diagnostic warnings. Warnings are
42/// non-fatal and should be printed to stderr so the user can clean up their
43/// configuration.
44///
45/// # Errors
46///
47/// Returns an [`Error`] if the file cannot be read, the YAML is invalid, the
48/// document fails schema validation, or normalization encounters invalid values.
49pub fn load(path: &camino::Utf8Path) -> Result<(Policy, Vec<String>)> {
50 let raw = load::load_file(path)?;
51 model::normalize(raw)
52}