subjective_time_expansion/
lib.rs1use std::collections::HashMap;
42use std::sync::Arc;
43use std::time::{Duration, Instant};
44
45use tokio::sync::{RwLock, Mutex};
46use nalgebra::{DMatrix, DVector};
47use rand::{Rng, thread_rng};
48use serde::{Deserialize, Serialize};
49use thiserror::Error;
50use tracing::{info, warn, debug, trace};
51
52pub mod prelude {
54 pub use crate::{
55 TemporalScheduler, SubjectiveAgent, PhiProxy, RetrocausalLoop,
56 AgentConfig, SchedulerConfig, CognitivePattern, CognitiveProcessor,
57 SubjectiveTimeError, TemporalMetrics, MetricsCollector,
58 };
59 pub use crate::scheduler::TemporalTask;
60 pub use crate::metrics::PerformanceReport;
61 pub use crate::scheduler::TaskPriority;
62 pub use std::time::Duration;
63}
64
65pub mod scheduler;
67pub mod agent;
68pub mod phi_proxy;
69pub mod retro_loop;
70pub mod cognitive;
71pub mod metrics;
72
73pub use scheduler::*;
75pub use agent::*;
76pub use phi_proxy::*;
77pub use retro_loop::*;
78pub use cognitive::*;
79pub use metrics::*;
80
81#[derive(Error, Debug)]
83pub enum SubjectiveTimeError {
84 #[error("Temporal scheduler error: {0}")]
85 Scheduler(String),
86
87 #[error("Agent processing error: {0}")]
88 Agent(String),
89
90 #[error("Consciousness measurement error: {0}")]
91 Consciousness(String),
92
93 #[error("Retrocausal simulation error: {0}")]
94 Retrocausal(String),
95
96 #[error("Configuration error: {0}")]
97 Configuration(String),
98
99 #[error("Integration error: {0}")]
100 Integration(String),
101}
102
103pub type SubjectiveResult<T> = Result<T, SubjectiveTimeError>;
105
106pub const VERSION: &str = env!("CARGO_PKG_VERSION");
108
109pub fn init() -> SubjectiveResult<()> {
111 let _ = tracing_subscriber::fmt()
113 .with_max_level(tracing::Level::INFO)
114 .try_init();
115
116 info!("Subjective Time Expansion Framework v{} initialized", VERSION);
117 Ok(())
118}
119
120#[cfg(feature = "wasm")]
121pub mod wasm;
122
123#[cfg(test)]
124mod tests {
125 use super::*;
126 use tokio_test;
127
128 #[tokio::test]
129 async fn test_framework_initialization() {
130 let result = init();
131 assert!(result.is_ok());
132 }
133
134 #[tokio::test]
135 async fn test_end_to_end_workflow() {
136 let _ = init();
138
139 let scheduler = TemporalScheduler::new(
141 SchedulerConfig::default()
142 .with_base_tick_duration(Duration::from_millis(1))
143 .with_max_agents(10)
144 );
145
146 let agent_config = AgentConfig::new("test-agent".to_string())
148 .with_pattern(CognitivePattern::CreativeSynthesis)
149 .with_dilation_factor(2.0);
150
151 let agent = scheduler.spawn_agent(agent_config).await.unwrap();
152
153 let phi = agent.measure_phi().await.unwrap();
155 assert!(phi >= 0.0 && phi <= 4.0);
156
157 let stats = agent.get_stats().await;
159 assert_eq!(stats.tasks_processed, 0); println!("End-to-end test completed: Φ = {:.3}", phi);
162 }
163}