Skip to main content

lean_ctx/core/
adaptive_policy.rs

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