Skip to main content

vtcode_core/tools/file_ops/
mod.rs

1//! File operation tools with composable functionality.
2//!
3//! This module provides the `FileOpsTool` for file discovery and listing operations,
4//! along with supporting utilities for diff previews and path helpers.
5
6mod diff_preview;
7mod list;
8mod path_policy;
9mod read;
10mod tool;
11mod write;
12
13pub use diff_preview::{
14    build_diff_preview, diff_preview_error_skip, diff_preview_size_skip, diff_preview_suppressed,
15};
16pub use tool::FileOpsTool;
17pub use vtcode_commons::fs::is_image_path;
18
19/// Restore exact text content by accounting for trailing newline differences.
20///
21/// When a file's byte size is slightly larger than the content string length,
22/// this reconstructs the original content by appending the missing trailing
23/// newline(s). Returns `None` if the size mismatch is unexpected.
24pub(crate) fn restore_exact_text_content(content: &str, size_bytes: u64) -> Option<String> {
25    let content_size = content.len() as u64;
26    match size_bytes.checked_sub(content_size) {
27        Some(0) => Some(content.to_string()),
28        Some(1) => Some(format!("{content}\n")),
29        Some(2) if content.contains("\r\n") || !content.contains('\n') => {
30            Some(format!("{content}\r\n"))
31        }
32        _ => None,
33    }
34}