scribe_selection/
lib.rs

1//! # Scribe Selection
2//!
3//! Intelligent code selection and context extraction capabilities for the Scribe library.
4//! This crate provides advanced algorithms for selecting relevant code sections based on
5//! semantic understanding, dependency analysis, and contextual relevance.
6
7pub mod ast_parser;
8pub mod bundler;
9pub mod context;
10pub mod covering_set;
11pub mod demotion;
12pub mod quota;
13pub mod selector;
14pub mod simple_router;
15pub mod token_budget;
16pub mod two_pass;
17
18// Re-export main types
19pub use ast_parser::{
20    AstChunk, AstLanguage, AstParser, AstSignature, EntityLocation, EntityQuery, EntityType,
21};
22pub use bundler::{BundleOptions, CodeBundle, CodeBundler};
23pub use context::{CodeContext, ContextExtractor, ContextFile, ContextOptions};
24pub use covering_set::{
25    CoveringSetComputer, CoveringSetFile, CoveringSetOptions, CoveringSetResult,
26    CoveringSetStatistics, InclusionReason,
27};
28pub use simple_router::{
29    ProjectSize, RoutingDecision, SelectionStrategy, SimpleRouter, TimeConstraint,
30};
31pub use demotion::{
32    ChunkInfo, CodeChunker, DemotionEngine, DemotionResult, FidelityMode, SignatureExtractor,
33};
34pub use quota::{
35    create_quota_manager, CategoryQuota, FileCategory, QuotaAllocation, QuotaManager,
36    QuotaScanResult,
37};
38pub use selector::{CodeSelector, SelectionCriteria, SelectionResult};
39pub use token_budget::apply_token_budget_selection;
40pub use two_pass::{
41    CoverageGap, FileInfo, SelectionContext, SelectionMetrics, SelectionRule, TwoPassConfig,
42    TwoPassResult, TwoPassSelector,
43};
44
45use scribe_core::Result;
46
47/// Main entry point for intelligent code selection
48pub struct SelectionEngine {
49    selector: CodeSelector,
50    context_extractor: ContextExtractor,
51    bundler: CodeBundler,
52}
53
54impl SelectionEngine {
55    /// Create a new selection engine
56    pub fn new() -> Result<Self> {
57        Ok(Self {
58            selector: CodeSelector::new(),
59            context_extractor: ContextExtractor::new(),
60            bundler: CodeBundler::new(),
61        })
62    }
63
64    /// Select relevant code based on criteria
65    pub async fn select_code(&self, criteria: SelectionCriteria<'_>) -> Result<SelectionResult> {
66        self.selector.select(criteria).await
67    }
68
69    /// Extract context for selected code
70    pub async fn extract_context(
71        &self,
72        selection: &SelectionResult,
73        options: &ContextOptions,
74    ) -> Result<CodeContext> {
75        self.context_extractor.extract(selection, options).await
76    }
77
78    /// Create a bundled representation of selected code
79    pub async fn create_bundle(
80        &self,
81        context: &CodeContext,
82        options: &BundleOptions,
83    ) -> Result<CodeBundle> {
84        self.bundler.bundle(context, options).await
85    }
86}
87
88impl Default for SelectionEngine {
89    fn default() -> Self {
90        Self::new().expect("Failed to create SelectionEngine")
91    }
92}
93
94#[cfg(test)]
95mod tests {
96    use super::*;
97
98    #[tokio::test]
99    async fn test_selection_engine_creation() {
100        let engine = SelectionEngine::new();
101        assert!(engine.is_ok());
102    }
103}