From 8e48b734a5e260158be3e45a1cb5b2ee4dc3dc8b Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Wed, 22 Jan 2025 08:42:01 -0800 Subject: [PATCH] Fix bug with role definition overrides for built-in modes --- .changeset/purple-grapes-destroy.md | 5 +++ src/core/prompts/__tests__/system.test.ts | 50 +++++++++++++++++++++++ src/core/prompts/system.ts | 2 +- 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 .changeset/purple-grapes-destroy.md diff --git a/.changeset/purple-grapes-destroy.md b/.changeset/purple-grapes-destroy.md new file mode 100644 index 0000000..ace0241 --- /dev/null +++ b/.changeset/purple-grapes-destroy.md @@ -0,0 +1,5 @@ +--- +"roo-cline": patch +--- + +Fix bug with role definition overrides for built-in modes diff --git a/src/core/prompts/__tests__/system.test.ts b/src/core/prompts/__tests__/system.test.ts index d22f834..6ecf7ef 100644 --- a/src/core/prompts/__tests__/system.test.ts +++ b/src/core/prompts/__tests__/system.test.ts @@ -350,6 +350,56 @@ describe("SYSTEM_PROMPT", () => { expect(customInstructionsIndex).toBeGreaterThan(userInstructionsHeader) }) + it("should use promptComponent roleDefinition when available", async () => { + const customPrompts = { + [defaultModeSlug]: { + roleDefinition: "Custom prompt role definition", + customInstructions: "Custom prompt instructions", + }, + } + + const prompt = await SYSTEM_PROMPT( + mockContext, + "/test/path", + false, + undefined, + undefined, + undefined, + defaultModeSlug, + customPrompts, + undefined, + ) + + // Role definition from promptComponent should be at the top + expect(prompt.indexOf("Custom prompt role definition")).toBeLessThan(prompt.indexOf("TOOL USE")) + // Should not contain the default mode's role definition + expect(prompt).not.toContain(modes[0].roleDefinition) + }) + + it("should fallback to modeConfig roleDefinition when promptComponent has no roleDefinition", async () => { + const customPrompts = { + [defaultModeSlug]: { + customInstructions: "Custom prompt instructions", + // No roleDefinition provided + }, + } + + const prompt = await SYSTEM_PROMPT( + mockContext, + "/test/path", + false, + undefined, + undefined, + undefined, + defaultModeSlug, + customPrompts, + undefined, + ) + + // Should use the default mode's role definition + expect(prompt.indexOf(modes[0].roleDefinition)).toBeLessThan(prompt.indexOf("TOOL USE")) + }) + afterAll(() => { jest.restoreAllMocks() }) diff --git a/src/core/prompts/system.ts b/src/core/prompts/system.ts index 017e1e9..2546adc 100644 --- a/src/core/prompts/system.ts +++ b/src/core/prompts/system.ts @@ -54,7 +54,7 @@ async function generatePrompt( // Get the full mode config to ensure we have the role definition const modeConfig = getModeBySlug(mode, customModeConfigs) || modes.find((m) => m.slug === mode) || modes[0] - const roleDefinition = modeConfig.roleDefinition + const roleDefinition = promptComponent?.roleDefinition || modeConfig.roleDefinition const basePrompt = `${roleDefinition}