Skip to main content

tea_context/
inspection.rs

1use std::ops::Range;
2
3use crate::{CacheScope, PromptModuleId, PromptProvenance, PromptSegmentId, TrustLevel};
4
5/// Final compiler disposition of one input segment.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum SegmentDisposition {
8    /// Full content appears in output.
9    Included,
10    /// Truncated content with marker appears in output.
11    Truncated,
12    /// Exact duplicate was deduplicated.
13    Duplicate,
14    /// Lower-precedence conflict was shadowed.
15    ConflictShadowed,
16    /// Explicit omit/truncate behavior could not fit the budget.
17    OmittedForBudget,
18}
19
20/// Explainable inspection row for one input prompt segment.
21#[derive(Debug, Clone, PartialEq, Eq)]
22pub struct PromptInspectionEntry {
23    module_id: PromptModuleId,
24    segment_id: PromptSegmentId,
25    provenance: PromptProvenance,
26    trust: TrustLevel,
27    cache_scope: CacheScope,
28    disposition: SegmentDisposition,
29    byte_range: Option<Range<usize>>,
30    rendered_bytes: usize,
31    estimated_tokens: usize,
32}
33
34impl PromptInspectionEntry {
35    #[allow(clippy::too_many_arguments)]
36    pub(crate) const fn new(
37        module_id: PromptModuleId,
38        segment_id: PromptSegmentId,
39        provenance: PromptProvenance,
40        trust: TrustLevel,
41        cache_scope: CacheScope,
42        disposition: SegmentDisposition,
43        byte_range: Option<Range<usize>>,
44        rendered_bytes: usize,
45        estimated_tokens: usize,
46    ) -> Self {
47        Self {
48            module_id,
49            segment_id,
50            provenance,
51            trust,
52            cache_scope,
53            disposition,
54            byte_range,
55            rendered_bytes,
56            estimated_tokens,
57        }
58    }
59    /// Returns source module.
60    #[must_use]
61    pub const fn module_id(&self) -> &PromptModuleId {
62        &self.module_id
63    }
64    /// Returns source segment.
65    #[must_use]
66    pub const fn segment_id(&self) -> &PromptSegmentId {
67        &self.segment_id
68    }
69    /// Returns source provenance.
70    #[must_use]
71    pub const fn provenance(&self) -> &PromptProvenance {
72        &self.provenance
73    }
74    /// Returns trust label.
75    #[must_use]
76    pub const fn trust(&self) -> TrustLevel {
77        self.trust
78    }
79    /// Returns cache scope.
80    #[must_use]
81    pub const fn cache_scope(&self) -> CacheScope {
82        self.cache_scope
83    }
84    /// Returns final disposition.
85    #[must_use]
86    pub const fn disposition(&self) -> SegmentDisposition {
87        self.disposition
88    }
89    /// Returns exact output content range, excluding separators.
90    #[must_use]
91    pub const fn byte_range(&self) -> Option<&Range<usize>> {
92        self.byte_range.as_ref()
93    }
94    /// Returns rendered content bytes excluding separators.
95    #[must_use]
96    pub const fn rendered_bytes(&self) -> usize {
97        self.rendered_bytes
98    }
99    /// Returns conservative rendered-content token estimate.
100    #[must_use]
101    pub const fn estimated_tokens(&self) -> usize {
102        self.estimated_tokens
103    }
104}