From 10d4d4cda0c252a36bac96178593d13b1ea6f2d6 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Mon, 11 Aug 2025 17:45:27 -0700 Subject: [PATCH] fix: editedCodeWithTokens uses the processed context block --- .../templating/NextEditPromptEngine.ts | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/core/nextEdit/templating/NextEditPromptEngine.ts b/core/nextEdit/templating/NextEditPromptEngine.ts index 326ac4d84..98e23e45b 100644 --- a/core/nextEdit/templating/NextEditPromptEngine.ts +++ b/core/nextEdit/templating/NextEditPromptEngine.ts @@ -4,35 +4,33 @@ import { SnippetPayload } from "../../autocomplete/snippets"; import { HelperVars } from "../../autocomplete/util/HelperVars"; import { NEXT_EDIT_MODELS } from "../../llm/constants"; import { + INSTINCT_USER_PROMPT_PREFIX, MERCURY_CURRENT_FILE_CONTENT_CLOSE, MERCURY_CURRENT_FILE_CONTENT_OPEN, - MERCURY_CURSOR, MERCURY_EDIT_DIFF_HISTORY_CLOSE, MERCURY_EDIT_DIFF_HISTORY_OPEN, MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_CLOSE, MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_OPEN, - MODEL_1_USER_CURSOR_IS_HERE_TOKEN, - MODEL_1_USER_PROMPT_PREFIX, } from "../constants"; import { + InstinctTemplateVars, MercuryTemplateVars, - Model1TemplateVars, NextEditTemplate, PromptMetadata, SystemPrompt, TemplateVars, UserPrompt, } from "../types"; +import { + contextSnippetsBlock, + currentFileContentBlock as instinctCurrentFileContentBlock, + editHistoryBlock as instinctEditHistoryBlock, +} from "./instinct"; import { currentFileContentBlock, editHistoryBlock, recentlyViewedCodeSnippetsBlock, } from "./mercuryCoderNextEdit"; -import { - contextSnippetsBlock, - currentFileContentBlock as model1CurrentFileContentBlock, - editHistoryBlock as model1EditHistoryBlock, -} from "./model1"; import { insertCursorToken, insertEditableRegionTokensWithStaticRange, @@ -44,8 +42,8 @@ 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.`, }, - "model-1": { - template: `${MODEL_1_USER_PROMPT_PREFIX}\n\n### Context:\n{{{contextSnippets}}}\n\n### User Edits:\n\n{{{editDiffHistory}}}\n\n### User Excerpts:\n\n\`\`\`{{{languageShorthand}}}\n{{{currentFileContent}}}\`\`\`\n### Response:`, + instinct: { + template: `${INSTINCT_USER_PROMPT_PREFIX}\n\n### Context:\n{{{contextSnippets}}}\n\n### User Edits:\n\n{{{editDiffHistory}}}\n\n### User Excerpts:\n{{{currentFilePath}}}\n\n{{{currentFileContent}}}\`\`\`\n### Response:`, }, }; @@ -95,11 +93,11 @@ export async function renderPrompt( case "mercury-coder-nextedit": { userEdits = ctx.editDiffHistory; - editedCodeWithTokens = insertTokens( - helper.fileContents.split("\n"), - helper.pos, - MERCURY_CURSOR, - ); + // editedCodeWithTokens = insertTokens( + // helper.fileContents.split("\n"), + // helper.pos, + // MERCURY_CURSOR, + // ); const mercuryCtx: MercuryTemplateVars = { recentlyViewedCodeSnippets: recentlyViewedCodeSnippetsBlock( @@ -117,20 +115,22 @@ export async function renderPrompt( tv = mercuryCtx; + editedCodeWithTokens = mercuryCtx.currentFileContent; + break; } - case "model-1": { + case "instinct": { userEdits = ctx.editDiffHistory; - editedCodeWithTokens = insertTokens( - helper.fileContents.split("\n"), - helper.pos, - MODEL_1_USER_CURSOR_IS_HERE_TOKEN, - ); + // editedCodeWithTokens = insertTokens( + // helper.fileContents.split("\n"), + // helper.pos, + // INSTINCT_USER_CURSOR_IS_HERE_TOKEN, + // ); - const model1Ctx: Model1TemplateVars = { + const instinctCtx: InstinctTemplateVars = { contextSnippets: contextSnippetsBlock(ctx.contextSnippets), - currentFileContent: model1CurrentFileContentBlock( + currentFileContent: instinctCurrentFileContentBlock( ctx.currentFileContent, ctx.windowStart, ctx.windowEnd, @@ -138,12 +138,14 @@ export async function renderPrompt( ctx.editableRegionEndLine, helper.pos, ), - editDiffHistory: model1EditHistoryBlock(ctx.editDiffHistory), + editDiffHistory: instinctEditHistoryBlock(ctx.editDiffHistory), currentFilePath: ctx.currentFilePath, languageShorthand: ctx.languageShorthand, }; - tv = model1Ctx; + tv = instinctCtx; + + editedCodeWithTokens = instinctCtx.currentFileContent; break; }