bctx-forge 0.1.16

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

use crate::signal::SignalKind;

#[derive(Debug, Clone)]
pub enum InterceptDecision {
    Capture(CaptureOpts),
    Passthrough,
    Reject(String),
}

#[derive(Debug, Clone, Default)]
pub struct CaptureOpts {
    pub capture_stderr: bool,
    pub timeout_secs: u64,
}

impl Default for InterceptDecision {
    fn default() -> Self {
        Self::Capture(CaptureOpts {
            capture_stderr: true,
            timeout_secs: 30,
        })
    }
}

pub trait CommandInterceptor: Send + Sync {
    fn intercept(&self, program: &str, args: &[String]) -> InterceptDecision;
}

/// Default interceptor: capture everything.
pub struct DefaultInterceptor;

impl CommandInterceptor for DefaultInterceptor {
    fn intercept(&self, program: &str, args: &[String]) -> InterceptDecision {
        let kind = SignalKind::from_program(program, args);
        match kind {
            SignalKind::Unknown => InterceptDecision::Passthrough,
            _ => InterceptDecision::Capture(CaptureOpts {
                capture_stderr: true,
                timeout_secs: 60,
            }),
        }
    }
}