# SLURP Context Intelligence Engine The Context Intelligence Engine is the core component of SLURP responsible for generating, extracting, and resolving contextual information about files and systems within the BZZZ distributed architecture. ## Purpose This module implements the "Understanding" and "Processing" aspects of SLURP by: - **Context Generation**: Creating intelligent, hierarchical context metadata - **Context Resolution**: Efficiently resolving context through CSS-like inheritance - **Bounded Hierarchy**: Limiting traversal depth to prevent excessive processing - **Role-Aware Context**: Generating context specific to AI agent roles ## Key Components ### cascading_metadata_generator.py Implements CSS-like cascading context inheritance system: - Context flows DOWN the directory tree (inheritance) - More specific contexts override parent contexts - Only unique/different metadata is stored per level - Massive space savings by avoiding redundant metadata ### context_resolver.py Efficient context resolution through hierarchical lookup: - Loads cascading metadata hierarchy - Resolves context through CSS-like inheritance - Fast lookups with caching - Global context support ### bounded_context_demo.py Complete demonstration system combining all context intelligence features: - Bounded hierarchy walking with configurable depth limits - Global context support for system-wide applicable metadata - Integration with temporal decision tracking - Smart context resolution with inheritance ## Architecture The Context Intelligence Engine follows these principles: 1. **Hierarchical Context**: Context inherits from parent directories unless overridden 2. **Bounded Traversal**: Limits hierarchy depth to prevent excessive processing 3. **CSS-like Specificity**: More specific contexts override general ones 4. **Global Contexts**: System-wide contexts that apply everywhere 5. **Role-Based Generation**: Context tailored to specific AI agent roles ## Integration with BZZZ Leader System In the BZZZ architecture, only the elected Leader node generates context intelligence: - **Leader-Only Generation**: Prevents conflicting context from multiple sources - **Role-Based Encryption**: Context is encrypted per AI agent role - **Need-to-Know Access**: Each agent receives only relevant context - **Quality Control**: Centralized generation ensures consistent, high-quality context ## Usage ```python from slurp.context_intelligence.context_resolver import CascadingContextResolver # Initialize resolver with bounded depth resolver = CascadingContextResolver(metadata_dir, max_hierarchy_depth=10) # Resolve context for a UCXL address context = resolver.resolve("ucxl://any:any@BZZZ:RUSTLE-testing/src/main.rs") # Search by tags or technologies rust_contexts = resolver.search_by_technology("rust") source_contexts = resolver.search_by_tag("source-code") ``` ## Performance Characteristics - **Space Efficiency**: 85%+ space savings through intelligent inheritance - **Resolution Speed**: O(log n) average case with caching - **Bounded Depth**: Configurable maximum traversal depth - **Memory Usage**: Minimal through lazy loading and caching strategies ## Future Enhancements - RAG integration for enhanced context analysis - Machine learning-based context quality scoring - Dynamic context refresh based on file changes - Advanced role-based context customization