Skip to main content

weavatrix_refactor_plan/
limits.rs

1use crate::{MAX_PLAN_OPERATION_BYTES, PlanError, PlanErrorCode};
2
3/// Hard ceilings applied before a refactor plan can be fingerprinted or executed.
4#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub struct RefactorPlanLimits {
6    pub max_operations: usize,
7    pub max_paths: usize,
8    pub max_path_bytes: usize,
9    pub max_operation_bytes: usize,
10    pub max_edits_per_file: usize,
11    pub max_total_edits: usize,
12    pub max_create_bytes_per_file: usize,
13    pub max_total_create_bytes: usize,
14    pub max_total_text_bytes: usize,
15    pub max_extension_bytes: usize,
16    pub max_extension_nodes: usize,
17    pub max_extension_depth: usize,
18    pub max_evidence_entries: usize,
19    pub max_evidence_text_bytes: usize,
20    pub max_code_bytes: usize,
21}
22
23impl Default for RefactorPlanLimits {
24    fn default() -> Self {
25        const MIB: usize = 1024 * 1024;
26        Self {
27            max_operations: 64,
28            max_paths: 64,
29            max_path_bytes: 4_096,
30            max_operation_bytes: 4_096,
31            max_edits_per_file: 2_000,
32            max_total_edits: 128_000,
33            max_create_bytes_per_file: 64 * MIB,
34            max_total_create_bytes: 256 * MIB,
35            max_total_text_bytes: 384 * MIB,
36            max_extension_bytes: 256 * 1024,
37            max_extension_nodes: 4_096,
38            max_extension_depth: 32,
39            max_evidence_entries: 10_000,
40            max_evidence_text_bytes: 8 * MIB,
41            max_code_bytes: 256,
42        }
43    }
44}
45
46impl RefactorPlanLimits {
47    pub(crate) fn validate(self) -> Result<(), PlanError> {
48        let values = [
49            self.max_operations,
50            self.max_paths,
51            self.max_path_bytes,
52            self.max_operation_bytes,
53            self.max_edits_per_file,
54            self.max_total_edits,
55            self.max_create_bytes_per_file,
56            self.max_total_create_bytes,
57            self.max_total_text_bytes,
58            self.max_extension_bytes,
59            self.max_extension_nodes,
60            self.max_extension_depth,
61            self.max_evidence_entries,
62            self.max_evidence_text_bytes,
63            self.max_code_bytes,
64        ];
65        if values.contains(&0)
66            || self.max_total_create_bytes < self.max_create_bytes_per_file
67            || self.max_operation_bytes > MAX_PLAN_OPERATION_BYTES
68        {
69            return Err(PlanError::new(
70                PlanErrorCode::InvalidPlan,
71                "refactor plan limits must be nonzero, internally consistent, and within absolute ceilings",
72            ));
73        }
74        Ok(())
75    }
76}
77
78/// Bounded statistics established by structural validation.
79#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
80pub struct PlanStats {
81    pub operations: usize,
82    pub paths: usize,
83    pub edits: usize,
84    pub edit_text_bytes: usize,
85    pub create_bytes: usize,
86}