Skip to content

Commit 37583e8

Browse files
authored
Merge pull request #3003 from Kilo-Org/mark/remove-ghost-strategy
Remove ghost strategy
2 parents 800860c + 6ab6981 commit 37583e8

File tree

8 files changed

+95
-450
lines changed

8 files changed

+95
-450
lines changed

src/services/ghost/GhostProvider.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import crypto from "crypto"
22
import * as vscode from "vscode"
33
import { t } from "../../i18n"
44
import { GhostDocumentStore } from "./GhostDocumentStore"
5-
import { GhostStrategy } from "./GhostStrategy"
5+
import { GhostStreamingParser } from "./GhostStreamingParser"
6+
import { PromptStrategyManager } from "./PromptStrategyManager"
67
import { GhostModel } from "./GhostModel"
78
import { GhostWorkspaceEdit } from "./GhostWorkspaceEdit"
89
import { GhostDecorations } from "./GhostDecorations"
@@ -27,7 +28,8 @@ export class GhostProvider {
2728
private decorations: GhostDecorations
2829
private documentStore: GhostDocumentStore
2930
private model: GhostModel
30-
private strategy: GhostStrategy
31+
private streamingParser: GhostStreamingParser
32+
private strategyManager: PromptStrategyManager
3133
private workspaceEdit: GhostWorkspaceEdit
3234
private suggestions: GhostSuggestionsState = new GhostSuggestionsState()
3335
private cline: ClineProvider
@@ -63,7 +65,8 @@ export class GhostProvider {
6365
// Register Internal Components
6466
this.decorations = new GhostDecorations()
6567
this.documentStore = new GhostDocumentStore()
66-
this.strategy = new GhostStrategy({ debug: true })
68+
this.streamingParser = new GhostStreamingParser()
69+
this.strategyManager = new PromptStrategyManager({ debug: true })
6770
this.workspaceEdit = new GhostWorkspaceEdit()
6871
this.providerSettingsManager = new ProviderSettingsManager(context)
6972
this.model = new GhostModel()
@@ -289,7 +292,7 @@ export class GhostProvider {
289292
this.isRequestCancelled = false
290293

291294
const context = await this.ghostContext.generate(initialContext)
292-
const { systemPrompt, userPrompt } = this.strategy.getPrompts(context)
295+
const { systemPrompt, userPrompt } = this.strategyManager.buildPrompt(context)
293296
if (this.isRequestCancelled) {
294297
return
295298
}
@@ -303,7 +306,7 @@ export class GhostProvider {
303306
console.log("userprompt", userPrompt)
304307

305308
// Initialize the streaming parser
306-
this.strategy.initializeStreamingParser(context)
309+
this.streamingParser.initialize(context)
307310

308311
let hasShownFirstSuggestion = false
309312
let cost = 0
@@ -323,7 +326,7 @@ export class GhostProvider {
323326
response += chunk.text
324327

325328
// Process the text chunk through our streaming parser
326-
const parseResult = this.strategy.processStreamingChunk(chunk.text)
329+
const parseResult = this.streamingParser.processChunk(chunk.text)
327330

328331
if (parseResult.hasNewSuggestions) {
329332
// Update our suggestions with the new parsed results
@@ -383,7 +386,7 @@ export class GhostProvider {
383386
}
384387

385388
// Finish the streaming parser to apply sanitization if needed
386-
const finalParseResult = this.strategy.finishStreamingParser()
389+
const finalParseResult = this.streamingParser.finishStream()
387390
if (finalParseResult.hasNewSuggestions && !hasShownFirstSuggestion) {
388391
// Handle case where sanitization produced suggestions
389392
this.suggestions = finalParseResult.suggestions
@@ -685,7 +688,7 @@ export class GhostProvider {
685688
this.clearAutoTriggerTimer()
686689
}
687690
// Reset streaming parser when cancelling
688-
this.strategy.resetStreamingParser()
691+
this.streamingParser.reset()
689692
}
690693

691694
/**

src/services/ghost/GhostStrategy.ts

Lines changed: 0 additions & 63 deletions
This file was deleted.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from "vscode"
22
import { describe, it, expect } from "vitest"
3-
import { GhostStrategy } from "../GhostStrategy"
3+
import { PromptStrategyManager } from "../PromptStrategyManager"
44
import { MockWorkspace } from "./MockWorkspace"
55
import { ApiHandler, buildApiHandler } from "../../../api"
66
import { GhostModel } from "../GhostModel"
@@ -14,7 +14,7 @@ const KEYS = {
1414

1515
describe("GhostModelPerformance", () => {
1616
const generatePrompt = (userInput: string) => {
17-
const strategy = new GhostStrategy()
17+
const strategyManager = new PromptStrategyManager()
1818
const mockWorkspace = new MockWorkspace()
1919

2020
const testUri = vscode.Uri.parse("file:///example.ts")
@@ -25,7 +25,7 @@ describe("GhostModelPerformance", () => {
2525
document: document,
2626
}
2727

28-
const { systemPrompt, userPrompt } = strategy.getPrompts(context)
28+
const { systemPrompt, userPrompt } = strategyManager.buildPrompt(context)
2929

3030
return { systemPrompt, suggestionPrompt: userPrompt }
3131
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as fs from "node:fs"
33
import * as path from "node:path"
44
import { MockWorkspace } from "./MockWorkspace"
55
import * as vscode from "vscode"
6-
import { GhostStrategy } from "../GhostStrategy"
6+
import { GhostStreamingParser } from "../GhostStreamingParser"
77
import { GhostWorkspaceEdit } from "../GhostWorkspaceEdit"
88
import { GhostSuggestionContext } from "../types"
99

@@ -68,12 +68,12 @@ vi.mock("vscode", () => ({
6868

6969
describe("GhostProvider", () => {
7070
let mockWorkspace: MockWorkspace
71-
let strategy: GhostStrategy
71+
let streamingParser: GhostStreamingParser
7272
let workspaceEdit: GhostWorkspaceEdit
7373

7474
beforeEach(() => {
7575
vi.clearAllMocks()
76-
strategy = new GhostStrategy()
76+
streamingParser = new GhostStreamingParser()
7777
mockWorkspace = new MockWorkspace()
7878
workspaceEdit = new GhostWorkspaceEdit()
7979

@@ -128,10 +128,10 @@ describe("GhostProvider", () => {
128128

129129
async function parseAndApplySuggestions(response: string, context: GhostSuggestionContext) {
130130
// Initialize streaming parser
131-
strategy.initializeStreamingParser(context)
131+
streamingParser.initialize(context)
132132

133133
// Process the response as a single chunk (simulating complete response)
134-
const result = strategy.processStreamingChunk(response)
134+
const result = streamingParser.processChunk(response)
135135

136136
// Apply the suggestions
137137
await workspaceEdit.applySuggestions(result.suggestions)
@@ -231,8 +231,8 @@ describe("GhostProvider", () => {
231231
const { context } = await setupTestDocument("empty.js", initialContent)
232232

233233
// Test empty response
234-
strategy.initializeStreamingParser(context)
235-
const result = strategy.processStreamingChunk("")
234+
streamingParser.initialize(context)
235+
const result = streamingParser.processChunk("")
236236
expect(result.suggestions.hasSuggestions()).toBe(false)
237237
})
238238

@@ -242,8 +242,8 @@ describe("GhostProvider", () => {
242242

243243
// Test invalid diff format
244244
const invalidDiff = "This is not a valid diff format"
245-
strategy.initializeStreamingParser(context)
246-
const result = strategy.processStreamingChunk(invalidDiff)
245+
streamingParser.initialize(context)
246+
const result = streamingParser.processChunk(invalidDiff)
247247
expect(result.suggestions.hasSuggestions()).toBe(false)
248248
})
249249

@@ -261,8 +261,8 @@ describe("GhostProvider", () => {
261261
const xmlResponse = `<change><search><![CDATA[console.log('test');]]></search><replace><![CDATA[// Added comment
262262
console.log('test');]]></replace></change>`
263263

264-
strategy.initializeStreamingParser(context)
265-
const result = strategy.processStreamingChunk(xmlResponse)
264+
streamingParser.initialize(context)
265+
const result = streamingParser.processChunk(xmlResponse)
266266
// Should work with the XML format
267267
expect(result.suggestions.hasSuggestions()).toBe(true)
268268
})

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach, vi, afterEach } from "vitest"
22
import * as vscode from "vscode"
33
import { GhostContext } from "../GhostContext"
44
import { GhostDocumentStore } from "../GhostDocumentStore"
5-
import { GhostStrategy } from "../GhostStrategy"
5+
import { PromptStrategyManager } from "../PromptStrategyManager"
66
import { GhostSuggestionContext } from "../types"
77
import { MockTextDocument } from "../../mocking/MockTextDocument"
88

@@ -78,13 +78,13 @@ vi.mock("diff", async (importOriginal) => {
7878
describe("GhostRecentOperations", () => {
7979
let documentStore: GhostDocumentStore
8080
let context: GhostContext
81-
let strategy: GhostStrategy
81+
let strategyManager: PromptStrategyManager
8282
let mockDocument: MockTextDocument
8383

8484
beforeEach(() => {
8585
documentStore = new GhostDocumentStore()
8686
context = new GhostContext(documentStore)
87-
strategy = new GhostStrategy()
87+
strategyManager = new PromptStrategyManager()
8888

8989
// Create a mock document
9090
const uri = vscode.Uri.parse("file:///test-file.ts")
@@ -116,7 +116,7 @@ describe("GhostRecentOperations", () => {
116116
expect(enrichedContext.recentOperations?.length).toBeGreaterThan(0)
117117

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

121121
// Verify that the prompt includes the recent operations section
122122
// The new strategy system uses "## Recent Typing" format
@@ -133,7 +133,7 @@ describe("GhostRecentOperations", () => {
133133
const enrichedContext = await context.generate(suggestionContext)
134134

135135
// Generate prompt
136-
const { userPrompt } = strategy.getPrompts(enrichedContext)
136+
const { userPrompt } = strategyManager.buildPrompt(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

0 commit comments

Comments
 (0)