Skip to content

Commit 8e48b73

Browse files
committed
Fix bug with role definition overrides for built-in modes
1 parent e211d83 commit 8e48b73

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"roo-cline": patch
3+
---
4+
5+
Fix bug with role definition overrides for built-in modes

src/core/prompts/__tests__/system.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,56 @@ describe("SYSTEM_PROMPT", () => {
350350
expect(customInstructionsIndex).toBeGreaterThan(userInstructionsHeader)
351351
})
352352

353+
it("should use promptComponent roleDefinition when available", async () => {
354+
const customPrompts = {
355+
[defaultModeSlug]: {
356+
roleDefinition: "Custom prompt role definition",
357+
customInstructions: "Custom prompt instructions",
358+
},
359+
}
360+
361+
const prompt = await SYSTEM_PROMPT(
362+
mockContext,
363+
"/test/path",
364+
false,
365+
undefined,
366+
undefined,
367+
undefined,
368+
defaultModeSlug,
369+
customPrompts,
370+
undefined,
371+
)
372+
373+
// Role definition from promptComponent should be at the top
374+
expect(prompt.indexOf("Custom prompt role definition")).toBeLessThan(prompt.indexOf("TOOL USE"))
375+
// Should not contain the default mode's role definition
376+
expect(prompt).not.toContain(modes[0].roleDefinition)
377+
})
378+
379+
it("should fallback to modeConfig roleDefinition when promptComponent has no roleDefinition", async () => {
380+
const customPrompts = {
381+
[defaultModeSlug]: {
382+
customInstructions: "Custom prompt instructions",
383+
// No roleDefinition provided
384+
},
385+
}
386+
387+
const prompt = await SYSTEM_PROMPT(
388+
mockContext,
389+
"/test/path",
390+
false,
391+
undefined,
392+
undefined,
393+
undefined,
394+
defaultModeSlug,
395+
customPrompts,
396+
undefined,
397+
)
398+
399+
// Should use the default mode's role definition
400+
expect(prompt.indexOf(modes[0].roleDefinition)).toBeLessThan(prompt.indexOf("TOOL USE"))
401+
})
402+
353403
afterAll(() => {
354404
jest.restoreAllMocks()
355405
})

src/core/prompts/system.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async function generatePrompt(
5454

5555
// Get the full mode config to ensure we have the role definition
5656
const modeConfig = getModeBySlug(mode, customModeConfigs) || modes.find((m) => m.slug === mode) || modes[0]
57-
const roleDefinition = modeConfig.roleDefinition
57+
const roleDefinition = promptComponent?.roleDefinition || modeConfig.roleDefinition
5858

5959
const basePrompt = `${roleDefinition}
6060

0 commit comments

Comments
 (0)