mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> Co-authored-by: Hannes Rudolph <hrudolph@gmail.com> Co-authored-by: Matt Rubens <mrubens@users.noreply.github.com>
98 lines
3.4 KiB
TypeScript
98 lines
3.4 KiB
TypeScript
import * as vscode from "vscode"
|
|
import { WebviewMessage } from "../../shared/WebviewMessage"
|
|
import { defaultModeSlug, getModeBySlug, getGroupName } from "../../shared/modes"
|
|
import { buildApiHandler } from "../../api"
|
|
import { experiments as experimentsModule, EXPERIMENT_IDS } from "../../shared/experiments"
|
|
|
|
import { SYSTEM_PROMPT } from "../prompts/system"
|
|
import { MultiSearchReplaceDiffStrategy } from "../diff/strategies/multi-search-replace"
|
|
import { MultiFileSearchReplaceDiffStrategy } from "../diff/strategies/multi-file-search-replace"
|
|
|
|
import { ClineProvider } from "./ClineProvider"
|
|
|
|
export const generateSystemPrompt = async (provider: ClineProvider, message: WebviewMessage) => {
|
|
const {
|
|
apiConfiguration,
|
|
customModePrompts,
|
|
customInstructions,
|
|
browserViewportSize,
|
|
diffEnabled,
|
|
mcpEnabled,
|
|
fuzzyMatchThreshold,
|
|
experiments,
|
|
enableMcpServerCreation,
|
|
browserToolEnabled,
|
|
language,
|
|
maxReadFileLine,
|
|
maxConcurrentFileReads,
|
|
} = await provider.getState()
|
|
|
|
// Check experiment to determine which diff strategy to use
|
|
const isMultiFileApplyDiffEnabled = experimentsModule.isEnabled(
|
|
experiments ?? {},
|
|
EXPERIMENT_IDS.MULTI_FILE_APPLY_DIFF,
|
|
)
|
|
|
|
const diffStrategy = isMultiFileApplyDiffEnabled
|
|
? new MultiFileSearchReplaceDiffStrategy(fuzzyMatchThreshold)
|
|
: new MultiSearchReplaceDiffStrategy(fuzzyMatchThreshold)
|
|
|
|
const cwd = provider.cwd
|
|
|
|
const mode = message.mode ?? defaultModeSlug
|
|
const customModes = await provider.customModesManager.getCustomModes()
|
|
|
|
const rooIgnoreInstructions = provider.getCurrentTask()?.rooIgnoreController?.getInstructions()
|
|
|
|
// Determine if browser tools can be used based on model support, mode, and user settings
|
|
let modelInfo: any = undefined
|
|
|
|
// Create a temporary API handler to check if the model supports browser capability
|
|
// This avoids relying on an active Cline instance which might not exist during preview
|
|
try {
|
|
const tempApiHandler = buildApiHandler(apiConfiguration)
|
|
modelInfo = tempApiHandler.getModel().info
|
|
} catch (error) {
|
|
console.error("Error checking if model supports browser capability:", error)
|
|
}
|
|
|
|
// Check if the current mode includes the browser tool group
|
|
const modeConfig = getModeBySlug(mode, customModes)
|
|
const modeSupportsBrowser = modeConfig?.groups.some((group) => getGroupName(group) === "browser") ?? false
|
|
|
|
// Check if model supports browser capability (images)
|
|
const modelSupportsBrowser = modelInfo && (modelInfo as any)?.supportsImages === true
|
|
|
|
// Only enable browser tools if the model supports it, the mode includes browser tools,
|
|
// and browser tools are enabled in settings
|
|
const canUseBrowserTool = modelSupportsBrowser && modeSupportsBrowser && (browserToolEnabled ?? true)
|
|
|
|
const systemPrompt = await SYSTEM_PROMPT(
|
|
provider.context,
|
|
cwd,
|
|
canUseBrowserTool,
|
|
mcpEnabled ? provider.getMcpHub() : undefined,
|
|
diffStrategy,
|
|
browserViewportSize ?? "900x600",
|
|
mode,
|
|
customModePrompts,
|
|
customModes,
|
|
customInstructions,
|
|
diffEnabled,
|
|
experiments,
|
|
enableMcpServerCreation,
|
|
language,
|
|
rooIgnoreInstructions,
|
|
maxReadFileLine !== -1,
|
|
{
|
|
maxConcurrentFileReads: maxConcurrentFileReads ?? 5,
|
|
todoListEnabled: apiConfiguration?.todoListEnabled ?? true,
|
|
useAgentRules: vscode.workspace.getConfiguration("roo-cline").get<boolean>("useAgentRules") ?? true,
|
|
newTaskRequireTodos: vscode.workspace
|
|
.getConfiguration("roo-cline")
|
|
.get<boolean>("newTaskRequireTodos", false),
|
|
},
|
|
)
|
|
|
|
return systemPrompt
|
|
}
|