File tree Expand file tree Collapse file tree 2 files changed +32
-36
lines changed
Expand file tree Collapse file tree 2 files changed +32
-36
lines changed Original file line number Diff line number Diff line change 1515
1616use crate :: config:: Config ;
1717use dunce:: canonicalize as normalize_path;
18+ use std:: fs;
1819use std:: path:: PathBuf ;
1920use tokio:: io:: AsyncReadExt ;
2021use tracing:: error;
@@ -178,6 +179,36 @@ pub fn discover_project_doc_paths(config: &Config) -> std::io::Result<Vec<PathBu
178179 Ok ( found)
179180}
180181
182+ /// Returns `true` when the concatenated docs would exceed `max_bytes`, matching
183+ /// the truncation logic used while embedding project documentation.
184+ pub fn docs_truncated ( paths : & [ PathBuf ] , max_bytes : usize ) -> bool {
185+ if paths. is_empty ( ) {
186+ return false ;
187+ }
188+ if max_bytes == 0 {
189+ return true ;
190+ }
191+
192+ let mut remaining = max_bytes as u64 ;
193+ for path in paths {
194+ if remaining == 0 {
195+ return true ;
196+ }
197+ let size = match fs:: metadata ( path) {
198+ Ok ( meta) => meta. len ( ) ,
199+ Err ( _) => continue ,
200+ } ;
201+ if size == 0 {
202+ continue ;
203+ }
204+ if size > remaining {
205+ return true ;
206+ }
207+ remaining = remaining. saturating_sub ( size) ;
208+ }
209+ false
210+ }
211+
181212fn candidate_filenames < ' a > ( config : & ' a Config ) -> Vec < & ' a str > {
182213 let mut names: Vec < & ' a str > =
183214 Vec :: with_capacity ( 2 + config. project_doc_fallback_filenames . len ( ) ) ;
Original file line number Diff line number Diff line change @@ -6,9 +6,8 @@ use codex_app_server_protocol::AuthMode;
66use codex_core:: AuthManager ;
77use codex_core:: config:: Config ;
88use codex_core:: project_doc:: discover_project_doc_paths;
9- use std :: fs ;
9+ use codex_core :: project_doc :: docs_truncated ;
1010use std:: path:: Path ;
11- use std:: path:: PathBuf ;
1211use unicode_width:: UnicodeWidthStr ;
1312
1413use super :: account:: StatusAccountDisplay ;
@@ -89,40 +88,6 @@ pub(crate) fn compose_agents_summary(config: &Config) -> (String, bool) {
8988 }
9089}
9190
92- /// Replicates the truncation logic in `project_doc::read_project_docs` by
93- /// walking the resolved doc paths and tracking how much of the configured
94- /// budget remains. Returns `true` when any file would exceed the budget (or
95- /// when the budget is zero but docs exist), signaling that the TUI should warn
96- /// the user in `/status`.
97- fn docs_truncated ( paths : & [ PathBuf ] , max_bytes : usize ) -> bool {
98- if paths. is_empty ( ) {
99- return false ;
100- }
101- if max_bytes == 0 {
102- // Docs exist but embedding disabled entirely.
103- return true ;
104- }
105-
106- let mut remaining = max_bytes as u64 ;
107- for path in paths {
108- if remaining == 0 {
109- return true ;
110- }
111- let size = match fs:: metadata ( path) {
112- Ok ( meta) => meta. len ( ) ,
113- Err ( _) => continue ,
114- } ;
115- if size == 0 {
116- continue ;
117- }
118- if size > remaining {
119- return true ;
120- }
121- remaining = remaining. saturating_sub ( size) ;
122- }
123- false
124- }
125-
12691pub ( crate ) fn compose_account_display ( auth_manager : & AuthManager ) -> Option < StatusAccountDisplay > {
12792 let auth = auth_manager. auth ( ) ?;
12893
You can’t perform that action at this time.
0 commit comments