Changesets · Branches · Tags · Compare
| Changeset | 772a6be82c3a6062a5dccbf74cfe3bf41a6dcf1990071c7a9560b55a4e4651fe |
|---|---|
| Author | adarshramiyer <adarsh.r.iyer@gmail.com> · 2025-07-03 17:05 -07:00 |
| Committer | adarshramiyer <adarsh.r.iyer@gmail.com> · 2025-07-03 17:05 -07:00 |
| Parents | b2cd4c5fbf76 |
3 files changed
modified core/core.ts +2 −2
| @@ -722,8 +722,8 @@ | ||
| 722 | 722 | const EDIT_AGGREGATION_OPTIONS = { |
| 723 | 723 | deltaT: 1.0, |
| 724 | 724 | deltaL: 5, |
| 725 | - maxEdits: 250, | |
| 726 | - maxDuration: 100.0, | |
| 725 | + maxEdits: 500, | |
| 726 | + maxDuration: 120.0, | |
| 727 | 727 | contextSize: 5, |
| 728 | 728 | }; |
| 729 | 729 |
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 @@ | ||
| 5 | 5 | import { DataLogger } from "../../data/log"; |
| 6 | 6 | import { RecentlyEditedRange } from "../types"; |
| 7 | 7 | import { getAutocompleteContext } from "./autocompleteContextFetching"; |
| 8 | +import { createDiff, DiffFormatType } from "./diffFormatting"; | |
| 9 | +import { | |
| 10 | + getPrevEditsDescending, | |
| 11 | + prevEdit, | |
| 12 | + prevEditLruCache, | |
| 13 | + setPrevEdit, | |
| 14 | +} from "./prevEditLruCache"; | |
| 8 | 15 | |
| 9 | 16 | const randomNumberBetween = (min: number, max: number) => { |
| 10 | 17 | min = Math.ceil(min); // Ensure min is an integer |
| @@ -27,6 +34,11 @@ | ||
| 27 | 34 | modelNameOrInstance?: string | undefined; |
| 28 | 35 | } |
| 29 | 36 | |
| 37 | +interface filenameAndDiff { | |
| 38 | + filename: string; | |
| 39 | + diff: string; | |
| 40 | +} | |
| 41 | + | |
| 30 | 42 | export const processNextEditData = async ({ |
| 31 | 43 | filePath, |
| 32 | 44 | beforeContent, |
| @@ -48,7 +60,6 @@ | ||
| 48 | 60 | // undefined; |
| 49 | 61 | |
| 50 | 62 | const modelName = "Codestral"; |
| 51 | - | |
| 52 | 63 | const maxPromptTokens = randomNumberBetween(500, 12000); |
| 53 | 64 | |
| 54 | 65 | const autocompleteContext = await getAutocompleteContext( |
| @@ -68,9 +79,39 @@ | ||
| 68 | 79 | // createDiff(beforeContent, afterContent, filePath, DiffFormatType.Unified), |
| 69 | 80 | // ); |
| 70 | 81 | |
| 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 | + | |
| 71 | 111 | void DataLogger.getInstance().logDevData({ |
| 72 | - name: "nextEdit", | |
| 112 | + name: "nextEditWithHistory", | |
| 73 | 113 | data: { |
| 114 | + previousEdits: filenamesAndDiffs, | |
| 74 | 115 | fileURI: filePath, |
| 75 | 116 | workspaceDirURI: workspaceDir, |
| 76 | 117 | beforeContent, |
| @@ -80,4 +121,19 @@ | ||
| 80 | 121 | context: autocompleteContext, |
| 81 | 122 | }, |
| 82 | 123 | }); |
| 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); | |
| 83 | 139 | }; |