Elffuss BraidHub

kikocis/continue public

made pipeline w/ LRU cache for recent edit sequences
Changeset772a6be82c3a6062a5dccbf74cfe3bf41a6dcf1990071c7a9560b55a4e4651fe
Authoradarshramiyer <adarsh.r.iyer@gmail.com> · 2025-07-03 17:05 -07:00
Committeradarshramiyer <adarsh.r.iyer@gmail.com> · 2025-07-03 17:05 -07:00
Parentsb2cd4c5fbf76

Browse the files at this changeset

3 files changed

modified core/core.ts +2 −2
@@ -722,8 +722,8 @@
722722 const EDIT_AGGREGATION_OPTIONS = {
723723 deltaT: 1.0,
724724 deltaL: 5,
725- maxEdits: 250,
726- maxDuration: 100.0,
725+ maxEdits: 500,
726+ maxDuration: 120.0,
727727 contextSize: 5,
728728 };
729729
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 +58 −2
@@ -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,9 +79,39 @@
6879 // createDiff(beforeContent, afterContent, filePath, DiffFormatType.Unified),
6980 // );
7081
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+
71111 void DataLogger.getInstance().logDevData({
72- name: "nextEdit",
112+ name: "nextEditWithHistory",
73113 data: {
114+ previousEdits: filenamesAndDiffs,
74115 fileURI: filePath,
75116 workspaceDirURI: workspaceDir,
76117 beforeContent,
@@ -80,4 +121,19 @@
80121 context: autocompleteContext,
81122 },
82123 });
124+
125+ // add current edit to history
126+ const thisEdit: prevEdit = {
127+ unidiff: createDiff(
128+ beforeContent,
129+ afterContent,
130+ filePath,
131+ DiffFormatType.Unified,
132+ ),
133+ fileUri: filePath,
134+ workspaceUri: workspaceDir,
135+ timestamp: timestamp,
136+ };
137+
138+ setPrevEdit(thisEdit);
83139 };