bctx-forge 0.1.16

bctx-forge — OS execution substrate, signal capture, BPE tokenizer, SQLite tracker
Documentation
pub mod estimator;
pub mod policy;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BudgetPressure {
    Calm,
    Elevated,
    Critical,
    Overflow,
}

#[derive(Debug, Clone)]
pub struct SignalBudget {
    pub limit: usize,
    pub used: usize,
}

impl SignalBudget {
    pub fn new(limit: usize) -> Self {
        Self { limit, used: 0 }
    }

    pub fn remaining(&self) -> usize {
        self.limit.saturating_sub(self.used)
    }

    pub fn consume(&mut self, tokens: usize) {
        self.used += tokens;
    }

    pub fn pressure(&self) -> BudgetPressure {
        let pct = self.used as f64 / self.limit as f64;
        match pct {
            p if p >= 1.0 => BudgetPressure::Overflow,
            p if p >= 0.85 => BudgetPressure::Critical,
            p if p >= 0.65 => BudgetPressure::Elevated,
            _ => BudgetPressure::Calm,
        }
    }
}