Skip to content

Commit 55a5a97

Browse files
committed
refactor: consolidate code action and enhance prompts into unified support prompts system
- Rename codeActionPrompt to supportPrompt for better clarity - Move enhance prompt functionality into support prompts system - Add ENHANCE tab alongside other support prompt types - Update UI to show enhancement configuration in ENHANCE tab - Update tests to reflect new unified structure This change simplifies the prompt system by treating enhancement as another type of support prompt rather than a separate system.
1 parent 22907a0 commit 55a5a97

File tree

5 files changed

+140
-213
lines changed

5 files changed

+140
-213
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { enhancePrompt } from "../../utils/enhance-prompt"
4040
import { getCommitInfo, searchCommits, getWorkingState } from "../../utils/git"
4141
import { ConfigManager } from "../config/ConfigManager"
4242
import { CustomModesManager } from "../config/CustomModesManager"
43-
import { enhance, codeActionPrompt } from "../../shared/support-prompt"
43+
import { supportPrompt } from "../../shared/support-prompt"
4444

4545
import { ACTION_NAMES } from "../CodeActionProvider"
4646

@@ -205,7 +205,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
205205

206206
const { customPrompts } = await visibleProvider.getState()
207207

208-
const prompt = codeActionPrompt.create(promptType, params, customPrompts)
208+
const prompt = supportPrompt.create(promptType, params, customPrompts)
209209

210210
await visibleProvider.initClineWithTask(prompt)
211211
}
@@ -996,16 +996,10 @@ export class ClineProvider implements vscode.WebviewViewProvider {
996996
}
997997
}
998998

999-
const getEnhancePrompt = (value: string | PromptComponent | undefined): string => {
1000-
if (typeof value === "string") {
1001-
return value
1002-
}
1003-
return enhance.prompt // Use the constant from modes.ts which we know is a string
1004-
}
1005999
const enhancedPrompt = await enhancePrompt(
10061000
configToUse,
10071001
message.text,
1008-
getEnhancePrompt(customPrompts?.enhance),
1002+
supportPrompt.get(customPrompts, "ENHANCE"),
10091003
)
10101004
await this.postMessageToWebview({
10111005
type: "enhancedPrompt",

src/shared/__tests__/support-prompts.test.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { codeActionPrompt, type CodeActionType } from "../support-prompt"
1+
import { supportPrompt } from "../support-prompt"
22

33
describe("Code Action Prompts", () => {
44
const testFilePath = "test/file.ts"
55
const testCode = "function test() { return true; }"
66

77
describe("EXPLAIN action", () => {
88
it("should format explain prompt correctly", () => {
9-
const prompt = codeActionPrompt.create("EXPLAIN", {
9+
const prompt = supportPrompt.create("EXPLAIN", {
1010
filePath: testFilePath,
1111
selectedText: testCode,
1212
})
@@ -21,7 +21,7 @@ describe("Code Action Prompts", () => {
2121

2222
describe("FIX action", () => {
2323
it("should format fix prompt without diagnostics", () => {
24-
const prompt = codeActionPrompt.create("FIX", {
24+
const prompt = supportPrompt.create("FIX", {
2525
filePath: testFilePath,
2626
selectedText: testCode,
2727
})
@@ -45,7 +45,7 @@ describe("Code Action Prompts", () => {
4545
},
4646
]
4747

48-
const prompt = codeActionPrompt.create("FIX", {
48+
const prompt = supportPrompt.create("FIX", {
4949
filePath: testFilePath,
5050
selectedText: testCode,
5151
diagnostics,
@@ -60,7 +60,7 @@ describe("Code Action Prompts", () => {
6060

6161
describe("IMPROVE action", () => {
6262
it("should format improve prompt correctly", () => {
63-
const prompt = codeActionPrompt.create("IMPROVE", {
63+
const prompt = supportPrompt.create("IMPROVE", {
6464
filePath: testFilePath,
6565
selectedText: testCode,
6666
})
@@ -74,27 +74,43 @@ describe("Code Action Prompts", () => {
7474
})
7575
})
7676

77+
describe("ENHANCE action", () => {
78+
it("should format enhance prompt correctly", () => {
79+
const prompt = supportPrompt.create("ENHANCE", {
80+
filePath: testFilePath,
81+
selectedText: testCode,
82+
})
83+
84+
expect(prompt).toBe(
85+
"Generate an enhanced version of this prompt (reply with only the enhanced prompt - no conversation, explanations, lead-in, bullet points, placeholders, or surrounding quotes):",
86+
)
87+
// Verify it ignores parameters since ENHANCE template doesn't use any
88+
expect(prompt).not.toContain(testFilePath)
89+
expect(prompt).not.toContain(testCode)
90+
})
91+
})
92+
7793
describe("get template", () => {
7894
it("should return default template when no custom prompts provided", () => {
79-
const template = codeActionPrompt.get(undefined, "EXPLAIN")
80-
expect(template).toBe(codeActionPrompt.default.EXPLAIN)
95+
const template = supportPrompt.get(undefined, "EXPLAIN")
96+
expect(template).toBe(supportPrompt.default.EXPLAIN)
8197
})
8298

8399
it("should return custom template when provided", () => {
84100
const customTemplate = "Custom template for explaining code"
85101
const customPrompts = {
86102
EXPLAIN: customTemplate,
87103
}
88-
const template = codeActionPrompt.get(customPrompts, "EXPLAIN")
104+
const template = supportPrompt.get(customPrompts, "EXPLAIN")
89105
expect(template).toBe(customTemplate)
90106
})
91107

92108
it("should return default template when custom prompts does not include type", () => {
93109
const customPrompts = {
94110
SOMETHING_ELSE: "Other template",
95111
}
96-
const template = codeActionPrompt.get(customPrompts, "EXPLAIN")
97-
expect(template).toBe(codeActionPrompt.default.EXPLAIN)
112+
const template = supportPrompt.get(customPrompts, "EXPLAIN")
113+
expect(template).toBe(supportPrompt.default.EXPLAIN)
98114
})
99115
})
100116

@@ -105,7 +121,7 @@ describe("Code Action Prompts", () => {
105121
EXPLAIN: customTemplate,
106122
}
107123

108-
const prompt = codeActionPrompt.create(
124+
const prompt = supportPrompt.create(
109125
"EXPLAIN",
110126
{
111127
filePath: testFilePath,
@@ -123,7 +139,7 @@ describe("Code Action Prompts", () => {
123139
EXPLAIN: "Other template",
124140
}
125141

126-
const prompt = codeActionPrompt.create(
142+
const prompt = supportPrompt.create(
127143
"EXPLAIN",
128144
{
129145
filePath: testFilePath,

src/shared/support-prompt.ts

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,4 @@
1-
// Separate enhance prompt type and definition
2-
export type EnhanceConfig = {
3-
prompt: string
4-
}
5-
6-
export const enhance: EnhanceConfig = {
7-
prompt: "Generate an enhanced version of this prompt (reply with only the enhanced prompt - no conversation, explanations, lead-in, bullet points, placeholders, or surrounding quotes):",
8-
} as const
9-
10-
// Completely separate enhance prompt handling
11-
export const enhancePrompt = {
12-
default: enhance.prompt,
13-
get: (customPrompts: Record<string, any> | undefined): string => {
14-
return customPrompts?.enhance ?? enhance.prompt
15-
},
16-
} as const
17-
18-
// Code action prompts
1+
// Support prompts
192
type PromptParams = Record<string, string | any[]>
203

214
const generateDiagnosticText = (diagnostics?: any[]) => {
@@ -41,8 +24,7 @@ export const createPrompt = (template: string, params: PromptParams): string =>
4124
return result
4225
}
4326

44-
const EXPLAIN_TEMPLATE = `
45-
Explain the following code from file path @/\${filePath}:
27+
const EXPLAIN_TEMPLATE = `Explain the following code from file path @/\${filePath}:
4628
\${userInput}
4729
4830
\`\`\`
@@ -55,8 +37,7 @@ Please provide a clear and concise explanation of what this code does, including
5537
3. Important patterns or techniques used
5638
`
5739

58-
const FIX_TEMPLATE = `
59-
Fix any issues in the following code from file path @/\${filePath}
40+
const FIX_TEMPLATE = `Fix any issues in the following code from file path @/\${filePath}
6041
\${diagnosticText}
6142
\${userInput}
6243
@@ -71,8 +52,7 @@ Please:
7152
4. Explain what was fixed and why
7253
`
7354

74-
const IMPROVE_TEMPLATE = `
75-
Improve the following code from file path @/\${filePath}:
55+
const IMPROVE_TEMPLATE = `Improve the following code from file path @/\${filePath}:
7656
\${userInput}
7757
7858
\`\`\`
@@ -88,31 +68,36 @@ Please suggest improvements for:
8868
Provide the improved code along with explanations for each enhancement.
8969
`
9070

71+
const ENHANCE_TEMPLATE =
72+
"Generate an enhanced version of this prompt (reply with only the enhanced prompt - no conversation, explanations, lead-in, bullet points, placeholders, or surrounding quotes):"
73+
9174
// Get template based on prompt type
9275
const defaultTemplates = {
9376
EXPLAIN: EXPLAIN_TEMPLATE,
9477
FIX: FIX_TEMPLATE,
9578
IMPROVE: IMPROVE_TEMPLATE,
79+
ENHANCE: ENHANCE_TEMPLATE,
9680
} as const
9781

98-
type CodeActionType = keyof typeof defaultTemplates
82+
type SupportPromptType = keyof typeof defaultTemplates
9983

100-
export const codeActionPrompt = {
84+
export const supportPrompt = {
10185
default: defaultTemplates,
102-
get: (customPrompts: Record<string, any> | undefined, type: CodeActionType): string => {
86+
get: (customPrompts: Record<string, any> | undefined, type: SupportPromptType): string => {
10387
return customPrompts?.[type] ?? defaultTemplates[type]
10488
},
105-
create: (type: CodeActionType, params: PromptParams, customPrompts?: Record<string, any>): string => {
106-
const template = codeActionPrompt.get(customPrompts, type)
89+
create: (type: SupportPromptType, params: PromptParams, customPrompts?: Record<string, any>): string => {
90+
const template = supportPrompt.get(customPrompts, type)
10791
return createPrompt(template, params)
10892
},
10993
} as const
11094

111-
export type { CodeActionType }
95+
export type { SupportPromptType }
11296

113-
// User-friendly labels for code action types
114-
export const codeActionLabels: Record<CodeActionType, string> = {
97+
// User-friendly labels for support prompt types
98+
export const supportPromptLabels: Record<SupportPromptType, string> = {
11599
FIX: "Fix Issues",
116100
EXPLAIN: "Explain Code",
117101
IMPROVE: "Improve Code",
102+
ENHANCE: "Enhance Prompt",
118103
} as const

0 commit comments

Comments
 (0)