pub struct LearningManager { /* private fields */ }Expand description
Central coordinator for all learning operations
Implementations§
Source§impl LearningManager
impl LearningManager
Sourcepub fn with_config(config: LearningConfig) -> Result<Self>
pub fn with_config(config: LearningConfig) -> Result<Self>
Create a new learning manager with custom configuration
Sourcepub async fn get_config(&self) -> LearningConfig
pub async fn get_config(&self) -> LearningConfig
Get the current configuration
Sourcepub async fn set_config(&self, config: LearningConfig) -> Result<()>
pub async fn set_config(&self, config: LearningConfig) -> Result<()>
Update the configuration
Sourcepub async fn is_enabled(&self) -> bool
pub async fn is_enabled(&self) -> bool
Check if learning is enabled
Sourcepub async fn set_enabled(&self, enabled: bool)
pub async fn set_enabled(&self, enabled: bool)
Enable or disable learning
Sourcepub async fn load_scope_configuration(&self) -> Result<ScopeConfiguration>
pub async fn load_scope_configuration(&self) -> Result<ScopeConfiguration>
Load scope configuration from project/user/defaults hierarchy
Sourcepub async fn get_scope_configuration(&self) -> ScopeConfiguration
pub async fn get_scope_configuration(&self) -> ScopeConfiguration
Get the current scope configuration
Sourcepub async fn set_scope_configuration(
&self,
config: ScopeConfiguration,
) -> Result<()>
pub async fn set_scope_configuration( &self, config: ScopeConfiguration, ) -> Result<()>
Update the scope configuration
Sourcepub async fn is_scope_learning_enabled(&self) -> bool
pub async fn is_scope_learning_enabled(&self) -> bool
Check if learning is enabled for the current scope
Sourcepub async fn set_scope_learning_enabled(&self, enabled: bool)
pub async fn set_scope_learning_enabled(&self, enabled: bool)
Enable or disable learning for the current scope
Sourcepub async fn is_project_only_learning(&self) -> bool
pub async fn is_project_only_learning(&self) -> bool
Check if project-only learning is enabled
Sourcepub async fn set_project_only_learning(&self, project_only: bool)
pub async fn set_project_only_learning(&self, project_only: bool)
Enable or disable project-only learning
Sourcepub async fn is_approval_required(&self) -> bool
pub async fn is_approval_required(&self) -> bool
Check if approval is required for new rules
Sourcepub async fn set_approval_required(&self, required: bool)
pub async fn set_approval_required(&self, required: bool)
Enable or disable approval requirement for new rules
Sourcepub async fn get_max_rules(&self) -> usize
pub async fn get_max_rules(&self) -> usize
Get the maximum number of rules for the current scope
Sourcepub async fn set_max_rules(&self, max_rules: usize) -> Result<()>
pub async fn set_max_rules(&self, max_rules: usize) -> Result<()>
Set the maximum number of rules for the current scope
Sourcepub async fn get_retention_days(&self) -> u32
pub async fn get_retention_days(&self) -> u32
Get the retention period in days for the current scope
Sourcepub async fn set_retention_days(&self, retention_days: u32) -> Result<()>
pub async fn set_retention_days(&self, retention_days: u32) -> Result<()>
Set the retention period in days for the current scope
Sourcepub async fn save_scope_configuration_to_project(&self) -> Result<()>
pub async fn save_scope_configuration_to_project(&self) -> Result<()>
Save scope configuration to project-level config file
Sourcepub async fn save_scope_configuration_to_user(&self) -> Result<()>
pub async fn save_scope_configuration_to_user(&self) -> Result<()>
Save scope configuration to user-level config file
Sourcepub async fn get_rules_for_scope(&self) -> Result<Vec<Rule>>
pub async fn get_rules_for_scope(&self) -> Result<Vec<Rule>>
Get rules filtered by current scope
Sourcepub async fn get_rules_by_scope(&self, scope: RuleScope) -> Result<Vec<Rule>>
pub async fn get_rules_by_scope(&self, scope: RuleScope) -> Result<Vec<Rule>>
Get rules filtered by specific scope
Sourcepub async fn check_scope_interference(
&self,
scope1: RuleScope,
scope2: RuleScope,
) -> Result<bool>
pub async fn check_scope_interference( &self, scope1: RuleScope, scope2: RuleScope, ) -> Result<bool>
Check if rules from different scopes interfere
Sourcepub async fn capture_decision(&self, decision: Decision) -> Result<String>
pub async fn capture_decision(&self, decision: Decision) -> Result<String>
Capture a decision with full metadata
Sourcepub async fn get_decisions(&self) -> Vec<Decision>
pub async fn get_decisions(&self) -> Vec<Decision>
Get all captured decisions
Sourcepub async fn get_decisions_by_type(&self, decision_type: &str) -> Vec<Decision>
pub async fn get_decisions_by_type(&self, decision_type: &str) -> Vec<Decision>
Get decisions by type
Sourcepub async fn get_decisions_by_context(
&self,
context: &DecisionContext,
) -> Vec<Decision>
pub async fn get_decisions_by_context( &self, context: &DecisionContext, ) -> Vec<Decision>
Get decisions by context
Sourcepub async fn get_decision(&self, decision_id: &str) -> Result<Decision>
pub async fn get_decision(&self, decision_id: &str) -> Result<Decision>
Get a specific decision by ID
Sourcepub async fn replay_decisions(&self) -> Vec<Decision>
pub async fn replay_decisions(&self) -> Vec<Decision>
Replay decisions for validation
Sourcepub async fn replay_decisions_for_context(
&self,
context: &DecisionContext,
) -> Vec<Decision>
pub async fn replay_decisions_for_context( &self, context: &DecisionContext, ) -> Vec<Decision>
Replay decisions for a specific context
Sourcepub async fn decision_count(&self) -> usize
pub async fn decision_count(&self) -> usize
Get the number of captured decisions
Sourcepub async fn clear_decisions(&self)
pub async fn clear_decisions(&self)
Clear all decisions
Sourcepub async fn get_decision_statistics(&self) -> DecisionStatistics
pub async fn get_decision_statistics(&self) -> DecisionStatistics
Get decision statistics
Sourcepub async fn store_rule(&self, rule: Rule) -> Result<String>
pub async fn store_rule(&self, rule: Rule) -> Result<String>
Store a rule (with validation)
Sourcepub async fn delete_rule(&self, rule_id: &str) -> Result<()>
pub async fn delete_rule(&self, rule_id: &str) -> Result<()>
Delete a rule
Sourcepub async fn update_rule(&self, rule: Rule) -> Result<String>
pub async fn update_rule(&self, rule: Rule) -> Result<String>
Update a rule (with validation)
Sourcepub fn validate_rule(&self, rule: &Rule) -> Result<()>
pub fn validate_rule(&self, rule: &Rule) -> Result<()>
Validate a rule without storing it
Sourcepub fn validate_rule_with_report(&self, rule: &Rule) -> ValidationReport
pub fn validate_rule_with_report(&self, rule: &Rule) -> ValidationReport
Get a detailed validation report for a rule
Sourcepub async fn check_rule_conflicts(&self, rule: &Rule) -> Result<()>
pub async fn check_rule_conflicts(&self, rule: &Rule) -> Result<()>
Check if a rule conflicts with existing rules
Sourcepub async fn get_rules_by_pattern(&self, pattern: &str) -> Result<Vec<Rule>>
pub async fn get_rules_by_pattern(&self, pattern: &str) -> Result<Vec<Rule>>
Get rules by pattern
Sourcepub async fn get_rules_by_source(&self, source: RuleSource) -> Result<Vec<Rule>>
pub async fn get_rules_by_source(&self, source: RuleSource) -> Result<Vec<Rule>>
Get rules by source
Sourcepub async fn get_rules_by_confidence(
&self,
min_confidence: f32,
) -> Result<Vec<Rule>>
pub async fn get_rules_by_confidence( &self, min_confidence: f32, ) -> Result<Vec<Rule>>
Get rules by confidence
Sourcepub async fn get_rules_by_usage(&self) -> Result<Vec<Rule>>
pub async fn get_rules_by_usage(&self) -> Result<Vec<Rule>>
Get rules sorted by usage
Sourcepub async fn get_rules_by_usage_count(
&self,
min_usage: u64,
) -> Result<Vec<Rule>>
pub async fn get_rules_by_usage_count( &self, min_usage: u64, ) -> Result<Vec<Rule>>
Get rules by usage count
Sourcepub async fn get_rules_by_success_rate(
&self,
min_success_rate: f32,
) -> Result<Vec<Rule>>
pub async fn get_rules_by_success_rate( &self, min_success_rate: f32, ) -> Result<Vec<Rule>>
Get rules by success rate
Sourcepub async fn rule_count(&self) -> Result<usize>
pub async fn rule_count(&self) -> Result<usize>
Get rule count
Sourcepub async fn clear_rules(&self) -> Result<()>
pub async fn clear_rules(&self) -> Result<()>
Clear all rules
Sourcepub async fn load_rules(&self) -> Result<()>
pub async fn load_rules(&self) -> Result<()>
Load all rules into cache
Sourcepub fn detect_rule_conflict(rule1: &Rule, rule2: &Rule) -> bool
pub fn detect_rule_conflict(rule1: &Rule, rule2: &Rule) -> bool
Detect if two rules conflict
Sourcepub async fn find_rule_conflicts(&self) -> Result<Vec<(Rule, Rule)>>
pub async fn find_rule_conflicts(&self) -> Result<Vec<(Rule, Rule)>>
Find all conflicts in the current rules
Sourcepub async fn check_rule_conflicts_before_storage(
&self,
rule: &Rule,
) -> Result<()>
pub async fn check_rule_conflicts_before_storage( &self, rule: &Rule, ) -> Result<()>
Check if a rule conflicts with existing rules before storage
Sourcepub async fn get_rule_by_pattern_with_precedence(
&self,
pattern: &str,
) -> Result<Option<Rule>>
pub async fn get_rule_by_pattern_with_precedence( &self, pattern: &str, ) -> Result<Option<Rule>>
Apply scope precedence to get the highest priority rule for a pattern
Sourcepub async fn get_rules_by_pattern_with_precedence(
&self,
pattern: &str,
) -> Result<Vec<Rule>>
pub async fn get_rules_by_pattern_with_precedence( &self, pattern: &str, ) -> Result<Vec<Rule>>
Get all rules for a pattern, applying scope precedence
Sourcepub async fn resolve_all_conflicts(&self) -> Result<Vec<Rule>>
pub async fn resolve_all_conflicts(&self) -> Result<Vec<Rule>>
Resolve conflicts in all rules by applying scope precedence
Sourcepub async fn check_cross_scope_conflicts(
&self,
project_rules: &[Rule],
global_rules: &[Rule],
) -> Vec<(Rule, Rule)>
pub async fn check_cross_scope_conflicts( &self, project_rules: &[Rule], global_rules: &[Rule], ) -> Vec<(Rule, Rule)>
Check for conflicts between project and global rules
Sourcepub fn log_conflict_resolution(
selected_rule: &Rule,
conflicting_rules: &[Rule],
) -> String
pub fn log_conflict_resolution( selected_rule: &Rule, conflicting_rules: &[Rule], ) -> String
Log conflict resolution decision
Sourcepub async fn store_pattern(&self, pattern: LearnedPattern) -> Result<String>
pub async fn store_pattern(&self, pattern: LearnedPattern) -> Result<String>
Store a pattern
Sourcepub async fn get_pattern(&self, pattern_id: &str) -> Result<LearnedPattern>
pub async fn get_pattern(&self, pattern_id: &str) -> Result<LearnedPattern>
Get a pattern
Sourcepub async fn get_patterns(&self) -> Vec<LearnedPattern>
pub async fn get_patterns(&self) -> Vec<LearnedPattern>
Get all patterns
Sourcepub async fn get_patterns_by_type(
&self,
pattern_type: &str,
) -> Vec<LearnedPattern>
pub async fn get_patterns_by_type( &self, pattern_type: &str, ) -> Vec<LearnedPattern>
Get patterns by type
Sourcepub async fn delete_pattern(&self, pattern_id: &str) -> Result<()>
pub async fn delete_pattern(&self, pattern_id: &str) -> Result<()>
Delete a pattern
Sourcepub fn get_scope_path(&self, scope: RuleScope) -> Result<PathBuf>
pub fn get_scope_path(&self, scope: RuleScope) -> Result<PathBuf>
Get the storage path for a given scope
Sourcepub async fn extract_patterns(&self) -> Result<Vec<LearnedPattern>>
pub async fn extract_patterns(&self) -> Result<Vec<LearnedPattern>>
Extract patterns from decision history
Sourcepub async fn extract_patterns_with_analysis(
&self,
) -> Result<Vec<(LearnedPattern, PatternAnalysis)>>
pub async fn extract_patterns_with_analysis( &self, ) -> Result<Vec<(LearnedPattern, PatternAnalysis)>>
Extract patterns from decision history with detailed analysis
Sourcepub async fn validate_pattern(&self, pattern: &LearnedPattern) -> Result<f32>
pub async fn validate_pattern(&self, pattern: &LearnedPattern) -> Result<f32>
Validate a pattern against historical decisions
Sourcepub async fn update_pattern_confidence(
&self,
pattern_id: &str,
validation_score: f32,
) -> Result<()>
pub async fn update_pattern_confidence( &self, pattern_id: &str, validation_score: f32, ) -> Result<()>
Update pattern confidence based on validation results
Sourcepub async fn validate_pattern_comprehensive(
&self,
pattern: &LearnedPattern,
) -> Result<ValidationResult>
pub async fn validate_pattern_comprehensive( &self, pattern: &LearnedPattern, ) -> Result<ValidationResult>
Validate a pattern using the pattern validator
Sourcepub async fn validate_patterns(
&self,
patterns: &[LearnedPattern],
) -> Result<Vec<ValidationResult>>
pub async fn validate_patterns( &self, patterns: &[LearnedPattern], ) -> Result<Vec<ValidationResult>>
Validate multiple patterns
Sourcepub async fn get_pattern_validation_statistics(
&self,
) -> Result<ValidationStatistics>
pub async fn get_pattern_validation_statistics( &self, ) -> Result<ValidationStatistics>
Get validation statistics for all stored patterns
Sourcepub async fn validate_and_update_pattern(
&self,
pattern_id: &str,
) -> Result<ValidationResult>
pub async fn validate_and_update_pattern( &self, pattern_id: &str, ) -> Result<ValidationResult>
Validate and update pattern confidence based on validation results
Sourcepub async fn capture_and_store_patterns(&self) -> Result<Vec<String>>
pub async fn capture_and_store_patterns(&self) -> Result<Vec<String>>
Capture patterns from recent decisions and store them
Sourcepub async fn get_patterns_by_confidence(
&self,
min_confidence: f32,
) -> Vec<LearnedPattern>
pub async fn get_patterns_by_confidence( &self, min_confidence: f32, ) -> Vec<LearnedPattern>
Get patterns by confidence threshold
Sourcepub async fn get_patterns_by_confidence_sorted(&self) -> Vec<LearnedPattern>
pub async fn get_patterns_by_confidence_sorted(&self) -> Vec<LearnedPattern>
Get patterns sorted by confidence
Sourcepub async fn get_patterns_by_occurrences(&self) -> Vec<LearnedPattern>
pub async fn get_patterns_by_occurrences(&self) -> Vec<LearnedPattern>
Get patterns sorted by occurrences
Sourcepub async fn pattern_count(&self) -> usize
pub async fn pattern_count(&self) -> usize
Get pattern count
Sourcepub async fn clear_patterns(&self)
pub async fn clear_patterns(&self)
Clear all patterns
Sourcepub async fn request_rule_promotion(&self, rule: Rule) -> Result<RuleReview>
pub async fn request_rule_promotion(&self, rule: Rule) -> Result<RuleReview>
Request promotion of a rule from project to global scope
Sourcepub async fn get_pending_promotion(&self, rule_id: &str) -> Result<RuleReview>
pub async fn get_pending_promotion(&self, rule_id: &str) -> Result<RuleReview>
Get a pending promotion for review
Sourcepub async fn get_pending_promotions(&self) -> Vec<RuleReview>
pub async fn get_pending_promotions(&self) -> Vec<RuleReview>
Get all pending promotions
Sourcepub async fn pending_promotion_count(&self) -> usize
pub async fn pending_promotion_count(&self) -> usize
Get the number of pending promotions
Sourcepub async fn approve_promotion(
&self,
rule_id: &str,
reason: Option<String>,
) -> Result<Rule>
pub async fn approve_promotion( &self, rule_id: &str, reason: Option<String>, ) -> Result<Rule>
Approve a pending promotion and store the promoted rule
Sourcepub async fn reject_promotion(
&self,
rule_id: &str,
reason: Option<String>,
) -> Result<()>
pub async fn reject_promotion( &self, rule_id: &str, reason: Option<String>, ) -> Result<()>
Reject a pending promotion
Sourcepub async fn get_promotion_history(&self) -> Vec<PromotionHistoryEntry>
pub async fn get_promotion_history(&self) -> Vec<PromotionHistoryEntry>
Get promotion history
Sourcepub async fn get_promotion_history_for_rule(
&self,
rule_id: &str,
) -> Vec<PromotionHistoryEntry>
pub async fn get_promotion_history_for_rule( &self, rule_id: &str, ) -> Vec<PromotionHistoryEntry>
Get promotion history for a specific rule
Sourcepub async fn get_approved_promotions(&self) -> Vec<PromotionHistoryEntry>
pub async fn get_approved_promotions(&self) -> Vec<PromotionHistoryEntry>
Get approved promotions from history
Sourcepub async fn get_rejected_promotions(&self) -> Vec<PromotionHistoryEntry>
pub async fn get_rejected_promotions(&self) -> Vec<PromotionHistoryEntry>
Get rejected promotions from history
Sourcepub async fn clear_pending_promotions(&self)
pub async fn clear_pending_promotions(&self)
Clear all pending promotions
Sourcepub async fn clear_promotion_history(&self)
pub async fn clear_promotion_history(&self)
Clear promotion history
Sourcepub async fn apply_rule_to_context(
&self,
rule: &Rule,
context: &GenerationContext,
) -> RuleApplicationResult
pub async fn apply_rule_to_context( &self, rule: &Rule, context: &GenerationContext, ) -> RuleApplicationResult
Apply a single rule to a generation context
Sourcepub async fn apply_rules_to_context(
&self,
rules: &[Rule],
context: &GenerationContext,
) -> Vec<RuleApplicationResult>
pub async fn apply_rules_to_context( &self, rules: &[Rule], context: &GenerationContext, ) -> Vec<RuleApplicationResult>
Apply multiple rules to a generation context
Sourcepub async fn apply_rules_with_precedence(
&self,
rules: &[Rule],
context: &GenerationContext,
) -> Option<RuleApplicationResult>
pub async fn apply_rules_with_precedence( &self, rules: &[Rule], context: &GenerationContext, ) -> Option<RuleApplicationResult>
Apply rules with precedence to get the best matching rule
Sourcepub async fn chain_rules(
&self,
rules: &[Rule],
context: &GenerationContext,
) -> Result<Vec<RuleApplicationResult>>
pub async fn chain_rules( &self, rules: &[Rule], context: &GenerationContext, ) -> Result<Vec<RuleApplicationResult>>
Chain multiple rules together for sequential application
Sourcepub async fn compose_rules(
&self,
rules: &[Rule],
context: &GenerationContext,
) -> Result<Option<String>>
pub async fn compose_rules( &self, rules: &[Rule], context: &GenerationContext, ) -> Result<Option<String>>
Compose multiple rules into a single action
Sourcepub async fn validate_rule_application(
&self,
rule: &Rule,
context: &GenerationContext,
) -> Result<()>
pub async fn validate_rule_application( &self, rule: &Rule, context: &GenerationContext, ) -> Result<()>
Validate that a rule can be applied to a context
Sourcepub async fn get_matching_rules(
&self,
context: &GenerationContext,
) -> Result<Vec<Rule>>
pub async fn get_matching_rules( &self, context: &GenerationContext, ) -> Result<Vec<Rule>>
Get all matching rules for a context
Sourcepub async fn get_matching_rules_sorted(
&self,
context: &GenerationContext,
) -> Result<Vec<Rule>>
pub async fn get_matching_rules_sorted( &self, context: &GenerationContext, ) -> Result<Vec<Rule>>
Get matching rules sorted by confidence
Sourcepub async fn get_matching_rules_by_usage(
&self,
context: &GenerationContext,
) -> Result<Vec<Rule>>
pub async fn get_matching_rules_by_usage( &self, context: &GenerationContext, ) -> Result<Vec<Rule>>
Get matching rules sorted by usage
Sourcepub async fn get_matching_rules_by_success(
&self,
context: &GenerationContext,
) -> Result<Vec<Rule>>
pub async fn get_matching_rules_by_success( &self, context: &GenerationContext, ) -> Result<Vec<Rule>>
Get matching rules sorted by success rate
Sourcepub async fn apply_learned_rules_to_generation(
&self,
context: &GenerationContext,
) -> Result<Option<String>>
pub async fn apply_learned_rules_to_generation( &self, context: &GenerationContext, ) -> Result<Option<String>>
Apply learned rules to guide code generation
Sourcepub async fn apply_learned_rules_get_all(
&self,
context: &GenerationContext,
) -> Result<Vec<String>>
pub async fn apply_learned_rules_get_all( &self, context: &GenerationContext, ) -> Result<Vec<String>>
Apply learned rules and get all matching actions
Sourcepub async fn apply_learned_rules_with_context(
&self,
generation_type: String,
language: String,
input: String,
) -> Result<Option<String>>
pub async fn apply_learned_rules_with_context( &self, generation_type: String, language: String, input: String, ) -> Result<Option<String>>
Apply learned rules with context-based matching
Sourcepub async fn record_rule_application(
&self,
rule_id: String,
success: bool,
application_time_ms: f64,
) -> Result<()>
pub async fn record_rule_application( &self, rule_id: String, success: bool, application_time_ms: f64, ) -> Result<()>
Record a rule application in analytics
Sourcepub async fn get_rule_metrics(
&self,
rule_id: &str,
) -> Result<Option<RuleMetrics>>
pub async fn get_rule_metrics( &self, rule_id: &str, ) -> Result<Option<RuleMetrics>>
Get metrics for a specific rule
Sourcepub async fn get_all_rule_metrics(&self) -> Result<Vec<RuleMetrics>>
pub async fn get_all_rule_metrics(&self) -> Result<Vec<RuleMetrics>>
Get all rule metrics
Sourcepub async fn update_rule_confidence(
&self,
rule_id: &str,
new_confidence: f32,
) -> Result<()>
pub async fn update_rule_confidence( &self, rule_id: &str, new_confidence: f32, ) -> Result<()>
Update rule confidence based on validation results
Sourcepub async fn generate_analytics_insights(&self) -> Result<AnalyticsInsights>
pub async fn generate_analytics_insights(&self) -> Result<AnalyticsInsights>
Generate analytics insights
Sourcepub async fn clear_analytics_metrics(&self) -> Result<()>
pub async fn clear_analytics_metrics(&self) -> Result<()>
Clear all analytics metrics
Sourcepub async fn get_metrics_for_scope(
&self,
scope: RuleScope,
) -> Result<Vec<RuleMetrics>>
pub async fn get_metrics_for_scope( &self, scope: RuleScope, ) -> Result<Vec<RuleMetrics>>
Get metrics for rules in a specific scope
Sourcepub async fn export_rules_with_metrics(
&self,
description: Option<String>,
) -> Result<String>
pub async fn export_rules_with_metrics( &self, description: Option<String>, ) -> Result<String>
Export rules with metrics to JSON
Sourcepub async fn export_rules_to_file(
&self,
path: &Path,
description: Option<String>,
) -> Result<()>
pub async fn export_rules_to_file( &self, path: &Path, description: Option<String>, ) -> Result<()>
Export rules with metrics to file
Sourcepub async fn import_rules_from_json(&self, json: &str) -> Result<Vec<Rule>>
pub async fn import_rules_from_json(&self, json: &str) -> Result<Vec<Rule>>
Import rules from JSON with validation
Sourcepub async fn import_rules_from_file(&self, path: &Path) -> Result<Vec<Rule>>
pub async fn import_rules_from_file(&self, path: &Path) -> Result<Vec<Rule>>
Import rules from file with validation