okf 0.2.1

A pure-Rust, zero-dependency implementation of the Open Knowledge Format (OKF) v0.2: parser, model, validator, provenance/trust/attestation families, link graph, and index/log tooling.
Documentation
//! # okf: the Open Knowledge Format, in pure Rust
//!
//! A dependency-free implementation of the [Open Knowledge Format (OKF)
//! v0.2][spec], Google's open, human- and agent-friendly format for
//! representing knowledge as a directory of markdown files with YAML
//! frontmatter.
//!
//! OKF is intentionally minimal ("if you can `cat` a file, you can read OKF; if
//! you can `git clone` a repo, you can ship it"), so this crate implements it
//! with the standard library alone: its own [YAML-subset parser](yaml), a
//! markdown [link scanner](links), a directory walker, and (in the binary) CLI
//! argument parsing. There are **no third-party dependencies**.
//!
//! ## Model
//!
//! - A [`Bundle`] is a directory tree of markdown files (§3).
//! - A [`Concept`] is one markdown [`Document`] = YAML [`Frontmatter`] + body
//!   (§4).
//! - A [`ConceptId`] is a concept's path within the bundle, minus `.md` (§2).
//! - Concepts relate via markdown [`links`] (§6); the bundle exposes the
//!   resulting graph and backlinks.
//! - `index.md` directory listings (§8) are generated by [`index`].
//! - `log.md` histories (§9) are parsed by [`log`].
//! - [`validate_bundle`] checks §11 conformance.
//!
//! ## What v0.2 adds
//!
//! v0.2 makes provenance, trust, lifecycle, and attestation first-class. Every
//! one of the new keys is optional, and absence is meaningful rather than
//! invalid, so a v0.1 document is still a conformant v0.2 document.
//!
//! | Concern     | Frontmatter                                                    | Module          |
//! |-------------|----------------------------------------------------------------|-----------------|
//! | Provenance  | `sources`, `usage_window` (§5.1)                                | [`provenance`]  |
//! | Trust       | `generated`, `verified` (§5.2), trust tiers (§5.3)              | [`trust`]       |
//! | Lifecycle   | `status` (§5.4), `stale_after` (§5.5)                           | [`trust`]       |
//! | Identity    | the actor convention (§7)                                       | [`actor`]       |
//! | Attestation | `runtime`, `parameters`, `computation`, `executor`, `attester` (§10) | [`computation`] |
//! | Attribution | `[^label]` footnotes keyed to `sources[].id` (§5.1)             | [`footnotes`]   |
//!
//! Two v0.1 constructs are superseded (§13.1) but still readable, since a v0.2
//! consumer is expected to handle v0.1 bundles: `timestamp` gives way to
//! `generated.at` (see [`Frontmatter::content_changed_at`]), and the body
//! `# Citations` list gives way to `sources` (see [`Document::citations`]).
//!
//! ## Example
//!
//! ```no_run
//! use okf::{Bundle, validate_bundle};
//!
//! let bundle = Bundle::load("./my_bundle")?;
//! println!("{} concepts", bundle.len());
//!
//! let report = validate_bundle(&bundle);
//! if report.is_conformant() {
//!     println!("conformant OKF v0.2 bundle");
//! }
//! # Ok::<(), okf::BundleError>(())
//! ```
//!
//! Reading a concept's trust signals:
//!
//! ```
//! use okf::{Document, TrustTier};
//!
//! let doc = Document::parse(
//!     "---\n\
//!      type: Metric\n\
//!      title: Revenue\n\
//!      status: stable\n\
//!      generated: { by: reference_agent/gemini-2.5-pro, at: 2026-06-20T22:53:05Z }\n\
//!      verified: { by: human:ahormati, at: 2026-06-25T09:00:00Z }\n\
//!      stale_after: 2026-12-31\n\
//!      ---\n\n\
//!      # Definition\n",
//! )
//! .unwrap();
//!
//! // A bare `verified` mapping counts as a one-element list (§5.2).
//! assert_eq!(doc.frontmatter.verified().len(), 1);
//! assert_eq!(doc.frontmatter.trust_tier(), TrustTier::HumanReviewed);
//! assert_eq!(doc.frontmatter.status().to_string(), "stable");
//! ```
//!
//! [spec]: https://github.com/GoogleCloudPlatform/knowledge-catalog/blob/main/okf/SPEC.md

#![forbid(unsafe_code)]
#![warn(missing_docs)]
// Pedantic and nursery lints keep the published crate tidy; the few cases
// where a lint is genuinely wrong for this codebase are silenced inline with a
// justification.
#![warn(clippy::pedantic, clippy::nursery)]

/// Compiles and runs the `README.md` examples as doctests.
///
/// `cfg(doctest)` means this item exists only while `cargo test` collects
/// doctests, so it never reaches the public API or the rendered documentation.
/// Without it the README's Rust blocks would be prose that nothing checks.
#[cfg(doctest)]
#[doc = include_str!("../README.md")]
pub struct ReadmeExamples;

pub mod actor;
pub mod bundle;
pub mod computation;
pub mod concept_id;
pub mod date;
pub mod diff;
pub mod document;
pub mod error;
pub mod footnotes;
pub mod frontmatter;
pub mod index;
pub mod links;
pub mod lint;
pub mod log;
pub mod provenance;
pub mod trust;
pub mod validate;
pub mod yaml;

/// The OKF specification version this crate implements.
pub const OKF_VERSION: &str = "0.2";

/// Specification versions this crate can consume.
///
/// v0.2 is a minor bump over v0.1 (§12) with two documented supersessions
/// (§13.1), both of which this crate still reads, so a v0.1 bundle loads and
/// validates without special handling.
pub const SUPPORTED_OKF_VERSIONS: [&str; 2] = ["0.1", "0.2"];

#[doc(inline)]
pub use actor::{Actor, ActorKind};
#[doc(inline)]
pub use bundle::{Bundle, Concept, ResolvedLink, ResolvedSource, RESERVED_FILENAMES};
#[doc(inline)]
pub use computation::{
    AttestedComputation, Attester, ComputationSource, Executor, InlineComputation, Parameter,
    ATTESTED_COMPUTATION_TYPE,
};
#[doc(inline)]
pub use concept_id::{ConceptId, ConceptIdError};
#[doc(inline)]
pub use date::{Date, DateField, DateTime, DateTimeField};
#[doc(inline)]
pub use diff::{bundle_diff, BundleDiff, FrontmatterChange, Rename, TrustChange};
#[doc(inline)]
pub use document::Document;
#[doc(inline)]
pub use error::{BundleError, DocumentError};
#[doc(inline)]
pub use footnotes::{FootnoteDef, FootnoteRef};
#[doc(inline)]
pub use frontmatter::{
    Frontmatter, KNOWN_FRONTMATTER_KEYS, LEGACY_FRONTMATTER_KEYS, PREFERRED_KEY_ORDER,
    RECOMMENDED_FRONTMATTER_KEYS, REQUIRED_FRONTMATTER_KEYS,
};
#[doc(inline)]
pub use links::{Citation, Link, LinkKind};
#[doc(inline)]
pub use lint::{lint_bundle, lint_bundle_at};
#[doc(inline)]
pub use log::Log;
#[doc(inline)]
pub use provenance::{Attribution, ResourceKind, Source, UsageWindow};
#[doc(inline)]
pub use trust::{Generated, Status, TrustTier, Verification};
#[doc(inline)]
pub use validate::{validate_bundle, validate_bundle_at, Diagnostic, Report, Severity};
#[doc(inline)]
pub use yaml::{Mapping, Value};