add current file path to prompt

This commit is contained in:
Kenan Hasanaliyev
2025-12-04 12:37:53 -08:00
parent a2e01a31a4
commit 881d3a6986
3 changed files with 6 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
import { HelperVars } from "../../autocomplete/util/HelperVars.js";
import { NEXT_EDIT_MODELS } from "../../llm/constants.js";
import { getUriPathBasename } from "../../util/uri.js";
import { MERCURY_SYSTEM_PROMPT, UNIQUE_TOKEN } from "../constants.js";
import {
currentFileContentBlock,
@@ -58,7 +59,7 @@ export class MercuryCoderProvider extends BaseNextEditModelProvider {
editableRegionStartLine: context.editableRegionStartLine,
editableRegionEndLine: context.editableRegionEndLine,
editDiffHistory: context.diffContext,
currentFilePath: context.helper.filepath,
currentFilePath: getUriPathBasename(context.helper.filepath),
};
}

View File

@@ -17,7 +17,7 @@ export const NEXT_EDIT_MODEL_TEMPLATES: Record<
NextEditTemplate
> = {
"mercury-coder": {
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`,
template: `${MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_OPEN}\n{{{recentlyViewedCodeSnippets}}}\n${MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_CLOSE}\n\n${MERCURY_CURRENT_FILE_CONTENT_OPEN}\ncurrent_file_path: {{{currentFilePath}}}\n{{{currentFileContent}}}\n${MERCURY_CURRENT_FILE_CONTENT_CLOSE}\n\n${MERCURY_EDIT_DIFF_HISTORY_OPEN}\n{{{editDiffHistory}}}\n${MERCURY_EDIT_DIFF_HISTORY_CLOSE}\n`,
},
instinct: {
template: `${INSTINCT_USER_PROMPT_PREFIX}\n\n### Context:\n{{{contextSnippets}}}\n\n### User Edits:\n\n{{{editDiffHistory}}}\n\n### User Excerpt:\n{{{currentFilePath}}}\n\n{{{currentFileContent}}}\`\`\`\n### Response:`,

View File

@@ -39,6 +39,7 @@ describe("NextEditPromptEngine", () => {
expect(template).toContain("{{{recentlyViewedCodeSnippets}}}");
expect(template).toContain("{{{currentFileContent}}}");
expect(template).toContain("{{{editDiffHistory}}}");
expect(template).toContain("{{{currentFilePath}}}");
});
it("instinct template should contain expected tokens", () => {
@@ -87,11 +88,13 @@ describe("NextEditPromptEngine", () => {
recentlyViewedCodeSnippets: "snippet1",
currentFileContent: "file content",
editDiffHistory: "diff history",
currentFilePath: "file.py",
});
expect(result).toContain("snippet1");
expect(result).toContain("file content");
expect(result).toContain("diff history");
expect(result).toContain("current_file_path: file.py");
});
});