1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//! # knowledge-runtime
//!
//! Hardened scaffold / bounded first-pass orchestration layer for `semantic-memory`.
//!
//! This crate provides intent classification, route planning, entity resolution,
//! result merging, and projection lifecycle tracking on top of `semantic-memory`.
//!
//! ## Authority Model
//!
//! This crate NEVER owns source truth. All facts, episodes, documents, and
//! conversation messages live in `semantic-memory`. This crate owns only:
//! - Derived projections (entity registry, projection tracker)
//! - Query pipeline logic (classification, planning, merge)
//! - Observability traces
//!
//! Deleting any projection forces recomputation but causes no data loss.
//!
//! ## Query Pipeline
//!
//! ```text
//! query text
//! -> classify (QueryMode: semantic | entity | temporal | mixed)
//! -> plan (RoutePlan with legs)
//! -> execute (per-leg retrieval via semantic-memory adapter)
//! -> merge (fuse duplicates with provenance, normalize, boost, rank, truncate)
//! -> results + QueryTrace (including degradation warnings)
//! ```
//!
//! ## Implemented Now
//!
//! - **Rule-based intent classification**: heuristic extraction of entity mentions
//! (`@name`, `"quoted"`), temporal keywords, and mixed signals.
//! - **Route planning**: translates classified query modes into retrieval legs.
//! - **Projection-backed retrieval for imported knowledge**: imported claim,
//! relation, and episode rows are queried directly through `semantic-memory`'s
//! public projection APIs.
//! - **Hybrid fallback where projection substrate is absent**: namespace-only
//! BM25/vector retrieval remains available when a supported projection route
//! is unavailable for the queried leg.
//! - **Entity search**: scope-aware registry resolution plus bounded imported
//! alias candidate expansion before fallback.
//! - **Deterministic result merge with provenance fusion**: duplicates across legs are
//! fused (not discarded), retaining union of source legs and per-leg scores. Tie-breaking
//! is three-tier: score > source leg count > lexicographic identity key. Multi-leg
//! support gets a configurable score boost.
//! - **Scope-aware entity registry**: entities are partitioned by `ScopeKey` (namespace +
//! domain + workspace_id + repo_id). Resolution falls back from narrow scope to
//! namespace-only when needed, with fallback visible in results.
//! - **Scope enforcement transparency**: projection-backed routes enforce full
//! scope directly. `ScopePartiallyEnforced` is emitted only when execution
//! must fall back to namespace-only hybrid retrieval.
//! - **Scope-aware code identity**: code entity IDs include repo_id/workspace_id/namespace
//! so the same qualified path in different repos yields different IDs.
//! - **Projection lifecycle observability**: health, staleness (time-based + explicit),
//! invalidation by scope/kind/id, stale cause, and version metadata. The tracker
//! currently emits `Healthy`, `Stale`, and `Missing`; reserved compatibility
//! variants remain in the public enum but are not emitted by the tracker today.
//! - **Import staleness detection**: the runtime checks `semantic-memory`'s last import
//! timestamp for the queried namespace and emits `ProjectionImportStale` warnings when
//! data may be outdated. Import freshness is surfaced as a query warning today,
//! not as a dedicated tracker health transition.
//! - **Query traces with degradation warnings**: unsupported temporal downgrade,
//! partial scope enforcement on hybrid fallback, entity scope fallback, and
//! import staleness are all surfaced in `QueryTrace::warnings`. Helper methods
//! (`is_degraded()`, `has_temporal_downgrade()`, etc.) make warnings inspectable.
//! - **Strict enforcement modes (KR-001/KR-002)**: `strict_temporal` and `strict_scope`
//! config flags convert degradation warnings into hard errors for callers that
//! require guaranteed temporal/scope semantics rather than best-effort.
//! - **Rebuild driver interface (KR-003)**: the [`RebuildDriver`] trait provides a
//! defined contract for external callers to drive projection rebuilds. The
//! [`rebuild_stale`] convenience function polls the tracker and drives rebuilds
//! automatically. The tracker remains observability-only.
//!
//! ## Not Real Yet (Deferred)
//!
//! - **Range temporal expressions**: projection-backed temporal execution is
//! implemented for concrete as-of markers such as `today`, `yesterday`,
//! `last week`, and `this month`. Range-style phrases such as `before`,
//! `after`, `since`, and `between` still degrade explicitly.
//! - **Namespace-only hybrid scope**: `semantic-memory` hybrid search only
//! pushes namespace. When runtime must use that path for a scoped query, the
//! limitation is surfaced via `QueryWarning::ScopePartiallyEnforced` or
//! `RuntimeError::ScopeNotFullyEnforced`.
//! - **Projection persistence**: the `persist` config flag is rejected at
//! validation time. Durable runtime projections are not implemented in this
//! crate today.
//! - **Projection rebuild execution**: the tracker is observability-only; it records
//! build/failure events but does not schedule, execute, or retry rebuilds.
//! External callers implement the [`RebuildDriver`] trait to drive actual rebuilds
//! and report outcomes back to the tracker (KR-003).
//! - **LLM-based intent classification**: classifier is rule-based heuristic.
//! - **Evidence handle external dereference**: this layer does not resolve
//! evidence handles against external stores.
//! - **Advanced fuzzy entity resolution**: bounded candidate expansion exists,
//! but there is no embedding-based or graph-ML entity resolver.
// Re-export primary public types.
pub use RuntimeConfig;
pub use RuntimeError;
pub use ;
pub use ;
pub use ;
// Re-export commonly used inner types.
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;