Skip to main content

weavatrix_edit/
limits.rs

1/// Absolute UTF-8 byte ceiling for a caller-defined operation label.
2///
3/// This hard ceiling is independent of caller-configurable plan budgets so a
4/// validated plan cannot carry unbounded metadata into hashing or journaling.
5pub const MAX_PLAN_OPERATION_BYTES: usize = 4_096;
6
7/// Bounded validation limits for a multi-file edit plan.
8#[derive(Clone, Copy, Debug, Eq, PartialEq)]
9pub struct PlanLimits {
10    pub max_files: usize,
11    pub max_edits_per_file: usize,
12    pub max_total_edits: usize,
13    pub max_path_bytes: usize,
14    pub max_total_text_bytes: usize,
15}
16
17impl Default for PlanLimits {
18    fn default() -> Self {
19        Self {
20            max_files: 500,
21            max_edits_per_file: 2_000,
22            max_total_edits: 1_000_000,
23            max_path_bytes: 4_096,
24            max_total_text_bytes: 64 * 1024 * 1024,
25        }
26    }
27}
28
29/// Bounded in-memory application limits for one source file.
30#[derive(Clone, Copy, Debug, Eq, PartialEq)]
31pub struct ApplyLimits {
32    pub max_source_bytes: usize,
33    pub max_edits: usize,
34    pub max_output_bytes: usize,
35}
36
37impl Default for ApplyLimits {
38    fn default() -> Self {
39        Self {
40            max_source_bytes: 16 * 1024 * 1024,
41            max_edits: 2_000,
42            max_output_bytes: 64 * 1024 * 1024,
43        }
44    }
45}
46
47/// Resource limits for building a reusable full [`crate::LineIndex`].
48///
49/// The byte ceiling covers the line-start offset table, not the borrowed source
50/// text. Position-based one-shot application uses a separate sparse index
51/// bounded by the existing [`ApplyLimits::max_edits`] ceiling.
52#[derive(Clone, Copy, Debug, Eq, PartialEq)]
53pub struct LineIndexLimits {
54    pub max_lines: usize,
55    pub max_index_bytes: usize,
56}
57
58impl Default for LineIndexLimits {
59    fn default() -> Self {
60        Self {
61            max_lines: 1_000_000,
62            max_index_bytes: 8 * 1024 * 1024,
63        }
64    }
65}
66
67/// Hard resource limits for incrementally building one original-source batch.
68#[derive(Clone, Copy, Debug, Eq, PartialEq)]
69pub struct BatchLimits {
70    pub max_source_bytes: usize,
71    pub max_edits: usize,
72    pub max_before_bytes: usize,
73    pub max_replacement_bytes: usize,
74    pub max_output_bytes: usize,
75}
76
77impl Default for BatchLimits {
78    fn default() -> Self {
79        Self {
80            max_source_bytes: 16 * 1024 * 1024,
81            max_edits: 2_000,
82            max_before_bytes: 16 * 1024 * 1024,
83            max_replacement_bytes: 64 * 1024 * 1024,
84            max_output_bytes: 64 * 1024 * 1024,
85        }
86    }
87}