ggen_dod/
lib.rs

1#![deny(warnings)]
2#![allow(missing_docs)]
3#![deny(unsafe_code)]
4#![doc = "Definition of Done: Type-safe, deterministic autonomous substrate"]
5
6//! # ggen-dod: The Definition of Done
7//!
8//! This crate implements the complete Definition of Done specification for ggen,
9//! ensuring it operates as a closed-world, autonomic substrate without human arbitration
10//! in the critical path.
11//!
12//! ## Core Systems
13//!
14//! - **O (Observations)**: Type-safe observation model with schema validation
15//! - **Σ (Contracts)**: Versioned ontology and contract system with invariant enforcement
16//! - **Q (Invariants)**: Hard-blocking constraint checks
17//! - **μ (Kernel)**: Deterministic decision kernel with timing guarantees (τ ≤ 8)
18//! - **Γ (History)**: Immutable receipt and audit trail system
19//! - **ΔΣ (Evolution)**: Doctrine-aligned schema changes with proofs
20//! - **MAPE-K (Autonomy)**: Monitor-Analyze-Plan-Execute-Knowledge loop
21//!
22//! ## Guarantees
23//!
24//! - **Determinism**: μ(O) produces identical A across all executions for fixed O, Σ*, Γ
25//! - **Idempotence**: μ ∘ μ = μ for all idempotent operations
26//! - **Closed-world**: All decisions derivable from O, Σ, Q, Γ (proven by decision closure checker)
27//! - **Provenance**: Every action has cryptographically signed receipt
28//! - **Timing**: Performance guarantees (τ ≤ 8ms) enforced at compile and runtime
29
30pub mod autonomic;
31pub mod binding_completeness;
32pub mod contract;
33pub mod decision;
34pub mod decision_closure;
35pub mod doctrine;
36pub mod error;
37pub mod invariant;
38pub mod kernel;
39pub mod observation;
40pub mod receipt;
41pub mod replay;
42pub mod tenant;
43pub mod timing;
44
45// Re-export commonly used types
46pub use autonomic::mape_k::{
47    AnalysisPhase, ExecutionPhase, MAPEKLoop, ObservationPhase, PlanningPhase,
48};
49pub use contract::{Contract, ContractId, ContractVersion, Ontology};
50pub use decision::{Decision, DecisionId, DecisionStore};
51pub use doctrine::DoctrineCompliance;
52pub use error::{DoDError, DoDResult};
53pub use invariant::{Invariant, InvariantChecker, InvariantId};
54pub use kernel::{Kernel, KernelAction, KernelDecision};
55pub use observation::{Observation, ObservationId, ObservationSchema, ObservationType};
56pub use receipt::{Receipt, ReceiptId, ReceiptStore};
57pub use tenant::{TenantContext, TenantId, TenantIsolation};
58pub use timing::{TimingEnforcer, TimingGuarantee, TimingMeasurement};
59
60/// Core constants for DoD
61pub mod constants {
62    /// Maximum kernel decision time (τ ≤ 8ms)
63    pub const KERNEL_MAX_TIME_MS: u64 = 8;
64
65    /// Maximum observation size (preventing DOS)
66    pub const MAX_OBSERVATION_SIZE: usize = 1024 * 1024; // 1MB
67
68    /// Maximum Σ* fragment depth
69    pub const MAX_SCHEMA_DEPTH: usize = 256;
70
71    /// Maximum fan-out per kernel tick
72    pub const MAX_FANOUT: usize = 1024;
73
74    /// Maximum ΔΣ promotions per time unit
75    pub const MAX_PROMOTION_RATE_PER_HOUR: usize = 100;
76
77    /// Minimum proof requirements for different decision classes
78    pub mod proof_thresholds {
79        /// Read-only operations (≤30% doctrine distance)
80        pub const WEAK_PROOF: u8 = 30;
81        /// Cache/snapshot updates (≤50%)
82        pub const STANDARD_PROOF: u8 = 50;
83        /// Schema changes (≤70%)
84        pub const STRONG_PROOF: u8 = 70;
85        /// Marketplace changes (≤80%)
86        pub const CRITICAL_PROOF: u8 = 80;
87    }
88}
89
90#[cfg(test)]
91mod tests {
92    use super::*;
93
94    #[test]
95    fn test_constants_consistency() {
96        // Verify proof threshold ordering
97        assert!(
98            constants::proof_thresholds::WEAK_PROOF < constants::proof_thresholds::STANDARD_PROOF
99        );
100        assert!(
101            constants::proof_thresholds::STANDARD_PROOF < constants::proof_thresholds::STRONG_PROOF
102        );
103        assert!(
104            constants::proof_thresholds::STRONG_PROOF < constants::proof_thresholds::CRITICAL_PROOF
105        );
106    }
107}