mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-22 05:11:06 -05:00
Refactor to support more sections in the future
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { architectMode, defaultPrompts } from "../../shared/modes"
|
||||
import { architectMode, defaultPrompts, PromptComponent } from "../../shared/modes"
|
||||
import { getToolDescriptionsForMode } from "./tools"
|
||||
import {
|
||||
getRulesSection,
|
||||
@@ -20,8 +20,8 @@ export const ARCHITECT_PROMPT = async (
|
||||
mcpHub?: McpHub,
|
||||
diffStrategy?: DiffStrategy,
|
||||
browserViewportSize?: string,
|
||||
customPrompt?: string,
|
||||
) => `${customPrompt || defaultPrompts[architectMode]}
|
||||
customPrompt?: PromptComponent,
|
||||
) => `${customPrompt?.roleDefinition || defaultPrompts[architectMode].roleDefinition}
|
||||
|
||||
${getSharedToolUseSection()}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Mode, askMode, defaultPrompts } from "../../shared/modes"
|
||||
import { Mode, askMode, defaultPrompts, PromptComponent } from "../../shared/modes"
|
||||
import { getToolDescriptionsForMode } from "./tools"
|
||||
import {
|
||||
getRulesSection,
|
||||
@@ -21,8 +21,8 @@ export const ASK_PROMPT = async (
|
||||
mcpHub?: McpHub,
|
||||
diffStrategy?: DiffStrategy,
|
||||
browserViewportSize?: string,
|
||||
customPrompt?: string,
|
||||
) => `${customPrompt || defaultPrompts[askMode]}
|
||||
customPrompt?: PromptComponent,
|
||||
) => `${customPrompt?.roleDefinition || defaultPrompts[askMode].roleDefinition}
|
||||
|
||||
${getSharedToolUseSection()}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Mode, codeMode, defaultPrompts } from "../../shared/modes"
|
||||
import { Mode, codeMode, defaultPrompts, PromptComponent } from "../../shared/modes"
|
||||
import { getToolDescriptionsForMode } from "./tools"
|
||||
import {
|
||||
getRulesSection,
|
||||
@@ -21,8 +21,8 @@ export const CODE_PROMPT = async (
|
||||
mcpHub?: McpHub,
|
||||
diffStrategy?: DiffStrategy,
|
||||
browserViewportSize?: string,
|
||||
customPrompt?: string,
|
||||
) => `${customPrompt || defaultPrompts[codeMode]}
|
||||
customPrompt?: PromptComponent,
|
||||
) => `${customPrompt?.roleDefinition || defaultPrompts[codeMode].roleDefinition}
|
||||
|
||||
${getSharedToolUseSection()}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { CODE_PROMPT } from "./code"
|
||||
import { ARCHITECT_PROMPT } from "./architect"
|
||||
import { ASK_PROMPT } from "./ask"
|
||||
import { Mode, codeMode, architectMode, askMode } from "./modes"
|
||||
import { CustomPrompts } from "../../shared/modes"
|
||||
import fs from 'fs/promises'
|
||||
import path from 'path'
|
||||
|
||||
@@ -64,7 +65,7 @@ export const SYSTEM_PROMPT = async (
|
||||
diffStrategy?: DiffStrategy,
|
||||
browserViewportSize?: string,
|
||||
mode: Mode = codeMode,
|
||||
customPrompts?: { ask?: string; code?: string; architect?: string; enhance?: string },
|
||||
customPrompts?: CustomPrompts,
|
||||
) => {
|
||||
switch (mode) {
|
||||
case architectMode:
|
||||
|
||||
@@ -16,7 +16,7 @@ import { ApiConfiguration, ApiProvider, ModelInfo } from "../../shared/api"
|
||||
import { findLast } from "../../shared/array"
|
||||
import { ApiConfigMeta, ExtensionMessage } from "../../shared/ExtensionMessage"
|
||||
import { HistoryItem } from "../../shared/HistoryItem"
|
||||
import { WebviewMessage } from "../../shared/WebviewMessage"
|
||||
import { WebviewMessage, PromptMode } from "../../shared/WebviewMessage"
|
||||
import { defaultPrompts } from "../../shared/modes"
|
||||
import { SYSTEM_PROMPT, addCustomInstructions } from "../prompts/system"
|
||||
import { fileExistsAtPath } from "../../utils/fs"
|
||||
@@ -731,6 +731,32 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
||||
|
||||
await this.postStateToWebview()
|
||||
break
|
||||
case "updateEnhancedPrompt":
|
||||
if (message.text !== undefined) {
|
||||
const existingPrompts = await this.getGlobalState("customPrompts") || {}
|
||||
|
||||
const updatedPrompts = {
|
||||
...existingPrompts,
|
||||
enhance: message.text
|
||||
}
|
||||
|
||||
await this.updateGlobalState("customPrompts", updatedPrompts)
|
||||
|
||||
// Get current state and explicitly include customPrompts
|
||||
const currentState = await this.getState()
|
||||
|
||||
const stateWithPrompts = {
|
||||
...currentState,
|
||||
customPrompts: updatedPrompts
|
||||
}
|
||||
|
||||
// Post state with prompts
|
||||
this.view?.webview.postMessage({
|
||||
type: "state",
|
||||
state: stateWithPrompts
|
||||
})
|
||||
}
|
||||
break
|
||||
case "updatePrompt":
|
||||
if (message.promptMode && message.customPrompt !== undefined) {
|
||||
const existingPrompts = await this.getGlobalState("customPrompts") || {}
|
||||
@@ -866,7 +892,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
||||
try {
|
||||
const { apiConfiguration, customPrompts, customInstructions, preferredLanguage, browserViewportSize, mcpEnabled } = await this.getState()
|
||||
const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) || ''
|
||||
|
||||
|
||||
const fullPrompt = await SYSTEM_PROMPT(
|
||||
cwd,
|
||||
apiConfiguration.openRouterModelInfo?.supportsComputerUse ?? false,
|
||||
|
||||
@@ -838,18 +838,6 @@ describe('ClineProvider', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('returns empty prompt for enhance mode', async () => {
|
||||
const enhanceHandler = getMessageHandler();
|
||||
await enhanceHandler({ type: 'getSystemPrompt', mode: 'enhance' })
|
||||
|
||||
expect(mockPostMessage).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: 'systemPrompt',
|
||||
text: ''
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test('handles errors gracefully', async () => {
|
||||
// Mock SYSTEM_PROMPT to throw an error
|
||||
const systemPrompt = require('../../prompts/system')
|
||||
|
||||
Reference in New Issue
Block a user