Skip to content

Commit 03c56c3

Browse files
committed
refactor: update loadRuleFiles to return single rule file content
- Modified loadRuleFiles function to return content from the first available rule file instead of combining multiple rule files. - Updated tests to reflect the new behavior of loading only the .roorules file content when available, ensuring clarity in rule file handling.
1 parent 5b1cc0c commit 03c56c3

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

src/core/prompts/sections/__tests__/custom-instructions.test.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ describe("loadRuleFiles", () => {
1414
mockedFs.readFile.mockResolvedValue(" content with spaces ")
1515
const result = await loadRuleFiles("/fake/path")
1616
expect(mockedFs.readFile).toHaveBeenCalled()
17-
expect(result).toBe(
18-
"\n# Rules from .roorules:\ncontent with spaces\n" + "\n# Rules from .clinerules:\ncontent with spaces\n",
19-
)
17+
expect(result).toBe("\n# Rules from .roorules:\ncontent with spaces\n")
2018
})
2119

2220
it("should handle ENOENT error", async () => {
@@ -47,7 +45,7 @@ describe("loadRuleFiles", () => {
4745
jest.clearAllMocks()
4846
})
4947

50-
it("should combine content from multiple rule files when they exist", async () => {
48+
it("should not combine content from multiple rule files when they exist", async () => {
5149
mockedFs.readFile.mockImplementation(((filePath: string | Buffer | URL | number) => {
5250
if (filePath.toString().endsWith(".roorules")) {
5351
return Promise.resolve("roo rules content")
@@ -59,9 +57,7 @@ describe("loadRuleFiles", () => {
5957
}) as any)
6058

6159
const result = await loadRuleFiles("/fake/path")
62-
expect(result).toBe(
63-
"\n# Rules from .roorules:\nroo rules content\n" + "\n# Rules from .clinerules:\ncline rules content\n",
64-
)
60+
expect(result).toBe("\n# Rules from .roorules:\nroo rules content\n")
6561
})
6662

6763
it("should handle when no rule files exist", async () => {

src/core/prompts/sections/custom-instructions.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ async function safeReadFile(filePath: string): Promise<string> {
1818

1919
export async function loadRuleFiles(cwd: string): Promise<string> {
2020
const ruleFiles = [".roorules", ".clinerules"]
21-
let combinedRules = ""
2221

2322
for (const file of ruleFiles) {
2423
const content = await safeReadFile(path.join(cwd, file))
2524
if (content) {
26-
combinedRules += `\n# Rules from ${file}:\n${content}\n`
25+
return `\n# Rules from ${file}:\n${content}\n`
2726
}
2827
}
2928

30-
return combinedRules
29+
return ""
3130
}
3231

3332
export async function addCustomInstructions(

0 commit comments

Comments
 (0)