vtcode_core/tools/read_limits.rs
1//! Read limit configuration for file operations
2//!
3//! This module provides the single source of truth for bounding file reads.
4//! These functions are used by both the new `ReadFileHandler` and the legacy
5//! `read_file_legacy` path to ensure consistent behavior.
6
7use super::cache::file_read_cache_config;
8
9/// Default absolute ceiling on lines returned by a single `read_file` call.
10///
11/// Re-exported from [`vtcode_config::constants::optimization`] so there is a
12/// single source of truth for the default cap value.
13pub const DEFAULT_MAX_READ_LINES: usize = vtcode_config::constants::optimization::DEFAULT_MAX_READ_LINES;
14
15/// Update the read cache config (called during startup)
16pub fn configure_read_limits(_config: &vtcode_config::FileReadCacheConfig) {
17 // Configuration is managed by cache::configure_file_cache()
18 // This function is kept for backward compatibility but is now a no-op
19}
20
21/// Absolute ceiling (in lines) for a single line-based `read_file` call.
22///
23/// Returns the configured `max_read_lines`, or [`DEFAULT_MAX_READ_LINES`] when
24/// the value is zero/unspecified, so a misconfigured `0` never disables the cap.
25pub fn read_limit_lines() -> usize {
26 let cfg = file_read_cache_config();
27 if cfg.max_read_lines == 0 {
28 DEFAULT_MAX_READ_LINES
29 } else {
30 cfg.max_read_lines
31 }
32}
33
34/// Per-call absolute ceiling (in lines) for any line-based `read_file` path.
35///
36/// Single source of truth shared by the new `ReadFileHandler` and the legacy
37/// `read_file_legacy` path, so the two can never drift apart. The hard floor of
38/// `1` guarantees a misconfigured `0` can never open an unbounded read.
39pub fn absolute_line_cap() -> usize {
40 read_limit_lines().max(1)
41}