dev data schemas, edit logging refinement
This commit is contained in:
parent
4f60c50914
commit
ef53d113be
9 changed files with 121 additions and 28 deletions
|
|
@ -726,17 +726,22 @@ export class Core {
|
|||
currentData.getDefsFromLspFunction,
|
||||
currentData.recentlyEditedRanges,
|
||||
currentData.recentlyVisitedRanges,
|
||||
currentData.workspaceDir,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const workspaceDir =
|
||||
data.actions.length > 0 ? data.actions[0].workspaceDir : undefined;
|
||||
|
||||
// Store the latest context data on the aggregator
|
||||
(global._editAggregator as any).latestContextData = {
|
||||
configHandler: data.configHandler,
|
||||
getDefsFromLspFunction: data.getDefsFromLspFunction,
|
||||
recentlyEditedRanges: data.recentlyEditedRanges,
|
||||
recentlyVisitedRanges: data.recentlyVisitedRanges,
|
||||
workspaceDir: workspaceDir,
|
||||
};
|
||||
|
||||
// queueMicrotask prevents blocking the UI thread during typing
|
||||
|
|
|
|||
1
core/index.d.ts
vendored
1
core/index.d.ts
vendored
|
|
@ -1307,6 +1307,7 @@ export interface RangeInFileWithNextEditInfo {
|
|||
editText: string;
|
||||
afterCursorPos: Position;
|
||||
beforeCursorPos: Position;
|
||||
workspaceDir: string;
|
||||
}
|
||||
|
||||
export type SetCodeToEditPayload = RangeInFileWithContents | FileWithContents;
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ export class EditAggregator {
|
|||
|
||||
const clustersToFinalize = this.identifyClustersToFinalize(
|
||||
fileState,
|
||||
editLine,
|
||||
edit,
|
||||
timestamp,
|
||||
false,
|
||||
);
|
||||
|
|
@ -360,29 +360,39 @@ export class EditAggregator {
|
|||
|
||||
private identifyClustersToFinalize(
|
||||
fileState: FileState,
|
||||
editLine: number,
|
||||
edit: RangeInFileWithNextEditInfo,
|
||||
timestamp: number,
|
||||
isStructuralEdit: boolean,
|
||||
): ClusterState[] {
|
||||
const clustersToFinalize: ClusterState[] = [];
|
||||
const editLine = edit.range.start.line;
|
||||
|
||||
fileState.activeClusters.forEach((cluster) => {
|
||||
const timeSinceLastEdit = (timestamp - cluster.lastTimestamp) / 1000;
|
||||
|
||||
// Only consider the line changed if it's a DIFFERENT line
|
||||
const isOnDifferentLine = cluster.lastLine !== editLine;
|
||||
const isOnDifferentLineByNumber = cluster.lastLine !== editLine;
|
||||
|
||||
// Finalize if we moved to a different line AND the time gap exceeds deltaT
|
||||
const isOnDifferentLineByNewline = edit.editText.includes("\n");
|
||||
|
||||
// Use different time thresholds for different types of line change detection
|
||||
const shouldFinalizeByLineNumber =
|
||||
isOnDifferentLineByNumber && timeSinceLastEdit > this.config.deltaT;
|
||||
|
||||
const shouldFinalizeByNewline =
|
||||
isOnDifferentLineByNewline &&
|
||||
timeSinceLastEdit > this.config.deltaT * 1.5;
|
||||
|
||||
// Finalize if we moved to a different line AND the time gap exceeds the respective threshold
|
||||
const shouldFinalizeByTime =
|
||||
isOnDifferentLine && timeSinceLastEdit > this.config.deltaT;
|
||||
|
||||
shouldFinalizeByLineNumber || shouldFinalizeByNewline;
|
||||
const shouldFinalizeByCount =
|
||||
cluster.edits.length >= this.config.maxEdits;
|
||||
|
||||
const shouldFinalizeByDuration =
|
||||
(timestamp - cluster.firstTimestamp) / 1000 > this.config.maxDuration;
|
||||
|
||||
// Structural edits should only finalize other clusters, not their own
|
||||
// For structural edits, use the combined line detection
|
||||
const isOnDifferentLine =
|
||||
isOnDifferentLineByNumber || isOnDifferentLineByNewline;
|
||||
const shouldFinalizeByStructuralEdit =
|
||||
isStructuralEdit && isOnDifferentLine;
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ export const getAutocompleteContext = async (
|
|||
manuallyPassFileContents,
|
||||
};
|
||||
|
||||
// Load config to get autocomplete options
|
||||
const { config } = await configHandler.loadConfig();
|
||||
if (!config) {
|
||||
throw new Error("No config available");
|
||||
|
|
@ -64,20 +63,31 @@ export const getAutocompleteContext = async (
|
|||
|
||||
// Use provided autocomplete model or fall back to configured autocomplete model
|
||||
let finalModel: ILLM;
|
||||
let modelNameForTemplating: string;
|
||||
|
||||
if (autocompleteModel) {
|
||||
if (typeof autocompleteModel === "string") {
|
||||
// If model name is provided as string, find it in the config
|
||||
// Try to find the model in config first
|
||||
const foundModel = config.modelsByRole.autocomplete.find(
|
||||
(m) => m.title === autocompleteModel,
|
||||
);
|
||||
if (!foundModel) {
|
||||
throw new Error(
|
||||
`Autocomplete model with title "${autocompleteModel}" not found`,
|
||||
);
|
||||
if (foundModel) {
|
||||
finalModel = foundModel;
|
||||
modelNameForTemplating = foundModel.model;
|
||||
} else {
|
||||
// Model not found in config, but we can still use it for template selection
|
||||
const configuredModel = config.selectedModelByRole.autocomplete;
|
||||
if (!configuredModel) {
|
||||
throw new Error(
|
||||
"No autocomplete model configured and provided model not found in config",
|
||||
);
|
||||
}
|
||||
finalModel = configuredModel;
|
||||
modelNameForTemplating = autocompleteModel; // Use the provided string for template selection
|
||||
}
|
||||
finalModel = foundModel;
|
||||
} else {
|
||||
finalModel = autocompleteModel;
|
||||
modelNameForTemplating = autocompleteModel.model;
|
||||
}
|
||||
} else {
|
||||
const configuredModel = config.selectedModelByRole.autocomplete;
|
||||
|
|
@ -85,27 +95,29 @@ export const getAutocompleteContext = async (
|
|||
throw new Error("No autocomplete model configured and no model provided");
|
||||
}
|
||||
finalModel = configuredModel;
|
||||
modelNameForTemplating = configuredModel.model;
|
||||
}
|
||||
|
||||
// Build options exactly like CompletionProvider does
|
||||
const options = {
|
||||
...DEFAULT_AUTOCOMPLETE_OPTS,
|
||||
...config.tabAutocompleteOptions,
|
||||
...finalModel.autocompleteOptions,
|
||||
// Allow maxPromptTokens override if provided
|
||||
...(maxPromptTokens && { maxPromptTokens }),
|
||||
};
|
||||
|
||||
// Handle template from model like CompletionProvider does
|
||||
if (finalModel.promptTemplates?.autocomplete) {
|
||||
options.template = finalModel.promptTemplates.autocomplete as string;
|
||||
}
|
||||
|
||||
const helper = await HelperVars.create(input, options, finalModel.model, ide);
|
||||
const helper = await HelperVars.create(
|
||||
input,
|
||||
options,
|
||||
modelNameForTemplating,
|
||||
ide,
|
||||
);
|
||||
|
||||
const contextRetrievalService = new ContextRetrievalService(ide);
|
||||
|
||||
// CRITICAL: Initialize the import definitions cache for this file
|
||||
// This is normally done when the active text editor changes, but we need to do it manually
|
||||
await contextRetrievalService.initializeForFile(filepath);
|
||||
|
||||
const [snippetPayload, workspaceDirs] = await Promise.all([
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ import { IDE, Position } from "../..";
|
|||
import { AutocompleteCodeSnippet } from "../../autocomplete/snippets/types";
|
||||
import { GetLspDefinitionsFunction } from "../../autocomplete/types";
|
||||
import { ConfigHandler } from "../../config/ConfigHandler";
|
||||
import { DataLogger } from "../../data/log";
|
||||
import { RecentlyEditedRange } from "../types";
|
||||
import { getAutocompleteContext } from "./autocompleteContextFetching";
|
||||
import { createDiff, DiffFormatType } from "./diffFormatting";
|
||||
|
||||
const randomNumberBetween = (min: number, max: number) => {
|
||||
min = Math.ceil(min); // Ensure min is an integer
|
||||
|
|
@ -23,6 +23,7 @@ export const processNextEditData = async (
|
|||
getDefinitionsFromLsp: GetLspDefinitionsFunction,
|
||||
recentlyEditedRanges: RecentlyEditedRange[],
|
||||
recentlyVisitedRanges: AutocompleteCodeSnippet[],
|
||||
workspaceDir: string,
|
||||
modelNameOrInstance?: string | undefined,
|
||||
// eslint-disable-next-line max-params
|
||||
) => {
|
||||
|
|
@ -34,7 +35,7 @@ export const processNextEditData = async (
|
|||
|
||||
const modelName = "Codestral";
|
||||
|
||||
const maxPromptTokens = randomNumberBetween(500, 14000);
|
||||
const maxPromptTokens = randomNumberBetween(500, 12000);
|
||||
|
||||
const autocompleteContext = await getAutocompleteContext(
|
||||
filePath,
|
||||
|
|
@ -49,7 +50,20 @@ export const processNextEditData = async (
|
|||
modelName,
|
||||
);
|
||||
|
||||
console.log(
|
||||
createDiff(beforeContent, afterContent, filePath, DiffFormatType.Unified),
|
||||
);
|
||||
// console.log(
|
||||
// createDiff(beforeContent, afterContent, filePath, DiffFormatType.Unified),
|
||||
// );
|
||||
|
||||
void DataLogger.getInstance().logDevData({
|
||||
name: "nextEdit",
|
||||
data: {
|
||||
fileURI: filePath,
|
||||
workspaceDirURI: workspaceDir,
|
||||
beforeContent,
|
||||
afterContent,
|
||||
beforeCursorPos: cursorPosBeforeEdit,
|
||||
afterCursorPos: cursorPosAfterPrevEdit,
|
||||
context: autocompleteContext,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -301,7 +301,9 @@ export class VsCodeExtension {
|
|||
const workspaceFolder = vscode.workspace.getWorkspaceFolder(
|
||||
event.document.uri,
|
||||
);
|
||||
if (!workspaceFolder) return;
|
||||
if (!workspaceFolder) {
|
||||
return;
|
||||
}
|
||||
|
||||
const workspaceDirUri = workspaceFolder.uri.toString();
|
||||
const repoName = await this.ide.getRepoName(workspaceDirUri);
|
||||
|
|
@ -325,6 +327,7 @@ export class VsCodeExtension {
|
|||
: change.range.start) as Position,
|
||||
|
||||
afterCursorPos: activeCursorPos as Position,
|
||||
workspaceDir: workspaceDirUri,
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,11 @@ import {
|
|||
editInteractionEventSchema_0_2_0,
|
||||
editInteractionEventSchema_0_2_0_noCode,
|
||||
} from "./editInteraction/v0.2.0.js";
|
||||
import { nextEditEventAllSchema } from "./nextEdit/index.js";
|
||||
import {
|
||||
nextEditEventSchema_0_2_0,
|
||||
nextEditEventSchema_0_2_0_noCode,
|
||||
} from "./nextEdit/v0.2.0.js";
|
||||
import { quickEditEventAllSchema } from "./quickEdit/index.js";
|
||||
import {
|
||||
quickEditEventSchema_0_1_0,
|
||||
|
|
@ -72,6 +77,7 @@ const devEventAllVersionDataSchemas = z.object({
|
|||
tokensGenerated: tokensGeneratedEventAllSchema,
|
||||
chatInteraction: chatInteractionEventAllSchema,
|
||||
editInteraction: editInteractionEventAllSchema,
|
||||
nextEdit: nextEditEventAllSchema,
|
||||
});
|
||||
|
||||
// Version and level specific schemas are organized here
|
||||
|
|
@ -97,6 +103,7 @@ export const devDataVersionedSchemas = {
|
|||
tokensGenerated: tokensGeneratedEventSchema_0_2_0,
|
||||
chatInteraction: chatInteractionEventSchema_0_2_0,
|
||||
editInteraction: editInteractionEventSchema_0_2_0,
|
||||
nextEdit: nextEditEventSchema_0_2_0,
|
||||
},
|
||||
noCode: {
|
||||
autocomplete: autocompleteEventSchema_0_2_0_noCode,
|
||||
|
|
@ -104,6 +111,7 @@ export const devDataVersionedSchemas = {
|
|||
tokensGenerated: tokensGeneratedEventSchema_0_2_0_noCode,
|
||||
chatInteraction: chatInteractionEventSchema_0_2_0_noCode,
|
||||
editInteraction: editInteractionEventSchema_0_2_0_noCode,
|
||||
nextEdit: nextEditEventSchema_0_2_0_noCode,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
|||
12
packages/config-yaml/src/schemas/data/nextEdit/index.ts
Normal file
12
packages/config-yaml/src/schemas/data/nextEdit/index.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { z } from "zod";
|
||||
import { baseDevDataAllSchema } from "../base.js";
|
||||
|
||||
export const nextEditEventAllSchema = baseDevDataAllSchema.extend({
|
||||
fileURI: z.string(),
|
||||
workspaceDirURI: z.string(),
|
||||
beforeContent: z.string(),
|
||||
afterContent: z.string(),
|
||||
beforeCursorPos: z.object({ line: z.number(), character: z.number() }),
|
||||
afterCursorPos: z.object({ line: z.number(), character: z.number() }),
|
||||
context: z.string(),
|
||||
});
|
||||
28
packages/config-yaml/src/schemas/data/nextEdit/v0.2.0.ts
Normal file
28
packages/config-yaml/src/schemas/data/nextEdit/v0.2.0.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { nextEditEventAllSchema } from "./index.js";
|
||||
|
||||
export const nextEditEventSchema_0_2_0 = nextEditEventAllSchema.pick({
|
||||
// base
|
||||
timestamp: true,
|
||||
userId: true,
|
||||
userAgent: true,
|
||||
selectedProfileId: true,
|
||||
eventName: true,
|
||||
schema: true,
|
||||
|
||||
// nextedit-specific
|
||||
fileURI: true,
|
||||
workspaceDirURI: true,
|
||||
beforeContent: true,
|
||||
afterContent: true,
|
||||
beforeCursorPos: true,
|
||||
afterCursorPos: true,
|
||||
context: true,
|
||||
});
|
||||
|
||||
export const nextEditEventSchema_0_2_0_noCode = nextEditEventSchema_0_2_0.omit({
|
||||
fileURI: true,
|
||||
workspaceDirURI: true,
|
||||
beforeContent: true,
|
||||
afterContent: true,
|
||||
context: true,
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue