Skip to main content

cortex_core/
lib.rs

1//! Core types, identifiers, errors, and schema constants for Cortex.
2//!
3//! `cortex-core` is the **shape layer**: it defines the typed primitives that
4//! every other crate in the workspace agrees on (events, traces, IDs, errors,
5//! schema version). It performs **no I/O**, **no network calls**, and **no
6//! LLM invocations** — those live in `cortex-ledger`, `cortex-store`,
7//! `cortex-llm`, etc. (BUILD_SPEC §8.)
8//!
9//! The intent is that any change to a type re-exported from this crate is
10//! immediately visible everywhere it is used, and any wire-format change is
11//! gated by a [`SCHEMA_VERSION`] bump (see [`version`] for the bump policy).
12
13#![deny(unsafe_code, missing_debug_implementations)]
14#![warn(missing_docs)]
15
16pub mod attestor;
17pub mod audit;
18pub mod authority;
19pub mod axiom_trust;
20pub mod boundary;
21pub mod canonical;
22pub mod claim_language;
23pub mod claims;
24pub mod consumer_advisory;
25pub mod error;
26pub mod event;
27pub mod ids;
28pub mod policy;
29pub mod proof;
30pub mod salience_v2;
31pub mod schema_migration;
32pub mod semantic_trust;
33pub mod source_attestation;
34pub mod summary;
35pub mod trace;
36pub mod version;
37
38pub use attestor::{
39    attest, sign_rotation, verify, verify_rotation, Attestation, Attestor, IdentityRotation,
40    InMemoryAttestor, RotationEnvelope, VerifyError,
41};
42pub use audit::{AuditRecord, Outcome};
43pub use authority::{
44    revalidate_temporal_authority, KeyLifecycleState, TemporalAuthorityEvidence,
45    TemporalAuthorityReason, TemporalAuthorityReport, TrustTier,
46};
47pub use axiom_trust::{
48    accepted_axiom_source_commits, is_axiom_source_commit_fresh, parse_authority_feedback_loop,
49    parse_axiom_execution_trust, parse_cortex_context_trust, ActorAttestation, AmplificationRisk,
50    ArtifactLifecycleState, AuthorityClaimStatus, AuthorityFeedbackLoop, AxiomExecutionTrust,
51    AxiomExecutionTrustEnvelope, CompatibilityTrustLabel, ConfidenceCeiling,
52    ContextAllowedClaimLanguage, ContextAllowedUse, ContextConfidence, ContextConfidenceScale,
53    ContextConfidenceValue, ContextForbiddenUse, ContextPolicyResult, ContextPolicyResultValue,
54    ContextProofState, ContextProofStateValue, ContextProvenanceClass, ContextQuarantineState,
55    ContextRedactionState, ContextRedactionStatus, ContextSemanticTrust, ContextSourceAnchor,
56    ContextSourceAnchorType, ContradictionState, CortexContextTrust, CortexContextTrustEnvelope,
57    ExecutionPolicyDecision, ExecutionPolicyResult, ExecutionSourceAnchor,
58    ExecutionSourceAnchorType, ExecutionToolProvenance, ExecutionTrustLevel,
59    FeedbackAuthorityClaims, FeedbackAxiomAction, FeedbackInitiatingContext,
60    FeedbackReturnedArtifact, NamedQuarantineOutputs, PromotionState, QuarantineOutput, RepoTrust,
61    RepoTrustResult, ReproducibilityLevel, TargetDomainValidation, TargetDomainValidationResult,
62    TokenRevocationResult, TokenScope, TrustExchangeFieldError, TrustExchangeValidation,
63    TruthCeiling, AUTHORITY_FEEDBACK_LOOP_SCHEMA, AXIOM_EXECUTION_TRUST_SCHEMA,
64    AXIOM_EXECUTION_TRUST_SOURCE_COMMIT_STALE_INVARIANT, CORTEX_AXIOM_ACCEPTED_SOURCE_COMMITS_ENV,
65    CORTEX_CONTEXT_TRUST_SCHEMA, DEFAULT_ACCEPTED_AXIOM_SOURCE_COMMITS,
66    TRUST_EXCHANGE_SCHEMA_VERSION,
67};
68pub use boundary::{
69    default_allowed_claim_language, default_forbidden_boundary_uses, AllowedClaimLanguage,
70    BoundaryContradictionState, BoundaryQuarantineState, BoundaryRedactionState,
71    BoundarySourceAnchor, BoundaryToolInvocation, BoundaryToolOutcome, CapabilityTokenDecision,
72    CapabilityTokenState, CortexAxiomConstraintEnvelopeV1, ExecutionTrustState,
73    ForbiddenBoundaryUse, OperatorApprovalState, PaiAxiomExecutionReceiptV1, RuntimeIntegrityState,
74    BOUNDARY_SCHEMA_VERSION, CORTEX_TO_AXIOM_CONSTRAINT_ENVELOPE_V1,
75    PAI_AXIOM_TO_CORTEX_EXECUTION_RECEIPT_V1,
76};
77pub use canonical::{
78    canonical_rotation_input, canonical_signing_input, AttestationPreimage, LineageBinding,
79    SourceIdentity, DOMAIN_TAG_ATTESTATION_PREIMAGE, DOMAIN_TAG_ROTATION_ENVELOPE,
80    SCHEMA_VERSION_ATTESTATION,
81};
82pub use claim_language::{
83    map_axiom_claims, AxiomClaimInput, AxiomConstraint, AxiomConstraintKind,
84    AxiomConstraintSeverity, AxiomElementKind, AxiomEvidenceKind, AxiomStatus, CortexClaimMapping,
85    CortexClaimRole,
86};
87pub use claims::{
88    effective_ceiling, mix_authority_to_weakest, mix_claims_to_weakest,
89    mix_reportable_claims_to_weakest, AuthorityClass, ClaimCeiling, ClaimProofState,
90    ReportableClaim, RuntimeMode,
91};
92pub use consumer_advisory::{
93    contains_exec_shaped_string, AdvisoryFlag, ConsumerAdvisory, ExecutionTrustClass,
94    RenderTrustClass,
95};
96pub use error::{CoreError, CoreResult};
97pub use error::{CortexError, CortexResult};
98pub use event::{Event, EventSource, EventType};
99pub use ids::{
100    AuditRecordId, ContextPackId, ContradictionId, CorrelationId, DecayJobId, DoctrineId,
101    EpisodeId, EventId, MemoryId, PrincipleId, TraceId,
102};
103pub use policy::{
104    compose_policy_outcomes, BreakGlassAuditShape, BreakGlassAuthorization, BreakGlassReasonCode,
105    BreakGlassScope, PolicyContribution, PolicyDecision, PolicyEngine, PolicyError, PolicyOutcome,
106    PolicyRuleId,
107};
108pub use proof::{
109    FailingEdge, ProofClosureReport, ProofEdge, ProofEdgeFailure, ProofEdgeKind, ProofState,
110};
111pub use salience_v2::{CrossSessionSalience, OutcomeMemoryRelation};
112pub use schema_migration::{
113    schema_migration_v1_to_v2_event, SchemaMigrationEventError, SchemaMigrationPayloadError,
114    SchemaMigrationV1ToV2Payload, SCHEMA_MIGRATION_V1_TO_V2_EVENT_KIND,
115    SCHEMA_MIGRATION_V1_TO_V2_ID, SCHEMA_MIGRATION_V1_TO_V2_TARGET,
116};
117pub use semantic_trust::{
118    evaluate_semantic_trust, ProvenanceClass, SemanticTrustClass, SemanticTrustInput,
119    SemanticTrustReport, SemanticUse,
120};
121pub use source_attestation::SourceAttestation;
122pub use summary::{validate_summary_spans, SourceAuthority, SummarySpan, SummarySpanError};
123pub use trace::{Trace, TraceStatus};
124pub use version::{crate_version, schema};
125
126/// Current schema version for persisted Cortex rows and JSON envelopes.
127///
128/// See [`version`] for the bump policy.
129///
130/// **Bumped to 2** in the schema v2 atomic cutover commit (ADR 0018). Forward-
131/// only: a v1 binary opening a v2 store fails closed with `Exit::SchemaMismatch`
132/// (ADR 0033 §6). Rollback is restore-from-blessed-pre-v2-backup; in-place
133/// down-migration is forbidden by ADR 0033 §3.
134pub const SCHEMA_VERSION: u16 = 2;
135
136// Compile-time assertion that the migration target and the live schema version
137// agree. If a future commit bumps `SCHEMA_VERSION` to a value other than the
138// `schema_migration::SCHEMA_MIGRATION_V1_TO_V2_TARGET` it should also update the
139// boundary event type and the migration verifier. This guard makes that drift
140// a build failure rather than a runtime surprise.
141const _: () = assert!(
142    SCHEMA_VERSION == schema_migration::SCHEMA_MIGRATION_V1_TO_V2_TARGET,
143    "cortex_core::SCHEMA_VERSION must equal SCHEMA_MIGRATION_V1_TO_V2_TARGET; \
144     update the schema_migration module or the migration verifier together"
145);