#![warn(missing_docs)]
pub mod budget;
pub mod capability;
pub mod metrics;
pub mod orchestrator;
pub mod relevance;
pub mod segment;
pub mod summarizer;
pub mod embedder;
#[cfg(feature = "sources-failure-warnings")]
pub mod failure_recall;
#[cfg(feature = "sources-trajectory-recap")]
pub mod trajectory_recap;
pub use budget::BudgetPolicy;
pub use capability::{CapabilityProbe, Tier};
pub use metrics::{ContextCompilerMetrics, SegmentMetrics};
pub use orchestrator::{ComposedPrompt, ContextCompiler};
pub use relevance::{HeuristicScorer, RelevanceScore, RelevanceScorer};
pub use segment::{Role, Segment, SegmentKind};
pub use embedder::{cosine, Embedder, EmbedderError, PlaceholderEmbedder};
pub use summarizer::{AnchoredSummary, AnchoredSummarySection, Summarizer, SummarizerError};
#[cfg(feature = "sources-failure-warnings")]
pub use failure_recall::memory_block_for_user_query;
#[cfg(feature = "sources-trajectory-recap")]
pub use trajectory_recap::format_trajectory_recap_lines;
use std::sync::Arc;
pub trait ContextEmissionSink: Send + Sync {
fn emit(&self, event: ContextCompilerEvent);
}
#[derive(Debug, Clone)]
pub enum ContextCompilerEvent {
BlockEmitted {
source: &'static str,
kind: SegmentKind,
original_tokens: usize,
kept_tokens: usize,
},
BudgetAllocated {
total: usize,
per_kind: Vec<(SegmentKind, usize)>,
},
TierSelected {
tier: Tier,
reason: &'static str,
},
SummarizerInvoked {
duration_ms: u64,
segments_in: usize,
summary_tokens: usize,
},
SummarizerFailed {
duration_ms: u64,
error_kind: &'static str,
},
BudgetExceeded {
overage: usize,
},
}
pub type SinkRef = Option<Arc<dyn ContextEmissionSink>>;
#[cfg(test)]
mod tests {
use super::*;
use std::sync::Mutex;
struct CapturingSink {
events: Mutex<Vec<ContextCompilerEvent>>,
}
impl ContextEmissionSink for CapturingSink {
fn emit(&self, event: ContextCompilerEvent) {
self.events.lock().expect("lock").push(event);
}
}
#[test]
fn sink_trait_is_object_safe() {
let sink: Arc<dyn ContextEmissionSink> = Arc::new(CapturingSink {
events: Mutex::new(Vec::new()),
});
sink.emit(ContextCompilerEvent::TierSelected {
tier: Tier::Heuristic,
reason: "test",
});
}
}