From e3cf991c3225471f46d86f030f9b0ab5c3a0aa45 Mon Sep 17 00:00:00 2001 From: Agent Date: Wed, 7 Jan 2026 08:55:26 +0000 Subject: [PATCH] feat(autocomplete): Add id field to cache for better visibility tracking - Add id property to FillInAtCursorSuggestion type - Update getSuggestionKey() to return the id instead of prefix/suffix/text triplet - Generate id when creating suggestions - Update tests to include id field --- .changeset/fast-carrots-remember.md | 7 +++++++ .../classic-auto-complete/AutocompleteTelemetry.ts | 2 +- .../GhostInlineCompletionProvider.ts | 13 +++++++++---- .../__tests__/AutocompleteTelemetry.test.ts | 1 + src/services/ghost/types.ts | 2 ++ 5 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 .changeset/fast-carrots-remember.md diff --git a/.changeset/fast-carrots-remember.md b/.changeset/fast-carrots-remember.md new file mode 100644 index 00000000000..14a96071c0f --- /dev/null +++ b/.changeset/fast-carrots-remember.md @@ -0,0 +1,7 @@ +--- +"kilo-code": patch +--- + +Add id field to autocomplete cache for better visibility tracking + +Added an `id` property to `FillInAtCursorSuggestion` type and updated visibility tracking to use the id instead of the prefix/suffix/suggestion triplet for more reliable telemetry. diff --git a/src/services/ghost/classic-auto-complete/AutocompleteTelemetry.ts b/src/services/ghost/classic-auto-complete/AutocompleteTelemetry.ts index ee231868d33..317055cff24 100644 --- a/src/services/ghost/classic-auto-complete/AutocompleteTelemetry.ts +++ b/src/services/ghost/classic-auto-complete/AutocompleteTelemetry.ts @@ -9,7 +9,7 @@ export type { AutocompleteContext, CacheMatchType, FillInAtCursorSuggestion } * This key is used to track whether the same suggestion is still being displayed. */ export function getSuggestionKey(suggestion: FillInAtCursorSuggestion): string { - return `${suggestion.prefix}|${suggestion.suffix}|${suggestion.text}` + return suggestion.id } /** diff --git a/src/services/ghost/classic-auto-complete/GhostInlineCompletionProvider.ts b/src/services/ghost/classic-auto-complete/GhostInlineCompletionProvider.ts index a557f165f36..e461a46ab47 100644 --- a/src/services/ghost/classic-auto-complete/GhostInlineCompletionProvider.ts +++ b/src/services/ghost/classic-auto-complete/GhostInlineCompletionProvider.ts @@ -322,8 +322,13 @@ export class GhostInlineCompletionProvider implements vscode.InlineCompletionIte return } + // Ensure the suggestion has an id for telemetry tracking + const suggestionWithId = fillInAtCursor.id + ? fillInAtCursor + : { ...fillInAtCursor, id: crypto.randomUUID() } + // Add to the end of the array (most recent) - this.suggestionsHistory.push(fillInAtCursor) + this.suggestionsHistory.push(suggestionWithId) // Remove oldest if we exceed the limit if (this.suggestionsHistory.length > MAX_SUGGESTIONS_HISTORY) { @@ -368,7 +373,7 @@ export class GhostInlineCompletionProvider implements vscode.InlineCompletionIte ): FillInAtCursorSuggestion { if (!suggestionText) { this.telemetry?.captureSuggestionFiltered("empty_response", telemetryContext) - return { text: "", prefix, suffix } + return { text: "", prefix, suffix, id: crypto.randomUUID() } } const processedText = postprocessGhostSuggestion({ @@ -379,11 +384,11 @@ export class GhostInlineCompletionProvider implements vscode.InlineCompletionIte }) if (processedText) { - return { text: processedText, prefix, suffix } + return { text: processedText, prefix, suffix, id: crypto.randomUUID() } } this.telemetry?.captureSuggestionFiltered("filtered_by_postprocessing", telemetryContext) - return { text: "", prefix, suffix } + return { text: "", prefix, suffix, id: crypto.randomUUID() } } private async disposeIgnoreController(): Promise { diff --git a/src/services/ghost/classic-auto-complete/__tests__/AutocompleteTelemetry.test.ts b/src/services/ghost/classic-auto-complete/__tests__/AutocompleteTelemetry.test.ts index a4a6581f8aa..38f3cc9342b 100644 --- a/src/services/ghost/classic-auto-complete/__tests__/AutocompleteTelemetry.test.ts +++ b/src/services/ghost/classic-auto-complete/__tests__/AutocompleteTelemetry.test.ts @@ -19,6 +19,7 @@ describe("AutocompleteTelemetry", () => { text: `text-${index}`, prefix: `prefix-${index}`, suffix: `suffix-${index}`, + id: `suggestion-${index}`, } } diff --git a/src/services/ghost/types.ts b/src/services/ghost/types.ts index 69d19db9b04..de26ea4ba29 100644 --- a/src/services/ghost/types.ts +++ b/src/services/ghost/types.ts @@ -96,6 +96,8 @@ export interface FillInAtCursorSuggestion { text: string prefix: string suffix: string + /** Unique identifier for this suggestion, used for telemetry tracking */ + id: string } export interface MatchingSuggestionResult {