lean_ctx/core/
solution_commercial.rs1use serde::{Deserialize, Serialize};
6
7const ENTERPRISE_LICENSE_REQUIRED: &str = "requires enterprise license";
8const ENTERPRISE_IMPLEMENTATION_BRANCH: &str = "enterprise/intelligence-layer";
9
10fn enterprise_license_error(feature_name: &str) -> String {
12 format!("{ENTERPRISE_LICENSE_REQUIRED}: {feature_name}")
13}
14
15fn enterprise_license_warning(feature_name: &str) {
17 eprintln!(
18 "warning: {} (implementation in {ENTERPRISE_IMPLEMENTATION_BRANCH} branch)",
19 enterprise_license_error(feature_name)
20 );
21}
22
23#[derive(Serialize, Deserialize, Clone, Debug)]
24#[serde(default)]
25pub struct AdaptiveConfig {
26 pub enabled: bool,
27 pub learning_rate: f64,
28 pub min_observations: u32,
29}
30
31impl Default for AdaptiveConfig {
32 fn default() -> Self {
33 Self {
34 enabled: false,
35 learning_rate: 0.1,
36 min_observations: 20,
37 }
38 }
39}
40
41#[derive(Serialize, Deserialize, Clone, Debug)]
42#[serde(default)]
43pub struct TeamPolicyConfig {
44 pub enabled: bool,
45 pub min_intensity: String,
46 pub require_decision_logging: bool,
47}
48
49impl Default for TeamPolicyConfig {
50 fn default() -> Self {
51 Self {
52 enabled: false,
53 min_intensity: "balanced".to_owned(),
54 require_decision_logging: false,
55 }
56 }
57}
58
59#[derive(Default, Serialize, Deserialize, Clone, Debug)]
60#[serde(default)]
61pub struct SolutionCommercialConfig {
62 pub adaptive: AdaptiveConfig,
63 pub team_policy: TeamPolicyConfig,
64 pub fingerprints_enabled: bool,
65 pub cross_project_patterns: bool,
66}
67
68pub fn commercial_features_available() -> Vec<(String, bool)> {
74 enterprise_license_warning("commercial_features_available");
75 Vec::new()
76}
77
78#[derive(Serialize, Clone, Debug)]
79pub struct AdaptiveRecommendation {
80 pub suggested_intensity: String,
81 pub confidence: f64,
82 pub reason: String,
83 pub observation_count: u32,
84}
85
86impl Default for AdaptiveRecommendation {
87 fn default() -> Self {
88 Self {
89 suggested_intensity: String::new(),
90 confidence: 0.0,
91 reason: String::new(),
92 observation_count: 0,
93 }
94 }
95}
96
97pub fn recommend_intensity(
99 _config: &AdaptiveConfig,
100 _decisions: &crate::core::solution_tracker::SolutionSnapshot,
101) -> Result<AdaptiveRecommendation, String> {
102 Err(enterprise_license_error("adaptive_intensity"))
103}
104
105#[derive(Serialize, Clone, Debug)]
106pub struct SolutionFingerprint {
107 pub task_pattern: String,
108 pub predicted_rung: String,
109 pub confidence: f64,
110}
111
112impl Default for SolutionFingerprint {
113 fn default() -> Self {
114 Self {
115 task_pattern: String::new(),
116 predicted_rung: String::new(),
117 confidence: 0.0,
118 }
119 }
120}
121
122pub fn predict_rung(_task_description: &str) -> Result<SolutionFingerprint, String> {
124 Err(enterprise_license_error("solution_fingerprints"))
125}
126
127pub fn validate_team_policy(
129 _policy: &TeamPolicyConfig,
130 _current_intensity: &str,
131) -> Result<(), String> {
132 Err(enterprise_license_error("team_policy"))
133}
134
135pub fn analyze_cross_project_patterns(_organization_id: &str) -> Result<(), String> {
142 Err(enterprise_license_error("cross_project_patterns"))
143}
144
145pub fn verify_attribution(_event_id: &str) -> Result<(), String> {
148 Err(enterprise_license_error("verified_attribution"))
149}
150
151pub fn append_solution_audit_event(_project_id: &str) -> Result<(), String> {
154 Err(enterprise_license_error("solution_audit_trail"))
155}
156
157#[cfg(test)]
158mod tests {
159 use super::*;
160
161 #[test]
162 fn adaptive_recommendations_are_gated_in_oss() {
163 let config = AdaptiveConfig {
164 enabled: true,
165 min_observations: 20,
166 ..AdaptiveConfig::default()
167 };
168 let decisions = crate::core::solution_tracker::SolutionSnapshot {
169 decisions_total: 19,
170 decisions_by_kind: Default::default(),
171 loc_added: 0,
172 loc_removed: 0,
173 loc_net_saved: 0,
174 output_tokens_baseline: 0,
175 output_tokens_actual: 0,
176 output_reduction_pct: 0,
177 };
178
179 assert_eq!(
180 recommend_intensity(&config, &decisions).unwrap_err(),
181 enterprise_license_error("adaptive_intensity")
182 );
183 }
184
185 #[test]
186 fn fingerprint_is_gated_in_oss() {
187 assert_eq!(
188 predict_rung("Refactor the request pipeline").unwrap_err(),
189 enterprise_license_error("solution_fingerprints")
190 );
191 }
192
193 #[test]
194 fn enabled_team_policy_still_requires_an_enterprise_license() {
195 let policy = TeamPolicyConfig {
196 enabled: true,
197 min_intensity: "balanced".to_owned(),
198 ..TeamPolicyConfig::default()
199 };
200
201 assert_eq!(
202 validate_team_policy(&policy, "minimal"),
203 Err(enterprise_license_error("team_policy"))
204 );
205 }
206
207 #[test]
208 fn disabled_policy_still_requires_an_enterprise_license() {
209 assert_eq!(
210 validate_team_policy(&TeamPolicyConfig::default(), "off"),
211 Err(enterprise_license_error("team_policy"))
212 );
213 }
214
215 #[test]
216 fn feature_availability_is_empty_in_oss() {
217 assert!(commercial_features_available().is_empty());
218 }
219
220 #[test]
221 fn enterprise_stubs_do_not_expose_commercial_logic() {
222 for result in [
223 analyze_cross_project_patterns("org-123"),
224 verify_attribution("event-123"),
225 append_solution_audit_event("project-123"),
226 ] {
227 assert!(
228 result
229 .expect_err("OSS commercial stub must require an enterprise license")
230 .starts_with(ENTERPRISE_LICENSE_REQUIRED)
231 );
232 }
233 }
234}