fix: show mode-specific instructions section with placeholder when empty (#5468)

- Modified addCustomInstructions to always show mode-specific section when string is provided
- Added placeholder text '(No mode-specific instructions set)' for empty content
- Updated test to expect placeholder text instead of empty string
- Ensures instruction sections are visible even when empty, improving user clarity
This commit is contained in:
Roo Code 2025-07-08 16:35:29 +00:00
parent 6ab57fae43
commit eee9644dec
2 changed files with 10 additions and 6 deletions

View file

@ -505,14 +505,16 @@ describe("addCustomInstructions", () => {
expect(result).toContain("Rules from .roorules-test-mode:\nmode specific rules")
})
it("should return empty string when no instructions provided", async () => {
it("should show placeholder text when no instructions provided", async () => {
// Simulate no .roo/rules directory
statMock.mockRejectedValueOnce({ code: "ENOENT" })
readFileMock.mockRejectedValue({ code: "ENOENT" })
const result = await addCustomInstructions("", "", "/fake/path", "", {})
expect(result).toBe("")
expect(result).toContain("Global Instructions:\n(No global instructions set)")
expect(result).toContain("Mode-specific Instructions:\n(No mode-specific instructions set)")
expect(result).toContain("USER'S CUSTOM INSTRUCTIONS")
})
it("should handle missing mode-specific rules file", async () => {

View file

@ -253,13 +253,15 @@ export async function addCustomInstructions(
}
// Add global instructions first
if (typeof globalCustomInstructions === "string" && globalCustomInstructions.trim()) {
sections.push(`Global Instructions:\n${globalCustomInstructions.trim()}`)
if (typeof globalCustomInstructions === "string") {
const trimmed = globalCustomInstructions.trim()
sections.push(`Global Instructions:\n${trimmed || "(No global instructions set)"}`)
}
// Add mode-specific instructions after
if (typeof modeCustomInstructions === "string" && modeCustomInstructions.trim()) {
sections.push(`Mode-specific Instructions:\n${modeCustomInstructions.trim()}`)
if (typeof modeCustomInstructions === "string") {
const trimmed = modeCustomInstructions.trim()
sections.push(`Mode-specific Instructions:\n${trimmed || "(No mode-specific instructions set)"}`)
}
// Add rules - include both mode-specific and generic rules if they exist