Skip to main content

sttp_core_rs/
lib.rs

1//! Core Rust library for working with STTP nodes, AVEC calibration, and context retrieval.
2//!
3//! This crate provides:
4//! - domain models and contracts,
5//! - parsers and validators for STTP node payloads,
6//! - application services for calibration, storage, retrieval, mood presets, rollups, and rekey,
7//! - storage implementations (in-memory and SurrealDB-backed).
8//!
9//! # Quick Start
10//!
11//! ```no_run
12//! use std::sync::Arc;
13//!
14//! use sttp_core_rs::{
15//!     CalibrationService, ContextQueryService, InMemoryNodeStore, NodeStoreInitializer,
16//!     StoreContextService, TreeSitterValidator,
17//! };
18//!
19//! # fn main() -> anyhow::Result<()> {
20//! let runtime = tokio::runtime::Builder::new_current_thread()
21//!     .enable_all()
22//!     .build()?;
23//!
24//! runtime.block_on(async {
25//!     let store = Arc::new(InMemoryNodeStore::new());
26//!     let initializer: Arc<dyn NodeStoreInitializer> = store.clone();
27//!     initializer.initialize_async().await?;
28//!
29//!     let validator = Arc::new(TreeSitterValidator::new());
30//!     let store_context = StoreContextService::new(store.clone(), validator);
31//!     let calibration = CalibrationService::new(store.clone());
32//!     let context_query = ContextQueryService::new(store);
33//!
34//!     let raw_node = r#"
35//! ⊕⟨ { trigger: manual, response_format: temporal_node, origin_session: "demo", compression_depth: 1, parent_node: null, prime: { attractor_config: { stability: 0.85, friction: 0.25, logic: 0.80, autonomy: 0.70 }, context_summary: "demo", relevant_tier: raw, retrieval_budget: 3 } } ⟩
36//! ⦿⟨ { timestamp: "2026-03-05T06:30:00Z", tier: raw, session_id: "demo", user_avec: { stability: 0.85, friction: 0.25, logic: 0.80, autonomy: 0.70, psi: 2.60 }, model_avec: { stability: 0.85, friction: 0.25, logic: 0.80, autonomy: 0.70, psi: 2.60 } } ⟩
37//! ◈⟨ { note(.99): "example" } ⟩
38//! ⍉⟨ { rho: 0.96, kappa: 0.94, psi: 2.60, compression_avec: { stability: 0.85, friction: 0.25, logic: 0.80, autonomy: 0.70, psi: 2.60 } } ⟩
39//! "#;
40//!
41//!     let store_result = store_context.store_async(raw_node, "demo-session").await;
42//!     if store_result.valid {
43//!         let _ = calibration
44//!             .calibrate_async("demo-session", 0.9, 0.2, 0.9, 0.85, "manual")
45//!             .await?;
46//!         let _ = context_query.get_context_async("demo-session", 0.9, 0.2, 0.9, 0.85, 5).await;
47//!     }
48//!
49//!     Ok::<(), anyhow::Error>(())
50//! })?;
51//! # Ok(())
52//! # }
53//! ```
54
55pub mod application;
56pub mod domain;
57pub mod parsing;
58pub mod storage;
59
60pub use application::services::{
61	CalibrationService, ContextQueryService, MonthlyRollupService, MoodCatalogService,
62	RekeyScopeService, StoreContextService, SyncCoordinatorService,
63};
64pub use application::validation::TreeSitterValidator;
65pub use domain::contracts::{
66	NodeStore, NodeStoreInitializer, NodeValidator, SyncChangeSource, SyncCoordinatorPolicy,
67};
68pub use domain::models::*;
69pub use parsing::SttpNodeParser;
70pub use storage::{
71	InMemoryNodeStore, QueryParams, SurrealDbClient, SurrealDbEndpointsSettings,
72	SurrealDbNodeStore, SurrealDbRuntimeOptions, SurrealDbSettings,
73};