Skip to main content

bctx_forge/budget/
mod.rs

1pub mod estimator;
2pub mod policy;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum BudgetPressure {
6    Calm,
7    Elevated,
8    Critical,
9    Overflow,
10}
11
12#[derive(Debug, Clone)]
13pub struct SignalBudget {
14    pub limit: usize,
15    pub used: usize,
16}
17
18impl SignalBudget {
19    pub fn new(limit: usize) -> Self {
20        Self { limit, used: 0 }
21    }
22
23    pub fn remaining(&self) -> usize {
24        self.limit.saturating_sub(self.used)
25    }
26
27    pub fn consume(&mut self, tokens: usize) {
28        self.used += tokens;
29    }
30
31    pub fn pressure(&self) -> BudgetPressure {
32        let pct = self.used as f64 / self.limit as f64;
33        match pct {
34            p if p >= 1.0 => BudgetPressure::Overflow,
35            p if p >= 0.85 => BudgetPressure::Critical,
36            p if p >= 0.65 => BudgetPressure::Elevated,
37            _ => BudgetPressure::Calm,
38        }
39    }
40}