Changesets · Branches · Tags · Compare
| Changeset | b14bcabca13278cf42ca75aae64a745bcb3f7607b5337fa055ca919835f25293 |
|---|---|
| Author | Nate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-07-03 18:38 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-07-03 18:38 -07:00 |
| Parents | 1b82fee9b1de, 5aed8ce6ba7e |
8 files changed
modified core/core.ts +2 −2
| @@ -721,8 +721,8 @@ | ||
| 721 | 721 | const EDIT_AGGREGATION_OPTIONS = { |
| 722 | 722 | deltaT: 1.0, |
| 723 | 723 | deltaL: 5, |
| 724 | - maxEdits: 250, | |
| 725 | - maxDuration: 100.0, | |
| 724 | + maxEdits: 500, | |
| 725 | + maxDuration: 120.0, | |
| 726 | 726 | contextSize: 5, |
| 727 | 727 | }; |
| 728 | 728 |
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 @@ | ||
| 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,16 +79,64 @@ | ||
| 68 | 79 | // createDiff(beforeContent, afterContent, filePath, DiffFormatType.Unified), |
| 69 | 80 | // ); |
| 70 | 81 | |
| 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( | |
| 76 | 131 | beforeContent, |
| 77 | 132 | 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); | |
| 83 | 142 | }; |
modified packages/config-yaml/src/schemas/data/index.ts +5 −5
| @@ -33,11 +33,11 @@ | ||
| 33 | 33 | editOutcomeEventSchema_0_2_0, |
| 34 | 34 | editOutcomeEventSchema_0_2_0_noCode, |
| 35 | 35 | } from "./editOutcome/v0.2.0.js"; |
| 36 | -import { nextEditEventAllSchema } from "./nextEdit/index.js"; | |
| 36 | +import { nextEditEventAllSchema } from "./nextEditWithHistory/index.js"; | |
| 37 | 37 | import { |
| 38 | 38 | nextEditEventSchema_0_2_0, |
| 39 | 39 | nextEditEventSchema_0_2_0_noCode, |
| 40 | -} from "./nextEdit/v0.2.0.js"; | |
| 40 | +} from "./nextEditWithHistory/v0.2.0.js"; | |
| 41 | 41 | import { quickEditEventAllSchema } from "./quickEdit/index.js"; |
| 42 | 42 | import { |
| 43 | 43 | quickEditEventSchema_0_1_0, |
| @@ -88,7 +88,7 @@ | ||
| 88 | 88 | chatInteraction: chatInteractionEventAllSchema, |
| 89 | 89 | editInteraction: editInteractionEventAllSchema, |
| 90 | 90 | editOutcome: editOutcomeEventAllSchema, |
| 91 | - nextEdit: nextEditEventAllSchema, | |
| 91 | + nextEditWithHistory: nextEditEventAllSchema, | |
| 92 | 92 | toolUsage: toolUsageEventAllSchema, |
| 93 | 93 | }); |
| 94 | 94 | |
| @@ -116,7 +116,7 @@ | ||
| 116 | 116 | chatInteraction: chatInteractionEventSchema_0_2_0, |
| 117 | 117 | editInteraction: editInteractionEventSchema_0_2_0, |
| 118 | 118 | editOutcome: editOutcomeEventSchema_0_2_0, |
| 119 | - nextEdit: nextEditEventSchema_0_2_0, | |
| 119 | + nextEditWithHistory: nextEditEventSchema_0_2_0, | |
| 120 | 120 | toolUsage: toolUsageEventSchema_0_2_0, |
| 121 | 121 | }, |
| 122 | 122 | noCode: { |
| @@ -126,7 +126,7 @@ | ||
| 126 | 126 | chatInteraction: chatInteractionEventSchema_0_2_0_noCode, |
| 127 | 127 | editInteraction: editInteractionEventSchema_0_2_0_noCode, |
| 128 | 128 | editOutcome: editOutcomeEventSchema_0_2_0_noCode, |
| 129 | - nextEdit: nextEditEventSchema_0_2_0_noCode, | |
| 129 | + nextEditWithHistory: nextEditEventSchema_0_2_0_noCode, | |
| 130 | 130 | toolUsage: toolUsageEventSchema_0_2_0_noCode, |
| 131 | 131 | }, |
| 132 | 132 | }, |
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 | +}); |