( context: vscode.ExtensionContext, cwd: string, supportsComputerUse: boolean, mode: Mode, mcpHub?: McpHub, diffStrategy?: DiffStrategy, promptComponent?: PromptComponent, customModeConfigs?: ModeConfig[], globalCustomInstructions?: string, experiments?: Record<string, boolean>, language?: string, rooIgnoreInstructions?: string, settings?: SystemPromptSettings, todoList?: TodoItem[], modelId?: string, skillsManager?: SkillsManager, )
| 39 | } |
| 40 | |
| 41 | async function generatePrompt( |
| 42 | context: vscode.ExtensionContext, |
| 43 | cwd: string, |
| 44 | supportsComputerUse: boolean, |
| 45 | mode: Mode, |
| 46 | mcpHub?: McpHub, |
| 47 | diffStrategy?: DiffStrategy, |
| 48 | promptComponent?: PromptComponent, |
| 49 | customModeConfigs?: ModeConfig[], |
| 50 | globalCustomInstructions?: string, |
| 51 | experiments?: Record<string, boolean>, |
| 52 | language?: string, |
| 53 | rooIgnoreInstructions?: string, |
| 54 | settings?: SystemPromptSettings, |
| 55 | todoList?: TodoItem[], |
| 56 | modelId?: string, |
| 57 | skillsManager?: SkillsManager, |
| 58 | ): Promise<string> { |
| 59 | if (!context) { |
| 60 | throw new Error("Extension context is required for generating system prompt") |
| 61 | } |
| 62 | |
| 63 | // Get the full mode config to ensure we have the role definition (used for groups, etc.) |
| 64 | const modeConfig = getModeBySlug(mode, customModeConfigs) || modes.find((m) => m.slug === mode) || modes[0] |
| 65 | const { roleDefinition, baseInstructions } = getModeSelection(mode, promptComponent, customModeConfigs) |
| 66 | |
| 67 | // Check if MCP functionality should be included |
| 68 | const hasMcpGroup = modeConfig.groups.some((groupEntry) => getGroupName(groupEntry) === "mcp") |
| 69 | const allowedMcpServers = modeConfig.allowedMcpServers |
| 70 | |
| 71 | // Hoist the allowlist Set once (matches the sibling call sites, e.g. mcp_server.ts) instead |
| 72 | // of constructing a new Set on every `.filter` iteration. |
| 73 | const allowSet = allowedMcpServers ? new Set(allowedMcpServers) : undefined |
| 74 | |
| 75 | let hasMcpServers = false |
| 76 | if (mcpHub) { |
| 77 | const servers = allowSet ? mcpHub.getServers().filter((s) => allowSet.has(s.name)) : mcpHub.getServers() |
| 78 | hasMcpServers = servers.length > 0 |
| 79 | } |
| 80 | const shouldIncludeMcp = hasMcpGroup && hasMcpServers |
| 81 | |
| 82 | const codeIndexManager = CodeIndexManager.getInstance(context, cwd) |
| 83 | |
| 84 | // Tool calling is native-only. |
| 85 | const effectiveProtocol = "native" |
| 86 | |
| 87 | const [modesSection, skillsSection] = await Promise.all([ |
| 88 | getModesSection(context), |
| 89 | getSkillsSection(skillsManager, mode as string), |
| 90 | ]) |
| 91 | |
| 92 | // Tools catalog is not included in the system prompt. |
| 93 | const toolsCatalog = "" |
| 94 | |
| 95 | const basePrompt = `${roleDefinition} |
| 96 | |
| 97 | ${markdownFormattingSection()} |
| 98 |
no test coverage detected