Skip to content

Commit eee9644

Browse files
committed
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
1 parent 6ab57fa commit eee9644

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,14 +505,16 @@ describe("addCustomInstructions", () => {
505505
expect(result).toContain("Rules from .roorules-test-mode:\nmode specific rules")
506506
})
507507

508-
it("should return empty string when no instructions provided", async () => {
508+
it("should show placeholder text when no instructions provided", async () => {
509509
// Simulate no .roo/rules directory
510510
statMock.mockRejectedValueOnce({ code: "ENOENT" })
511511

512512
readFileMock.mockRejectedValue({ code: "ENOENT" })
513513

514514
const result = await addCustomInstructions("", "", "/fake/path", "", {})
515-
expect(result).toBe("")
515+
expect(result).toContain("Global Instructions:\n(No global instructions set)")
516+
expect(result).toContain("Mode-specific Instructions:\n(No mode-specific instructions set)")
517+
expect(result).toContain("USER'S CUSTOM INSTRUCTIONS")
516518
})
517519

518520
it("should handle missing mode-specific rules file", async () => {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,15 @@ export async function addCustomInstructions(
253253
}
254254

255255
// Add global instructions first
256-
if (typeof globalCustomInstructions === "string" && globalCustomInstructions.trim()) {
257-
sections.push(`Global Instructions:\n${globalCustomInstructions.trim()}`)
256+
if (typeof globalCustomInstructions === "string") {
257+
const trimmed = globalCustomInstructions.trim()
258+
sections.push(`Global Instructions:\n${trimmed || "(No global instructions set)"}`)
258259
}
259260

260261
// Add mode-specific instructions after
261-
if (typeof modeCustomInstructions === "string" && modeCustomInstructions.trim()) {
262-
sections.push(`Mode-specific Instructions:\n${modeCustomInstructions.trim()}`)
262+
if (typeof modeCustomInstructions === "string") {
263+
const trimmed = modeCustomInstructions.trim()
264+
sections.push(`Mode-specific Instructions:\n${trimmed || "(No mode-specific instructions set)"}`)
263265
}
264266

265267
// Add rules - include both mode-specific and generic rules if they exist

0 commit comments

Comments
 (0)