Skip to content

Commit 51a0e48

Browse files
committed
Merge remote-tracking branch 'origin/main' into mark/remove-error-fix-strategy
2 parents f18645d + 558d0ff commit 51a0e48

File tree

6 files changed

+41
-69
lines changed

6 files changed

+41
-69
lines changed

src/services/ghost/GhostProvider.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ export class GhostProvider {
253253
this.isRequestCancelled = false
254254

255255
const context = await this.ghostContext.generate(initialContext)
256-
const systemPrompt = this.strategy.getSystemPrompt(context)
257-
const userPrompt = this.strategy.getSuggestionPrompt(context)
256+
const { systemPrompt, userPrompt } = this.strategy.getPrompts(context)
258257
if (this.isRequestCancelled) {
259258
return
260259
}

src/services/ghost/GhostStrategy.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,16 @@ export class GhostStrategy {
1414
}
1515

1616
/**
17-
* Get the system prompt based on context using the new strategy system
18-
* Overloaded to support both new context-based and legacy string-only calls
19-
*/
20-
getSystemPrompt(context: GhostSuggestionContext): string {
21-
const { systemPrompt, strategy } = this.strategyManager.buildPrompt(context)
22-
if (this.debug) {
23-
console.log(`[GhostStrategy] Using strategy: ${strategy.name}`)
24-
}
25-
return systemPrompt
26-
}
27-
28-
/**
29-
* Get the user prompt based on context using the new strategy system
17+
* Get both system and user prompts based on context
3018
* @param context The suggestion context
31-
* @returns The user prompt
19+
* @returns Object containing systemPrompt and userPrompt
3220
*/
33-
getSuggestionPrompt(context: GhostSuggestionContext): string {
34-
const { userPrompt, strategy } = this.strategyManager.buildPrompt(context)
35-
21+
getPrompts(context: GhostSuggestionContext): { systemPrompt: string; userPrompt: string } {
22+
const { systemPrompt, userPrompt, strategy } = this.strategyManager.buildPrompt(context)
3623
if (this.debug) {
37-
console.log(`[GhostStrategy] Generated prompt with strategy: ${strategy.name}`)
24+
console.log(`[GhostStrategy] Using strategy: ${strategy.name}`)
3825
}
39-
40-
return userPrompt
26+
return { systemPrompt, userPrompt }
4127
}
4228

4329
/**

src/services/ghost/__tests__/GhostModelPerformance.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ describe("GhostModelPerformance", () => {
2525
document: document,
2626
}
2727

28-
const systemPrompt = strategy.getSystemPrompt(context)
29-
const suggestionPrompt = strategy.getSuggestionPrompt(context)
28+
const { systemPrompt, userPrompt } = strategy.getPrompts(context)
3029

31-
return { systemPrompt, suggestionPrompt }
30+
return { systemPrompt, suggestionPrompt: userPrompt }
3231
}
3332

3433
const performTest = async (apiHandler: ApiHandler, prompt: { systemPrompt: string; suggestionPrompt: string }) => {

src/services/ghost/__tests__/GhostRecentOperations.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ describe("GhostRecentOperations", () => {
116116
expect(enrichedContext.recentOperations?.length).toBeGreaterThan(0)
117117

118118
// Generate prompt
119-
const prompt = strategy.getSuggestionPrompt(enrichedContext)
119+
const { userPrompt } = strategy.getPrompts(enrichedContext)
120120

121121
// Verify that the prompt includes the recent operations section
122122
// The new strategy system uses "## Recent Typing" format
123-
expect(prompt).toContain("## Recent Typing")
123+
expect(userPrompt).toContain("## Recent Typing")
124124
})
125125

126126
it("should not include recent operations in the prompt when not available", async () => {
@@ -133,11 +133,11 @@ describe("GhostRecentOperations", () => {
133133
const enrichedContext = await context.generate(suggestionContext)
134134

135135
// Generate prompt
136-
const prompt = strategy.getSuggestionPrompt(enrichedContext)
136+
const { userPrompt } = strategy.getPrompts(enrichedContext)
137137

138138
// Verify that the prompt does not include recent operations section
139139
// The current document content will still be in the prompt, so we should only check
140140
// that the "**Recent Changes (Diff):**" section is not present
141-
expect(prompt.includes("**Recent Changes (Diff):**")).toBe(false)
141+
expect(userPrompt.includes("**Recent Changes (Diff):**")).toBe(false)
142142
})
143143
})

src/services/ghost/__tests__/GhostStrategy.spec.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,25 +232,39 @@ describe("GhostStrategy", () => {
232232
})
233233

234234
describe("prompt generation", () => {
235-
it("should generate system prompt", () => {
235+
it("should generate both prompts efficiently with getPrompts", () => {
236+
const context: GhostSuggestionContext = {
237+
document: mockDocument,
238+
userInput: "Add a comment",
239+
range: new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)),
240+
}
241+
242+
const { systemPrompt, userPrompt } = strategy.getPrompts(context)
243+
expect(systemPrompt).toContain("CRITICAL OUTPUT FORMAT")
244+
expect(systemPrompt).toContain("XML-formatted changes")
245+
expect(userPrompt).toContain("Add a comment")
246+
expect(userPrompt).toContain("<<<AUTOCOMPLETE_HERE>>>")
247+
})
248+
249+
it("should generate system prompt via getPrompts", () => {
236250
const context: GhostSuggestionContext = {
237251
document: mockDocument,
238252
}
239-
const systemPrompt = strategy.getSystemPrompt(context)
253+
const { systemPrompt } = strategy.getPrompts(context)
240254
expect(systemPrompt).toContain("CRITICAL OUTPUT FORMAT")
241255
expect(systemPrompt).toContain("XML-formatted changes")
242256
})
243257

244-
it("should generate suggestion prompt with context", () => {
258+
it("should generate suggestion prompt with context via getPrompts", () => {
245259
const context: GhostSuggestionContext = {
246260
document: mockDocument,
247261
userInput: "Add a comment",
248262
range: new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)),
249263
}
250264

251-
const suggestionPrompt = strategy.getSuggestionPrompt(context)
252-
expect(suggestionPrompt).toContain("Add a comment")
253-
expect(suggestionPrompt).toContain("<<<AUTOCOMPLETE_HERE>>>")
265+
const { userPrompt } = strategy.getPrompts(context)
266+
expect(userPrompt).toContain("Add a comment")
267+
expect(userPrompt).toContain("<<<AUTOCOMPLETE_HERE>>>")
254268
})
255269
})
256270
})

src/services/ghost/__tests__/GhostStrategy.test.ts

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ describe("GhostStrategy", () => {
1313
strategy = new GhostStrategy()
1414
})
1515

16-
describe("getSystemPrompt", () => {
17-
it("should use PromptStrategyManager to generate system prompt", () => {
16+
describe("getPrompts", () => {
17+
it("should use PromptStrategyManager to generate prompts", () => {
1818
const mockDocument = {
1919
languageId: "typescript",
2020
getText: () => "const x = 1;",
@@ -27,10 +27,10 @@ describe("GhostStrategy", () => {
2727
userInput: "Complete this function",
2828
}
2929

30-
const prompt = strategy.getSystemPrompt(context)
30+
const { systemPrompt } = strategy.getPrompts(context)
3131

3232
// Should contain base instructions from strategy system
33-
expect(prompt).toContain("CRITICAL OUTPUT FORMAT")
33+
expect(systemPrompt).toContain("CRITICAL OUTPUT FORMAT")
3434
})
3535

3636
it("should select UserRequestStrategy when user input is provided", () => {
@@ -47,37 +47,14 @@ describe("GhostStrategy", () => {
4747
userInput: "Add a function to calculate sum",
4848
}
4949

50-
const systemPrompt = strategy.getSystemPrompt(context)
51-
const userPrompt = strategy.getSuggestionPrompt(context)
50+
const { systemPrompt, userPrompt } = strategy.getPrompts(context)
5251

5352
// UserRequestStrategy should be selected
5453
expect(systemPrompt).toContain("Execute User's Explicit Request")
5554
expect(userPrompt).toContain("Add a function to calculate sum")
5655
})
5756
})
5857

59-
describe("getSuggestionPrompt", () => {
60-
it("should delegate to PromptStrategyManager", () => {
61-
const mockDocument = {
62-
languageId: "typescript",
63-
getText: () => "const x = 1;",
64-
lineAt: (line: number) => ({ text: "const x = 1;" }),
65-
uri: { toString: () => "file:///test.ts" },
66-
offsetAt: (position: vscode.Position) => 13,
67-
} as vscode.TextDocument
68-
69-
const context: GhostSuggestionContext = {
70-
document: mockDocument,
71-
}
72-
73-
const prompt = strategy.getSuggestionPrompt(context)
74-
75-
// Should return a structured prompt
76-
expect(prompt).toBeDefined()
77-
expect(prompt.length).toBeGreaterThan(0)
78-
})
79-
})
80-
8158
describe("Integration", () => {
8259
it("should work with both system and user prompts", () => {
8360
const mockDocument = {
@@ -93,8 +70,7 @@ describe("GhostStrategy", () => {
9370
userInput: "Complete this function",
9471
}
9572

96-
const systemPrompt = strategy.getSystemPrompt(context)
97-
const userPrompt = strategy.getSuggestionPrompt(context)
73+
const { systemPrompt, userPrompt } = strategy.getPrompts(context)
9874

9975
// System prompt should contain format instructions
10076
expect(systemPrompt).toContain("CRITICAL OUTPUT FORMAT")
@@ -175,8 +151,7 @@ describe("GhostStrategy", () => {
175151
document: mockDocument,
176152
}
177153

178-
const systemPrompt = strategy.getSystemPrompt(context)
179-
const userPrompt = strategy.getSuggestionPrompt(context)
154+
const { systemPrompt, userPrompt } = strategy.getPrompts(context)
180155

181156
expect(systemPrompt).toBeDefined()
182157
expect(systemPrompt.length).toBeGreaterThan(0)
@@ -234,8 +209,7 @@ describe("GhostStrategy", () => {
234209
]
235210

236211
contexts.forEach((context) => {
237-
const systemPrompt = strategy.getSystemPrompt(context as GhostSuggestionContext)
238-
const userPrompt = strategy.getSuggestionPrompt(context as GhostSuggestionContext)
212+
const { systemPrompt, userPrompt } = strategy.getPrompts(context as GhostSuggestionContext)
239213

240214
expect(systemPrompt).toBeDefined()
241215
expect(systemPrompt.length).toBeGreaterThan(0)

0 commit comments

Comments
 (0)