From 26fa12fa93b19790a1fb94975aed60a26f614535 Mon Sep 17 00:00:00 2001 From: Magesh Date: Sat, 6 Sep 2025 00:39:04 +0530 Subject: [PATCH] fix: enhance system prompts and improve embedding configuration extraction --- .../system-prompt/build-system-prompt.ts | 14 ++++++- .../local-models/compact-system-prompt.ts | 2 +- .../next-gen-models/next-gen-system-prompt.ts | 26 +++++++++++-- src/core/storage/CacheService.ts | 38 +++++++++---------- .../src/components/experts/ExpertsView.tsx | 28 +++++++++++++- 5 files changed, 83 insertions(+), 25 deletions(-) diff --git a/src/core/prompts/system-prompt/build-system-prompt.ts b/src/core/prompts/system-prompt/build-system-prompt.ts index 0fcf26e1..ded0b311 100644 --- a/src/core/prompts/system-prompt/build-system-prompt.ts +++ b/src/core/prompts/system-prompt/build-system-prompt.ts @@ -27,11 +27,23 @@ export const buildSystemPrompt = async ( if (providerInfo.customPrompt === "compact" && isLocalModelFamily(providerInfo.providerId)) { return SYSTEM_PROMPT_COMPACT(cwd, supportsBrowserUse, mcpHub, browserSettings, focusChainSettings) } + // New prompts per family can be added as granularly as we like by adding a folder in the "families" folder // We then discriminate between families with a functions in the utils. if (isNextGenModelFamily(apiHandlerModel.id)) { - return SYSTEM_PROMPT_NEXT_GEN(cwd, supportsBrowserUse, mcpHub, browserSettings, focusChainSettings) + return SYSTEM_PROMPT_NEXT_GEN( + cwd, + supportsBrowserUse, + mcpHub, + browserSettings, + focusChainSettings, + supportsCodeIndex, + expertPrompt, + isDeepCrawlEnabled, + expertName, + ) } + return haiSystemPrompt( cwd, supportsBrowserUse, diff --git a/src/core/prompts/system-prompt/families/local-models/compact-system-prompt.ts b/src/core/prompts/system-prompt/families/local-models/compact-system-prompt.ts index b907b9ab..ebefedfb 100644 --- a/src/core/prompts/system-prompt/families/local-models/compact-system-prompt.ts +++ b/src/core/prompts/system-prompt/families/local-models/compact-system-prompt.ts @@ -12,7 +12,7 @@ export const SYSTEM_PROMPT_COMPACT = async ( _browserSettings: BrowserSettings, _focusChainSettings: FocusChainSettings, ) => { - return `**CLINE — Identity & Mission** + return `**HAI — Identity & Mission** Senior software engineer + precise task runner. Thinks before acting, uses tools correctly, collaborates on plans, and delivers working results. ==== diff --git a/src/core/prompts/system-prompt/families/next-gen-models/next-gen-system-prompt.ts b/src/core/prompts/system-prompt/families/next-gen-models/next-gen-system-prompt.ts index 51631798..16249f1d 100644 --- a/src/core/prompts/system-prompt/families/next-gen-models/next-gen-system-prompt.ts +++ b/src/core/prompts/system-prompt/families/next-gen-models/next-gen-system-prompt.ts @@ -4,6 +4,13 @@ import { FocusChainSettings } from "@shared/FocusChainSettings" import { getShell } from "@utils/shell" import os from "os" import osName from "os-name" +import { + customCapabilitiesPrompt, + customObjectivePrompt, + customRulesPrompt, + customToolsPrompt, + customToolUseGuidelinePrompt, +} from "@/core/prompts/custom" export const SYSTEM_PROMPT_NEXT_GEN = async ( cwd: string, @@ -11,8 +18,14 @@ export const SYSTEM_PROMPT_NEXT_GEN = async ( mcpHub: McpHub, browserSettings: BrowserSettings, focusChainSettings: FocusChainSettings, + + // TAG:HAI + supportsCodeIndex: boolean, + expertPrompt?: string, + isDeepCrawlEnabled?: boolean, + expertName?: string, ) => { - return `You are HAI, a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices. + return ` ${expertPrompt || "You are HAI, a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices"}. ==== @@ -47,6 +60,8 @@ Always adhere to this format for the tool use to ensure proper parsing and execu # Tools +${customToolsPrompt(supportsCodeIndex, isDeepCrawlEnabled, expertName)} + ## execute_command Description: Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. For command chaining, use the appropriate chaining syntax for the user's shell. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Commands will be executed in the current working directory: ${cwd.toPosix()} Parameters: @@ -552,6 +567,8 @@ ${ - Any other relevant feedback or information related to the tool use. 6. ALWAYS wait for user confirmation after each tool use before proceeding. Never assume the success of a tool use without explicit confirmation of the result from the user. +${customToolUseGuidelinePrompt(supportsCodeIndex)} + It is crucial to proceed step-by-step, waiting for the user's message after each tool use before moving forward with the task. This approach allows you to: 1. Confirm the success of each step before proceeding. 2. Address any issues or errors that arise immediately. @@ -768,6 +785,7 @@ CAPABILITIES ? "\n- You can use the browser_action tool to interact with websites (including html files and locally running development servers) through a Puppeteer-controlled browser when you feel it is necessary in accomplishing the user's task. This tool is particularly useful for web development tasks as it allows you to launch a browser, navigate to pages, interact with elements through clicks and keyboard input, and capture the results through screenshots and console logs. This tool may be useful at key stages of web development tasks-such as after implementing new features, making substantial changes, when troubleshooting issues, or to verify the result of your work. You can analyze the provided screenshots to ensure correct rendering or identify errors, and review console logs for runtime issues.\n - For example, if asked to add a component to a react website, you might create the necessary files, use execute_command to run the site locally, then use browser_action to launch the browser, navigate to the local server, and verify the component renders & functions correctly before closing the browser." : "" } +${customCapabilitiesPrompt(supportsCodeIndex)} - You have access to MCP servers that may provide additional tools and resources. Each server may provide different capabilities that you can use to accomplish tasks more effectively. ==== @@ -776,7 +794,7 @@ If the user asks for help or wants to give feedback inform them of the following - To give feedback, users should report the issue using the /reportbug slash command in the chat. When the user directly asks about HAI (eg 'can HAI do...', 'does HAI have...') or asks in second person (eg 'are you able...', 'can you do...'), first use the web_fetch tool to gather information to answer the question from HAI docs at https://docs.cline.bot. - - The available sub-pages are \`getting-started\` (Intro for new coders, installing HAI and dev essentials), \`model-selection\` (Model Selection Guide, Custom Model Configs, Bedrock, Vertex, Codestral, LM Studio, Ollama), \`features\` (Auto approve, Checkpoints, HAI rules, Drag & Drop, Plan & Act, Workflows, etc), \`task-management\` (Task and Context Management in HAI), \`prompt-engineering\` (Improving your prompting skills, Prompt Engineering Guide), \`cline-tools\` (HAI Tools Reference Guide, New Task Tool, Remote Browser Support, Slash Commands), \`mcp\` (MCP Overview, Adding/Configuring Servers, Transport Mechanisms, MCP Dev Protocol), \`enterprise\` (Cloud provider integration, Security concerns, Custom instructions), \`more-info\` (Telemetry and other reference content) + - The available sub-pages are \`getting-started\` (Intro for new coders, installing HAI and dev essentials), \`model-selection\` (Model Selection Guide, Custom Model Configs, Bedrock, Vertex, Codestral, LM Studio, Ollama), \`features\` (Auto approve, Checkpoints, HAI rules, Drag & Drop, Plan & Act, Workflows, etc), \`task-management\` (Task and Context Management in HAI), \`prompt-engineering\` (Improving your prompting skills, Prompt Engineering Guide), \`hai-tools\` (HAI Tools Reference Guide, New Task Tool, Remote Browser Support, Slash Commands), \`mcp\` (MCP Overview, Adding/Configuring Servers, Transport Mechanisms, MCP Dev Protocol), \`enterprise\` (Cloud provider integration, Security concerns, Custom instructions), \`more-info\` (Telemetry and other reference content) - Example: https://docs.cline.bot/features/auto-approve ==== @@ -816,6 +834,7 @@ RULES ? " Then if you want to test your work, you might use browser_action to launch the site, wait for the user's response confirming the site was launched along with a screenshot, then perhaps e.g., click a button to test functionality if needed, wait for the user's response confirming the button was clicked along with a screenshot of the new state, before finally closing the browser." : "" } +${customRulesPrompt(supportsCodeIndex, isDeepCrawlEnabled)} - MCP operations should be used one at a time, similar to other tool usage. Wait for confirmation of success before proceeding with additional operations. ==== @@ -837,5 +856,6 @@ You accomplish a given task iteratively, breaking it down into clear steps and w 2. Work through these goals sequentially, utilizing available tools one at a time as necessary. Each goal should correspond to a distinct step in your problem-solving process. You will be informed on the work completed and what's remaining as you go. 3. Remember, you have extensive capabilities with access to a wide range of tools that can be used in powerful and clever ways as necessary to accomplish each goal. Before calling a tool, do some analysis within tags. First, analyze the file structure provided in environment_details to gain context and insights for proceeding effectively. Then, think about which of the provided tools is the most relevant tool to accomplish the user's task. Next, go through each of the required parameters of the relevant tool and determine if the user has directly provided or given enough information to infer a value. When deciding if the parameter can be inferred, carefully consider all the context to see if it supports a specific value. If all of the required parameters are present or can be reasonably inferred, close the thinking tag and proceed with the tool use. BUT, if one of the values for a required parameter is missing, DO NOT invoke the tool (not even with fillers for the missing params) and instead, ask the user to provide the missing parameters using the ask_followup_question tool. DO NOT ask for more information on optional parameters if it is not provided. 4. Once you've completed the user's task, you must use the attempt_completion tool to present the result of the task to the user. You may also provide a CLI command to showcase the result of your task; this can be particularly useful for web development tasks, where you can run e.g. \`open index.html\` to show the website you've built. -5. The user may provide feedback, which you can use to make improvements and try again. But DO NOT continue in pointless back and forth conversations, i.e. don't end your responses with questions or offers for further assistance.` +5. The user may provide feedback, which you can use to make improvements and try again. But DO NOT continue in pointless back and forth conversations, i.e. don't end your responses with questions or offers for further assistance. +${customObjectivePrompt(supportsCodeIndex)}` } diff --git a/src/core/storage/CacheService.ts b/src/core/storage/CacheService.ts index c5538c43..a2ccebb3 100644 --- a/src/core/storage/CacheService.ts +++ b/src/core/storage/CacheService.ts @@ -852,25 +852,25 @@ export class CacheService { // Extract embedding configuration fields const { - embeddingProvider, - embeddingModelId, - embeddingApiKey, - embeddingOpenRouterApiKey, - embeddingAwsAccessKey, - embeddingAwsSecretKey, - embeddingAwsSessionToken, - embeddingAwsRegion, - embeddingOpenAiBaseUrl, - embeddingOpenAiApiKey, - embeddingOpenAiModelId, - embeddingOpenAiNativeApiKey, - embeddingAzureOpenAIApiKey, - embeddingAzureOpenAIApiInstanceName, - embeddingAzureOpenAIApiEmbeddingsDeploymentName, - embeddingAzureOpenAIApiVersion, - embeddingOllamaBaseUrl, - embeddingOllamaModelId, - embeddingMaxRetries, + provider: embeddingProvider, + modelId: embeddingModelId, + apiKey: embeddingApiKey, + openRouterApiKey: embeddingOpenRouterApiKey, + awsAccessKey: embeddingAwsAccessKey, + awsSecretKey: embeddingAwsSecretKey, + awsSessionToken: embeddingAwsSessionToken, + awsRegion: embeddingAwsRegion, + openAiBaseUrl: embeddingOpenAiBaseUrl, + openAiApiKey: embeddingOpenAiApiKey, + openAiModelId: embeddingOpenAiModelId, + openAiNativeApiKey: embeddingOpenAiNativeApiKey, + azureOpenAIApiKey: embeddingAzureOpenAIApiKey, + azureOpenAIApiInstanceName: embeddingAzureOpenAIApiInstanceName, + azureOpenAIApiEmbeddingsDeploymentName: embeddingAzureOpenAIApiEmbeddingsDeploymentName, + azureOpenAIApiVersion: embeddingAzureOpenAIApiVersion, + ollamaBaseUrl: embeddingOllamaBaseUrl, + ollamaModelId: embeddingOllamaModelId, + maxRetries: embeddingMaxRetries, } = state.embeddingConfiguration || {} // TAG:HAI - Extract HAI-specific fields diff --git a/webview-ui/src/components/experts/ExpertsView.tsx b/webview-ui/src/components/experts/ExpertsView.tsx index 1eb627c8..5c601264 100644 --- a/webview-ui/src/components/experts/ExpertsView.tsx +++ b/webview-ui/src/components/experts/ExpertsView.tsx @@ -64,7 +64,6 @@ const ExpertsView: React.FC = ({ onDone }) => { setDefaultExperts(message.grpc_response.message.experts) } if (message.grpc_response?.message?.key === "customExpertsLoaded") { - console.log("Custom experts loaded:", message.grpc_response.message.experts) setCustomExperts(message.grpc_response.message.experts) } } @@ -734,6 +733,33 @@ const ExpertsView: React.FC = ({ onDone }) => {

Enabling deep crawl can explore websites beyond a single page by following internal links.

+
+ + + Please note: Experts feature won't work when 'Auto Compact' is enabled or when using a + local LLM model. + +
{deepCrawl && ( <>