pub mod init;
pub use clawft_kernel as kernel;
pub use clawft_kernel::{
Kernel, KernelState,
Pid, ProcessEntry, ProcessState, ProcessTable,
AgentSupervisor, SpawnBackend, SpawnRequest, SpawnResult,
AgentCapabilities, CapabilityChecker, IpcScope, ResourceLimits,
KernelIpc, KernelMessage, KernelSignal, MessagePayload, MessageTarget,
GlobalPid,
ServiceRegistry, ServiceEntry, SystemService,
HealthSystem, HealthStatus, OverallHealth,
GovernanceEngine, GovernanceRule, GovernanceRequest, GovernanceDecision,
EffectVector,
TopicRouter, Subscription,
ClusterConfig, ClusterMembership, NodeState, PeerNode,
KernelConfigExt,
BootEvent, BootPhase, BootLog,
KernelError, KernelResult,
CronService,
AppManager, AppManifest, InstalledApp, AppState,
ContainerManager, ContainerConfig, ContainerState,
};
#[cfg(feature = "exochain")]
pub use clawft_kernel::{
ChainManager, ChainEvent, TreeManager, TreeStats,
GateBackend, GateDecision, GovernanceGate, CapabilityGate,
};
#[cfg(feature = "ecc")]
pub use clawft_kernel::{
CausalGraph, CausalEdgeType, CognitiveTick, CognitiveTickConfig,
CrossRef, CrossRefStore, CrossRefType, UniversalNodeId,
HnswService, HnswServiceConfig, HnswSearchResult,
ImpulseQueue, ImpulseType,
EccCalibration,
};
#[cfg(feature = "mesh")]
pub use clawft_kernel::{
MeshError, MeshPeer, MeshStream, MeshTransport, TransportListener,
WeftHandshake, MeshConnectionPool, TcpTransport,
DiscoveryCoordinator, BootstrapDiscovery,
MeshIpcEnvelope, DedupFilter,
HeartbeatTracker, HeartbeatConfig, HeartbeatState,
DistributedProcessTable, ClusterServiceRegistry,
};
#[cfg(feature = "os-patterns")]
pub use clawft_kernel::{
MetricsRegistry, LogService, TimerService,
DeadLetterQueue, ReliableQueue, NamedPipeRegistry,
ReconciliationController,
};
use std::path::Path;
#[cfg(feature = "native")]
use std::sync::Arc;
#[cfg(feature = "native")]
use clawft_platform::NativePlatform;
#[cfg(feature = "native")]
pub struct WeftOs {
kernel: clawft_kernel::Kernel<NativePlatform>,
project_root: std::path::PathBuf,
}
#[cfg(feature = "native")]
impl WeftOs {
pub async fn boot_default() -> Result<Self, KernelError> {
Self::boot_in(std::env::current_dir().unwrap_or_else(|_| ".".into())).await
}
pub async fn boot_in(project_root: impl Into<std::path::PathBuf>) -> Result<Self, KernelError> {
let project_root = project_root.into();
let config = clawft_types::config::Config::default();
let kernel_config = clawft_types::config::KernelConfig::default();
let platform = Arc::new(NativePlatform::new());
let kernel = Kernel::boot(config, kernel_config, platform).await?;
Ok(Self { kernel, project_root })
}
pub async fn boot_with(
config: clawft_types::config::Config,
kernel_config: clawft_types::config::KernelConfig,
project_root: impl Into<std::path::PathBuf>,
) -> Result<Self, KernelError> {
let project_root = project_root.into();
let platform = Arc::new(NativePlatform::new());
let kernel = Kernel::boot(config, kernel_config, platform).await?;
Ok(Self { kernel, project_root })
}
pub fn project_root(&self) -> &Path {
&self.project_root
}
pub fn state(&self) -> &KernelState {
self.kernel.state()
}
pub fn service_count(&self) -> usize {
self.kernel.services().len()
}
pub fn process_count(&self) -> usize {
self.kernel.process_table().len()
}
pub fn kernel(&self) -> &Kernel<NativePlatform> {
&self.kernel
}
pub fn kernel_mut(&mut self) -> &mut Kernel<NativePlatform> {
&mut self.kernel
}
pub async fn shutdown(mut self) -> KernelResult<()> {
tracing::info!("WeftOS shutting down");
self.kernel.shutdown().await
}
}
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub fn is_initialized(path: impl AsRef<Path>) -> bool {
path.as_ref().join(".weftos").exists()
|| path.as_ref().join("weave.toml").exists()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn is_not_initialized_in_random_dir() {
assert!(!is_initialized("/tmp/nonexistent-weftos-test"));
}
#[test]
fn init_creates_structure() {
let dir = std::env::temp_dir().join("weftos-test-init");
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
let result = init::init_project(&dir).unwrap();
assert!(result.weftos_dir_created);
assert!(result.weave_toml_created);
assert!(dir.join(".weftos").exists());
assert!(dir.join("weave.toml").exists());
assert!(dir.join(".weftos/chain").exists());
assert!(dir.join(".weftos/logs").exists());
std::fs::remove_dir_all(&dir).ok();
}
#[test]
fn init_detects_rust_project() {
let dir = std::env::temp_dir().join("weftos-test-rust");
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(dir.join("Cargo.toml"), "[package]\nname = \"test\"").unwrap();
let _result = init::init_project(&dir).unwrap();
let config = std::fs::read_to_string(dir.join("weave.toml")).unwrap();
assert!(config.contains("language = \"rust\""));
assert!(config.contains("*.rs"));
std::fs::remove_dir_all(&dir).ok();
}
#[tokio::test]
async fn weftos_boots_and_reports_state() {
let os = WeftOs::boot_default().await.unwrap();
assert!(matches!(os.state(), KernelState::Running));
assert!(os.service_count() > 0);
os.shutdown().await.unwrap();
}
}