agentic_codebase/collective/
patterns.rs1use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
10pub enum PatternCategory {
11 DesignPattern,
13 ApiUsage,
15 ErrorHandling,
17 Concurrency,
19 DataTransform,
21 TestingPattern,
23}
24
25impl std::fmt::Display for PatternCategory {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 match self {
28 Self::DesignPattern => write!(f, "design-pattern"),
29 Self::ApiUsage => write!(f, "api-usage"),
30 Self::ErrorHandling => write!(f, "error-handling"),
31 Self::Concurrency => write!(f, "concurrency"),
32 Self::DataTransform => write!(f, "data-transform"),
33 Self::TestingPattern => write!(f, "testing-pattern"),
34 }
35 }
36}
37
38#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
40pub enum ComplexityBucket {
41 Low,
43 Medium,
45 High,
47 VeryHigh,
49}
50
51impl ComplexityBucket {
52 pub fn from_complexity(complexity: u32) -> Self {
54 match complexity {
55 0..=5 => Self::Low,
56 6..=15 => Self::Medium,
57 16..=30 => Self::High,
58 _ => Self::VeryHigh,
59 }
60 }
61}
62
63impl std::fmt::Display for ComplexityBucket {
64 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65 match self {
66 Self::Low => write!(f, "low"),
67 Self::Medium => write!(f, "medium"),
68 Self::High => write!(f, "high"),
69 Self::VeryHigh => write!(f, "very-high"),
70 }
71 }
72}
73
74#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
76pub enum PatternQuality {
77 Established,
79 Emerging,
81 Declining,
83 Unknown,
85}
86
87impl std::fmt::Display for PatternQuality {
88 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
89 match self {
90 Self::Established => write!(f, "established"),
91 Self::Emerging => write!(f, "emerging"),
92 Self::Declining => write!(f, "declining"),
93 Self::Unknown => write!(f, "unknown"),
94 }
95 }
96}
97
98#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct PatternSignature {
101 pub language: String,
103 pub category: PatternCategory,
105 pub structure_hash: String,
107 pub description: String,
109}
110
111#[derive(Debug, Clone, Serialize, Deserialize)]
113pub struct UsagePattern {
114 pub signature: PatternSignature,
116 pub occurrence_count: u32,
118 pub quality: PatternQuality,
120 pub confidence: f32,
122 pub typical_complexity: ComplexityBucket,
124 pub example_paths: Vec<String>,
126}
127
128#[derive(Debug, Clone)]
133pub struct PatternExtractor {
134 min_occurrences: u32,
136}
137
138impl PatternExtractor {
139 pub fn new() -> Self {
141 Self { min_occurrences: 2 }
142 }
143
144 pub fn with_min_occurrences(min_occurrences: u32) -> Self {
146 Self { min_occurrences }
147 }
148
149 pub fn extract(&self, _graph: &crate::graph::CodeGraph) -> Vec<UsagePattern> {
155 tracing::debug!(
157 "PatternExtractor::extract called (min_occurrences={}); returning empty (placeholder).",
158 self.min_occurrences
159 );
160 Vec::new()
161 }
162
163 pub fn min_occurrences(&self) -> u32 {
165 self.min_occurrences
166 }
167}
168
169impl Default for PatternExtractor {
170 fn default() -> Self {
171 Self::new()
172 }
173}