lean_ctx/core/context_kernel/
mod.rs1use crate::core::knowledge::KnowledgeQuery;
4use crate::core::knowledge::snapshot::{KnowledgeRef, KnowledgeSnapshot};
5use crate::core::knowledge::store::KnowledgeStore;
6
7const KNOWLEDGE_POLICY_VERSION: &str = "knowledge-task-flow-v1";
8
9#[derive(Debug, Clone)]
11pub struct ContextState {
12 pub technical_refs: Vec<String>,
13 pub knowledge_query: KnowledgeQuery,
14 pub knowledge_snapshot: Option<KnowledgeSnapshot>,
15}
16
17impl ContextState {
18 #[must_use]
19 pub fn new(technical_refs: Vec<String>, knowledge_query: KnowledgeQuery) -> Self {
20 Self {
21 technical_refs,
22 knowledge_query,
23 knowledge_snapshot: None,
24 }
25 }
26}
27
28pub fn enrich_with_knowledge(
30 task_id: &str,
31 context: &mut ContextState,
32 store: &dyn KnowledgeStore,
33) -> Vec<KnowledgeRef> {
34 let items = store.query(&context.knowledge_query);
35 let snapshot = KnowledgeSnapshot::from_items(task_id, KNOWLEDGE_POLICY_VERSION, &items);
36 let references = snapshot.knowledge_refs.clone();
37 context.knowledge_snapshot = Some(snapshot);
38 references
39}
40
41pub fn enrich_with_optional_knowledge(
43 task_id: &str,
44 context: &mut ContextState,
45 store: Option<&dyn KnowledgeStore>,
46) -> Vec<KnowledgeRef> {
47 store.map_or_else(Vec::new, |store| {
48 enrich_with_knowledge(task_id, context, store)
49 })
50}
51
52pub mod a2a_fixes;
53pub mod accounting_fix;
54pub mod activation;
55pub(crate) mod activation_e2e;
56pub mod adaptive_bridge;
57pub mod adaptive_hook;
58pub(crate) mod airgap_e2e;
59pub mod attribution;
60pub(crate) mod bench;
61pub mod bounded;
62pub mod bridge;
63pub(crate) mod bridge_e2e;
64pub mod capsule_wire;
65pub(crate) mod client_e2e;
66pub mod client_profile;
67pub mod client_wiring;
68pub mod config_bridge;
69pub(crate) mod conformance;
70pub mod context_broker;
71pub mod context_dedup;
72pub mod coverage_class;
73pub mod ctx_read_dedup;
74pub mod dashboard_report;
75pub mod dedup_wiring;
76pub mod degradation;
77pub mod enforce;
78pub mod envelope_bridge;
79pub(crate) mod envelope_e2e;
80pub(crate) mod envelope_wiring;
81pub mod etpao;
82pub mod etpao_live;
83pub mod evidence_hook;
84pub mod evidence_wiring;
85pub mod feedback;
86pub(crate) mod feedback_e2e;
87pub mod health;
88pub mod health_api;
89pub mod hotpath_wiring;
90pub mod identity;
91pub(crate) mod identity_resolver;
92pub(crate) mod integration_e2e;
93pub mod invalidation;
94pub mod kernel_config;
95pub mod knowledge_health;
96pub mod learning;
97pub mod list_tools_opt;
98pub mod live_dashboard;
99pub mod mcp_bridge;
100pub mod mcp_coverage;
101pub(crate) mod mcp_e2e;
102pub mod mcp_receipt;
103pub mod mcp_schema_opt;
104pub(crate) mod multi_agent_e2e;
105pub mod orchestrator;
106pub mod outcome_signal;
107pub(crate) mod perf_benchmark;
108pub mod policy;
109pub mod policy_engine;
110pub(crate) mod production_e2e;
111pub mod provider_display;
112pub(crate) mod provider_metrics_e2e;
113pub mod provider_normalization;
114pub mod provider_parity;
115pub(crate) mod provider_traces;
116pub(crate) mod providers;
117pub mod proxy_bridge;
118pub(crate) mod quality_e2e;
119pub mod receipt_builder;
120pub mod receipt_chain;
121pub mod recovery;
122pub mod response_evidence;
123pub mod result_fusion;
124pub mod schema_wiring;
125pub mod shadow;
126pub(crate) mod smoke_test;
127pub mod startup;
128pub mod stream_controller;
129pub(crate) mod token_envelope;
130pub mod tool_surface;
131pub mod types;
132pub mod usage_normalizer;
133pub(crate) mod wiring_e2e;