lunaris/lib.rs
1//! lunaris — umbrella crate. Re-exports `lunaris_core` types, exposes the
2//! `open(url)` URL-scheme dispatcher AND the higher-level `Lunaris` handle
3//! that drives the Phase 2 ingest hot path.
4//!
5//! ## Two construction paths
6//!
7//! - [`open()`](crate::open::open) — returns `Arc<dyn StoragePort>` for
8//! callers that just want raw storage access (Plan 5 conformance harness,
9//! low-level tests).
10//! - [`Lunaris::open`](crate::handle::Lunaris::open) — returns a high-level
11//! handle wired with a default [`Embedder`] + [`HlcClock`] so callers can
12//! call `lunaris.ingest(episode).await?` without manually plumbing the
13//! Phase 2 pipeline. This is what Helios uses.
14//!
15//! ## Prelude
16//!
17//! For day-to-day use, glob-import the curated common surface:
18//!
19//! ```rust
20//! use lunaris::prelude::*;
21//! ```
22//!
23//! See [`prelude`] for the exact list — it intentionally stays small
24//! (handle, scope, episode builder, retrieval DSL, the pluggable
25//! trait + `Noop*` pairs, and the umbrella error type).
26#![deny(rust_2018_idioms, unreachable_pub)]
27#![forbid(unsafe_code)]
28
29pub mod audit;
30pub mod consolidator_pipeline;
31// RFC 0001 Wave 1D — EpisodeBuilder lives here (NOT in lunaris-core) so
32// `into_episode` can be `pub(crate)`, enforcing that only ScopedLunaris::ingest
33// can stamp a scope onto an episode.
34pub mod digest;
35pub mod episode_builder;
36pub mod forget;
37pub mod graph_pipeline;
38pub mod handle;
39pub mod ingest;
40// W2-L2 — bulk FT invalidation for Helios force-push recovery (UC-G3).
41// Internal fan-out logic; public surface is `Lunaris::invalidate_range`.
42pub(crate) mod invalidate;
43// Plan 05-05 OPS-08 — `lunaris::logging::init()` JSON-vs-pretty subscriber
44// selector helper. Production triggers per CONTEXT.md D-26: `LUNARIS_ENV=production`
45// OR `!std::io::stdout().is_terminal()`. Re-exported as `init_logging` below
46// so embedded callers can `use lunaris::init_logging;` without reaching into
47// the module path.
48pub mod logging;
49pub mod open;
50// Phase 12 Option-A relocation: `WorkingMemory` moved here from
51// `lunaris-recipes` so `HeliosScratchpad` (also in this crate) can compose
52// over it without a dependency cycle. `lunaris-recipes` re-exports the type
53// so Phase 9/10/11 callers using `lunaris_recipes::WorkingMemory` compile
54// unchanged. Phase 13 proper primitives-crate extraction subsumes this.
55pub mod primitives;
56pub mod recall;
57// GA-1 — opt-in cross-encoder rerank stage on the production recall root
58// (`LUNARIS_RECALL_RERANK`, read once at handle construction).
59pub mod recall_rerank;
60pub mod recipes;
61pub mod retention;
62// `memory-update-intelligence` — pure cross-episode reconciliation decision
63// core (dedup NOOP / additive Append / cross-episode Supersede). Consumed by
64// `structured_ingest` to converge memories without copying Mem0's
65// LLM-mutate-on-write; bi-temporal MVCC stays the source of truth.
66pub mod reconcile;
67// Plan 08-00 — `Lunaris::snapshot()` monotonic LSN marker. Pre-req for Plan
68// 08-01 codegen so the `snapshot` surface entry has a real inherent method
69// to bind from PyO3 + napi-rs. The module only contains an `impl Lunaris`
70// block + `#[cfg(test)] mod tests`, so no extra `pub use` is required.
71pub mod snapshot;
72// Phase 23 — agent-facing structured ingest. Reuses the same INGEST-04
73// single-atomic_write invariant as `ingest` but skips the LLM extractor.
74pub mod structured_ingest;
75pub mod verify_pipeline;
76
77pub use audit::{AUDIT_TOPIC, AuditEvent, publish_audit_event};
78pub use consolidator_pipeline::{
79 ConsolidatorPipelineHandle, ENABLED_ENV_VAR as CONSOLIDATE_ENABLED_ENV_VAR,
80};
81pub use digest::recent_by_source;
82pub use episode_builder::EpisodeBuilder;
83pub use forget::{ForgetConfirmation, ForgetReceipt, ForgetTarget, IndexKind, ScopeSpec};
84pub use graph_pipeline::{ENABLED_ENV_VAR as GRAPH_ENABLED_ENV_VAR, GraphPipelineHandle};
85pub use handle::{
86 DegradationNotice, EmbedderBackend, IngestKind, Lunaris, SUPPRESS_DEGRADED_WARNING_ENV,
87 ScopedLunaris, VerifyAgendaEntry, degradation_notice, lazy_default_embedder,
88 resolve_default_embedder, resolve_default_reranker, resolved_embedder_backend,
89};
90pub use recall_rerank::{RECALL_RERANK_ENV_VAR, RECALL_RERANK_TOP_IN_ENV_VAR, RecallRerankConfig};
91// Phase 23 — agent-facing structured-ingest public surface.
92pub use structured_ingest::{EntityInput, FactInput, RelationInput, StructuredIngest};
93// Phase 12 Option-A: `WorkingMemory` lives here now. `lunaris-recipes`
94// re-exports this path so the established `lunaris_recipes::WorkingMemory`
95// import stays stable.
96pub use primitives::WorkingMemory;
97// Plan 05-05 OPS-08 — re-export `lunaris::logging::init` as
98// `lunaris::init_logging` for the canonical embedded-caller use site
99// `lunaris::init_logging();`. The `lunaris-server` binary calls
100// `lunaris::logging::init()` via the full path; both are equivalent.
101pub use logging::init as init_logging;
102pub use lunaris_core::*;
103pub use open::open;
104// `bootstrap_app_role` / `BootstrapReport` (the Postgres production-role
105// bootstrap behind `lunaris-server bootstrap-db`) were removed in 0.7.0 with
106// `lunaris-storage-postgres`. Moon has no role/RLS bootstrap step — see
107// docs/operations/external-moon.md.
108// Plan 05-04 — opinionated v0 recipes (helios-rfc §5.3 surface). v0 ships only
109// CodingSessionMemory (renamed from HeliosScratchpad in v0.5) + its borrowed
110// AsOfScratchpad time-travel view; the other 9 recipes (RECIPE-V1-01..11) ship in v1.
111/// Deprecated alias for [`CodingSessionMemory`]. Remove in v0.7.
112// allow(deprecated): re-exporting the deprecated alias is the whole point —
113// without the allow, the defining crate trips its own deprecation lint and
114// `clippy -D warnings` fails. Downstream importers still get the warning.
115#[allow(deprecated)]
116#[deprecated(
117 since = "0.5.0",
118 note = "use CodingSessionMemory; HeliosScratchpad will be removed in v0.7"
119)]
120pub use recipes::HeliosScratchpad;
121pub use recipes::{AsOfScratchpad, CodingSessionMemory};
122pub use verify_pipeline::{ENABLED_ENV_VAR as VERIFY_ENABLED_ENV_VAR, VerifierPipelineHandle};
123
124// Plan 04 — verifier + consolidator trait surface re-exports so callers
125// `use lunaris::{Verifier, Consolidator, NoopVerifier, NoopConsolidator}`
126// without reaching into the per-crate paths.
127// T1d (260609-dvi): ActRConsolidator re-exported so lunaris-mcp needs no
128// direct dep on lunaris-consolidate.
129pub use lunaris_consolidate::{
130 ActRConsolidator, Consolidator, DreamAgenda, DreamCluster, DreamConfig, NoopConsolidator,
131};
132pub use lunaris_verify::{
133 NeedsReviewItem as VerifyNeedsReviewItem, NoopVerifier, Verifier, VerifierBackend,
134 VerifyDecision,
135};
136// Phase 13 — per-turn reflect supervisor re-exports. Callers
137// `use lunaris::{ReflectSupervisor, NoopReflectSupervisor, LlmReflectSupervisor,
138// ReflectInput, ReflectOutput, ReflectOpts}`
139// without reaching into lunaris-verify directly.
140pub use lunaris_verify::{
141 LlmReflectSupervisor, NoopReflectSupervisor, ReflectInput, ReflectOpts, ReflectOutput,
142 ReflectSupervisor,
143};
144
145// Cfg-gated verifier backends — mirror the extract backends gating pattern.
146#[cfg(feature = "cloud-api")]
147pub use lunaris_verify::{CloudApiVerifier, CloudApiVerifierOpts};
148#[cfg(feature = "ollama")]
149pub use lunaris_verify::{OllamaVerifier, OllamaVerifierOpts};
150
151// Phase 2 retrieve DSL re-exports — callers `use lunaris::{Vector, Keyword, ...}`
152// rather than reaching into `lunaris_retrieve::`.
153//
154// Plan 03-02 added `Graph` to the retrieve crate; the umbrella crate forwards
155// it here so callers `use lunaris::{Graph, EntityId}` for the canonical
156// blueprint §8 compose example.
157//
158// N5/B2 added the RAPTOR `Tree` operator; forwarded here so callers
159// `use lunaris::{Tree, Vector}` and never reach into `lunaris_retrieve::`
160// (the retrieval-DSL guide's standing contract).
161pub use lunaris_retrieve::{
162 AndRetriever, DEFAULT_GRAPH_HOPS, DEFAULT_GRAPH_K, DegradedFallbackRetriever,
163 FlooredTopRetriever, FuseRrfRetriever, Graph, Hit, Keyword, LUNARIS_GRAPH_NAME, MAX_GRAPH_HOPS,
164 Navigate, Plan, PlanError, Query, RawHit, RerankRetriever, RetrievalBuilder, RetrievalService,
165 Retriever, SourceOp, TopRetriever, Tree, Vector, degraded_fallback, filter_str, floored_top,
166 hybrid_root, plan_query, rerank, retriever_from_json,
167};
168
169// Reranker trait + helpers re-exported from lunaris-rerank so callers
170// `use lunaris::{Reranker, NoopReranker}`. The concrete cross-encoder
171// (`LlamaCppReranker`) lives in `lunaris-llamacpp` — operators who want
172// to construct it directly import from that crate; callers who only need
173// the trait + Noop seam stay on this re-export. v0.4 N-03 cutover.
174pub use lunaris_rerank::{NoopReranker, RerankCandidate, Reranker};
175
176// Plan 03-03: Extractor trait + helpers re-exported from lunaris-extract so
177// callers `use lunaris::{Extractor, NoopExtractor, EntityId}` for the
178// canonical compose example. Following the W-8 fix, we re-export ONLY the
179// trait + ID newtype + Noop impl + Validator outputs at the umbrella level.
180// Callers wanting extract DTOs directly use `lunaris_extract::{Entity,
181// Relation, Fact}` — namespacing prevents collision with `lunaris_core`'s
182// storage primitives that share those names.
183pub use lunaris_extract::{
184 EntityId, Extractor, NeedsReviewItem, NeedsReviewReason, NoopExtractor, ValidatedExtraction,
185};
186
187// Cfg-gated extractor backends. A `cargo check --no-default-features`
188// build pulls no http stack.
189#[cfg(feature = "cloud-api")]
190pub use lunaris_extract::{CloudApiExtractor, CloudApiExtractorOpts, CloudProvider};
191#[cfg(feature = "ollama")]
192pub use lunaris_extract::{OllamaExtractor, OllamaExtractorOpts};
193
194// Re-export the backend concrete type for callers who want to construct
195// directly (bypassing URL routing — needed by the conformance harness in
196// Phase 5). Since 0.7.0 there is exactly one.
197pub use lunaris_storage_moon::MoonStorage;
198
199/// Glob-import the common surface: `use lunaris::prelude::*;`.
200///
201/// This is a *curated* set — the handful of symbols a typical caller needs to
202/// open a store, build an episode, run a retrieval, and plug in (or stub out)
203/// the optional pipeline stages. It is deliberately **not** a glob of every
204/// re-export; reach into `lunaris::` directly for the long tail (pipeline
205/// handles, backend opts, conformance helpers, env-var constants, …).
206pub mod prelude {
207 // Handle + scoping.
208 pub use crate::handle::{Lunaris, ScopedLunaris};
209 pub use lunaris_core::scope::Scope;
210
211 // Building an episode + targeting a forget.
212 pub use crate::episode_builder::EpisodeBuilder;
213 pub use crate::forget::{ForgetTarget, ScopeSpec};
214
215 // Retrieval DSL.
216 pub use lunaris_retrieve::{Graph, Hit, Keyword, Query, RetrievalBuilder, Tree, Vector};
217
218 // Umbrella error type.
219 pub use lunaris_core::error::LunarisError;
220
221 // Pluggable trait surface + their Noop fallbacks.
222 pub use lunaris_consolidate::{Consolidator, NoopConsolidator};
223 pub use lunaris_core::embedder::Embedder;
224 pub use lunaris_core::hlc::HlcClock;
225 pub use lunaris_extract::{Extractor, NoopExtractor};
226 pub use lunaris_rerank::{NoopReranker, Reranker};
227 pub use lunaris_verify::{NoopVerifier, Verifier};
228}