@@ -20,6 +20,7 @@ import type {
2020 CustomToolDefinitions ,
2121 FileTreeNode ,
2222} from '../../common/src/util/file'
23+ import path from 'path'
2324
2425export type RunState = {
2526 sessionState : SessionState
@@ -108,21 +109,25 @@ async function computeProjectIndex(
108109 * Discovers project files using .gitignore patterns when projectFiles is undefined
109110 */
110111function discoverProjectFiles ( cwd : string ) : Record < string , string > {
111- try {
112- const fileTree = getProjectFileTree ( cwd )
113- const filePaths = getAllFilePaths ( fileTree )
114-
115- // Create projectFiles with empty content - the token scorer will read from disk
116- return Object . fromEntries (
117- filePaths . map ( ( filePath ) => [
118- filePath ,
119- fs . readFileSync ( filePath , 'utf8' ) ,
120- ] ) ,
121- )
122- } catch ( error ) {
123- console . warn ( 'Failed to discover project files:' , error )
124- return { }
112+ const fileTree = getProjectFileTree ( cwd )
113+ const filePaths = getAllFilePaths ( fileTree )
114+ let error
115+
116+ // Create projectFiles with empty content - the token scorer will read from disk
117+ const projectFiles = Object . fromEntries (
118+ filePaths . map ( ( filePath ) => {
119+ try {
120+ return [ filePath , fs . readFileSync ( path . join ( cwd , filePath ) , 'utf8' ) ]
121+ } catch ( err ) {
122+ error = err
123+ return [ filePath , '[ERROR_READING_FILE]' ]
124+ }
125+ } ) ,
126+ )
127+ if ( error ) {
128+ console . warn ( 'Failed to discover some project files:' , error )
125129 }
130+ return projectFiles
126131}
127132
128133/**
0 commit comments