-
Notifications
You must be signed in to change notification settings - Fork 436
Expand file tree
/
Copy pathline_tracker.rs
More file actions
52 lines (47 loc) · 1.62 KB
/
Copy pathline_tracker.rs
File metadata and controls
52 lines (47 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::time::SystemTime;
use serde::{
Deserialize,
Serialize,
};
/// Contains metadata for tracking user and agent contribution metrics for a given file for
/// `fs_write` tool uses.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileLineTracker {
/// Line count at the end of the last `fs_write`
pub prev_fswrite_lines: usize,
/// Line count before `fs_write` executes
pub before_fswrite_lines: usize,
/// Line count after `fs_write` executes
pub after_fswrite_lines: usize,
/// Lines added by agent in the current operation
pub lines_added_by_agent: usize,
/// Lines removed by agent in the current operation
pub lines_removed_by_agent: usize,
/// Whether or not this is the first `fs_write` invocation
pub is_first_write: bool,
/// mtime of the file at the time it was last read by `fs_read`.
/// Used by `fs_write` to detect external modifications between read and write.
#[serde(skip)]
pub last_read_mtime: Option<SystemTime>,
}
impl Default for FileLineTracker {
fn default() -> Self {
Self {
prev_fswrite_lines: 0,
before_fswrite_lines: 0,
after_fswrite_lines: 0,
lines_added_by_agent: 0,
lines_removed_by_agent: 0,
is_first_write: true,
last_read_mtime: None,
}
}
}
impl FileLineTracker {
pub fn lines_by_user(&self) -> isize {
(self.before_fswrite_lines as isize) - (self.prev_fswrite_lines as isize)
}
pub fn lines_by_agent(&self) -> isize {
(self.lines_added_by_agent + self.lines_removed_by_agent) as isize
}
}