From c70f5695dc571ef0ed3b4fce7a0218300561fc61 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 6 Aug 2025 15:49:22 -0700 Subject: [PATCH 01/14] chore: add comments --- core/nextEdit/templating/NextEditPromptEngine.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/core/nextEdit/templating/NextEditPromptEngine.ts b/core/nextEdit/templating/NextEditPromptEngine.ts index 1369ebbc6..54e19212d 100644 --- a/core/nextEdit/templating/NextEditPromptEngine.ts +++ b/core/nextEdit/templating/NextEditPromptEngine.ts @@ -33,6 +33,7 @@ import { type TemplateRenderer = (vars: TemplateVars) => string; +// NOTE: When updating this union, update core/llm/autodetect.ts as well. export type NextEditModelName = | "mercury-coder-nextedit" | "model-1" From f691b90778e700e4644bfb6b63702f3138af6e5b Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 6 Aug 2025 15:49:47 -0700 Subject: [PATCH 02/14] feat: add next_edit capability --- core/config/yaml/models.ts | 1 + core/index.d.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/core/config/yaml/models.ts b/core/config/yaml/models.ts index 3f571c3fb..102e4152b 100644 --- a/core/config/yaml/models.ts +++ b/core/config/yaml/models.ts @@ -68,6 +68,7 @@ async function modelConfigToBaseLLM({ capabilities: { tools: model.capabilities?.includes("tool_use"), uploadImage: model.capabilities?.includes("image_input"), + nextEdit: model.capabilities?.includes("next_edit"), }, autocompleteOptions: model.autocompleteOptions, }; diff --git a/core/index.d.ts b/core/index.d.ts index eacffcb56..3dc7a1f71 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1138,6 +1138,7 @@ export interface BaseCompletionOptions { export interface ModelCapability { uploadImage?: boolean; tools?: boolean; + nextEdit?: boolean; } export interface ModelDescription { From c5c2e2e0f2a3efd1cda6e88b3534f888a927f43d Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 6 Aug 2025 15:50:29 -0700 Subject: [PATCH 03/14] feat: add a checker function to see if next_edit capability is set, or if the model is one of our supported models --- core/llm/autodetect.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/core/llm/autodetect.ts b/core/llm/autodetect.ts index 571a7a700..9d0b72626 100644 --- a/core/llm/autodetect.ts +++ b/core/llm/autodetect.ts @@ -173,6 +173,35 @@ function isProviderHandlesTemplatingOrNoTemplateTypeRequired( ); } +// NOTE: When updating this list, +// update core/nextEdit/templating/NextEditPromptEngine.ts as well. +const MODEL_SUPPORTS_NEXT_EDIT: string[] = [ + "mercury-coder-nextedit", + "model-1", + "this field is not used", +]; + +function modelSupportsNextEdit( + model: string, + title: string | undefined, + capabilities: ModelCapability | undefined, +): boolean { + if (capabilities?.nextEdit !== undefined) { + return capabilities.nextEdit; + } + + const lower = model.toLowerCase(); + if ( + MODEL_SUPPORTS_NEXT_EDIT.some( + (modelName) => lower.includes(modelName) || title?.includes(modelName), + ) + ) { + return true; + } + + return false; +} + function autodetectTemplateType(model: string): TemplateType | undefined { const lower = model.toLowerCase(); @@ -391,4 +420,5 @@ export { autodetectTemplateType, llmCanGenerateInParallel, modelSupportsImages, + modelSupportsNextEdit, }; From e480bcf9d00a73a09c360bd1e8b22fc311ed59ba Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 6 Aug 2025 15:50:59 -0700 Subject: [PATCH 04/14] refactor: check if model supports next edit --- core/nextEdit/NextEditProvider.ts | 9 +++++++++ extensions/vscode/src/extension/VsCodeExtension.ts | 12 +++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/core/nextEdit/NextEditProvider.ts b/core/nextEdit/NextEditProvider.ts index 1ae21c152..8e37d2547 100644 --- a/core/nextEdit/NextEditProvider.ts +++ b/core/nextEdit/NextEditProvider.ts @@ -18,6 +18,7 @@ import { AutocompleteDebouncer } from "../autocomplete/util/AutocompleteDebounce import AutocompleteLruCache from "../autocomplete/util/AutocompleteLruCache.js"; import { HelperVars } from "../autocomplete/util/HelperVars.js"; import { AutocompleteInput } from "../autocomplete/util/types.js"; +import { modelSupportsNextEdit } from "../llm/autodetect.js"; import { localPathOrUriToPath } from "../util/pathToUri.js"; import { replaceEscapedCharacters } from "../util/text.js"; import { @@ -286,6 +287,14 @@ export class NextEditProvider { return undefined; } + // In vscode, this check is done in extensions/vscode/src/extension/VsCodeExtension.ts. + // For other editors, this check should be done in their respective config reloaders. + // This is left for a final check. + if (!modelSupportsNextEdit(llm.model, llm.title, llm.capabilities)) { + console.error(`${llm.model} is not capable of next edit.`); + return undefined; + } + if (llm.promptTemplates?.autocomplete) { options.template = llm.promptTemplates.autocomplete as string; } diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index a8fcdbb88..898d648a0 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -43,13 +43,14 @@ import { ConfigYamlDocumentLinkProvider } from "./ConfigYamlDocumentLinkProvider import { VsCodeMessenger } from "./VsCodeMessenger"; import { getAst } from "core/autocomplete/util/ast"; +import { modelSupportsNextEdit } from "core/llm/autodetect"; import { DocumentHistoryTracker } from "core/nextEdit/DocumentHistoryTracker"; import { EditableRegionStrategy, getNextEditableRegion, } from "core/nextEdit/NextEditEditableRegionCalculator"; import { NextEditProvider } from "core/nextEdit/NextEditProvider"; -import { isModelCapableOfNextEdit } from "core/nextEdit/utils"; +import { isNextEditTest } from "core/nextEdit/utils"; import { localPathOrUriToPath } from "core/util/pathToUri"; import { JumpManager } from "../activation/JumpManager"; import setupNextEditWindowManager, { @@ -190,8 +191,13 @@ export class VsCodeExtension { async ({ config: newConfig, configLoadInterrupted }) => { const autocompleteModel = newConfig?.selectedModelByRole.autocomplete; if ( - autocompleteModel && - isModelCapableOfNextEdit(autocompleteModel.model) + (autocompleteModel && + modelSupportsNextEdit( + autocompleteModel.model, + autocompleteModel.title, + autocompleteModel.capabilities, + )) || + isNextEditTest() ) { // Set up next edit window manager only for Continue team members await setupNextEditWindowManager(context); From 51ef9a9ec76426f0da65f968cf6c653b6b08cb12 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 6 Aug 2025 15:51:12 -0700 Subject: [PATCH 05/14] refactor: only handle test environments --- core/nextEdit/utils.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/core/nextEdit/utils.ts b/core/nextEdit/utils.ts index 152e55933..bf1081ebe 100644 --- a/core/nextEdit/utils.ts +++ b/core/nextEdit/utils.ts @@ -1,15 +1,13 @@ -type NextEditModelName = "mercury-coder-nextedit"; +export function isNextEditTest(): boolean { + const enabled = process.env.NEXT_EDIT_TEST_ENABLED; -export function isModelCapableOfNextEdit(modelName: string): boolean { - // In test mode, we can control whether next edit is enabled via environment variable. - if (process.env.NEXT_EDIT_TEST_ENABLED === "false") { + if (enabled === "false") { return false; } - if (process.env.NEXT_EDIT_TEST_ENABLED === "true") { + if (enabled === "true") { return true; } - const supportedModels: NextEditModelName[] = ["mercury-coder-nextedit"]; - return supportedModels.some((supported) => modelName.includes(supported)); + return false; } From 6a31f985b02d595b76f98404359ddb5be0bf9656 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 6 Aug 2025 15:51:57 -0700 Subject: [PATCH 06/14] feat: add next_edit z.literal --- packages/config-yaml/src/schemas/models.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/config-yaml/src/schemas/models.ts b/packages/config-yaml/src/schemas/models.ts index 283ec6781..0693675a2 100644 --- a/packages/config-yaml/src/schemas/models.ts +++ b/packages/config-yaml/src/schemas/models.ts @@ -36,6 +36,7 @@ export type ModelRole = z.infer; export const modelCapabilitySchema = z.union([ z.literal("tool_use"), z.literal("image_input"), + z.literal("next_edit"), ]); export type ModelCapability = z.infer; From 3c51d54cc2096eaf47bc1b9f59bc0ecb141e874f Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 6 Aug 2025 15:59:27 -0700 Subject: [PATCH 07/14] test: add vitest for autodetect next edit --- core/llm/autodetect.vitest.ts | 126 +++++++++++++++++++++++++++++++++- 1 file changed, 124 insertions(+), 2 deletions(-) diff --git a/core/llm/autodetect.vitest.ts b/core/llm/autodetect.vitest.ts index e9d7180ae..5743a749c 100644 --- a/core/llm/autodetect.vitest.ts +++ b/core/llm/autodetect.vitest.ts @@ -1,5 +1,5 @@ -import { expect, test } from "vitest"; -import { autodetectTemplateType } from "./autodetect"; +import { describe, expect, it, test } from "vitest"; +import { autodetectTemplateType, modelSupportsNextEdit } from "./autodetect"; test("autodetectTemplateType returns 'codellama-70b' for CodeLlama 70B models", () => { expect(autodetectTemplateType("codellama-70b")).toBe("codellama-70b"); @@ -201,3 +201,125 @@ test("autodetectTemplateType handles models with mixed keywords", () => { expect(autodetectTemplateType("gpt-llama")).toBe(undefined); // gpt comes first, returns undefined expect(autodetectTemplateType("claude-llama")).toBe("llama2"); // llama comes first, returns llama2 }); + +describe("modelSupportsNextEdit", () => { + describe("when capabilities.nextEdit is defined", () => { + it("should return true when capabilities.nextEdit is true", () => { + const result = modelSupportsNextEdit("any-model", "Any Title", { + nextEdit: true, + }); + + expect(result).toBe(true); + }); + + it("should return false when capabilities.nextEdit is false", () => { + const result = modelSupportsNextEdit( + "mercury-coder-nextedit", + "Mercury Coder", + { nextEdit: false }, + ); + + expect(result).toBe(false); + }); + + it("should prioritize capabilities over model name matching", () => { + // Even though model name matches, capabilities should take precedence. + const result = modelSupportsNextEdit( + "mercury-coder-nextedit", + "Mercury Coder", + { nextEdit: false }, + ); + + expect(result).toBe(false); + }); + }); + + describe("when capabilities.nextEdit is undefined", () => { + it("should return true for mercury-coder-nextedit model (case insensitive)", () => { + expect( + modelSupportsNextEdit("Mercury-Coder-Nextedit", undefined, undefined), + ).toBe(true); + }); + + it("should return true for model-1", () => { + expect(modelSupportsNextEdit("model-1", undefined, undefined)).toBe(true); + }); + + it("should return true when model contains supported model name as substring", () => { + expect( + modelSupportsNextEdit( + "provider/mercury-coder-nextedit-v2", + undefined, + undefined, + ), + ).toBe(true); + }); + + it("should return true when title contains supported model name", () => { + expect( + modelSupportsNextEdit( + "some-model", + "This is mercury-coder-nextedit model", + undefined, + ), + ).toBe(true); + }); + + it("should return true when title contains model-1", () => { + expect( + modelSupportsNextEdit("some-model", "model-1 deployment", undefined), + ).toBe(true); + }); + + it("should return true for unsupported models that have capabilities explicitly set to true", () => { + expect( + modelSupportsNextEdit("gpt-4", "GPT-4 Model", { + nextEdit: true, + }), + ).toBe(true); + }); + + it("should return false for unsupported models", () => { + expect(modelSupportsNextEdit("gpt-4", "GPT-4 Model", undefined)).toBe( + false, + ); + }); + + it("should return false when model and title are both undefined/null", () => { + expect(modelSupportsNextEdit("", undefined, undefined)).toBe(false); + }); + + it("should return false when model and title do not contain supported names", () => { + expect( + modelSupportsNextEdit("claude-3", "Claude 3 Sonnet", undefined), + ).toBe(false); + }); + }); + + describe("edge cases", () => { + it("should handle empty strings", () => { + expect(modelSupportsNextEdit("", "", undefined)).toBe(false); + }); + + it("should handle undefined title gracefully", () => { + expect( + modelSupportsNextEdit("mercury-coder-nextedit", undefined, undefined), + ).toBe(true); + }); + + it("should handle case sensitivity correctly", () => { + expect( + modelSupportsNextEdit("MERCURY-CODER-NEXTEDIT", "MODEL-1", undefined), + ).toBe(true); + }); + + it("should handle capabilities with other properties", () => { + expect( + modelSupportsNextEdit("unsupported-model", undefined, { + nextEdit: true, + uploadImage: false, + }), + ).toBe(true); + }); + }); +}); From b3da8c7c70ba9f0769bced204a4c94cd7ce015a9 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 6 Aug 2025 16:06:45 -0700 Subject: [PATCH 08/14] refactor: return token, startTime, and helper --- core/nextEdit/NextEditProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/nextEdit/NextEditProvider.ts b/core/nextEdit/NextEditProvider.ts index 1af6b6fc0..0b549dfde 100644 --- a/core/nextEdit/NextEditProvider.ts +++ b/core/nextEdit/NextEditProvider.ts @@ -347,7 +347,7 @@ export class NextEditProvider { // This is left for a final check. if (!modelSupportsNextEdit(llm.model, llm.title, llm.capabilities)) { console.error(`${llm.model} is not capable of next edit.`); - return undefined; + return { token, startTime, helper: undefined }; } if (llm.promptTemplates?.autocomplete) { From 793c835f23cfd4248c36675d0b449b0d250e2fe7 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 6 Aug 2025 16:20:43 -0700 Subject: [PATCH 09/14] fix: remove test model for now --- core/llm/autodetect.ts | 1 - .../templating/NextEditPromptEngine.ts | 19 +------------------ 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/core/llm/autodetect.ts b/core/llm/autodetect.ts index 9d0b72626..4d59bd667 100644 --- a/core/llm/autodetect.ts +++ b/core/llm/autodetect.ts @@ -178,7 +178,6 @@ function isProviderHandlesTemplatingOrNoTemplateTypeRequired( const MODEL_SUPPORTS_NEXT_EDIT: string[] = [ "mercury-coder-nextedit", "model-1", - "this field is not used", ]; function modelSupportsNextEdit( diff --git a/core/nextEdit/templating/NextEditPromptEngine.ts b/core/nextEdit/templating/NextEditPromptEngine.ts index 59cea94f5..bfab03a73 100644 --- a/core/nextEdit/templating/NextEditPromptEngine.ts +++ b/core/nextEdit/templating/NextEditPromptEngine.ts @@ -34,10 +34,7 @@ import { type TemplateRenderer = (vars: TemplateVars) => string; // NOTE: When updating this union, update core/llm/autodetect.ts as well. -export type NextEditModelName = - | "mercury-coder-nextedit" - | "model-1" - | "this field is not used"; +export type NextEditModelName = "mercury-coder-nextedit" | "model-1"; const NEXT_EDIT_MODEL_TEMPLATES: Record = { "mercury-coder-nextedit": { @@ -47,9 +44,6 @@ const NEXT_EDIT_MODEL_TEMPLATES: Record = { template: "### User Edits:\n\n{{{userEdits}}}\n\n### User Excerpts:\n\n```{{{languageShorthand}}}\n{{{userExcerpts}}}```", }, - "this field is not used": { - template: "NEXT_EDIT", - }, }; function templateRendererOfModel( @@ -73,17 +67,6 @@ export async function renderPrompt( ): Promise { let modelName = helper.modelName as NextEditModelName; - if (modelName === "this field is not used") { - return { - prompt: { - role: "user", - content: "NEXT_EDIT", - }, - userEdits: "", - userExcerpts: helper.fileContents, - }; - } - // Validate that the modelName is actually a supported model. if (!Object.keys(NEXT_EDIT_MODEL_TEMPLATES).includes(modelName)) { // Check if modelName includes any known model name as substring. From 6b51f556a9bed2343951eb8b6cb317ede8b97612 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 6 Aug 2025 16:26:56 -0700 Subject: [PATCH 10/14] fix: remove test llm from prompt engine vitest --- .../templating/NextEditPromptEngine.vitest.ts | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/core/nextEdit/templating/NextEditPromptEngine.vitest.ts b/core/nextEdit/templating/NextEditPromptEngine.vitest.ts index 03ffd26e8..a83f19330 100644 --- a/core/nextEdit/templating/NextEditPromptEngine.vitest.ts +++ b/core/nextEdit/templating/NextEditPromptEngine.vitest.ts @@ -41,12 +41,6 @@ describe("NextEditPromptEngine", () => { pos: { line: 1, character: 12 } as Position, lang: { name: "typescript" }, } as HelperVars; - testHelper = { - modelName: "this field is not used" as NextEditModelName, - fileContents: "function test() {\n const a = 1;\n return a;\n}", - pos: { line: 1, character: 12 } as Position, - lang: { name: "typescript" }, - } as HelperVars; unsupportedHelper = { modelName: "mistral/codestral" as NextEditModelName, fileContents: "function test() {\n const a = 1;\n return a;\n}", @@ -99,16 +93,6 @@ describe("NextEditPromptEngine", () => { expect(result.userExcerpts).toContain(MODEL_1_USER_CURSOR_IS_HERE_TOKEN); }); - it("should handle 'this field is not used' model name", async () => { - const result = await renderPrompt(testHelper, ctx); - - expect(result).toHaveProperty("prompt"); - expect(result.prompt.role).toBe("user"); - expect(result.prompt.content).toBe("NEXT_EDIT"); - expect(result.userEdits).toBe(""); - expect(result.userExcerpts).toBe(testHelper.fileContents); - }); - it("should throw error for unsupported model name", async () => { await expect(renderPrompt(unsupportedHelper, ctx)).rejects.toThrow( "mistral/codestral is not yet supported for next edit.", From def9970dbd83aa12f30f8ed539cf2161adb5745a Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 6 Aug 2025 18:23:44 -0700 Subject: [PATCH 11/14] refactor: define next edit model enum to use elsewhere --- core/llm/constants.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/llm/constants.ts b/core/llm/constants.ts index b6759663d..5b93048e9 100644 --- a/core/llm/constants.ts +++ b/core/llm/constants.ts @@ -19,6 +19,11 @@ export enum LLMConfigurationStatuses { MISSING_ENV_SECRET = "missing-env-secret", } +export enum NEXT_EDIT_MODELS { + MERCURY_CODER_NEXTEDIT = "mercury-coder-nextedit", + MODEL_1 = "model-1", +} + export { DEFAULT_ARGS, DEFAULT_CONTEXT_LENGTH, From 722bdbf97d7d44890e5a2cac96ec91cd3f3ed83f Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 6 Aug 2025 18:24:17 -0700 Subject: [PATCH 12/14] refactor: use next edit model enum --- core/llm/autodetect.ts | 7 ++++--- core/nextEdit/templating/NextEditPromptEngine.ts | 12 +++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/core/llm/autodetect.ts b/core/llm/autodetect.ts index 4d59bd667..b2943e316 100644 --- a/core/llm/autodetect.ts +++ b/core/llm/autodetect.ts @@ -1,4 +1,5 @@ import { ChatMessage, ModelCapability, TemplateType } from "../index.js"; +import { NEXT_EDIT_MODELS } from "./constants.js"; import { anthropicTemplateMessages, @@ -176,14 +177,14 @@ function isProviderHandlesTemplatingOrNoTemplateTypeRequired( // NOTE: When updating this list, // update core/nextEdit/templating/NextEditPromptEngine.ts as well. const MODEL_SUPPORTS_NEXT_EDIT: string[] = [ - "mercury-coder-nextedit", - "model-1", + NEXT_EDIT_MODELS.MERCURY_CODER_NEXTEDIT, + NEXT_EDIT_MODELS.MODEL_1, ]; function modelSupportsNextEdit( + capabilities: ModelCapability | undefined, model: string, title: string | undefined, - capabilities: ModelCapability | undefined, ): boolean { if (capabilities?.nextEdit !== undefined) { return capabilities.nextEdit; diff --git a/core/nextEdit/templating/NextEditPromptEngine.ts b/core/nextEdit/templating/NextEditPromptEngine.ts index bfab03a73..29e958b18 100644 --- a/core/nextEdit/templating/NextEditPromptEngine.ts +++ b/core/nextEdit/templating/NextEditPromptEngine.ts @@ -30,13 +30,11 @@ import { insertCursorToken, insertEditableRegionTokensWithStaticRange, } from "./utils"; +import { NEXT_EDIT_MODELS } from "../../llm/constants"; type TemplateRenderer = (vars: TemplateVars) => string; -// NOTE: When updating this union, update core/llm/autodetect.ts as well. -export type NextEditModelName = "mercury-coder-nextedit" | "model-1"; - -const NEXT_EDIT_MODEL_TEMPLATES: Record = { +const NEXT_EDIT_MODEL_TEMPLATES: Record = { "mercury-coder-nextedit": { template: `${MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_OPEN}\n{{{recentlyViewedCodeSnippets}}}\n${MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_CLOSE}\n\n${MERCURY_CURRENT_FILE_CONTENT_OPEN}\n{{{currentFileContent}}}\n${MERCURY_CURRENT_FILE_CONTENT_CLOSE}\n\n${MERCURY_EDIT_DIFF_HISTORY_OPEN}\n{{{editDiffHistory}}}\n${MERCURY_EDIT_DIFF_HISTORY_CLOSE}\n\nThe developer was working on a section of code within the tags \`<|code_to_edit|>\` in the file located at {{{currentFilePath}}}.\nUsing the given \`recently_viewed_code_snippets\`, \`current_file_content\`, \`edit_diff_history\`, and the cursor position marked as \`<|cursor|>\`, please continue the developer's work. Update the \`code_to_edit\` section by predicting and completing the changes they would have made next. Provide the revised code that was between the \`<|code_to_edit|>\` and \`<|/code_to_edit|>\` tags, including the tags themselves.`, }, @@ -47,7 +45,7 @@ const NEXT_EDIT_MODEL_TEMPLATES: Record = { }; function templateRendererOfModel( - modelName: NextEditModelName, + modelName: NEXT_EDIT_MODELS, ): TemplateRenderer { let template = NEXT_EDIT_MODEL_TEMPLATES[modelName]; if (!template) { @@ -65,7 +63,7 @@ export async function renderPrompt( helper: HelperVars, ctx: any, ): Promise { - let modelName = helper.modelName as NextEditModelName; + let modelName = helper.modelName as NEXT_EDIT_MODELS; // Validate that the modelName is actually a supported model. if (!Object.keys(NEXT_EDIT_MODEL_TEMPLATES).includes(modelName)) { @@ -75,7 +73,7 @@ export async function renderPrompt( ); if (matchingModel) { - modelName = matchingModel as NextEditModelName; + modelName = matchingModel as NEXT_EDIT_MODELS; } else { throw new Error( `${helper.modelName} is not yet supported for next edit.`, From 2aae07efc37d0847f3de8d3224afcd3d3021a3c5 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 6 Aug 2025 18:24:43 -0700 Subject: [PATCH 13/14] refactor: move capabilities to the top --- core/llm/autodetect.vitest.ts | 86 +++++++++++-------- core/nextEdit/NextEditProvider.ts | 2 +- .../templating/NextEditPromptEngine.vitest.ts | 10 +-- 3 files changed, 55 insertions(+), 43 deletions(-) diff --git a/core/llm/autodetect.vitest.ts b/core/llm/autodetect.vitest.ts index 5743a749c..01d48aacc 100644 --- a/core/llm/autodetect.vitest.ts +++ b/core/llm/autodetect.vitest.ts @@ -205,51 +205,55 @@ test("autodetectTemplateType handles models with mixed keywords", () => { describe("modelSupportsNextEdit", () => { describe("when capabilities.nextEdit is defined", () => { it("should return true when capabilities.nextEdit is true", () => { - const result = modelSupportsNextEdit("any-model", "Any Title", { - nextEdit: true, - }); - - expect(result).toBe(true); + expect( + modelSupportsNextEdit( + { + nextEdit: true, + }, + "any-model", + "Any Title", + ), + ).toBe(true); }); it("should return false when capabilities.nextEdit is false", () => { - const result = modelSupportsNextEdit( - "mercury-coder-nextedit", - "Mercury Coder", - { nextEdit: false }, - ); - - expect(result).toBe(false); + expect( + modelSupportsNextEdit( + { nextEdit: false }, + "mercury-coder-nextedit", + "Mercury Coder", + ), + ).toBe(false); }); it("should prioritize capabilities over model name matching", () => { // Even though model name matches, capabilities should take precedence. - const result = modelSupportsNextEdit( - "mercury-coder-nextedit", - "Mercury Coder", - { nextEdit: false }, - ); - - expect(result).toBe(false); + expect( + modelSupportsNextEdit( + { nextEdit: false }, + "mercury-coder-nextedit", + "Mercury Coder", + ), + ).toBe(false); }); }); describe("when capabilities.nextEdit is undefined", () => { it("should return true for mercury-coder-nextedit model (case insensitive)", () => { expect( - modelSupportsNextEdit("Mercury-Coder-Nextedit", undefined, undefined), + modelSupportsNextEdit(undefined, "Mercury-Coder-Nextedit", undefined), ).toBe(true); }); it("should return true for model-1", () => { - expect(modelSupportsNextEdit("model-1", undefined, undefined)).toBe(true); + expect(modelSupportsNextEdit(undefined, "model-1", undefined)).toBe(true); }); it("should return true when model contains supported model name as substring", () => { expect( modelSupportsNextEdit( - "provider/mercury-coder-nextedit-v2", undefined, + "provider/mercury-coder-nextedit-v2", undefined, ), ).toBe(true); @@ -258,67 +262,75 @@ describe("modelSupportsNextEdit", () => { it("should return true when title contains supported model name", () => { expect( modelSupportsNextEdit( + undefined, "some-model", "This is mercury-coder-nextedit model", - undefined, ), ).toBe(true); }); it("should return true when title contains model-1", () => { expect( - modelSupportsNextEdit("some-model", "model-1 deployment", undefined), + modelSupportsNextEdit(undefined, "some-model", "model-1 deployment"), ).toBe(true); }); it("should return true for unsupported models that have capabilities explicitly set to true", () => { expect( - modelSupportsNextEdit("gpt-4", "GPT-4 Model", { - nextEdit: true, - }), + modelSupportsNextEdit( + { + nextEdit: true, + }, + "gpt-4", + "GPT-4 Model", + ), ).toBe(true); }); it("should return false for unsupported models", () => { - expect(modelSupportsNextEdit("gpt-4", "GPT-4 Model", undefined)).toBe( + expect(modelSupportsNextEdit(undefined, "gpt-4", "GPT-4 Model")).toBe( false, ); }); it("should return false when model and title are both undefined/null", () => { - expect(modelSupportsNextEdit("", undefined, undefined)).toBe(false); + expect(modelSupportsNextEdit(undefined, "", undefined)).toBe(false); }); it("should return false when model and title do not contain supported names", () => { expect( - modelSupportsNextEdit("claude-3", "Claude 3 Sonnet", undefined), + modelSupportsNextEdit(undefined, "claude-3", "Claude 3 Sonnet"), ).toBe(false); }); }); describe("edge cases", () => { it("should handle empty strings", () => { - expect(modelSupportsNextEdit("", "", undefined)).toBe(false); + expect(modelSupportsNextEdit(undefined, "", "")).toBe(false); }); it("should handle undefined title gracefully", () => { expect( - modelSupportsNextEdit("mercury-coder-nextedit", undefined, undefined), + modelSupportsNextEdit(undefined, "mercury-coder-nextedit", undefined), ).toBe(true); }); it("should handle case sensitivity correctly", () => { expect( - modelSupportsNextEdit("MERCURY-CODER-NEXTEDIT", "MODEL-1", undefined), + modelSupportsNextEdit(undefined, "MERCURY-CODER-NEXTEDIT", "MODEL-1"), ).toBe(true); }); it("should handle capabilities with other properties", () => { expect( - modelSupportsNextEdit("unsupported-model", undefined, { - nextEdit: true, - uploadImage: false, - }), + modelSupportsNextEdit( + { + nextEdit: true, + uploadImage: false, + }, + "unsupported-model", + undefined, + ), ).toBe(true); }); }); diff --git a/core/nextEdit/NextEditProvider.ts b/core/nextEdit/NextEditProvider.ts index 0b549dfde..ade13b4c3 100644 --- a/core/nextEdit/NextEditProvider.ts +++ b/core/nextEdit/NextEditProvider.ts @@ -345,7 +345,7 @@ export class NextEditProvider { // In vscode, this check is done in extensions/vscode/src/extension/VsCodeExtension.ts. // For other editors, this check should be done in their respective config reloaders. // This is left for a final check. - if (!modelSupportsNextEdit(llm.model, llm.title, llm.capabilities)) { + if (!modelSupportsNextEdit(llm.capabilities, llm.model, llm.title)) { console.error(`${llm.model} is not capable of next edit.`); return { token, startTime, helper: undefined }; } diff --git a/core/nextEdit/templating/NextEditPromptEngine.vitest.ts b/core/nextEdit/templating/NextEditPromptEngine.vitest.ts index a83f19330..785dd79cc 100644 --- a/core/nextEdit/templating/NextEditPromptEngine.vitest.ts +++ b/core/nextEdit/templating/NextEditPromptEngine.vitest.ts @@ -14,11 +14,11 @@ import { MODEL_1_USER_CURSOR_IS_HERE_TOKEN, } from "../constants"; import { - NextEditModelName, renderDefaultSystemPrompt, renderDefaultUserPrompt, renderPrompt, } from "./NextEditPromptEngine"; +import { NEXT_EDIT_MODELS } from "../../llm/constants"; describe("NextEditPromptEngine", () => { describe("renderPrompt", () => { @@ -30,19 +30,19 @@ describe("NextEditPromptEngine", () => { beforeEach(() => { mercuryHelper = { - modelName: "inception/mercury-coder-nextedit" as NextEditModelName, + modelName: "inception/mercury-coder-nextedit" as NEXT_EDIT_MODELS, fileContents: "function test() {\n const a = 1;\n return a;\n}", pos: { line: 1, character: 12 } as Position, lang: { name: "typescript" }, } as HelperVars; model1Helper = { - modelName: "continuedev/model-1" as NextEditModelName, + modelName: "continuedev/model-1" as NEXT_EDIT_MODELS, fileContents: "function test() {\n const a = 1;\n return a;\n}", pos: { line: 1, character: 12 } as Position, lang: { name: "typescript" }, } as HelperVars; unsupportedHelper = { - modelName: "mistral/codestral" as NextEditModelName, + modelName: "mistral/codestral" as NEXT_EDIT_MODELS, fileContents: "function test() {\n const a = 1;\n return a;\n}", pos: { line: 1, character: 12 } as Position, lang: { name: "typescript" }, @@ -193,7 +193,7 @@ describe("NextEditPromptEngine", () => { describe("insertTokens", () => { it("should correctly insert cursor and editable region tokens", () => { const mercuryHelper = { - modelName: "inception/mercury-coder-nextedit" as NextEditModelName, + modelName: "inception/mercury-coder-nextedit" as NEXT_EDIT_MODELS, fileContents: "function test() {\n const a = 1;\n return a;\n}", pos: { line: 1, character: 12 } as Position, lang: { name: "typescript" }, From 6f65295a17e53e7e36b4d3a1fa5f3e451a89a348 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 6 Aug 2025 18:28:00 -0700 Subject: [PATCH 14/14] refactor: move capabilities to the top --- extensions/vscode/src/extension/VsCodeExtension.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index 387faf311..3861edcb7 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -205,9 +205,9 @@ export class VsCodeExtension { if ( (autocompleteModel && modelSupportsNextEdit( + autocompleteModel.capabilities, autocompleteModel.model, autocompleteModel.title, - autocompleteModel.capabilities, )) || isNextEditTest() ) {