Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1c0e0c1
WiP ghost context provider
beatlevic Nov 4, 2025
0d5a465
Use pure function for formatContextForPrompt
beatlevic Nov 4, 2025
c067c1d
Added more context snippets like clipboard, static, recentlyVisited a…
beatlevic Nov 4, 2025
dc1f5f6
Improved categorizeSnippets
beatlevic Nov 4, 2025
3ade747
Used comment wrapped formatSnippets directly
beatlevic Nov 4, 2025
5810ccb
Removed RECENT_EDITS
beatlevic Nov 4, 2025
3e3060c
Cleanup auto trigger strategy test
beatlevic Nov 4, 2025
a90e41a
Removed Ghost recent operations spec
beatlevic Nov 4, 2025
d10b8bc
Merge branch 'main' into beatlevic/ghost-context-provider
beatlevic Nov 4, 2025
2334465
Cleanup ghost context provider
beatlevic Nov 4, 2025
4c28d9b
Cleanup GhostContextProvider.test.ts
beatlevic Nov 4, 2025
b935be2
Plumb through GhostContextProvider
jrf0110 Nov 6, 2025
44f5165
Added GhostRecentlyVisitedRangesService to keep track of recent files
beatlevic Nov 6, 2025
ead100a
Added GhostRecentlyEditedTracker
beatlevic Nov 6, 2025
f9378a9
Use recentlyEditedRanges and recentlyVisitedRanges services directly
beatlevic Nov 6, 2025
1432705
Added continuedev dispose methods
beatlevic Nov 6, 2025
dd4f395
Merge branch 'main' into beatlevic/ghost-context-provider
beatlevic Nov 6, 2025
adcac93
Merge branch 'main' into beatlevic/ghost-context-provider
beatlevic Nov 6, 2025
aad27a6
Fixed GhostInlineCompletionProvider.test.ts
beatlevic Nov 6, 2025
7bf414b
Merge branch 'beatlevic/ghost-context-provider' of github.com:Kilo-Or…
beatlevic Nov 6, 2025
a3c1aad
Merge branch 'main' into beatlevic/ghost-context-provider
beatlevic Nov 6, 2025
48450b3
Merge branch 'main' into beatlevic/ghost-context-provider
beatlevic Nov 6, 2025
787ec84
Fixed HoleFiller.test.ts
beatlevic Nov 6, 2025
bdfceaa
Removed addCursorMarker from HoleFiller
beatlevic Nov 6, 2025
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
153 changes: 0 additions & 153 deletions src/services/ghost/__tests__/GhostRecentOperations.spec.ts

This file was deleted.

48 changes: 32 additions & 16 deletions src/services/ghost/classic-auto-complete/AutoTriggerStrategy.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { AutocompleteInput } from "../types"
import { CURSOR_MARKER } from "./ghostConstants"
import type { TextDocument, Range } from "vscode"
import { GhostContextProvider } from "./GhostContextProvider"

