Skip to content

Commit ea426cc

Browse files
committed
feat: Add file content context to AICODE agent
- Agent now detects relevant files based on task keywords - Reads and includes actual file content in the prompt - Ensures AI generates diffs with accurate line numbers - Fixes patch application failures from outdated context This solves the issue where AI generated diffs didn't match actual file content, causing all patch strategies to fail.
1 parent 9b8b4e4 commit ea426cc

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

.github/agent/agent.mjs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,37 @@ try {
170170
console.log("[AGENT] No .cursorrules file found");
171171
}
172172

173+
// Try to identify and read relevant files based on the task
174+
// This helps the AI generate accurate diffs with correct line numbers
175+
let relevantFiles = "";
176+
const taskLower = task.toLowerCase();
177+
178+
// Common file patterns to check based on task keywords
179+
const filePatterns = [
180+
{ keywords: ["help", "admin", "command"], files: ["templates/help/helpTextAdmin.txt", "templates/help/helpText.txt"] },
181+
{ keywords: ["config", "setting"], files: ["config/config.json", "src/config-handler.js"] },
182+
{ keywords: ["slack", "message", "notification"], files: ["src/slack-handler.js", "src/notification-handler.js"] },
183+
{ keywords: ["discord"], files: ["src/discord-handler.js"] },
184+
{ keywords: ["sonos", "speaker", "playback"], files: ["src/sonos-handler.js"] },
185+
{ keywords: ["route", "endpoint", "web", "admin panel"], files: ["src/webserver.js", "public/admin.html"] },
186+
{ keywords: ["queue", "track"], files: ["src/queue-handler.js"] },
187+
{ keywords: ["vote", "voting"], files: ["src/voting-handler.js"] },
188+
];
189+
190+
for (const pattern of filePatterns) {
191+
if (pattern.keywords.some(keyword => taskLower.includes(keyword))) {
192+
for (const filePath of pattern.files) {
193+
try {
194+
const content = fs.readFileSync(filePath, "utf8");
195+
relevantFiles += `\n\n=== ${filePath} ===\n${content}`;
196+
console.log(`[AGENT] Including content of ${filePath} for context`);
197+
} catch (e) {
198+
// File doesn't exist, skip it
199+
}
200+
}
201+
}
202+
}
203+
173204
// Build specialized prompt for SlackONOS
174205
const prompt = `You are an autonomous coding agent for SlackONOS, a democratic music bot for Discord and Slack that controls Sonos speakers.
175206
@@ -194,6 +225,8 @@ ${files}
194225
Recent Commits:
195226
${recentCommits}
196227
228+
${relevantFiles ? `RELEVANT FILE CONTENTS (use these for accurate line numbers):\n${relevantFiles}` : ''}
229+
197230
TASK FROM ADMIN (${requester}):
198231
${task}
199232

0 commit comments

Comments
 (0)