talos_agent/compaction/types.rs
1use thiserror::Error;
2
3/// Errors that can occur during context compaction.
4#[derive(Debug, Error)]
5pub enum CompactionError {
6 /// Token estimation failed during compaction.
7 #[error("token estimation failed")]
8 TokenEstimationFailed,
9
10 /// Compaction could not reduce context sufficiently.
11 #[error("compaction failed: {0}")]
12 CompactionFailed(String),
13
14 /// The circuit breaker has tripped due to repeated failures.
15 #[error("circuit breaker tripped after repeated compaction failures")]
16 CircuitBreakerTripped,
17
18 /// The LLM provider returned an error during summarization.
19 #[error("provider error: {0}")]
20 ProviderError(String),
21}
22
23/// Result alias for compaction operations.
24pub type CompactionResult<T> = Result<T, CompactionError>;
25
26/// Outcome of a compaction attempt, reported without exposing hidden tool output.
27///
28/// Status fields contain only counts and token estimates — never raw message
29/// content or tool result text. This is the hidden-output guard (MEM-005-A).
30#[derive(Debug, Clone, PartialEq)]
31pub enum CompactionStatus {
32 /// Compaction was applied successfully.
33 Applied {
34 /// Names of layers applied, in order (e.g., `["budget", "trim"]`).
35 layers_applied: Vec<&'static str>,
36 /// Estimated token count before compaction.
37 tokens_before: u32,
38 /// Estimated token count after compaction.
39 tokens_after: u32,
40 },
41 /// Compaction was skipped (context already fits or below threshold).
42 Skipped {
43 /// Why compaction was skipped.
44 reason: &'static str,
45 /// Current estimated token count.
46 tokens_current: u32,
47 },
48 /// Compaction failed.
49 Failed {
50 /// Error message (never includes tool result content).
51 error: String,
52 },
53}