From eee9644deca7bb06d2914ac732e54391b123ed31 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Tue, 8 Jul 2025 16:35:29 +0000 Subject: [PATCH] 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 --- .../sections/__tests__/custom-instructions.spec.ts | 6 ++++-- src/core/prompts/sections/custom-instructions.ts | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/core/prompts/sections/__tests__/custom-instructions.spec.ts b/src/core/prompts/sections/__tests__/custom-instructions.spec.ts index 9c8e003143..7c7ece4822 100644 --- a/src/core/prompts/sections/__tests__/custom-instructions.spec.ts +++ b/src/core/prompts/sections/__tests__/custom-instructions.spec.ts @@ -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 () => { diff --git a/src/core/prompts/sections/custom-instructions.ts b/src/core/prompts/sections/custom-instructions.ts index 3c8558a57f..92e5e09bf0 100644 --- a/src/core/prompts/sections/custom-instructions.ts +++ b/src/core/prompts/sections/custom-instructions.ts @@ -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