pub struct RuleBasedCompressor { /* private fields */ }Expand description
Regex-based compressor that applies operator- and LLM-evolved rules to tool output.
Rules are sorted deterministically by id to ensure stable application order.
Hit counts are stored in hits keyed by rule.id; the rules vec can be swapped
on reload without losing any unflushed counts.
§Invariants
- Rules are applied in
id-ascending order (deterministic). compressreturns the first successful match (earliest rule wins).- A rule is skipped when
globis set and does not matchtool_name. regex::Regex::replace_allguarantees linear time (no catastrophic backtracking). Nocatch_unwindis needed aroundreplace_all.
Implementations§
Source§impl RuleBasedCompressor
impl RuleBasedCompressor
Sourcepub async fn load(
store: Arc<CompressionRuleStore>,
max_output_lines: usize,
regex_timeout_ms: u64,
) -> Result<Self, CompressionError>
pub async fn load( store: Arc<CompressionRuleStore>, max_output_lines: usize, regex_timeout_ms: u64, ) -> Result<Self, CompressionError>
Load all active rules from the store and compile them.
Rules that fail compilation are skipped and logged as warnings.
regex_timeout_ms controls the DoS-safe regex compilation timeout passed to
super::safe_compile. Sourced from [tools.compression] regex_compile_timeout_ms.
§Errors
Returns CompressionError::Db if the store query fails.
Sourcepub async fn reload(&self) -> Result<(), CompressionError>
pub async fn reload(&self) -> Result<(), CompressionError>
Reload rules from the store, preserving hit counts for still-present rules and flushing counts for rules that no longer exist.
§Errors
Returns CompressionError::Db if the store query fails.
Sourcepub async fn flush_hit_counts(&self) -> Result<(), CompressionError>
pub async fn flush_hit_counts(&self) -> Result<(), CompressionError>
Drain pending hit counts into a batch and write them to the store.
Called during the maybe_autodream maintenance pass. Resets all counters
to zero after flushing.
§Errors
Returns a database error if the batch write fails.
Trait Implementations§
Source§impl Debug for RuleBasedCompressor
impl Debug for RuleBasedCompressor
Auto Trait Implementations§
impl !Freeze for RuleBasedCompressor
impl !RefUnwindSafe for RuleBasedCompressor
impl Send for RuleBasedCompressor
impl Sync for RuleBasedCompressor
impl Unpin for RuleBasedCompressor
impl UnsafeUnpin for RuleBasedCompressor
impl !UnwindSafe for RuleBasedCompressor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more