ai_agent/utils/
read_edit_context.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct ReadContext {
8 pub file_path: String,
9 pub start_line: Option<usize>,
10 pub end_line: Option<usize>,
11 pub offset: Option<usize>,
12 pub limit: Option<usize>,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct EditContext {
18 pub file_path: String,
19 pub operation: EditOperation,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
24pub enum EditOperation {
25 Replace {
26 old_string: String,
27 new_string: String,
28 },
29 Insert {
30 position: InsertPosition,
31 content: String,
32 },
33 Delete {
34 start_line: usize,
35 end_line: usize,
36 },
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41pub enum InsertPosition {
42 Before(usize),
43 After(usize),
44 At(usize),
45}
46
47impl ReadContext {
48 pub fn new(file_path: &str) -> Self {
49 Self {
50 file_path: file_path.to_string(),
51 start_line: None,
52 end_line: None,
53 offset: None,
54 limit: None,
55 }
56 }
57
58 pub fn with_lines(mut self, start: usize, end: usize) -> Self {
59 self.start_line = Some(start);
60 self.end_line = Some(end);
61 self
62 }
63
64 pub fn with_offset(mut self, offset: usize, limit: usize) -> Self {
65 self.offset = Some(offset);
66 self.limit = Some(limit);
67 self
68 }
69}
70
71impl EditContext {
72 pub fn replace(file_path: &str, old: &str, new: &str) -> Self {
73 Self {
74 file_path: file_path.to_string(),
75 operation: EditOperation::Replace {
76 old_string: old.to_string(),
77 new_string: new.to_string(),
78 },
79 }
80 }
81}