pub mod init;
pub use clawft_kernel as kernel;
pub use clawft_kernel::{
AgentCapabilities,
AgentSupervisor,
AppManager,
AppManifest,
AppState,
BootEvent,
BootLog,
BootPhase,
CapabilityChecker,
ClusterConfig,
ClusterMembership,
ContainerConfig,
ContainerManager,
ContainerState,
CronService,
EffectVector,
GlobalPid,
GovernanceDecision,
GovernanceEngine,
GovernanceRequest,
GovernanceRule,
HealthStatus,
HealthSystem,
InstalledApp,
IpcScope,
Kernel,
KernelConfigExt,
KernelError,
KernelIpc,
KernelMessage,
KernelResult,
KernelSignal,
KernelState,
MessagePayload,
MessageTarget,
NodeState,
OverallHealth,
PeerNode,
Pid,
ProcessEntry,
ProcessState,
ProcessTable,
ResourceLimits,
ServiceEntry,
ServiceRegistry,
SpawnBackend,
SpawnRequest,
SpawnResult,
Subscription,
SystemService,
TopicRouter,
};
#[cfg(feature = "exochain")]
pub use clawft_kernel::{
CapabilityGate, ChainEvent, ChainManager, GateBackend, GateDecision, GovernanceGate,
TreeManager, TreeStats,
};
#[cfg(feature = "ecc")]
pub use clawft_kernel::{
CausalEdgeType, CausalGraph, CognitiveTick, CognitiveTickConfig, CrossRef, CrossRefStore,
CrossRefType, EccCalibration, HnswSearchResult, HnswService, HnswServiceConfig, ImpulseQueue,
ImpulseType, UniversalNodeId,
};
#[cfg(feature = "mesh")]
pub use clawft_kernel::{
BootstrapDiscovery, ClusterServiceRegistry, DedupFilter, DiscoveryCoordinator,
DistributedProcessTable, HeartbeatConfig, HeartbeatState, HeartbeatTracker, MeshConnectionPool,
MeshError, MeshIpcEnvelope, MeshPeer, MeshStream, MeshTransport, TcpTransport,
TransportListener, WeftHandshake,
};
#[cfg(feature = "os-patterns")]
pub use clawft_kernel::{
DeadLetterQueue, LogService, MetricsRegistry, NamedPipeRegistry, ReconciliationController,
ReliableQueue, TimerService,
};
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 chain_dir =
std::env::temp_dir().join(format!("weftos-lib-test-chain-{}", std::process::id()));
let kernel_config = clawft_types::config::KernelConfig {
chain: Some(clawft_types::config::ChainConfig::isolated_in(&chain_dir)),
..clawft_types::config::KernelConfig::default()
};
let os = WeftOs::boot_with(
clawft_types::config::Config::default(),
kernel_config,
std::env::current_dir().unwrap(),
)
.await
.unwrap();
assert!(matches!(os.state(), KernelState::Running));
assert!(os.service_count() > 0);
os.shutdown().await.unwrap();
}
}