omega-cognitive-kernel 0.16.0

Online strategy-patch runtime: training-free RuleEffect adaptation with audit and rollback
Documentation
#![forbid(unsafe_code)]
#![warn(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "std", doc = include_str!("../README.md"))]
#![cfg_attr(
    not(feature = "std"),
    doc = "Core cognitive-kernel types and algorithms that can run without the Rust standard library. Enable the `std` feature for persistence, configuration files, and the product-facing `Kernel` API."
)]
#![cfg_attr(docsrs, feature(doc_cfg))]

extern crate alloc;

use core::sync::atomic::{AtomicU32, Ordering};

static UUID_SEQUENCE: AtomicU32 = AtomicU32::new(1);

/// Generates process-local identifiers without requiring an OS random source.
/// Host applications can replace this with an external identity source when
/// globally unique IDs are required; the core only needs stable instance IDs.
pub fn new_uuid() -> uuid::Uuid {
    let sequence = UUID_SEQUENCE.fetch_add(1, Ordering::Relaxed) as u128;
    uuid::Uuid::from_u128(0x4f4d_4547_412d_4b45_524e_454c_0000_0000u128 | sequence)
}

/// Returns the current UTC time, or the Unix epoch when built without `std`.
pub fn now_utc() -> crate::types::UtcTimestamp {
    crate::types::UtcTimestamp::now()
}

/// Returns the current UTC time as RFC 3339, or the Unix epoch without `std`.
#[cfg(feature = "std")]
pub fn now_utc_string() -> alloc::string::String {
    now_utc().to_rfc3339()
}

#[cfg(not(feature = "std"))]
/// Returns the fixed Unix-epoch timestamp because `no_std` builds have no clock source.
pub fn now_utc_string() -> alloc::string::String {
    "1970-01-01T00:00:00+00:00".into()
}

#[doc(hidden)]
pub mod prelude {
    pub use alloc::{
        boxed::Box,
        format,
        string::{String, ToString},
        vec,
        vec::Vec,
    };
}

/// Adaptive Kernel Protocol v1 contract types and pure `no_std` state machine.
pub mod adaptive;
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub mod api;
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub mod audit;
#[doc(hidden)]
pub mod body;
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub mod checkpoint;
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub mod config;
#[cfg(all(feature = "std", feature = "toml"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", feature = "toml"))))]
pub mod config_toml;
#[doc(hidden)]
pub mod critic;
#[doc(hidden)]
pub mod error;
#[doc(hidden)]
pub mod goals;
#[doc(hidden)]
pub mod introspect;
/// World-interaction layer for observation, prediction, decision-making, and execution.
pub mod l0;
/// Cognitive reflection, learning, and safely bounded policy-patching layer.
pub mod l1;
/// Meta-cognitive control, stability monitoring, and policy-gating layer.
pub mod l2;
#[doc(hidden)]
pub mod llm;
/// Memory stores and utilities for cases, strategies, and serialized weights.
pub mod memory;
/// Coordinates the L0, L1, and L2 layers for each kernel step.
pub mod orchestrator;
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub mod persist;
#[doc(hidden)]
pub mod planning;
#[cfg(feature = "std")]
mod private_fs;
#[doc(hidden)]
pub mod reactor;
/// Authorization, action-boundary, and storage-protection APIs.
pub mod safety;
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub mod task;
/// Shared domain and state types used by the public kernel API.
pub mod types;

#[cfg(feature = "std")]
pub use api::{
    replay_trajectory_file, Kernel, KernelMetricsSnapshot, KernelStatus, RunReport,
    TrajectoryReplayRow, TrajectoryReplaySummary, DEFAULT_MAX_TRAJECTORY_BYTES,
};
#[cfg(feature = "std")]
pub use audit::{AuditEvent, AuditLog, AuditRecord, AuditSummary, KernelEvent};
#[cfg(feature = "std")]
pub use config::{
    InterventionLevel, InterventionMode, InterventionPolicy, KernelConfig, L2Config, PrivacyConfig,
};
pub use critic::{Critic, ReflectionReport, RewardSignal, TrialBudget};
pub use error::{OmegaError, Result};
pub use orchestrator::{OmegaOrchestrator, StepResult};
#[cfg(all(feature = "std", feature = "async"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", feature = "async"))))]
pub use persist::AsyncStateStore;
#[cfg(feature = "std")]
pub use persist::{KernelSnapshot, CURRENT_SCHEMA_VERSION, DEFAULT_STATE_PATH};
#[cfg(feature = "std")]
pub use task::{
    run_bandit_task, run_l1_l2_factorial_benchmark, run_l2_benchmark, run_l2_benchmark_scenario,
    run_l2_benchmark_scenario_with_gate, run_l2_gain_matrix, BanditReport, FactorialArm,
    FactorialBenchmarkReport, FactorialEffect, FactorialRun, L2BenchmarkAggregate,
    L2BenchmarkReport, L2GainAssessment, L2GainMatrixReport, L2GainScenarioAssessment,
    L2GainSeedSet, L2PairedRun, PairedMeanDifference, L2_GAIN_DEFAULT_EPISODES,
    L2_GAIN_DEFAULT_RUNS, L2_GAIN_DEFAULT_STEPS, L2_GAIN_DISCOVERY_SEED, L2_GAIN_SCENARIOS,
    L2_GAIN_VALIDATION_SEED,
};
pub use types::*;

// Public adapter surface — implement these to plug real world I/O into the kernel.
pub use body::{
    BodyBus, BodyChannelInfo, BodyCommandProposal, BodyPacket, BodyPacketStatus, BodySummary,
    ChannelKind,
};
pub use goals::{
    GoalNode, GoalStatus, GoalTree, GoalTreeSummary, IntrinsicMotivation, IntrinsicSignal,
};
pub use introspect::{EntropyReport, EntropyWatchdog};
pub use l0::bandit_decision::{BanditUcbDecisionMaker, BanditUcbSnapshot};
pub use l0::decision::{ConstrainedDecisionMaker, DecisionMaker};
#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
pub use l0::executor::{AsyncExecutor, AsyncExecutorAdapter, AsyncLoggingExecutor};
pub use l0::executor::{Executor, SandboxedExecutor};
#[cfg(feature = "std")]
pub use l0::executor::{LoggingExecutor, ToolGateExecutor};
pub use l0::hybrid_predictor::{HybridWorldModel, HybridWorldPredictor, TinyAttentionPredictor};
#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
pub use l0::observer::{
    AsyncDirSnapshotObserver, AsyncFileObserver, AsyncHttpObserver, AsyncObserver,
    AsyncObserverAdapter,
};
#[cfg(feature = "std")]
pub use l0::observer::{DirSnapshotObserver, FileObserver, HttpObserver};
pub use l0::observer::{MultiModalObserver, Observer};
pub use l0::predictor::{ModelBasedPredictor, Predictor};
pub use l1::{L1SpectralReflector, SpectralBin, SpectralPatch};
pub use l2::{
    CognitiveRealm, KernelStepOutput, L2CognitiveGate, L2Decision, L2State, SpectralGateConfig,
};
pub use llm::{parse_suggestion_json, LlmBridge, LlmProposal, SchemaResult};
pub use memory::{
    export_weights, migrate_payload, squash_delta_history, verify_weights, WeightsPayload,
    WEIGHTS_MAGIC, WEIGHTS_VERSION,
};
pub use planning::{Plan, PlanStep, ShortHorizonPlanner};
pub use reactor::{PriorityReactor, ReactorTask};
pub use safety::{ActionBoundary, AuthorizationToken, TokenBook};
#[cfg(feature = "std")]
pub use safety::{StorageLock, Vault};