Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .tmp/Roo-Code
Submodule Roo-Code added at 86debe
61 changes: 55 additions & 6 deletions src/core/prompts/__tests__/custom-system-prompt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ describe("File-Based Custom System Prompt", () => {
expect(prompt).toContain(modes[0].roleDefinition)
expect(prompt).toContain(fileCustomSystemPrompt)

// Should not contain any of the default sections
expect(prompt).not.toContain("CAPABILITIES")
expect(prompt).not.toContain("MODES")
// After the fix, should now contain tool sections for proper tool usage
expect(prompt).toContain("TOOL USE")
expect(prompt).toContain("# Tools")
})

it("should combine file-based system prompt with role definition and custom instructions", async () => {
Expand Down Expand Up @@ -200,8 +200,57 @@ describe("File-Based Custom System Prompt", () => {
expect(prompt).toContain(customRoleDefinition)
expect(prompt).toContain(fileCustomSystemPrompt)

// Should not contain any of the default sections
expect(prompt).not.toContain("CAPABILITIES")
expect(prompt).not.toContain("MODES")
// After the fix, should now contain tool sections for proper tool usage
expect(prompt).toContain("TOOL USE")
expect(prompt).toContain("# Tools")
})

it("should include simplified read_file tool for code-supernova model with custom prompt", async () => {
// Mock the readFile to return content from a file
const fileCustomSystemPrompt = "Custom system prompt for code-supernova"
mockedFs.readFile.mockImplementation((filePath, options) => {
if (toPosix(filePath).includes(`.roo/system-prompt-${defaultModeSlug}`) && options === "utf-8") {
return Promise.resolve(fileCustomSystemPrompt)
}
return Promise.reject({ code: "ENOENT" })
})

const prompt = await SYSTEM_PROMPT(
mockContext,
"test/path",
false, // supportsComputerUse
undefined, // mcpHub
undefined, // diffStrategy
undefined, // browserViewportSize
defaultModeSlug, // mode
undefined, // customModePrompts
undefined, // customModes
undefined, // globalCustomInstructions
undefined, // diffEnabled
undefined, // experiments
true, // enableMcpServerCreation
undefined, // language
undefined, // rooIgnoreInstructions
undefined, // partialReadsEnabled
undefined, // settings
undefined, // todoList
"roo/code-supernova", // modelId - this is the key for this test
)

// Should contain the custom system prompt
expect(prompt).toContain(fileCustomSystemPrompt)

// Should contain tool descriptions
expect(prompt).toContain("# Tools")
expect(prompt).toContain("## read_file")

// Should contain the simplified read_file format for code-supernova
expect(prompt).toContain("<read_file>")
expect(prompt).toContain("<path>path/to/file</path>")
expect(prompt).toContain("</read_file>")

// Should NOT contain the complex multi-file read format
expect(prompt).not.toContain("<args>")
expect(prompt).not.toContain("You can read a maximum of 5 files")
})
})
40 changes: 39 additions & 1 deletion src/core/prompts/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,47 @@ export const SYSTEM_PROMPT = async (
},
)

// For file-based prompts, don't include the tool sections
// Get the full mode config to ensure we have the role definition (used for groups, etc.)
const modeConfig = getModeBySlug(mode, customModes) || modes.find((m) => m.slug === mode) || modes[0]

// Check if MCP functionality should be included
const hasMcpGroup = modeConfig.groups.some((groupEntry) => getGroupName(groupEntry) === "mcp")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: modeConfig.groups is accessed without a guard. A custom mode object may omit groups, causing a runtime error. Also applies to the earlier generatePrompt path.

Suggested change
const hasMcpGroup = modeConfig.groups.some((groupEntry) => getGroupName(groupEntry) === "mcp")
const hasMcpGroup = (modeConfig.groups || []).some((groupEntry) => getGroupName(groupEntry) === "mcp")

const hasMcpServers = mcpHub && mcpHub.getServers().length > 0
const shouldIncludeMcp = hasMcpGroup && hasMcpServers

// If diff is disabled, don't pass the diffStrategy
const effectiveDiffStrategy = diffEnabled ? diffStrategy : undefined

const codeIndexManager = CodeIndexManager.getInstance(context, cwd)

// Always include tool descriptions for file-based custom prompts
// This ensures models like code-supernova get the proper tool format
const toolDescriptions = getToolDescriptionsForMode(
mode,
cwd,
supportsComputerUse,
codeIndexManager,
effectiveDiffStrategy,
browserViewportSize,
shouldIncludeMcp ? mcpHub : undefined,
customModes,
experiments,
partialReadsEnabled,
settings,
enableMcpServerCreation,
modelId,
)

return `${roleDefinition}

${markdownFormattingSection()}

${getSharedToolUseSection()}

${toolDescriptions}

${getToolUseGuidelinesSection(codeIndexManager)}

${fileCustomSystemPrompt}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The custom file-based prompt is appended after the Roo Tool Use sections. Consider placing the user’s custom prompt before tool/guidelines to preserve authorial context, or clarify precedence so Roo tool sections supersede overlapping instructions.


${customInstructions}`
Expand Down
Loading