@@ -170,78 +170,61 @@ try {
170170 console . log ( "[AGENT] No .cursorrules file found" ) ;
171171}
172172
173- // Smart file selection: Include only the most relevant files based on task
174- // This keeps us under the 200K token limit while providing accurate context
175- let relevantFiles = "" ;
176- const taskLower = task . toLowerCase ( ) ;
173+ // Include all code files while excluding docs, images, and large files
174+ // This provides complete context while staying under 200K token limit
175+ let codebaseContent = "" ;
177176const fileList = files . split ( "\n" ) . filter ( f => f . trim ( ) ) ;
178177
179- // File patterns to check based on task keywords
180- const filePatterns = [
181- { keywords : [ "help" , "admin" , "command" ] , files : [ "templates/help/helpTextAdmin.txt" , "templates/help/helpText.txt" ] } ,
182- { keywords : [ "config" , "setting" ] , files : [ "config/config.json" , "src/config-handler.js" ] } ,
183- { keywords : [ "slack" , "message" , "notification" ] , files : [ "src/slack-handler.js" , "src/notification-handler.js" ] } ,
184- { keywords : [ "discord" ] , files : [ "src/discord-handler.js" ] } ,
185- { keywords : [ "sonos" , "speaker" , "playback" , "volume" ] , files : [ "src/sonos-handler.js" ] } ,
186- { keywords : [ "web" , "admin panel" , "webui" , "route" , "endpoint" ] , files : [ "src/webserver.js" , "public/admin.html" ] } ,
187- { keywords : [ "queue" , "track" ] , files : [ "src/queue-handler.js" ] } ,
188- { keywords : [ "vote" , "voting" ] , files : [ "src/voting-handler.js" ] } ,
189- { keywords : [ "ai" , "openai" , "gemini" ] , files : [ "src/ai-handler.js" ] } ,
190- { keywords : [ "test" ] , files : [ "test/unit/" ] } ,
178+ // Include code files, exclude non-code
179+ const includedExtensions = [ '.js' , '.mjs' , '.json' , '.txt' , '.html' , '.css' , '.yml' , '.yaml' ] ;
180+ const excludedPaths = [
181+ 'node_modules/' ,
182+ 'package-lock.json' ,
183+ '.git/' ,
184+ 'coverage/' ,
185+ 'dist/' ,
186+ 'build/' ,
187+ 'docs/' , // Exclude documentation
188+ 'README.md' , // Exclude large README
189+ 'CHANGELOG.md' , // Exclude changelog
190+ '.github/workflows/' , // Exclude workflow files (too verbose)
191+ 'test/' , // Exclude tests
191192] ;
192193
193- console . log ( "[AGENT] Identifying relevant files based on task ..." ) ;
194+ console . log ( "[AGENT] Loading codebase files..." ) ;
194195let filesIncluded = 0 ;
196+ let totalSize = 0 ;
195197
196- // First, include files that match task keywords
197- for ( const pattern of filePatterns ) {
198- if ( pattern . keywords . some ( keyword => taskLower . includes ( keyword ) ) ) {
199- for ( const filePath of pattern . files ) {
200- try {
201- // Handle directory patterns
202- if ( filePath . endsWith ( '/' ) ) {
203- const dirFiles = fileList . filter ( f => f . startsWith ( filePath ) ) ;
204- for ( const dirFile of dirFiles . slice ( 0 , 5 ) ) { // Limit to 5 files per directory
205- const content = fs . readFileSync ( dirFile , "utf8" ) ;
206- relevantFiles += `\n\n=== ${ dirFile } ===\n${ content } ` ;
207- filesIncluded ++ ;
208- console . log ( `[AGENT] Including ${ dirFile } ` ) ;
209- }
210- } else {
211- const content = fs . readFileSync ( filePath , "utf8" ) ;
212- relevantFiles += `\n\n=== ${ filePath } ===\n${ content } ` ;
213- filesIncluded ++ ;
214- console . log ( `[AGENT] Including ${ filePath } ` ) ;
215- }
216- } catch ( e ) {
217- // File doesn't exist, skip it
218- }
219- }
198+ for ( const filePath of fileList ) {
199+ // Skip excluded paths
200+ if ( excludedPaths . some ( excluded => filePath . includes ( excluded ) ) ) {
201+ continue ;
220202 }
221- }
222203
223- // If no specific files matched, include a summary of available files
224- if ( filesIncluded === 0 ) {
225- console . log ( "[AGENT] No keyword match - including key architecture files" ) ;
226- const keyFiles = [
227- "src/webserver.js" ,
228- "src/slack-handler.js" ,
229- "src/discord-handler.js" ,
230- "templates/help/helpTextAdmin.txt"
231- ] ;
232-
233- for ( const filePath of keyFiles ) {
234- try {
235- const content = fs . readFileSync ( filePath , "utf8" ) ;
236- relevantFiles += `\n\n=== ${ filePath } ===\n${ content } ` ;
237- filesIncluded ++ ;
238- } catch ( e ) {
239- // Skip if doesn't exist
204+ // Skip if not code extension
205+ if ( ! includedExtensions . some ( ext => filePath . endsWith ( ext ) ) ) {
206+ continue ;
207+ }
208+
209+ try {
210+ const stats = fs . statSync ( filePath ) ;
211+
212+ // Skip very large files (>50KB)
213+ if ( stats . size > 50000 ) {
214+ console . log ( `[AGENT] Skipping large file: ${ filePath } (${ stats . size } bytes)` ) ;
215+ continue ;
240216 }
217+
218+ const content = fs . readFileSync ( filePath , "utf8" ) ;
219+ codebaseContent += `\n\n=== ${ filePath } ===\n${ content } ` ;
220+ filesIncluded ++ ;
221+ totalSize += stats . size ;
222+ } catch ( e ) {
223+ // Skip files we can't read
241224 }
242225}
243226
244- console . log ( `[AGENT] Included ${ filesIncluded } relevant files for AI context ` ) ;
227+ console . log ( `[AGENT] Included ${ filesIncluded } code files ( ${ Math . round ( totalSize / 1024 ) } KB) ` ) ;
245228
246229// Build specialized prompt for SlackONOS
247230const prompt = `You are an autonomous coding agent for SlackONOS, a democratic music bot for Discord and Slack that controls Sonos speakers.
@@ -264,11 +247,8 @@ ${cursorRules}
264247Recent Commits:
265248${ recentCommits }
266249
267- Repository Files (for reference):
268- ${ files }
269-
270- RELEVANT FILE CONTENTS (use these exact contents for accurate diffs):
271- ${ relevantFiles }
250+ COMPLETE CODEBASE (use these exact contents for accurate diffs):
251+ ${ codebaseContent }
272252
273253TASK FROM ADMIN (${ requester } ):
274254${ task }
0 commit comments