Skip to main content

weavatrix_edit/
limits.rs

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