Skip to main content

claude_native/scoring/
weights.rs

1use std::collections::HashMap;
2
3use crate::detection::{PrimaryType, ProjectType};
4use crate::rules::Dimension;
5
6/// Get dimension weights for a project type (from GOLDEN_RULES.md section 6.15)
7pub fn get_weights(project_type: &ProjectType) -> HashMap<Dimension, f64> {
8    let base = match &project_type.primary {
9        PrimaryType::Standard => standard_weights(),
10        PrimaryType::Monorepo => monorepo_weights(),
11        PrimaryType::MicroRepo => micro_repo_weights(),
12        PrimaryType::Mobile(_) => mobile_weights(),
13        PrimaryType::Frontend(_) => frontend_weights(),
14        PrimaryType::Backend(_) => backend_weights(),
15        PrimaryType::IaC(_) => iac_weights(),
16        PrimaryType::Serverless(_) => serverless_weights(),
17        PrimaryType::ML => ml_weights(),
18        PrimaryType::CodegenHeavy => codegen_weights(),
19        PrimaryType::DocSite(_) => doc_site_weights(),
20        PrimaryType::GameDev(_) => game_dev_weights(),
21    };
22
23    // Apply flag adjustments
24    let mut weights = base;
25    if project_type.flags.is_legacy {
26        // Legacy: boost Foundation and Code Quality
27        adjust(&mut weights, Dimension::Foundation, 0.05);
28        adjust(&mut weights, Dimension::CodeQuality, 0.05);
29        adjust(&mut weights, Dimension::ContextEfficiency, -0.05);
30        adjust(&mut weights, Dimension::Tooling, -0.05);
31    }
32
33    weights
34}
35
36fn adjust(weights: &mut HashMap<Dimension, f64>, dim: Dimension, delta: f64) {
37    if let Some(w) = weights.get_mut(&dim) {
38        *w = (*w + delta).max(0.05).min(0.50);
39    }
40}
41
42fn standard_weights() -> HashMap<Dimension, f64> {
43    HashMap::from([
44        (Dimension::Foundation, 0.25),
45        (Dimension::ContextEfficiency, 0.25),
46        (Dimension::Navigation, 0.20),
47        (Dimension::Tooling, 0.15),
48        (Dimension::CodeQuality, 0.15),
49    ])
50}
51
52fn monorepo_weights() -> HashMap<Dimension, f64> {
53    HashMap::from([
54        (Dimension::Foundation, 0.30),
55        (Dimension::ContextEfficiency, 0.25),
56        (Dimension::Navigation, 0.20),
57        (Dimension::Tooling, 0.15),
58        (Dimension::CodeQuality, 0.10),
59    ])
60}
61
62fn micro_repo_weights() -> HashMap<Dimension, f64> {
63    HashMap::from([
64        (Dimension::Foundation, 0.20),
65        (Dimension::ContextEfficiency, 0.20),
66        (Dimension::Navigation, 0.15),
67        (Dimension::Tooling, 0.15),
68        (Dimension::CodeQuality, 0.30),
69    ])
70}
71
72fn mobile_weights() -> HashMap<Dimension, f64> {
73    HashMap::from([
74        (Dimension::Foundation, 0.25),
75        (Dimension::ContextEfficiency, 0.30),
76        (Dimension::Navigation, 0.15),
77        (Dimension::Tooling, 0.15),
78        (Dimension::CodeQuality, 0.15),
79    ])
80}
81
82fn frontend_weights() -> HashMap<Dimension, f64> {
83    HashMap::from([
84        (Dimension::Foundation, 0.25),
85        (Dimension::ContextEfficiency, 0.30),
86        (Dimension::Navigation, 0.15),
87        (Dimension::Tooling, 0.15),
88        (Dimension::CodeQuality, 0.15),
89    ])
90}
91
92fn backend_weights() -> HashMap<Dimension, f64> {
93    HashMap::from([
94        (Dimension::Foundation, 0.25),
95        (Dimension::ContextEfficiency, 0.20),
96        (Dimension::Navigation, 0.20),
97        (Dimension::Tooling, 0.15),
98        (Dimension::CodeQuality, 0.20),
99    ])
100}
101
102fn iac_weights() -> HashMap<Dimension, f64> {
103    HashMap::from([
104        (Dimension::Foundation, 0.30),
105        (Dimension::ContextEfficiency, 0.20),
106        (Dimension::Navigation, 0.15),
107        (Dimension::Tooling, 0.20),
108        (Dimension::CodeQuality, 0.15),
109    ])
110}
111
112fn serverless_weights() -> HashMap<Dimension, f64> {
113    HashMap::from([
114        (Dimension::Foundation, 0.25),
115        (Dimension::ContextEfficiency, 0.25),
116        (Dimension::Navigation, 0.15),
117        (Dimension::Tooling, 0.20),
118        (Dimension::CodeQuality, 0.15),
119    ])
120}
121
122fn ml_weights() -> HashMap<Dimension, f64> {
123    HashMap::from([
124        (Dimension::Foundation, 0.20),
125        (Dimension::ContextEfficiency, 0.35),
126        (Dimension::Navigation, 0.10),
127        (Dimension::Tooling, 0.15),
128        (Dimension::CodeQuality, 0.20),
129    ])
130}
131
132fn codegen_weights() -> HashMap<Dimension, f64> {
133    HashMap::from([
134        (Dimension::Foundation, 0.25),
135        (Dimension::ContextEfficiency, 0.30),
136        (Dimension::Navigation, 0.15),
137        (Dimension::Tooling, 0.20),
138        (Dimension::CodeQuality, 0.10),
139    ])
140}
141
142fn doc_site_weights() -> HashMap<Dimension, f64> {
143    HashMap::from([
144        (Dimension::Foundation, 0.20),
145        (Dimension::ContextEfficiency, 0.25),
146        (Dimension::Navigation, 0.20),
147        (Dimension::Tooling, 0.15),
148        (Dimension::CodeQuality, 0.20),
149    ])
150}
151
152fn game_dev_weights() -> HashMap<Dimension, f64> {
153    HashMap::from([
154        (Dimension::Foundation, 0.25),
155        (Dimension::ContextEfficiency, 0.35),
156        (Dimension::Navigation, 0.15),
157        (Dimension::Tooling, 0.10),
158        (Dimension::CodeQuality, 0.15),
159    ])
160}