Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/many-peaches-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hai-build-code-generator": minor
---

add system prompt optimization
12 changes: 10 additions & 2 deletions src/core/Cline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ import { isCommandIncludedInSecretScanning, isSecretFile } from "../integrations
import { ClineIgnoreController, LOCK_TEXT_SYMBOL } from "./ignore/ClineIgnoreController"
import { parseMentions } from "./mentions"
import { formatResponse } from "./prompts/responses"
import { addUserInstructions, SYSTEM_PROMPT } from "./prompts/system"
import { addUserInstructions } from "./prompts/system"
import { getNextTruncationRange, getTruncatedMessages } from "./sliding-window"
import { ClineProvider, GlobalFileNames } from "./webview/ClineProvider"
import { haiSystemPrompt } from "./prompts/system.hai"

const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) ?? path.join(os.homedir(), "Desktop") // may or may not exist but fs checking existence would immediately ask for permission which would be bad UX, need to come up with a better solution

Expand Down Expand Up @@ -1281,7 +1282,14 @@ export class Cline {
const supportsComputerUse = modelSupportsComputerUse && !disableBrowserTool // only enable computer use if the model supports it and the user hasn't disabled it

const supportsCodeIndex = this.buildContextOptions?.useIndex ?? false
let systemPrompt = await SYSTEM_PROMPT(cwd, supportsComputerUse, supportsCodeIndex, mcpHub, this.browserSettings)
let systemPrompt = await haiSystemPrompt(
cwd,
supportsComputerUse,
supportsCodeIndex,
mcpHub,
this.browserSettings,
this.buildContextOptions?.systemPromptVersion,
)
let settingsCustomInstructions = this.customInstructions?.trim()

const clineRulesFilePath = path.resolve(cwd, GlobalFileNames.clineRules)
Expand Down
26 changes: 26 additions & 0 deletions src/core/prompts/system.hai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { McpHub } from "../../services/mcp/McpHub"
import type { BrowserSettings } from "../../shared/BrowserSettings"
import { SYSTEM_PROMPT as haiSystemPromptV1 } from "./system.hai.v1"
import { SYSTEM_PROMPT as haiSystemPromptV2 } from "./system.hai.v2"
import { SYSTEM_PROMPT as haiSystemPromptV3 } from "./system.hai.v3"
import { SYSTEM_PROMPT as haiDefaultSystemPrompt } from "./system"

export const haiSystemPrompt = (
cwd: string,
supportsComputerUse: boolean,
supportsCodeIndex: boolean,
mcpHub: McpHub,
browserSettings: BrowserSettings,
version?: string,
) => {
switch (version) {
case "v1":
return haiSystemPromptV1(cwd, supportsComputerUse, supportsCodeIndex, mcpHub, browserSettings)
case "v2":
return haiSystemPromptV2(cwd, supportsComputerUse, supportsCodeIndex, mcpHub, browserSettings)
case "v3":
return haiSystemPromptV3(cwd, supportsComputerUse, supportsCodeIndex, mcpHub, browserSettings)
default:
return haiDefaultSystemPrompt(cwd, supportsComputerUse, supportsCodeIndex, mcpHub, browserSettings)
}
}
Loading