Skip to main content

lean_ctx/proxy/
adaptive_policy.rs

1//! Adaptive compression policy (OSS stub).
2//!
3//! The enterprise build replaces this with outcome-trained policies that learn
4//! from Value Gate feedback. In OSS mode, a static default policy is used.
5
6use serde::{Deserialize, Serialize};
7
8/// Compression tuning knobs applied per-request based on task classification.
9#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
10pub struct CompressionPolicy {
11    pub compress_tool_output: bool,
12    pub log_compression_level: u8,
13    pub code_preserve: bool,
14}
15
16impl Default for CompressionPolicy {
17    fn default() -> Self {
18        Self {
19            compress_tool_output: true,
20            log_compression_level: 2,
21            code_preserve: true,
22        }
23    }
24}
25
26/// Returns the best compression policy for the given task class.
27/// OSS: always returns the static default.
28pub fn best_policy_for(_task_class: &str) -> CompressionPolicy {
29    CompressionPolicy::default()
30}
31
32/// Selects the optimal policy (OSS: returns default).
33pub fn select_policy(_task_class: &str) -> CompressionPolicy {
34    CompressionPolicy::default()
35}
36
37/// Records a Value Gate outcome for policy feedback learning.
38/// OSS: no-op (no feedback loop without enterprise).
39pub fn record_value_gate_outcome(
40    _task_class: String,
41    _policy: CompressionPolicy,
42    _accepted: bool,
43    _savings_pct: f64,
44) {
45}
46
47/// Recorded policy outcome for feedback learning.
48#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq)]
49pub struct PolicyOutcome {
50    pub task_class: String,
51    pub policy_used: CompressionPolicy,
52    pub session_success: Option<bool>,
53    pub savings_pct: f64,
54}