Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class RecentlyVisitedRangesService {
private maxRecentFiles = 3
private maxSnippetsPerFile = 3
private isEnabled = true
private disposable: vscode.Disposable | undefined

constructor(private readonly ide: IDE) {
this.cache = new LRUCache<string, Array<AutocompleteCodeSnippet & { timestamp: number }>>({
Expand All @@ -32,7 +33,7 @@ export class RecentlyVisitedRangesService {
this.numSurroundingLines = recentlyVisitedRangesNumSurroundingLines
}

vscode.window.onDidChangeTextEditorSelection(this.cacheCurrentSelectionContext)
this.disposable = vscode.window.onDidChangeTextEditorSelection(this.cacheCurrentSelectionContext)
}

private cacheCurrentSelectionContext = async (event: vscode.TextEditorSelectionChangeEvent) => {
Expand Down Expand Up @@ -105,4 +106,9 @@ export class RecentlyVisitedRangesService {
.sort((a, b) => b.timestamp - a.timestamp)
.map(({ timestamp: _timestamp, ...snippet }) => snippet)
}

public dispose(): void {
this.disposable?.dispose()
this.cache.clear()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ export class RecentlyEditedTracker {

private recentlyEditedDocuments: VsCodeRecentlyEditedDocument[] = []
private static maxRecentlyEditedDocuments = 10
private disposable: vscode.Disposable | undefined
private cleanupInterval: NodeJS.Timeout | undefined

constructor(private ide: IDE) {
vscode.workspace.onDidChangeTextDocument((event) => {
this.disposable = vscode.workspace.onDidChangeTextDocument((event) => {
event.contentChanges.forEach((change) => {
const editedRange = {
uri: event.document.uri,
Expand All @@ -39,7 +41,7 @@ export class RecentlyEditedTracker {
this.insertDocument(event.document.uri)
})

setInterval(() => {
this.cleanupInterval = setInterval(() => {
this.removeOldEntries()
}, 1000 * 15)
}
Expand Down Expand Up @@ -128,4 +130,13 @@ export class RecentlyEditedTracker {
}
})
}

public dispose(): void {
this.disposable?.dispose()
if (this.cleanupInterval) {
clearInterval(this.cleanupInterval)
}
this.recentlyEditedRanges = []
this.recentlyEditedDocuments = []
}
}
6 changes: 6 additions & 0 deletions src/services/ghost/GhostServiceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { GhostModel } from "./GhostModel"
import { GhostStatusBar } from "./GhostStatusBar"
import { GhostCodeActionProvider } from "./GhostCodeActionProvider"
import { GhostInlineCompletionProvider } from "./classic-auto-complete/GhostInlineCompletionProvider"
import { GhostContextProvider } from "./classic-auto-complete/GhostContextProvider"
//import { NewAutocompleteProvider } from "./new-auto-complete/NewAutocompleteProvider"
import { GhostServiceSettings, TelemetryEventName } from "@roo-code/types"
import { ContextProxy } from "../../core/config/ContextProxy"
Expand All @@ -24,6 +25,7 @@ export class GhostServiceManager {
private providerSettingsManager: ProviderSettingsManager
private settings: GhostServiceSettings | null = null
private ghostContext: GhostContext
private ghostContextProvider: GhostContextProvider

private taskId: string | null = null
private isProcessing: boolean = false
Expand All @@ -50,6 +52,7 @@ export class GhostServiceManager {
this.providerSettingsManager = new ProviderSettingsManager(context)
this.model = new GhostModel()
this.ghostContext = new GhostContext(this.documentStore)
this.ghostContextProvider = new GhostContextProvider(context)

// Register the providers
this.codeActionProvider = new GhostCodeActionProvider()
Expand All @@ -58,6 +61,7 @@ export class GhostServiceManager {
this.updateCostTracking.bind(this),
this.ghostContext,
() => this.settings,
this.ghostContextProvider,
)

// Register document event handlers
Expand Down Expand Up @@ -457,6 +461,8 @@ export class GhostServiceManager {
this.inlineCompletionProviderDisposable = null
}

// Dispose inline completion provider resources
this.inlineCompletionProvider.dispose()
// Dispose new autocomplete provider if it exists
//if (this.newAutocompleteProvider) {
// this.newAutocompleteProvider.dispose()
Expand Down
153 changes: 0 additions & 153 deletions src/services/ghost/__tests__/GhostRecentOperations.spec.ts

This file was deleted.

89 changes: 89 additions & 0 deletions src/services/ghost/classic-auto-complete/GhostContextProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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 the IDE instance for use by tracking services
*/
public getIde(): VsCodeIde {
return 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 {
// Convert filepath to URI if it's not already one
const filepathUri = filepath.startsWith("file://") ? filepath : vscode.Uri.file(filepath).toString()

// Initialize import definitions cache
await this.contextService.initializeForFile(filepathUri)

const continuedevInput = convertToContinuedevInput(autocompleteInput)

// Create helper with URI filepath
const helperInput = {
...continuedevInput,
filepath: filepathUri,
}

const helper = await HelperVars.create(helperInput 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)

// Convert all snippet filepaths to URIs
const snippetsWithUris = filteredSnippets.map((snippet: any) => ({
...snippet,
filepath: snippet.filepath?.startsWith("file://")
? snippet.filepath
: vscode.Uri.file(snippet.filepath).toString(),
}))

const workspaceDirs = await this.ide.getWorkspaceDirs()
const formattedContext = formatSnippets(helper, snippetsWithUris, workspaceDirs)

console.log("[GhostContextProvider] - formattedContext:", formattedContext)

return formattedContext
} catch (error) {
console.warn("Failed to get formatted context:", error)
return ""
}
}
}
Loading