| 1 | //! Cloud facts (`facts/v1`): a signed, versioned, off-by-default overlay of |
| 2 | //! facts CodeWhale wants to move faster than binary releases — model catalog |
| 3 | //! deltas, provider defaults, release truth, and one-line announcements. |
| 4 | //! |
| 5 | //! This module is **network-free and tokio-free**. It owns the payload types, |
| 6 | //! the pinned trust anchors, envelope verification, version scoping, the |
| 7 | //! process-wide overlay, and the catalog patch semantics. Fetching and the |
| 8 | //! disk cache live in the `codewhale-cloud-facts` crate; the TUI wires both. |
| 9 | //! |
| 10 | //! Invariants: |
| 11 | //! - Bundled facts are the floor. Off / unreachable / rejected / inapplicable |
| 12 | //! payloads leave the binary exactly as it ships. |
| 13 | //! - Nothing here can change an explicitly configured or session-selected |
| 14 | //! model, point a provider at a non-official host, or touch safety policy. |
| 15 | //! - Verification happens before any payload byte is interpreted. |
| 16 | |
| 17 | pub mod catalog_patch; |
| 18 | pub mod keys; |
| 19 | pub mod overlay; |
| 20 | pub mod provenance; |
| 21 | pub mod scope; |
| 22 | pub mod types; |
| 23 | pub mod verify; |
| 24 | |
| 25 | pub use keys::{ |
| 26 | DOMAIN, ENVELOPE_VERSION, KeyStatus, MAX_ENVELOPE_BYTES, MAX_PAYLOAD_BYTES, |
| 27 | SUPPORTED_SCHEMA_VERSION, TRUSTED_KEYS, TrustedKey, |
| 28 | }; |
| 29 | pub use overlay::{ |
| 30 | DefaultSource, cloud_default_base_url, cloud_default_model, cloud_default_model_for_route, |
| 31 | }; |
| 32 | pub use provenance::{CloudFactsState, CloudFactsStatus, FactsOrigin}; |
| 33 | pub use scope::{ScopedFacts, scoped_view}; |
| 34 | pub use types::{ |
| 35 | Announcement, AnnouncementLevel, CloudFacts, ModelFact, ModelOp, PricingFact, |
| 36 | ProviderDefaultFact, ReleaseFact, Surface, |
| 37 | }; |
| 38 | pub use verify::{Envelope, FactsRejection, VerifiedFacts, verify_envelope}; |
| 39 | |
| 40 | /// Whether any pinned key can authenticate a release. With none, the layer is |
| 41 | /// inert regardless of the feature flag. |
| 42 | #[must_use] |
| 43 | pub fn has_active_trusted_key() -> bool { |
| 44 | TRUSTED_KEYS |
| 45 | .iter() |
| 46 | .any(|key| key.status == KeyStatus::Active) |
| 47 | } |
| 48 | |
| 49 | /// The running binary's version as semver, for `applies_to` evaluation. |
| 50 | #[must_use] |
| 51 | pub fn current_version() -> semver::Version { |
| 52 | semver::Version::parse(env!("CARGO_PKG_VERSION")) |
| 53 | .unwrap_or_else(|_| semver::Version::new(0, 0, 0)) |
| 54 | } |
| 55 | |
| 56 | #[cfg(test)] |
| 57 | mod tests; |
| 58 |