aethellib 0.9.5

Composable text generation primitives over target-specific TOML corpora with provenance tracking.
Documentation
// Copyright 2026 Arad Fadaei

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! # aethellib
//!
//! `aethellib` is a small Rust library for composable text generation over
//! target-specific TOML corpora.
//!
//! It focuses on three things:
//! - Loading typed documents into a single-target [`Corpus`]
//! - Generating text with typed expressions and compiled plans
//! - Preserving source provenance for generated values so outputs remain traceable
//!
//! ## Core Concepts
//!
//! - [`corpus`] loads and validates documents, then builds pooled values grouped by
//!   section and field.
//! - [`engine`] validates and executes typed generation plans and stores prior outputs in a
//!   [`GenerationContext`].
//! - [`prelude`] re-exports the most commonly used types for quick onboarding.
//!
//! ## Why Provenance Matters
//!
//! Generated text is more useful when you can explain where it came from.
//! `aethellib` keeps provenance on pooled and composed values so you can:
//! - Debug generation outcomes quickly
//! - Audit content sources for pipelines and toolchains
//! - Build UI/UX that can show source attribution to users
//!
//! ## Architecture
//!
//! ```text
//! TOML Sources
//!     |
//!     v
//! corpus::Corpus::from_files / CorpusBuilder
//!     |
//!     v
//! Value Pools (section + field, with provenance)
//!     |
//!     v
//! engine::PlanBuilder + RuleExpr
//!     |
//!     v
//! validate + compile
//!     |
//!     v
//! GenerationContext (named outputs + provenance)
//! ```
//!
//! ## Quick Start
//!
//! ```no_run
//! use aethellib::engine::combinators;
//! use aethellib::prelude::*;
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//!     let corpus = Corpus::from_files(&["data/weapon_test_data.toml"], "weapon", None, None)?;
//!     let key = RuleKey::new("weapon_name")?;
//!     let prefix = PoolRef::new("name", "prefix")?;
//!     let kind = PoolRef::new("type", "type")?;
//!
//!     let compiled = PlanBuilder::new(&corpus)
//!         .rule(
//!             &key,
//!             combinators::join([
//!                 combinators::pick(prefix, None, ""),
//!                 combinators::lit(" "),
//!                 combinators::pick(kind, None, "")
//!            ]),
//!         )
//!         .validate()?
//!         .compile()?;
//!
//!     let mut rng = rand::rng();
//!     let ctx = compiled.generate(&mut rng)?;
//!
//!     println!("{}", ctx.require(&key)?.value);
//!
//!     Ok(())
//! }
//! ```
//!
//! For a fuller workflow (chance, recall, custom expressions), see
//! `examples/main.rs` in the repository.
//!
//! ## API At A Glance
//!
//! - [`Corpus::from_files`] to load corpora from TOML sources
//! - [`PlanBuilder::new`] and [`PlanBuilder::rule`] to build typed plans
//! - [`combinators`] for typed expression helpers like `pick`, `join`, and
//!   `weighted`
//! - [`prelude`] for ergonomic imports in applications and examples
//!
//! ## Stability
//!
//! `aethellib` is currently pre-1.0. Public API naming and module layout may
//! evolve as the crate approaches `1.0.0`.
//!
//! [`Corpus`]: crate::corpus::Corpus
//! [`PlanBuilder::new`]: crate::engine::PlanBuilder::new
//! [`PlanBuilder::rule`]: crate::engine::PlanBuilder::rule
//! [`GenerationContext`]: crate::engine::GenerationContext
//! [`Corpus::from_files`]: crate::corpus::Corpus::from_files
//! [`combinators`]: crate::engine::combinators

/// corpus module entrypoint.
pub mod corpus;
/// generation engine for typed planning and compiled execution.
pub mod engine;

pub mod prelude {
    //! Lightweight re-exports for common application-level usage.
    //!
    //! Import this when you want quick access to the most frequently used
    //! corpus and engine types without managing many individual paths.

    pub use crate::corpus::error::CorpusLoaderError;
    pub use crate::corpus::types::{Document, DocumentMetadata, Field, Section, Target};
    pub use crate::corpus::utils::{CorpusLoaderOptions, LoadValidator};
    pub use crate::corpus::{Corpus, CorpusBuilder, PooledValue, ValuePool, ValueProvenance};

    pub use crate::engine::error::AethelError;
    pub use crate::engine::{
        CompiledPlan, ComposedValue, GenerationContext, PlanBuilder, PoolRef, RuleExpr, RuleKey,
    };
}