Skip to main content

firstpass_core/
lib.rs

1//! # firstpass-core
2//!
3//! The Firstpass domain contract — pure, with **no I/O** (no filesystem, network, clock, or
4//! env access). Everything here is deterministic so the audit hash chain and feature
5//! extraction are reproducible and testable in isolation; all I/O lives in `firstpass-proxy`.
6//!
7//! This crate is the versioned thing every other component (gates, bandit, CLI, auditors)
8//! depends on. The serde field names on [`Trace`], [`Config`], [`Verdict`], and friends are
9//! the wire/audit contract — see each module for the "don't rename silently" rule.
10//!
11//! ## Modules
12//! - [`verdict`] — [`Verdict`], validated [`Score`], [`GateResult`] (the unit of ground truth).
13//! - [`features`] — the versioned, privacy-preserving request [`Features`] vector.
14//! - [`trace`] — the [`Trace`] audit record (SPEC §9.1).
15//! - [`hashchain`] — tamper-evident, auditor-re-derivable hashing.
16//! - [`config`] — declarative routing [`Config`] (SPEC §8.4).
17//! - [`cost`] — model pricing and the counterfactual baseline.
18//! - [`conformal`] — split-conformal risk control on the gate threshold (SPEC §10.1).
19//! - [`ltt`] — Learn-then-Test threshold calibration (RCPS, Angelopoulos et al. 2021).
20//! - [`error`] — the crate [`Error`] type.
21
22#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used))]
23#![doc(html_root_url = "https://docs.rs/firstpass-core")]
24
25pub mod config;
26pub mod conformal;
27pub mod cost;
28pub mod error;
29pub mod features;
30pub mod guardrail;
31pub mod hashchain;
32pub mod ltt;
33pub mod predictor;
34pub mod rollout;
35pub mod trace;
36pub mod verdict;
37
38pub use config::{
39    AbstainPolicy, AuthScheme, BanditAlgorithm, BanditConfig, Budget, Config, ConsistencyDef,
40    Dialect, Escalation, GateDef, JudgeDef, Mode, ModePreset, ModelRef, OnExhausted,
41    PredictorConfig, PriceDef, ProbeConfig, ProviderDef, Route, RoutingMode, SessionPromotion,
42};
43pub use conformal::{ConformalResult, calibrate, served_failure_rate};
44pub use cost::{ModelPrice, PriceTable};
45pub use error::{Error, Result};
46pub use features::{FEATURE_VERSION, Features, TaskKind};
47pub use guardrail::{Guardrail, GuardrailAction, GuardrailVerdict};
48pub use hashchain::{Chained, GENESIS_HASH, canonical_json, record_hash, verify_chain};
49pub use ltt::{LttDiagnostic, LttResult};
50pub use predictor::PassPredictor;
51pub use rollout::{Rollout, RolloutDecision, RolloutKey};
52pub use trace::{
53    Attempt, DeferredVerdict, ElasticAction, ElasticDecision, FinalOutcome, PolicyRef, ProbeRegime,
54    ProbeSignal, RequestInfo, ServedFrom, Trace,
55};
56pub use verdict::{GateResult, Score, Verdict};