Elffuss BraidHub

kikocis/continue public

Merge pull request #6442 from continuedev/adarsh/feat/seq-in-nexteditdata

Add edit history sequences to nextEdit dev data for easier processing
Changesetb14bcabca13278cf42ca75aae64a745bcb3f7607b5337fa055ca919835f25293
AuthorNate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-07-03 18:38 -07:00
CommitterGitHub <noreply@github.com> · 2025-07-03 18:38 -07:00
Parents1b82fee9b1de, 5aed8ce6ba7e

Browse the files at this changeset

8 files changed

modified core/core.ts +2 −2
@@ -721,8 +721,8 @@
721721 const EDIT_AGGREGATION_OPTIONS = {
722722 deltaT: 1.0,
723723 deltaL: 5,
724- maxEdits: 250,
725- maxDuration: 100.0,
724+ maxEdits: 500,
725+ maxDuration: 120.0,
726726 contextSize: 5,
727727 };
728728
added core/nextEdit/context/prevEditLruCache.ts +30 −0
@@ -0,0 +1,30 @@
1+import QuickLRU from "quick-lru";
2+
3+export interface prevEdit {
4+ unidiff: string;
5+ fileUri: string;
6+ workspaceUri: string;
7+ timestamp: number;
8+}
9+const maxPrevEdits = 5;
10+
11+export const prevEditLruCache = new QuickLRU<string, prevEdit>({
12+ maxSize: maxPrevEdits,
13+});
14+
15+export const setPrevEdit = (edit: prevEdit): void => {
16+ const uniqueSuffix = Math.random().toString(36).substring(2, 8);
17+ const key = `${edit.fileUri}:${edit.timestamp}:${uniqueSuffix}`;
18+ prevEditLruCache.set(key, edit);
19+};
20+
21+export const getPrevEditsDescending = (): prevEdit[] => {
22+ const edits: prevEdit[] = [];
23+ for (const [_, edit] of prevEditLruCache.entriesDescending()) {
24+ if (edits.length >= maxPrevEdits) {
25+ break;
26+ }
27+ edits.push(edit);
28+ }
29+ return edits;
30+};
modified core/nextEdit/context/processNextEditData.ts +70 −11
@@ -5,6 +5,13 @@
55 import { DataLogger } from "../../data/log";
66 import { RecentlyEditedRange } from "../types";
77 import { getAutocompleteContext } from "./autocompleteContextFetching";
8+import { createDiff, DiffFormatType } from "./diffFormatting";
9+import {
10+ getPrevEditsDescending,
11+ prevEdit,
12+ prevEditLruCache,
13+ setPrevEdit,
14+} from "./prevEditLruCache";
815
916 const randomNumberBetween = (min: number, max: number) => {
1017 min = Math.ceil(min); // Ensure min is an integer
@@ -27,6 +34,11 @@
2734 modelNameOrInstance?: string | undefined;
2835 }
2936
37+interface filenameAndDiff {
38+ filename: string;
39+ diff: string;
40+}
41+
3042 export const processNextEditData = async ({
3143 filePath,
3244 beforeContent,
@@ -48,7 +60,6 @@
4860 // undefined;
4961
5062 const modelName = "Codestral";
51-
5263 const maxPromptTokens = randomNumberBetween(500, 12000);
5364
5465 const autocompleteContext = await getAutocompleteContext(
@@ -68,16 +79,64 @@
6879 // createDiff(beforeContent, afterContent, filePath, DiffFormatType.Unified),
6980 // );
7081
71- void DataLogger.getInstance().logDevData({
72- name: "nextEdit",
73- data: {
74- fileURI: filePath,
75- workspaceDirURI: workspaceDir,
82+ let filenamesAndDiffs: filenameAndDiff[] = [];
83+
84+ const timestamp = Date.now();
85+ let prevEdits: prevEdit[] = getPrevEditsDescending(); // edits from most to least recent
86+ if (prevEdits.length > 0) {
87+ // if last edit was 10+ minutes ago or the workspace changed, forget previous edits
88+ if (
89+ timestamp - prevEdits[0].timestamp >= 1000 * 60 * 10 ||
90+ workspaceDir !== prevEdits[0].workspaceUri
91+ ) {
92+ prevEditLruCache.clear();
93+ prevEdits = [];
94+ }
95+
96+ // extract filenames and diffs for logging
97+ filenamesAndDiffs = prevEdits.map(
98+ (edit) =>
99+ ({
100+ // filename relative to workspace dir
101+ filename: edit.fileUri
102+ .replace(edit.workspaceUri, "")
103+ .replace(/^[/\\]/, ""),
104+
105+ // diff without the first 4 lines (the file header)
106+ diff: edit.unidiff.split("\n").slice(4).join("\n"),
107+ }) as filenameAndDiff,
108+ );
109+ }
110+
111+ if (filenamesAndDiffs.length > 0) {
112+ // if there are previous edits, log
113+ void DataLogger.getInstance().logDevData({
114+ name: "nextEditWithHistory",
115+ data: {
116+ previousEdits: filenamesAndDiffs,
117+ fileURI: filePath,
118+ workspaceDirURI: workspaceDir,
119+ beforeContent,
120+ afterContent,
121+ beforeCursorPos: cursorPosBeforeEdit,
122+ afterCursorPos: cursorPosAfterPrevEdit,
123+ context: autocompleteContext,
124+ },
125+ });
126+ }
127+
128+ // add current edit to history
129+ const thisEdit: prevEdit = {
130+ unidiff: createDiff(
76131 beforeContent,
77132 afterContent,
78- beforeCursorPos: cursorPosBeforeEdit,
79- afterCursorPos: cursorPosAfterPrevEdit,
80- context: autocompleteContext,
81- },
82- });
133+ filePath,
134+ DiffFormatType.Unified,
135+ ),
136+ fileUri: filePath,
137+ workspaceUri: workspaceDir,
138+ timestamp: timestamp,
139+ };
140+
141+ setPrevEdit(thisEdit);
83142 };
modified packages/config-yaml/src/schemas/data/index.ts +5 −5
@@ -33,11 +33,11 @@
3333 editOutcomeEventSchema_0_2_0,
3434 editOutcomeEventSchema_0_2_0_noCode,
3535 } from "./editOutcome/v0.2.0.js";
36-import { nextEditEventAllSchema } from "./nextEdit/index.js";
36+import { nextEditEventAllSchema } from "./nextEditWithHistory/index.js";
3737 import {
3838 nextEditEventSchema_0_2_0,
3939 nextEditEventSchema_0_2_0_noCode,
40-} from "./nextEdit/v0.2.0.js";
40+} from "./nextEditWithHistory/v0.2.0.js";
4141 import { quickEditEventAllSchema } from "./quickEdit/index.js";
4242 import {
4343 quickEditEventSchema_0_1_0,
@@ -88,7 +88,7 @@
8888 chatInteraction: chatInteractionEventAllSchema,
8989 editInteraction: editInteractionEventAllSchema,
9090 editOutcome: editOutcomeEventAllSchema,
91- nextEdit: nextEditEventAllSchema,
91+ nextEditWithHistory: nextEditEventAllSchema,
9292 toolUsage: toolUsageEventAllSchema,
9393 });
9494
@@ -116,7 +116,7 @@
116116 chatInteraction: chatInteractionEventSchema_0_2_0,
117117 editInteraction: editInteractionEventSchema_0_2_0,
118118 editOutcome: editOutcomeEventSchema_0_2_0,
119- nextEdit: nextEditEventSchema_0_2_0,
119+ nextEditWithHistory: nextEditEventSchema_0_2_0,
120120 toolUsage: toolUsageEventSchema_0_2_0,
121121 },
122122 noCode: {
@@ -126,7 +126,7 @@
126126 chatInteraction: chatInteractionEventSchema_0_2_0_noCode,
127127 editInteraction: editInteractionEventSchema_0_2_0_noCode,
128128 editOutcome: editOutcomeEventSchema_0_2_0_noCode,
129- nextEdit: nextEditEventSchema_0_2_0_noCode,
129+ nextEditWithHistory: nextEditEventSchema_0_2_0_noCode,
130130 toolUsage: toolUsageEventSchema_0_2_0_noCode,
131131 },
132132 },
deleted packages/config-yaml/src/schemas/data/nextEdit/index.ts +0 −12
@@ -1,12 +0,0 @@
1-import { z } from "zod";
2-import { baseDevDataAllSchema } from "../base.js";
3-
4-export const nextEditEventAllSchema = baseDevDataAllSchema.extend({
5- fileURI: z.string(),
6- workspaceDirURI: z.string(),
7- beforeContent: z.string(),
8- afterContent: z.string(),
9- beforeCursorPos: z.object({ line: z.number(), character: z.number() }),
10- afterCursorPos: z.object({ line: z.number(), character: z.number() }),
11- context: z.string(),
12-});
deleted packages/config-yaml/src/schemas/data/nextEdit/v0.2.0.ts +0 −28
@@ -1,28 +0,0 @@
1-import { nextEditEventAllSchema } from "./index.js";
2-
3-export const nextEditEventSchema_0_2_0 = nextEditEventAllSchema.pick({
4- // base
5- timestamp: true,
6- userId: true,
7- userAgent: true,
8- selectedProfileId: true,
9- eventName: true,
10- schema: true,
11-
12- // nextedit-specific
13- fileURI: true,
14- workspaceDirURI: true,
15- beforeContent: true,
16- afterContent: true,
17- beforeCursorPos: true,
18- afterCursorPos: true,
19- context: true,
20-});
21-
22-export const nextEditEventSchema_0_2_0_noCode = nextEditEventSchema_0_2_0.omit({
23- fileURI: true,
24- workspaceDirURI: true,
25- beforeContent: true,
26- afterContent: true,
27- context: true,
28-});
added packages/config-yaml/src/schemas/data/nextEditWithHistory/index.ts +18 −0
@@ -0,0 +1,18 @@
1+import { z } from "zod";
2+import { baseDevDataAllSchema } from "../base.js";
3+
4+export const nextEditEventAllSchema = baseDevDataAllSchema.extend({
5+ previousEdits: z.array(
6+ z.object({
7+ filename: z.string(),
8+ diff: z.string(),
9+ }),
10+ ),
11+ fileURI: z.string(),
12+ workspaceDirURI: z.string(),
13+ beforeContent: z.string(),
14+ afterContent: z.string(),
15+ beforeCursorPos: z.object({ line: z.number(), character: z.number() }),
16+ afterCursorPos: z.object({ line: z.number(), character: z.number() }),
17+ context: z.string(),
18+});
added packages/config-yaml/src/schemas/data/nextEditWithHistory/v0.2.0.ts +30 −0
@@ -0,0 +1,30 @@
1+import { nextEditEventAllSchema } from "./index.js";
2+
3+export const nextEditEventSchema_0_2_0 = nextEditEventAllSchema.pick({
4+ // base
5+ timestamp: true,
6+ userId: true,
7+ userAgent: true,
8+ selectedProfileId: true,
9+ eventName: true,
10+ schema: true,
11+
12+ // nextedit-specific
13+ previousEdits: true,
14+ fileURI: true,
15+ workspaceDirURI: true,
16+ beforeContent: true,
17+ afterContent: true,
18+ beforeCursorPos: true,
19+ afterCursorPos: true,
20+ context: true,
21+});
22+
23+export const nextEditEventSchema_0_2_0_noCode = nextEditEventSchema_0_2_0.omit({
24+ previousEdits: true,
25+ fileURI: true,
26+ workspaceDirURI: true,
27+ beforeContent: true,
28+ afterContent: true,
29+ context: true,
30+});