Skip to main content

lean_ctx_ext/core/shadow/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Counterfactual cost and quality reporting for completed tasks.
3
4pub mod baseline;
5pub mod comparison;
6pub mod persistence;
7pub mod recommendation;
8pub mod runtime;
9
10pub use comparison::ShadowReport;
11pub use recommendation::ShadowTask;
12
13use baseline::simulate_baseline;
14use comparison::compare;
15use recommendation::measure_treatment;
16
17/// Runs the LeanCTX treatment beside a deterministic baseline without context reduction. Each
18/// task is compared with its own host-chosen model; only context changes count as savings.
19#[derive(Debug, Default)]
20pub struct ShadowEngine;
21
22impl ShadowEngine {
23    pub fn run_comparison(tasks: &[ShadowTask]) -> ShadowReport {
24        let baselines: Vec<_> = tasks.iter().map(simulate_baseline).collect();
25        let treatments: Vec<_> = tasks.iter().map(measure_treatment).collect();
26        compare(&baselines, &treatments)
27    }
28}
29
30pub fn run_comparison(tasks: &[ShadowTask]) -> ShadowReport {
31    ShadowEngine::run_comparison(tasks)
32}
33
34#[cfg(test)]
35mod runtime_tests;
36#[cfg(test)]
37mod tests;