Merge pull request #6358 from continuedev/edit-outcome

Add edit outcome tracking to record accept/reject
This commit is contained in:
Nate Sesti 2025-06-30 23:14:50 -07:00 • committed by GitHub
commit 79668ebb00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 204 additions and 40 deletions

View file

@ -167,12 +167,12 @@
},
"../packages/openai-adapters": {
"name": "@continuedev/openai-adapters",
"version": "1.0.42",
"version": "1.0.44",
"license": "Apache-2.0",
"dependencies": {
"@continuedev/config-types": "^1.0.5",
"@continuedev/config-yaml": "^1.0.51",
"@continuedev/fetch": "^1.0.14",
"@continuedev/fetch": "^1.0.15",
"dotenv": "^16.5.0",
"json-schema": "^0.4.0",
"node-fetch": "^3.3.2",

View file

@ -2,7 +2,7 @@
"name": "continue",
"icon": "media/icon.png",
"author": "Continue Dev, Inc",
"version": "1.1.52",
"version": "1.1.53",
"repository": {
"type": "git",
"url": "https://github.com/continuedev/continue"

View file

@ -42,7 +42,7 @@ export class ApplyManager {
const { activeTextEditor } = vscode.window;
if (!activeTextEditor) {
vscode.window.showErrorMessage("No active editor to apply edits to");
void vscode.window.showErrorMessage("No active editor to apply edits to");
return;
}
@ -116,14 +116,14 @@ export class ApplyManager {
) {
const { config } = await this.configHandler.loadConfig();
if (!config) {
vscode.window.showErrorMessage("Config not loaded");
void vscode.window.showErrorMessage("Config not loaded");
return;
}
const llm =
config.selectedModelByRole.apply ?? config.selectedModelByRole.chat;
if (!llm) {
vscode.window.showErrorMessage(
void vscode.window.showErrorMessage(
`No model with roles "apply" or "chat" found in config.`,
);
return;
@ -177,7 +177,7 @@ export class ApplyManager {
) {
const { config } = await this.configHandler.loadConfig();
if (!config) {
vscode.window.showErrorMessage("Config not loaded");
void vscode.window.showErrorMessage("Config not loaded");
return;
}

View file

@ -1,5 +1,7 @@
import { Core } from "core/core";
import { DataLogger } from "core/data/log";
import { ContinueGUIWebviewViewProvider } from "../ContinueGUIWebviewViewProvider";
import { editOutcomeTracker } from "../extension/EditOutcomeTracker";
import { VsCodeIde } from "../VsCodeIde";
import { VerticalDiffManager } from "./vertical/manager";
@ -27,6 +29,11 @@ export async function processDiff(
await ide.openFile(newOrCurrentUri);
// If streamId is not provided, try to get it from the VerticalDiffManager
if (!streamId) {
streamId = verticalDiffManager.getStreamIdForFile(newOrCurrentUri);
}
// Clear vertical diffs depending on action
verticalDiffManager.clearForfileUri(newOrCurrentUri, action === "accept");
if (action === "reject") {
@ -37,6 +44,13 @@ export async function processDiff(
if (streamId) {
const fileContent = await ide.readFile(newOrCurrentUri);
// Record the edit outcome before updating the apply state
await editOutcomeTracker.recordEditOutcome(
streamId,
action === "accept",
DataLogger.getInstance(),
);
await sidebar.webviewProtocol.request("updateApplyState", {
fileContent,
filepath: newOrCurrentUri,

View file

@ -9,8 +9,8 @@ import {
indexDecorationType,
} from "./decorations";
import type { VerticalDiffCodeLens } from "./manager";
import type { ApplyState, DiffLine } from "core";
import type { VerticalDiffCodeLens } from "./manager";
export interface VerticalDiffHandlerOptions {
input?: string;
@ -20,10 +20,12 @@ export interface VerticalDiffHandlerOptions {
numDiffs?: ApplyState["numDiffs"],
fileContent?: ApplyState["fileContent"],
) => void;
streamId?: string;
}
export class VerticalDiffHandler implements vscode.Disposable {
public insertedInCurrentBlock = 0;
public streamId?: string;
disposables: vscode.Disposable[] = [];
private currentLineIndex: number;
private cancelled = false;
@ -50,6 +52,7 @@ export class VerticalDiffHandler implements vscode.Disposable {
public options: VerticalDiffHandlerOptions,
) {
this.currentLineIndex = startLine;
this.streamId = options.streamId;
this.removedLineDecorations = new RemovedLineDecorationManager(this.editor);
this.addedLineDecorations = new AddedLineDecorationManager(this.editor);
@ -330,10 +333,7 @@ export class VerticalDiffHandler implements vscode.Disposable {
// Then, we insert our diff lines
await this.editor.edit((editBuilder) => {
editBuilder.replace(this.range, replaceContent),
{
undoStopAfter: false,
undoStopBefore: false,
};
{ undoStopAfter: false, undoStopBefore: false };
});
// Lastly, we apply decorations
@ -446,10 +446,7 @@ export class VerticalDiffHandler implements vscode.Disposable {
editBuilder.insert(new vscode.Position(index, 0), `${text}\n`);
}
},
{
undoStopAfter: false,
undoStopBefore: false,
},
{ undoStopAfter: false, undoStopBefore: false },
);
}
@ -467,10 +464,7 @@ export class VerticalDiffHandler implements vscode.Disposable {
new vscode.Range(startLine, startLine.translate(numLines)),
);
},
{
undoStopAfter: false,
undoStopBefore: false,
},
{ undoStopAfter: false, undoStopBefore: false },
);
}
@ -486,10 +480,7 @@ export class VerticalDiffHandler implements vscode.Disposable {
);
}
},
{
undoStopAfter: false,
undoStopBefore: false,
},
{ undoStopAfter: false, undoStopBefore: false },
);
}

View file

@ -1,4 +1,4 @@
import { ChatMessage, DiffLine, ILLM, RuleWithSource } from "core";
import { ChatMessage, DiffLine, IDE, ILLM, RuleWithSource } from "core";
import { streamDiffLines } from "core/edit/streamDiffLines";
import { pruneLinesFromBottom, pruneLinesFromTop } from "core/llm/countTokens";
import { getMarkdownLanguageTagForFile } from "core/util";
@ -11,6 +11,9 @@ import { handleLLMError } from "../../util/errorHandling";
import { VsCodeWebviewProtocol } from "../../webviewProtocol";
import { ApplyAbortManager } from "core/edit/applyAbortManager";
import { EDIT_MODE_STREAM_ID } from "core/edit/constants";
import { stripImages } from "core/util/messageContent";
import { editOutcomeTracker } from "../../extension/EditOutcomeTracker";
import { VerticalDiffHandler, VerticalDiffHandlerOptions } from "./handler";
export interface VerticalDiffCodeLens {
@ -23,7 +26,6 @@ export class VerticalDiffManager {
public refreshCodeLens: () => void = () => {};
private fileUriToHandler: Map<string, VerticalDiffHandler> = new Map();
fileUriToCodeLens: Map<string, VerticalDiffCodeLens[]> = new Map();
private userChangeListener: vscode.Disposable | undefined;
@ -33,6 +35,7 @@ export class VerticalDiffManager {
constructor(
private readonly webviewProtocol: VsCodeWebviewProtocol,
private readonly editDecorationManager: EditDecorationManager,
private readonly ide: IDE,
) {
this.userChangeListener = undefined;
}
@ -69,6 +72,10 @@ export class VerticalDiffManager {
return this.fileUriToHandler.get(fileUri);
}
getStreamIdForFile(fileUri: string): string | undefined {
return this.fileUriToHandler.get(fileUri)?.streamId;
}
// Creates a listener for document changes by user.
private enableDocumentChangeListener(): vscode.Disposable | undefined {
if (this.userChangeListener) {
@ -229,6 +236,7 @@ export class VerticalDiffManager {
filepath: fileUri,
toolCallId,
}),
streamId,
},
);
@ -296,7 +304,11 @@ export class VerticalDiffManager {
toolCallId?: string;
rulesToInclude: undefined | RuleWithSource[];
}): Promise<string | undefined> {
vscode.commands.executeCommand("setContext", "continue.diffVisible", true);
void vscode.commands.executeCommand(
"setContext",
"continue.diffVisible",
true,
);
let editor = vscode.window.activeTextEditor;
@ -373,6 +385,7 @@ export class VerticalDiffManager {
filepath: fileUri,
toolCallId,
}),
streamId,
},
);
@ -430,7 +443,7 @@ export class VerticalDiffManager {
);
}
vscode.commands.executeCommand(
void vscode.commands.executeCommand(
"setContext",
"continue.streamingDiff",
true,
@ -472,10 +485,18 @@ export class VerticalDiffManager {
this.enableDocumentChangeListener();
if (abortController.signal.aborted) {
vscode.commands.executeCommand("continue.rejectDiff");
void vscode.commands.executeCommand("continue.rejectDiff");
}
return `${prefix}${streamedLines.join("\n")}${suffix}`;
const fileAfterEdit = `${prefix}${streamedLines.join("\n")}${suffix}`;
await this.trackEditInteraction({
model: llm,
filepath: fileUri,
prompt: input,
fileAfterEdit,
});
return fileAfterEdit;
} catch (e) {
this.disableDocumentChangeListener();
const handled = await handleLLMError(e);
@ -487,11 +508,46 @@ export class VerticalDiffManager {
throw new Error(message);
}
} finally {
vscode.commands.executeCommand(
void vscode.commands.executeCommand(
"setContext",
"continue.streamingDiff",
false,
);
}
}
async trackEditInteraction({
model,
filepath,
prompt,
fileAfterEdit,
}: {
model: ILLM;
filepath: string;
prompt: string;
fileAfterEdit: string | undefined;
}) {
// Get previous code content for outcome tracking
const previousCode = await this.ide.readFile(filepath);
const newCode = fileAfterEdit ?? "";
const previousCodeLines = previousCode.split("\n").length;
const newCodeLines = newCode.split("\n").length;
const lineChange = newCodeLines - previousCodeLines;
// Store pending edit data for outcome tracking
editOutcomeTracker.trackEditInteraction({
streamId: EDIT_MODE_STREAM_ID,
timestamp: new Date().toISOString(),
modelProvider: model.underlyingProviderName,
modelTitle: model.title ?? "",
prompt: stripImages(prompt),
completion: newCode,
previousCode,
newCode,
filepath: filepath,
previousCodeLines,
newCodeLines,
lineChange,
});
}
}

View file

@ -0,0 +1,96 @@
/**
* Tracks pending edit interactions until they are accepted or rejected,
* then emits editOutcome events with the final result.
*/
export interface PendingEditData {
streamId: string;
timestamp: string;
modelProvider: string;
modelTitle: string;
prompt: string;
completion: string;
previousCode: string;
newCode: string;
filepath: string;
previousCodeLines: number;
newCodeLines: number;
lineChange: number;
}
class EditOutcomeTracker {
private static instance: EditOutcomeTracker;
private pendingEdits: Map<string, PendingEditData> = new Map();
private constructor() {}
public static getInstance(): EditOutcomeTracker {
if (!EditOutcomeTracker.instance) {
EditOutcomeTracker.instance = new EditOutcomeTracker();
}
return EditOutcomeTracker.instance;
}
/**
* Store a pending edit interaction for later outcome tracking
*/
public trackEditInteraction(data: PendingEditData): void {
this.pendingEdits.set(data.streamId, data);
}
/**
* Record the outcome of an edit interaction and emit the editOutcome event
*/
public async recordEditOutcome(
streamId: string,
accepted: boolean,
dataLogger: any,
): Promise<void> {
const pendingEdit = this.pendingEdits.get(streamId);
if (!pendingEdit) {
console.warn(`No pending edit found for streamId: ${streamId}`);
return;
}
// Emit the editOutcome event
await dataLogger.logDevData({
name: "editOutcome",
data: {
modelProvider: pendingEdit.modelProvider,
modelTitle: pendingEdit.modelTitle,
prompt: pendingEdit.prompt,
completion: pendingEdit.completion,
previousCode: pendingEdit.previousCode,
newCode: pendingEdit.newCode,
previousCodeLines: pendingEdit.previousCodeLines,
newCodeLines: pendingEdit.newCodeLines,
lineChange: pendingEdit.lineChange,
accepted,
},
});
// Clean up the pending edit
this.pendingEdits.delete(streamId);
}
/**
* Clean up pending edits that might have been abandoned
*/
public cleanupOldPendingEdits(maxAgeMs: number = 30 * 60 * 1000): void {
const now = Date.now();
for (const [streamId, edit] of this.pendingEdits.entries()) {
const editTime = new Date(edit.timestamp).getTime();
if (now - editTime > maxAgeMs) {
this.pendingEdits.delete(streamId);
}
}
}
/**
* Get count of pending edits (for debugging/monitoring)
*/
public getPendingEditCount(): number {
return this.pendingEdits.size;
}
}
export const editOutcomeTracker = EditOutcomeTracker.getInstance();

View file

@ -36,6 +36,7 @@ import {
} from "../stubs/WorkOsAuthProvider";
import { Battery } from "../util/battery";
import { FileSearch } from "../util/FileSearch";
import { VsCodeIdeUtils } from "../util/ideUtils";
import { VsCodeIde } from "../VsCodeIde";
import { ConfigYamlDocumentLinkProvider } from "./ConfigYamlDocumentLinkProvider";
@ -46,7 +47,6 @@ import setupNextEditWindowManager, {
} from "../activation/NextEditWindowManager";
import { getDefinitionsFromLsp } from "../autocomplete/lsp";
import { handleTextDocumentChange } from "../util/editLoggingUtils";
import { VsCodeIdeUtils } from "../util/ideUtils";
import type { VsCodeWebviewProtocol } from "../webviewProtocol";
export class VsCodeExtension {
@ -72,7 +72,7 @@ export class VsCodeExtension {
constructor(context: vscode.ExtensionContext) {
// Register auth provider
this.workOsAuthProvider = new WorkOsAuthProvider(context, this.uriHandler);
this.workOsAuthProvider.refreshSessions();
void this.workOsAuthProvider.refreshSessions();
context.subscriptions.push(this.workOsAuthProvider);
this.editDecorationManager = new EditDecorationManager(context);
@ -138,19 +138,20 @@ export class VsCodeExtension {
this.configHandler = this.core.configHandler;
resolveConfigHandler?.(this.configHandler);
this.configHandler.loadConfig();
void this.configHandler.loadConfig();
this.verticalDiffManager = new VerticalDiffManager(
this.sidebar.webviewProtocol,
this.editDecorationManager,
this.ide,
);
resolveVerticalDiffManager?.(this.verticalDiffManager);
setupRemoteConfigSync(
void setupRemoteConfigSync(
this.configHandler.reloadConfig.bind(this.configHandler),
);
this.configHandler.loadConfig().then(({ config }) => {
void this.configHandler.loadConfig().then(({ config }) => {
const { verticalDiffCodeLens } = registerAllCodeLensProviders(
context,
this.verticalDiffManager.fileUriToCodeLens,
@ -301,7 +302,7 @@ export class VsCodeExtension {
if (stats.size === 0) {
return;
}
this.configHandler.reloadConfig();
void this.configHandler.reloadConfig();
});
vscode.workspace.onDidChangeTextDocument(async (event) => {
@ -344,7 +345,7 @@ export class VsCodeExtension {
vscode.authentication.onDidChangeSessions(async (e) => {
const env = await getControlPlaneEnv(this.ide.getIdeSettings());
if (e.provider.id === env.AUTH_TYPE) {
vscode.commands.executeCommand(
void vscode.commands.executeCommand(
"setContext",
"continue.isSignedInToControlPlane",
true,
@ -355,7 +356,7 @@ export class VsCodeExtension {
sessionInfo,
});
} else {
vscode.commands.executeCommand(
void vscode.commands.executeCommand(
"setContext",
"continue.isSignedInToControlPlane",
false,
@ -368,7 +369,7 @@ export class VsCodeExtension {
});
// Refresh index when branch is changed
this.ide.getWorkspaceDirs().then((dirs) =>
void this.ide.getWorkspaceDirs().then((dirs) =>
dirs.forEach(async (dir) => {
const repo = await this.ide.getRepo(dir);
if (repo) {

View file

@ -28,6 +28,10 @@ import {
editInteractionEventSchema_0_2_0,
editInteractionEventSchema_0_2_0_noCode,
} from "./editInteraction/v0.2.0.js";
import {
editOutcomeEventSchema_0_2_0,
editOutcomeEventSchema_0_2_0_noCode,
} from "./editOutcome/v0.2.0.js";
import { nextEditEventAllSchema } from "./nextEdit/index.js";
import {
nextEditEventSchema_0_2_0,
@ -103,6 +107,7 @@ export const devDataVersionedSchemas = {
tokensGenerated: tokensGeneratedEventSchema_0_2_0,
chatInteraction: chatInteractionEventSchema_0_2_0,
editInteraction: editInteractionEventSchema_0_2_0,
editOutcome: editOutcomeEventSchema_0_2_0,
nextEdit: nextEditEventSchema_0_2_0,
},
noCode: {
@ -111,6 +116,7 @@ export const devDataVersionedSchemas = {
tokensGenerated: tokensGeneratedEventSchema_0_2_0_noCode,
chatInteraction: chatInteractionEventSchema_0_2_0_noCode,
editInteraction: editInteractionEventSchema_0_2_0_noCode,
editOutcome: editOutcomeEventSchema_0_2_0_noCode,
nextEdit: nextEditEventSchema_0_2_0_noCode,
},
},