Skip to main content

agent_sessions/reader/
options.rs

1use crate::{CodexUsageMode, EventKinds, ReadError};
2use serde::Serialize;
3use std::collections::BTreeMap;
4
5#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
6#[non_exhaustive]
7pub enum TailMode {
8    #[default]
9    Strict,
10    AllowIncomplete,
11}
12
13#[derive(Debug, Clone)]
14pub struct ReadOptions {
15    pub accounting: crate::AccountingPolicy,
16    pub max_file_bytes: Option<u64>,
17    /// Includes the line delimiter. Enforced before allocating the whole line.
18    pub max_line_bytes: Option<usize>,
19    pub stop_at_byte: Option<u64>,
20    pub include: EventKinds,
21    pub tail: TailMode,
22    pub codex_usage: CodexUsageMode,
23}
24impl Default for ReadOptions {
25    fn default() -> Self {
26        Self {
27            max_file_bytes: Some(200 * 1024 * 1024),
28            max_line_bytes: Some(8 * 1024 * 1024),
29            stop_at_byte: None,
30            include: EventKinds::ALL,
31            tail: TailMode::Strict,
32            codex_usage: CodexUsageMode::TokenCount,
33            accounting: crate::AccountingPolicy::Strict,
34        }
35    }
36}
37impl ReadOptions {
38    pub(crate) fn validate(&self) -> Result<(), ReadError> {
39        if matches!((self.stop_at_byte,self.max_file_bytes),(Some(s),Some(m)) if s>m) {
40            return Err(ReadError::InvalidOptions("snapshot exceeds byte budget"));
41        }
42        Ok(())
43    }
44}
45
46#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize)]
47#[non_exhaustive]
48pub enum ReadStatus {
49    Complete,
50    CompleteWithErrors,
51    IncompleteTail,
52    #[default]
53    StoppedEarly,
54    Failed,
55}
56
57#[derive(Debug, Clone, Default, Serialize)]
58pub struct ReadSummary {
59    pub status: ReadStatus,
60    pub lines: u64,
61    pub bytes_read: u64,
62    /// End of the contiguous, error-free, fully delivered record prefix.
63    pub last_complete_byte: u64,
64    pub truncated_tail: bool,
65    pub line_errors: u64,
66    pub unknown_types: BTreeMap<String, u64>,
67    pub ignored_types: BTreeMap<String, u64>,
68}
69impl ReadSummary {
70    pub fn is_complete(&self) -> bool {
71        self.status == ReadStatus::Complete
72    }
73}