#![allow(clippy::multiple_crate_versions)]
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use aprender::format::{self, Compression, ModelType, SaveOptions};
use aprender::metrics::drift::{DriftConfig, DriftDetector, DriftStatus};
use aprender::primitives::Matrix;
use aprender::tree::RandomForestClassifier;
use serde::{Deserialize, Serialize};
pub mod categories;
pub mod classifier;
pub mod corpus;
pub mod features;
pub use categories::ErrorCategory;
pub use classifier::ErrorClassifier;
pub use corpus::{Corpus, TrainingExample};
pub use features::ErrorFeatures;
#[derive(Debug, thiserror::Error)]
pub enum OracleError {
#[error("Model error: {0}")]
Model(String),
#[error("Feature extraction error: {0}")]
Feature(String),
#[error("Training error: {0}")]
Training(String),
#[error("Classification error: {0}")]
Classification(String),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
}
pub type Result<T> = std::result::Result<T, OracleError>;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ClassificationResult {
pub category: ErrorCategory,
pub confidence: f32,
pub suggested_fix: Option<String>,
pub related_patterns: Vec<String>,
}
#[derive(Clone, Debug)]
pub struct OracleConfig {
pub n_estimators: usize,
pub max_depth: usize,
pub random_state: Option<u64>,
}
impl Default for OracleConfig {
fn default() -> Self {
Self {
n_estimators: 100,
max_depth: 10,
random_state: Some(42),
}
}
}
const DEFAULT_MODEL_NAME: &str = "bashrs_oracle.apr";
pub struct Oracle {
classifier: RandomForestClassifier,
#[allow(dead_code)]
config: OracleConfig,
#[allow(dead_code)]
categories: Vec<ErrorCategory>,
fix_templates: HashMap<ErrorCategory, Vec<String>>,
drift_detector: DriftDetector,
performance_history: Vec<f32>,
is_trained: bool,
}
impl Default for Oracle {
fn default() -> Self {
Self::new()
}
}
include!("lib_oracle.rs");