pub mod auth;
pub mod bus;
pub mod capture;
pub mod company_bound;
pub mod compute;
pub mod conductor;
pub mod config;
pub mod connect;
pub mod consent;
pub mod convert;
pub mod delivery;
pub mod disconnect;
pub mod effective_floor;
pub mod effective_policy;
pub mod error;
pub mod events;
pub mod friction;
pub mod identity_v2;
pub mod instance_key;
pub mod keyset_v3;
pub mod knowledge;
pub mod lease;
pub mod link;
pub mod mapping;
pub mod metrics;
pub mod metrics_v2;
pub mod migrate;
pub mod outbox;
pub mod own_text;
pub mod policy;
pub mod receipts;
pub mod replica;
pub mod review;
pub mod revoked;
pub mod root_cert;
pub mod runtime_lease;
pub mod scheduler;
pub mod sealed;
pub mod state;
pub mod status;
pub mod swarm;
pub mod swarms;
pub mod sync;
pub mod tasks;
pub mod throttle;
pub mod transport;
pub mod untrusted;
pub mod vault;
pub mod vault_address;
pub mod worker;
pub mod workers;
#[cfg(test)]
mod x5_guard_tests;
pub use config::HiveConfig;
pub use error::{HiveError, Revocation, TaskRefusal};
pub use state::HiveStore;
pub const HIVE_AVAILABLE: bool = false;
pub const PREVIEW_ENV: &str = "LEAN_CTX_HIVE_PREVIEW";
pub const NOT_AVAILABLE: &str =
"LeanCTX Hive comes with 3.12.1; this version does not connect to a Hive.";
pub const TOOL_NOT_AVAILABLE: &str =
"LeanCTX Hive comes with 3.12.1; this tool is not available in this version.";
fn preview() -> bool {
std::env::var(PREVIEW_ENV).as_deref() == Ok("1")
}
pub(crate) fn is_loopback(origin: &str) -> bool {
let rest = origin
.strip_prefix("http://")
.or_else(|| origin.strip_prefix("https://"))
.unwrap_or(origin);
let host = if let Some(v6) = rest.strip_prefix('[') {
v6.split(']').next().unwrap_or_default()
} else {
rest.split(['/', ':']).next().unwrap_or_default()
};
matches!(host, "127.0.0.1" | "localhost" | "::1")
}
pub fn available_for(origin: &str) -> bool {
HIVE_AVAILABLE || (preview() && is_loopback(origin))
}
pub fn available_locally() -> bool {
HIVE_AVAILABLE || preview()
}
#[cfg(test)]
mod availability_tests {
#[test]
fn the_preview_never_opens_a_real_hive() {
assert!(!super::is_loopback("https://hive.leanctx.com"));
assert!(!super::is_loopback("https://127.0.0.1.example.com"));
assert!(super::is_loopback("http://127.0.0.1:4100"));
assert!(super::is_loopback("http://[::1]:4100"));
assert!(super::is_loopback("http://localhost"));
assert_eq!(
super::available_for("https://hive.leanctx.com"),
super::HIVE_AVAILABLE
);
}
}