export function getBaseSystemInstructions(): string {
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.

## Context Tags
<LANGUAGE>: file language | <RECENT_EDITS>: recent changes | <QUERY>: code with {{FILL_HERE}}
## Context Format
<LANGUAGE>: file language
<QUERY>: contains commented reference code (// Path: file.ts) followed by code with {{FILL_HERE}}
Comments provide context from related files, recent edits, imports, etc.

## EXAMPLE QUERY:

Expand Down Expand Up @@ -105,18 +108,21 @@ export function addCursorMarker(document: TextDocument, range?: Range): string {
}

export class AutoTriggerStrategy {
getPrompts(
constructor(private contextProvider?: GhostContextProvider) {}

async getPrompts(
autocompleteInput: AutocompleteInput,
prefix: string,
suffix: string,
languageId: string,
): {
): Promise<{
systemPrompt: string
userPrompt: string
} {
}> {
const userPrompt = await this.getUserPrompt(autocompleteInput, prefix, suffix, languageId)
return {
systemPrompt: this.getSystemInstructions(),
userPrompt: this.getUserPrompt(autocompleteInput, prefix, suffix, languageId),
userPrompt,
}
}

Expand All @@ -131,22 +137,32 @@ Provide a subtle, non-intrusive completion after a typing pause.
}

/**
* Build minimal prompt for auto-trigger
* Build minimal prompt for auto-trigger with optional context
*/
getUserPrompt(autocompleteInput: AutocompleteInput, prefix: string, suffix: string, languageId: string): string {
async getUserPrompt(
autocompleteInput: AutocompleteInput,
prefix: string,
suffix: string,
languageId: string,
): Promise<string> {
let prompt = `<LANGUAGE>${languageId}</LANGUAGE>\n\n`

if (autocompleteInput.recentlyEditedRanges && autocompleteInput.recentlyEditedRanges.length > 0) {
prompt += "<RECENT_EDITS>\n"
autocompleteInput.recentlyEditedRanges.forEach((range, index) => {
const description = `Edited ${range.filepath} at line ${range.range.start.line}`
prompt += `${index + 1}. ${description}\n`
})
prompt += "</RECENT_EDITS>\n\n"
// Get comment-wrapped context (includes all context types with token-based filtering)
let formattedContext = ""
if (this.contextProvider && autocompleteInput.filepath) {
try {
formattedContext = await this.contextProvider.getFormattedContext(
autocompleteInput,
autocompleteInput.filepath,
)
} catch (error) {
console.warn("Failed to get formatted context:", error)
}
}

// Context and code go together in QUERY (comments provide context for the code)
prompt += `<QUERY>
${prefix}{{FILL_HERE}}${suffix}
${formattedContext}${prefix}{{FILL_HERE}}${suffix}
</QUERY>

TASK: Fill the {{FILL_HERE}} hole. Answer only with the CORRECT completion, and NOTHING ELSE. Do it now.
Expand Down
66 changes: 66 additions & 0 deletions src/services/ghost/classic-auto-complete/GhostContextProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import * as vscode from "vscode"
import { ContextRetrievalService } from "../../continuedev/core/autocomplete/context/ContextRetrievalService"
import { VsCodeIde } from "../../continuedev/core/vscode-test-harness/src/VSCodeIde"
import { AutocompleteInput } from "../types"
import { AutocompleteSnippetType } from "../../continuedev/core/autocomplete/snippets/types"
import { HelperVars } from "../../continuedev/core/autocomplete/util/HelperVars"
import { getAllSnippetsWithoutRace } from "../../continuedev/core/autocomplete/snippets/getAllSnippets"
import { getDefinitionsFromLsp } from "../../continuedev/core/vscode-test-harness/src/autocomplete/lsp"
import { DEFAULT_AUTOCOMPLETE_OPTS } from "../../continuedev/core/util/parameters"
import { getSnippets } from "../../continuedev/core/autocomplete/templating/filtering"
import { formatSnippets } from "../../continuedev/core/autocomplete/templating/formatting"

function convertToContinuedevInput(autocompleteInput: AutocompleteInput) {
return {
...autocompleteInput,
recentlyVisitedRanges: autocompleteInput.recentlyVisitedRanges.map((range) => ({
...range,
type: AutocompleteSnippetType.Code,
})),
}
}

export class GhostContextProvider {
private contextService: ContextRetrievalService
private ide: VsCodeIde

constructor(context: vscode.ExtensionContext) {
this.ide = new VsCodeIde(context)
this.contextService = new ContextRetrievalService(this.ide)
}

/**
* Get context snippets for the current autocomplete request
* Returns comment-based formatted context that can be added to prompts
*/
async getFormattedContext(autocompleteInput: AutocompleteInput, filepath: string): Promise<string> {
try {
// Initialize import definitions cache
await this.contextService.initializeForFile(filepath)

const continuedevInput = convertToContinuedevInput(autocompleteInput)
const helper = await HelperVars.create(
continuedevInput as any,
DEFAULT_AUTOCOMPLETE_OPTS,
"codestral",
this.ide,
)

const snippetPayload = await getAllSnippetsWithoutRace({
helper,
ide: this.ide,
getDefinitionsFromLsp,
contextRetrievalService: this.contextService,
})

const filteredSnippets = getSnippets(helper, snippetPayload)
const workspaceDirs = await this.ide.getWorkspaceDirs()
const formattedContext = formatSnippets(helper, filteredSnippets, workspaceDirs)

return formattedContext
} catch (error) {
console.warn("Failed to get formatted context:", error)
return ""
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class GhostInlineCompletionProvider implements vscode.InlineCompletionIte
}
}

const { systemPrompt, userPrompt } = this.autoTriggerStrategy.getPrompts(
const { systemPrompt, userPrompt } = await this.autoTriggerStrategy.getPrompts(
autocompleteInput,
prefix,
suffix,
Expand Down
Loading