Roo-Code/src/core/webview/generateSystemPrompt.ts
Roo Code b486282f6b feat: add Jupyter notebook cell-level support
- Implement JupyterNotebookHandler for cell-aware operations
- Add cell-level editing, diffing, and checkpoint support
- Update extract-text to use cell markers for better readability
- Create JupyterNotebookDiffStrategy for notebook-specific operations
- Auto-detect and use Jupyter strategy for .ipynb files
- Add comprehensive tests for Jupyter notebook handling

Fixes #7609
2025-09-03 02:50:32 +00:00

96 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 { JupyterNotebookDiffStrategy } from "../diff/strategies/jupyter-notebook-diff"
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 modelSupportsComputerUse = false
// Create a temporary API handler to check if the model supports computer use
// This avoids relying on an active Cline instance which might not exist during preview
try {
const tempApiHandler = buildApiHandler(apiConfiguration)
modelSupportsComputerUse = tempApiHandler.getModel().info.supportsComputerUse ?? false
} catch (error) {
console.error("Error checking if model supports computer use:", 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
// Only enable browser tools if the model supports it, the mode includes browser tools,
// and browser tools are enabled in settings
const canUseBrowserTool = modelSupportsComputerUse && 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
}