Elffuss BraidHub

kikocis/continue public

feat: wrap each recently viewed code snippet inside a token block (#7269)

* feat: wrap each recently viewed code snippet inside a token block

* fix: update vitest

* fix: update test
Changeset625e95c1684134c8df9e59598647e1a4da8e5e3b8415fd386feb8921f780919e
AuthorJacob Kim <jacob@continue.dev> · 2025-08-20 18:00 -07:00
CommitterGitHub <noreply@github.com> · 2025-08-20 21:00 -04:00
Parentsfd844fe861c4

Browse the files at this changeset

3 files changed

modified core/nextEdit/templating/NextEditPromptEngine.vitest.ts +6 −2
@@ -14,6 +14,8 @@
1414 MERCURY_EDIT_DIFF_HISTORY_OPEN,
1515 MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_CLOSE,
1616 MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_OPEN,
17+ MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_CLOSE,
18+ MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_OPEN,
1719 } from "../constants";
1820 import {
1921 renderDefaultSystemPrompt,
@@ -31,7 +33,7 @@
3133
3234 beforeEach(() => {
3335 mercuryHelper = {
34- modelName: "inception/mercury-coder-nextedit" as NEXT_EDIT_MODELS,
36+ modelName: "inception/mercury-coder" as NEXT_EDIT_MODELS,
3537 fileContents: "function test() {\n const a = 1;\n return a;\n}",
3638 pos: { line: 1, character: 12 } as Position,
3739 lang: { name: "typescript" },
@@ -63,7 +65,7 @@
6365 };
6466 });
6567
66- it("should render mercury-coder-nextedit prompt correctly", async () => {
68+ it("should render mercury-coder prompt correctly", async () => {
6769 const result = await renderPrompt(mercuryHelper, ctx);
6870
6971 expect(result).toHaveProperty("prompt");
@@ -72,6 +74,8 @@
7274 const content = result.prompt.content;
7375 expect(content).toContain(MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_OPEN);
7476 expect(content).toContain(MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_CLOSE);
77+ expect(content).toContain(MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_OPEN);
78+ expect(content).toContain(MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_CLOSE);
7579 expect(content).toContain(MERCURY_CURRENT_FILE_CONTENT_OPEN);
7680 expect(content).toContain(MERCURY_CURRENT_FILE_CONTENT_CLOSE);
7781 expect(content).toContain(MERCURY_EDIT_DIFF_HISTORY_OPEN);
modified core/nextEdit/templating/mercuryCoderNextEdit.ts +4 −0
@@ -3,6 +3,8 @@
33 MERCURY_CODE_TO_EDIT_CLOSE,
44 MERCURY_CODE_TO_EDIT_OPEN,
55 MERCURY_CURSOR,
6+ MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_CLOSE,
7+ MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_OPEN,
68 } from "../constants";
79 import { insertCursorToken } from "./utils";
810
@@ -11,8 +13,10 @@
1113 ) {
1214 return recentlyViewedCodeSnippets.reduce((acc, snippet, i) => {
1315 const block = [
16+ MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_OPEN,
1417 `code_snippet_file_path: ${snippet.filepath}`,
1518 snippet.content,
19+ MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_CLOSE,
1620 ].join("\n");
1721
1822 return (
modified core/nextEdit/templating/mercuryCoderNextEdit.vitest.ts +7 −1
@@ -4,6 +4,8 @@
44 MERCURY_CODE_TO_EDIT_CLOSE,
55 MERCURY_CODE_TO_EDIT_OPEN,
66 MERCURY_CURSOR,
7+ MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_CLOSE,
8+ MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_OPEN,
79 } from "../constants";
810 import {
911 currentFileContentBlock,
@@ -25,10 +27,14 @@
2527 const result = recentlyViewedCodeSnippetsBlock(snippets);
2628
2729 const expected =
30+ `${MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_OPEN}\n` +
2831 "code_snippet_file_path: /path/to/file1.ts\n" +
2932 "const a = 1;\n" +
33+ `${MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_CLOSE}\n` +
34+ `${MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_OPEN}\n` +
3035 "code_snippet_file_path: /path/to/file2.ts\n" +
31- "function test() { return true; }";
36+ "function test() { return true; }\n" +
37+ MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_CLOSE;
3238
3339 expect(result).toBe(expected);
3440 });