Skip to content

Commit bd8111a

Browse files
authored
Merge branch 'main' into feat/add-ovhcloud-ai-endpoints-provider-to-kilocode-cli
2 parents 44f067d + c79df25 commit bd8111a

15 files changed

+340
-663
lines changed

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 { AutoTriggerStrategy } from "../classic-auto-complete/AutoTriggerStrategy"
5+
import { HoleFiller } from "../classic-auto-complete/HoleFiller"
66
import { GhostSuggestionContext, contextToAutocompleteInput } 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 autoTriggerStrategy: AutoTriggerStrategy
81+
let holeFiller: HoleFiller
8282
let mockDocument: MockTextDocument
8383

8484
beforeEach(() => {
8585
documentStore = new GhostDocumentStore()
8686
context = new GhostContext(documentStore)
87-
autoTriggerStrategy = new AutoTriggerStrategy()
87+
holeFiller = new HoleFiller()
8888

8989
// Create a mock document
9090
const uri = vscode.Uri.parse("file:///test-file.ts")
@@ -121,7 +121,7 @@ describe("GhostRecentOperations", () => {
121121
const prefix = enrichedContext.document.getText()
122122
const suffix = ""
123123
const languageId = enrichedContext.document.languageId
124-
const { userPrompt } = autoTriggerStrategy.getPrompts(autocompleteInput, prefix, suffix, languageId)
124+
const { userPrompt } = holeFiller.getPrompts(autocompleteInput, prefix, suffix, languageId)
125125

126126
// Verify that the prompt includes the recent operations section
127127
// The strategy system uses "<RECENT_EDITS>" XML format
@@ -143,7 +143,7 @@ describe("GhostRecentOperations", () => {
143143
const prefix = enrichedContext.document.getText()
144144
const suffix = ""
145145
const languageId = enrichedContext.document.languageId
146-
const { userPrompt } = autoTriggerStrategy.getPrompts(autocompleteInput, prefix, suffix, languageId)
146+
const { userPrompt } = holeFiller.getPrompts(autocompleteInput, prefix, suffix, languageId)
147147

148148
// Verify that the prompt does not include recent operations section
149149
// The current document content will still be in the prompt, so we should only check

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, it, expect, beforeEach, vi } from "vitest"
22
import { MockWorkspace } from "./MockWorkspace"
33
import * as vscode from "vscode"
4-
import { parseGhostResponse } from "../classic-auto-complete/GhostStreamingParser"
4+
import { parseGhostResponse } from "../classic-auto-complete/HoleFiller"
55
import { GhostSuggestionContext, extractPrefixSuffix } from "../types"
66

77
vi.mock("vscode", () => ({

src/services/ghost/classic-auto-complete/CommentHelpers.ts

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

src/services/ghost/classic-auto-complete/GhostInlineCompletionProvider.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as vscode from "vscode"
2-
import { FillInAtCursorSuggestion } from "./GhostSuggestions"
32
import { extractPrefixSuffix, GhostSuggestionContext, contextToAutocompleteInput } from "../types"
4-
import { parseGhostResponse } from "./GhostStreamingParser"
5-
import { AutoTriggerStrategy } from "./AutoTriggerStrategy"
3+
import { parseGhostResponse, HoleFiller, FillInAtCursorSuggestion } from "./HoleFiller"
64
import { GhostModel } from "../GhostModel"
75
import { GhostContext } from "../GhostContext"
86
import { ApiStreamChunk } from "../../../api/transform/stream"
@@ -72,7 +70,7 @@ export interface LLMRetrievalResult {
7270

7371
export class GhostInlineCompletionProvider implements vscode.InlineCompletionItemProvider {
7472
private suggestionsHistory: FillInAtCursorSuggestion[] = []
75-
private autoTriggerStrategy: AutoTriggerStrategy
73+
private holeFiller: HoleFiller
7674
private isRequestCancelled: boolean = false
7775
private model: GhostModel
7876
private costTrackingCallback: CostTrackingCallback
@@ -89,7 +87,7 @@ export class GhostInlineCompletionProvider implements vscode.InlineCompletionIte
8987
this.costTrackingCallback = costTrackingCallback
9088
this.ghostContext = ghostContext
9189
this.getSettings = getSettings
92-
this.autoTriggerStrategy = new AutoTriggerStrategy()
90+
this.holeFiller = new HoleFiller()
9391
}
9492

9593
public updateSuggestions(fillInAtCursor: FillInAtCursorSuggestion): void {
@@ -142,12 +140,7 @@ export class GhostInlineCompletionProvider implements vscode.InlineCompletionIte
142140
}
143141
}
144142

145-
const { systemPrompt, userPrompt } = this.autoTriggerStrategy.getPrompts(
146-
autocompleteInput,
147-
prefix,
148-
suffix,
149-
languageId,
150-
)
143+
const { systemPrompt, userPrompt } = this.holeFiller.getPrompts(autocompleteInput, prefix, suffix, languageId)
151144

152145
if (this.isRequestCancelled) {
153146
return {

src/services/ghost/classic-auto-complete/GhostStreamingParser.ts

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

src/services/ghost/classic-auto-complete/GhostSuggestions.ts

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

src/services/ghost/classic-auto-complete/AutoTriggerStrategy.ts renamed to src/services/ghost/classic-auto-complete/HoleFiller.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import { AutocompleteInput } from "../types"
2-
import { CURSOR_MARKER } from "./ghostConstants"
32
import type { TextDocument, Range } from "vscode"
43

4+
/**
5+
* Special marker used to indicate where completions should occur in the document
6+
*/
7+
export const CURSOR_MARKER = "<<<AUTOCOMPLETE_HERE>>>"
8+
9+
export interface FillInAtCursorSuggestion {
10+
text: string
11+
prefix: string
12+
suffix: string
13+
}
14+
515
export function getBaseSystemInstructions(): string {
616
return `You are a HOLE FILLER. You are provided with a file containing holes, formatted as '{{FILL_HERE}}'. Your TASK is to complete with a string to replace this hole with, inside a <COMPLETION/> XML tag, including context-aware indentation, if needed. All completions MUST be truthful, accurate, well-written and correct.
717
@@ -104,7 +114,32 @@ export function addCursorMarker(document: TextDocument, range?: Range): string {
104114
return `${beforeCursor}${CURSOR_MARKER}${afterCursor}`
105115
}
106116

107-
export class AutoTriggerStrategy {
117+
/**
118+
* Parse the response - only handles responses with <COMPLETION> tags
119+
* Returns a FillInAtCursorSuggestion with the extracted text, or an empty string if nothing found
120+
*/
121+
export function parseGhostResponse(fullResponse: string, prefix: string, suffix: string): FillInAtCursorSuggestion {
122+
let fimText: string = ""
123+
124+
// Match content strictly between <COMPLETION> and </COMPLETION> tags
125+
const completionMatch = fullResponse.match(/<COMPLETION>([\s\S]*?)<\/COMPLETION>/i)
126+
127+
if (completionMatch) {
128+
// Extract the captured group (content between tags)
129+
fimText = completionMatch[1] || ""
130+
}
131+
// Remove any accidentally captured tag remnants
132+
fimText = fimText.replace(/<\/?COMPLETION>/gi, "")
133+
134+
// Return FillInAtCursorSuggestion with the text (empty string if nothing found)
135+
return {
136+
text: fimText,
137+
prefix,
138+
suffix,
139+
}
140+
}
141+
142+
export class HoleFiller {
108143
getPrompts(
109144
autocompleteInput: AutocompleteInput,
110145
prefix: string,

src/services/ghost/classic-auto-complete/__tests__/AutoTriggerStrategy.test.ts

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

0 commit comments

Comments
 (0)